]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-3.0-3.16.1-201409021826.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-3.0-3.16.1-201409021826.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 87663a2..906dc62 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-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
4023 index aead77a..a2253fa 100644
4024 --- a/arch/arm/mach-omap2/board-n8x0.c
4025 +++ b/arch/arm/mach-omap2/board-n8x0.c
4026 @@ -568,7 +568,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
4027 }
4028 #endif
4029
4030 -static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
4031 +static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
4032 .late_init = n8x0_menelaus_late_init,
4033 };
4034
4035 diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
4036 index 8bc1338..8b28b69 100644
4037 --- a/arch/arm/mach-omap2/gpmc.c
4038 +++ b/arch/arm/mach-omap2/gpmc.c
4039 @@ -151,7 +151,6 @@ struct omap3_gpmc_regs {
4040 };
4041
4042 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
4043 -static struct irq_chip gpmc_irq_chip;
4044 static int gpmc_irq_start;
4045
4046 static struct resource gpmc_mem_root;
4047 @@ -736,6 +735,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
4048
4049 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
4050
4051 +static struct irq_chip gpmc_irq_chip = {
4052 + .name = "gpmc",
4053 + .irq_startup = gpmc_irq_noop_ret,
4054 + .irq_enable = gpmc_irq_enable,
4055 + .irq_disable = gpmc_irq_disable,
4056 + .irq_shutdown = gpmc_irq_noop,
4057 + .irq_ack = gpmc_irq_noop,
4058 + .irq_mask = gpmc_irq_noop,
4059 + .irq_unmask = gpmc_irq_noop,
4060 +
4061 +};
4062 +
4063 static int gpmc_setup_irq(void)
4064 {
4065 int i;
4066 @@ -750,15 +761,6 @@ static int gpmc_setup_irq(void)
4067 return gpmc_irq_start;
4068 }
4069
4070 - gpmc_irq_chip.name = "gpmc";
4071 - gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
4072 - gpmc_irq_chip.irq_enable = gpmc_irq_enable;
4073 - gpmc_irq_chip.irq_disable = gpmc_irq_disable;
4074 - gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
4075 - gpmc_irq_chip.irq_ack = gpmc_irq_noop;
4076 - gpmc_irq_chip.irq_mask = gpmc_irq_noop;
4077 - gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
4078 -
4079 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
4080 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
4081
4082 diff --git a/arch/arm/mach-omap2/omap-mpuss-lowpower.c b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
4083 index 4001325..b14e2a0 100644
4084 --- a/arch/arm/mach-omap2/omap-mpuss-lowpower.c
4085 +++ b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
4086 @@ -84,7 +84,7 @@ struct cpu_pm_ops {
4087 int (*finish_suspend)(unsigned long cpu_state);
4088 void (*resume)(void);
4089 void (*scu_prepare)(unsigned int cpu_id, unsigned int cpu_state);
4090 -};
4091 +} __no_const;
4092
4093 static DEFINE_PER_CPU(struct omap4_cpu_pm_info, omap4_pm_info);
4094 static struct powerdomain *mpuss_pd;
4095 @@ -102,7 +102,7 @@ static void dummy_cpu_resume(void)
4096 static void dummy_scu_prepare(unsigned int cpu_id, unsigned int cpu_state)
4097 {}
4098
4099 -struct cpu_pm_ops omap_pm_ops = {
4100 +static struct cpu_pm_ops omap_pm_ops __read_only = {
4101 .finish_suspend = default_finish_suspend,
4102 .resume = dummy_cpu_resume,
4103 .scu_prepare = dummy_scu_prepare,
4104 diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
4105 index 37843a7..a98df13 100644
4106 --- a/arch/arm/mach-omap2/omap-wakeupgen.c
4107 +++ b/arch/arm/mach-omap2/omap-wakeupgen.c
4108 @@ -343,7 +343,7 @@ static int irq_cpu_hotplug_notify(struct notifier_block *self,
4109 return NOTIFY_OK;
4110 }
4111
4112 -static struct notifier_block __refdata irq_hotplug_notifier = {
4113 +static struct notifier_block irq_hotplug_notifier = {
4114 .notifier_call = irq_cpu_hotplug_notify,
4115 };
4116
4117 diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
4118 index 01ef59d..32ae28a8 100644
4119 --- a/arch/arm/mach-omap2/omap_device.c
4120 +++ b/arch/arm/mach-omap2/omap_device.c
4121 @@ -510,7 +510,7 @@ void omap_device_delete(struct omap_device *od)
4122 struct platform_device __init *omap_device_build(const char *pdev_name,
4123 int pdev_id,
4124 struct omap_hwmod *oh,
4125 - void *pdata, int pdata_len)
4126 + const void *pdata, int pdata_len)
4127 {
4128 struct omap_hwmod *ohs[] = { oh };
4129
4130 @@ -538,7 +538,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
4131 struct platform_device __init *omap_device_build_ss(const char *pdev_name,
4132 int pdev_id,
4133 struct omap_hwmod **ohs,
4134 - int oh_cnt, void *pdata,
4135 + int oh_cnt, const void *pdata,
4136 int pdata_len)
4137 {
4138 int ret = -ENOMEM;
4139 diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
4140 index 78c02b3..c94109a 100644
4141 --- a/arch/arm/mach-omap2/omap_device.h
4142 +++ b/arch/arm/mach-omap2/omap_device.h
4143 @@ -72,12 +72,12 @@ int omap_device_idle(struct platform_device *pdev);
4144 /* Core code interface */
4145
4146 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
4147 - struct omap_hwmod *oh, void *pdata,
4148 + struct omap_hwmod *oh, const void *pdata,
4149 int pdata_len);
4150
4151 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
4152 struct omap_hwmod **oh, int oh_cnt,
4153 - void *pdata, int pdata_len);
4154 + const void *pdata, int pdata_len);
4155
4156 struct omap_device *omap_device_alloc(struct platform_device *pdev,
4157 struct omap_hwmod **ohs, int oh_cnt);
4158 diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
4159 index 6c074f3..cd58cb7 100644
4160 --- a/arch/arm/mach-omap2/omap_hwmod.c
4161 +++ b/arch/arm/mach-omap2/omap_hwmod.c
4162 @@ -194,10 +194,10 @@ struct omap_hwmod_soc_ops {
4163 int (*init_clkdm)(struct omap_hwmod *oh);
4164 void (*update_context_lost)(struct omap_hwmod *oh);
4165 int (*get_context_lost)(struct omap_hwmod *oh);
4166 -};
4167 +} __no_const;
4168
4169 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
4170 -static struct omap_hwmod_soc_ops soc_ops;
4171 +static struct omap_hwmod_soc_ops soc_ops __read_only;
4172
4173 /* omap_hwmod_list contains all registered struct omap_hwmods */
4174 static LIST_HEAD(omap_hwmod_list);
4175 diff --git a/arch/arm/mach-omap2/powerdomains43xx_data.c b/arch/arm/mach-omap2/powerdomains43xx_data.c
4176 index 95fee54..cfa9cf1 100644
4177 --- a/arch/arm/mach-omap2/powerdomains43xx_data.c
4178 +++ b/arch/arm/mach-omap2/powerdomains43xx_data.c
4179 @@ -10,6 +10,7 @@
4180
4181 #include <linux/kernel.h>
4182 #include <linux/init.h>
4183 +#include <asm/pgtable.h>
4184
4185 #include "powerdomain.h"
4186
4187 @@ -129,7 +130,9 @@ static int am43xx_check_vcvp(void)
4188
4189 void __init am43xx_powerdomains_init(void)
4190 {
4191 - omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
4192 + pax_open_kernel();
4193 + *(void **)&omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
4194 + pax_close_kernel();
4195 pwrdm_register_platform_funcs(&omap4_pwrdm_operations);
4196 pwrdm_register_pwrdms(powerdomains_am43xx);
4197 pwrdm_complete_init();
4198 diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
4199 index 97d6607..8429d14 100644
4200 --- a/arch/arm/mach-omap2/wd_timer.c
4201 +++ b/arch/arm/mach-omap2/wd_timer.c
4202 @@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
4203 struct omap_hwmod *oh;
4204 char *oh_name = "wd_timer2";
4205 char *dev_name = "omap_wdt";
4206 - struct omap_wd_timer_platform_data pdata;
4207 + static struct omap_wd_timer_platform_data pdata = {
4208 + .read_reset_sources = prm_read_reset_sources
4209 + };
4210
4211 if (!cpu_class_is_omap2() || of_have_populated_dt())
4212 return 0;
4213 @@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
4214 return -EINVAL;
4215 }
4216
4217 - pdata.read_reset_sources = prm_read_reset_sources;
4218 -
4219 pdev = omap_device_build(dev_name, id, oh, &pdata,
4220 sizeof(struct omap_wd_timer_platform_data));
4221 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
4222 diff --git a/arch/arm/mach-tegra/cpuidle-tegra20.c b/arch/arm/mach-tegra/cpuidle-tegra20.c
4223 index b82dcae..44ee5b6 100644
4224 --- a/arch/arm/mach-tegra/cpuidle-tegra20.c
4225 +++ b/arch/arm/mach-tegra/cpuidle-tegra20.c
4226 @@ -180,7 +180,7 @@ static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev,
4227 bool entered_lp2 = false;
4228
4229 if (tegra_pending_sgi())
4230 - ACCESS_ONCE(abort_flag) = true;
4231 + ACCESS_ONCE_RW(abort_flag) = true;
4232
4233 cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
4234
4235 diff --git a/arch/arm/mach-ux500/setup.h b/arch/arm/mach-ux500/setup.h
4236 index 2dea8b5..6499da2 100644
4237 --- a/arch/arm/mach-ux500/setup.h
4238 +++ b/arch/arm/mach-ux500/setup.h
4239 @@ -33,13 +33,6 @@ extern void ux500_timer_init(void);
4240 .type = MT_DEVICE, \
4241 }
4242
4243 -#define __MEM_DEV_DESC(x, sz) { \
4244 - .virtual = IO_ADDRESS(x), \
4245 - .pfn = __phys_to_pfn(x), \
4246 - .length = sz, \
4247 - .type = MT_MEMORY_RWX, \
4248 -}
4249 -
4250 extern struct smp_operations ux500_smp_ops;
4251 extern void ux500_cpu_die(unsigned int cpu);
4252
4253 diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
4254 index c348eae..456a1a4 100644
4255 --- a/arch/arm/mm/Kconfig
4256 +++ b/arch/arm/mm/Kconfig
4257 @@ -446,6 +446,7 @@ config CPU_32v5
4258
4259 config CPU_32v6
4260 bool
4261 + select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
4262 select TLS_REG_EMUL if !CPU_32v6K && !MMU
4263
4264 config CPU_32v6K
4265 @@ -600,6 +601,7 @@ config CPU_CP15_MPU
4266
4267 config CPU_USE_DOMAINS
4268 bool
4269 + depends on !ARM_LPAE && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
4270 help
4271 This option enables or disables the use of domain switching
4272 via the set_fs() function.
4273 @@ -799,6 +801,7 @@ config NEED_KUSER_HELPERS
4274 config KUSER_HELPERS
4275 bool "Enable kuser helpers in vector page" if !NEED_KUSER_HELPERS
4276 default y
4277 + depends on !(CPU_V6 || CPU_V6K || CPU_V7) || GRKERNSEC_OLD_ARM_USERLAND
4278 help
4279 Warning: disabling this option may break user programs.
4280
4281 @@ -811,7 +814,7 @@ config KUSER_HELPERS
4282 See Documentation/arm/kernel_user_helpers.txt for details.
4283
4284 However, the fixed address nature of these helpers can be used
4285 - by ROP (return orientated programming) authors when creating
4286 + by ROP (Return Oriented Programming) authors when creating
4287 exploits.
4288
4289 If all of the binaries and libraries which run on your platform
4290 diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
4291 index b8cb1a2..6a5624a 100644
4292 --- a/arch/arm/mm/alignment.c
4293 +++ b/arch/arm/mm/alignment.c
4294 @@ -214,10 +214,12 @@ union offset_union {
4295 #define __get16_unaligned_check(ins,val,addr) \
4296 do { \
4297 unsigned int err = 0, v, a = addr; \
4298 + pax_open_userland(); \
4299 __get8_unaligned_check(ins,v,a,err); \
4300 val = v << ((BE) ? 8 : 0); \
4301 __get8_unaligned_check(ins,v,a,err); \
4302 val |= v << ((BE) ? 0 : 8); \
4303 + pax_close_userland(); \
4304 if (err) \
4305 goto fault; \
4306 } while (0)
4307 @@ -231,6 +233,7 @@ union offset_union {
4308 #define __get32_unaligned_check(ins,val,addr) \
4309 do { \
4310 unsigned int err = 0, v, a = addr; \
4311 + pax_open_userland(); \
4312 __get8_unaligned_check(ins,v,a,err); \
4313 val = v << ((BE) ? 24 : 0); \
4314 __get8_unaligned_check(ins,v,a,err); \
4315 @@ -239,6 +242,7 @@ union offset_union {
4316 val |= v << ((BE) ? 8 : 16); \
4317 __get8_unaligned_check(ins,v,a,err); \
4318 val |= v << ((BE) ? 0 : 24); \
4319 + pax_close_userland(); \
4320 if (err) \
4321 goto fault; \
4322 } while (0)
4323 @@ -252,6 +256,7 @@ union offset_union {
4324 #define __put16_unaligned_check(ins,val,addr) \
4325 do { \
4326 unsigned int err = 0, v = val, a = addr; \
4327 + pax_open_userland(); \
4328 __asm__( FIRST_BYTE_16 \
4329 ARM( "1: "ins" %1, [%2], #1\n" ) \
4330 THUMB( "1: "ins" %1, [%2]\n" ) \
4331 @@ -271,6 +276,7 @@ union offset_union {
4332 " .popsection\n" \
4333 : "=r" (err), "=&r" (v), "=&r" (a) \
4334 : "0" (err), "1" (v), "2" (a)); \
4335 + pax_close_userland(); \
4336 if (err) \
4337 goto fault; \
4338 } while (0)
4339 @@ -284,6 +290,7 @@ union offset_union {
4340 #define __put32_unaligned_check(ins,val,addr) \
4341 do { \
4342 unsigned int err = 0, v = val, a = addr; \
4343 + pax_open_userland(); \
4344 __asm__( FIRST_BYTE_32 \
4345 ARM( "1: "ins" %1, [%2], #1\n" ) \
4346 THUMB( "1: "ins" %1, [%2]\n" ) \
4347 @@ -313,6 +320,7 @@ union offset_union {
4348 " .popsection\n" \
4349 : "=r" (err), "=&r" (v), "=&r" (a) \
4350 : "0" (err), "1" (v), "2" (a)); \
4351 + pax_close_userland(); \
4352 if (err) \
4353 goto fault; \
4354 } while (0)
4355 diff --git a/arch/arm/mm/cache-l2x0.c b/arch/arm/mm/cache-l2x0.c
4356 index 7c3fb41..bfb87d8 100644
4357 --- a/arch/arm/mm/cache-l2x0.c
4358 +++ b/arch/arm/mm/cache-l2x0.c
4359 @@ -41,7 +41,7 @@ struct l2c_init_data {
4360 void (*fixup)(void __iomem *, u32, struct outer_cache_fns *);
4361 void (*save)(void __iomem *);
4362 struct outer_cache_fns outer_cache;
4363 -};
4364 +} __do_const;
4365
4366 #define CACHE_LINE_SIZE 32
4367
4368 diff --git a/arch/arm/mm/context.c b/arch/arm/mm/context.c
4369 index 6eb97b3..ac509f6 100644
4370 --- a/arch/arm/mm/context.c
4371 +++ b/arch/arm/mm/context.c
4372 @@ -43,7 +43,7 @@
4373 #define NUM_USER_ASIDS ASID_FIRST_VERSION
4374
4375 static DEFINE_RAW_SPINLOCK(cpu_asid_lock);
4376 -static atomic64_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
4377 +static atomic64_unchecked_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
4378 static DECLARE_BITMAP(asid_map, NUM_USER_ASIDS);
4379
4380 static DEFINE_PER_CPU(atomic64_t, active_asids);
4381 @@ -182,7 +182,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
4382 {
4383 static u32 cur_idx = 1;
4384 u64 asid = atomic64_read(&mm->context.id);
4385 - u64 generation = atomic64_read(&asid_generation);
4386 + u64 generation = atomic64_read_unchecked(&asid_generation);
4387
4388 if (asid != 0 && is_reserved_asid(asid)) {
4389 /*
4390 @@ -203,7 +203,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
4391 */
4392 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, cur_idx);
4393 if (asid == NUM_USER_ASIDS) {
4394 - generation = atomic64_add_return(ASID_FIRST_VERSION,
4395 + generation = atomic64_add_return_unchecked(ASID_FIRST_VERSION,
4396 &asid_generation);
4397 flush_context(cpu);
4398 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
4399 @@ -234,14 +234,14 @@ void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk)
4400 cpu_set_reserved_ttbr0();
4401
4402 asid = atomic64_read(&mm->context.id);
4403 - if (!((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS)
4404 + if (!((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS)
4405 && atomic64_xchg(&per_cpu(active_asids, cpu), asid))
4406 goto switch_mm_fastpath;
4407
4408 raw_spin_lock_irqsave(&cpu_asid_lock, flags);
4409 /* Check that our ASID belongs to the current generation. */
4410 asid = atomic64_read(&mm->context.id);
4411 - if ((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS) {
4412 + if ((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS) {
4413 asid = new_context(mm, cpu);
4414 atomic64_set(&mm->context.id, asid);
4415 }
4416 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
4417 index eb8830a..5360ce7 100644
4418 --- a/arch/arm/mm/fault.c
4419 +++ b/arch/arm/mm/fault.c
4420 @@ -25,6 +25,7 @@
4421 #include <asm/system_misc.h>
4422 #include <asm/system_info.h>
4423 #include <asm/tlbflush.h>
4424 +#include <asm/sections.h>
4425
4426 #include "fault.h"
4427
4428 @@ -138,6 +139,31 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
4429 if (fixup_exception(regs))
4430 return;
4431
4432 +#ifdef CONFIG_PAX_MEMORY_UDEREF
4433 + if (addr < TASK_SIZE) {
4434 + if (current->signal->curr_ip)
4435 + 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),
4436 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4437 + else
4438 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
4439 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4440 + }
4441 +#endif
4442 +
4443 +#ifdef CONFIG_PAX_KERNEXEC
4444 + if ((fsr & FSR_WRITE) &&
4445 + (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
4446 + (MODULES_VADDR <= addr && addr < MODULES_END)))
4447 + {
4448 + if (current->signal->curr_ip)
4449 + 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),
4450 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
4451 + else
4452 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
4453 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
4454 + }
4455 +#endif
4456 +
4457 /*
4458 * No handler, we'll have to terminate things with extreme prejudice.
4459 */
4460 @@ -174,6 +200,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
4461 }
4462 #endif
4463
4464 +#ifdef CONFIG_PAX_PAGEEXEC
4465 + if (fsr & FSR_LNX_PF) {
4466 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
4467 + do_group_exit(SIGKILL);
4468 + }
4469 +#endif
4470 +
4471 tsk->thread.address = addr;
4472 tsk->thread.error_code = fsr;
4473 tsk->thread.trap_no = 14;
4474 @@ -401,6 +434,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
4475 }
4476 #endif /* CONFIG_MMU */
4477
4478 +#ifdef CONFIG_PAX_PAGEEXEC
4479 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4480 +{
4481 + long i;
4482 +
4483 + printk(KERN_ERR "PAX: bytes at PC: ");
4484 + for (i = 0; i < 20; i++) {
4485 + unsigned char c;
4486 + if (get_user(c, (__force unsigned char __user *)pc+i))
4487 + printk(KERN_CONT "?? ");
4488 + else
4489 + printk(KERN_CONT "%02x ", c);
4490 + }
4491 + printk("\n");
4492 +
4493 + printk(KERN_ERR "PAX: bytes at SP-4: ");
4494 + for (i = -1; i < 20; i++) {
4495 + unsigned long c;
4496 + if (get_user(c, (__force unsigned long __user *)sp+i))
4497 + printk(KERN_CONT "???????? ");
4498 + else
4499 + printk(KERN_CONT "%08lx ", c);
4500 + }
4501 + printk("\n");
4502 +}
4503 +#endif
4504 +
4505 /*
4506 * First Level Translation Fault Handler
4507 *
4508 @@ -548,9 +608,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
4509 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
4510 struct siginfo info;
4511
4512 +#ifdef CONFIG_PAX_MEMORY_UDEREF
4513 + if (addr < TASK_SIZE && is_domain_fault(fsr)) {
4514 + if (current->signal->curr_ip)
4515 + 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),
4516 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4517 + else
4518 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
4519 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4520 + goto die;
4521 + }
4522 +#endif
4523 +
4524 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
4525 return;
4526
4527 +die:
4528 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
4529 inf->name, fsr, addr);
4530
4531 @@ -574,15 +647,98 @@ hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *
4532 ifsr_info[nr].name = name;
4533 }
4534
4535 +asmlinkage int sys_sigreturn(struct pt_regs *regs);
4536 +asmlinkage int sys_rt_sigreturn(struct pt_regs *regs);
4537 +
4538 asmlinkage void __exception
4539 do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
4540 {
4541 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
4542 struct siginfo info;
4543 + unsigned long pc = instruction_pointer(regs);
4544 +
4545 + if (user_mode(regs)) {
4546 + unsigned long sigpage = current->mm->context.sigpage;
4547 +
4548 + if (sigpage <= pc && pc < sigpage + 7*4) {
4549 + if (pc < sigpage + 3*4)
4550 + sys_sigreturn(regs);
4551 + else
4552 + sys_rt_sigreturn(regs);
4553 + return;
4554 + }
4555 + if (pc == 0xffff0f60UL) {
4556 + /*
4557 + * PaX: __kuser_cmpxchg64 emulation
4558 + */
4559 + // TODO
4560 + //regs->ARM_pc = regs->ARM_lr;
4561 + //return;
4562 + }
4563 + if (pc == 0xffff0fa0UL) {
4564 + /*
4565 + * PaX: __kuser_memory_barrier emulation
4566 + */
4567 + // dmb(); implied by the exception
4568 + regs->ARM_pc = regs->ARM_lr;
4569 + return;
4570 + }
4571 + if (pc == 0xffff0fc0UL) {
4572 + /*
4573 + * PaX: __kuser_cmpxchg emulation
4574 + */
4575 + // TODO
4576 + //long new;
4577 + //int op;
4578 +
4579 + //op = FUTEX_OP_SET << 28;
4580 + //new = futex_atomic_op_inuser(op, regs->ARM_r2);
4581 + //regs->ARM_r0 = old != new;
4582 + //regs->ARM_pc = regs->ARM_lr;
4583 + //return;
4584 + }
4585 + if (pc == 0xffff0fe0UL) {
4586 + /*
4587 + * PaX: __kuser_get_tls emulation
4588 + */
4589 + regs->ARM_r0 = current_thread_info()->tp_value[0];
4590 + regs->ARM_pc = regs->ARM_lr;
4591 + return;
4592 + }
4593 + }
4594 +
4595 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4596 + else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
4597 + if (current->signal->curr_ip)
4598 + 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),
4599 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4600 + pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4601 + else
4602 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
4603 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4604 + pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4605 + goto die;
4606 + }
4607 +#endif
4608 +
4609 +#ifdef CONFIG_PAX_REFCOUNT
4610 + if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
4611 + unsigned int bkpt;
4612 +
4613 + if (!probe_kernel_address(pc, bkpt) && cpu_to_le32(bkpt) == 0xe12f1073) {
4614 + current->thread.error_code = ifsr;
4615 + current->thread.trap_no = 0;
4616 + pax_report_refcount_overflow(regs);
4617 + fixup_exception(regs);
4618 + return;
4619 + }
4620 + }
4621 +#endif
4622
4623 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
4624 return;
4625
4626 +die:
4627 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
4628 inf->name, ifsr, addr);
4629
4630 diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
4631 index cf08bdf..772656c 100644
4632 --- a/arch/arm/mm/fault.h
4633 +++ b/arch/arm/mm/fault.h
4634 @@ -3,6 +3,7 @@
4635
4636 /*
4637 * Fault status register encodings. We steal bit 31 for our own purposes.
4638 + * Set when the FSR value is from an instruction fault.
4639 */
4640 #define FSR_LNX_PF (1 << 31)
4641 #define FSR_WRITE (1 << 11)
4642 @@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
4643 }
4644 #endif
4645
4646 +/* valid for LPAE and !LPAE */
4647 +static inline int is_xn_fault(unsigned int fsr)
4648 +{
4649 + return ((fsr_fs(fsr) & 0x3c) == 0xc);
4650 +}
4651 +
4652 +static inline int is_domain_fault(unsigned int fsr)
4653 +{
4654 + return ((fsr_fs(fsr) & 0xD) == 0x9);
4655 +}
4656 +
4657 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
4658 unsigned long search_exception_table(unsigned long addr);
4659
4660 diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
4661 index 659c75d..6f8c029 100644
4662 --- a/arch/arm/mm/init.c
4663 +++ b/arch/arm/mm/init.c
4664 @@ -31,6 +31,8 @@
4665 #include <asm/setup.h>
4666 #include <asm/tlb.h>
4667 #include <asm/fixmap.h>
4668 +#include <asm/system_info.h>
4669 +#include <asm/cp15.h>
4670
4671 #include <asm/mach/arch.h>
4672 #include <asm/mach/map.h>
4673 @@ -619,7 +621,46 @@ void free_initmem(void)
4674 {
4675 #ifdef CONFIG_HAVE_TCM
4676 extern char __tcm_start, __tcm_end;
4677 +#endif
4678
4679 +#ifdef CONFIG_PAX_KERNEXEC
4680 + unsigned long addr;
4681 + pgd_t *pgd;
4682 + pud_t *pud;
4683 + pmd_t *pmd;
4684 + int cpu_arch = cpu_architecture();
4685 + unsigned int cr = get_cr();
4686 +
4687 + if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
4688 + /* make pages tables, etc before .text NX */
4689 + for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
4690 + pgd = pgd_offset_k(addr);
4691 + pud = pud_offset(pgd, addr);
4692 + pmd = pmd_offset(pud, addr);
4693 + __section_update(pmd, addr, PMD_SECT_XN);
4694 + }
4695 + /* make init NX */
4696 + for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
4697 + pgd = pgd_offset_k(addr);
4698 + pud = pud_offset(pgd, addr);
4699 + pmd = pmd_offset(pud, addr);
4700 + __section_update(pmd, addr, PMD_SECT_XN);
4701 + }
4702 + /* make kernel code/rodata RX */
4703 + for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
4704 + pgd = pgd_offset_k(addr);
4705 + pud = pud_offset(pgd, addr);
4706 + pmd = pmd_offset(pud, addr);
4707 +#ifdef CONFIG_ARM_LPAE
4708 + __section_update(pmd, addr, PMD_SECT_RDONLY);
4709 +#else
4710 + __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
4711 +#endif
4712 + }
4713 + }
4714 +#endif
4715 +
4716 +#ifdef CONFIG_HAVE_TCM
4717 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
4718 free_reserved_area(&__tcm_start, &__tcm_end, -1, "TCM link");
4719 #endif
4720 diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
4721 index d1e5ad7..84dcbf2 100644
4722 --- a/arch/arm/mm/ioremap.c
4723 +++ b/arch/arm/mm/ioremap.c
4724 @@ -392,9 +392,9 @@ __arm_ioremap_exec(phys_addr_t phys_addr, size_t size, bool cached)
4725 unsigned int mtype;
4726
4727 if (cached)
4728 - mtype = MT_MEMORY_RWX;
4729 + mtype = MT_MEMORY_RX;
4730 else
4731 - mtype = MT_MEMORY_RWX_NONCACHED;
4732 + mtype = MT_MEMORY_RX_NONCACHED;
4733
4734 return __arm_ioremap_caller(phys_addr, size, mtype,
4735 __builtin_return_address(0));
4736 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
4737 index 5e85ed3..b10a7ed 100644
4738 --- a/arch/arm/mm/mmap.c
4739 +++ b/arch/arm/mm/mmap.c
4740 @@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4741 struct vm_area_struct *vma;
4742 int do_align = 0;
4743 int aliasing = cache_is_vipt_aliasing();
4744 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4745 struct vm_unmapped_area_info info;
4746
4747 /*
4748 @@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4749 if (len > TASK_SIZE)
4750 return -ENOMEM;
4751
4752 +#ifdef CONFIG_PAX_RANDMMAP
4753 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4754 +#endif
4755 +
4756 if (addr) {
4757 if (do_align)
4758 addr = COLOUR_ALIGN(addr, pgoff);
4759 @@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4760 addr = PAGE_ALIGN(addr);
4761
4762 vma = find_vma(mm, addr);
4763 - if (TASK_SIZE - len >= addr &&
4764 - (!vma || addr + len <= vma->vm_start))
4765 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4766 return addr;
4767 }
4768
4769 @@ -99,6 +103,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4770 info.high_limit = TASK_SIZE;
4771 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4772 info.align_offset = pgoff << PAGE_SHIFT;
4773 + info.threadstack_offset = offset;
4774 return vm_unmapped_area(&info);
4775 }
4776
4777 @@ -112,6 +117,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4778 unsigned long addr = addr0;
4779 int do_align = 0;
4780 int aliasing = cache_is_vipt_aliasing();
4781 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4782 struct vm_unmapped_area_info info;
4783
4784 /*
4785 @@ -132,6 +138,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4786 return addr;
4787 }
4788
4789 +#ifdef CONFIG_PAX_RANDMMAP
4790 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4791 +#endif
4792 +
4793 /* requesting a specific address */
4794 if (addr) {
4795 if (do_align)
4796 @@ -139,8 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4797 else
4798 addr = PAGE_ALIGN(addr);
4799 vma = find_vma(mm, addr);
4800 - if (TASK_SIZE - len >= addr &&
4801 - (!vma || addr + len <= vma->vm_start))
4802 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4803 return addr;
4804 }
4805
4806 @@ -150,6 +159,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4807 info.high_limit = mm->mmap_base;
4808 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4809 info.align_offset = pgoff << PAGE_SHIFT;
4810 + info.threadstack_offset = offset;
4811 addr = vm_unmapped_area(&info);
4812
4813 /*
4814 @@ -173,6 +183,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4815 {
4816 unsigned long random_factor = 0UL;
4817
4818 +#ifdef CONFIG_PAX_RANDMMAP
4819 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4820 +#endif
4821 +
4822 /* 8 bits of randomness in 20 address space bits */
4823 if ((current->flags & PF_RANDOMIZE) &&
4824 !(current->personality & ADDR_NO_RANDOMIZE))
4825 @@ -180,9 +194,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4826
4827 if (mmap_is_legacy()) {
4828 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4829 +
4830 +#ifdef CONFIG_PAX_RANDMMAP
4831 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4832 + mm->mmap_base += mm->delta_mmap;
4833 +#endif
4834 +
4835 mm->get_unmapped_area = arch_get_unmapped_area;
4836 } else {
4837 mm->mmap_base = mmap_base(random_factor);
4838 +
4839 +#ifdef CONFIG_PAX_RANDMMAP
4840 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4841 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4842 +#endif
4843 +
4844 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4845 }
4846 }
4847 diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
4848 index 6e3ba8d..9cbb4d7 100644
4849 --- a/arch/arm/mm/mmu.c
4850 +++ b/arch/arm/mm/mmu.c
4851 @@ -40,6 +40,22 @@
4852 #include "mm.h"
4853 #include "tcm.h"
4854
4855 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4856 +void modify_domain(unsigned int dom, unsigned int type)
4857 +{
4858 + struct thread_info *thread = current_thread_info();
4859 + unsigned int domain = thread->cpu_domain;
4860 + /*
4861 + * DOMAIN_MANAGER might be defined to some other value,
4862 + * use the arch-defined constant
4863 + */
4864 + domain &= ~domain_val(dom, 3);
4865 + thread->cpu_domain = domain | domain_val(dom, type);
4866 + set_domain(thread->cpu_domain);
4867 +}
4868 +EXPORT_SYMBOL(modify_domain);
4869 +#endif
4870 +
4871 /*
4872 * empty_zero_page is a special page that is used for
4873 * zero-initialized data and COW.
4874 @@ -239,7 +255,15 @@ __setup("noalign", noalign_setup);
4875 #define PROT_PTE_S2_DEVICE PROT_PTE_DEVICE
4876 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4877
4878 -static struct mem_type mem_types[] = {
4879 +#ifdef CONFIG_PAX_KERNEXEC
4880 +#define L_PTE_KERNEXEC L_PTE_RDONLY
4881 +#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4882 +#else
4883 +#define L_PTE_KERNEXEC L_PTE_DIRTY
4884 +#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4885 +#endif
4886 +
4887 +static struct mem_type mem_types[] __read_only = {
4888 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4889 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4890 L_PTE_SHARED,
4891 @@ -268,19 +292,19 @@ static struct mem_type mem_types[] = {
4892 .prot_sect = PROT_SECT_DEVICE,
4893 .domain = DOMAIN_IO,
4894 },
4895 - [MT_UNCACHED] = {
4896 + [MT_UNCACHED_RW] = {
4897 .prot_pte = PROT_PTE_DEVICE,
4898 .prot_l1 = PMD_TYPE_TABLE,
4899 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4900 .domain = DOMAIN_IO,
4901 },
4902 - [MT_CACHECLEAN] = {
4903 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4904 + [MT_CACHECLEAN_RO] = {
4905 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_RDONLY,
4906 .domain = DOMAIN_KERNEL,
4907 },
4908 #ifndef CONFIG_ARM_LPAE
4909 - [MT_MINICLEAN] = {
4910 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4911 + [MT_MINICLEAN_RO] = {
4912 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_XN | PMD_SECT_RDONLY,
4913 .domain = DOMAIN_KERNEL,
4914 },
4915 #endif
4916 @@ -288,15 +312,15 @@ static struct mem_type mem_types[] = {
4917 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4918 L_PTE_RDONLY,
4919 .prot_l1 = PMD_TYPE_TABLE,
4920 - .domain = DOMAIN_USER,
4921 + .domain = DOMAIN_VECTORS,
4922 },
4923 [MT_HIGH_VECTORS] = {
4924 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4925 L_PTE_USER | L_PTE_RDONLY,
4926 .prot_l1 = PMD_TYPE_TABLE,
4927 - .domain = DOMAIN_USER,
4928 + .domain = DOMAIN_VECTORS,
4929 },
4930 - [MT_MEMORY_RWX] = {
4931 + [__MT_MEMORY_RWX] = {
4932 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4933 .prot_l1 = PMD_TYPE_TABLE,
4934 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4935 @@ -309,17 +333,30 @@ static struct mem_type mem_types[] = {
4936 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4937 .domain = DOMAIN_KERNEL,
4938 },
4939 - [MT_ROM] = {
4940 - .prot_sect = PMD_TYPE_SECT,
4941 + [MT_MEMORY_RX] = {
4942 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4943 + .prot_l1 = PMD_TYPE_TABLE,
4944 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4945 + .domain = DOMAIN_KERNEL,
4946 + },
4947 + [MT_ROM_RX] = {
4948 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4949 .domain = DOMAIN_KERNEL,
4950 },
4951 - [MT_MEMORY_RWX_NONCACHED] = {
4952 + [MT_MEMORY_RW_NONCACHED] = {
4953 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4954 L_PTE_MT_BUFFERABLE,
4955 .prot_l1 = PMD_TYPE_TABLE,
4956 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4957 .domain = DOMAIN_KERNEL,
4958 },
4959 + [MT_MEMORY_RX_NONCACHED] = {
4960 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4961 + L_PTE_MT_BUFFERABLE,
4962 + .prot_l1 = PMD_TYPE_TABLE,
4963 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4964 + .domain = DOMAIN_KERNEL,
4965 + },
4966 [MT_MEMORY_RW_DTCM] = {
4967 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4968 L_PTE_XN,
4969 @@ -327,9 +364,10 @@ static struct mem_type mem_types[] = {
4970 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4971 .domain = DOMAIN_KERNEL,
4972 },
4973 - [MT_MEMORY_RWX_ITCM] = {
4974 - .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4975 + [MT_MEMORY_RX_ITCM] = {
4976 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4977 .prot_l1 = PMD_TYPE_TABLE,
4978 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4979 .domain = DOMAIN_KERNEL,
4980 },
4981 [MT_MEMORY_RW_SO] = {
4982 @@ -547,9 +585,14 @@ static void __init build_mem_type_table(void)
4983 * Mark cache clean areas and XIP ROM read only
4984 * from SVC mode and no access from userspace.
4985 */
4986 - mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4987 - mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4988 - mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4989 + mem_types[MT_ROM_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4990 +#ifdef CONFIG_PAX_KERNEXEC
4991 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4992 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4993 + mem_types[MT_MEMORY_RX_ITCM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4994 +#endif
4995 + mem_types[MT_MINICLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4996 + mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4997 #endif
4998
4999 /*
5000 @@ -566,13 +609,17 @@ static void __init build_mem_type_table(void)
5001 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
5002 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
5003 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
5004 - mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
5005 - mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
5006 + mem_types[__MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
5007 + mem_types[__MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
5008 mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
5009 mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
5010 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
5011 + mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
5012 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
5013 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_S;
5014 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_pte |= L_PTE_SHARED;
5015 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_S;
5016 + mem_types[MT_MEMORY_RW_NONCACHED].prot_pte |= L_PTE_SHARED;
5017 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_S;
5018 + mem_types[MT_MEMORY_RX_NONCACHED].prot_pte |= L_PTE_SHARED;
5019 }
5020 }
5021
5022 @@ -583,15 +630,20 @@ static void __init build_mem_type_table(void)
5023 if (cpu_arch >= CPU_ARCH_ARMv6) {
5024 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
5025 /* Non-cacheable Normal is XCB = 001 */
5026 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
5027 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
5028 + PMD_SECT_BUFFERED;
5029 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
5030 PMD_SECT_BUFFERED;
5031 } else {
5032 /* For both ARMv6 and non-TEX-remapping ARMv7 */
5033 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
5034 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
5035 + PMD_SECT_TEX(1);
5036 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
5037 PMD_SECT_TEX(1);
5038 }
5039 } else {
5040 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
5041 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
5042 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
5043 }
5044
5045 #ifdef CONFIG_ARM_LPAE
5046 @@ -607,6 +659,8 @@ static void __init build_mem_type_table(void)
5047 vecs_pgprot |= PTE_EXT_AF;
5048 #endif
5049
5050 + user_pgprot |= __supported_pte_mask;
5051 +
5052 for (i = 0; i < 16; i++) {
5053 pteval_t v = pgprot_val(protection_map[i]);
5054 protection_map[i] = __pgprot(v | user_pgprot);
5055 @@ -624,21 +678,24 @@ static void __init build_mem_type_table(void)
5056
5057 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
5058 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
5059 - mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
5060 - mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
5061 + mem_types[__MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
5062 + mem_types[__MT_MEMORY_RWX].prot_pte |= kern_pgprot;
5063 mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
5064 mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
5065 + mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
5066 + mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
5067 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
5068 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= ecc_mask;
5069 - mem_types[MT_ROM].prot_sect |= cp->pmd;
5070 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= ecc_mask;
5071 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= ecc_mask;
5072 + mem_types[MT_ROM_RX].prot_sect |= cp->pmd;
5073
5074 switch (cp->pmd) {
5075 case PMD_SECT_WT:
5076 - mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WT;
5077 + mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WT;
5078 break;
5079 case PMD_SECT_WB:
5080 case PMD_SECT_WBWA:
5081 - mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WB;
5082 + mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WB;
5083 break;
5084 }
5085 pr_info("Memory policy: %sData cache %s\n",
5086 @@ -856,7 +913,7 @@ static void __init create_mapping(struct map_desc *md)
5087 return;
5088 }
5089
5090 - if ((md->type == MT_DEVICE || md->type == MT_ROM) &&
5091 + if ((md->type == MT_DEVICE || md->type == MT_ROM_RX) &&
5092 md->virtual >= PAGE_OFFSET &&
5093 (md->virtual < VMALLOC_START || md->virtual >= VMALLOC_END)) {
5094 printk(KERN_WARNING "BUG: mapping for 0x%08llx"
5095 @@ -1224,18 +1281,15 @@ void __init arm_mm_memblock_reserve(void)
5096 * called function. This means you can't use any function or debugging
5097 * method which may touch any device, otherwise the kernel _will_ crash.
5098 */
5099 +
5100 +static char vectors[PAGE_SIZE * 2] __read_only __aligned(PAGE_SIZE);
5101 +
5102 static void __init devicemaps_init(const struct machine_desc *mdesc)
5103 {
5104 struct map_desc map;
5105 unsigned long addr;
5106 - void *vectors;
5107
5108 - /*
5109 - * Allocate the vector page early.
5110 - */
5111 - vectors = early_alloc(PAGE_SIZE * 2);
5112 -
5113 - early_trap_init(vectors);
5114 + early_trap_init(&vectors);
5115
5116 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
5117 pmd_clear(pmd_off_k(addr));
5118 @@ -1248,7 +1302,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
5119 map.pfn = __phys_to_pfn(CONFIG_XIP_PHYS_ADDR & SECTION_MASK);
5120 map.virtual = MODULES_VADDR;
5121 map.length = ((unsigned long)_etext - map.virtual + ~SECTION_MASK) & SECTION_MASK;
5122 - map.type = MT_ROM;
5123 + map.type = MT_ROM_RX;
5124 create_mapping(&map);
5125 #endif
5126
5127 @@ -1259,14 +1313,14 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
5128 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS);
5129 map.virtual = FLUSH_BASE;
5130 map.length = SZ_1M;
5131 - map.type = MT_CACHECLEAN;
5132 + map.type = MT_CACHECLEAN_RO;
5133 create_mapping(&map);
5134 #endif
5135 #ifdef FLUSH_BASE_MINICACHE
5136 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS + SZ_1M);
5137 map.virtual = FLUSH_BASE_MINICACHE;
5138 map.length = SZ_1M;
5139 - map.type = MT_MINICLEAN;
5140 + map.type = MT_MINICLEAN_RO;
5141 create_mapping(&map);
5142 #endif
5143
5144 @@ -1275,7 +1329,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
5145 * location (0xffff0000). If we aren't using high-vectors, also
5146 * create a mapping at the low-vectors virtual address.
5147 */
5148 - map.pfn = __phys_to_pfn(virt_to_phys(vectors));
5149 + map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
5150 map.virtual = 0xffff0000;
5151 map.length = PAGE_SIZE;
5152 #ifdef CONFIG_KUSER_HELPERS
5153 @@ -1335,8 +1389,10 @@ static void __init kmap_init(void)
5154 static void __init map_lowmem(void)
5155 {
5156 struct memblock_region *reg;
5157 +#ifndef CONFIG_PAX_KERNEXEC
5158 unsigned long kernel_x_start = round_down(__pa(_stext), SECTION_SIZE);
5159 unsigned long kernel_x_end = round_up(__pa(__init_end), SECTION_SIZE);
5160 +#endif
5161
5162 /* Map all the lowmem memory banks. */
5163 for_each_memblock(memory, reg) {
5164 @@ -1349,11 +1405,48 @@ static void __init map_lowmem(void)
5165 if (start >= end)
5166 break;
5167
5168 +#ifdef CONFIG_PAX_KERNEXEC
5169 + map.pfn = __phys_to_pfn(start);
5170 + map.virtual = __phys_to_virt(start);
5171 + map.length = end - start;
5172 +
5173 + if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
5174 + struct map_desc kernel;
5175 + struct map_desc initmap;
5176 +
5177 + /* when freeing initmem we will make this RW */
5178 + initmap.pfn = __phys_to_pfn(__pa(__init_begin));
5179 + initmap.virtual = (unsigned long)__init_begin;
5180 + initmap.length = _sdata - __init_begin;
5181 + initmap.type = __MT_MEMORY_RWX;
5182 + create_mapping(&initmap);
5183 +
5184 + /* when freeing initmem we will make this RX */
5185 + kernel.pfn = __phys_to_pfn(__pa(_stext));
5186 + kernel.virtual = (unsigned long)_stext;
5187 + kernel.length = __init_begin - _stext;
5188 + kernel.type = __MT_MEMORY_RWX;
5189 + create_mapping(&kernel);
5190 +
5191 + if (map.virtual < (unsigned long)_stext) {
5192 + map.length = (unsigned long)_stext - map.virtual;
5193 + map.type = __MT_MEMORY_RWX;
5194 + create_mapping(&map);
5195 + }
5196 +
5197 + map.pfn = __phys_to_pfn(__pa(_sdata));
5198 + map.virtual = (unsigned long)_sdata;
5199 + map.length = end - __pa(_sdata);
5200 + }
5201 +
5202 + map.type = MT_MEMORY_RW;
5203 + create_mapping(&map);
5204 +#else
5205 if (end < kernel_x_start || start >= kernel_x_end) {
5206 map.pfn = __phys_to_pfn(start);
5207 map.virtual = __phys_to_virt(start);
5208 map.length = end - start;
5209 - map.type = MT_MEMORY_RWX;
5210 + map.type = __MT_MEMORY_RWX;
5211
5212 create_mapping(&map);
5213 } else {
5214 @@ -1370,7 +1463,7 @@ static void __init map_lowmem(void)
5215 map.pfn = __phys_to_pfn(kernel_x_start);
5216 map.virtual = __phys_to_virt(kernel_x_start);
5217 map.length = kernel_x_end - kernel_x_start;
5218 - map.type = MT_MEMORY_RWX;
5219 + map.type = __MT_MEMORY_RWX;
5220
5221 create_mapping(&map);
5222
5223 @@ -1383,6 +1476,7 @@ static void __init map_lowmem(void)
5224 create_mapping(&map);
5225 }
5226 }
5227 +#endif
5228 }
5229 }
5230
5231 diff --git a/arch/arm/plat-iop/setup.c b/arch/arm/plat-iop/setup.c
5232 index 5b217f4..c23f40e 100644
5233 --- a/arch/arm/plat-iop/setup.c
5234 +++ b/arch/arm/plat-iop/setup.c
5235 @@ -24,7 +24,7 @@ static struct map_desc iop3xx_std_desc[] __initdata = {
5236 .virtual = IOP3XX_PERIPHERAL_VIRT_BASE,
5237 .pfn = __phys_to_pfn(IOP3XX_PERIPHERAL_PHYS_BASE),
5238 .length = IOP3XX_PERIPHERAL_SIZE,
5239 - .type = MT_UNCACHED,
5240 + .type = MT_UNCACHED_RW,
5241 },
5242 };
5243
5244 diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
5245 index a5bc92d..0bb4730 100644
5246 --- a/arch/arm/plat-omap/sram.c
5247 +++ b/arch/arm/plat-omap/sram.c
5248 @@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
5249 * Looks like we need to preserve some bootloader code at the
5250 * beginning of SRAM for jumping to flash for reboot to work...
5251 */
5252 + pax_open_kernel();
5253 memset_io(omap_sram_base + omap_sram_skip, 0,
5254 omap_sram_size - omap_sram_skip);
5255 + pax_close_kernel();
5256 }
5257 diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
5258 index ce6d763..cfea917 100644
5259 --- a/arch/arm/plat-samsung/include/plat/dma-ops.h
5260 +++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
5261 @@ -47,7 +47,7 @@ struct samsung_dma_ops {
5262 int (*started)(unsigned ch);
5263 int (*flush)(unsigned ch);
5264 int (*stop)(unsigned ch);
5265 -};
5266 +} __no_const;
5267
5268 extern void *samsung_dmadev_get_ops(void);
5269 extern void *s3c_dma_get_ops(void);
5270 diff --git a/arch/arm64/include/asm/barrier.h b/arch/arm64/include/asm/barrier.h
5271 index 6389d60..b5d3bdd 100644
5272 --- a/arch/arm64/include/asm/barrier.h
5273 +++ b/arch/arm64/include/asm/barrier.h
5274 @@ -41,7 +41,7 @@
5275 do { \
5276 compiletime_assert_atomic_type(*p); \
5277 barrier(); \
5278 - ACCESS_ONCE(*p) = (v); \
5279 + ACCESS_ONCE_RW(*p) = (v); \
5280 } while (0)
5281
5282 #define smp_load_acquire(p) \
5283 diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h
5284 index 3bf8f4e..5dd5491 100644
5285 --- a/arch/arm64/include/asm/uaccess.h
5286 +++ b/arch/arm64/include/asm/uaccess.h
5287 @@ -99,6 +99,7 @@ static inline void set_fs(mm_segment_t fs)
5288 flag; \
5289 })
5290
5291 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
5292 #define access_ok(type, addr, size) __range_ok(addr, size)
5293 #define user_addr_max get_fs
5294
5295 diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
5296 index c3a58a1..78fbf54 100644
5297 --- a/arch/avr32/include/asm/cache.h
5298 +++ b/arch/avr32/include/asm/cache.h
5299 @@ -1,8 +1,10 @@
5300 #ifndef __ASM_AVR32_CACHE_H
5301 #define __ASM_AVR32_CACHE_H
5302
5303 +#include <linux/const.h>
5304 +
5305 #define L1_CACHE_SHIFT 5
5306 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5307 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5308
5309 /*
5310 * Memory returned by kmalloc() may be used for DMA, so we must make
5311 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
5312 index d232888..87c8df1 100644
5313 --- a/arch/avr32/include/asm/elf.h
5314 +++ b/arch/avr32/include/asm/elf.h
5315 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
5316 the loader. We need to make sure that it is out of the way of the program
5317 that it will "exec", and that there is sufficient room for the brk. */
5318
5319 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
5320 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
5321
5322 +#ifdef CONFIG_PAX_ASLR
5323 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
5324 +
5325 +#define PAX_DELTA_MMAP_LEN 15
5326 +#define PAX_DELTA_STACK_LEN 15
5327 +#endif
5328
5329 /* This yields a mask that user programs can use to figure out what
5330 instruction set this CPU supports. This could be done in user space,
5331 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
5332 index 479330b..53717a8 100644
5333 --- a/arch/avr32/include/asm/kmap_types.h
5334 +++ b/arch/avr32/include/asm/kmap_types.h
5335 @@ -2,9 +2,9 @@
5336 #define __ASM_AVR32_KMAP_TYPES_H
5337
5338 #ifdef CONFIG_DEBUG_HIGHMEM
5339 -# define KM_TYPE_NR 29
5340 +# define KM_TYPE_NR 30
5341 #else
5342 -# define KM_TYPE_NR 14
5343 +# define KM_TYPE_NR 15
5344 #endif
5345
5346 #endif /* __ASM_AVR32_KMAP_TYPES_H */
5347 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
5348 index 0eca933..eb78c7b 100644
5349 --- a/arch/avr32/mm/fault.c
5350 +++ b/arch/avr32/mm/fault.c
5351 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
5352
5353 int exception_trace = 1;
5354
5355 +#ifdef CONFIG_PAX_PAGEEXEC
5356 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5357 +{
5358 + unsigned long i;
5359 +
5360 + printk(KERN_ERR "PAX: bytes at PC: ");
5361 + for (i = 0; i < 20; i++) {
5362 + unsigned char c;
5363 + if (get_user(c, (unsigned char *)pc+i))
5364 + printk(KERN_CONT "???????? ");
5365 + else
5366 + printk(KERN_CONT "%02x ", c);
5367 + }
5368 + printk("\n");
5369 +}
5370 +#endif
5371 +
5372 /*
5373 * This routine handles page faults. It determines the address and the
5374 * problem, and then passes it off to one of the appropriate routines.
5375 @@ -176,6 +193,16 @@ bad_area:
5376 up_read(&mm->mmap_sem);
5377
5378 if (user_mode(regs)) {
5379 +
5380 +#ifdef CONFIG_PAX_PAGEEXEC
5381 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
5382 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
5383 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
5384 + do_group_exit(SIGKILL);
5385 + }
5386 + }
5387 +#endif
5388 +
5389 if (exception_trace && printk_ratelimit())
5390 printk("%s%s[%d]: segfault at %08lx pc %08lx "
5391 "sp %08lx ecr %lu\n",
5392 diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
5393 index 568885a..f8008df 100644
5394 --- a/arch/blackfin/include/asm/cache.h
5395 +++ b/arch/blackfin/include/asm/cache.h
5396 @@ -7,6 +7,7 @@
5397 #ifndef __ARCH_BLACKFIN_CACHE_H
5398 #define __ARCH_BLACKFIN_CACHE_H
5399
5400 +#include <linux/const.h>
5401 #include <linux/linkage.h> /* for asmlinkage */
5402
5403 /*
5404 @@ -14,7 +15,7 @@
5405 * Blackfin loads 32 bytes for cache
5406 */
5407 #define L1_CACHE_SHIFT 5
5408 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5409 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5410 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5411
5412 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5413 diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
5414 index aea2718..3639a60 100644
5415 --- a/arch/cris/include/arch-v10/arch/cache.h
5416 +++ b/arch/cris/include/arch-v10/arch/cache.h
5417 @@ -1,8 +1,9 @@
5418 #ifndef _ASM_ARCH_CACHE_H
5419 #define _ASM_ARCH_CACHE_H
5420
5421 +#include <linux/const.h>
5422 /* Etrax 100LX have 32-byte cache-lines. */
5423 -#define L1_CACHE_BYTES 32
5424 #define L1_CACHE_SHIFT 5
5425 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5426
5427 #endif /* _ASM_ARCH_CACHE_H */
5428 diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
5429 index 7caf25d..ee65ac5 100644
5430 --- a/arch/cris/include/arch-v32/arch/cache.h
5431 +++ b/arch/cris/include/arch-v32/arch/cache.h
5432 @@ -1,11 +1,12 @@
5433 #ifndef _ASM_CRIS_ARCH_CACHE_H
5434 #define _ASM_CRIS_ARCH_CACHE_H
5435
5436 +#include <linux/const.h>
5437 #include <arch/hwregs/dma.h>
5438
5439 /* A cache-line is 32 bytes. */
5440 -#define L1_CACHE_BYTES 32
5441 #define L1_CACHE_SHIFT 5
5442 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5443
5444 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
5445
5446 diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
5447 index f6c3a16..cd422a4 100644
5448 --- a/arch/frv/include/asm/atomic.h
5449 +++ b/arch/frv/include/asm/atomic.h
5450 @@ -181,6 +181,16 @@ static inline void atomic64_dec(atomic64_t *v)
5451 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
5452 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
5453
5454 +#define atomic64_read_unchecked(v) atomic64_read(v)
5455 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5456 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5457 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5458 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5459 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
5460 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5461 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
5462 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5463 +
5464 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5465 {
5466 int c, old;
5467 diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
5468 index 2797163..c2a401d 100644
5469 --- a/arch/frv/include/asm/cache.h
5470 +++ b/arch/frv/include/asm/cache.h
5471 @@ -12,10 +12,11 @@
5472 #ifndef __ASM_CACHE_H
5473 #define __ASM_CACHE_H
5474
5475 +#include <linux/const.h>
5476
5477 /* bytes per L1 cache line */
5478 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
5479 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5480 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5481
5482 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
5483 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
5484 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
5485 index 43901f2..0d8b865 100644
5486 --- a/arch/frv/include/asm/kmap_types.h
5487 +++ b/arch/frv/include/asm/kmap_types.h
5488 @@ -2,6 +2,6 @@
5489 #ifndef _ASM_KMAP_TYPES_H
5490 #define _ASM_KMAP_TYPES_H
5491
5492 -#define KM_TYPE_NR 17
5493 +#define KM_TYPE_NR 18
5494
5495 #endif
5496 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
5497 index 836f147..4cf23f5 100644
5498 --- a/arch/frv/mm/elf-fdpic.c
5499 +++ b/arch/frv/mm/elf-fdpic.c
5500 @@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5501 {
5502 struct vm_area_struct *vma;
5503 struct vm_unmapped_area_info info;
5504 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
5505
5506 if (len > TASK_SIZE)
5507 return -ENOMEM;
5508 @@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5509 if (addr) {
5510 addr = PAGE_ALIGN(addr);
5511 vma = find_vma(current->mm, addr);
5512 - if (TASK_SIZE - len >= addr &&
5513 - (!vma || addr + len <= vma->vm_start))
5514 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
5515 goto success;
5516 }
5517
5518 @@ -85,6 +85,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5519 info.high_limit = (current->mm->start_stack - 0x00200000);
5520 info.align_mask = 0;
5521 info.align_offset = 0;
5522 + info.threadstack_offset = offset;
5523 addr = vm_unmapped_area(&info);
5524 if (!(addr & ~PAGE_MASK))
5525 goto success;
5526 diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
5527 index f4ca594..adc72fd6 100644
5528 --- a/arch/hexagon/include/asm/cache.h
5529 +++ b/arch/hexagon/include/asm/cache.h
5530 @@ -21,9 +21,11 @@
5531 #ifndef __ASM_CACHE_H
5532 #define __ASM_CACHE_H
5533
5534 +#include <linux/const.h>
5535 +
5536 /* Bytes per L1 cache line */
5537 -#define L1_CACHE_SHIFT (5)
5538 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5539 +#define L1_CACHE_SHIFT 5
5540 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5541
5542 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
5543 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
5544 diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig
5545 index 2f3abcf..e63c7fa 100644
5546 --- a/arch/ia64/Kconfig
5547 +++ b/arch/ia64/Kconfig
5548 @@ -547,6 +547,7 @@ source "drivers/sn/Kconfig"
5549 config KEXEC
5550 bool "kexec system call"
5551 depends on !IA64_HP_SIM && (!SMP || HOTPLUG_CPU)
5552 + depends on !GRKERNSEC_KMEM
5553 help
5554 kexec is a system call that implements the ability to shutdown your
5555 current kernel, and to start another kernel. It is like a reboot
5556 diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
5557 index 0f8bf48..40ea950 100644
5558 --- a/arch/ia64/include/asm/atomic.h
5559 +++ b/arch/ia64/include/asm/atomic.h
5560 @@ -209,4 +209,14 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
5561 #define atomic64_inc(v) atomic64_add(1, (v))
5562 #define atomic64_dec(v) atomic64_sub(1, (v))
5563
5564 +#define atomic64_read_unchecked(v) atomic64_read(v)
5565 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5566 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5567 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5568 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5569 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
5570 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5571 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
5572 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5573 +
5574 #endif /* _ASM_IA64_ATOMIC_H */
5575 diff --git a/arch/ia64/include/asm/barrier.h b/arch/ia64/include/asm/barrier.h
5576 index a48957c..e097b56 100644
5577 --- a/arch/ia64/include/asm/barrier.h
5578 +++ b/arch/ia64/include/asm/barrier.h
5579 @@ -67,7 +67,7 @@
5580 do { \
5581 compiletime_assert_atomic_type(*p); \
5582 barrier(); \
5583 - ACCESS_ONCE(*p) = (v); \
5584 + ACCESS_ONCE_RW(*p) = (v); \
5585 } while (0)
5586
5587 #define smp_load_acquire(p) \
5588 diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
5589 index 988254a..e1ee885 100644
5590 --- a/arch/ia64/include/asm/cache.h
5591 +++ b/arch/ia64/include/asm/cache.h
5592 @@ -1,6 +1,7 @@
5593 #ifndef _ASM_IA64_CACHE_H
5594 #define _ASM_IA64_CACHE_H
5595
5596 +#include <linux/const.h>
5597
5598 /*
5599 * Copyright (C) 1998-2000 Hewlett-Packard Co
5600 @@ -9,7 +10,7 @@
5601
5602 /* Bytes per L1 (data) cache line. */
5603 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
5604 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5605 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5606
5607 #ifdef CONFIG_SMP
5608 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
5609 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
5610 index 5a83c5c..4d7f553 100644
5611 --- a/arch/ia64/include/asm/elf.h
5612 +++ b/arch/ia64/include/asm/elf.h
5613 @@ -42,6 +42,13 @@
5614 */
5615 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
5616
5617 +#ifdef CONFIG_PAX_ASLR
5618 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
5619 +
5620 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5621 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5622 +#endif
5623 +
5624 #define PT_IA_64_UNWIND 0x70000001
5625
5626 /* IA-64 relocations: */
5627 diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
5628 index 5767cdf..7462574 100644
5629 --- a/arch/ia64/include/asm/pgalloc.h
5630 +++ b/arch/ia64/include/asm/pgalloc.h
5631 @@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5632 pgd_val(*pgd_entry) = __pa(pud);
5633 }
5634
5635 +static inline void
5636 +pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5637 +{
5638 + pgd_populate(mm, pgd_entry, pud);
5639 +}
5640 +
5641 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
5642 {
5643 return quicklist_alloc(0, GFP_KERNEL, NULL);
5644 @@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5645 pud_val(*pud_entry) = __pa(pmd);
5646 }
5647
5648 +static inline void
5649 +pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5650 +{
5651 + pud_populate(mm, pud_entry, pmd);
5652 +}
5653 +
5654 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5655 {
5656 return quicklist_alloc(0, GFP_KERNEL, NULL);
5657 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
5658 index 7935115..c0eca6a 100644
5659 --- a/arch/ia64/include/asm/pgtable.h
5660 +++ b/arch/ia64/include/asm/pgtable.h
5661 @@ -12,7 +12,7 @@
5662 * David Mosberger-Tang <davidm@hpl.hp.com>
5663 */
5664
5665 -
5666 +#include <linux/const.h>
5667 #include <asm/mman.h>
5668 #include <asm/page.h>
5669 #include <asm/processor.h>
5670 @@ -142,6 +142,17 @@
5671 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5672 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5673 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
5674 +
5675 +#ifdef CONFIG_PAX_PAGEEXEC
5676 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
5677 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5678 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5679 +#else
5680 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
5681 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
5682 +# define PAGE_COPY_NOEXEC PAGE_COPY
5683 +#endif
5684 +
5685 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
5686 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
5687 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
5688 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
5689 index 45698cd..e8e2dbc 100644
5690 --- a/arch/ia64/include/asm/spinlock.h
5691 +++ b/arch/ia64/include/asm/spinlock.h
5692 @@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
5693 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
5694
5695 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
5696 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
5697 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
5698 }
5699
5700 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
5701 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
5702 index 449c8c0..3d4b1e9 100644
5703 --- a/arch/ia64/include/asm/uaccess.h
5704 +++ b/arch/ia64/include/asm/uaccess.h
5705 @@ -70,6 +70,7 @@
5706 && ((segment).seg == KERNEL_DS.seg \
5707 || likely(REGION_OFFSET((unsigned long) (addr)) < RGN_MAP_LIMIT))); \
5708 })
5709 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
5710 #define access_ok(type, addr, size) __access_ok((addr), (size), get_fs())
5711
5712 /*
5713 @@ -240,12 +241,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
5714 static inline unsigned long
5715 __copy_to_user (void __user *to, const void *from, unsigned long count)
5716 {
5717 + if (count > INT_MAX)
5718 + return count;
5719 +
5720 + if (!__builtin_constant_p(count))
5721 + check_object_size(from, count, true);
5722 +
5723 return __copy_user(to, (__force void __user *) from, count);
5724 }
5725
5726 static inline unsigned long
5727 __copy_from_user (void *to, const void __user *from, unsigned long count)
5728 {
5729 + if (count > INT_MAX)
5730 + return count;
5731 +
5732 + if (!__builtin_constant_p(count))
5733 + check_object_size(to, count, false);
5734 +
5735 return __copy_user((__force void __user *) to, from, count);
5736 }
5737
5738 @@ -255,10 +268,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5739 ({ \
5740 void __user *__cu_to = (to); \
5741 const void *__cu_from = (from); \
5742 - long __cu_len = (n); \
5743 + unsigned long __cu_len = (n); \
5744 \
5745 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
5746 + if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
5747 + if (!__builtin_constant_p(n)) \
5748 + check_object_size(__cu_from, __cu_len, true); \
5749 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
5750 + } \
5751 __cu_len; \
5752 })
5753
5754 @@ -266,11 +282,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5755 ({ \
5756 void *__cu_to = (to); \
5757 const void __user *__cu_from = (from); \
5758 - long __cu_len = (n); \
5759 + unsigned long __cu_len = (n); \
5760 \
5761 __chk_user_ptr(__cu_from); \
5762 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
5763 + if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
5764 + if (!__builtin_constant_p(n)) \
5765 + check_object_size(__cu_to, __cu_len, false); \
5766 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
5767 + } \
5768 __cu_len; \
5769 })
5770
5771 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
5772 index 24603be..948052d 100644
5773 --- a/arch/ia64/kernel/module.c
5774 +++ b/arch/ia64/kernel/module.c
5775 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
5776 void
5777 module_free (struct module *mod, void *module_region)
5778 {
5779 - if (mod && mod->arch.init_unw_table &&
5780 - module_region == mod->module_init) {
5781 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
5782 unw_remove_unwind_table(mod->arch.init_unw_table);
5783 mod->arch.init_unw_table = NULL;
5784 }
5785 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
5786 }
5787
5788 static inline int
5789 +in_init_rx (const struct module *mod, uint64_t addr)
5790 +{
5791 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
5792 +}
5793 +
5794 +static inline int
5795 +in_init_rw (const struct module *mod, uint64_t addr)
5796 +{
5797 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
5798 +}
5799 +
5800 +static inline int
5801 in_init (const struct module *mod, uint64_t addr)
5802 {
5803 - return addr - (uint64_t) mod->module_init < mod->init_size;
5804 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
5805 +}
5806 +
5807 +static inline int
5808 +in_core_rx (const struct module *mod, uint64_t addr)
5809 +{
5810 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
5811 +}
5812 +
5813 +static inline int
5814 +in_core_rw (const struct module *mod, uint64_t addr)
5815 +{
5816 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
5817 }
5818
5819 static inline int
5820 in_core (const struct module *mod, uint64_t addr)
5821 {
5822 - return addr - (uint64_t) mod->module_core < mod->core_size;
5823 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
5824 }
5825
5826 static inline int
5827 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
5828 break;
5829
5830 case RV_BDREL:
5831 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
5832 + if (in_init_rx(mod, val))
5833 + val -= (uint64_t) mod->module_init_rx;
5834 + else if (in_init_rw(mod, val))
5835 + val -= (uint64_t) mod->module_init_rw;
5836 + else if (in_core_rx(mod, val))
5837 + val -= (uint64_t) mod->module_core_rx;
5838 + else if (in_core_rw(mod, val))
5839 + val -= (uint64_t) mod->module_core_rw;
5840 break;
5841
5842 case RV_LTV:
5843 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
5844 * addresses have been selected...
5845 */
5846 uint64_t gp;
5847 - if (mod->core_size > MAX_LTOFF)
5848 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
5849 /*
5850 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
5851 * at the end of the module.
5852 */
5853 - gp = mod->core_size - MAX_LTOFF / 2;
5854 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
5855 else
5856 - gp = mod->core_size / 2;
5857 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
5858 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
5859 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
5860 mod->arch.gp = gp;
5861 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
5862 }
5863 diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
5864 index c39c3cd..3c77738 100644
5865 --- a/arch/ia64/kernel/palinfo.c
5866 +++ b/arch/ia64/kernel/palinfo.c
5867 @@ -980,7 +980,7 @@ static int palinfo_cpu_callback(struct notifier_block *nfb,
5868 return NOTIFY_OK;
5869 }
5870
5871 -static struct notifier_block __refdata palinfo_cpu_notifier =
5872 +static struct notifier_block palinfo_cpu_notifier =
5873 {
5874 .notifier_call = palinfo_cpu_callback,
5875 .priority = 0,
5876 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
5877 index 41e33f8..65180b2a 100644
5878 --- a/arch/ia64/kernel/sys_ia64.c
5879 +++ b/arch/ia64/kernel/sys_ia64.c
5880 @@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5881 unsigned long align_mask = 0;
5882 struct mm_struct *mm = current->mm;
5883 struct vm_unmapped_area_info info;
5884 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5885
5886 if (len > RGN_MAP_LIMIT)
5887 return -ENOMEM;
5888 @@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5889 if (REGION_NUMBER(addr) == RGN_HPAGE)
5890 addr = 0;
5891 #endif
5892 +
5893 +#ifdef CONFIG_PAX_RANDMMAP
5894 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5895 + addr = mm->free_area_cache;
5896 + else
5897 +#endif
5898 +
5899 if (!addr)
5900 addr = TASK_UNMAPPED_BASE;
5901
5902 @@ -61,6 +69,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5903 info.high_limit = TASK_SIZE;
5904 info.align_mask = align_mask;
5905 info.align_offset = 0;
5906 + info.threadstack_offset = offset;
5907 return vm_unmapped_area(&info);
5908 }
5909
5910 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5911 index 84f8a52..7c76178 100644
5912 --- a/arch/ia64/kernel/vmlinux.lds.S
5913 +++ b/arch/ia64/kernel/vmlinux.lds.S
5914 @@ -192,7 +192,7 @@ SECTIONS {
5915 /* Per-cpu data: */
5916 . = ALIGN(PERCPU_PAGE_SIZE);
5917 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5918 - __phys_per_cpu_start = __per_cpu_load;
5919 + __phys_per_cpu_start = per_cpu_load;
5920 /*
5921 * ensure percpu data fits
5922 * into percpu page size
5923 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5924 index 7225dad..2a7c8256 100644
5925 --- a/arch/ia64/mm/fault.c
5926 +++ b/arch/ia64/mm/fault.c
5927 @@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5928 return pte_present(pte);
5929 }
5930
5931 +#ifdef CONFIG_PAX_PAGEEXEC
5932 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5933 +{
5934 + unsigned long i;
5935 +
5936 + printk(KERN_ERR "PAX: bytes at PC: ");
5937 + for (i = 0; i < 8; i++) {
5938 + unsigned int c;
5939 + if (get_user(c, (unsigned int *)pc+i))
5940 + printk(KERN_CONT "???????? ");
5941 + else
5942 + printk(KERN_CONT "%08x ", c);
5943 + }
5944 + printk("\n");
5945 +}
5946 +#endif
5947 +
5948 # define VM_READ_BIT 0
5949 # define VM_WRITE_BIT 1
5950 # define VM_EXEC_BIT 2
5951 @@ -151,8 +168,21 @@ retry:
5952 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5953 goto bad_area;
5954
5955 - if ((vma->vm_flags & mask) != mask)
5956 + if ((vma->vm_flags & mask) != mask) {
5957 +
5958 +#ifdef CONFIG_PAX_PAGEEXEC
5959 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5960 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5961 + goto bad_area;
5962 +
5963 + up_read(&mm->mmap_sem);
5964 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5965 + do_group_exit(SIGKILL);
5966 + }
5967 +#endif
5968 +
5969 goto bad_area;
5970 + }
5971
5972 /*
5973 * If for any reason at all we couldn't handle the fault, make
5974 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5975 index 76069c1..c2aa816 100644
5976 --- a/arch/ia64/mm/hugetlbpage.c
5977 +++ b/arch/ia64/mm/hugetlbpage.c
5978 @@ -149,6 +149,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5979 unsigned long pgoff, unsigned long flags)
5980 {
5981 struct vm_unmapped_area_info info;
5982 + unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5983
5984 if (len > RGN_MAP_LIMIT)
5985 return -ENOMEM;
5986 @@ -172,6 +173,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5987 info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
5988 info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
5989 info.align_offset = 0;
5990 + info.threadstack_offset = offset;
5991 return vm_unmapped_area(&info);
5992 }
5993
5994 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5995 index 25c3502..560dae7 100644
5996 --- a/arch/ia64/mm/init.c
5997 +++ b/arch/ia64/mm/init.c
5998 @@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5999 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
6000 vma->vm_end = vma->vm_start + PAGE_SIZE;
6001 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
6002 +
6003 +#ifdef CONFIG_PAX_PAGEEXEC
6004 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
6005 + vma->vm_flags &= ~VM_EXEC;
6006 +
6007 +#ifdef CONFIG_PAX_MPROTECT
6008 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
6009 + vma->vm_flags &= ~VM_MAYEXEC;
6010 +#endif
6011 +
6012 + }
6013 +#endif
6014 +
6015 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6016 down_write(&current->mm->mmap_sem);
6017 if (insert_vm_struct(current->mm, vma)) {
6018 diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
6019 index 40b3ee9..8c2c112 100644
6020 --- a/arch/m32r/include/asm/cache.h
6021 +++ b/arch/m32r/include/asm/cache.h
6022 @@ -1,8 +1,10 @@
6023 #ifndef _ASM_M32R_CACHE_H
6024 #define _ASM_M32R_CACHE_H
6025
6026 +#include <linux/const.h>
6027 +
6028 /* L1 cache line size */
6029 #define L1_CACHE_SHIFT 4
6030 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6031 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6032
6033 #endif /* _ASM_M32R_CACHE_H */
6034 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
6035 index 82abd15..d95ae5d 100644
6036 --- a/arch/m32r/lib/usercopy.c
6037 +++ b/arch/m32r/lib/usercopy.c
6038 @@ -14,6 +14,9 @@
6039 unsigned long
6040 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
6041 {
6042 + if ((long)n < 0)
6043 + return n;
6044 +
6045 prefetch(from);
6046 if (access_ok(VERIFY_WRITE, to, n))
6047 __copy_user(to,from,n);
6048 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
6049 unsigned long
6050 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
6051 {
6052 + if ((long)n < 0)
6053 + return n;
6054 +
6055 prefetchw(to);
6056 if (access_ok(VERIFY_READ, from, n))
6057 __copy_user_zeroing(to,from,n);
6058 diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
6059 index 0395c51..5f26031 100644
6060 --- a/arch/m68k/include/asm/cache.h
6061 +++ b/arch/m68k/include/asm/cache.h
6062 @@ -4,9 +4,11 @@
6063 #ifndef __ARCH_M68K_CACHE_H
6064 #define __ARCH_M68K_CACHE_H
6065
6066 +#include <linux/const.h>
6067 +
6068 /* bytes per L1 cache line */
6069 #define L1_CACHE_SHIFT 4
6070 -#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
6071 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6072
6073 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
6074
6075 diff --git a/arch/metag/include/asm/barrier.h b/arch/metag/include/asm/barrier.h
6076 index c7591e8..ecef036 100644
6077 --- a/arch/metag/include/asm/barrier.h
6078 +++ b/arch/metag/include/asm/barrier.h
6079 @@ -89,7 +89,7 @@ static inline void fence(void)
6080 do { \
6081 compiletime_assert_atomic_type(*p); \
6082 smp_mb(); \
6083 - ACCESS_ONCE(*p) = (v); \
6084 + ACCESS_ONCE_RW(*p) = (v); \
6085 } while (0)
6086
6087 #define smp_load_acquire(p) \
6088 diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
6089 index 3c52fa6..11b2ad8 100644
6090 --- a/arch/metag/mm/hugetlbpage.c
6091 +++ b/arch/metag/mm/hugetlbpage.c
6092 @@ -200,6 +200,7 @@ hugetlb_get_unmapped_area_new_pmd(unsigned long len)
6093 info.high_limit = TASK_SIZE;
6094 info.align_mask = PAGE_MASK & HUGEPT_MASK;
6095 info.align_offset = 0;
6096 + info.threadstack_offset = 0;
6097 return vm_unmapped_area(&info);
6098 }
6099
6100 diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
6101 index 4efe96a..60e8699 100644
6102 --- a/arch/microblaze/include/asm/cache.h
6103 +++ b/arch/microblaze/include/asm/cache.h
6104 @@ -13,11 +13,12 @@
6105 #ifndef _ASM_MICROBLAZE_CACHE_H
6106 #define _ASM_MICROBLAZE_CACHE_H
6107
6108 +#include <linux/const.h>
6109 #include <asm/registers.h>
6110
6111 #define L1_CACHE_SHIFT 5
6112 /* word-granular cache in microblaze */
6113 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6114 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6115
6116 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6117
6118 diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
6119 index 4e238e6..7c9ed92 100644
6120 --- a/arch/mips/Kconfig
6121 +++ b/arch/mips/Kconfig
6122 @@ -2392,6 +2392,7 @@ source "kernel/Kconfig.preempt"
6123
6124 config KEXEC
6125 bool "Kexec system call"
6126 + depends on !GRKERNSEC_KMEM
6127 help
6128 kexec is a system call that implements the ability to shutdown your
6129 current kernel, and to start another kernel. It is like a reboot
6130 diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
6131 index 02f2444..506969c 100644
6132 --- a/arch/mips/cavium-octeon/dma-octeon.c
6133 +++ b/arch/mips/cavium-octeon/dma-octeon.c
6134 @@ -199,7 +199,7 @@ static void octeon_dma_free_coherent(struct device *dev, size_t size,
6135 if (dma_release_from_coherent(dev, order, vaddr))
6136 return;
6137
6138 - swiotlb_free_coherent(dev, size, vaddr, dma_handle);
6139 + swiotlb_free_coherent(dev, size, vaddr, dma_handle, attrs);
6140 }
6141
6142 static dma_addr_t octeon_unity_phys_to_dma(struct device *dev, phys_addr_t paddr)
6143 diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
6144 index 37b2bef..02122b8 100644
6145 --- a/arch/mips/include/asm/atomic.h
6146 +++ b/arch/mips/include/asm/atomic.h
6147 @@ -21,15 +21,39 @@
6148 #include <asm/cmpxchg.h>
6149 #include <asm/war.h>
6150
6151 +#ifdef CONFIG_GENERIC_ATOMIC64
6152 +#include <asm-generic/atomic64.h>
6153 +#endif
6154 +
6155 #define ATOMIC_INIT(i) { (i) }
6156
6157 +#ifdef CONFIG_64BIT
6158 +#define _ASM_EXTABLE(from, to) \
6159 +" .section __ex_table,\"a\"\n" \
6160 +" .dword " #from ", " #to"\n" \
6161 +" .previous\n"
6162 +#else
6163 +#define _ASM_EXTABLE(from, to) \
6164 +" .section __ex_table,\"a\"\n" \
6165 +" .word " #from ", " #to"\n" \
6166 +" .previous\n"
6167 +#endif
6168 +
6169 /*
6170 * atomic_read - read atomic variable
6171 * @v: pointer of type atomic_t
6172 *
6173 * Atomically reads the value of @v.
6174 */
6175 -#define atomic_read(v) (*(volatile int *)&(v)->counter)
6176 +static inline int atomic_read(const atomic_t *v)
6177 +{
6178 + return (*(volatile const int *) &v->counter);
6179 +}
6180 +
6181 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
6182 +{
6183 + return (*(volatile const int *) &v->counter);
6184 +}
6185
6186 /*
6187 * atomic_set - set atomic variable
6188 @@ -38,7 +62,15 @@
6189 *
6190 * Atomically sets the value of @v to @i.
6191 */
6192 -#define atomic_set(v, i) ((v)->counter = (i))
6193 +static inline void atomic_set(atomic_t *v, int i)
6194 +{
6195 + v->counter = i;
6196 +}
6197 +
6198 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
6199 +{
6200 + v->counter = i;
6201 +}
6202
6203 /*
6204 * atomic_add - add integer to atomic variable
6205 @@ -47,7 +79,67 @@
6206 *
6207 * Atomically adds @i to @v.
6208 */
6209 -static __inline__ void atomic_add(int i, atomic_t * v)
6210 +static __inline__ void atomic_add(int i, atomic_t *v)
6211 +{
6212 + int temp;
6213 +
6214 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6215 + __asm__ __volatile__(
6216 + " .set mips3 \n"
6217 + "1: ll %0, %1 # atomic_add \n"
6218 +#ifdef CONFIG_PAX_REFCOUNT
6219 + /* Exception on overflow. */
6220 + "2: add %0, %2 \n"
6221 +#else
6222 + " addu %0, %2 \n"
6223 +#endif
6224 + " sc %0, %1 \n"
6225 + " beqzl %0, 1b \n"
6226 +#ifdef CONFIG_PAX_REFCOUNT
6227 + "3: \n"
6228 + _ASM_EXTABLE(2b, 3b)
6229 +#endif
6230 + " .set mips0 \n"
6231 + : "=&r" (temp), "+m" (v->counter)
6232 + : "Ir" (i));
6233 + } else if (kernel_uses_llsc) {
6234 + __asm__ __volatile__(
6235 + " .set mips3 \n"
6236 + "1: ll %0, %1 # atomic_add \n"
6237 +#ifdef CONFIG_PAX_REFCOUNT
6238 + /* Exception on overflow. */
6239 + "2: add %0, %2 \n"
6240 +#else
6241 + " addu %0, %2 \n"
6242 +#endif
6243 + " sc %0, %1 \n"
6244 + " beqz %0, 1b \n"
6245 +#ifdef CONFIG_PAX_REFCOUNT
6246 + "3: \n"
6247 + _ASM_EXTABLE(2b, 3b)
6248 +#endif
6249 + " .set mips0 \n"
6250 + : "=&r" (temp), "+m" (v->counter)
6251 + : "Ir" (i));
6252 + } else {
6253 + unsigned long flags;
6254 +
6255 + raw_local_irq_save(flags);
6256 + __asm__ __volatile__(
6257 +#ifdef CONFIG_PAX_REFCOUNT
6258 + /* Exception on overflow. */
6259 + "1: add %0, %1 \n"
6260 + "2: \n"
6261 + _ASM_EXTABLE(1b, 2b)
6262 +#else
6263 + " addu %0, %1 \n"
6264 +#endif
6265 + : "+r" (v->counter) : "Ir" (i));
6266 + raw_local_irq_restore(flags);
6267 + }
6268 +}
6269 +
6270 +static __inline__ void atomic_add_unchecked(int i, atomic_unchecked_t *v)
6271 {
6272 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6273 int temp;
6274 @@ -90,7 +182,67 @@ static __inline__ void atomic_add(int i, atomic_t * v)
6275 *
6276 * Atomically subtracts @i from @v.
6277 */
6278 -static __inline__ void atomic_sub(int i, atomic_t * v)
6279 +static __inline__ void atomic_sub(int i, atomic_t *v)
6280 +{
6281 + int temp;
6282 +
6283 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6284 + __asm__ __volatile__(
6285 + " .set mips3 \n"
6286 + "1: ll %0, %1 # atomic64_sub \n"
6287 +#ifdef CONFIG_PAX_REFCOUNT
6288 + /* Exception on overflow. */
6289 + "2: sub %0, %2 \n"
6290 +#else
6291 + " subu %0, %2 \n"
6292 +#endif
6293 + " sc %0, %1 \n"
6294 + " beqzl %0, 1b \n"
6295 +#ifdef CONFIG_PAX_REFCOUNT
6296 + "3: \n"
6297 + _ASM_EXTABLE(2b, 3b)
6298 +#endif
6299 + " .set mips0 \n"
6300 + : "=&r" (temp), "+m" (v->counter)
6301 + : "Ir" (i));
6302 + } else if (kernel_uses_llsc) {
6303 + __asm__ __volatile__(
6304 + " .set mips3 \n"
6305 + "1: ll %0, %1 # atomic64_sub \n"
6306 +#ifdef CONFIG_PAX_REFCOUNT
6307 + /* Exception on overflow. */
6308 + "2: sub %0, %2 \n"
6309 +#else
6310 + " subu %0, %2 \n"
6311 +#endif
6312 + " sc %0, %1 \n"
6313 + " beqz %0, 1b \n"
6314 +#ifdef CONFIG_PAX_REFCOUNT
6315 + "3: \n"
6316 + _ASM_EXTABLE(2b, 3b)
6317 +#endif
6318 + " .set mips0 \n"
6319 + : "=&r" (temp), "+m" (v->counter)
6320 + : "Ir" (i));
6321 + } else {
6322 + unsigned long flags;
6323 +
6324 + raw_local_irq_save(flags);
6325 + __asm__ __volatile__(
6326 +#ifdef CONFIG_PAX_REFCOUNT
6327 + /* Exception on overflow. */
6328 + "1: sub %0, %1 \n"
6329 + "2: \n"
6330 + _ASM_EXTABLE(1b, 2b)
6331 +#else
6332 + " subu %0, %1 \n"
6333 +#endif
6334 + : "+r" (v->counter) : "Ir" (i));
6335 + raw_local_irq_restore(flags);
6336 + }
6337 +}
6338 +
6339 +static __inline__ void atomic_sub_unchecked(long i, atomic_unchecked_t *v)
6340 {
6341 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6342 int temp;
6343 @@ -129,7 +281,93 @@ static __inline__ void atomic_sub(int i, atomic_t * v)
6344 /*
6345 * Same as above, but return the result value
6346 */
6347 -static __inline__ int atomic_add_return(int i, atomic_t * v)
6348 +static __inline__ int atomic_add_return(int i, atomic_t *v)
6349 +{
6350 + int result;
6351 + int temp;
6352 +
6353 + smp_mb__before_llsc();
6354 +
6355 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6356 + __asm__ __volatile__(
6357 + " .set mips3 \n"
6358 + "1: ll %1, %2 # atomic_add_return \n"
6359 +#ifdef CONFIG_PAX_REFCOUNT
6360 + "2: add %0, %1, %3 \n"
6361 +#else
6362 + " addu %0, %1, %3 \n"
6363 +#endif
6364 + " sc %0, %2 \n"
6365 + " beqzl %0, 1b \n"
6366 +#ifdef CONFIG_PAX_REFCOUNT
6367 + " b 4f \n"
6368 + " .set noreorder \n"
6369 + "3: b 5f \n"
6370 + " move %0, %1 \n"
6371 + " .set reorder \n"
6372 + _ASM_EXTABLE(2b, 3b)
6373 +#endif
6374 + "4: addu %0, %1, %3 \n"
6375 +#ifdef CONFIG_PAX_REFCOUNT
6376 + "5: \n"
6377 +#endif
6378 + " .set mips0 \n"
6379 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6380 + : "Ir" (i));
6381 + } else if (kernel_uses_llsc) {
6382 + __asm__ __volatile__(
6383 + " .set mips3 \n"
6384 + "1: ll %1, %2 # atomic_add_return \n"
6385 +#ifdef CONFIG_PAX_REFCOUNT
6386 + "2: add %0, %1, %3 \n"
6387 +#else
6388 + " addu %0, %1, %3 \n"
6389 +#endif
6390 + " sc %0, %2 \n"
6391 + " bnez %0, 4f \n"
6392 + " b 1b \n"
6393 +#ifdef CONFIG_PAX_REFCOUNT
6394 + " .set noreorder \n"
6395 + "3: b 5f \n"
6396 + " move %0, %1 \n"
6397 + " .set reorder \n"
6398 + _ASM_EXTABLE(2b, 3b)
6399 +#endif
6400 + "4: addu %0, %1, %3 \n"
6401 +#ifdef CONFIG_PAX_REFCOUNT
6402 + "5: \n"
6403 +#endif
6404 + " .set mips0 \n"
6405 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6406 + : "Ir" (i));
6407 + } else {
6408 + unsigned long flags;
6409 +
6410 + raw_local_irq_save(flags);
6411 + __asm__ __volatile__(
6412 + " lw %0, %1 \n"
6413 +#ifdef CONFIG_PAX_REFCOUNT
6414 + /* Exception on overflow. */
6415 + "1: add %0, %2 \n"
6416 +#else
6417 + " addu %0, %2 \n"
6418 +#endif
6419 + " sw %0, %1 \n"
6420 +#ifdef CONFIG_PAX_REFCOUNT
6421 + /* Note: Dest reg is not modified on overflow */
6422 + "2: \n"
6423 + _ASM_EXTABLE(1b, 2b)
6424 +#endif
6425 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6426 + raw_local_irq_restore(flags);
6427 + }
6428 +
6429 + smp_llsc_mb();
6430 +
6431 + return result;
6432 +}
6433 +
6434 +static __inline__ int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
6435 {
6436 int result;
6437
6438 @@ -178,7 +416,93 @@ static __inline__ int atomic_add_return(int i, atomic_t * v)
6439 return result;
6440 }
6441
6442 -static __inline__ int atomic_sub_return(int i, atomic_t * v)
6443 +static __inline__ int atomic_sub_return(int i, atomic_t *v)
6444 +{
6445 + int result;
6446 + int temp;
6447 +
6448 + smp_mb__before_llsc();
6449 +
6450 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6451 + __asm__ __volatile__(
6452 + " .set mips3 \n"
6453 + "1: ll %1, %2 # atomic_sub_return \n"
6454 +#ifdef CONFIG_PAX_REFCOUNT
6455 + "2: sub %0, %1, %3 \n"
6456 +#else
6457 + " subu %0, %1, %3 \n"
6458 +#endif
6459 + " sc %0, %2 \n"
6460 + " beqzl %0, 1b \n"
6461 +#ifdef CONFIG_PAX_REFCOUNT
6462 + " b 4f \n"
6463 + " .set noreorder \n"
6464 + "3: b 5f \n"
6465 + " move %0, %1 \n"
6466 + " .set reorder \n"
6467 + _ASM_EXTABLE(2b, 3b)
6468 +#endif
6469 + "4: subu %0, %1, %3 \n"
6470 +#ifdef CONFIG_PAX_REFCOUNT
6471 + "5: \n"
6472 +#endif
6473 + " .set mips0 \n"
6474 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6475 + : "Ir" (i), "m" (v->counter)
6476 + : "memory");
6477 + } else if (kernel_uses_llsc) {
6478 + __asm__ __volatile__(
6479 + " .set mips3 \n"
6480 + "1: ll %1, %2 # atomic_sub_return \n"
6481 +#ifdef CONFIG_PAX_REFCOUNT
6482 + "2: sub %0, %1, %3 \n"
6483 +#else
6484 + " subu %0, %1, %3 \n"
6485 +#endif
6486 + " sc %0, %2 \n"
6487 + " bnez %0, 4f \n"
6488 + " b 1b \n"
6489 +#ifdef CONFIG_PAX_REFCOUNT
6490 + " .set noreorder \n"
6491 + "3: b 5f \n"
6492 + " move %0, %1 \n"
6493 + " .set reorder \n"
6494 + _ASM_EXTABLE(2b, 3b)
6495 +#endif
6496 + "4: subu %0, %1, %3 \n"
6497 +#ifdef CONFIG_PAX_REFCOUNT
6498 + "5: \n"
6499 +#endif
6500 + " .set mips0 \n"
6501 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6502 + : "Ir" (i));
6503 + } else {
6504 + unsigned long flags;
6505 +
6506 + raw_local_irq_save(flags);
6507 + __asm__ __volatile__(
6508 + " lw %0, %1 \n"
6509 +#ifdef CONFIG_PAX_REFCOUNT
6510 + /* Exception on overflow. */
6511 + "1: sub %0, %2 \n"
6512 +#else
6513 + " subu %0, %2 \n"
6514 +#endif
6515 + " sw %0, %1 \n"
6516 +#ifdef CONFIG_PAX_REFCOUNT
6517 + /* Note: Dest reg is not modified on overflow */
6518 + "2: \n"
6519 + _ASM_EXTABLE(1b, 2b)
6520 +#endif
6521 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6522 + raw_local_irq_restore(flags);
6523 + }
6524 +
6525 + smp_llsc_mb();
6526 +
6527 + return result;
6528 +}
6529 +static __inline__ int atomic_sub_return_unchecked(int i, atomic_unchecked_t *v)
6530 {
6531 int result;
6532
6533 @@ -238,7 +562,7 @@ static __inline__ int atomic_sub_return(int i, atomic_t * v)
6534 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6535 * The function returns the old value of @v minus @i.
6536 */
6537 -static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
6538 +static __inline__ int atomic_sub_if_positive(int i, atomic_t *v)
6539 {
6540 int result;
6541
6542 @@ -295,8 +619,26 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
6543 return result;
6544 }
6545
6546 -#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
6547 -#define atomic_xchg(v, new) (xchg(&((v)->counter), (new)))
6548 +static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
6549 +{
6550 + return cmpxchg(&v->counter, old, new);
6551 +}
6552 +
6553 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old,
6554 + int new)
6555 +{
6556 + return cmpxchg(&(v->counter), old, new);
6557 +}
6558 +
6559 +static inline int atomic_xchg(atomic_t *v, int new)
6560 +{
6561 + return xchg(&v->counter, new);
6562 +}
6563 +
6564 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
6565 +{
6566 + return xchg(&(v->counter), new);
6567 +}
6568
6569 /**
6570 * __atomic_add_unless - add unless the number is a given value
6571 @@ -324,6 +666,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6572
6573 #define atomic_dec_return(v) atomic_sub_return(1, (v))
6574 #define atomic_inc_return(v) atomic_add_return(1, (v))
6575 +static __inline__ int atomic_inc_return_unchecked(atomic_unchecked_t *v)
6576 +{
6577 + return atomic_add_return_unchecked(1, v);
6578 +}
6579
6580 /*
6581 * atomic_sub_and_test - subtract value from variable and test result
6582 @@ -345,6 +691,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6583 * other cases.
6584 */
6585 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
6586 +static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
6587 +{
6588 + return atomic_add_return_unchecked(1, v) == 0;
6589 +}
6590
6591 /*
6592 * atomic_dec_and_test - decrement by 1 and test
6593 @@ -369,6 +719,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6594 * Atomically increments @v by 1.
6595 */
6596 #define atomic_inc(v) atomic_add(1, (v))
6597 +static __inline__ void atomic_inc_unchecked(atomic_unchecked_t *v)
6598 +{
6599 + atomic_add_unchecked(1, v);
6600 +}
6601
6602 /*
6603 * atomic_dec - decrement and test
6604 @@ -377,6 +731,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6605 * Atomically decrements @v by 1.
6606 */
6607 #define atomic_dec(v) atomic_sub(1, (v))
6608 +static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
6609 +{
6610 + atomic_sub_unchecked(1, v);
6611 +}
6612
6613 /*
6614 * atomic_add_negative - add and test if negative
6615 @@ -398,14 +756,30 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6616 * @v: pointer of type atomic64_t
6617 *
6618 */
6619 -#define atomic64_read(v) (*(volatile long *)&(v)->counter)
6620 +static inline long atomic64_read(const atomic64_t *v)
6621 +{
6622 + return (*(volatile const long *) &v->counter);
6623 +}
6624 +
6625 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
6626 +{
6627 + return (*(volatile const long *) &v->counter);
6628 +}
6629
6630 /*
6631 * atomic64_set - set atomic variable
6632 * @v: pointer of type atomic64_t
6633 * @i: required value
6634 */
6635 -#define atomic64_set(v, i) ((v)->counter = (i))
6636 +static inline void atomic64_set(atomic64_t *v, long i)
6637 +{
6638 + v->counter = i;
6639 +}
6640 +
6641 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
6642 +{
6643 + v->counter = i;
6644 +}
6645
6646 /*
6647 * atomic64_add - add integer to atomic variable
6648 @@ -414,7 +788,66 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6649 *
6650 * Atomically adds @i to @v.
6651 */
6652 -static __inline__ void atomic64_add(long i, atomic64_t * v)
6653 +static __inline__ void atomic64_add(long i, atomic64_t *v)
6654 +{
6655 + long temp;
6656 +
6657 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6658 + __asm__ __volatile__(
6659 + " .set mips3 \n"
6660 + "1: lld %0, %1 # atomic64_add \n"
6661 +#ifdef CONFIG_PAX_REFCOUNT
6662 + /* Exception on overflow. */
6663 + "2: dadd %0, %2 \n"
6664 +#else
6665 + " daddu %0, %2 \n"
6666 +#endif
6667 + " scd %0, %1 \n"
6668 + " beqzl %0, 1b \n"
6669 +#ifdef CONFIG_PAX_REFCOUNT
6670 + "3: \n"
6671 + _ASM_EXTABLE(2b, 3b)
6672 +#endif
6673 + " .set mips0 \n"
6674 + : "=&r" (temp), "+m" (v->counter)
6675 + : "Ir" (i));
6676 + } else if (kernel_uses_llsc) {
6677 + __asm__ __volatile__(
6678 + " .set mips3 \n"
6679 + "1: lld %0, %1 # atomic64_add \n"
6680 +#ifdef CONFIG_PAX_REFCOUNT
6681 + /* Exception on overflow. */
6682 + "2: dadd %0, %2 \n"
6683 +#else
6684 + " daddu %0, %2 \n"
6685 +#endif
6686 + " scd %0, %1 \n"
6687 + " beqz %0, 1b \n"
6688 +#ifdef CONFIG_PAX_REFCOUNT
6689 + "3: \n"
6690 + _ASM_EXTABLE(2b, 3b)
6691 +#endif
6692 + " .set mips0 \n"
6693 + : "=&r" (temp), "+m" (v->counter)
6694 + : "Ir" (i));
6695 + } else {
6696 + unsigned long flags;
6697 +
6698 + raw_local_irq_save(flags);
6699 + __asm__ __volatile__(
6700 +#ifdef CONFIG_PAX_REFCOUNT
6701 + /* Exception on overflow. */
6702 + "1: dadd %0, %1 \n"
6703 + "2: \n"
6704 + _ASM_EXTABLE(1b, 2b)
6705 +#else
6706 + " daddu %0, %1 \n"
6707 +#endif
6708 + : "+r" (v->counter) : "Ir" (i));
6709 + raw_local_irq_restore(flags);
6710 + }
6711 +}
6712 +static __inline__ void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
6713 {
6714 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6715 long temp;
6716 @@ -457,7 +890,67 @@ static __inline__ void atomic64_add(long i, atomic64_t * v)
6717 *
6718 * Atomically subtracts @i from @v.
6719 */
6720 -static __inline__ void atomic64_sub(long i, atomic64_t * v)
6721 +static __inline__ void atomic64_sub(long i, atomic64_t *v)
6722 +{
6723 + long temp;
6724 +
6725 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6726 + __asm__ __volatile__(
6727 + " .set mips3 \n"
6728 + "1: lld %0, %1 # atomic64_sub \n"
6729 +#ifdef CONFIG_PAX_REFCOUNT
6730 + /* Exception on overflow. */
6731 + "2: dsub %0, %2 \n"
6732 +#else
6733 + " dsubu %0, %2 \n"
6734 +#endif
6735 + " scd %0, %1 \n"
6736 + " beqzl %0, 1b \n"
6737 +#ifdef CONFIG_PAX_REFCOUNT
6738 + "3: \n"
6739 + _ASM_EXTABLE(2b, 3b)
6740 +#endif
6741 + " .set mips0 \n"
6742 + : "=&r" (temp), "+m" (v->counter)
6743 + : "Ir" (i));
6744 + } else if (kernel_uses_llsc) {
6745 + __asm__ __volatile__(
6746 + " .set mips3 \n"
6747 + "1: lld %0, %1 # atomic64_sub \n"
6748 +#ifdef CONFIG_PAX_REFCOUNT
6749 + /* Exception on overflow. */
6750 + "2: dsub %0, %2 \n"
6751 +#else
6752 + " dsubu %0, %2 \n"
6753 +#endif
6754 + " scd %0, %1 \n"
6755 + " beqz %0, 1b \n"
6756 +#ifdef CONFIG_PAX_REFCOUNT
6757 + "3: \n"
6758 + _ASM_EXTABLE(2b, 3b)
6759 +#endif
6760 + " .set mips0 \n"
6761 + : "=&r" (temp), "+m" (v->counter)
6762 + : "Ir" (i));
6763 + } else {
6764 + unsigned long flags;
6765 +
6766 + raw_local_irq_save(flags);
6767 + __asm__ __volatile__(
6768 +#ifdef CONFIG_PAX_REFCOUNT
6769 + /* Exception on overflow. */
6770 + "1: dsub %0, %1 \n"
6771 + "2: \n"
6772 + _ASM_EXTABLE(1b, 2b)
6773 +#else
6774 + " dsubu %0, %1 \n"
6775 +#endif
6776 + : "+r" (v->counter) : "Ir" (i));
6777 + raw_local_irq_restore(flags);
6778 + }
6779 +}
6780 +
6781 +static __inline__ void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
6782 {
6783 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6784 long temp;
6785 @@ -496,7 +989,93 @@ static __inline__ void atomic64_sub(long i, atomic64_t * v)
6786 /*
6787 * Same as above, but return the result value
6788 */
6789 -static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6790 +static __inline__ long atomic64_add_return(long i, atomic64_t *v)
6791 +{
6792 + long result;
6793 + long temp;
6794 +
6795 + smp_mb__before_llsc();
6796 +
6797 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6798 + __asm__ __volatile__(
6799 + " .set mips3 \n"
6800 + "1: lld %1, %2 # atomic64_add_return \n"
6801 +#ifdef CONFIG_PAX_REFCOUNT
6802 + "2: dadd %0, %1, %3 \n"
6803 +#else
6804 + " daddu %0, %1, %3 \n"
6805 +#endif
6806 + " scd %0, %2 \n"
6807 + " beqzl %0, 1b \n"
6808 +#ifdef CONFIG_PAX_REFCOUNT
6809 + " b 4f \n"
6810 + " .set noreorder \n"
6811 + "3: b 5f \n"
6812 + " move %0, %1 \n"
6813 + " .set reorder \n"
6814 + _ASM_EXTABLE(2b, 3b)
6815 +#endif
6816 + "4: daddu %0, %1, %3 \n"
6817 +#ifdef CONFIG_PAX_REFCOUNT
6818 + "5: \n"
6819 +#endif
6820 + " .set mips0 \n"
6821 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6822 + : "Ir" (i));
6823 + } else if (kernel_uses_llsc) {
6824 + __asm__ __volatile__(
6825 + " .set mips3 \n"
6826 + "1: lld %1, %2 # atomic64_add_return \n"
6827 +#ifdef CONFIG_PAX_REFCOUNT
6828 + "2: dadd %0, %1, %3 \n"
6829 +#else
6830 + " daddu %0, %1, %3 \n"
6831 +#endif
6832 + " scd %0, %2 \n"
6833 + " bnez %0, 4f \n"
6834 + " b 1b \n"
6835 +#ifdef CONFIG_PAX_REFCOUNT
6836 + " .set noreorder \n"
6837 + "3: b 5f \n"
6838 + " move %0, %1 \n"
6839 + " .set reorder \n"
6840 + _ASM_EXTABLE(2b, 3b)
6841 +#endif
6842 + "4: daddu %0, %1, %3 \n"
6843 +#ifdef CONFIG_PAX_REFCOUNT
6844 + "5: \n"
6845 +#endif
6846 + " .set mips0 \n"
6847 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6848 + : "Ir" (i), "m" (v->counter)
6849 + : "memory");
6850 + } else {
6851 + unsigned long flags;
6852 +
6853 + raw_local_irq_save(flags);
6854 + __asm__ __volatile__(
6855 + " ld %0, %1 \n"
6856 +#ifdef CONFIG_PAX_REFCOUNT
6857 + /* Exception on overflow. */
6858 + "1: dadd %0, %2 \n"
6859 +#else
6860 + " daddu %0, %2 \n"
6861 +#endif
6862 + " sd %0, %1 \n"
6863 +#ifdef CONFIG_PAX_REFCOUNT
6864 + /* Note: Dest reg is not modified on overflow */
6865 + "2: \n"
6866 + _ASM_EXTABLE(1b, 2b)
6867 +#endif
6868 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6869 + raw_local_irq_restore(flags);
6870 + }
6871 +
6872 + smp_llsc_mb();
6873 +
6874 + return result;
6875 +}
6876 +static __inline__ long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
6877 {
6878 long result;
6879
6880 @@ -546,7 +1125,97 @@ static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6881 return result;
6882 }
6883
6884 -static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6885 +static __inline__ long atomic64_sub_return(long i, atomic64_t *v)
6886 +{
6887 + long result;
6888 + long temp;
6889 +
6890 + smp_mb__before_llsc();
6891 +
6892 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6893 + long temp;
6894 +
6895 + __asm__ __volatile__(
6896 + " .set mips3 \n"
6897 + "1: lld %1, %2 # atomic64_sub_return \n"
6898 +#ifdef CONFIG_PAX_REFCOUNT
6899 + "2: dsub %0, %1, %3 \n"
6900 +#else
6901 + " dsubu %0, %1, %3 \n"
6902 +#endif
6903 + " scd %0, %2 \n"
6904 + " beqzl %0, 1b \n"
6905 +#ifdef CONFIG_PAX_REFCOUNT
6906 + " b 4f \n"
6907 + " .set noreorder \n"
6908 + "3: b 5f \n"
6909 + " move %0, %1 \n"
6910 + " .set reorder \n"
6911 + _ASM_EXTABLE(2b, 3b)
6912 +#endif
6913 + "4: dsubu %0, %1, %3 \n"
6914 +#ifdef CONFIG_PAX_REFCOUNT
6915 + "5: \n"
6916 +#endif
6917 + " .set mips0 \n"
6918 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6919 + : "Ir" (i), "m" (v->counter)
6920 + : "memory");
6921 + } else if (kernel_uses_llsc) {
6922 + __asm__ __volatile__(
6923 + " .set mips3 \n"
6924 + "1: lld %1, %2 # atomic64_sub_return \n"
6925 +#ifdef CONFIG_PAX_REFCOUNT
6926 + "2: dsub %0, %1, %3 \n"
6927 +#else
6928 + " dsubu %0, %1, %3 \n"
6929 +#endif
6930 + " scd %0, %2 \n"
6931 + " bnez %0, 4f \n"
6932 + " b 1b \n"
6933 +#ifdef CONFIG_PAX_REFCOUNT
6934 + " .set noreorder \n"
6935 + "3: b 5f \n"
6936 + " move %0, %1 \n"
6937 + " .set reorder \n"
6938 + _ASM_EXTABLE(2b, 3b)
6939 +#endif
6940 + "4: dsubu %0, %1, %3 \n"
6941 +#ifdef CONFIG_PAX_REFCOUNT
6942 + "5: \n"
6943 +#endif
6944 + " .set mips0 \n"
6945 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6946 + : "Ir" (i), "m" (v->counter)
6947 + : "memory");
6948 + } else {
6949 + unsigned long flags;
6950 +
6951 + raw_local_irq_save(flags);
6952 + __asm__ __volatile__(
6953 + " ld %0, %1 \n"
6954 +#ifdef CONFIG_PAX_REFCOUNT
6955 + /* Exception on overflow. */
6956 + "1: dsub %0, %2 \n"
6957 +#else
6958 + " dsubu %0, %2 \n"
6959 +#endif
6960 + " sd %0, %1 \n"
6961 +#ifdef CONFIG_PAX_REFCOUNT
6962 + /* Note: Dest reg is not modified on overflow */
6963 + "2: \n"
6964 + _ASM_EXTABLE(1b, 2b)
6965 +#endif
6966 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6967 + raw_local_irq_restore(flags);
6968 + }
6969 +
6970 + smp_llsc_mb();
6971 +
6972 + return result;
6973 +}
6974 +
6975 +static __inline__ long atomic64_sub_return_unchecked(long i, atomic64_unchecked_t *v)
6976 {
6977 long result;
6978
6979 @@ -605,7 +1274,7 @@ static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6980 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6981 * The function returns the old value of @v minus @i.
6982 */
6983 -static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6984 +static __inline__ long atomic64_sub_if_positive(long i, atomic64_t *v)
6985 {
6986 long result;
6987
6988 @@ -662,9 +1331,26 @@ static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6989 return result;
6990 }
6991
6992 -#define atomic64_cmpxchg(v, o, n) \
6993 - ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
6994 -#define atomic64_xchg(v, new) (xchg(&((v)->counter), (new)))
6995 +static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
6996 +{
6997 + return cmpxchg(&v->counter, old, new);
6998 +}
6999 +
7000 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old,
7001 + long new)
7002 +{
7003 + return cmpxchg(&(v->counter), old, new);
7004 +}
7005 +
7006 +static inline long atomic64_xchg(atomic64_t *v, long new)
7007 +{
7008 + return xchg(&v->counter, new);
7009 +}
7010 +
7011 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
7012 +{
7013 + return xchg(&(v->counter), new);
7014 +}
7015
7016 /**
7017 * atomic64_add_unless - add unless the number is a given value
7018 @@ -694,6 +1380,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
7019
7020 #define atomic64_dec_return(v) atomic64_sub_return(1, (v))
7021 #define atomic64_inc_return(v) atomic64_add_return(1, (v))
7022 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1, (v))
7023
7024 /*
7025 * atomic64_sub_and_test - subtract value from variable and test result
7026 @@ -715,6 +1402,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
7027 * other cases.
7028 */
7029 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
7030 +#define atomic64_inc_and_test_unchecked(v) atomic64_add_return_unchecked(1, (v)) == 0)
7031
7032 /*
7033 * atomic64_dec_and_test - decrement by 1 and test
7034 @@ -739,6 +1427,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
7035 * Atomically increments @v by 1.
7036 */
7037 #define atomic64_inc(v) atomic64_add(1, (v))
7038 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1, (v))
7039
7040 /*
7041 * atomic64_dec - decrement and test
7042 @@ -747,6 +1436,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
7043 * Atomically decrements @v by 1.
7044 */
7045 #define atomic64_dec(v) atomic64_sub(1, (v))
7046 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1, (v))
7047
7048 /*
7049 * atomic64_add_negative - add and test if negative
7050 diff --git a/arch/mips/include/asm/barrier.h b/arch/mips/include/asm/barrier.h
7051 index d0101dd..266982c 100644
7052 --- a/arch/mips/include/asm/barrier.h
7053 +++ b/arch/mips/include/asm/barrier.h
7054 @@ -184,7 +184,7 @@
7055 do { \
7056 compiletime_assert_atomic_type(*p); \
7057 smp_mb(); \
7058 - ACCESS_ONCE(*p) = (v); \
7059 + ACCESS_ONCE_RW(*p) = (v); \
7060 } while (0)
7061
7062 #define smp_load_acquire(p) \
7063 diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
7064 index b4db69f..8f3b093 100644
7065 --- a/arch/mips/include/asm/cache.h
7066 +++ b/arch/mips/include/asm/cache.h
7067 @@ -9,10 +9,11 @@
7068 #ifndef _ASM_CACHE_H
7069 #define _ASM_CACHE_H
7070
7071 +#include <linux/const.h>
7072 #include <kmalloc.h>
7073
7074 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
7075 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7076 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7077
7078 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
7079 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7080 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
7081 index d414405..6bb4ba2 100644
7082 --- a/arch/mips/include/asm/elf.h
7083 +++ b/arch/mips/include/asm/elf.h
7084 @@ -398,13 +398,16 @@ extern const char *__elf_platform;
7085 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
7086 #endif
7087
7088 +#ifdef CONFIG_PAX_ASLR
7089 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
7090 +
7091 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
7092 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
7093 +#endif
7094 +
7095 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
7096 struct linux_binprm;
7097 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
7098 int uses_interp);
7099
7100 -struct mm_struct;
7101 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
7102 -#define arch_randomize_brk arch_randomize_brk
7103 -
7104 #endif /* _ASM_ELF_H */
7105 diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
7106 index c1f6afa..38cc6e9 100644
7107 --- a/arch/mips/include/asm/exec.h
7108 +++ b/arch/mips/include/asm/exec.h
7109 @@ -12,6 +12,6 @@
7110 #ifndef _ASM_EXEC_H
7111 #define _ASM_EXEC_H
7112
7113 -extern unsigned long arch_align_stack(unsigned long sp);
7114 +#define arch_align_stack(x) ((x) & ~0xfUL)
7115
7116 #endif /* _ASM_EXEC_H */
7117 diff --git a/arch/mips/include/asm/hw_irq.h b/arch/mips/include/asm/hw_irq.h
7118 index 9e8ef59..1139d6b 100644
7119 --- a/arch/mips/include/asm/hw_irq.h
7120 +++ b/arch/mips/include/asm/hw_irq.h
7121 @@ -10,7 +10,7 @@
7122
7123 #include <linux/atomic.h>
7124
7125 -extern atomic_t irq_err_count;
7126 +extern atomic_unchecked_t irq_err_count;
7127
7128 /*
7129 * interrupt-retrigger: NOP for now. This may not be appropriate for all
7130 diff --git a/arch/mips/include/asm/local.h b/arch/mips/include/asm/local.h
7131 index 46dfc3c..a16b13a 100644
7132 --- a/arch/mips/include/asm/local.h
7133 +++ b/arch/mips/include/asm/local.h
7134 @@ -12,15 +12,25 @@ typedef struct
7135 atomic_long_t a;
7136 } local_t;
7137
7138 +typedef struct {
7139 + atomic_long_unchecked_t a;
7140 +} local_unchecked_t;
7141 +
7142 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
7143
7144 #define local_read(l) atomic_long_read(&(l)->a)
7145 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
7146 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
7147 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
7148
7149 #define local_add(i, l) atomic_long_add((i), (&(l)->a))
7150 +#define local_add_unchecked(i, l) atomic_long_add_unchecked((i), (&(l)->a))
7151 #define local_sub(i, l) atomic_long_sub((i), (&(l)->a))
7152 +#define local_sub_unchecked(i, l) atomic_long_sub_unchecked((i), (&(l)->a))
7153 #define local_inc(l) atomic_long_inc(&(l)->a)
7154 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
7155 #define local_dec(l) atomic_long_dec(&(l)->a)
7156 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
7157
7158 /*
7159 * Same as above, but return the result value
7160 @@ -70,6 +80,51 @@ static __inline__ long local_add_return(long i, local_t * l)
7161 return result;
7162 }
7163
7164 +static __inline__ long local_add_return_unchecked(long i, local_unchecked_t * l)
7165 +{
7166 + unsigned long result;
7167 +
7168 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
7169 + unsigned long temp;
7170 +
7171 + __asm__ __volatile__(
7172 + " .set mips3 \n"
7173 + "1:" __LL "%1, %2 # local_add_return \n"
7174 + " addu %0, %1, %3 \n"
7175 + __SC "%0, %2 \n"
7176 + " beqzl %0, 1b \n"
7177 + " addu %0, %1, %3 \n"
7178 + " .set mips0 \n"
7179 + : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
7180 + : "Ir" (i), "m" (l->a.counter)
7181 + : "memory");
7182 + } else if (kernel_uses_llsc) {
7183 + unsigned long temp;
7184 +
7185 + __asm__ __volatile__(
7186 + " .set mips3 \n"
7187 + "1:" __LL "%1, %2 # local_add_return \n"
7188 + " addu %0, %1, %3 \n"
7189 + __SC "%0, %2 \n"
7190 + " beqz %0, 1b \n"
7191 + " addu %0, %1, %3 \n"
7192 + " .set mips0 \n"
7193 + : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
7194 + : "Ir" (i), "m" (l->a.counter)
7195 + : "memory");
7196 + } else {
7197 + unsigned long flags;
7198 +
7199 + local_irq_save(flags);
7200 + result = l->a.counter;
7201 + result += i;
7202 + l->a.counter = result;
7203 + local_irq_restore(flags);
7204 + }
7205 +
7206 + return result;
7207 +}
7208 +
7209 static __inline__ long local_sub_return(long i, local_t * l)
7210 {
7211 unsigned long result;
7212 @@ -117,6 +172,8 @@ static __inline__ long local_sub_return(long i, local_t * l)
7213
7214 #define local_cmpxchg(l, o, n) \
7215 ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
7216 +#define local_cmpxchg_unchecked(l, o, n) \
7217 + ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
7218 #define local_xchg(l, n) (atomic_long_xchg((&(l)->a), (n)))
7219
7220 /**
7221 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
7222 index 5699ec3..95def83 100644
7223 --- a/arch/mips/include/asm/page.h
7224 +++ b/arch/mips/include/asm/page.h
7225 @@ -120,7 +120,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
7226 #ifdef CONFIG_CPU_MIPS32
7227 typedef struct { unsigned long pte_low, pte_high; } pte_t;
7228 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
7229 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
7230 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
7231 #else
7232 typedef struct { unsigned long long pte; } pte_t;
7233 #define pte_val(x) ((x).pte)
7234 diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
7235 index b336037..5b874cc 100644
7236 --- a/arch/mips/include/asm/pgalloc.h
7237 +++ b/arch/mips/include/asm/pgalloc.h
7238 @@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
7239 {
7240 set_pud(pud, __pud((unsigned long)pmd));
7241 }
7242 +
7243 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
7244 +{
7245 + pud_populate(mm, pud, pmd);
7246 +}
7247 #endif
7248
7249 /*
7250 diff --git a/arch/mips/include/asm/pgtable.h b/arch/mips/include/asm/pgtable.h
7251 index 539ddd1..8783f9a 100644
7252 --- a/arch/mips/include/asm/pgtable.h
7253 +++ b/arch/mips/include/asm/pgtable.h
7254 @@ -20,6 +20,9 @@
7255 #include <asm/io.h>
7256 #include <asm/pgtable-bits.h>
7257
7258 +#define ktla_ktva(addr) (addr)
7259 +#define ktva_ktla(addr) (addr)
7260 +
7261 struct mm_struct;
7262 struct vm_area_struct;
7263
7264 diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
7265 index 7de8658..c109224 100644
7266 --- a/arch/mips/include/asm/thread_info.h
7267 +++ b/arch/mips/include/asm/thread_info.h
7268 @@ -105,6 +105,9 @@ static inline struct thread_info *current_thread_info(void)
7269 #define TIF_SECCOMP 4 /* secure computing */
7270 #define TIF_NOTIFY_RESUME 5 /* callback before returning to user */
7271 #define TIF_RESTORE_SIGMASK 9 /* restore signal mask in do_signal() */
7272 +/* li takes a 32bit immediate */
7273 +#define TIF_GRSEC_SETXID 10 /* update credentials on syscall entry/exit */
7274 +
7275 #define TIF_USEDFPU 16 /* FPU was used by this task this quantum (SMP) */
7276 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
7277 #define TIF_NOHZ 19 /* in adaptive nohz mode */
7278 @@ -138,14 +141,16 @@ static inline struct thread_info *current_thread_info(void)
7279 #define _TIF_USEDMSA (1<<TIF_USEDMSA)
7280 #define _TIF_MSA_CTX_LIVE (1<<TIF_MSA_CTX_LIVE)
7281 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
7282 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
7283
7284 #define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
7285 _TIF_SYSCALL_AUDIT | \
7286 - _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
7287 + _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | \
7288 + _TIF_GRSEC_SETXID)
7289
7290 /* work to do in syscall_trace_leave() */
7291 #define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
7292 - _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
7293 + _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
7294
7295 /* work to do on interrupt/exception return */
7296 #define _TIF_WORK_MASK \
7297 @@ -153,7 +158,7 @@ static inline struct thread_info *current_thread_info(void)
7298 /* work to do on any return to u-space */
7299 #define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | \
7300 _TIF_WORK_SYSCALL_EXIT | \
7301 - _TIF_SYSCALL_TRACEPOINT)
7302 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
7303
7304 /*
7305 * We stash processor id into a COP0 register to retrieve it fast
7306 diff --git a/arch/mips/include/asm/uaccess.h b/arch/mips/include/asm/uaccess.h
7307 index a109510..94ee3f6 100644
7308 --- a/arch/mips/include/asm/uaccess.h
7309 +++ b/arch/mips/include/asm/uaccess.h
7310 @@ -130,6 +130,7 @@ extern u64 __ua_limit;
7311 __ok == 0; \
7312 })
7313
7314 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
7315 #define access_ok(type, addr, size) \
7316 likely(__access_ok((addr), (size), __access_mask))
7317
7318 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
7319 index 1188e00..41cf144 100644
7320 --- a/arch/mips/kernel/binfmt_elfn32.c
7321 +++ b/arch/mips/kernel/binfmt_elfn32.c
7322 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
7323 #undef ELF_ET_DYN_BASE
7324 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
7325
7326 +#ifdef CONFIG_PAX_ASLR
7327 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
7328 +
7329 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
7330 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
7331 +#endif
7332 +
7333 #include <asm/processor.h>
7334 #include <linux/module.h>
7335 #include <linux/elfcore.h>
7336 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
7337 index 7faf5f2..f3d3cf4 100644
7338 --- a/arch/mips/kernel/binfmt_elfo32.c
7339 +++ b/arch/mips/kernel/binfmt_elfo32.c
7340 @@ -70,6 +70,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
7341 #undef ELF_ET_DYN_BASE
7342 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
7343
7344 +#ifdef CONFIG_PAX_ASLR
7345 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
7346 +
7347 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
7348 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
7349 +#endif
7350 +
7351 #include <asm/processor.h>
7352
7353 /*
7354 diff --git a/arch/mips/kernel/i8259.c b/arch/mips/kernel/i8259.c
7355 index 50b3648..c2f3cec 100644
7356 --- a/arch/mips/kernel/i8259.c
7357 +++ b/arch/mips/kernel/i8259.c
7358 @@ -201,7 +201,7 @@ spurious_8259A_irq:
7359 printk(KERN_DEBUG "spurious 8259A interrupt: IRQ%d.\n", irq);
7360 spurious_irq_mask |= irqmask;
7361 }
7362 - atomic_inc(&irq_err_count);
7363 + atomic_inc_unchecked(&irq_err_count);
7364 /*
7365 * Theoretically we do not have to handle this IRQ,
7366 * but in Linux this does not cause problems and is
7367 diff --git a/arch/mips/kernel/irq-gt641xx.c b/arch/mips/kernel/irq-gt641xx.c
7368 index 44a1f79..2bd6aa3 100644
7369 --- a/arch/mips/kernel/irq-gt641xx.c
7370 +++ b/arch/mips/kernel/irq-gt641xx.c
7371 @@ -110,7 +110,7 @@ void gt641xx_irq_dispatch(void)
7372 }
7373 }
7374
7375 - atomic_inc(&irq_err_count);
7376 + atomic_inc_unchecked(&irq_err_count);
7377 }
7378
7379 void __init gt641xx_irq_init(void)
7380 diff --git a/arch/mips/kernel/irq.c b/arch/mips/kernel/irq.c
7381 index d2bfbc2..a8eacd2 100644
7382 --- a/arch/mips/kernel/irq.c
7383 +++ b/arch/mips/kernel/irq.c
7384 @@ -76,17 +76,17 @@ void ack_bad_irq(unsigned int irq)
7385 printk("unexpected IRQ # %d\n", irq);
7386 }
7387
7388 -atomic_t irq_err_count;
7389 +atomic_unchecked_t irq_err_count;
7390
7391 int arch_show_interrupts(struct seq_file *p, int prec)
7392 {
7393 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
7394 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
7395 return 0;
7396 }
7397
7398 asmlinkage void spurious_interrupt(void)
7399 {
7400 - atomic_inc(&irq_err_count);
7401 + atomic_inc_unchecked(&irq_err_count);
7402 }
7403
7404 void __init init_IRQ(void)
7405 @@ -109,7 +109,10 @@ void __init init_IRQ(void)
7406 #endif
7407 }
7408
7409 +
7410 #ifdef DEBUG_STACKOVERFLOW
7411 +extern void gr_handle_kernel_exploit(void);
7412 +
7413 static inline void check_stack_overflow(void)
7414 {
7415 unsigned long sp;
7416 @@ -125,6 +128,7 @@ static inline void check_stack_overflow(void)
7417 printk("do_IRQ: stack overflow: %ld\n",
7418 sp - sizeof(struct thread_info));
7419 dump_stack();
7420 + gr_handle_kernel_exploit();
7421 }
7422 }
7423 #else
7424 diff --git a/arch/mips/kernel/pm-cps.c b/arch/mips/kernel/pm-cps.c
7425 index c4c2069..bde8051 100644
7426 --- a/arch/mips/kernel/pm-cps.c
7427 +++ b/arch/mips/kernel/pm-cps.c
7428 @@ -168,7 +168,7 @@ int cps_pm_enter_state(enum cps_pm_state state)
7429 nc_core_ready_count = nc_addr;
7430
7431 /* Ensure ready_count is zero-initialised before the assembly runs */
7432 - ACCESS_ONCE(*nc_core_ready_count) = 0;
7433 + ACCESS_ONCE_RW(*nc_core_ready_count) = 0;
7434 coupled_barrier(&per_cpu(pm_barrier, core), online);
7435
7436 /* Run the generated entry code */
7437 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
7438 index 0a1ec0f..d9e93b6 100644
7439 --- a/arch/mips/kernel/process.c
7440 +++ b/arch/mips/kernel/process.c
7441 @@ -572,15 +572,3 @@ unsigned long get_wchan(struct task_struct *task)
7442 out:
7443 return pc;
7444 }
7445 -
7446 -/*
7447 - * Don't forget that the stack pointer must be aligned on a 8 bytes
7448 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
7449 - */
7450 -unsigned long arch_align_stack(unsigned long sp)
7451 -{
7452 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7453 - sp -= get_random_int() & ~PAGE_MASK;
7454 -
7455 - return sp & ALMASK;
7456 -}
7457 diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
7458 index f639ccd..e4b110d 100644
7459 --- a/arch/mips/kernel/ptrace.c
7460 +++ b/arch/mips/kernel/ptrace.c
7461 @@ -630,6 +630,10 @@ long arch_ptrace(struct task_struct *child, long request,
7462 return ret;
7463 }
7464
7465 +#ifdef CONFIG_GRKERNSEC_SETXID
7466 +extern void gr_delayed_cred_worker(void);
7467 +#endif
7468 +
7469 /*
7470 * Notification of system call entry/exit
7471 * - triggered by current->work.syscall_trace
7472 @@ -646,6 +650,11 @@ asmlinkage long syscall_trace_enter(struct pt_regs *regs, long syscall)
7473 tracehook_report_syscall_entry(regs))
7474 ret = -1;
7475
7476 +#ifdef CONFIG_GRKERNSEC_SETXID
7477 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
7478 + gr_delayed_cred_worker();
7479 +#endif
7480 +
7481 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
7482 trace_sys_enter(regs, regs->regs[2]);
7483
7484 diff --git a/arch/mips/kernel/reset.c b/arch/mips/kernel/reset.c
7485 index 07fc524..b9d7f28 100644
7486 --- a/arch/mips/kernel/reset.c
7487 +++ b/arch/mips/kernel/reset.c
7488 @@ -13,6 +13,7 @@
7489 #include <linux/reboot.h>
7490
7491 #include <asm/reboot.h>
7492 +#include <asm/bug.h>
7493
7494 /*
7495 * Urgs ... Too many MIPS machines to handle this in a generic way.
7496 @@ -29,16 +30,19 @@ void machine_restart(char *command)
7497 {
7498 if (_machine_restart)
7499 _machine_restart(command);
7500 + BUG();
7501 }
7502
7503 void machine_halt(void)
7504 {
7505 if (_machine_halt)
7506 _machine_halt();
7507 + BUG();
7508 }
7509
7510 void machine_power_off(void)
7511 {
7512 if (pm_power_off)
7513 pm_power_off();
7514 + BUG();
7515 }
7516 diff --git a/arch/mips/kernel/sync-r4k.c b/arch/mips/kernel/sync-r4k.c
7517 index 2242bdd..b284048 100644
7518 --- a/arch/mips/kernel/sync-r4k.c
7519 +++ b/arch/mips/kernel/sync-r4k.c
7520 @@ -18,8 +18,8 @@
7521 #include <asm/mipsregs.h>
7522
7523 static atomic_t count_start_flag = ATOMIC_INIT(0);
7524 -static atomic_t count_count_start = ATOMIC_INIT(0);
7525 -static atomic_t count_count_stop = ATOMIC_INIT(0);
7526 +static atomic_unchecked_t count_count_start = ATOMIC_INIT(0);
7527 +static atomic_unchecked_t count_count_stop = ATOMIC_INIT(0);
7528 static atomic_t count_reference = ATOMIC_INIT(0);
7529
7530 #define COUNTON 100
7531 @@ -58,13 +58,13 @@ void synchronise_count_master(int cpu)
7532
7533 for (i = 0; i < NR_LOOPS; i++) {
7534 /* slaves loop on '!= 2' */
7535 - while (atomic_read(&count_count_start) != 1)
7536 + while (atomic_read_unchecked(&count_count_start) != 1)
7537 mb();
7538 - atomic_set(&count_count_stop, 0);
7539 + atomic_set_unchecked(&count_count_stop, 0);
7540 smp_wmb();
7541
7542 /* this lets the slaves write their count register */
7543 - atomic_inc(&count_count_start);
7544 + atomic_inc_unchecked(&count_count_start);
7545
7546 /*
7547 * Everyone initialises count in the last loop:
7548 @@ -75,11 +75,11 @@ void synchronise_count_master(int cpu)
7549 /*
7550 * Wait for all slaves to leave the synchronization point:
7551 */
7552 - while (atomic_read(&count_count_stop) != 1)
7553 + while (atomic_read_unchecked(&count_count_stop) != 1)
7554 mb();
7555 - atomic_set(&count_count_start, 0);
7556 + atomic_set_unchecked(&count_count_start, 0);
7557 smp_wmb();
7558 - atomic_inc(&count_count_stop);
7559 + atomic_inc_unchecked(&count_count_stop);
7560 }
7561 /* Arrange for an interrupt in a short while */
7562 write_c0_compare(read_c0_count() + COUNTON);
7563 @@ -112,8 +112,8 @@ void synchronise_count_slave(int cpu)
7564 initcount = atomic_read(&count_reference);
7565
7566 for (i = 0; i < NR_LOOPS; i++) {
7567 - atomic_inc(&count_count_start);
7568 - while (atomic_read(&count_count_start) != 2)
7569 + atomic_inc_unchecked(&count_count_start);
7570 + while (atomic_read_unchecked(&count_count_start) != 2)
7571 mb();
7572
7573 /*
7574 @@ -122,8 +122,8 @@ void synchronise_count_slave(int cpu)
7575 if (i == NR_LOOPS-1)
7576 write_c0_count(initcount);
7577
7578 - atomic_inc(&count_count_stop);
7579 - while (atomic_read(&count_count_stop) != 2)
7580 + atomic_inc_unchecked(&count_count_stop);
7581 + while (atomic_read_unchecked(&count_count_stop) != 2)
7582 mb();
7583 }
7584 /* Arrange for an interrupt in a short while */
7585 diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
7586 index 51706d6..ec1178c 100644
7587 --- a/arch/mips/kernel/traps.c
7588 +++ b/arch/mips/kernel/traps.c
7589 @@ -687,7 +687,18 @@ asmlinkage void do_ov(struct pt_regs *regs)
7590 siginfo_t info;
7591
7592 prev_state = exception_enter();
7593 - die_if_kernel("Integer overflow", regs);
7594 + if (unlikely(!user_mode(regs))) {
7595 +
7596 +#ifdef CONFIG_PAX_REFCOUNT
7597 + if (fixup_exception(regs)) {
7598 + pax_report_refcount_overflow(regs);
7599 + exception_exit(prev_state);
7600 + return;
7601 + }
7602 +#endif
7603 +
7604 + die("Integer overflow", regs);
7605 + }
7606
7607 info.si_code = FPE_INTOVF;
7608 info.si_signo = SIGFPE;
7609 diff --git a/arch/mips/kvm/kvm_mips.c b/arch/mips/kvm/kvm_mips.c
7610 index f3c56a1..6a2f01c 100644
7611 --- a/arch/mips/kvm/kvm_mips.c
7612 +++ b/arch/mips/kvm/kvm_mips.c
7613 @@ -841,7 +841,7 @@ long kvm_arch_vm_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg)
7614 return r;
7615 }
7616
7617 -int kvm_arch_init(void *opaque)
7618 +int kvm_arch_init(const void *opaque)
7619 {
7620 int ret;
7621
7622 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
7623 index becc42b..9e43d4b 100644
7624 --- a/arch/mips/mm/fault.c
7625 +++ b/arch/mips/mm/fault.c
7626 @@ -28,6 +28,23 @@
7627 #include <asm/highmem.h> /* For VMALLOC_END */
7628 #include <linux/kdebug.h>
7629
7630 +#ifdef CONFIG_PAX_PAGEEXEC
7631 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7632 +{
7633 + unsigned long i;
7634 +
7635 + printk(KERN_ERR "PAX: bytes at PC: ");
7636 + for (i = 0; i < 5; i++) {
7637 + unsigned int c;
7638 + if (get_user(c, (unsigned int *)pc+i))
7639 + printk(KERN_CONT "???????? ");
7640 + else
7641 + printk(KERN_CONT "%08x ", c);
7642 + }
7643 + printk("\n");
7644 +}
7645 +#endif
7646 +
7647 /*
7648 * This routine handles page faults. It determines the address,
7649 * and the problem, and then passes it off to one of the appropriate
7650 @@ -199,6 +216,14 @@ bad_area:
7651 bad_area_nosemaphore:
7652 /* User mode accesses just cause a SIGSEGV */
7653 if (user_mode(regs)) {
7654 +
7655 +#ifdef CONFIG_PAX_PAGEEXEC
7656 + if (cpu_has_rixi && (mm->pax_flags & MF_PAX_PAGEEXEC) && !write && address == instruction_pointer(regs)) {
7657 + pax_report_fault(regs, (void *)address, (void *)user_stack_pointer(regs));
7658 + do_group_exit(SIGKILL);
7659 + }
7660 +#endif
7661 +
7662 tsk->thread.cp0_badvaddr = address;
7663 tsk->thread.error_code = write;
7664 #if 0
7665 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
7666 index f1baadd..5472dca 100644
7667 --- a/arch/mips/mm/mmap.c
7668 +++ b/arch/mips/mm/mmap.c
7669 @@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7670 struct vm_area_struct *vma;
7671 unsigned long addr = addr0;
7672 int do_color_align;
7673 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7674 struct vm_unmapped_area_info info;
7675
7676 if (unlikely(len > TASK_SIZE))
7677 @@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7678 do_color_align = 1;
7679
7680 /* requesting a specific address */
7681 +
7682 +#ifdef CONFIG_PAX_RANDMMAP
7683 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
7684 +#endif
7685 +
7686 if (addr) {
7687 if (do_color_align)
7688 addr = COLOUR_ALIGN(addr, pgoff);
7689 @@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7690 addr = PAGE_ALIGN(addr);
7691
7692 vma = find_vma(mm, addr);
7693 - if (TASK_SIZE - len >= addr &&
7694 - (!vma || addr + len <= vma->vm_start))
7695 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7696 return addr;
7697 }
7698
7699 info.length = len;
7700 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
7701 info.align_offset = pgoff << PAGE_SHIFT;
7702 + info.threadstack_offset = offset;
7703
7704 if (dir == DOWN) {
7705 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
7706 @@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7707 {
7708 unsigned long random_factor = 0UL;
7709
7710 +#ifdef CONFIG_PAX_RANDMMAP
7711 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7712 +#endif
7713 +
7714 if (current->flags & PF_RANDOMIZE) {
7715 random_factor = get_random_int();
7716 random_factor = random_factor << PAGE_SHIFT;
7717 @@ -157,40 +167,25 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7718
7719 if (mmap_is_legacy()) {
7720 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
7721 +
7722 +#ifdef CONFIG_PAX_RANDMMAP
7723 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7724 + mm->mmap_base += mm->delta_mmap;
7725 +#endif
7726 +
7727 mm->get_unmapped_area = arch_get_unmapped_area;
7728 } else {
7729 mm->mmap_base = mmap_base(random_factor);
7730 +
7731 +#ifdef CONFIG_PAX_RANDMMAP
7732 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7733 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7734 +#endif
7735 +
7736 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7737 }
7738 }
7739
7740 -static inline unsigned long brk_rnd(void)
7741 -{
7742 - unsigned long rnd = get_random_int();
7743 -
7744 - rnd = rnd << PAGE_SHIFT;
7745 - /* 8MB for 32bit, 256MB for 64bit */
7746 - if (TASK_IS_32BIT_ADDR)
7747 - rnd = rnd & 0x7ffffful;
7748 - else
7749 - rnd = rnd & 0xffffffful;
7750 -
7751 - return rnd;
7752 -}
7753 -
7754 -unsigned long arch_randomize_brk(struct mm_struct *mm)
7755 -{
7756 - unsigned long base = mm->brk;
7757 - unsigned long ret;
7758 -
7759 - ret = PAGE_ALIGN(base + brk_rnd());
7760 -
7761 - if (ret < mm->brk)
7762 - return mm->brk;
7763 -
7764 - return ret;
7765 -}
7766 -
7767 int __virt_addr_valid(const volatile void *kaddr)
7768 {
7769 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
7770 diff --git a/arch/mips/pci/pci-octeon.c b/arch/mips/pci/pci-octeon.c
7771 index 59cccd9..f39ac2f 100644
7772 --- a/arch/mips/pci/pci-octeon.c
7773 +++ b/arch/mips/pci/pci-octeon.c
7774 @@ -327,8 +327,8 @@ static int octeon_write_config(struct pci_bus *bus, unsigned int devfn,
7775
7776
7777 static struct pci_ops octeon_pci_ops = {
7778 - octeon_read_config,
7779 - octeon_write_config,
7780 + .read = octeon_read_config,
7781 + .write = octeon_write_config,
7782 };
7783
7784 static struct resource octeon_pci_mem_resource = {
7785 diff --git a/arch/mips/pci/pcie-octeon.c b/arch/mips/pci/pcie-octeon.c
7786 index 5e36c33..eb4a17b 100644
7787 --- a/arch/mips/pci/pcie-octeon.c
7788 +++ b/arch/mips/pci/pcie-octeon.c
7789 @@ -1792,8 +1792,8 @@ static int octeon_dummy_write_config(struct pci_bus *bus, unsigned int devfn,
7790 }
7791
7792 static struct pci_ops octeon_pcie0_ops = {
7793 - octeon_pcie0_read_config,
7794 - octeon_pcie0_write_config,
7795 + .read = octeon_pcie0_read_config,
7796 + .write = octeon_pcie0_write_config,
7797 };
7798
7799 static struct resource octeon_pcie0_mem_resource = {
7800 @@ -1813,8 +1813,8 @@ static struct pci_controller octeon_pcie0_controller = {
7801 };
7802
7803 static struct pci_ops octeon_pcie1_ops = {
7804 - octeon_pcie1_read_config,
7805 - octeon_pcie1_write_config,
7806 + .read = octeon_pcie1_read_config,
7807 + .write = octeon_pcie1_write_config,
7808 };
7809
7810 static struct resource octeon_pcie1_mem_resource = {
7811 @@ -1834,8 +1834,8 @@ static struct pci_controller octeon_pcie1_controller = {
7812 };
7813
7814 static struct pci_ops octeon_dummy_ops = {
7815 - octeon_dummy_read_config,
7816 - octeon_dummy_write_config,
7817 + .read = octeon_dummy_read_config,
7818 + .write = octeon_dummy_write_config,
7819 };
7820
7821 static struct resource octeon_dummy_mem_resource = {
7822 diff --git a/arch/mips/sgi-ip27/ip27-nmi.c b/arch/mips/sgi-ip27/ip27-nmi.c
7823 index a2358b4..7cead4f 100644
7824 --- a/arch/mips/sgi-ip27/ip27-nmi.c
7825 +++ b/arch/mips/sgi-ip27/ip27-nmi.c
7826 @@ -187,9 +187,9 @@ void
7827 cont_nmi_dump(void)
7828 {
7829 #ifndef REAL_NMI_SIGNAL
7830 - static atomic_t nmied_cpus = ATOMIC_INIT(0);
7831 + static atomic_unchecked_t nmied_cpus = ATOMIC_INIT(0);
7832
7833 - atomic_inc(&nmied_cpus);
7834 + atomic_inc_unchecked(&nmied_cpus);
7835 #endif
7836 /*
7837 * Only allow 1 cpu to proceed
7838 @@ -233,7 +233,7 @@ cont_nmi_dump(void)
7839 udelay(10000);
7840 }
7841 #else
7842 - while (atomic_read(&nmied_cpus) != num_online_cpus());
7843 + while (atomic_read_unchecked(&nmied_cpus) != num_online_cpus());
7844 #endif
7845
7846 /*
7847 diff --git a/arch/mips/sni/rm200.c b/arch/mips/sni/rm200.c
7848 index a046b30..6799527 100644
7849 --- a/arch/mips/sni/rm200.c
7850 +++ b/arch/mips/sni/rm200.c
7851 @@ -270,7 +270,7 @@ spurious_8259A_irq:
7852 "spurious RM200 8259A interrupt: IRQ%d.\n", irq);
7853 spurious_irq_mask |= irqmask;
7854 }
7855 - atomic_inc(&irq_err_count);
7856 + atomic_inc_unchecked(&irq_err_count);
7857 /*
7858 * Theoretically we do not have to handle this IRQ,
7859 * but in Linux this does not cause problems and is
7860 diff --git a/arch/mips/vr41xx/common/icu.c b/arch/mips/vr41xx/common/icu.c
7861 index 41e873b..34d33a7 100644
7862 --- a/arch/mips/vr41xx/common/icu.c
7863 +++ b/arch/mips/vr41xx/common/icu.c
7864 @@ -653,7 +653,7 @@ static int icu_get_irq(unsigned int irq)
7865
7866 printk(KERN_ERR "spurious ICU interrupt: %04x,%04x\n", pend1, pend2);
7867
7868 - atomic_inc(&irq_err_count);
7869 + atomic_inc_unchecked(&irq_err_count);
7870
7871 return -1;
7872 }
7873 diff --git a/arch/mips/vr41xx/common/irq.c b/arch/mips/vr41xx/common/irq.c
7874 index ae0e4ee..e8f0692 100644
7875 --- a/arch/mips/vr41xx/common/irq.c
7876 +++ b/arch/mips/vr41xx/common/irq.c
7877 @@ -64,7 +64,7 @@ static void irq_dispatch(unsigned int irq)
7878 irq_cascade_t *cascade;
7879
7880 if (irq >= NR_IRQS) {
7881 - atomic_inc(&irq_err_count);
7882 + atomic_inc_unchecked(&irq_err_count);
7883 return;
7884 }
7885
7886 @@ -84,7 +84,7 @@ static void irq_dispatch(unsigned int irq)
7887 ret = cascade->get_irq(irq);
7888 irq = ret;
7889 if (ret < 0)
7890 - atomic_inc(&irq_err_count);
7891 + atomic_inc_unchecked(&irq_err_count);
7892 else
7893 irq_dispatch(irq);
7894 if (!irqd_irq_disabled(idata) && chip->irq_unmask)
7895 diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7896 index 967d144..db12197 100644
7897 --- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
7898 +++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7899 @@ -11,12 +11,14 @@
7900 #ifndef _ASM_PROC_CACHE_H
7901 #define _ASM_PROC_CACHE_H
7902
7903 +#include <linux/const.h>
7904 +
7905 /* L1 cache */
7906
7907 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7908 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
7909 -#define L1_CACHE_BYTES 16 /* bytes per entry */
7910 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
7911 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7912 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
7913
7914 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7915 diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7916 index bcb5df2..84fabd2 100644
7917 --- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7918 +++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7919 @@ -16,13 +16,15 @@
7920 #ifndef _ASM_PROC_CACHE_H
7921 #define _ASM_PROC_CACHE_H
7922
7923 +#include <linux/const.h>
7924 +
7925 /*
7926 * L1 cache
7927 */
7928 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7929 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
7930 -#define L1_CACHE_BYTES 32 /* bytes per entry */
7931 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
7932 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7933 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
7934
7935 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7936 diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
7937 index 4ce7a01..449202a 100644
7938 --- a/arch/openrisc/include/asm/cache.h
7939 +++ b/arch/openrisc/include/asm/cache.h
7940 @@ -19,11 +19,13 @@
7941 #ifndef __ASM_OPENRISC_CACHE_H
7942 #define __ASM_OPENRISC_CACHE_H
7943
7944 +#include <linux/const.h>
7945 +
7946 /* FIXME: How can we replace these with values from the CPU...
7947 * they shouldn't be hard-coded!
7948 */
7949
7950 -#define L1_CACHE_BYTES 16
7951 #define L1_CACHE_SHIFT 4
7952 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7953
7954 #endif /* __ASM_OPENRISC_CACHE_H */
7955 diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
7956 index 0be2db2..1b0f26d 100644
7957 --- a/arch/parisc/include/asm/atomic.h
7958 +++ b/arch/parisc/include/asm/atomic.h
7959 @@ -248,6 +248,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
7960 return dec;
7961 }
7962
7963 +#define atomic64_read_unchecked(v) atomic64_read(v)
7964 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7965 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7966 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7967 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7968 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
7969 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7970 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
7971 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7972 +
7973 #endif /* !CONFIG_64BIT */
7974
7975
7976 diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
7977 index 47f11c7..3420df2 100644
7978 --- a/arch/parisc/include/asm/cache.h
7979 +++ b/arch/parisc/include/asm/cache.h
7980 @@ -5,6 +5,7 @@
7981 #ifndef __ARCH_PARISC_CACHE_H
7982 #define __ARCH_PARISC_CACHE_H
7983
7984 +#include <linux/const.h>
7985
7986 /*
7987 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
7988 @@ -15,13 +16,13 @@
7989 * just ruin performance.
7990 */
7991 #ifdef CONFIG_PA20
7992 -#define L1_CACHE_BYTES 64
7993 #define L1_CACHE_SHIFT 6
7994 #else
7995 -#define L1_CACHE_BYTES 32
7996 #define L1_CACHE_SHIFT 5
7997 #endif
7998
7999 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8000 +
8001 #ifndef __ASSEMBLY__
8002
8003 #define SMP_CACHE_BYTES L1_CACHE_BYTES
8004 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
8005 index 3391d06..c23a2cc 100644
8006 --- a/arch/parisc/include/asm/elf.h
8007 +++ b/arch/parisc/include/asm/elf.h
8008 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
8009
8010 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
8011
8012 +#ifdef CONFIG_PAX_ASLR
8013 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
8014 +
8015 +#define PAX_DELTA_MMAP_LEN 16
8016 +#define PAX_DELTA_STACK_LEN 16
8017 +#endif
8018 +
8019 /* This yields a mask that user programs can use to figure out what
8020 instruction set this CPU supports. This could be done in user space,
8021 but it's not easy, and we've already done it here. */
8022 diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
8023 index f213f5b..0af3e8e 100644
8024 --- a/arch/parisc/include/asm/pgalloc.h
8025 +++ b/arch/parisc/include/asm/pgalloc.h
8026 @@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
8027 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
8028 }
8029
8030 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
8031 +{
8032 + pgd_populate(mm, pgd, pmd);
8033 +}
8034 +
8035 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
8036 {
8037 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
8038 @@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
8039 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
8040 #define pmd_free(mm, x) do { } while (0)
8041 #define pgd_populate(mm, pmd, pte) BUG()
8042 +#define pgd_populate_kernel(mm, pmd, pte) BUG()
8043
8044 #endif
8045
8046 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
8047 index 22b89d1..ce34230 100644
8048 --- a/arch/parisc/include/asm/pgtable.h
8049 +++ b/arch/parisc/include/asm/pgtable.h
8050 @@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
8051 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
8052 #define PAGE_COPY PAGE_EXECREAD
8053 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
8054 +
8055 +#ifdef CONFIG_PAX_PAGEEXEC
8056 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
8057 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
8058 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
8059 +#else
8060 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
8061 +# define PAGE_COPY_NOEXEC PAGE_COPY
8062 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
8063 +#endif
8064 +
8065 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
8066 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
8067 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
8068 diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
8069 index 4006964..fcb3cc2 100644
8070 --- a/arch/parisc/include/asm/uaccess.h
8071 +++ b/arch/parisc/include/asm/uaccess.h
8072 @@ -246,10 +246,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
8073 const void __user *from,
8074 unsigned long n)
8075 {
8076 - int sz = __compiletime_object_size(to);
8077 + size_t sz = __compiletime_object_size(to);
8078 int ret = -EFAULT;
8079
8080 - if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
8081 + if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
8082 ret = __copy_from_user(to, from, n);
8083 else
8084 copy_from_user_overflow();
8085 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
8086 index 50dfafc..b9fc230 100644
8087 --- a/arch/parisc/kernel/module.c
8088 +++ b/arch/parisc/kernel/module.c
8089 @@ -98,16 +98,38 @@
8090
8091 /* three functions to determine where in the module core
8092 * or init pieces the location is */
8093 +static inline int in_init_rx(struct module *me, void *loc)
8094 +{
8095 + return (loc >= me->module_init_rx &&
8096 + loc < (me->module_init_rx + me->init_size_rx));
8097 +}
8098 +
8099 +static inline int in_init_rw(struct module *me, void *loc)
8100 +{
8101 + return (loc >= me->module_init_rw &&
8102 + loc < (me->module_init_rw + me->init_size_rw));
8103 +}
8104 +
8105 static inline int in_init(struct module *me, void *loc)
8106 {
8107 - return (loc >= me->module_init &&
8108 - loc <= (me->module_init + me->init_size));
8109 + return in_init_rx(me, loc) || in_init_rw(me, loc);
8110 +}
8111 +
8112 +static inline int in_core_rx(struct module *me, void *loc)
8113 +{
8114 + return (loc >= me->module_core_rx &&
8115 + loc < (me->module_core_rx + me->core_size_rx));
8116 +}
8117 +
8118 +static inline int in_core_rw(struct module *me, void *loc)
8119 +{
8120 + return (loc >= me->module_core_rw &&
8121 + loc < (me->module_core_rw + me->core_size_rw));
8122 }
8123
8124 static inline int in_core(struct module *me, void *loc)
8125 {
8126 - return (loc >= me->module_core &&
8127 - loc <= (me->module_core + me->core_size));
8128 + return in_core_rx(me, loc) || in_core_rw(me, loc);
8129 }
8130
8131 static inline int in_local(struct module *me, void *loc)
8132 @@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
8133 }
8134
8135 /* align things a bit */
8136 - me->core_size = ALIGN(me->core_size, 16);
8137 - me->arch.got_offset = me->core_size;
8138 - me->core_size += gots * sizeof(struct got_entry);
8139 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
8140 + me->arch.got_offset = me->core_size_rw;
8141 + me->core_size_rw += gots * sizeof(struct got_entry);
8142
8143 - me->core_size = ALIGN(me->core_size, 16);
8144 - me->arch.fdesc_offset = me->core_size;
8145 - me->core_size += fdescs * sizeof(Elf_Fdesc);
8146 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
8147 + me->arch.fdesc_offset = me->core_size_rw;
8148 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
8149
8150 me->arch.got_max = gots;
8151 me->arch.fdesc_max = fdescs;
8152 @@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
8153
8154 BUG_ON(value == 0);
8155
8156 - got = me->module_core + me->arch.got_offset;
8157 + got = me->module_core_rw + me->arch.got_offset;
8158 for (i = 0; got[i].addr; i++)
8159 if (got[i].addr == value)
8160 goto out;
8161 @@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
8162 #ifdef CONFIG_64BIT
8163 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
8164 {
8165 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
8166 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
8167
8168 if (!value) {
8169 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
8170 @@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
8171
8172 /* Create new one */
8173 fdesc->addr = value;
8174 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
8175 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
8176 return (Elf_Addr)fdesc;
8177 }
8178 #endif /* CONFIG_64BIT */
8179 @@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
8180
8181 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
8182 end = table + sechdrs[me->arch.unwind_section].sh_size;
8183 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
8184 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
8185
8186 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
8187 me->arch.unwind_section, table, end, gp);
8188 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
8189 index e1ffea2..46ed66e 100644
8190 --- a/arch/parisc/kernel/sys_parisc.c
8191 +++ b/arch/parisc/kernel/sys_parisc.c
8192 @@ -89,6 +89,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8193 unsigned long task_size = TASK_SIZE;
8194 int do_color_align, last_mmap;
8195 struct vm_unmapped_area_info info;
8196 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
8197
8198 if (len > task_size)
8199 return -ENOMEM;
8200 @@ -106,6 +107,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8201 goto found_addr;
8202 }
8203
8204 +#ifdef CONFIG_PAX_RANDMMAP
8205 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8206 +#endif
8207 +
8208 if (addr) {
8209 if (do_color_align && last_mmap)
8210 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
8211 @@ -124,6 +129,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8212 info.high_limit = mmap_upper_limit();
8213 info.align_mask = last_mmap ? (PAGE_MASK & (SHM_COLOUR - 1)) : 0;
8214 info.align_offset = shared_align_offset(last_mmap, pgoff);
8215 + info.threadstack_offset = offset;
8216 addr = vm_unmapped_area(&info);
8217
8218 found_addr:
8219 @@ -143,6 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8220 unsigned long addr = addr0;
8221 int do_color_align, last_mmap;
8222 struct vm_unmapped_area_info info;
8223 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
8224
8225 #ifdef CONFIG_64BIT
8226 /* This should only ever run for 32-bit processes. */
8227 @@ -167,6 +174,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8228 }
8229
8230 /* requesting a specific address */
8231 +#ifdef CONFIG_PAX_RANDMMAP
8232 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8233 +#endif
8234 +
8235 if (addr) {
8236 if (do_color_align && last_mmap)
8237 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
8238 @@ -184,6 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8239 info.high_limit = mm->mmap_base;
8240 info.align_mask = last_mmap ? (PAGE_MASK & (SHM_COLOUR - 1)) : 0;
8241 info.align_offset = shared_align_offset(last_mmap, pgoff);
8242 + info.threadstack_offset = offset;
8243 addr = vm_unmapped_area(&info);
8244 if (!(addr & ~PAGE_MASK))
8245 goto found_addr;
8246 @@ -249,6 +261,13 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8247 mm->mmap_legacy_base = mmap_legacy_base();
8248 mm->mmap_base = mmap_upper_limit();
8249
8250 +#ifdef CONFIG_PAX_RANDMMAP
8251 + if (mm->pax_flags & MF_PAX_RANDMMAP) {
8252 + mm->mmap_legacy_base += mm->delta_mmap;
8253 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8254 + }
8255 +#endif
8256 +
8257 if (mmap_is_legacy()) {
8258 mm->mmap_base = mm->mmap_legacy_base;
8259 mm->get_unmapped_area = arch_get_unmapped_area;
8260 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
8261 index 47ee620..1107387 100644
8262 --- a/arch/parisc/kernel/traps.c
8263 +++ b/arch/parisc/kernel/traps.c
8264 @@ -726,9 +726,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
8265
8266 down_read(&current->mm->mmap_sem);
8267 vma = find_vma(current->mm,regs->iaoq[0]);
8268 - if (vma && (regs->iaoq[0] >= vma->vm_start)
8269 - && (vma->vm_flags & VM_EXEC)) {
8270 -
8271 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
8272 fault_address = regs->iaoq[0];
8273 fault_space = regs->iasq[0];
8274
8275 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
8276 index 3ca9c11..d163ef7 100644
8277 --- a/arch/parisc/mm/fault.c
8278 +++ b/arch/parisc/mm/fault.c
8279 @@ -15,6 +15,7 @@
8280 #include <linux/sched.h>
8281 #include <linux/interrupt.h>
8282 #include <linux/module.h>
8283 +#include <linux/unistd.h>
8284
8285 #include <asm/uaccess.h>
8286 #include <asm/traps.h>
8287 @@ -50,7 +51,7 @@ int show_unhandled_signals = 1;
8288 static unsigned long
8289 parisc_acctyp(unsigned long code, unsigned int inst)
8290 {
8291 - if (code == 6 || code == 16)
8292 + if (code == 6 || code == 7 || code == 16)
8293 return VM_EXEC;
8294
8295 switch (inst & 0xf0000000) {
8296 @@ -136,6 +137,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
8297 }
8298 #endif
8299
8300 +#ifdef CONFIG_PAX_PAGEEXEC
8301 +/*
8302 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
8303 + *
8304 + * returns 1 when task should be killed
8305 + * 2 when rt_sigreturn trampoline was detected
8306 + * 3 when unpatched PLT trampoline was detected
8307 + */
8308 +static int pax_handle_fetch_fault(struct pt_regs *regs)
8309 +{
8310 +
8311 +#ifdef CONFIG_PAX_EMUPLT
8312 + int err;
8313 +
8314 + do { /* PaX: unpatched PLT emulation */
8315 + unsigned int bl, depwi;
8316 +
8317 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
8318 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
8319 +
8320 + if (err)
8321 + break;
8322 +
8323 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
8324 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
8325 +
8326 + err = get_user(ldw, (unsigned int *)addr);
8327 + err |= get_user(bv, (unsigned int *)(addr+4));
8328 + err |= get_user(ldw2, (unsigned int *)(addr+8));
8329 +
8330 + if (err)
8331 + break;
8332 +
8333 + if (ldw == 0x0E801096U &&
8334 + bv == 0xEAC0C000U &&
8335 + ldw2 == 0x0E881095U)
8336 + {
8337 + unsigned int resolver, map;
8338 +
8339 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
8340 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
8341 + if (err)
8342 + break;
8343 +
8344 + regs->gr[20] = instruction_pointer(regs)+8;
8345 + regs->gr[21] = map;
8346 + regs->gr[22] = resolver;
8347 + regs->iaoq[0] = resolver | 3UL;
8348 + regs->iaoq[1] = regs->iaoq[0] + 4;
8349 + return 3;
8350 + }
8351 + }
8352 + } while (0);
8353 +#endif
8354 +
8355 +#ifdef CONFIG_PAX_EMUTRAMP
8356 +
8357 +#ifndef CONFIG_PAX_EMUSIGRT
8358 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
8359 + return 1;
8360 +#endif
8361 +
8362 + do { /* PaX: rt_sigreturn emulation */
8363 + unsigned int ldi1, ldi2, bel, nop;
8364 +
8365 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
8366 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
8367 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
8368 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
8369 +
8370 + if (err)
8371 + break;
8372 +
8373 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
8374 + ldi2 == 0x3414015AU &&
8375 + bel == 0xE4008200U &&
8376 + nop == 0x08000240U)
8377 + {
8378 + regs->gr[25] = (ldi1 & 2) >> 1;
8379 + regs->gr[20] = __NR_rt_sigreturn;
8380 + regs->gr[31] = regs->iaoq[1] + 16;
8381 + regs->sr[0] = regs->iasq[1];
8382 + regs->iaoq[0] = 0x100UL;
8383 + regs->iaoq[1] = regs->iaoq[0] + 4;
8384 + regs->iasq[0] = regs->sr[2];
8385 + regs->iasq[1] = regs->sr[2];
8386 + return 2;
8387 + }
8388 + } while (0);
8389 +#endif
8390 +
8391 + return 1;
8392 +}
8393 +
8394 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
8395 +{
8396 + unsigned long i;
8397 +
8398 + printk(KERN_ERR "PAX: bytes at PC: ");
8399 + for (i = 0; i < 5; i++) {
8400 + unsigned int c;
8401 + if (get_user(c, (unsigned int *)pc+i))
8402 + printk(KERN_CONT "???????? ");
8403 + else
8404 + printk(KERN_CONT "%08x ", c);
8405 + }
8406 + printk("\n");
8407 +}
8408 +#endif
8409 +
8410 int fixup_exception(struct pt_regs *regs)
8411 {
8412 const struct exception_table_entry *fix;
8413 @@ -234,8 +345,33 @@ retry:
8414
8415 good_area:
8416
8417 - if ((vma->vm_flags & acc_type) != acc_type)
8418 + if ((vma->vm_flags & acc_type) != acc_type) {
8419 +
8420 +#ifdef CONFIG_PAX_PAGEEXEC
8421 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
8422 + (address & ~3UL) == instruction_pointer(regs))
8423 + {
8424 + up_read(&mm->mmap_sem);
8425 + switch (pax_handle_fetch_fault(regs)) {
8426 +
8427 +#ifdef CONFIG_PAX_EMUPLT
8428 + case 3:
8429 + return;
8430 +#endif
8431 +
8432 +#ifdef CONFIG_PAX_EMUTRAMP
8433 + case 2:
8434 + return;
8435 +#endif
8436 +
8437 + }
8438 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
8439 + do_group_exit(SIGKILL);
8440 + }
8441 +#endif
8442 +
8443 goto bad_area;
8444 + }
8445
8446 /*
8447 * If for any reason at all we couldn't handle the fault, make
8448 diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
8449 index 80b94b0..a3274fb 100644
8450 --- a/arch/powerpc/Kconfig
8451 +++ b/arch/powerpc/Kconfig
8452 @@ -398,6 +398,7 @@ config PPC64_SUPPORTS_MEMORY_FAILURE
8453 config KEXEC
8454 bool "kexec system call"
8455 depends on (PPC_BOOK3S || FSL_BOOKE || (44x && !SMP))
8456 + depends on !GRKERNSEC_KMEM
8457 help
8458 kexec is a system call that implements the ability to shutdown your
8459 current kernel, and to start another kernel. It is like a reboot
8460 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
8461 index 28992d0..c797b20 100644
8462 --- a/arch/powerpc/include/asm/atomic.h
8463 +++ b/arch/powerpc/include/asm/atomic.h
8464 @@ -519,6 +519,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
8465 return t1;
8466 }
8467
8468 +#define atomic64_read_unchecked(v) atomic64_read(v)
8469 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
8470 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
8471 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
8472 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
8473 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
8474 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
8475 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
8476 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
8477 +
8478 #endif /* __powerpc64__ */
8479
8480 #endif /* __KERNEL__ */
8481 diff --git a/arch/powerpc/include/asm/barrier.h b/arch/powerpc/include/asm/barrier.h
8482 index bab79a1..4a3eabc 100644
8483 --- a/arch/powerpc/include/asm/barrier.h
8484 +++ b/arch/powerpc/include/asm/barrier.h
8485 @@ -73,7 +73,7 @@
8486 do { \
8487 compiletime_assert_atomic_type(*p); \
8488 __lwsync(); \
8489 - ACCESS_ONCE(*p) = (v); \
8490 + ACCESS_ONCE_RW(*p) = (v); \
8491 } while (0)
8492
8493 #define smp_load_acquire(p) \
8494 diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
8495 index ed0afc1..0332825 100644
8496 --- a/arch/powerpc/include/asm/cache.h
8497 +++ b/arch/powerpc/include/asm/cache.h
8498 @@ -3,6 +3,7 @@
8499
8500 #ifdef __KERNEL__
8501
8502 +#include <linux/const.h>
8503
8504 /* bytes per L1 cache line */
8505 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
8506 @@ -22,7 +23,7 @@
8507 #define L1_CACHE_SHIFT 7
8508 #endif
8509
8510 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8511 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8512
8513 #define SMP_CACHE_BYTES L1_CACHE_BYTES
8514
8515 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
8516 index 888d8f3..66f581c 100644
8517 --- a/arch/powerpc/include/asm/elf.h
8518 +++ b/arch/powerpc/include/asm/elf.h
8519 @@ -28,8 +28,19 @@
8520 the loader. We need to make sure that it is out of the way of the program
8521 that it will "exec", and that there is sufficient room for the brk. */
8522
8523 -extern unsigned long randomize_et_dyn(unsigned long base);
8524 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
8525 +#define ELF_ET_DYN_BASE (0x20000000)
8526 +
8527 +#ifdef CONFIG_PAX_ASLR
8528 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
8529 +
8530 +#ifdef __powerpc64__
8531 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
8532 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
8533 +#else
8534 +#define PAX_DELTA_MMAP_LEN 15
8535 +#define PAX_DELTA_STACK_LEN 15
8536 +#endif
8537 +#endif
8538
8539 #define ELF_CORE_EFLAGS (is_elf2_task() ? 2 : 0)
8540
8541 @@ -129,10 +140,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
8542 (0x7ff >> (PAGE_SHIFT - 12)) : \
8543 (0x3ffff >> (PAGE_SHIFT - 12)))
8544
8545 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
8546 -#define arch_randomize_brk arch_randomize_brk
8547 -
8548 -
8549 #ifdef CONFIG_SPU_BASE
8550 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
8551 #define NT_SPU 1
8552 diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
8553 index 8196e9c..d83a9f3 100644
8554 --- a/arch/powerpc/include/asm/exec.h
8555 +++ b/arch/powerpc/include/asm/exec.h
8556 @@ -4,6 +4,6 @@
8557 #ifndef _ASM_POWERPC_EXEC_H
8558 #define _ASM_POWERPC_EXEC_H
8559
8560 -extern unsigned long arch_align_stack(unsigned long sp);
8561 +#define arch_align_stack(x) ((x) & ~0xfUL)
8562
8563 #endif /* _ASM_POWERPC_EXEC_H */
8564 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
8565 index 5acabbd..7ea14fa 100644
8566 --- a/arch/powerpc/include/asm/kmap_types.h
8567 +++ b/arch/powerpc/include/asm/kmap_types.h
8568 @@ -10,7 +10,7 @@
8569 * 2 of the License, or (at your option) any later version.
8570 */
8571
8572 -#define KM_TYPE_NR 16
8573 +#define KM_TYPE_NR 17
8574
8575 #endif /* __KERNEL__ */
8576 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
8577 diff --git a/arch/powerpc/include/asm/local.h b/arch/powerpc/include/asm/local.h
8578 index b8da913..60b608a 100644
8579 --- a/arch/powerpc/include/asm/local.h
8580 +++ b/arch/powerpc/include/asm/local.h
8581 @@ -9,15 +9,26 @@ typedef struct
8582 atomic_long_t a;
8583 } local_t;
8584
8585 +typedef struct
8586 +{
8587 + atomic_long_unchecked_t a;
8588 +} local_unchecked_t;
8589 +
8590 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
8591
8592 #define local_read(l) atomic_long_read(&(l)->a)
8593 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
8594 #define local_set(l,i) atomic_long_set(&(l)->a, (i))
8595 +#define local_set_unchecked(l,i) atomic_long_set_unchecked(&(l)->a, (i))
8596
8597 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
8598 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
8599 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
8600 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
8601 #define local_inc(l) atomic_long_inc(&(l)->a)
8602 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
8603 #define local_dec(l) atomic_long_dec(&(l)->a)
8604 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
8605
8606 static __inline__ long local_add_return(long a, local_t *l)
8607 {
8608 @@ -35,6 +46,7 @@ static __inline__ long local_add_return(long a, local_t *l)
8609
8610 return t;
8611 }
8612 +#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
8613
8614 #define local_add_negative(a, l) (local_add_return((a), (l)) < 0)
8615
8616 @@ -54,6 +66,7 @@ static __inline__ long local_sub_return(long a, local_t *l)
8617
8618 return t;
8619 }
8620 +#define local_sub_return_unchecked(i, l) atomic_long_sub_return_unchecked((i), (&(l)->a))
8621
8622 static __inline__ long local_inc_return(local_t *l)
8623 {
8624 @@ -101,6 +114,8 @@ static __inline__ long local_dec_return(local_t *l)
8625
8626 #define local_cmpxchg(l, o, n) \
8627 (cmpxchg_local(&((l)->a.counter), (o), (n)))
8628 +#define local_cmpxchg_unchecked(l, o, n) \
8629 + (cmpxchg_local(&((l)->a.counter), (o), (n)))
8630 #define local_xchg(l, n) (xchg_local(&((l)->a.counter), (n)))
8631
8632 /**
8633 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
8634 index 8565c25..2865190 100644
8635 --- a/arch/powerpc/include/asm/mman.h
8636 +++ b/arch/powerpc/include/asm/mman.h
8637 @@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
8638 }
8639 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
8640
8641 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
8642 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
8643 {
8644 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
8645 }
8646 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
8647 index 32e4e21..62afb12 100644
8648 --- a/arch/powerpc/include/asm/page.h
8649 +++ b/arch/powerpc/include/asm/page.h
8650 @@ -230,8 +230,9 @@ extern long long virt_phys_offset;
8651 * and needs to be executable. This means the whole heap ends
8652 * up being executable.
8653 */
8654 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8655 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8656 +#define VM_DATA_DEFAULT_FLAGS32 \
8657 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8658 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8659
8660 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8661 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8662 @@ -259,6 +260,9 @@ extern long long virt_phys_offset;
8663 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
8664 #endif
8665
8666 +#define ktla_ktva(addr) (addr)
8667 +#define ktva_ktla(addr) (addr)
8668 +
8669 #ifndef CONFIG_PPC_BOOK3S_64
8670 /*
8671 * Use the top bit of the higher-level page table entries to indicate whether
8672 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
8673 index 88693ce..ac6f9ab 100644
8674 --- a/arch/powerpc/include/asm/page_64.h
8675 +++ b/arch/powerpc/include/asm/page_64.h
8676 @@ -153,15 +153,18 @@ do { \
8677 * stack by default, so in the absence of a PT_GNU_STACK program header
8678 * we turn execute permission off.
8679 */
8680 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8681 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8682 +#define VM_STACK_DEFAULT_FLAGS32 \
8683 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8684 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8685
8686 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8687 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8688
8689 +#ifndef CONFIG_PAX_PAGEEXEC
8690 #define VM_STACK_DEFAULT_FLAGS \
8691 (is_32bit_task() ? \
8692 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
8693 +#endif
8694
8695 #include <asm-generic/getorder.h>
8696
8697 diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
8698 index 4b0be20..c15a27d 100644
8699 --- a/arch/powerpc/include/asm/pgalloc-64.h
8700 +++ b/arch/powerpc/include/asm/pgalloc-64.h
8701 @@ -54,6 +54,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
8702 #ifndef CONFIG_PPC_64K_PAGES
8703
8704 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
8705 +#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
8706
8707 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
8708 {
8709 @@ -71,6 +72,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8710 pud_set(pud, (unsigned long)pmd);
8711 }
8712
8713 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8714 +{
8715 + pud_populate(mm, pud, pmd);
8716 +}
8717 +
8718 #define pmd_populate(mm, pmd, pte_page) \
8719 pmd_populate_kernel(mm, pmd, page_address(pte_page))
8720 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
8721 @@ -173,6 +179,7 @@ extern void __tlb_remove_table(void *_table);
8722 #endif
8723
8724 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
8725 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
8726
8727 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
8728 pte_t *pte)
8729 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
8730 index d98c1ec..9f61569 100644
8731 --- a/arch/powerpc/include/asm/pgtable.h
8732 +++ b/arch/powerpc/include/asm/pgtable.h
8733 @@ -2,6 +2,7 @@
8734 #define _ASM_POWERPC_PGTABLE_H
8735 #ifdef __KERNEL__
8736
8737 +#include <linux/const.h>
8738 #ifndef __ASSEMBLY__
8739 #include <linux/mmdebug.h>
8740 #include <asm/processor.h> /* For TASK_SIZE */
8741 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
8742 index 4aad413..85d86bf 100644
8743 --- a/arch/powerpc/include/asm/pte-hash32.h
8744 +++ b/arch/powerpc/include/asm/pte-hash32.h
8745 @@ -21,6 +21,7 @@
8746 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
8747 #define _PAGE_USER 0x004 /* usermode access allowed */
8748 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
8749 +#define _PAGE_EXEC _PAGE_GUARDED
8750 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
8751 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
8752 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
8753 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
8754 index bffd89d..a6641ed 100644
8755 --- a/arch/powerpc/include/asm/reg.h
8756 +++ b/arch/powerpc/include/asm/reg.h
8757 @@ -251,6 +251,7 @@
8758 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
8759 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
8760 #define DSISR_NOHPTE 0x40000000 /* no translation found */
8761 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
8762 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
8763 #define DSISR_ISSTORE 0x02000000 /* access was a store */
8764 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
8765 diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
8766 index 5a6614a..d89995d1 100644
8767 --- a/arch/powerpc/include/asm/smp.h
8768 +++ b/arch/powerpc/include/asm/smp.h
8769 @@ -51,7 +51,7 @@ struct smp_ops_t {
8770 int (*cpu_disable)(void);
8771 void (*cpu_die)(unsigned int nr);
8772 int (*cpu_bootable)(unsigned int nr);
8773 -};
8774 +} __no_const;
8775
8776 extern void smp_send_debugger_break(void);
8777 extern void start_secondary_resume(void);
8778 diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
8779 index b034ecd..af7e31f 100644
8780 --- a/arch/powerpc/include/asm/thread_info.h
8781 +++ b/arch/powerpc/include/asm/thread_info.h
8782 @@ -107,6 +107,8 @@ static inline struct thread_info *current_thread_info(void)
8783 #if defined(CONFIG_PPC64)
8784 #define TIF_ELF2ABI 18 /* function descriptors must die! */
8785 #endif
8786 +/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
8787 +#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
8788
8789 /* as above, but as bit values */
8790 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
8791 @@ -125,9 +127,10 @@ static inline struct thread_info *current_thread_info(void)
8792 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
8793 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
8794 #define _TIF_NOHZ (1<<TIF_NOHZ)
8795 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
8796 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
8797 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
8798 - _TIF_NOHZ)
8799 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
8800
8801 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
8802 _TIF_NOTIFY_RESUME | _TIF_UPROBE | \
8803 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
8804 index 9485b43..3bd3c16 100644
8805 --- a/arch/powerpc/include/asm/uaccess.h
8806 +++ b/arch/powerpc/include/asm/uaccess.h
8807 @@ -58,6 +58,7 @@
8808
8809 #endif
8810
8811 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
8812 #define access_ok(type, addr, size) \
8813 (__chk_user_ptr(addr), \
8814 __access_ok((__force unsigned long)(addr), (size), get_fs()))
8815 @@ -318,52 +319,6 @@ do { \
8816 extern unsigned long __copy_tofrom_user(void __user *to,
8817 const void __user *from, unsigned long size);
8818
8819 -#ifndef __powerpc64__
8820 -
8821 -static inline unsigned long copy_from_user(void *to,
8822 - const void __user *from, unsigned long n)
8823 -{
8824 - unsigned long over;
8825 -
8826 - if (access_ok(VERIFY_READ, from, n))
8827 - return __copy_tofrom_user((__force void __user *)to, from, n);
8828 - if ((unsigned long)from < TASK_SIZE) {
8829 - over = (unsigned long)from + n - TASK_SIZE;
8830 - return __copy_tofrom_user((__force void __user *)to, from,
8831 - n - over) + over;
8832 - }
8833 - return n;
8834 -}
8835 -
8836 -static inline unsigned long copy_to_user(void __user *to,
8837 - const void *from, unsigned long n)
8838 -{
8839 - unsigned long over;
8840 -
8841 - if (access_ok(VERIFY_WRITE, to, n))
8842 - return __copy_tofrom_user(to, (__force void __user *)from, n);
8843 - if ((unsigned long)to < TASK_SIZE) {
8844 - over = (unsigned long)to + n - TASK_SIZE;
8845 - return __copy_tofrom_user(to, (__force void __user *)from,
8846 - n - over) + over;
8847 - }
8848 - return n;
8849 -}
8850 -
8851 -#else /* __powerpc64__ */
8852 -
8853 -#define __copy_in_user(to, from, size) \
8854 - __copy_tofrom_user((to), (from), (size))
8855 -
8856 -extern unsigned long copy_from_user(void *to, const void __user *from,
8857 - unsigned long n);
8858 -extern unsigned long copy_to_user(void __user *to, const void *from,
8859 - unsigned long n);
8860 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
8861 - unsigned long n);
8862 -
8863 -#endif /* __powerpc64__ */
8864 -
8865 static inline unsigned long __copy_from_user_inatomic(void *to,
8866 const void __user *from, unsigned long n)
8867 {
8868 @@ -387,6 +342,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
8869 if (ret == 0)
8870 return 0;
8871 }
8872 +
8873 + if (!__builtin_constant_p(n))
8874 + check_object_size(to, n, false);
8875 +
8876 return __copy_tofrom_user((__force void __user *)to, from, n);
8877 }
8878
8879 @@ -413,6 +372,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
8880 if (ret == 0)
8881 return 0;
8882 }
8883 +
8884 + if (!__builtin_constant_p(n))
8885 + check_object_size(from, n, true);
8886 +
8887 return __copy_tofrom_user(to, (__force const void __user *)from, n);
8888 }
8889
8890 @@ -430,6 +393,92 @@ static inline unsigned long __copy_to_user(void __user *to,
8891 return __copy_to_user_inatomic(to, from, size);
8892 }
8893
8894 +#ifndef __powerpc64__
8895 +
8896 +static inline unsigned long __must_check copy_from_user(void *to,
8897 + const void __user *from, unsigned long n)
8898 +{
8899 + unsigned long over;
8900 +
8901 + if ((long)n < 0)
8902 + return n;
8903 +
8904 + if (access_ok(VERIFY_READ, from, n)) {
8905 + if (!__builtin_constant_p(n))
8906 + check_object_size(to, n, false);
8907 + return __copy_tofrom_user((__force void __user *)to, from, n);
8908 + }
8909 + if ((unsigned long)from < TASK_SIZE) {
8910 + over = (unsigned long)from + n - TASK_SIZE;
8911 + if (!__builtin_constant_p(n - over))
8912 + check_object_size(to, n - over, false);
8913 + return __copy_tofrom_user((__force void __user *)to, from,
8914 + n - over) + over;
8915 + }
8916 + return n;
8917 +}
8918 +
8919 +static inline unsigned long __must_check copy_to_user(void __user *to,
8920 + const void *from, unsigned long n)
8921 +{
8922 + unsigned long over;
8923 +
8924 + if ((long)n < 0)
8925 + return n;
8926 +
8927 + if (access_ok(VERIFY_WRITE, to, n)) {
8928 + if (!__builtin_constant_p(n))
8929 + check_object_size(from, n, true);
8930 + return __copy_tofrom_user(to, (__force void __user *)from, n);
8931 + }
8932 + if ((unsigned long)to < TASK_SIZE) {
8933 + over = (unsigned long)to + n - TASK_SIZE;
8934 + if (!__builtin_constant_p(n))
8935 + check_object_size(from, n - over, true);
8936 + return __copy_tofrom_user(to, (__force void __user *)from,
8937 + n - over) + over;
8938 + }
8939 + return n;
8940 +}
8941 +
8942 +#else /* __powerpc64__ */
8943 +
8944 +#define __copy_in_user(to, from, size) \
8945 + __copy_tofrom_user((to), (from), (size))
8946 +
8947 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
8948 +{
8949 + if ((long)n < 0 || n > INT_MAX)
8950 + return n;
8951 +
8952 + if (!__builtin_constant_p(n))
8953 + check_object_size(to, n, false);
8954 +
8955 + if (likely(access_ok(VERIFY_READ, from, n)))
8956 + n = __copy_from_user(to, from, n);
8957 + else
8958 + memset(to, 0, n);
8959 + return n;
8960 +}
8961 +
8962 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
8963 +{
8964 + if ((long)n < 0 || n > INT_MAX)
8965 + return n;
8966 +
8967 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
8968 + if (!__builtin_constant_p(n))
8969 + check_object_size(from, n, true);
8970 + n = __copy_to_user(to, from, n);
8971 + }
8972 + return n;
8973 +}
8974 +
8975 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
8976 + unsigned long n);
8977 +
8978 +#endif /* __powerpc64__ */
8979 +
8980 extern unsigned long __clear_user(void __user *addr, unsigned long size);
8981
8982 static inline unsigned long clear_user(void __user *addr, unsigned long size)
8983 diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
8984 index 670c312..60c2b52 100644
8985 --- a/arch/powerpc/kernel/Makefile
8986 +++ b/arch/powerpc/kernel/Makefile
8987 @@ -27,6 +27,8 @@ CFLAGS_REMOVE_ftrace.o = -pg -mno-sched-epilog
8988 CFLAGS_REMOVE_time.o = -pg -mno-sched-epilog
8989 endif
8990
8991 +CFLAGS_REMOVE_prom_init.o += $(LATENT_ENTROPY_PLUGIN_CFLAGS)
8992 +
8993 obj-y := cputable.o ptrace.o syscalls.o \
8994 irq.o align.o signal_32.o pmc.o vdso.o \
8995 process.o systbl.o idle.o \
8996 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
8997 index bb9cac6..5181202 100644
8998 --- a/arch/powerpc/kernel/exceptions-64e.S
8999 +++ b/arch/powerpc/kernel/exceptions-64e.S
9000 @@ -1010,6 +1010,7 @@ storage_fault_common:
9001 std r14,_DAR(r1)
9002 std r15,_DSISR(r1)
9003 addi r3,r1,STACK_FRAME_OVERHEAD
9004 + bl save_nvgprs
9005 mr r4,r14
9006 mr r5,r15
9007 ld r14,PACA_EXGEN+EX_R14(r13)
9008 @@ -1018,8 +1019,7 @@ storage_fault_common:
9009 cmpdi r3,0
9010 bne- 1f
9011 b ret_from_except_lite
9012 -1: bl save_nvgprs
9013 - mr r5,r3
9014 +1: mr r5,r3
9015 addi r3,r1,STACK_FRAME_OVERHEAD
9016 ld r4,_DAR(r1)
9017 bl bad_page_fault
9018 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
9019 index a7d36b1..53af150 100644
9020 --- a/arch/powerpc/kernel/exceptions-64s.S
9021 +++ b/arch/powerpc/kernel/exceptions-64s.S
9022 @@ -1637,10 +1637,10 @@ handle_page_fault:
9023 11: ld r4,_DAR(r1)
9024 ld r5,_DSISR(r1)
9025 addi r3,r1,STACK_FRAME_OVERHEAD
9026 + bl save_nvgprs
9027 bl do_page_fault
9028 cmpdi r3,0
9029 beq+ 12f
9030 - bl save_nvgprs
9031 mr r5,r3
9032 addi r3,r1,STACK_FRAME_OVERHEAD
9033 lwz r4,_DAR(r1)
9034 diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c
9035 index 248ee7e..1eb60dd 100644
9036 --- a/arch/powerpc/kernel/irq.c
9037 +++ b/arch/powerpc/kernel/irq.c
9038 @@ -447,6 +447,8 @@ void migrate_irqs(void)
9039 }
9040 #endif
9041
9042 +extern void gr_handle_kernel_exploit(void);
9043 +
9044 static inline void check_stack_overflow(void)
9045 {
9046 #ifdef CONFIG_DEBUG_STACKOVERFLOW
9047 @@ -459,6 +461,7 @@ static inline void check_stack_overflow(void)
9048 printk("do_IRQ: stack overflow: %ld\n",
9049 sp - sizeof(struct thread_info));
9050 dump_stack();
9051 + gr_handle_kernel_exploit();
9052 }
9053 #endif
9054 }
9055 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
9056 index 6cff040..74ac5d1b 100644
9057 --- a/arch/powerpc/kernel/module_32.c
9058 +++ b/arch/powerpc/kernel/module_32.c
9059 @@ -161,7 +161,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
9060 me->arch.core_plt_section = i;
9061 }
9062 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
9063 - printk("Module doesn't contain .plt or .init.plt sections.\n");
9064 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
9065 return -ENOEXEC;
9066 }
9067
9068 @@ -191,11 +191,16 @@ static uint32_t do_plt_call(void *location,
9069
9070 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
9071 /* Init, or core PLT? */
9072 - if (location >= mod->module_core
9073 - && location < mod->module_core + mod->core_size)
9074 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
9075 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
9076 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
9077 - else
9078 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
9079 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
9080 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
9081 + else {
9082 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
9083 + return ~0UL;
9084 + }
9085
9086 /* Find this entry, or if that fails, the next avail. entry */
9087 while (entry->jump[0]) {
9088 @@ -299,7 +304,7 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
9089 }
9090 #ifdef CONFIG_DYNAMIC_FTRACE
9091 module->arch.tramp =
9092 - do_plt_call(module->module_core,
9093 + do_plt_call(module->module_core_rx,
9094 (unsigned long)ftrace_caller,
9095 sechdrs, module);
9096 #endif
9097 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
9098 index be99774..9879c82 100644
9099 --- a/arch/powerpc/kernel/process.c
9100 +++ b/arch/powerpc/kernel/process.c
9101 @@ -1039,8 +1039,8 @@ void show_regs(struct pt_regs * regs)
9102 * Lookup NIP late so we have the best change of getting the
9103 * above info out without failing
9104 */
9105 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
9106 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
9107 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
9108 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
9109 #endif
9110 show_stack(current, (unsigned long *) regs->gpr[1]);
9111 if (!user_mode(regs))
9112 @@ -1554,10 +1554,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
9113 newsp = stack[0];
9114 ip = stack[STACK_FRAME_LR_SAVE];
9115 if (!firstframe || ip != lr) {
9116 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
9117 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
9118 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
9119 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
9120 - printk(" (%pS)",
9121 + printk(" (%pA)",
9122 (void *)current->ret_stack[curr_frame].ret);
9123 curr_frame--;
9124 }
9125 @@ -1577,7 +1577,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
9126 struct pt_regs *regs = (struct pt_regs *)
9127 (sp + STACK_FRAME_OVERHEAD);
9128 lr = regs->link;
9129 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
9130 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
9131 regs->trap, (void *)regs->nip, (void *)lr);
9132 firstframe = 1;
9133 }
9134 @@ -1613,58 +1613,3 @@ void notrace __ppc64_runlatch_off(void)
9135 mtspr(SPRN_CTRLT, ctrl);
9136 }
9137 #endif /* CONFIG_PPC64 */
9138 -
9139 -unsigned long arch_align_stack(unsigned long sp)
9140 -{
9141 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
9142 - sp -= get_random_int() & ~PAGE_MASK;
9143 - return sp & ~0xf;
9144 -}
9145 -
9146 -static inline unsigned long brk_rnd(void)
9147 -{
9148 - unsigned long rnd = 0;
9149 -
9150 - /* 8MB for 32bit, 1GB for 64bit */
9151 - if (is_32bit_task())
9152 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
9153 - else
9154 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
9155 -
9156 - return rnd << PAGE_SHIFT;
9157 -}
9158 -
9159 -unsigned long arch_randomize_brk(struct mm_struct *mm)
9160 -{
9161 - unsigned long base = mm->brk;
9162 - unsigned long ret;
9163 -
9164 -#ifdef CONFIG_PPC_STD_MMU_64
9165 - /*
9166 - * If we are using 1TB segments and we are allowed to randomise
9167 - * the heap, we can put it above 1TB so it is backed by a 1TB
9168 - * segment. Otherwise the heap will be in the bottom 1TB
9169 - * which always uses 256MB segments and this may result in a
9170 - * performance penalty.
9171 - */
9172 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
9173 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
9174 -#endif
9175 -
9176 - ret = PAGE_ALIGN(base + brk_rnd());
9177 -
9178 - if (ret < mm->brk)
9179 - return mm->brk;
9180 -
9181 - return ret;
9182 -}
9183 -
9184 -unsigned long randomize_et_dyn(unsigned long base)
9185 -{
9186 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
9187 -
9188 - if (ret < base)
9189 - return base;
9190 -
9191 - return ret;
9192 -}
9193 diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
9194 index 2e3d2bf..35df241 100644
9195 --- a/arch/powerpc/kernel/ptrace.c
9196 +++ b/arch/powerpc/kernel/ptrace.c
9197 @@ -1762,6 +1762,10 @@ long arch_ptrace(struct task_struct *child, long request,
9198 return ret;
9199 }
9200
9201 +#ifdef CONFIG_GRKERNSEC_SETXID
9202 +extern void gr_delayed_cred_worker(void);
9203 +#endif
9204 +
9205 /*
9206 * We must return the syscall number to actually look up in the table.
9207 * This can be -1L to skip running any syscall at all.
9208 @@ -1774,6 +1778,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
9209
9210 secure_computing_strict(regs->gpr[0]);
9211
9212 +#ifdef CONFIG_GRKERNSEC_SETXID
9213 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9214 + gr_delayed_cred_worker();
9215 +#endif
9216 +
9217 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
9218 tracehook_report_syscall_entry(regs))
9219 /*
9220 @@ -1808,6 +1817,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
9221 {
9222 int step;
9223
9224 +#ifdef CONFIG_GRKERNSEC_SETXID
9225 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9226 + gr_delayed_cred_worker();
9227 +#endif
9228 +
9229 audit_syscall_exit(regs);
9230
9231 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
9232 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
9233 index 1bc5a17..910d3f3 100644
9234 --- a/arch/powerpc/kernel/signal_32.c
9235 +++ b/arch/powerpc/kernel/signal_32.c
9236 @@ -1012,7 +1012,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
9237 /* Save user registers on the stack */
9238 frame = &rt_sf->uc.uc_mcontext;
9239 addr = frame;
9240 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
9241 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
9242 sigret = 0;
9243 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
9244 } else {
9245 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
9246 index 97c1e4b..f427f81 100644
9247 --- a/arch/powerpc/kernel/signal_64.c
9248 +++ b/arch/powerpc/kernel/signal_64.c
9249 @@ -755,7 +755,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
9250 current->thread.fp_state.fpscr = 0;
9251
9252 /* Set up to return from userspace. */
9253 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
9254 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
9255 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
9256 } else {
9257 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
9258 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
9259 index 239f1cd..5359f76 100644
9260 --- a/arch/powerpc/kernel/traps.c
9261 +++ b/arch/powerpc/kernel/traps.c
9262 @@ -142,6 +142,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
9263 return flags;
9264 }
9265
9266 +extern void gr_handle_kernel_exploit(void);
9267 +
9268 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
9269 int signr)
9270 {
9271 @@ -191,6 +193,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
9272 panic("Fatal exception in interrupt");
9273 if (panic_on_oops)
9274 panic("Fatal exception");
9275 +
9276 + gr_handle_kernel_exploit();
9277 +
9278 do_exit(signr);
9279 }
9280
9281 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
9282 index ce74c33..0803371 100644
9283 --- a/arch/powerpc/kernel/vdso.c
9284 +++ b/arch/powerpc/kernel/vdso.c
9285 @@ -35,6 +35,7 @@
9286 #include <asm/vdso.h>
9287 #include <asm/vdso_datapage.h>
9288 #include <asm/setup.h>
9289 +#include <asm/mman.h>
9290
9291 #undef DEBUG
9292
9293 @@ -221,7 +222,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
9294 vdso_base = VDSO32_MBASE;
9295 #endif
9296
9297 - current->mm->context.vdso_base = 0;
9298 + current->mm->context.vdso_base = ~0UL;
9299
9300 /* vDSO has a problem and was disabled, just don't "enable" it for the
9301 * process
9302 @@ -241,7 +242,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
9303 vdso_base = get_unmapped_area(NULL, vdso_base,
9304 (vdso_pages << PAGE_SHIFT) +
9305 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
9306 - 0, 0);
9307 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
9308 if (IS_ERR_VALUE(vdso_base)) {
9309 rc = vdso_base;
9310 goto fail_mmapsem;
9311 diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
9312 index 61c738a..b1092d6 100644
9313 --- a/arch/powerpc/kvm/powerpc.c
9314 +++ b/arch/powerpc/kvm/powerpc.c
9315 @@ -1195,7 +1195,7 @@ void kvmppc_init_lpid(unsigned long nr_lpids_param)
9316 }
9317 EXPORT_SYMBOL_GPL(kvmppc_init_lpid);
9318
9319 -int kvm_arch_init(void *opaque)
9320 +int kvm_arch_init(const void *opaque)
9321 {
9322 return 0;
9323 }
9324 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
9325 index 5eea6f3..5d10396 100644
9326 --- a/arch/powerpc/lib/usercopy_64.c
9327 +++ b/arch/powerpc/lib/usercopy_64.c
9328 @@ -9,22 +9,6 @@
9329 #include <linux/module.h>
9330 #include <asm/uaccess.h>
9331
9332 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
9333 -{
9334 - if (likely(access_ok(VERIFY_READ, from, n)))
9335 - n = __copy_from_user(to, from, n);
9336 - else
9337 - memset(to, 0, n);
9338 - return n;
9339 -}
9340 -
9341 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
9342 -{
9343 - if (likely(access_ok(VERIFY_WRITE, to, n)))
9344 - n = __copy_to_user(to, from, n);
9345 - return n;
9346 -}
9347 -
9348 unsigned long copy_in_user(void __user *to, const void __user *from,
9349 unsigned long n)
9350 {
9351 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
9352 return n;
9353 }
9354
9355 -EXPORT_SYMBOL(copy_from_user);
9356 -EXPORT_SYMBOL(copy_to_user);
9357 EXPORT_SYMBOL(copy_in_user);
9358
9359 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
9360 index 51ab9e7..7d3c78b 100644
9361 --- a/arch/powerpc/mm/fault.c
9362 +++ b/arch/powerpc/mm/fault.c
9363 @@ -33,6 +33,10 @@
9364 #include <linux/magic.h>
9365 #include <linux/ratelimit.h>
9366 #include <linux/context_tracking.h>
9367 +#include <linux/slab.h>
9368 +#include <linux/pagemap.h>
9369 +#include <linux/compiler.h>
9370 +#include <linux/unistd.h>
9371
9372 #include <asm/firmware.h>
9373 #include <asm/page.h>
9374 @@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
9375 }
9376 #endif
9377
9378 +#ifdef CONFIG_PAX_PAGEEXEC
9379 +/*
9380 + * PaX: decide what to do with offenders (regs->nip = fault address)
9381 + *
9382 + * returns 1 when task should be killed
9383 + */
9384 +static int pax_handle_fetch_fault(struct pt_regs *regs)
9385 +{
9386 + return 1;
9387 +}
9388 +
9389 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
9390 +{
9391 + unsigned long i;
9392 +
9393 + printk(KERN_ERR "PAX: bytes at PC: ");
9394 + for (i = 0; i < 5; i++) {
9395 + unsigned int c;
9396 + if (get_user(c, (unsigned int __user *)pc+i))
9397 + printk(KERN_CONT "???????? ");
9398 + else
9399 + printk(KERN_CONT "%08x ", c);
9400 + }
9401 + printk("\n");
9402 +}
9403 +#endif
9404 +
9405 /*
9406 * Check whether the instruction at regs->nip is a store using
9407 * an update addressing form which will update r1.
9408 @@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
9409 * indicate errors in DSISR but can validly be set in SRR1.
9410 */
9411 if (trap == 0x400)
9412 - error_code &= 0x48200000;
9413 + error_code &= 0x58200000;
9414 else
9415 is_write = error_code & DSISR_ISSTORE;
9416 #else
9417 @@ -378,7 +409,7 @@ good_area:
9418 * "undefined". Of those that can be set, this is the only
9419 * one which seems bad.
9420 */
9421 - if (error_code & 0x10000000)
9422 + if (error_code & DSISR_GUARDED)
9423 /* Guarded storage error. */
9424 goto bad_area;
9425 #endif /* CONFIG_8xx */
9426 @@ -393,7 +424,7 @@ good_area:
9427 * processors use the same I/D cache coherency mechanism
9428 * as embedded.
9429 */
9430 - if (error_code & DSISR_PROTFAULT)
9431 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
9432 goto bad_area;
9433 #endif /* CONFIG_PPC_STD_MMU */
9434
9435 @@ -483,6 +514,23 @@ bad_area:
9436 bad_area_nosemaphore:
9437 /* User mode accesses cause a SIGSEGV */
9438 if (user_mode(regs)) {
9439 +
9440 +#ifdef CONFIG_PAX_PAGEEXEC
9441 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
9442 +#ifdef CONFIG_PPC_STD_MMU
9443 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
9444 +#else
9445 + if (is_exec && regs->nip == address) {
9446 +#endif
9447 + switch (pax_handle_fetch_fault(regs)) {
9448 + }
9449 +
9450 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
9451 + do_group_exit(SIGKILL);
9452 + }
9453 + }
9454 +#endif
9455 +
9456 _exception(SIGSEGV, regs, code, address);
9457 goto bail;
9458 }
9459 diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c
9460 index cb8bdbe..cde4bc7 100644
9461 --- a/arch/powerpc/mm/mmap.c
9462 +++ b/arch/powerpc/mm/mmap.c
9463 @@ -53,10 +53,14 @@ static inline int mmap_is_legacy(void)
9464 return sysctl_legacy_va_layout;
9465 }
9466
9467 -static unsigned long mmap_rnd(void)
9468 +static unsigned long mmap_rnd(struct mm_struct *mm)
9469 {
9470 unsigned long rnd = 0;
9471
9472 +#ifdef CONFIG_PAX_RANDMMAP
9473 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9474 +#endif
9475 +
9476 if (current->flags & PF_RANDOMIZE) {
9477 /* 8MB for 32bit, 1GB for 64bit */
9478 if (is_32bit_task())
9479 @@ -67,7 +71,7 @@ static unsigned long mmap_rnd(void)
9480 return rnd << PAGE_SHIFT;
9481 }
9482
9483 -static inline unsigned long mmap_base(void)
9484 +static inline unsigned long mmap_base(struct mm_struct *mm)
9485 {
9486 unsigned long gap = rlimit(RLIMIT_STACK);
9487
9488 @@ -76,7 +80,7 @@ static inline unsigned long mmap_base(void)
9489 else if (gap > MAX_GAP)
9490 gap = MAX_GAP;
9491
9492 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
9493 + return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd(mm));
9494 }
9495
9496 /*
9497 @@ -91,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9498 */
9499 if (mmap_is_legacy()) {
9500 mm->mmap_base = TASK_UNMAPPED_BASE;
9501 +
9502 +#ifdef CONFIG_PAX_RANDMMAP
9503 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9504 + mm->mmap_base += mm->delta_mmap;
9505 +#endif
9506 +
9507 mm->get_unmapped_area = arch_get_unmapped_area;
9508 } else {
9509 - mm->mmap_base = mmap_base();
9510 + mm->mmap_base = mmap_base(mm);
9511 +
9512 +#ifdef CONFIG_PAX_RANDMMAP
9513 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9514 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9515 +#endif
9516 +
9517 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9518 }
9519 }
9520 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
9521 index b0c75cc..ef7fb93 100644
9522 --- a/arch/powerpc/mm/slice.c
9523 +++ b/arch/powerpc/mm/slice.c
9524 @@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
9525 if ((mm->task_size - len) < addr)
9526 return 0;
9527 vma = find_vma(mm, addr);
9528 - return (!vma || (addr + len) <= vma->vm_start);
9529 + return check_heap_stack_gap(vma, addr, len, 0);
9530 }
9531
9532 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
9533 @@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
9534 info.align_offset = 0;
9535
9536 addr = TASK_UNMAPPED_BASE;
9537 +
9538 +#ifdef CONFIG_PAX_RANDMMAP
9539 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9540 + addr += mm->delta_mmap;
9541 +#endif
9542 +
9543 while (addr < TASK_SIZE) {
9544 info.low_limit = addr;
9545 if (!slice_scan_available(addr, available, 1, &addr))
9546 @@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
9547 if (fixed && addr > (mm->task_size - len))
9548 return -ENOMEM;
9549
9550 +#ifdef CONFIG_PAX_RANDMMAP
9551 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
9552 + addr = 0;
9553 +#endif
9554 +
9555 /* If hint, make sure it matches our alignment restrictions */
9556 if (!fixed && addr) {
9557 addr = _ALIGN_UP(addr, 1ul << pshift);
9558 diff --git a/arch/powerpc/platforms/cell/celleb_scc_pciex.c b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
9559 index 4278acf..67fd0e6 100644
9560 --- a/arch/powerpc/platforms/cell/celleb_scc_pciex.c
9561 +++ b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
9562 @@ -400,8 +400,8 @@ static int scc_pciex_write_config(struct pci_bus *bus, unsigned int devfn,
9563 }
9564
9565 static struct pci_ops scc_pciex_pci_ops = {
9566 - scc_pciex_read_config,
9567 - scc_pciex_write_config,
9568 + .read = scc_pciex_read_config,
9569 + .write = scc_pciex_write_config,
9570 };
9571
9572 static void pciex_clear_intr_all(unsigned int __iomem *base)
9573 diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
9574 index 9098692..3d54cd1 100644
9575 --- a/arch/powerpc/platforms/cell/spufs/file.c
9576 +++ b/arch/powerpc/platforms/cell/spufs/file.c
9577 @@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9578 return VM_FAULT_NOPAGE;
9579 }
9580
9581 -static int spufs_mem_mmap_access(struct vm_area_struct *vma,
9582 +static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
9583 unsigned long address,
9584 - void *buf, int len, int write)
9585 + void *buf, size_t len, int write)
9586 {
9587 struct spu_context *ctx = vma->vm_file->private_data;
9588 unsigned long offset = address - vma->vm_start;
9589 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
9590 index fa934fe..c296056 100644
9591 --- a/arch/s390/include/asm/atomic.h
9592 +++ b/arch/s390/include/asm/atomic.h
9593 @@ -412,4 +412,14 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
9594 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
9595 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9596
9597 +#define atomic64_read_unchecked(v) atomic64_read(v)
9598 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
9599 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
9600 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
9601 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
9602 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
9603 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
9604 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
9605 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
9606 +
9607 #endif /* __ARCH_S390_ATOMIC__ */
9608 diff --git a/arch/s390/include/asm/barrier.h b/arch/s390/include/asm/barrier.h
9609 index 19ff956..8d39cb1 100644
9610 --- a/arch/s390/include/asm/barrier.h
9611 +++ b/arch/s390/include/asm/barrier.h
9612 @@ -37,7 +37,7 @@
9613 do { \
9614 compiletime_assert_atomic_type(*p); \
9615 barrier(); \
9616 - ACCESS_ONCE(*p) = (v); \
9617 + ACCESS_ONCE_RW(*p) = (v); \
9618 } while (0)
9619
9620 #define smp_load_acquire(p) \
9621 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
9622 index 4d7ccac..d03d0ad 100644
9623 --- a/arch/s390/include/asm/cache.h
9624 +++ b/arch/s390/include/asm/cache.h
9625 @@ -9,8 +9,10 @@
9626 #ifndef __ARCH_S390_CACHE_H
9627 #define __ARCH_S390_CACHE_H
9628
9629 -#define L1_CACHE_BYTES 256
9630 +#include <linux/const.h>
9631 +
9632 #define L1_CACHE_SHIFT 8
9633 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9634 #define NET_SKB_PAD 32
9635
9636 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9637 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
9638 index 78f4f87..598ce39 100644
9639 --- a/arch/s390/include/asm/elf.h
9640 +++ b/arch/s390/include/asm/elf.h
9641 @@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
9642 the loader. We need to make sure that it is out of the way of the program
9643 that it will "exec", and that there is sufficient room for the brk. */
9644
9645 -extern unsigned long randomize_et_dyn(unsigned long base);
9646 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
9647 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
9648 +
9649 +#ifdef CONFIG_PAX_ASLR
9650 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
9651 +
9652 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9653 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9654 +#endif
9655
9656 /* This yields a mask that user programs can use to figure out what
9657 instruction set this CPU supports. */
9658 @@ -222,9 +228,6 @@ struct linux_binprm;
9659 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
9660 int arch_setup_additional_pages(struct linux_binprm *, int);
9661
9662 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
9663 -#define arch_randomize_brk arch_randomize_brk
9664 -
9665 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
9666
9667 #endif
9668 diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
9669 index c4a93d6..4d2a9b4 100644
9670 --- a/arch/s390/include/asm/exec.h
9671 +++ b/arch/s390/include/asm/exec.h
9672 @@ -7,6 +7,6 @@
9673 #ifndef __ASM_EXEC_H
9674 #define __ASM_EXEC_H
9675
9676 -extern unsigned long arch_align_stack(unsigned long sp);
9677 +#define arch_align_stack(x) ((x) & ~0xfUL)
9678
9679 #endif /* __ASM_EXEC_H */
9680 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
9681 index cd4c68e..6764641 100644
9682 --- a/arch/s390/include/asm/uaccess.h
9683 +++ b/arch/s390/include/asm/uaccess.h
9684 @@ -59,6 +59,7 @@ static inline int __range_ok(unsigned long addr, unsigned long size)
9685 __range_ok((unsigned long)(addr), (size)); \
9686 })
9687
9688 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
9689 #define access_ok(type, addr, size) __access_ok(addr, size)
9690
9691 /*
9692 @@ -275,6 +276,10 @@ static inline unsigned long __must_check
9693 copy_to_user(void __user *to, const void *from, unsigned long n)
9694 {
9695 might_fault();
9696 +
9697 + if ((long)n < 0)
9698 + return n;
9699 +
9700 return __copy_to_user(to, from, n);
9701 }
9702
9703 @@ -303,10 +308,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
9704 static inline unsigned long __must_check
9705 copy_from_user(void *to, const void __user *from, unsigned long n)
9706 {
9707 - unsigned int sz = __compiletime_object_size(to);
9708 + size_t sz = __compiletime_object_size(to);
9709
9710 might_fault();
9711 - if (unlikely(sz != -1 && sz < n)) {
9712 +
9713 + if ((long)n < 0)
9714 + return n;
9715 +
9716 + if (unlikely(sz != (size_t)-1 && sz < n)) {
9717 copy_from_user_overflow();
9718 return n;
9719 }
9720 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
9721 index b89b591..fd9609d 100644
9722 --- a/arch/s390/kernel/module.c
9723 +++ b/arch/s390/kernel/module.c
9724 @@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
9725
9726 /* Increase core size by size of got & plt and set start
9727 offsets for got and plt. */
9728 - me->core_size = ALIGN(me->core_size, 4);
9729 - me->arch.got_offset = me->core_size;
9730 - me->core_size += me->arch.got_size;
9731 - me->arch.plt_offset = me->core_size;
9732 - me->core_size += me->arch.plt_size;
9733 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
9734 + me->arch.got_offset = me->core_size_rw;
9735 + me->core_size_rw += me->arch.got_size;
9736 + me->arch.plt_offset = me->core_size_rx;
9737 + me->core_size_rx += me->arch.plt_size;
9738 return 0;
9739 }
9740
9741 @@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9742 if (info->got_initialized == 0) {
9743 Elf_Addr *gotent;
9744
9745 - gotent = me->module_core + me->arch.got_offset +
9746 + gotent = me->module_core_rw + me->arch.got_offset +
9747 info->got_offset;
9748 *gotent = val;
9749 info->got_initialized = 1;
9750 @@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9751 rc = apply_rela_bits(loc, val, 0, 64, 0);
9752 else if (r_type == R_390_GOTENT ||
9753 r_type == R_390_GOTPLTENT) {
9754 - val += (Elf_Addr) me->module_core - loc;
9755 + val += (Elf_Addr) me->module_core_rw - loc;
9756 rc = apply_rela_bits(loc, val, 1, 32, 1);
9757 }
9758 break;
9759 @@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9760 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
9761 if (info->plt_initialized == 0) {
9762 unsigned int *ip;
9763 - ip = me->module_core + me->arch.plt_offset +
9764 + ip = me->module_core_rx + me->arch.plt_offset +
9765 info->plt_offset;
9766 #ifndef CONFIG_64BIT
9767 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
9768 @@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9769 val - loc + 0xffffUL < 0x1ffffeUL) ||
9770 (r_type == R_390_PLT32DBL &&
9771 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
9772 - val = (Elf_Addr) me->module_core +
9773 + val = (Elf_Addr) me->module_core_rx +
9774 me->arch.plt_offset +
9775 info->plt_offset;
9776 val += rela->r_addend - loc;
9777 @@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9778 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
9779 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
9780 val = val + rela->r_addend -
9781 - ((Elf_Addr) me->module_core + me->arch.got_offset);
9782 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
9783 if (r_type == R_390_GOTOFF16)
9784 rc = apply_rela_bits(loc, val, 0, 16, 0);
9785 else if (r_type == R_390_GOTOFF32)
9786 @@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9787 break;
9788 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
9789 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
9790 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
9791 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
9792 rela->r_addend - loc;
9793 if (r_type == R_390_GOTPC)
9794 rc = apply_rela_bits(loc, val, 1, 32, 0);
9795 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
9796 index 93b9ca4..4ea1454 100644
9797 --- a/arch/s390/kernel/process.c
9798 +++ b/arch/s390/kernel/process.c
9799 @@ -242,37 +242,3 @@ unsigned long get_wchan(struct task_struct *p)
9800 }
9801 return 0;
9802 }
9803 -
9804 -unsigned long arch_align_stack(unsigned long sp)
9805 -{
9806 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
9807 - sp -= get_random_int() & ~PAGE_MASK;
9808 - return sp & ~0xf;
9809 -}
9810 -
9811 -static inline unsigned long brk_rnd(void)
9812 -{
9813 - /* 8MB for 32bit, 1GB for 64bit */
9814 - if (is_32bit_task())
9815 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
9816 - else
9817 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
9818 -}
9819 -
9820 -unsigned long arch_randomize_brk(struct mm_struct *mm)
9821 -{
9822 - unsigned long ret;
9823 -
9824 - ret = PAGE_ALIGN(mm->brk + brk_rnd());
9825 - return (ret > mm->brk) ? ret : mm->brk;
9826 -}
9827 -
9828 -unsigned long randomize_et_dyn(unsigned long base)
9829 -{
9830 - unsigned long ret;
9831 -
9832 - if (!(current->flags & PF_RANDOMIZE))
9833 - return base;
9834 - ret = PAGE_ALIGN(base + brk_rnd());
9835 - return (ret > base) ? ret : base;
9836 -}
9837 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
9838 index 9b436c2..54fbf0a 100644
9839 --- a/arch/s390/mm/mmap.c
9840 +++ b/arch/s390/mm/mmap.c
9841 @@ -95,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9842 */
9843 if (mmap_is_legacy()) {
9844 mm->mmap_base = mmap_base_legacy();
9845 +
9846 +#ifdef CONFIG_PAX_RANDMMAP
9847 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9848 + mm->mmap_base += mm->delta_mmap;
9849 +#endif
9850 +
9851 mm->get_unmapped_area = arch_get_unmapped_area;
9852 } else {
9853 mm->mmap_base = mmap_base();
9854 +
9855 +#ifdef CONFIG_PAX_RANDMMAP
9856 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9857 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9858 +#endif
9859 +
9860 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9861 }
9862 }
9863 @@ -170,9 +182,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 = s390_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 = s390_get_unmapped_area_topdown;
9883 }
9884 }
9885 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
9886 index ae3d59f..f65f075 100644
9887 --- a/arch/score/include/asm/cache.h
9888 +++ b/arch/score/include/asm/cache.h
9889 @@ -1,7 +1,9 @@
9890 #ifndef _ASM_SCORE_CACHE_H
9891 #define _ASM_SCORE_CACHE_H
9892
9893 +#include <linux/const.h>
9894 +
9895 #define L1_CACHE_SHIFT 4
9896 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9897 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9898
9899 #endif /* _ASM_SCORE_CACHE_H */
9900 diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
9901 index f9f3cd5..58ff438 100644
9902 --- a/arch/score/include/asm/exec.h
9903 +++ b/arch/score/include/asm/exec.h
9904 @@ -1,6 +1,6 @@
9905 #ifndef _ASM_SCORE_EXEC_H
9906 #define _ASM_SCORE_EXEC_H
9907
9908 -extern unsigned long arch_align_stack(unsigned long sp);
9909 +#define arch_align_stack(x) (x)
9910
9911 #endif /* _ASM_SCORE_EXEC_H */
9912 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
9913 index a1519ad3..e8ac1ff 100644
9914 --- a/arch/score/kernel/process.c
9915 +++ b/arch/score/kernel/process.c
9916 @@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
9917
9918 return task_pt_regs(task)->cp0_epc;
9919 }
9920 -
9921 -unsigned long arch_align_stack(unsigned long sp)
9922 -{
9923 - return sp;
9924 -}
9925 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
9926 index ef9e555..331bd29 100644
9927 --- a/arch/sh/include/asm/cache.h
9928 +++ b/arch/sh/include/asm/cache.h
9929 @@ -9,10 +9,11 @@
9930 #define __ASM_SH_CACHE_H
9931 #ifdef __KERNEL__
9932
9933 +#include <linux/const.h>
9934 #include <linux/init.h>
9935 #include <cpu/cache.h>
9936
9937 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9938 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9939
9940 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9941
9942 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
9943 index 6777177..cb5e44f 100644
9944 --- a/arch/sh/mm/mmap.c
9945 +++ b/arch/sh/mm/mmap.c
9946 @@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9947 struct mm_struct *mm = current->mm;
9948 struct vm_area_struct *vma;
9949 int do_colour_align;
9950 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9951 struct vm_unmapped_area_info info;
9952
9953 if (flags & MAP_FIXED) {
9954 @@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9955 if (filp || (flags & MAP_SHARED))
9956 do_colour_align = 1;
9957
9958 +#ifdef CONFIG_PAX_RANDMMAP
9959 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9960 +#endif
9961 +
9962 if (addr) {
9963 if (do_colour_align)
9964 addr = COLOUR_ALIGN(addr, pgoff);
9965 @@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9966 addr = PAGE_ALIGN(addr);
9967
9968 vma = find_vma(mm, addr);
9969 - if (TASK_SIZE - len >= addr &&
9970 - (!vma || addr + len <= vma->vm_start))
9971 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9972 return addr;
9973 }
9974
9975 info.flags = 0;
9976 info.length = len;
9977 - info.low_limit = TASK_UNMAPPED_BASE;
9978 + info.low_limit = mm->mmap_base;
9979 info.high_limit = TASK_SIZE;
9980 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
9981 info.align_offset = pgoff << PAGE_SHIFT;
9982 @@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9983 struct mm_struct *mm = current->mm;
9984 unsigned long addr = addr0;
9985 int do_colour_align;
9986 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9987 struct vm_unmapped_area_info info;
9988
9989 if (flags & MAP_FIXED) {
9990 @@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9991 if (filp || (flags & MAP_SHARED))
9992 do_colour_align = 1;
9993
9994 +#ifdef CONFIG_PAX_RANDMMAP
9995 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9996 +#endif
9997 +
9998 /* requesting a specific address */
9999 if (addr) {
10000 if (do_colour_align)
10001 @@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10002 addr = PAGE_ALIGN(addr);
10003
10004 vma = find_vma(mm, addr);
10005 - if (TASK_SIZE - len >= addr &&
10006 - (!vma || addr + len <= vma->vm_start))
10007 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10008 return addr;
10009 }
10010
10011 @@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10012 VM_BUG_ON(addr != -ENOMEM);
10013 info.flags = 0;
10014 info.low_limit = TASK_UNMAPPED_BASE;
10015 +
10016 +#ifdef CONFIG_PAX_RANDMMAP
10017 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10018 + info.low_limit += mm->delta_mmap;
10019 +#endif
10020 +
10021 info.high_limit = TASK_SIZE;
10022 addr = vm_unmapped_area(&info);
10023 }
10024 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
10025 index bb894c8..8141d5c 100644
10026 --- a/arch/sparc/include/asm/atomic_64.h
10027 +++ b/arch/sparc/include/asm/atomic_64.h
10028 @@ -15,18 +15,40 @@
10029 #define ATOMIC64_INIT(i) { (i) }
10030
10031 #define atomic_read(v) (*(volatile int *)&(v)->counter)
10032 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
10033 +{
10034 + return v->counter;
10035 +}
10036 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
10037 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
10038 +{
10039 + return v->counter;
10040 +}
10041
10042 #define atomic_set(v, i) (((v)->counter) = i)
10043 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
10044 +{
10045 + v->counter = i;
10046 +}
10047 #define atomic64_set(v, i) (((v)->counter) = i)
10048 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
10049 +{
10050 + v->counter = i;
10051 +}
10052
10053 void atomic_add(int, atomic_t *);
10054 +void atomic_add_unchecked(int, atomic_unchecked_t *);
10055 void atomic64_add(long, atomic64_t *);
10056 +void atomic64_add_unchecked(long, atomic64_unchecked_t *);
10057 void atomic_sub(int, atomic_t *);
10058 +void atomic_sub_unchecked(int, atomic_unchecked_t *);
10059 void atomic64_sub(long, atomic64_t *);
10060 +void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
10061
10062 int atomic_add_ret(int, atomic_t *);
10063 +int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
10064 long atomic64_add_ret(long, atomic64_t *);
10065 +long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
10066 int atomic_sub_ret(int, atomic_t *);
10067 long atomic64_sub_ret(long, atomic64_t *);
10068
10069 @@ -34,13 +56,29 @@ long atomic64_sub_ret(long, atomic64_t *);
10070 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
10071
10072 #define atomic_inc_return(v) atomic_add_ret(1, v)
10073 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
10074 +{
10075 + return atomic_add_ret_unchecked(1, v);
10076 +}
10077 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
10078 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
10079 +{
10080 + return atomic64_add_ret_unchecked(1, v);
10081 +}
10082
10083 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
10084 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
10085
10086 #define atomic_add_return(i, v) atomic_add_ret(i, v)
10087 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
10088 +{
10089 + return atomic_add_ret_unchecked(i, v);
10090 +}
10091 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
10092 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
10093 +{
10094 + return atomic64_add_ret_unchecked(i, v);
10095 +}
10096
10097 /*
10098 * atomic_inc_and_test - increment and test
10099 @@ -51,6 +89,10 @@ long atomic64_sub_ret(long, atomic64_t *);
10100 * other cases.
10101 */
10102 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
10103 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
10104 +{
10105 + return atomic_inc_return_unchecked(v) == 0;
10106 +}
10107 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
10108
10109 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
10110 @@ -60,25 +102,60 @@ long atomic64_sub_ret(long, atomic64_t *);
10111 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
10112
10113 #define atomic_inc(v) atomic_add(1, v)
10114 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
10115 +{
10116 + atomic_add_unchecked(1, v);
10117 +}
10118 #define atomic64_inc(v) atomic64_add(1, v)
10119 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
10120 +{
10121 + atomic64_add_unchecked(1, v);
10122 +}
10123
10124 #define atomic_dec(v) atomic_sub(1, v)
10125 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
10126 +{
10127 + atomic_sub_unchecked(1, v);
10128 +}
10129 #define atomic64_dec(v) atomic64_sub(1, v)
10130 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
10131 +{
10132 + atomic64_sub_unchecked(1, v);
10133 +}
10134
10135 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
10136 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
10137
10138 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
10139 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
10140 +{
10141 + return cmpxchg(&v->counter, old, new);
10142 +}
10143 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
10144 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
10145 +{
10146 + return xchg(&v->counter, new);
10147 +}
10148
10149 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
10150 {
10151 - int c, old;
10152 + int c, old, new;
10153 c = atomic_read(v);
10154 for (;;) {
10155 - if (unlikely(c == (u)))
10156 + if (unlikely(c == u))
10157 break;
10158 - old = atomic_cmpxchg((v), c, c + (a));
10159 +
10160 + asm volatile("addcc %2, %0, %0\n"
10161 +
10162 +#ifdef CONFIG_PAX_REFCOUNT
10163 + "tvs %%icc, 6\n"
10164 +#endif
10165 +
10166 + : "=r" (new)
10167 + : "0" (c), "ir" (a)
10168 + : "cc");
10169 +
10170 + old = atomic_cmpxchg(v, c, new);
10171 if (likely(old == c))
10172 break;
10173 c = old;
10174 @@ -89,20 +166,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
10175 #define atomic64_cmpxchg(v, o, n) \
10176 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
10177 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
10178 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
10179 +{
10180 + return xchg(&v->counter, new);
10181 +}
10182
10183 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
10184 {
10185 - long c, old;
10186 + long c, old, new;
10187 c = atomic64_read(v);
10188 for (;;) {
10189 - if (unlikely(c == (u)))
10190 + if (unlikely(c == u))
10191 break;
10192 - old = atomic64_cmpxchg((v), c, c + (a));
10193 +
10194 + asm volatile("addcc %2, %0, %0\n"
10195 +
10196 +#ifdef CONFIG_PAX_REFCOUNT
10197 + "tvs %%xcc, 6\n"
10198 +#endif
10199 +
10200 + : "=r" (new)
10201 + : "0" (c), "ir" (a)
10202 + : "cc");
10203 +
10204 + old = atomic64_cmpxchg(v, c, new);
10205 if (likely(old == c))
10206 break;
10207 c = old;
10208 }
10209 - return c != (u);
10210 + return c != u;
10211 }
10212
10213 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10214 diff --git a/arch/sparc/include/asm/barrier_64.h b/arch/sparc/include/asm/barrier_64.h
10215 index 305dcc3..7835030 100644
10216 --- a/arch/sparc/include/asm/barrier_64.h
10217 +++ b/arch/sparc/include/asm/barrier_64.h
10218 @@ -57,7 +57,7 @@ do { __asm__ __volatile__("ba,pt %%xcc, 1f\n\t" \
10219 do { \
10220 compiletime_assert_atomic_type(*p); \
10221 barrier(); \
10222 - ACCESS_ONCE(*p) = (v); \
10223 + ACCESS_ONCE_RW(*p) = (v); \
10224 } while (0)
10225
10226 #define smp_load_acquire(p) \
10227 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
10228 index 5bb6991..5c2132e 100644
10229 --- a/arch/sparc/include/asm/cache.h
10230 +++ b/arch/sparc/include/asm/cache.h
10231 @@ -7,10 +7,12 @@
10232 #ifndef _SPARC_CACHE_H
10233 #define _SPARC_CACHE_H
10234
10235 +#include <linux/const.h>
10236 +
10237 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
10238
10239 #define L1_CACHE_SHIFT 5
10240 -#define L1_CACHE_BYTES 32
10241 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10242
10243 #ifdef CONFIG_SPARC32
10244 #define SMP_CACHE_BYTES_SHIFT 5
10245 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
10246 index a24e41f..47677ff 100644
10247 --- a/arch/sparc/include/asm/elf_32.h
10248 +++ b/arch/sparc/include/asm/elf_32.h
10249 @@ -114,6 +114,13 @@ typedef struct {
10250
10251 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
10252
10253 +#ifdef CONFIG_PAX_ASLR
10254 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
10255 +
10256 +#define PAX_DELTA_MMAP_LEN 16
10257 +#define PAX_DELTA_STACK_LEN 16
10258 +#endif
10259 +
10260 /* This yields a mask that user programs can use to figure out what
10261 instruction set this cpu supports. This can NOT be done in userspace
10262 on Sparc. */
10263 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
10264 index 370ca1e..d4f4a98 100644
10265 --- a/arch/sparc/include/asm/elf_64.h
10266 +++ b/arch/sparc/include/asm/elf_64.h
10267 @@ -189,6 +189,13 @@ typedef struct {
10268 #define ELF_ET_DYN_BASE 0x0000010000000000UL
10269 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
10270
10271 +#ifdef CONFIG_PAX_ASLR
10272 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
10273 +
10274 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
10275 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
10276 +#endif
10277 +
10278 extern unsigned long sparc64_elf_hwcap;
10279 #define ELF_HWCAP sparc64_elf_hwcap
10280
10281 diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
10282 index a3890da..f6a408e 100644
10283 --- a/arch/sparc/include/asm/pgalloc_32.h
10284 +++ b/arch/sparc/include/asm/pgalloc_32.h
10285 @@ -35,6 +35,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
10286 }
10287
10288 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
10289 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
10290
10291 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
10292 unsigned long address)
10293 diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
10294 index 39a7ac4..2c9b586 100644
10295 --- a/arch/sparc/include/asm/pgalloc_64.h
10296 +++ b/arch/sparc/include/asm/pgalloc_64.h
10297 @@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
10298 }
10299
10300 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
10301 +#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
10302
10303 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
10304 {
10305 diff --git a/arch/sparc/include/asm/pgtable.h b/arch/sparc/include/asm/pgtable.h
10306 index 59ba6f6..4518128 100644
10307 --- a/arch/sparc/include/asm/pgtable.h
10308 +++ b/arch/sparc/include/asm/pgtable.h
10309 @@ -5,4 +5,8 @@
10310 #else
10311 #include <asm/pgtable_32.h>
10312 #endif
10313 +
10314 +#define ktla_ktva(addr) (addr)
10315 +#define ktva_ktla(addr) (addr)
10316 +
10317 #endif
10318 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
10319 index b9b91ae..950b91e 100644
10320 --- a/arch/sparc/include/asm/pgtable_32.h
10321 +++ b/arch/sparc/include/asm/pgtable_32.h
10322 @@ -51,6 +51,9 @@ unsigned long __init bootmem_init(unsigned long *pages_avail);
10323 #define PAGE_SHARED SRMMU_PAGE_SHARED
10324 #define PAGE_COPY SRMMU_PAGE_COPY
10325 #define PAGE_READONLY SRMMU_PAGE_RDONLY
10326 +#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
10327 +#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
10328 +#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
10329 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
10330
10331 /* Top-level page directory - dummy used by init-mm.
10332 @@ -63,18 +66,18 @@ extern unsigned long ptr_in_current_pgd;
10333
10334 /* xwr */
10335 #define __P000 PAGE_NONE
10336 -#define __P001 PAGE_READONLY
10337 -#define __P010 PAGE_COPY
10338 -#define __P011 PAGE_COPY
10339 +#define __P001 PAGE_READONLY_NOEXEC
10340 +#define __P010 PAGE_COPY_NOEXEC
10341 +#define __P011 PAGE_COPY_NOEXEC
10342 #define __P100 PAGE_READONLY
10343 #define __P101 PAGE_READONLY
10344 #define __P110 PAGE_COPY
10345 #define __P111 PAGE_COPY
10346
10347 #define __S000 PAGE_NONE
10348 -#define __S001 PAGE_READONLY
10349 -#define __S010 PAGE_SHARED
10350 -#define __S011 PAGE_SHARED
10351 +#define __S001 PAGE_READONLY_NOEXEC
10352 +#define __S010 PAGE_SHARED_NOEXEC
10353 +#define __S011 PAGE_SHARED_NOEXEC
10354 #define __S100 PAGE_READONLY
10355 #define __S101 PAGE_READONLY
10356 #define __S110 PAGE_SHARED
10357 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
10358 index 79da178..c2eede8 100644
10359 --- a/arch/sparc/include/asm/pgtsrmmu.h
10360 +++ b/arch/sparc/include/asm/pgtsrmmu.h
10361 @@ -115,6 +115,11 @@
10362 SRMMU_EXEC | SRMMU_REF)
10363 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
10364 SRMMU_EXEC | SRMMU_REF)
10365 +
10366 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
10367 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
10368 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
10369 +
10370 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
10371 SRMMU_DIRTY | SRMMU_REF)
10372
10373 diff --git a/arch/sparc/include/asm/setup.h b/arch/sparc/include/asm/setup.h
10374 index f5fffd8..a0669f0 100644
10375 --- a/arch/sparc/include/asm/setup.h
10376 +++ b/arch/sparc/include/asm/setup.h
10377 @@ -53,8 +53,8 @@ int handle_ldf_stq(u32 insn, struct pt_regs *regs);
10378 void handle_ld_nf(u32 insn, struct pt_regs *regs);
10379
10380 /* init_64.c */
10381 -extern atomic_t dcpage_flushes;
10382 -extern atomic_t dcpage_flushes_xcall;
10383 +extern atomic_unchecked_t dcpage_flushes;
10384 +extern atomic_unchecked_t dcpage_flushes_xcall;
10385
10386 extern int sysctl_tsb_ratio;
10387 #endif
10388 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
10389 index 9689176..63c18ea 100644
10390 --- a/arch/sparc/include/asm/spinlock_64.h
10391 +++ b/arch/sparc/include/asm/spinlock_64.h
10392 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
10393
10394 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
10395
10396 -static void inline arch_read_lock(arch_rwlock_t *lock)
10397 +static inline void arch_read_lock(arch_rwlock_t *lock)
10398 {
10399 unsigned long tmp1, tmp2;
10400
10401 __asm__ __volatile__ (
10402 "1: ldsw [%2], %0\n"
10403 " brlz,pn %0, 2f\n"
10404 -"4: add %0, 1, %1\n"
10405 +"4: addcc %0, 1, %1\n"
10406 +
10407 +#ifdef CONFIG_PAX_REFCOUNT
10408 +" tvs %%icc, 6\n"
10409 +#endif
10410 +
10411 " cas [%2], %0, %1\n"
10412 " cmp %0, %1\n"
10413 " bne,pn %%icc, 1b\n"
10414 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
10415 " .previous"
10416 : "=&r" (tmp1), "=&r" (tmp2)
10417 : "r" (lock)
10418 - : "memory");
10419 + : "memory", "cc");
10420 }
10421
10422 -static int inline arch_read_trylock(arch_rwlock_t *lock)
10423 +static inline int arch_read_trylock(arch_rwlock_t *lock)
10424 {
10425 int tmp1, tmp2;
10426
10427 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
10428 "1: ldsw [%2], %0\n"
10429 " brlz,a,pn %0, 2f\n"
10430 " mov 0, %0\n"
10431 -" add %0, 1, %1\n"
10432 +" addcc %0, 1, %1\n"
10433 +
10434 +#ifdef CONFIG_PAX_REFCOUNT
10435 +" tvs %%icc, 6\n"
10436 +#endif
10437 +
10438 " cas [%2], %0, %1\n"
10439 " cmp %0, %1\n"
10440 " bne,pn %%icc, 1b\n"
10441 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
10442 return tmp1;
10443 }
10444
10445 -static void inline arch_read_unlock(arch_rwlock_t *lock)
10446 +static inline void arch_read_unlock(arch_rwlock_t *lock)
10447 {
10448 unsigned long tmp1, tmp2;
10449
10450 __asm__ __volatile__(
10451 "1: lduw [%2], %0\n"
10452 -" sub %0, 1, %1\n"
10453 +" subcc %0, 1, %1\n"
10454 +
10455 +#ifdef CONFIG_PAX_REFCOUNT
10456 +" tvs %%icc, 6\n"
10457 +#endif
10458 +
10459 " cas [%2], %0, %1\n"
10460 " cmp %0, %1\n"
10461 " bne,pn %%xcc, 1b\n"
10462 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
10463 : "memory");
10464 }
10465
10466 -static void inline arch_write_lock(arch_rwlock_t *lock)
10467 +static inline void arch_write_lock(arch_rwlock_t *lock)
10468 {
10469 unsigned long mask, tmp1, tmp2;
10470
10471 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
10472 : "memory");
10473 }
10474
10475 -static void inline arch_write_unlock(arch_rwlock_t *lock)
10476 +static inline void arch_write_unlock(arch_rwlock_t *lock)
10477 {
10478 __asm__ __volatile__(
10479 " stw %%g0, [%0]"
10480 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
10481 : "memory");
10482 }
10483
10484 -static int inline arch_write_trylock(arch_rwlock_t *lock)
10485 +static inline int arch_write_trylock(arch_rwlock_t *lock)
10486 {
10487 unsigned long mask, tmp1, tmp2, result;
10488
10489 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
10490 index 96efa7a..16858bf 100644
10491 --- a/arch/sparc/include/asm/thread_info_32.h
10492 +++ b/arch/sparc/include/asm/thread_info_32.h
10493 @@ -49,6 +49,8 @@ struct thread_info {
10494 unsigned long w_saved;
10495
10496 struct restart_block restart_block;
10497 +
10498 + unsigned long lowest_stack;
10499 };
10500
10501 /*
10502 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
10503 index a5f01ac..703b554 100644
10504 --- a/arch/sparc/include/asm/thread_info_64.h
10505 +++ b/arch/sparc/include/asm/thread_info_64.h
10506 @@ -63,6 +63,8 @@ struct thread_info {
10507 struct pt_regs *kern_una_regs;
10508 unsigned int kern_una_insn;
10509
10510 + unsigned long lowest_stack;
10511 +
10512 unsigned long fpregs[0] __attribute__ ((aligned(64)));
10513 };
10514
10515 @@ -188,12 +190,13 @@ register struct thread_info *current_thread_info_reg asm("g6");
10516 #define TIF_NEED_RESCHED 3 /* rescheduling necessary */
10517 /* flag bit 4 is available */
10518 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
10519 -/* flag bit 6 is available */
10520 +#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
10521 #define TIF_32BIT 7 /* 32-bit binary */
10522 #define TIF_NOHZ 8 /* in adaptive nohz mode */
10523 #define TIF_SECCOMP 9 /* secure computing */
10524 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
10525 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
10526 +
10527 /* NOTE: Thread flags >= 12 should be ones we have no interest
10528 * in using in assembly, else we can't use the mask as
10529 * an immediate value in instructions such as andcc.
10530 @@ -213,12 +216,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
10531 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
10532 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
10533 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
10534 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
10535
10536 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
10537 _TIF_DO_NOTIFY_RESUME_MASK | \
10538 _TIF_NEED_RESCHED)
10539 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
10540
10541 +#define _TIF_WORK_SYSCALL \
10542 + (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
10543 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
10544 +
10545 +
10546 /*
10547 * Thread-synchronous status.
10548 *
10549 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
10550 index bd56c28..4b63d83 100644
10551 --- a/arch/sparc/include/asm/uaccess.h
10552 +++ b/arch/sparc/include/asm/uaccess.h
10553 @@ -1,5 +1,6 @@
10554 #ifndef ___ASM_SPARC_UACCESS_H
10555 #define ___ASM_SPARC_UACCESS_H
10556 +
10557 #if defined(__sparc__) && defined(__arch64__)
10558 #include <asm/uaccess_64.h>
10559 #else
10560 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
10561 index 9634d08..f55fe4f 100644
10562 --- a/arch/sparc/include/asm/uaccess_32.h
10563 +++ b/arch/sparc/include/asm/uaccess_32.h
10564 @@ -250,27 +250,46 @@ unsigned long __copy_user(void __user *to, const void __user *from, unsigned lon
10565
10566 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
10567 {
10568 - if (n && __access_ok((unsigned long) to, n))
10569 + if ((long)n < 0)
10570 + return n;
10571 +
10572 + if (n && __access_ok((unsigned long) to, n)) {
10573 + if (!__builtin_constant_p(n))
10574 + check_object_size(from, n, true);
10575 return __copy_user(to, (__force void __user *) from, n);
10576 - else
10577 + } else
10578 return n;
10579 }
10580
10581 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
10582 {
10583 + if ((long)n < 0)
10584 + return n;
10585 +
10586 + if (!__builtin_constant_p(n))
10587 + check_object_size(from, n, true);
10588 +
10589 return __copy_user(to, (__force void __user *) from, n);
10590 }
10591
10592 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
10593 {
10594 - if (n && __access_ok((unsigned long) from, n))
10595 + if ((long)n < 0)
10596 + return n;
10597 +
10598 + if (n && __access_ok((unsigned long) from, n)) {
10599 + if (!__builtin_constant_p(n))
10600 + check_object_size(to, n, false);
10601 return __copy_user((__force void __user *) to, from, n);
10602 - else
10603 + } else
10604 return n;
10605 }
10606
10607 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
10608 {
10609 + if ((long)n < 0)
10610 + return n;
10611 +
10612 return __copy_user((__force void __user *) to, from, n);
10613 }
10614
10615 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
10616 index c990a5e..f17b9c1 100644
10617 --- a/arch/sparc/include/asm/uaccess_64.h
10618 +++ b/arch/sparc/include/asm/uaccess_64.h
10619 @@ -10,6 +10,7 @@
10620 #include <linux/compiler.h>
10621 #include <linux/string.h>
10622 #include <linux/thread_info.h>
10623 +#include <linux/kernel.h>
10624 #include <asm/asi.h>
10625 #include <asm/spitfire.h>
10626 #include <asm-generic/uaccess-unaligned.h>
10627 @@ -214,8 +215,15 @@ unsigned long copy_from_user_fixup(void *to, const void __user *from,
10628 static inline unsigned long __must_check
10629 copy_from_user(void *to, const void __user *from, unsigned long size)
10630 {
10631 - unsigned long ret = ___copy_from_user(to, from, size);
10632 + unsigned long ret;
10633
10634 + if ((long)size < 0 || size > INT_MAX)
10635 + return size;
10636 +
10637 + if (!__builtin_constant_p(size))
10638 + check_object_size(to, size, false);
10639 +
10640 + ret = ___copy_from_user(to, from, size);
10641 if (unlikely(ret))
10642 ret = copy_from_user_fixup(to, from, size);
10643
10644 @@ -231,8 +239,15 @@ unsigned long copy_to_user_fixup(void __user *to, const void *from,
10645 static inline unsigned long __must_check
10646 copy_to_user(void __user *to, const void *from, unsigned long size)
10647 {
10648 - unsigned long ret = ___copy_to_user(to, from, size);
10649 + unsigned long ret;
10650
10651 + if ((long)size < 0 || size > INT_MAX)
10652 + return size;
10653 +
10654 + if (!__builtin_constant_p(size))
10655 + check_object_size(from, size, true);
10656 +
10657 + ret = ___copy_to_user(to, from, size);
10658 if (unlikely(ret))
10659 ret = copy_to_user_fixup(to, from, size);
10660 return ret;
10661 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
10662 index 7cf9c6e..6206648 100644
10663 --- a/arch/sparc/kernel/Makefile
10664 +++ b/arch/sparc/kernel/Makefile
10665 @@ -4,7 +4,7 @@
10666 #
10667
10668 asflags-y := -ansi
10669 -ccflags-y := -Werror
10670 +#ccflags-y := -Werror
10671
10672 extra-y := head_$(BITS).o
10673
10674 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
10675 index 50e7b62..79fae35 100644
10676 --- a/arch/sparc/kernel/process_32.c
10677 +++ b/arch/sparc/kernel/process_32.c
10678 @@ -123,14 +123,14 @@ void show_regs(struct pt_regs *r)
10679
10680 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
10681 r->psr, r->pc, r->npc, r->y, print_tainted());
10682 - printk("PC: <%pS>\n", (void *) r->pc);
10683 + printk("PC: <%pA>\n", (void *) r->pc);
10684 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10685 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
10686 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
10687 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10688 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
10689 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
10690 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
10691 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
10692
10693 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10694 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
10695 @@ -167,7 +167,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10696 rw = (struct reg_window32 *) fp;
10697 pc = rw->ins[7];
10698 printk("[%08lx : ", pc);
10699 - printk("%pS ] ", (void *) pc);
10700 + printk("%pA ] ", (void *) pc);
10701 fp = rw->ins[6];
10702 } while (++count < 16);
10703 printk("\n");
10704 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
10705 index 027e099..6d4178f 100644
10706 --- a/arch/sparc/kernel/process_64.c
10707 +++ b/arch/sparc/kernel/process_64.c
10708 @@ -161,7 +161,7 @@ static void show_regwindow(struct pt_regs *regs)
10709 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
10710 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
10711 if (regs->tstate & TSTATE_PRIV)
10712 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
10713 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
10714 }
10715
10716 void show_regs(struct pt_regs *regs)
10717 @@ -170,7 +170,7 @@ void show_regs(struct pt_regs *regs)
10718
10719 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
10720 regs->tpc, regs->tnpc, regs->y, print_tainted());
10721 - printk("TPC: <%pS>\n", (void *) regs->tpc);
10722 + printk("TPC: <%pA>\n", (void *) regs->tpc);
10723 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
10724 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
10725 regs->u_regs[3]);
10726 @@ -183,7 +183,7 @@ void show_regs(struct pt_regs *regs)
10727 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
10728 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
10729 regs->u_regs[15]);
10730 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
10731 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
10732 show_regwindow(regs);
10733 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
10734 }
10735 @@ -278,7 +278,7 @@ void arch_trigger_all_cpu_backtrace(bool include_self)
10736 ((tp && tp->task) ? tp->task->pid : -1));
10737
10738 if (gp->tstate & TSTATE_PRIV) {
10739 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
10740 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
10741 (void *) gp->tpc,
10742 (void *) gp->o7,
10743 (void *) gp->i7,
10744 diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
10745 index 79cc0d1..ec62734 100644
10746 --- a/arch/sparc/kernel/prom_common.c
10747 +++ b/arch/sparc/kernel/prom_common.c
10748 @@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
10749
10750 unsigned int prom_early_allocated __initdata;
10751
10752 -static struct of_pdt_ops prom_sparc_ops __initdata = {
10753 +static struct of_pdt_ops prom_sparc_ops __initconst = {
10754 .nextprop = prom_common_nextprop,
10755 .getproplen = prom_getproplen,
10756 .getproperty = prom_getproperty,
10757 diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
10758 index c13c9f2..d572c34 100644
10759 --- a/arch/sparc/kernel/ptrace_64.c
10760 +++ b/arch/sparc/kernel/ptrace_64.c
10761 @@ -1060,6 +1060,10 @@ long arch_ptrace(struct task_struct *child, long request,
10762 return ret;
10763 }
10764
10765 +#ifdef CONFIG_GRKERNSEC_SETXID
10766 +extern void gr_delayed_cred_worker(void);
10767 +#endif
10768 +
10769 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10770 {
10771 int ret = 0;
10772 @@ -1070,6 +1074,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10773 if (test_thread_flag(TIF_NOHZ))
10774 user_exit();
10775
10776 +#ifdef CONFIG_GRKERNSEC_SETXID
10777 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10778 + gr_delayed_cred_worker();
10779 +#endif
10780 +
10781 if (test_thread_flag(TIF_SYSCALL_TRACE))
10782 ret = tracehook_report_syscall_entry(regs);
10783
10784 @@ -1093,6 +1102,11 @@ asmlinkage void syscall_trace_leave(struct pt_regs *regs)
10785 if (test_thread_flag(TIF_NOHZ))
10786 user_exit();
10787
10788 +#ifdef CONFIG_GRKERNSEC_SETXID
10789 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10790 + gr_delayed_cred_worker();
10791 +#endif
10792 +
10793 audit_syscall_exit(regs);
10794
10795 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
10796 diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
10797 index 41aa247..eadfb74 100644
10798 --- a/arch/sparc/kernel/smp_64.c
10799 +++ b/arch/sparc/kernel/smp_64.c
10800 @@ -883,7 +883,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10801 return;
10802
10803 #ifdef CONFIG_DEBUG_DCFLUSH
10804 - atomic_inc(&dcpage_flushes);
10805 + atomic_inc_unchecked(&dcpage_flushes);
10806 #endif
10807
10808 this_cpu = get_cpu();
10809 @@ -907,7 +907,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10810 xcall_deliver(data0, __pa(pg_addr),
10811 (u64) pg_addr, cpumask_of(cpu));
10812 #ifdef CONFIG_DEBUG_DCFLUSH
10813 - atomic_inc(&dcpage_flushes_xcall);
10814 + atomic_inc_unchecked(&dcpage_flushes_xcall);
10815 #endif
10816 }
10817 }
10818 @@ -926,7 +926,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10819 preempt_disable();
10820
10821 #ifdef CONFIG_DEBUG_DCFLUSH
10822 - atomic_inc(&dcpage_flushes);
10823 + atomic_inc_unchecked(&dcpage_flushes);
10824 #endif
10825 data0 = 0;
10826 pg_addr = page_address(page);
10827 @@ -943,7 +943,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10828 xcall_deliver(data0, __pa(pg_addr),
10829 (u64) pg_addr, cpu_online_mask);
10830 #ifdef CONFIG_DEBUG_DCFLUSH
10831 - atomic_inc(&dcpage_flushes_xcall);
10832 + atomic_inc_unchecked(&dcpage_flushes_xcall);
10833 #endif
10834 }
10835 __local_flush_dcache_page(page);
10836 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
10837 index 646988d..b88905f 100644
10838 --- a/arch/sparc/kernel/sys_sparc_32.c
10839 +++ b/arch/sparc/kernel/sys_sparc_32.c
10840 @@ -54,7 +54,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10841 if (len > TASK_SIZE - PAGE_SIZE)
10842 return -ENOMEM;
10843 if (!addr)
10844 - addr = TASK_UNMAPPED_BASE;
10845 + addr = current->mm->mmap_base;
10846
10847 info.flags = 0;
10848 info.length = len;
10849 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
10850 index c85403d..6af95c9 100644
10851 --- a/arch/sparc/kernel/sys_sparc_64.c
10852 +++ b/arch/sparc/kernel/sys_sparc_64.c
10853 @@ -89,13 +89,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10854 struct vm_area_struct * vma;
10855 unsigned long task_size = TASK_SIZE;
10856 int do_color_align;
10857 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10858 struct vm_unmapped_area_info info;
10859
10860 if (flags & MAP_FIXED) {
10861 /* We do not accept a shared mapping if it would violate
10862 * cache aliasing constraints.
10863 */
10864 - if ((flags & MAP_SHARED) &&
10865 + if ((filp || (flags & MAP_SHARED)) &&
10866 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10867 return -EINVAL;
10868 return addr;
10869 @@ -110,6 +111,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10870 if (filp || (flags & MAP_SHARED))
10871 do_color_align = 1;
10872
10873 +#ifdef CONFIG_PAX_RANDMMAP
10874 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10875 +#endif
10876 +
10877 if (addr) {
10878 if (do_color_align)
10879 addr = COLOR_ALIGN(addr, pgoff);
10880 @@ -117,22 +122,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10881 addr = PAGE_ALIGN(addr);
10882
10883 vma = find_vma(mm, addr);
10884 - if (task_size - len >= addr &&
10885 - (!vma || addr + len <= vma->vm_start))
10886 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10887 return addr;
10888 }
10889
10890 info.flags = 0;
10891 info.length = len;
10892 - info.low_limit = TASK_UNMAPPED_BASE;
10893 + info.low_limit = mm->mmap_base;
10894 info.high_limit = min(task_size, VA_EXCLUDE_START);
10895 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10896 info.align_offset = pgoff << PAGE_SHIFT;
10897 + info.threadstack_offset = offset;
10898 addr = vm_unmapped_area(&info);
10899
10900 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
10901 VM_BUG_ON(addr != -ENOMEM);
10902 info.low_limit = VA_EXCLUDE_END;
10903 +
10904 +#ifdef CONFIG_PAX_RANDMMAP
10905 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10906 + info.low_limit += mm->delta_mmap;
10907 +#endif
10908 +
10909 info.high_limit = task_size;
10910 addr = vm_unmapped_area(&info);
10911 }
10912 @@ -150,6 +161,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10913 unsigned long task_size = STACK_TOP32;
10914 unsigned long addr = addr0;
10915 int do_color_align;
10916 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10917 struct vm_unmapped_area_info info;
10918
10919 /* This should only ever run for 32-bit processes. */
10920 @@ -159,7 +171,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10921 /* We do not accept a shared mapping if it would violate
10922 * cache aliasing constraints.
10923 */
10924 - if ((flags & MAP_SHARED) &&
10925 + if ((filp || (flags & MAP_SHARED)) &&
10926 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10927 return -EINVAL;
10928 return addr;
10929 @@ -172,6 +184,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10930 if (filp || (flags & MAP_SHARED))
10931 do_color_align = 1;
10932
10933 +#ifdef CONFIG_PAX_RANDMMAP
10934 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10935 +#endif
10936 +
10937 /* requesting a specific address */
10938 if (addr) {
10939 if (do_color_align)
10940 @@ -180,8 +196,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10941 addr = PAGE_ALIGN(addr);
10942
10943 vma = find_vma(mm, addr);
10944 - if (task_size - len >= addr &&
10945 - (!vma || addr + len <= vma->vm_start))
10946 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10947 return addr;
10948 }
10949
10950 @@ -191,6 +206,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10951 info.high_limit = mm->mmap_base;
10952 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10953 info.align_offset = pgoff << PAGE_SHIFT;
10954 + info.threadstack_offset = offset;
10955 addr = vm_unmapped_area(&info);
10956
10957 /*
10958 @@ -203,6 +219,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10959 VM_BUG_ON(addr != -ENOMEM);
10960 info.flags = 0;
10961 info.low_limit = TASK_UNMAPPED_BASE;
10962 +
10963 +#ifdef CONFIG_PAX_RANDMMAP
10964 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10965 + info.low_limit += mm->delta_mmap;
10966 +#endif
10967 +
10968 info.high_limit = STACK_TOP32;
10969 addr = vm_unmapped_area(&info);
10970 }
10971 @@ -259,10 +281,14 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
10972 EXPORT_SYMBOL(get_fb_unmapped_area);
10973
10974 /* Essentially the same as PowerPC. */
10975 -static unsigned long mmap_rnd(void)
10976 +static unsigned long mmap_rnd(struct mm_struct *mm)
10977 {
10978 unsigned long rnd = 0UL;
10979
10980 +#ifdef CONFIG_PAX_RANDMMAP
10981 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10982 +#endif
10983 +
10984 if (current->flags & PF_RANDOMIZE) {
10985 unsigned long val = get_random_int();
10986 if (test_thread_flag(TIF_32BIT))
10987 @@ -275,7 +301,7 @@ static unsigned long mmap_rnd(void)
10988
10989 void arch_pick_mmap_layout(struct mm_struct *mm)
10990 {
10991 - unsigned long random_factor = mmap_rnd();
10992 + unsigned long random_factor = mmap_rnd(mm);
10993 unsigned long gap;
10994
10995 /*
10996 @@ -288,6 +314,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10997 gap == RLIM_INFINITY ||
10998 sysctl_legacy_va_layout) {
10999 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
11000 +
11001 +#ifdef CONFIG_PAX_RANDMMAP
11002 + if (mm->pax_flags & MF_PAX_RANDMMAP)
11003 + mm->mmap_base += mm->delta_mmap;
11004 +#endif
11005 +
11006 mm->get_unmapped_area = arch_get_unmapped_area;
11007 } else {
11008 /* We know it's 32-bit */
11009 @@ -299,6 +331,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
11010 gap = (task_size / 6 * 5);
11011
11012 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
11013 +
11014 +#ifdef CONFIG_PAX_RANDMMAP
11015 + if (mm->pax_flags & MF_PAX_RANDMMAP)
11016 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
11017 +#endif
11018 +
11019 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
11020 }
11021 }
11022 diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
11023 index 33a17e7..d87fb1f 100644
11024 --- a/arch/sparc/kernel/syscalls.S
11025 +++ b/arch/sparc/kernel/syscalls.S
11026 @@ -52,7 +52,7 @@ sys32_rt_sigreturn:
11027 #endif
11028 .align 32
11029 1: ldx [%g6 + TI_FLAGS], %l5
11030 - andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
11031 + andcc %l5, _TIF_WORK_SYSCALL, %g0
11032 be,pt %icc, rtrap
11033 nop
11034 call syscall_trace_leave
11035 @@ -184,7 +184,7 @@ linux_sparc_syscall32:
11036
11037 srl %i3, 0, %o3 ! IEU0
11038 srl %i2, 0, %o2 ! IEU0 Group
11039 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
11040 + andcc %l0, _TIF_WORK_SYSCALL, %g0
11041 bne,pn %icc, linux_syscall_trace32 ! CTI
11042 mov %i0, %l5 ! IEU1
11043 5: call %l7 ! CTI Group brk forced
11044 @@ -208,7 +208,7 @@ linux_sparc_syscall:
11045
11046 mov %i3, %o3 ! IEU1
11047 mov %i4, %o4 ! IEU0 Group
11048 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
11049 + andcc %l0, _TIF_WORK_SYSCALL, %g0
11050 bne,pn %icc, linux_syscall_trace ! CTI Group
11051 mov %i0, %l5 ! IEU0
11052 2: call %l7 ! CTI Group brk forced
11053 @@ -223,7 +223,7 @@ ret_sys_call:
11054
11055 cmp %o0, -ERESTART_RESTARTBLOCK
11056 bgeu,pn %xcc, 1f
11057 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
11058 + andcc %l0, _TIF_WORK_SYSCALL, %g0
11059 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
11060
11061 2:
11062 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
11063 index 6fd386c5..6907d81 100644
11064 --- a/arch/sparc/kernel/traps_32.c
11065 +++ b/arch/sparc/kernel/traps_32.c
11066 @@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
11067 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
11068 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
11069
11070 +extern void gr_handle_kernel_exploit(void);
11071 +
11072 void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11073 {
11074 static int die_counter;
11075 @@ -76,15 +78,17 @@ void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11076 count++ < 30 &&
11077 (((unsigned long) rw) >= PAGE_OFFSET) &&
11078 !(((unsigned long) rw) & 0x7)) {
11079 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
11080 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
11081 (void *) rw->ins[7]);
11082 rw = (struct reg_window32 *)rw->ins[6];
11083 }
11084 }
11085 printk("Instruction DUMP:");
11086 instruction_dump ((unsigned long *) regs->pc);
11087 - if(regs->psr & PSR_PS)
11088 + if(regs->psr & PSR_PS) {
11089 + gr_handle_kernel_exploit();
11090 do_exit(SIGKILL);
11091 + }
11092 do_exit(SIGSEGV);
11093 }
11094
11095 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
11096 index fb6640e..2daada8 100644
11097 --- a/arch/sparc/kernel/traps_64.c
11098 +++ b/arch/sparc/kernel/traps_64.c
11099 @@ -79,7 +79,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
11100 i + 1,
11101 p->trapstack[i].tstate, p->trapstack[i].tpc,
11102 p->trapstack[i].tnpc, p->trapstack[i].tt);
11103 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
11104 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
11105 }
11106 }
11107
11108 @@ -99,6 +99,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
11109
11110 lvl -= 0x100;
11111 if (regs->tstate & TSTATE_PRIV) {
11112 +
11113 +#ifdef CONFIG_PAX_REFCOUNT
11114 + if (lvl == 6)
11115 + pax_report_refcount_overflow(regs);
11116 +#endif
11117 +
11118 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
11119 die_if_kernel(buffer, regs);
11120 }
11121 @@ -117,11 +123,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
11122 void bad_trap_tl1(struct pt_regs *regs, long lvl)
11123 {
11124 char buffer[32];
11125 -
11126 +
11127 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
11128 0, lvl, SIGTRAP) == NOTIFY_STOP)
11129 return;
11130
11131 +#ifdef CONFIG_PAX_REFCOUNT
11132 + if (lvl == 6)
11133 + pax_report_refcount_overflow(regs);
11134 +#endif
11135 +
11136 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
11137
11138 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
11139 @@ -1151,7 +1162,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
11140 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
11141 printk("%s" "ERROR(%d): ",
11142 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
11143 - printk("TPC<%pS>\n", (void *) regs->tpc);
11144 + printk("TPC<%pA>\n", (void *) regs->tpc);
11145 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
11146 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
11147 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
11148 @@ -1758,7 +1769,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
11149 smp_processor_id(),
11150 (type & 0x1) ? 'I' : 'D',
11151 regs->tpc);
11152 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
11153 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
11154 panic("Irrecoverable Cheetah+ parity error.");
11155 }
11156
11157 @@ -1766,7 +1777,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
11158 smp_processor_id(),
11159 (type & 0x1) ? 'I' : 'D',
11160 regs->tpc);
11161 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
11162 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
11163 }
11164
11165 struct sun4v_error_entry {
11166 @@ -1839,8 +1850,8 @@ struct sun4v_error_entry {
11167 /*0x38*/u64 reserved_5;
11168 };
11169
11170 -static atomic_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
11171 -static atomic_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
11172 +static atomic_unchecked_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
11173 +static atomic_unchecked_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
11174
11175 static const char *sun4v_err_type_to_str(u8 type)
11176 {
11177 @@ -1932,7 +1943,7 @@ static void sun4v_report_real_raddr(const char *pfx, struct pt_regs *regs)
11178 }
11179
11180 static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
11181 - int cpu, const char *pfx, atomic_t *ocnt)
11182 + int cpu, const char *pfx, atomic_unchecked_t *ocnt)
11183 {
11184 u64 *raw_ptr = (u64 *) ent;
11185 u32 attrs;
11186 @@ -1990,8 +2001,8 @@ static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
11187
11188 show_regs(regs);
11189
11190 - if ((cnt = atomic_read(ocnt)) != 0) {
11191 - atomic_set(ocnt, 0);
11192 + if ((cnt = atomic_read_unchecked(ocnt)) != 0) {
11193 + atomic_set_unchecked(ocnt, 0);
11194 wmb();
11195 printk("%s: Queue overflowed %d times.\n",
11196 pfx, cnt);
11197 @@ -2048,7 +2059,7 @@ out:
11198 */
11199 void sun4v_resum_overflow(struct pt_regs *regs)
11200 {
11201 - atomic_inc(&sun4v_resum_oflow_cnt);
11202 + atomic_inc_unchecked(&sun4v_resum_oflow_cnt);
11203 }
11204
11205 /* We run with %pil set to PIL_NORMAL_MAX and PSTATE_IE enabled in %pstate.
11206 @@ -2101,7 +2112,7 @@ void sun4v_nonresum_overflow(struct pt_regs *regs)
11207 /* XXX Actually even this can make not that much sense. Perhaps
11208 * XXX we should just pull the plug and panic directly from here?
11209 */
11210 - atomic_inc(&sun4v_nonresum_oflow_cnt);
11211 + atomic_inc_unchecked(&sun4v_nonresum_oflow_cnt);
11212 }
11213
11214 unsigned long sun4v_err_itlb_vaddr;
11215 @@ -2116,9 +2127,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
11216
11217 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
11218 regs->tpc, tl);
11219 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
11220 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
11221 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
11222 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
11223 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
11224 (void *) regs->u_regs[UREG_I7]);
11225 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
11226 "pte[%lx] error[%lx]\n",
11227 @@ -2140,9 +2151,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
11228
11229 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
11230 regs->tpc, tl);
11231 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
11232 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
11233 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
11234 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
11235 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
11236 (void *) regs->u_regs[UREG_I7]);
11237 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
11238 "pte[%lx] error[%lx]\n",
11239 @@ -2359,13 +2370,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
11240 fp = (unsigned long)sf->fp + STACK_BIAS;
11241 }
11242
11243 - printk(" [%016lx] %pS\n", pc, (void *) pc);
11244 + printk(" [%016lx] %pA\n", pc, (void *) pc);
11245 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
11246 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
11247 int index = tsk->curr_ret_stack;
11248 if (tsk->ret_stack && index >= graph) {
11249 pc = tsk->ret_stack[index - graph].ret;
11250 - printk(" [%016lx] %pS\n", pc, (void *) pc);
11251 + printk(" [%016lx] %pA\n", pc, (void *) pc);
11252 graph++;
11253 }
11254 }
11255 @@ -2383,6 +2394,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
11256 return (struct reg_window *) (fp + STACK_BIAS);
11257 }
11258
11259 +extern void gr_handle_kernel_exploit(void);
11260 +
11261 void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11262 {
11263 static int die_counter;
11264 @@ -2411,7 +2424,7 @@ void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11265 while (rw &&
11266 count++ < 30 &&
11267 kstack_valid(tp, (unsigned long) rw)) {
11268 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
11269 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
11270 (void *) rw->ins[7]);
11271
11272 rw = kernel_stack_up(rw);
11273 @@ -2424,8 +2437,10 @@ void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11274 }
11275 user_instruction_dump ((unsigned int __user *) regs->tpc);
11276 }
11277 - if (regs->tstate & TSTATE_PRIV)
11278 + if (regs->tstate & TSTATE_PRIV) {
11279 + gr_handle_kernel_exploit();
11280 do_exit(SIGKILL);
11281 + }
11282 do_exit(SIGSEGV);
11283 }
11284 EXPORT_SYMBOL(die_if_kernel);
11285 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
11286 index 62098a8..547ab2c 100644
11287 --- a/arch/sparc/kernel/unaligned_64.c
11288 +++ b/arch/sparc/kernel/unaligned_64.c
11289 @@ -297,7 +297,7 @@ static void log_unaligned(struct pt_regs *regs)
11290 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
11291
11292 if (__ratelimit(&ratelimit)) {
11293 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
11294 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
11295 regs->tpc, (void *) regs->tpc);
11296 }
11297 }
11298 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
11299 index 3269b02..64f5231 100644
11300 --- a/arch/sparc/lib/Makefile
11301 +++ b/arch/sparc/lib/Makefile
11302 @@ -2,7 +2,7 @@
11303 #
11304
11305 asflags-y := -ansi -DST_DIV0=0x02
11306 -ccflags-y := -Werror
11307 +#ccflags-y := -Werror
11308
11309 lib-$(CONFIG_SPARC32) += ashrdi3.o
11310 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
11311 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
11312 index 85c233d..68500e0 100644
11313 --- a/arch/sparc/lib/atomic_64.S
11314 +++ b/arch/sparc/lib/atomic_64.S
11315 @@ -17,7 +17,12 @@
11316 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
11317 BACKOFF_SETUP(%o2)
11318 1: lduw [%o1], %g1
11319 - add %g1, %o0, %g7
11320 + addcc %g1, %o0, %g7
11321 +
11322 +#ifdef CONFIG_PAX_REFCOUNT
11323 + tvs %icc, 6
11324 +#endif
11325 +
11326 cas [%o1], %g1, %g7
11327 cmp %g1, %g7
11328 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
11329 @@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
11330 2: BACKOFF_SPIN(%o2, %o3, 1b)
11331 ENDPROC(atomic_add)
11332
11333 +ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
11334 + BACKOFF_SETUP(%o2)
11335 +1: lduw [%o1], %g1
11336 + add %g1, %o0, %g7
11337 + cas [%o1], %g1, %g7
11338 + cmp %g1, %g7
11339 + bne,pn %icc, 2f
11340 + nop
11341 + retl
11342 + nop
11343 +2: BACKOFF_SPIN(%o2, %o3, 1b)
11344 +ENDPROC(atomic_add_unchecked)
11345 +
11346 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
11347 BACKOFF_SETUP(%o2)
11348 1: lduw [%o1], %g1
11349 - sub %g1, %o0, %g7
11350 + subcc %g1, %o0, %g7
11351 +
11352 +#ifdef CONFIG_PAX_REFCOUNT
11353 + tvs %icc, 6
11354 +#endif
11355 +
11356 cas [%o1], %g1, %g7
11357 cmp %g1, %g7
11358 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
11359 @@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
11360 2: BACKOFF_SPIN(%o2, %o3, 1b)
11361 ENDPROC(atomic_sub)
11362
11363 +ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
11364 + BACKOFF_SETUP(%o2)
11365 +1: lduw [%o1], %g1
11366 + sub %g1, %o0, %g7
11367 + cas [%o1], %g1, %g7
11368 + cmp %g1, %g7
11369 + bne,pn %icc, 2f
11370 + nop
11371 + retl
11372 + nop
11373 +2: BACKOFF_SPIN(%o2, %o3, 1b)
11374 +ENDPROC(atomic_sub_unchecked)
11375 +
11376 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
11377 BACKOFF_SETUP(%o2)
11378 1: lduw [%o1], %g1
11379 - add %g1, %o0, %g7
11380 + addcc %g1, %o0, %g7
11381 +
11382 +#ifdef CONFIG_PAX_REFCOUNT
11383 + tvs %icc, 6
11384 +#endif
11385 +
11386 cas [%o1], %g1, %g7
11387 cmp %g1, %g7
11388 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
11389 @@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
11390 2: BACKOFF_SPIN(%o2, %o3, 1b)
11391 ENDPROC(atomic_add_ret)
11392
11393 +ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
11394 + BACKOFF_SETUP(%o2)
11395 +1: lduw [%o1], %g1
11396 + addcc %g1, %o0, %g7
11397 + cas [%o1], %g1, %g7
11398 + cmp %g1, %g7
11399 + bne,pn %icc, 2f
11400 + add %g7, %o0, %g7
11401 + sra %g7, 0, %o0
11402 + retl
11403 + nop
11404 +2: BACKOFF_SPIN(%o2, %o3, 1b)
11405 +ENDPROC(atomic_add_ret_unchecked)
11406 +
11407 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
11408 BACKOFF_SETUP(%o2)
11409 1: lduw [%o1], %g1
11410 - sub %g1, %o0, %g7
11411 + subcc %g1, %o0, %g7
11412 +
11413 +#ifdef CONFIG_PAX_REFCOUNT
11414 + tvs %icc, 6
11415 +#endif
11416 +
11417 cas [%o1], %g1, %g7
11418 cmp %g1, %g7
11419 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
11420 @@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
11421 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
11422 BACKOFF_SETUP(%o2)
11423 1: ldx [%o1], %g1
11424 - add %g1, %o0, %g7
11425 + addcc %g1, %o0, %g7
11426 +
11427 +#ifdef CONFIG_PAX_REFCOUNT
11428 + tvs %xcc, 6
11429 +#endif
11430 +
11431 casx [%o1], %g1, %g7
11432 cmp %g1, %g7
11433 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11434 @@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
11435 2: BACKOFF_SPIN(%o2, %o3, 1b)
11436 ENDPROC(atomic64_add)
11437
11438 +ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
11439 + BACKOFF_SETUP(%o2)
11440 +1: ldx [%o1], %g1
11441 + addcc %g1, %o0, %g7
11442 + casx [%o1], %g1, %g7
11443 + cmp %g1, %g7
11444 + bne,pn %xcc, 2f
11445 + nop
11446 + retl
11447 + nop
11448 +2: BACKOFF_SPIN(%o2, %o3, 1b)
11449 +ENDPROC(atomic64_add_unchecked)
11450 +
11451 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
11452 BACKOFF_SETUP(%o2)
11453 1: ldx [%o1], %g1
11454 - sub %g1, %o0, %g7
11455 + subcc %g1, %o0, %g7
11456 +
11457 +#ifdef CONFIG_PAX_REFCOUNT
11458 + tvs %xcc, 6
11459 +#endif
11460 +
11461 casx [%o1], %g1, %g7
11462 cmp %g1, %g7
11463 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11464 @@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
11465 2: BACKOFF_SPIN(%o2, %o3, 1b)
11466 ENDPROC(atomic64_sub)
11467
11468 +ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
11469 + BACKOFF_SETUP(%o2)
11470 +1: ldx [%o1], %g1
11471 + subcc %g1, %o0, %g7
11472 + casx [%o1], %g1, %g7
11473 + cmp %g1, %g7
11474 + bne,pn %xcc, 2f
11475 + nop
11476 + retl
11477 + nop
11478 +2: BACKOFF_SPIN(%o2, %o3, 1b)
11479 +ENDPROC(atomic64_sub_unchecked)
11480 +
11481 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
11482 BACKOFF_SETUP(%o2)
11483 1: ldx [%o1], %g1
11484 - add %g1, %o0, %g7
11485 + addcc %g1, %o0, %g7
11486 +
11487 +#ifdef CONFIG_PAX_REFCOUNT
11488 + tvs %xcc, 6
11489 +#endif
11490 +
11491 casx [%o1], %g1, %g7
11492 cmp %g1, %g7
11493 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11494 @@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
11495 2: BACKOFF_SPIN(%o2, %o3, 1b)
11496 ENDPROC(atomic64_add_ret)
11497
11498 +ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
11499 + BACKOFF_SETUP(%o2)
11500 +1: ldx [%o1], %g1
11501 + addcc %g1, %o0, %g7
11502 + casx [%o1], %g1, %g7
11503 + cmp %g1, %g7
11504 + bne,pn %xcc, 2f
11505 + add %g7, %o0, %g7
11506 + mov %g7, %o0
11507 + retl
11508 + nop
11509 +2: BACKOFF_SPIN(%o2, %o3, 1b)
11510 +ENDPROC(atomic64_add_ret_unchecked)
11511 +
11512 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
11513 BACKOFF_SETUP(%o2)
11514 1: ldx [%o1], %g1
11515 - sub %g1, %o0, %g7
11516 + subcc %g1, %o0, %g7
11517 +
11518 +#ifdef CONFIG_PAX_REFCOUNT
11519 + tvs %xcc, 6
11520 +#endif
11521 +
11522 casx [%o1], %g1, %g7
11523 cmp %g1, %g7
11524 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11525 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
11526 index 323335b..ed85ea2 100644
11527 --- a/arch/sparc/lib/ksyms.c
11528 +++ b/arch/sparc/lib/ksyms.c
11529 @@ -100,12 +100,18 @@ EXPORT_SYMBOL(__clear_user);
11530
11531 /* Atomic counter implementation. */
11532 EXPORT_SYMBOL(atomic_add);
11533 +EXPORT_SYMBOL(atomic_add_unchecked);
11534 EXPORT_SYMBOL(atomic_add_ret);
11535 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
11536 EXPORT_SYMBOL(atomic_sub);
11537 +EXPORT_SYMBOL(atomic_sub_unchecked);
11538 EXPORT_SYMBOL(atomic_sub_ret);
11539 EXPORT_SYMBOL(atomic64_add);
11540 +EXPORT_SYMBOL(atomic64_add_unchecked);
11541 EXPORT_SYMBOL(atomic64_add_ret);
11542 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
11543 EXPORT_SYMBOL(atomic64_sub);
11544 +EXPORT_SYMBOL(atomic64_sub_unchecked);
11545 EXPORT_SYMBOL(atomic64_sub_ret);
11546 EXPORT_SYMBOL(atomic64_dec_if_positive);
11547
11548 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
11549 index 30c3ecc..736f015 100644
11550 --- a/arch/sparc/mm/Makefile
11551 +++ b/arch/sparc/mm/Makefile
11552 @@ -2,7 +2,7 @@
11553 #
11554
11555 asflags-y := -ansi
11556 -ccflags-y := -Werror
11557 +#ccflags-y := -Werror
11558
11559 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
11560 obj-y += fault_$(BITS).o
11561 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
11562 index 908e8c1..1524793 100644
11563 --- a/arch/sparc/mm/fault_32.c
11564 +++ b/arch/sparc/mm/fault_32.c
11565 @@ -21,6 +21,9 @@
11566 #include <linux/perf_event.h>
11567 #include <linux/interrupt.h>
11568 #include <linux/kdebug.h>
11569 +#include <linux/slab.h>
11570 +#include <linux/pagemap.h>
11571 +#include <linux/compiler.h>
11572
11573 #include <asm/page.h>
11574 #include <asm/pgtable.h>
11575 @@ -156,6 +159,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
11576 return safe_compute_effective_address(regs, insn);
11577 }
11578
11579 +#ifdef CONFIG_PAX_PAGEEXEC
11580 +#ifdef CONFIG_PAX_DLRESOLVE
11581 +static void pax_emuplt_close(struct vm_area_struct *vma)
11582 +{
11583 + vma->vm_mm->call_dl_resolve = 0UL;
11584 +}
11585 +
11586 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11587 +{
11588 + unsigned int *kaddr;
11589 +
11590 + vmf->page = alloc_page(GFP_HIGHUSER);
11591 + if (!vmf->page)
11592 + return VM_FAULT_OOM;
11593 +
11594 + kaddr = kmap(vmf->page);
11595 + memset(kaddr, 0, PAGE_SIZE);
11596 + kaddr[0] = 0x9DE3BFA8U; /* save */
11597 + flush_dcache_page(vmf->page);
11598 + kunmap(vmf->page);
11599 + return VM_FAULT_MAJOR;
11600 +}
11601 +
11602 +static const struct vm_operations_struct pax_vm_ops = {
11603 + .close = pax_emuplt_close,
11604 + .fault = pax_emuplt_fault
11605 +};
11606 +
11607 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11608 +{
11609 + int ret;
11610 +
11611 + INIT_LIST_HEAD(&vma->anon_vma_chain);
11612 + vma->vm_mm = current->mm;
11613 + vma->vm_start = addr;
11614 + vma->vm_end = addr + PAGE_SIZE;
11615 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11616 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11617 + vma->vm_ops = &pax_vm_ops;
11618 +
11619 + ret = insert_vm_struct(current->mm, vma);
11620 + if (ret)
11621 + return ret;
11622 +
11623 + ++current->mm->total_vm;
11624 + return 0;
11625 +}
11626 +#endif
11627 +
11628 +/*
11629 + * PaX: decide what to do with offenders (regs->pc = fault address)
11630 + *
11631 + * returns 1 when task should be killed
11632 + * 2 when patched PLT trampoline was detected
11633 + * 3 when unpatched PLT trampoline was detected
11634 + */
11635 +static int pax_handle_fetch_fault(struct pt_regs *regs)
11636 +{
11637 +
11638 +#ifdef CONFIG_PAX_EMUPLT
11639 + int err;
11640 +
11641 + do { /* PaX: patched PLT emulation #1 */
11642 + unsigned int sethi1, sethi2, jmpl;
11643 +
11644 + err = get_user(sethi1, (unsigned int *)regs->pc);
11645 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
11646 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
11647 +
11648 + if (err)
11649 + break;
11650 +
11651 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11652 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
11653 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
11654 + {
11655 + unsigned int addr;
11656 +
11657 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11658 + addr = regs->u_regs[UREG_G1];
11659 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11660 + regs->pc = addr;
11661 + regs->npc = addr+4;
11662 + return 2;
11663 + }
11664 + } while (0);
11665 +
11666 + do { /* PaX: patched PLT emulation #2 */
11667 + unsigned int ba;
11668 +
11669 + err = get_user(ba, (unsigned int *)regs->pc);
11670 +
11671 + if (err)
11672 + break;
11673 +
11674 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11675 + unsigned int addr;
11676 +
11677 + if ((ba & 0xFFC00000U) == 0x30800000U)
11678 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11679 + else
11680 + addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11681 + regs->pc = addr;
11682 + regs->npc = addr+4;
11683 + return 2;
11684 + }
11685 + } while (0);
11686 +
11687 + do { /* PaX: patched PLT emulation #3 */
11688 + unsigned int sethi, bajmpl, nop;
11689 +
11690 + err = get_user(sethi, (unsigned int *)regs->pc);
11691 + err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
11692 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
11693 +
11694 + if (err)
11695 + break;
11696 +
11697 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11698 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11699 + nop == 0x01000000U)
11700 + {
11701 + unsigned int addr;
11702 +
11703 + addr = (sethi & 0x003FFFFFU) << 10;
11704 + regs->u_regs[UREG_G1] = addr;
11705 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11706 + addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11707 + else
11708 + addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11709 + regs->pc = addr;
11710 + regs->npc = addr+4;
11711 + return 2;
11712 + }
11713 + } while (0);
11714 +
11715 + do { /* PaX: unpatched PLT emulation step 1 */
11716 + unsigned int sethi, ba, nop;
11717 +
11718 + err = get_user(sethi, (unsigned int *)regs->pc);
11719 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
11720 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
11721 +
11722 + if (err)
11723 + break;
11724 +
11725 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11726 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11727 + nop == 0x01000000U)
11728 + {
11729 + unsigned int addr, save, call;
11730 +
11731 + if ((ba & 0xFFC00000U) == 0x30800000U)
11732 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11733 + else
11734 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11735 +
11736 + err = get_user(save, (unsigned int *)addr);
11737 + err |= get_user(call, (unsigned int *)(addr+4));
11738 + err |= get_user(nop, (unsigned int *)(addr+8));
11739 + if (err)
11740 + break;
11741 +
11742 +#ifdef CONFIG_PAX_DLRESOLVE
11743 + if (save == 0x9DE3BFA8U &&
11744 + (call & 0xC0000000U) == 0x40000000U &&
11745 + nop == 0x01000000U)
11746 + {
11747 + struct vm_area_struct *vma;
11748 + unsigned long call_dl_resolve;
11749 +
11750 + down_read(&current->mm->mmap_sem);
11751 + call_dl_resolve = current->mm->call_dl_resolve;
11752 + up_read(&current->mm->mmap_sem);
11753 + if (likely(call_dl_resolve))
11754 + goto emulate;
11755 +
11756 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11757 +
11758 + down_write(&current->mm->mmap_sem);
11759 + if (current->mm->call_dl_resolve) {
11760 + call_dl_resolve = current->mm->call_dl_resolve;
11761 + up_write(&current->mm->mmap_sem);
11762 + if (vma)
11763 + kmem_cache_free(vm_area_cachep, vma);
11764 + goto emulate;
11765 + }
11766 +
11767 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11768 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11769 + up_write(&current->mm->mmap_sem);
11770 + if (vma)
11771 + kmem_cache_free(vm_area_cachep, vma);
11772 + return 1;
11773 + }
11774 +
11775 + if (pax_insert_vma(vma, call_dl_resolve)) {
11776 + up_write(&current->mm->mmap_sem);
11777 + kmem_cache_free(vm_area_cachep, vma);
11778 + return 1;
11779 + }
11780 +
11781 + current->mm->call_dl_resolve = call_dl_resolve;
11782 + up_write(&current->mm->mmap_sem);
11783 +
11784 +emulate:
11785 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11786 + regs->pc = call_dl_resolve;
11787 + regs->npc = addr+4;
11788 + return 3;
11789 + }
11790 +#endif
11791 +
11792 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11793 + if ((save & 0xFFC00000U) == 0x05000000U &&
11794 + (call & 0xFFFFE000U) == 0x85C0A000U &&
11795 + nop == 0x01000000U)
11796 + {
11797 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11798 + regs->u_regs[UREG_G2] = addr + 4;
11799 + addr = (save & 0x003FFFFFU) << 10;
11800 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11801 + regs->pc = addr;
11802 + regs->npc = addr+4;
11803 + return 3;
11804 + }
11805 + }
11806 + } while (0);
11807 +
11808 + do { /* PaX: unpatched PLT emulation step 2 */
11809 + unsigned int save, call, nop;
11810 +
11811 + err = get_user(save, (unsigned int *)(regs->pc-4));
11812 + err |= get_user(call, (unsigned int *)regs->pc);
11813 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
11814 + if (err)
11815 + break;
11816 +
11817 + if (save == 0x9DE3BFA8U &&
11818 + (call & 0xC0000000U) == 0x40000000U &&
11819 + nop == 0x01000000U)
11820 + {
11821 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
11822 +
11823 + regs->u_regs[UREG_RETPC] = regs->pc;
11824 + regs->pc = dl_resolve;
11825 + regs->npc = dl_resolve+4;
11826 + return 3;
11827 + }
11828 + } while (0);
11829 +#endif
11830 +
11831 + return 1;
11832 +}
11833 +
11834 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11835 +{
11836 + unsigned long i;
11837 +
11838 + printk(KERN_ERR "PAX: bytes at PC: ");
11839 + for (i = 0; i < 8; i++) {
11840 + unsigned int c;
11841 + if (get_user(c, (unsigned int *)pc+i))
11842 + printk(KERN_CONT "???????? ");
11843 + else
11844 + printk(KERN_CONT "%08x ", c);
11845 + }
11846 + printk("\n");
11847 +}
11848 +#endif
11849 +
11850 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
11851 int text_fault)
11852 {
11853 @@ -226,6 +500,24 @@ good_area:
11854 if (!(vma->vm_flags & VM_WRITE))
11855 goto bad_area;
11856 } else {
11857 +
11858 +#ifdef CONFIG_PAX_PAGEEXEC
11859 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
11860 + up_read(&mm->mmap_sem);
11861 + switch (pax_handle_fetch_fault(regs)) {
11862 +
11863 +#ifdef CONFIG_PAX_EMUPLT
11864 + case 2:
11865 + case 3:
11866 + return;
11867 +#endif
11868 +
11869 + }
11870 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
11871 + do_group_exit(SIGKILL);
11872 + }
11873 +#endif
11874 +
11875 /* Allow reads even for write-only mappings */
11876 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
11877 goto bad_area;
11878 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
11879 index 587cd05..fbdf17a 100644
11880 --- a/arch/sparc/mm/fault_64.c
11881 +++ b/arch/sparc/mm/fault_64.c
11882 @@ -22,6 +22,9 @@
11883 #include <linux/kdebug.h>
11884 #include <linux/percpu.h>
11885 #include <linux/context_tracking.h>
11886 +#include <linux/slab.h>
11887 +#include <linux/pagemap.h>
11888 +#include <linux/compiler.h>
11889
11890 #include <asm/page.h>
11891 #include <asm/pgtable.h>
11892 @@ -76,7 +79,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
11893 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
11894 regs->tpc);
11895 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
11896 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
11897 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
11898 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
11899 dump_stack();
11900 unhandled_fault(regs->tpc, current, regs);
11901 @@ -279,6 +282,466 @@ static void noinline __kprobes bogus_32bit_fault_tpc(struct pt_regs *regs)
11902 show_regs(regs);
11903 }
11904
11905 +#ifdef CONFIG_PAX_PAGEEXEC
11906 +#ifdef CONFIG_PAX_DLRESOLVE
11907 +static void pax_emuplt_close(struct vm_area_struct *vma)
11908 +{
11909 + vma->vm_mm->call_dl_resolve = 0UL;
11910 +}
11911 +
11912 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11913 +{
11914 + unsigned int *kaddr;
11915 +
11916 + vmf->page = alloc_page(GFP_HIGHUSER);
11917 + if (!vmf->page)
11918 + return VM_FAULT_OOM;
11919 +
11920 + kaddr = kmap(vmf->page);
11921 + memset(kaddr, 0, PAGE_SIZE);
11922 + kaddr[0] = 0x9DE3BFA8U; /* save */
11923 + flush_dcache_page(vmf->page);
11924 + kunmap(vmf->page);
11925 + return VM_FAULT_MAJOR;
11926 +}
11927 +
11928 +static const struct vm_operations_struct pax_vm_ops = {
11929 + .close = pax_emuplt_close,
11930 + .fault = pax_emuplt_fault
11931 +};
11932 +
11933 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11934 +{
11935 + int ret;
11936 +
11937 + INIT_LIST_HEAD(&vma->anon_vma_chain);
11938 + vma->vm_mm = current->mm;
11939 + vma->vm_start = addr;
11940 + vma->vm_end = addr + PAGE_SIZE;
11941 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11942 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11943 + vma->vm_ops = &pax_vm_ops;
11944 +
11945 + ret = insert_vm_struct(current->mm, vma);
11946 + if (ret)
11947 + return ret;
11948 +
11949 + ++current->mm->total_vm;
11950 + return 0;
11951 +}
11952 +#endif
11953 +
11954 +/*
11955 + * PaX: decide what to do with offenders (regs->tpc = fault address)
11956 + *
11957 + * returns 1 when task should be killed
11958 + * 2 when patched PLT trampoline was detected
11959 + * 3 when unpatched PLT trampoline was detected
11960 + */
11961 +static int pax_handle_fetch_fault(struct pt_regs *regs)
11962 +{
11963 +
11964 +#ifdef CONFIG_PAX_EMUPLT
11965 + int err;
11966 +
11967 + do { /* PaX: patched PLT emulation #1 */
11968 + unsigned int sethi1, sethi2, jmpl;
11969 +
11970 + err = get_user(sethi1, (unsigned int *)regs->tpc);
11971 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
11972 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
11973 +
11974 + if (err)
11975 + break;
11976 +
11977 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11978 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
11979 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
11980 + {
11981 + unsigned long addr;
11982 +
11983 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11984 + addr = regs->u_regs[UREG_G1];
11985 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11986 +
11987 + if (test_thread_flag(TIF_32BIT))
11988 + addr &= 0xFFFFFFFFUL;
11989 +
11990 + regs->tpc = addr;
11991 + regs->tnpc = addr+4;
11992 + return 2;
11993 + }
11994 + } while (0);
11995 +
11996 + do { /* PaX: patched PLT emulation #2 */
11997 + unsigned int ba;
11998 +
11999 + err = get_user(ba, (unsigned int *)regs->tpc);
12000 +
12001 + if (err)
12002 + break;
12003 +
12004 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
12005 + unsigned long addr;
12006 +
12007 + if ((ba & 0xFFC00000U) == 0x30800000U)
12008 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
12009 + else
12010 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
12011 +
12012 + if (test_thread_flag(TIF_32BIT))
12013 + addr &= 0xFFFFFFFFUL;
12014 +
12015 + regs->tpc = addr;
12016 + regs->tnpc = addr+4;
12017 + return 2;
12018 + }
12019 + } while (0);
12020 +
12021 + do { /* PaX: patched PLT emulation #3 */
12022 + unsigned int sethi, bajmpl, nop;
12023 +
12024 + err = get_user(sethi, (unsigned int *)regs->tpc);
12025 + err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
12026 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
12027 +
12028 + if (err)
12029 + break;
12030 +
12031 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
12032 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
12033 + nop == 0x01000000U)
12034 + {
12035 + unsigned long addr;
12036 +
12037 + addr = (sethi & 0x003FFFFFU) << 10;
12038 + regs->u_regs[UREG_G1] = addr;
12039 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
12040 + addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
12041 + else
12042 + addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
12043 +
12044 + if (test_thread_flag(TIF_32BIT))
12045 + addr &= 0xFFFFFFFFUL;
12046 +
12047 + regs->tpc = addr;
12048 + regs->tnpc = addr+4;
12049 + return 2;
12050 + }
12051 + } while (0);
12052 +
12053 + do { /* PaX: patched PLT emulation #4 */
12054 + unsigned int sethi, mov1, call, mov2;
12055 +
12056 + err = get_user(sethi, (unsigned int *)regs->tpc);
12057 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
12058 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
12059 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
12060 +
12061 + if (err)
12062 + break;
12063 +
12064 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
12065 + mov1 == 0x8210000FU &&
12066 + (call & 0xC0000000U) == 0x40000000U &&
12067 + mov2 == 0x9E100001U)
12068 + {
12069 + unsigned long addr;
12070 +
12071 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
12072 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
12073 +
12074 + if (test_thread_flag(TIF_32BIT))
12075 + addr &= 0xFFFFFFFFUL;
12076 +
12077 + regs->tpc = addr;
12078 + regs->tnpc = addr+4;
12079 + return 2;
12080 + }
12081 + } while (0);
12082 +
12083 + do { /* PaX: patched PLT emulation #5 */
12084 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
12085 +
12086 + err = get_user(sethi, (unsigned int *)regs->tpc);
12087 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
12088 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
12089 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
12090 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
12091 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
12092 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
12093 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
12094 +
12095 + if (err)
12096 + break;
12097 +
12098 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
12099 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
12100 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
12101 + (or1 & 0xFFFFE000U) == 0x82106000U &&
12102 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
12103 + sllx == 0x83287020U &&
12104 + jmpl == 0x81C04005U &&
12105 + nop == 0x01000000U)
12106 + {
12107 + unsigned long addr;
12108 +
12109 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
12110 + regs->u_regs[UREG_G1] <<= 32;
12111 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
12112 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
12113 + regs->tpc = addr;
12114 + regs->tnpc = addr+4;
12115 + return 2;
12116 + }
12117 + } while (0);
12118 +
12119 + do { /* PaX: patched PLT emulation #6 */
12120 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
12121 +
12122 + err = get_user(sethi, (unsigned int *)regs->tpc);
12123 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
12124 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
12125 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
12126 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
12127 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
12128 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
12129 +
12130 + if (err)
12131 + break;
12132 +
12133 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
12134 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
12135 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
12136 + sllx == 0x83287020U &&
12137 + (or & 0xFFFFE000U) == 0x8A116000U &&
12138 + jmpl == 0x81C04005U &&
12139 + nop == 0x01000000U)
12140 + {
12141 + unsigned long addr;
12142 +
12143 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
12144 + regs->u_regs[UREG_G1] <<= 32;
12145 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
12146 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
12147 + regs->tpc = addr;
12148 + regs->tnpc = addr+4;
12149 + return 2;
12150 + }
12151 + } while (0);
12152 +
12153 + do { /* PaX: unpatched PLT emulation step 1 */
12154 + unsigned int sethi, ba, nop;
12155 +
12156 + err = get_user(sethi, (unsigned int *)regs->tpc);
12157 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
12158 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
12159 +
12160 + if (err)
12161 + break;
12162 +
12163 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
12164 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
12165 + nop == 0x01000000U)
12166 + {
12167 + unsigned long addr;
12168 + unsigned int save, call;
12169 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
12170 +
12171 + if ((ba & 0xFFC00000U) == 0x30800000U)
12172 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
12173 + else
12174 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
12175 +
12176 + if (test_thread_flag(TIF_32BIT))
12177 + addr &= 0xFFFFFFFFUL;
12178 +
12179 + err = get_user(save, (unsigned int *)addr);
12180 + err |= get_user(call, (unsigned int *)(addr+4));
12181 + err |= get_user(nop, (unsigned int *)(addr+8));
12182 + if (err)
12183 + break;
12184 +
12185 +#ifdef CONFIG_PAX_DLRESOLVE
12186 + if (save == 0x9DE3BFA8U &&
12187 + (call & 0xC0000000U) == 0x40000000U &&
12188 + nop == 0x01000000U)
12189 + {
12190 + struct vm_area_struct *vma;
12191 + unsigned long call_dl_resolve;
12192 +
12193 + down_read(&current->mm->mmap_sem);
12194 + call_dl_resolve = current->mm->call_dl_resolve;
12195 + up_read(&current->mm->mmap_sem);
12196 + if (likely(call_dl_resolve))
12197 + goto emulate;
12198 +
12199 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
12200 +
12201 + down_write(&current->mm->mmap_sem);
12202 + if (current->mm->call_dl_resolve) {
12203 + call_dl_resolve = current->mm->call_dl_resolve;
12204 + up_write(&current->mm->mmap_sem);
12205 + if (vma)
12206 + kmem_cache_free(vm_area_cachep, vma);
12207 + goto emulate;
12208 + }
12209 +
12210 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
12211 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
12212 + up_write(&current->mm->mmap_sem);
12213 + if (vma)
12214 + kmem_cache_free(vm_area_cachep, vma);
12215 + return 1;
12216 + }
12217 +
12218 + if (pax_insert_vma(vma, call_dl_resolve)) {
12219 + up_write(&current->mm->mmap_sem);
12220 + kmem_cache_free(vm_area_cachep, vma);
12221 + return 1;
12222 + }
12223 +
12224 + current->mm->call_dl_resolve = call_dl_resolve;
12225 + up_write(&current->mm->mmap_sem);
12226 +
12227 +emulate:
12228 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12229 + regs->tpc = call_dl_resolve;
12230 + regs->tnpc = addr+4;
12231 + return 3;
12232 + }
12233 +#endif
12234 +
12235 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
12236 + if ((save & 0xFFC00000U) == 0x05000000U &&
12237 + (call & 0xFFFFE000U) == 0x85C0A000U &&
12238 + nop == 0x01000000U)
12239 + {
12240 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12241 + regs->u_regs[UREG_G2] = addr + 4;
12242 + addr = (save & 0x003FFFFFU) << 10;
12243 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
12244 +
12245 + if (test_thread_flag(TIF_32BIT))
12246 + addr &= 0xFFFFFFFFUL;
12247 +
12248 + regs->tpc = addr;
12249 + regs->tnpc = addr+4;
12250 + return 3;
12251 + }
12252 +
12253 + /* PaX: 64-bit PLT stub */
12254 + err = get_user(sethi1, (unsigned int *)addr);
12255 + err |= get_user(sethi2, (unsigned int *)(addr+4));
12256 + err |= get_user(or1, (unsigned int *)(addr+8));
12257 + err |= get_user(or2, (unsigned int *)(addr+12));
12258 + err |= get_user(sllx, (unsigned int *)(addr+16));
12259 + err |= get_user(add, (unsigned int *)(addr+20));
12260 + err |= get_user(jmpl, (unsigned int *)(addr+24));
12261 + err |= get_user(nop, (unsigned int *)(addr+28));
12262 + if (err)
12263 + break;
12264 +
12265 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
12266 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
12267 + (or1 & 0xFFFFE000U) == 0x88112000U &&
12268 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
12269 + sllx == 0x89293020U &&
12270 + add == 0x8A010005U &&
12271 + jmpl == 0x89C14000U &&
12272 + nop == 0x01000000U)
12273 + {
12274 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12275 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
12276 + regs->u_regs[UREG_G4] <<= 32;
12277 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
12278 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
12279 + regs->u_regs[UREG_G4] = addr + 24;
12280 + addr = regs->u_regs[UREG_G5];
12281 + regs->tpc = addr;
12282 + regs->tnpc = addr+4;
12283 + return 3;
12284 + }
12285 + }
12286 + } while (0);
12287 +
12288 +#ifdef CONFIG_PAX_DLRESOLVE
12289 + do { /* PaX: unpatched PLT emulation step 2 */
12290 + unsigned int save, call, nop;
12291 +
12292 + err = get_user(save, (unsigned int *)(regs->tpc-4));
12293 + err |= get_user(call, (unsigned int *)regs->tpc);
12294 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
12295 + if (err)
12296 + break;
12297 +
12298 + if (save == 0x9DE3BFA8U &&
12299 + (call & 0xC0000000U) == 0x40000000U &&
12300 + nop == 0x01000000U)
12301 + {
12302 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
12303 +
12304 + if (test_thread_flag(TIF_32BIT))
12305 + dl_resolve &= 0xFFFFFFFFUL;
12306 +
12307 + regs->u_regs[UREG_RETPC] = regs->tpc;
12308 + regs->tpc = dl_resolve;
12309 + regs->tnpc = dl_resolve+4;
12310 + return 3;
12311 + }
12312 + } while (0);
12313 +#endif
12314 +
12315 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
12316 + unsigned int sethi, ba, nop;
12317 +
12318 + err = get_user(sethi, (unsigned int *)regs->tpc);
12319 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
12320 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
12321 +
12322 + if (err)
12323 + break;
12324 +
12325 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
12326 + (ba & 0xFFF00000U) == 0x30600000U &&
12327 + nop == 0x01000000U)
12328 + {
12329 + unsigned long addr;
12330 +
12331 + addr = (sethi & 0x003FFFFFU) << 10;
12332 + regs->u_regs[UREG_G1] = addr;
12333 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
12334 +
12335 + if (test_thread_flag(TIF_32BIT))
12336 + addr &= 0xFFFFFFFFUL;
12337 +
12338 + regs->tpc = addr;
12339 + regs->tnpc = addr+4;
12340 + return 2;
12341 + }
12342 + } while (0);
12343 +
12344 +#endif
12345 +
12346 + return 1;
12347 +}
12348 +
12349 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
12350 +{
12351 + unsigned long i;
12352 +
12353 + printk(KERN_ERR "PAX: bytes at PC: ");
12354 + for (i = 0; i < 8; i++) {
12355 + unsigned int c;
12356 + if (get_user(c, (unsigned int *)pc+i))
12357 + printk(KERN_CONT "???????? ");
12358 + else
12359 + printk(KERN_CONT "%08x ", c);
12360 + }
12361 + printk("\n");
12362 +}
12363 +#endif
12364 +
12365 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
12366 {
12367 enum ctx_state prev_state = exception_enter();
12368 @@ -350,6 +813,29 @@ retry:
12369 if (!vma)
12370 goto bad_area;
12371
12372 +#ifdef CONFIG_PAX_PAGEEXEC
12373 + /* PaX: detect ITLB misses on non-exec pages */
12374 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
12375 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
12376 + {
12377 + if (address != regs->tpc)
12378 + goto good_area;
12379 +
12380 + up_read(&mm->mmap_sem);
12381 + switch (pax_handle_fetch_fault(regs)) {
12382 +
12383 +#ifdef CONFIG_PAX_EMUPLT
12384 + case 2:
12385 + case 3:
12386 + return;
12387 +#endif
12388 +
12389 + }
12390 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
12391 + do_group_exit(SIGKILL);
12392 + }
12393 +#endif
12394 +
12395 /* Pure DTLB misses do not tell us whether the fault causing
12396 * load/store/atomic was a write or not, it only says that there
12397 * was no match. So in such a case we (carefully) read the
12398 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
12399 index d329537..2c3746a 100644
12400 --- a/arch/sparc/mm/hugetlbpage.c
12401 +++ b/arch/sparc/mm/hugetlbpage.c
12402 @@ -25,8 +25,10 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
12403 unsigned long addr,
12404 unsigned long len,
12405 unsigned long pgoff,
12406 - unsigned long flags)
12407 + unsigned long flags,
12408 + unsigned long offset)
12409 {
12410 + struct mm_struct *mm = current->mm;
12411 unsigned long task_size = TASK_SIZE;
12412 struct vm_unmapped_area_info info;
12413
12414 @@ -35,15 +37,22 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
12415
12416 info.flags = 0;
12417 info.length = len;
12418 - info.low_limit = TASK_UNMAPPED_BASE;
12419 + info.low_limit = mm->mmap_base;
12420 info.high_limit = min(task_size, VA_EXCLUDE_START);
12421 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
12422 info.align_offset = 0;
12423 + info.threadstack_offset = offset;
12424 addr = vm_unmapped_area(&info);
12425
12426 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
12427 VM_BUG_ON(addr != -ENOMEM);
12428 info.low_limit = VA_EXCLUDE_END;
12429 +
12430 +#ifdef CONFIG_PAX_RANDMMAP
12431 + if (mm->pax_flags & MF_PAX_RANDMMAP)
12432 + info.low_limit += mm->delta_mmap;
12433 +#endif
12434 +
12435 info.high_limit = task_size;
12436 addr = vm_unmapped_area(&info);
12437 }
12438 @@ -55,7 +64,8 @@ static unsigned long
12439 hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12440 const unsigned long len,
12441 const unsigned long pgoff,
12442 - const unsigned long flags)
12443 + const unsigned long flags,
12444 + const unsigned long offset)
12445 {
12446 struct mm_struct *mm = current->mm;
12447 unsigned long addr = addr0;
12448 @@ -70,6 +80,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12449 info.high_limit = mm->mmap_base;
12450 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
12451 info.align_offset = 0;
12452 + info.threadstack_offset = offset;
12453 addr = vm_unmapped_area(&info);
12454
12455 /*
12456 @@ -82,6 +93,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12457 VM_BUG_ON(addr != -ENOMEM);
12458 info.flags = 0;
12459 info.low_limit = TASK_UNMAPPED_BASE;
12460 +
12461 +#ifdef CONFIG_PAX_RANDMMAP
12462 + if (mm->pax_flags & MF_PAX_RANDMMAP)
12463 + info.low_limit += mm->delta_mmap;
12464 +#endif
12465 +
12466 info.high_limit = STACK_TOP32;
12467 addr = vm_unmapped_area(&info);
12468 }
12469 @@ -96,6 +113,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
12470 struct mm_struct *mm = current->mm;
12471 struct vm_area_struct *vma;
12472 unsigned long task_size = TASK_SIZE;
12473 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
12474
12475 if (test_thread_flag(TIF_32BIT))
12476 task_size = STACK_TOP32;
12477 @@ -111,19 +129,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
12478 return addr;
12479 }
12480
12481 +#ifdef CONFIG_PAX_RANDMMAP
12482 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
12483 +#endif
12484 +
12485 if (addr) {
12486 addr = ALIGN(addr, HPAGE_SIZE);
12487 vma = find_vma(mm, addr);
12488 - if (task_size - len >= addr &&
12489 - (!vma || addr + len <= vma->vm_start))
12490 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
12491 return addr;
12492 }
12493 if (mm->get_unmapped_area == arch_get_unmapped_area)
12494 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
12495 - pgoff, flags);
12496 + pgoff, flags, offset);
12497 else
12498 return hugetlb_get_unmapped_area_topdown(file, addr, len,
12499 - pgoff, flags);
12500 + pgoff, flags, offset);
12501 }
12502
12503 pte_t *huge_pte_alloc(struct mm_struct *mm,
12504 diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
12505 index 2cfb0f2..e917d9f 100644
12506 --- a/arch/sparc/mm/init_64.c
12507 +++ b/arch/sparc/mm/init_64.c
12508 @@ -189,9 +189,9 @@ unsigned long sparc64_kern_sec_context __read_mostly;
12509 int num_kernel_image_mappings;
12510
12511 #ifdef CONFIG_DEBUG_DCFLUSH
12512 -atomic_t dcpage_flushes = ATOMIC_INIT(0);
12513 +atomic_unchecked_t dcpage_flushes = ATOMIC_INIT(0);
12514 #ifdef CONFIG_SMP
12515 -atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
12516 +atomic_unchecked_t dcpage_flushes_xcall = ATOMIC_INIT(0);
12517 #endif
12518 #endif
12519
12520 @@ -199,7 +199,7 @@ inline void flush_dcache_page_impl(struct page *page)
12521 {
12522 BUG_ON(tlb_type == hypervisor);
12523 #ifdef CONFIG_DEBUG_DCFLUSH
12524 - atomic_inc(&dcpage_flushes);
12525 + atomic_inc_unchecked(&dcpage_flushes);
12526 #endif
12527
12528 #ifdef DCACHE_ALIASING_POSSIBLE
12529 @@ -471,10 +471,10 @@ void mmu_info(struct seq_file *m)
12530
12531 #ifdef CONFIG_DEBUG_DCFLUSH
12532 seq_printf(m, "DCPageFlushes\t: %d\n",
12533 - atomic_read(&dcpage_flushes));
12534 + atomic_read_unchecked(&dcpage_flushes));
12535 #ifdef CONFIG_SMP
12536 seq_printf(m, "DCPageFlushesXC\t: %d\n",
12537 - atomic_read(&dcpage_flushes_xcall));
12538 + atomic_read_unchecked(&dcpage_flushes_xcall));
12539 #endif /* CONFIG_SMP */
12540 #endif /* CONFIG_DEBUG_DCFLUSH */
12541 }
12542 diff --git a/arch/tile/Kconfig b/arch/tile/Kconfig
12543 index 4f3006b..453f625f 100644
12544 --- a/arch/tile/Kconfig
12545 +++ b/arch/tile/Kconfig
12546 @@ -192,6 +192,7 @@ source "kernel/Kconfig.hz"
12547
12548 config KEXEC
12549 bool "kexec system call"
12550 + depends on !GRKERNSEC_KMEM
12551 ---help---
12552 kexec is a system call that implements the ability to shutdown your
12553 current kernel, and to start another kernel. It is like a reboot
12554 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
12555 index 7b11c5f..755a026 100644
12556 --- a/arch/tile/include/asm/atomic_64.h
12557 +++ b/arch/tile/include/asm/atomic_64.h
12558 @@ -105,6 +105,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
12559
12560 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
12561
12562 +#define atomic64_read_unchecked(v) atomic64_read(v)
12563 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
12564 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
12565 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
12566 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
12567 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
12568 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
12569 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
12570 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
12571 +
12572 /* Define this to indicate that cmpxchg is an efficient operation. */
12573 #define __HAVE_ARCH_CMPXCHG
12574
12575 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
12576 index 6160761..00cac88 100644
12577 --- a/arch/tile/include/asm/cache.h
12578 +++ b/arch/tile/include/asm/cache.h
12579 @@ -15,11 +15,12 @@
12580 #ifndef _ASM_TILE_CACHE_H
12581 #define _ASM_TILE_CACHE_H
12582
12583 +#include <linux/const.h>
12584 #include <arch/chip.h>
12585
12586 /* bytes per L1 data cache line */
12587 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
12588 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12589 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12590
12591 /* bytes per L2 cache line */
12592 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
12593 diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
12594 index b6cde32..c0cb736 100644
12595 --- a/arch/tile/include/asm/uaccess.h
12596 +++ b/arch/tile/include/asm/uaccess.h
12597 @@ -414,9 +414,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
12598 const void __user *from,
12599 unsigned long n)
12600 {
12601 - int sz = __compiletime_object_size(to);
12602 + size_t sz = __compiletime_object_size(to);
12603
12604 - if (likely(sz == -1 || sz >= n))
12605 + if (likely(sz == (size_t)-1 || sz >= n))
12606 n = _copy_from_user(to, from, n);
12607 else
12608 copy_from_user_overflow();
12609 diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
12610 index e514899..f8743c4 100644
12611 --- a/arch/tile/mm/hugetlbpage.c
12612 +++ b/arch/tile/mm/hugetlbpage.c
12613 @@ -207,6 +207,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
12614 info.high_limit = TASK_SIZE;
12615 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
12616 info.align_offset = 0;
12617 + info.threadstack_offset = 0;
12618 return vm_unmapped_area(&info);
12619 }
12620
12621 @@ -224,6 +225,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
12622 info.high_limit = current->mm->mmap_base;
12623 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
12624 info.align_offset = 0;
12625 + info.threadstack_offset = 0;
12626 addr = vm_unmapped_area(&info);
12627
12628 /*
12629 diff --git a/arch/um/Makefile b/arch/um/Makefile
12630 index e4b1a96..16162f8 100644
12631 --- a/arch/um/Makefile
12632 +++ b/arch/um/Makefile
12633 @@ -72,6 +72,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
12634 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
12635 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
12636
12637 +ifdef CONSTIFY_PLUGIN
12638 +USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12639 +endif
12640 +
12641 #This will adjust *FLAGS accordingly to the platform.
12642 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
12643
12644 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
12645 index 19e1bdd..3665b77 100644
12646 --- a/arch/um/include/asm/cache.h
12647 +++ b/arch/um/include/asm/cache.h
12648 @@ -1,6 +1,7 @@
12649 #ifndef __UM_CACHE_H
12650 #define __UM_CACHE_H
12651
12652 +#include <linux/const.h>
12653
12654 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
12655 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
12656 @@ -12,6 +13,6 @@
12657 # define L1_CACHE_SHIFT 5
12658 #endif
12659
12660 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12661 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12662
12663 #endif
12664 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
12665 index 2e0a6b1..a64d0f5 100644
12666 --- a/arch/um/include/asm/kmap_types.h
12667 +++ b/arch/um/include/asm/kmap_types.h
12668 @@ -8,6 +8,6 @@
12669
12670 /* No more #include "asm/arch/kmap_types.h" ! */
12671
12672 -#define KM_TYPE_NR 14
12673 +#define KM_TYPE_NR 15
12674
12675 #endif
12676 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
12677 index 5ff53d9..5850cdf 100644
12678 --- a/arch/um/include/asm/page.h
12679 +++ b/arch/um/include/asm/page.h
12680 @@ -14,6 +14,9 @@
12681 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
12682 #define PAGE_MASK (~(PAGE_SIZE-1))
12683
12684 +#define ktla_ktva(addr) (addr)
12685 +#define ktva_ktla(addr) (addr)
12686 +
12687 #ifndef __ASSEMBLY__
12688
12689 struct page;
12690 diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
12691 index 0032f92..cd151e0 100644
12692 --- a/arch/um/include/asm/pgtable-3level.h
12693 +++ b/arch/um/include/asm/pgtable-3level.h
12694 @@ -58,6 +58,7 @@
12695 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
12696 #define pud_populate(mm, pud, pmd) \
12697 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
12698 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
12699
12700 #ifdef CONFIG_64BIT
12701 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
12702 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
12703 index f17bca8..48adb87 100644
12704 --- a/arch/um/kernel/process.c
12705 +++ b/arch/um/kernel/process.c
12706 @@ -356,22 +356,6 @@ int singlestepping(void * t)
12707 return 2;
12708 }
12709
12710 -/*
12711 - * Only x86 and x86_64 have an arch_align_stack().
12712 - * All other arches have "#define arch_align_stack(x) (x)"
12713 - * in their asm/exec.h
12714 - * As this is included in UML from asm-um/system-generic.h,
12715 - * we can use it to behave as the subarch does.
12716 - */
12717 -#ifndef arch_align_stack
12718 -unsigned long arch_align_stack(unsigned long sp)
12719 -{
12720 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
12721 - sp -= get_random_int() % 8192;
12722 - return sp & ~0xf;
12723 -}
12724 -#endif
12725 -
12726 unsigned long get_wchan(struct task_struct *p)
12727 {
12728 unsigned long stack_page, sp, ip;
12729 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
12730 index ad8f795..2c7eec6 100644
12731 --- a/arch/unicore32/include/asm/cache.h
12732 +++ b/arch/unicore32/include/asm/cache.h
12733 @@ -12,8 +12,10 @@
12734 #ifndef __UNICORE_CACHE_H__
12735 #define __UNICORE_CACHE_H__
12736
12737 -#define L1_CACHE_SHIFT (5)
12738 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12739 +#include <linux/const.h>
12740 +
12741 +#define L1_CACHE_SHIFT 5
12742 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12743
12744 /*
12745 * Memory returned by kmalloc() may be used for DMA, so we must make
12746 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
12747 index d24887b..267d526 100644
12748 --- a/arch/x86/Kconfig
12749 +++ b/arch/x86/Kconfig
12750 @@ -128,7 +128,7 @@ config X86
12751 select RTC_LIB
12752 select HAVE_DEBUG_STACKOVERFLOW
12753 select HAVE_IRQ_EXIT_ON_IRQ_STACK if X86_64
12754 - select HAVE_CC_STACKPROTECTOR
12755 + select HAVE_CC_STACKPROTECTOR if X86_64 || !PAX_MEMORY_UDEREF
12756 select GENERIC_CPU_AUTOPROBE
12757 select HAVE_ARCH_AUDITSYSCALL
12758 select ARCH_SUPPORTS_ATOMIC_RMW
12759 @@ -253,7 +253,7 @@ config X86_HT
12760
12761 config X86_32_LAZY_GS
12762 def_bool y
12763 - depends on X86_32 && !CC_STACKPROTECTOR
12764 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
12765
12766 config ARCH_HWEIGHT_CFLAGS
12767 string
12768 @@ -549,6 +549,7 @@ config SCHED_OMIT_FRAME_POINTER
12769
12770 menuconfig HYPERVISOR_GUEST
12771 bool "Linux guest support"
12772 + depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_GUEST || (GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_XEN)
12773 ---help---
12774 Say Y here to enable options for running Linux under various hyper-
12775 visors. This option enables basic hypervisor detection and platform
12776 @@ -1076,6 +1077,7 @@ choice
12777
12778 config NOHIGHMEM
12779 bool "off"
12780 + depends on !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12781 ---help---
12782 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
12783 However, the address space of 32-bit x86 processors is only 4
12784 @@ -1112,6 +1114,7 @@ config NOHIGHMEM
12785
12786 config HIGHMEM4G
12787 bool "4GB"
12788 + depends on !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12789 ---help---
12790 Select this if you have a 32-bit processor and between 1 and 4
12791 gigabytes of physical RAM.
12792 @@ -1164,7 +1167,7 @@ config PAGE_OFFSET
12793 hex
12794 default 0xB0000000 if VMSPLIT_3G_OPT
12795 default 0x80000000 if VMSPLIT_2G
12796 - default 0x78000000 if VMSPLIT_2G_OPT
12797 + default 0x70000000 if VMSPLIT_2G_OPT
12798 default 0x40000000 if VMSPLIT_1G
12799 default 0xC0000000
12800 depends on X86_32
12801 @@ -1577,6 +1580,7 @@ source kernel/Kconfig.hz
12802
12803 config KEXEC
12804 bool "kexec system call"
12805 + depends on !GRKERNSEC_KMEM
12806 ---help---
12807 kexec is a system call that implements the ability to shutdown your
12808 current kernel, and to start another kernel. It is like a reboot
12809 @@ -1727,7 +1731,9 @@ config X86_NEED_RELOCS
12810
12811 config PHYSICAL_ALIGN
12812 hex "Alignment value to which kernel should be aligned"
12813 - default "0x200000"
12814 + default "0x1000000"
12815 + range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
12816 + range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
12817 range 0x2000 0x1000000 if X86_32
12818 range 0x200000 0x1000000 if X86_64
12819 ---help---
12820 @@ -1810,6 +1816,7 @@ config COMPAT_VDSO
12821 def_bool n
12822 prompt "Disable the 32-bit vDSO (needed for glibc 2.3.3)"
12823 depends on X86_32 || IA32_EMULATION
12824 + depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
12825 ---help---
12826 Certain buggy versions of glibc will crash if they are
12827 presented with a 32-bit vDSO that is not mapped at the address
12828 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
12829 index 6983314..54ad7e8 100644
12830 --- a/arch/x86/Kconfig.cpu
12831 +++ b/arch/x86/Kconfig.cpu
12832 @@ -319,7 +319,7 @@ config X86_PPRO_FENCE
12833
12834 config X86_F00F_BUG
12835 def_bool y
12836 - depends on M586MMX || M586TSC || M586 || M486
12837 + depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
12838
12839 config X86_INVD_BUG
12840 def_bool y
12841 @@ -327,7 +327,7 @@ config X86_INVD_BUG
12842
12843 config X86_ALIGNMENT_16
12844 def_bool y
12845 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12846 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12847
12848 config X86_INTEL_USERCOPY
12849 def_bool y
12850 @@ -369,7 +369,7 @@ config X86_CMPXCHG64
12851 # generates cmov.
12852 config X86_CMOV
12853 def_bool y
12854 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12855 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12856
12857 config X86_MINIMUM_CPU_FAMILY
12858 int
12859 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
12860 index 61bd2ad..50b625d 100644
12861 --- a/arch/x86/Kconfig.debug
12862 +++ b/arch/x86/Kconfig.debug
12863 @@ -93,7 +93,7 @@ config EFI_PGT_DUMP
12864 config DEBUG_RODATA
12865 bool "Write protect kernel read-only data structures"
12866 default y
12867 - depends on DEBUG_KERNEL
12868 + depends on DEBUG_KERNEL && BROKEN
12869 ---help---
12870 Mark the kernel read-only data as write-protected in the pagetables,
12871 in order to catch accidental (and incorrect) writes to such const
12872 @@ -111,7 +111,7 @@ config DEBUG_RODATA_TEST
12873
12874 config DEBUG_SET_MODULE_RONX
12875 bool "Set loadable kernel module data as NX and text as RO"
12876 - depends on MODULES
12877 + depends on MODULES && BROKEN
12878 ---help---
12879 This option helps catch unintended modifications to loadable
12880 kernel module's text and read-only data. It also prevents execution
12881 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
12882 index 33f71b0..c2cefa2 100644
12883 --- a/arch/x86/Makefile
12884 +++ b/arch/x86/Makefile
12885 @@ -71,9 +71,6 @@ ifeq ($(CONFIG_X86_32),y)
12886 # CPU-specific tuning. Anything which can be shared with UML should go here.
12887 include $(srctree)/arch/x86/Makefile_32.cpu
12888 KBUILD_CFLAGS += $(cflags-y)
12889 -
12890 - # temporary until string.h is fixed
12891 - KBUILD_CFLAGS += -ffreestanding
12892 else
12893 BITS := 64
12894 UTS_MACHINE := x86_64
12895 @@ -114,6 +111,9 @@ else
12896 KBUILD_CFLAGS += $(call cc-option,-maccumulate-outgoing-args)
12897 endif
12898
12899 +# temporary until string.h is fixed
12900 +KBUILD_CFLAGS += -ffreestanding
12901 +
12902 # Make sure compiler does not have buggy stack-protector support.
12903 ifdef CONFIG_CC_STACKPROTECTOR
12904 cc_has_sp := $(srctree)/scripts/gcc-x86_$(BITS)-has-stack-protector.sh
12905 @@ -271,3 +271,12 @@ define archhelp
12906 echo ' FDINITRD=file initrd for the booted kernel'
12907 echo ' kvmconfig - Enable additional options for guest kernel support'
12908 endef
12909 +
12910 +define OLD_LD
12911 +
12912 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
12913 +*** Please upgrade your binutils to 2.18 or newer
12914 +endef
12915 +
12916 +archprepare:
12917 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
12918 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
12919 index dbe8dd2..2f0a98f 100644
12920 --- a/arch/x86/boot/Makefile
12921 +++ b/arch/x86/boot/Makefile
12922 @@ -52,6 +52,9 @@ $(obj)/cpustr.h: $(obj)/mkcpustr FORCE
12923 # ---------------------------------------------------------------------------
12924
12925 KBUILD_CFLAGS := $(USERINCLUDE) $(REALMODE_CFLAGS) -D_SETUP
12926 +ifdef CONSTIFY_PLUGIN
12927 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12928 +endif
12929 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12930 GCOV_PROFILE := n
12931
12932 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
12933 index 878e4b9..20537ab 100644
12934 --- a/arch/x86/boot/bitops.h
12935 +++ b/arch/x86/boot/bitops.h
12936 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12937 u8 v;
12938 const u32 *p = (const u32 *)addr;
12939
12940 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12941 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12942 return v;
12943 }
12944
12945 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12946
12947 static inline void set_bit(int nr, void *addr)
12948 {
12949 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12950 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12951 }
12952
12953 #endif /* BOOT_BITOPS_H */
12954 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
12955 index bd49ec6..94c7f58 100644
12956 --- a/arch/x86/boot/boot.h
12957 +++ b/arch/x86/boot/boot.h
12958 @@ -84,7 +84,7 @@ static inline void io_delay(void)
12959 static inline u16 ds(void)
12960 {
12961 u16 seg;
12962 - asm("movw %%ds,%0" : "=rm" (seg));
12963 + asm volatile("movw %%ds,%0" : "=rm" (seg));
12964 return seg;
12965 }
12966
12967 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
12968 index 0fcd913..3bb5c42 100644
12969 --- a/arch/x86/boot/compressed/Makefile
12970 +++ b/arch/x86/boot/compressed/Makefile
12971 @@ -16,6 +16,9 @@ KBUILD_CFLAGS += $(cflags-y)
12972 KBUILD_CFLAGS += -mno-mmx -mno-sse
12973 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
12974 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
12975 +ifdef CONSTIFY_PLUGIN
12976 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12977 +endif
12978
12979 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12980 GCOV_PROFILE := n
12981 diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
12982 index a53440e..c3dbf1e 100644
12983 --- a/arch/x86/boot/compressed/efi_stub_32.S
12984 +++ b/arch/x86/boot/compressed/efi_stub_32.S
12985 @@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
12986 * parameter 2, ..., param n. To make things easy, we save the return
12987 * address of efi_call_phys in a global variable.
12988 */
12989 - popl %ecx
12990 - movl %ecx, saved_return_addr(%edx)
12991 - /* get the function pointer into ECX*/
12992 - popl %ecx
12993 - movl %ecx, efi_rt_function_ptr(%edx)
12994 + popl saved_return_addr(%edx)
12995 + popl efi_rt_function_ptr(%edx)
12996
12997 /*
12998 * 3. Call the physical function.
12999 */
13000 - call *%ecx
13001 + call *efi_rt_function_ptr(%edx)
13002
13003 /*
13004 * 4. Balance the stack. And because EAX contain the return value,
13005 @@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
13006 1: popl %edx
13007 subl $1b, %edx
13008
13009 - movl efi_rt_function_ptr(%edx), %ecx
13010 - pushl %ecx
13011 + pushl efi_rt_function_ptr(%edx)
13012
13013 /*
13014 * 10. Push the saved return address onto the stack and return.
13015 */
13016 - movl saved_return_addr(%edx), %ecx
13017 - pushl %ecx
13018 - ret
13019 + jmpl *saved_return_addr(%edx)
13020 ENDPROC(efi_call_phys)
13021 .previous
13022
13023 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
13024 index cbed140..5f2ca57 100644
13025 --- a/arch/x86/boot/compressed/head_32.S
13026 +++ b/arch/x86/boot/compressed/head_32.S
13027 @@ -140,10 +140,10 @@ preferred_addr:
13028 addl %eax, %ebx
13029 notl %eax
13030 andl %eax, %ebx
13031 - cmpl $LOAD_PHYSICAL_ADDR, %ebx
13032 + cmpl $____LOAD_PHYSICAL_ADDR, %ebx
13033 jge 1f
13034 #endif
13035 - movl $LOAD_PHYSICAL_ADDR, %ebx
13036 + movl $____LOAD_PHYSICAL_ADDR, %ebx
13037 1:
13038
13039 /* Target address to relocate to for decompression */
13040 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
13041 index 2884e0c..904a2f7 100644
13042 --- a/arch/x86/boot/compressed/head_64.S
13043 +++ b/arch/x86/boot/compressed/head_64.S
13044 @@ -94,10 +94,10 @@ ENTRY(startup_32)
13045 addl %eax, %ebx
13046 notl %eax
13047 andl %eax, %ebx
13048 - cmpl $LOAD_PHYSICAL_ADDR, %ebx
13049 + cmpl $____LOAD_PHYSICAL_ADDR, %ebx
13050 jge 1f
13051 #endif
13052 - movl $LOAD_PHYSICAL_ADDR, %ebx
13053 + movl $____LOAD_PHYSICAL_ADDR, %ebx
13054 1:
13055
13056 /* Target address to relocate to for decompression */
13057 @@ -322,10 +322,10 @@ preferred_addr:
13058 addq %rax, %rbp
13059 notq %rax
13060 andq %rax, %rbp
13061 - cmpq $LOAD_PHYSICAL_ADDR, %rbp
13062 + cmpq $____LOAD_PHYSICAL_ADDR, %rbp
13063 jge 1f
13064 #endif
13065 - movq $LOAD_PHYSICAL_ADDR, %rbp
13066 + movq $____LOAD_PHYSICAL_ADDR, %rbp
13067 1:
13068
13069 /* Target address to relocate to for decompression */
13070 @@ -431,8 +431,8 @@ gdt:
13071 .long gdt
13072 .word 0
13073 .quad 0x0000000000000000 /* NULL descriptor */
13074 - .quad 0x00af9a000000ffff /* __KERNEL_CS */
13075 - .quad 0x00cf92000000ffff /* __KERNEL_DS */
13076 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
13077 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
13078 .quad 0x0080890000000000 /* TS descriptor */
13079 .quad 0x0000000000000000 /* TS continued */
13080 gdt_end:
13081 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
13082 index 57ab74d..7c52182 100644
13083 --- a/arch/x86/boot/compressed/misc.c
13084 +++ b/arch/x86/boot/compressed/misc.c
13085 @@ -242,7 +242,7 @@ static void handle_relocations(void *output, unsigned long output_len)
13086 * Calculate the delta between where vmlinux was linked to load
13087 * and where it was actually loaded.
13088 */
13089 - delta = min_addr - LOAD_PHYSICAL_ADDR;
13090 + delta = min_addr - ____LOAD_PHYSICAL_ADDR;
13091 if (!delta) {
13092 debug_putstr("No relocation needed... ");
13093 return;
13094 @@ -312,7 +312,7 @@ static void parse_elf(void *output)
13095 Elf32_Ehdr ehdr;
13096 Elf32_Phdr *phdrs, *phdr;
13097 #endif
13098 - void *dest;
13099 + void *dest, *prev;
13100 int i;
13101
13102 memcpy(&ehdr, output, sizeof(ehdr));
13103 @@ -339,13 +339,16 @@ static void parse_elf(void *output)
13104 case PT_LOAD:
13105 #ifdef CONFIG_RELOCATABLE
13106 dest = output;
13107 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
13108 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
13109 #else
13110 dest = (void *)(phdr->p_paddr);
13111 #endif
13112 memcpy(dest,
13113 output + phdr->p_offset,
13114 phdr->p_filesz);
13115 + if (i)
13116 + memset(prev, 0xff, dest - prev);
13117 + prev = dest + phdr->p_filesz;
13118 break;
13119 default: /* Ignore other PT_* */ break;
13120 }
13121 @@ -395,7 +398,7 @@ asmlinkage __visible void *decompress_kernel(void *rmode, memptr heap,
13122 error("Destination address too large");
13123 #endif
13124 #ifndef CONFIG_RELOCATABLE
13125 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
13126 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
13127 error("Wrong destination address");
13128 #endif
13129
13130 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
13131 index 1fd7d57..0f7d096 100644
13132 --- a/arch/x86/boot/cpucheck.c
13133 +++ b/arch/x86/boot/cpucheck.c
13134 @@ -125,9 +125,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
13135 u32 ecx = MSR_K7_HWCR;
13136 u32 eax, edx;
13137
13138 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13139 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13140 eax &= ~(1 << 15);
13141 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13142 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13143
13144 get_cpuflags(); /* Make sure it really did something */
13145 err = check_cpuflags();
13146 @@ -140,9 +140,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
13147 u32 ecx = MSR_VIA_FCR;
13148 u32 eax, edx;
13149
13150 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13151 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13152 eax |= (1<<1)|(1<<7);
13153 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13154 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13155
13156 set_bit(X86_FEATURE_CX8, cpu.flags);
13157 err = check_cpuflags();
13158 @@ -153,12 +153,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
13159 u32 eax, edx;
13160 u32 level = 1;
13161
13162 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13163 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
13164 - asm("cpuid"
13165 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13166 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
13167 + asm volatile("cpuid"
13168 : "+a" (level), "=d" (cpu.flags[0])
13169 : : "ecx", "ebx");
13170 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13171 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13172
13173 err = check_cpuflags();
13174 } else if (err == 0x01 &&
13175 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
13176 index 7a6d43a..edf6e40 100644
13177 --- a/arch/x86/boot/header.S
13178 +++ b/arch/x86/boot/header.S
13179 @@ -438,10 +438,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
13180 # single linked list of
13181 # struct setup_data
13182
13183 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
13184 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
13185
13186 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
13187 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13188 +#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
13189 +#else
13190 #define VO_INIT_SIZE (VO__end - VO__text)
13191 +#endif
13192 #if ZO_INIT_SIZE > VO_INIT_SIZE
13193 #define INIT_SIZE ZO_INIT_SIZE
13194 #else
13195 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
13196 index db75d07..8e6d0af 100644
13197 --- a/arch/x86/boot/memory.c
13198 +++ b/arch/x86/boot/memory.c
13199 @@ -19,7 +19,7 @@
13200
13201 static int detect_memory_e820(void)
13202 {
13203 - int count = 0;
13204 + unsigned int count = 0;
13205 struct biosregs ireg, oreg;
13206 struct e820entry *desc = boot_params.e820_map;
13207 static struct e820entry buf; /* static so it is zeroed */
13208 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
13209 index ba3e100..6501b8f 100644
13210 --- a/arch/x86/boot/video-vesa.c
13211 +++ b/arch/x86/boot/video-vesa.c
13212 @@ -201,6 +201,7 @@ static void vesa_store_pm_info(void)
13213
13214 boot_params.screen_info.vesapm_seg = oreg.es;
13215 boot_params.screen_info.vesapm_off = oreg.di;
13216 + boot_params.screen_info.vesapm_size = oreg.cx;
13217 }
13218
13219 /*
13220 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
13221 index 43eda28..5ab5fdb 100644
13222 --- a/arch/x86/boot/video.c
13223 +++ b/arch/x86/boot/video.c
13224 @@ -96,7 +96,7 @@ static void store_mode_params(void)
13225 static unsigned int get_entry(void)
13226 {
13227 char entry_buf[4];
13228 - int i, len = 0;
13229 + unsigned int i, len = 0;
13230 int key;
13231 unsigned int v;
13232
13233 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
13234 index 9105655..41779c1 100644
13235 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
13236 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
13237 @@ -8,6 +8,8 @@
13238 * including this sentence is retained in full.
13239 */
13240
13241 +#include <asm/alternative-asm.h>
13242 +
13243 .extern crypto_ft_tab
13244 .extern crypto_it_tab
13245 .extern crypto_fl_tab
13246 @@ -70,6 +72,8 @@
13247 je B192; \
13248 leaq 32(r9),r9;
13249
13250 +#define ret pax_force_retaddr; ret
13251 +
13252 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
13253 movq r1,r2; \
13254 movq r3,r4; \
13255 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
13256 index 477e9d7..c92c7d8 100644
13257 --- a/arch/x86/crypto/aesni-intel_asm.S
13258 +++ b/arch/x86/crypto/aesni-intel_asm.S
13259 @@ -31,6 +31,7 @@
13260
13261 #include <linux/linkage.h>
13262 #include <asm/inst.h>
13263 +#include <asm/alternative-asm.h>
13264
13265 #ifdef __x86_64__
13266 .data
13267 @@ -205,7 +206,7 @@ enc: .octa 0x2
13268 * num_initial_blocks = b mod 4
13269 * encrypt the initial num_initial_blocks blocks and apply ghash on
13270 * the ciphertext
13271 -* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13272 +* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13273 * are clobbered
13274 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
13275 */
13276 @@ -214,8 +215,8 @@ enc: .octa 0x2
13277 .macro INITIAL_BLOCKS_DEC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
13278 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
13279 mov arg7, %r10 # %r10 = AAD
13280 - mov arg8, %r12 # %r12 = aadLen
13281 - mov %r12, %r11
13282 + mov arg8, %r15 # %r15 = aadLen
13283 + mov %r15, %r11
13284 pxor %xmm\i, %xmm\i
13285 _get_AAD_loop\num_initial_blocks\operation:
13286 movd (%r10), \TMP1
13287 @@ -223,15 +224,15 @@ _get_AAD_loop\num_initial_blocks\operation:
13288 psrldq $4, %xmm\i
13289 pxor \TMP1, %xmm\i
13290 add $4, %r10
13291 - sub $4, %r12
13292 + sub $4, %r15
13293 jne _get_AAD_loop\num_initial_blocks\operation
13294 cmp $16, %r11
13295 je _get_AAD_loop2_done\num_initial_blocks\operation
13296 - mov $16, %r12
13297 + mov $16, %r15
13298 _get_AAD_loop2\num_initial_blocks\operation:
13299 psrldq $4, %xmm\i
13300 - sub $4, %r12
13301 - cmp %r11, %r12
13302 + sub $4, %r15
13303 + cmp %r11, %r15
13304 jne _get_AAD_loop2\num_initial_blocks\operation
13305 _get_AAD_loop2_done\num_initial_blocks\operation:
13306 movdqa SHUF_MASK(%rip), %xmm14
13307 @@ -443,7 +444,7 @@ _initial_blocks_done\num_initial_blocks\operation:
13308 * num_initial_blocks = b mod 4
13309 * encrypt the initial num_initial_blocks blocks and apply ghash on
13310 * the ciphertext
13311 -* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13312 +* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13313 * are clobbered
13314 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
13315 */
13316 @@ -452,8 +453,8 @@ _initial_blocks_done\num_initial_blocks\operation:
13317 .macro INITIAL_BLOCKS_ENC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
13318 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
13319 mov arg7, %r10 # %r10 = AAD
13320 - mov arg8, %r12 # %r12 = aadLen
13321 - mov %r12, %r11
13322 + mov arg8, %r15 # %r15 = aadLen
13323 + mov %r15, %r11
13324 pxor %xmm\i, %xmm\i
13325 _get_AAD_loop\num_initial_blocks\operation:
13326 movd (%r10), \TMP1
13327 @@ -461,15 +462,15 @@ _get_AAD_loop\num_initial_blocks\operation:
13328 psrldq $4, %xmm\i
13329 pxor \TMP1, %xmm\i
13330 add $4, %r10
13331 - sub $4, %r12
13332 + sub $4, %r15
13333 jne _get_AAD_loop\num_initial_blocks\operation
13334 cmp $16, %r11
13335 je _get_AAD_loop2_done\num_initial_blocks\operation
13336 - mov $16, %r12
13337 + mov $16, %r15
13338 _get_AAD_loop2\num_initial_blocks\operation:
13339 psrldq $4, %xmm\i
13340 - sub $4, %r12
13341 - cmp %r11, %r12
13342 + sub $4, %r15
13343 + cmp %r11, %r15
13344 jne _get_AAD_loop2\num_initial_blocks\operation
13345 _get_AAD_loop2_done\num_initial_blocks\operation:
13346 movdqa SHUF_MASK(%rip), %xmm14
13347 @@ -1269,7 +1270,7 @@ TMP7 XMM1 XMM2 XMM3 XMM4 XMMDst
13348 *
13349 *****************************************************************************/
13350 ENTRY(aesni_gcm_dec)
13351 - push %r12
13352 + push %r15
13353 push %r13
13354 push %r14
13355 mov %rsp, %r14
13356 @@ -1279,8 +1280,8 @@ ENTRY(aesni_gcm_dec)
13357 */
13358 sub $VARIABLE_OFFSET, %rsp
13359 and $~63, %rsp # align rsp to 64 bytes
13360 - mov %arg6, %r12
13361 - movdqu (%r12), %xmm13 # %xmm13 = HashKey
13362 + mov %arg6, %r15
13363 + movdqu (%r15), %xmm13 # %xmm13 = HashKey
13364 movdqa SHUF_MASK(%rip), %xmm2
13365 PSHUFB_XMM %xmm2, %xmm13
13366
13367 @@ -1308,10 +1309,10 @@ ENTRY(aesni_gcm_dec)
13368 movdqa %xmm13, HashKey(%rsp) # store HashKey<<1 (mod poly)
13369 mov %arg4, %r13 # save the number of bytes of plaintext/ciphertext
13370 and $-16, %r13 # %r13 = %r13 - (%r13 mod 16)
13371 - mov %r13, %r12
13372 - and $(3<<4), %r12
13373 + mov %r13, %r15
13374 + and $(3<<4), %r15
13375 jz _initial_num_blocks_is_0_decrypt
13376 - cmp $(2<<4), %r12
13377 + cmp $(2<<4), %r15
13378 jb _initial_num_blocks_is_1_decrypt
13379 je _initial_num_blocks_is_2_decrypt
13380 _initial_num_blocks_is_3_decrypt:
13381 @@ -1361,16 +1362,16 @@ _zero_cipher_left_decrypt:
13382 sub $16, %r11
13383 add %r13, %r11
13384 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte block
13385 - lea SHIFT_MASK+16(%rip), %r12
13386 - sub %r13, %r12
13387 + lea SHIFT_MASK+16(%rip), %r15
13388 + sub %r13, %r15
13389 # adjust the shuffle mask pointer to be able to shift 16-%r13 bytes
13390 # (%r13 is the number of bytes in plaintext mod 16)
13391 - movdqu (%r12), %xmm2 # get the appropriate shuffle mask
13392 + movdqu (%r15), %xmm2 # get the appropriate shuffle mask
13393 PSHUFB_XMM %xmm2, %xmm1 # right shift 16-%r13 butes
13394
13395 movdqa %xmm1, %xmm2
13396 pxor %xmm1, %xmm0 # Ciphertext XOR E(K, Yn)
13397 - movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
13398 + movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
13399 # get the appropriate mask to mask out top 16-%r13 bytes of %xmm0
13400 pand %xmm1, %xmm0 # mask out top 16-%r13 bytes of %xmm0
13401 pand %xmm1, %xmm2
13402 @@ -1399,9 +1400,9 @@ _less_than_8_bytes_left_decrypt:
13403 sub $1, %r13
13404 jne _less_than_8_bytes_left_decrypt
13405 _multiple_of_16_bytes_decrypt:
13406 - mov arg8, %r12 # %r13 = aadLen (number of bytes)
13407 - shl $3, %r12 # convert into number of bits
13408 - movd %r12d, %xmm15 # len(A) in %xmm15
13409 + mov arg8, %r15 # %r13 = aadLen (number of bytes)
13410 + shl $3, %r15 # convert into number of bits
13411 + movd %r15d, %xmm15 # len(A) in %xmm15
13412 shl $3, %arg4 # len(C) in bits (*128)
13413 MOVQ_R64_XMM %arg4, %xmm1
13414 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
13415 @@ -1440,7 +1441,8 @@ _return_T_done_decrypt:
13416 mov %r14, %rsp
13417 pop %r14
13418 pop %r13
13419 - pop %r12
13420 + pop %r15
13421 + pax_force_retaddr
13422 ret
13423 ENDPROC(aesni_gcm_dec)
13424
13425 @@ -1529,7 +1531,7 @@ ENDPROC(aesni_gcm_dec)
13426 * poly = x^128 + x^127 + x^126 + x^121 + 1
13427 ***************************************************************************/
13428 ENTRY(aesni_gcm_enc)
13429 - push %r12
13430 + push %r15
13431 push %r13
13432 push %r14
13433 mov %rsp, %r14
13434 @@ -1539,8 +1541,8 @@ ENTRY(aesni_gcm_enc)
13435 #
13436 sub $VARIABLE_OFFSET, %rsp
13437 and $~63, %rsp
13438 - mov %arg6, %r12
13439 - movdqu (%r12), %xmm13
13440 + mov %arg6, %r15
13441 + movdqu (%r15), %xmm13
13442 movdqa SHUF_MASK(%rip), %xmm2
13443 PSHUFB_XMM %xmm2, %xmm13
13444
13445 @@ -1564,13 +1566,13 @@ ENTRY(aesni_gcm_enc)
13446 movdqa %xmm13, HashKey(%rsp)
13447 mov %arg4, %r13 # %xmm13 holds HashKey<<1 (mod poly)
13448 and $-16, %r13
13449 - mov %r13, %r12
13450 + mov %r13, %r15
13451
13452 # Encrypt first few blocks
13453
13454 - and $(3<<4), %r12
13455 + and $(3<<4), %r15
13456 jz _initial_num_blocks_is_0_encrypt
13457 - cmp $(2<<4), %r12
13458 + cmp $(2<<4), %r15
13459 jb _initial_num_blocks_is_1_encrypt
13460 je _initial_num_blocks_is_2_encrypt
13461 _initial_num_blocks_is_3_encrypt:
13462 @@ -1623,14 +1625,14 @@ _zero_cipher_left_encrypt:
13463 sub $16, %r11
13464 add %r13, %r11
13465 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte blocks
13466 - lea SHIFT_MASK+16(%rip), %r12
13467 - sub %r13, %r12
13468 + lea SHIFT_MASK+16(%rip), %r15
13469 + sub %r13, %r15
13470 # adjust the shuffle mask pointer to be able to shift 16-r13 bytes
13471 # (%r13 is the number of bytes in plaintext mod 16)
13472 - movdqu (%r12), %xmm2 # get the appropriate shuffle mask
13473 + movdqu (%r15), %xmm2 # get the appropriate shuffle mask
13474 PSHUFB_XMM %xmm2, %xmm1 # shift right 16-r13 byte
13475 pxor %xmm1, %xmm0 # Plaintext XOR Encrypt(K, Yn)
13476 - movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
13477 + movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
13478 # get the appropriate mask to mask out top 16-r13 bytes of xmm0
13479 pand %xmm1, %xmm0 # mask out top 16-r13 bytes of xmm0
13480 movdqa SHUF_MASK(%rip), %xmm10
13481 @@ -1663,9 +1665,9 @@ _less_than_8_bytes_left_encrypt:
13482 sub $1, %r13
13483 jne _less_than_8_bytes_left_encrypt
13484 _multiple_of_16_bytes_encrypt:
13485 - mov arg8, %r12 # %r12 = addLen (number of bytes)
13486 - shl $3, %r12
13487 - movd %r12d, %xmm15 # len(A) in %xmm15
13488 + mov arg8, %r15 # %r15 = addLen (number of bytes)
13489 + shl $3, %r15
13490 + movd %r15d, %xmm15 # len(A) in %xmm15
13491 shl $3, %arg4 # len(C) in bits (*128)
13492 MOVQ_R64_XMM %arg4, %xmm1
13493 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
13494 @@ -1704,7 +1706,8 @@ _return_T_done_encrypt:
13495 mov %r14, %rsp
13496 pop %r14
13497 pop %r13
13498 - pop %r12
13499 + pop %r15
13500 + pax_force_retaddr
13501 ret
13502 ENDPROC(aesni_gcm_enc)
13503
13504 @@ -1722,6 +1725,7 @@ _key_expansion_256a:
13505 pxor %xmm1, %xmm0
13506 movaps %xmm0, (TKEYP)
13507 add $0x10, TKEYP
13508 + pax_force_retaddr
13509 ret
13510 ENDPROC(_key_expansion_128)
13511 ENDPROC(_key_expansion_256a)
13512 @@ -1748,6 +1752,7 @@ _key_expansion_192a:
13513 shufps $0b01001110, %xmm2, %xmm1
13514 movaps %xmm1, 0x10(TKEYP)
13515 add $0x20, TKEYP
13516 + pax_force_retaddr
13517 ret
13518 ENDPROC(_key_expansion_192a)
13519
13520 @@ -1768,6 +1773,7 @@ _key_expansion_192b:
13521
13522 movaps %xmm0, (TKEYP)
13523 add $0x10, TKEYP
13524 + pax_force_retaddr
13525 ret
13526 ENDPROC(_key_expansion_192b)
13527
13528 @@ -1781,6 +1787,7 @@ _key_expansion_256b:
13529 pxor %xmm1, %xmm2
13530 movaps %xmm2, (TKEYP)
13531 add $0x10, TKEYP
13532 + pax_force_retaddr
13533 ret
13534 ENDPROC(_key_expansion_256b)
13535
13536 @@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
13537 #ifndef __x86_64__
13538 popl KEYP
13539 #endif
13540 + pax_force_retaddr
13541 ret
13542 ENDPROC(aesni_set_key)
13543
13544 @@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
13545 popl KLEN
13546 popl KEYP
13547 #endif
13548 + pax_force_retaddr
13549 ret
13550 ENDPROC(aesni_enc)
13551
13552 @@ -1974,6 +1983,7 @@ _aesni_enc1:
13553 AESENC KEY STATE
13554 movaps 0x70(TKEYP), KEY
13555 AESENCLAST KEY STATE
13556 + pax_force_retaddr
13557 ret
13558 ENDPROC(_aesni_enc1)
13559
13560 @@ -2083,6 +2093,7 @@ _aesni_enc4:
13561 AESENCLAST KEY STATE2
13562 AESENCLAST KEY STATE3
13563 AESENCLAST KEY STATE4
13564 + pax_force_retaddr
13565 ret
13566 ENDPROC(_aesni_enc4)
13567
13568 @@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
13569 popl KLEN
13570 popl KEYP
13571 #endif
13572 + pax_force_retaddr
13573 ret
13574 ENDPROC(aesni_dec)
13575
13576 @@ -2164,6 +2176,7 @@ _aesni_dec1:
13577 AESDEC KEY STATE
13578 movaps 0x70(TKEYP), KEY
13579 AESDECLAST KEY STATE
13580 + pax_force_retaddr
13581 ret
13582 ENDPROC(_aesni_dec1)
13583
13584 @@ -2273,6 +2286,7 @@ _aesni_dec4:
13585 AESDECLAST KEY STATE2
13586 AESDECLAST KEY STATE3
13587 AESDECLAST KEY STATE4
13588 + pax_force_retaddr
13589 ret
13590 ENDPROC(_aesni_dec4)
13591
13592 @@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
13593 popl KEYP
13594 popl LEN
13595 #endif
13596 + pax_force_retaddr
13597 ret
13598 ENDPROC(aesni_ecb_enc)
13599
13600 @@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
13601 popl KEYP
13602 popl LEN
13603 #endif
13604 + pax_force_retaddr
13605 ret
13606 ENDPROC(aesni_ecb_dec)
13607
13608 @@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
13609 popl LEN
13610 popl IVP
13611 #endif
13612 + pax_force_retaddr
13613 ret
13614 ENDPROC(aesni_cbc_enc)
13615
13616 @@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
13617 popl LEN
13618 popl IVP
13619 #endif
13620 + pax_force_retaddr
13621 ret
13622 ENDPROC(aesni_cbc_dec)
13623
13624 @@ -2550,6 +2568,7 @@ _aesni_inc_init:
13625 mov $1, TCTR_LOW
13626 MOVQ_R64_XMM TCTR_LOW INC
13627 MOVQ_R64_XMM CTR TCTR_LOW
13628 + pax_force_retaddr
13629 ret
13630 ENDPROC(_aesni_inc_init)
13631
13632 @@ -2579,6 +2598,7 @@ _aesni_inc:
13633 .Linc_low:
13634 movaps CTR, IV
13635 PSHUFB_XMM BSWAP_MASK IV
13636 + pax_force_retaddr
13637 ret
13638 ENDPROC(_aesni_inc)
13639
13640 @@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
13641 .Lctr_enc_ret:
13642 movups IV, (IVP)
13643 .Lctr_enc_just_ret:
13644 + pax_force_retaddr
13645 ret
13646 ENDPROC(aesni_ctr_enc)
13647
13648 @@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
13649 pxor INC, STATE4
13650 movdqu STATE4, 0x70(OUTP)
13651
13652 + pax_force_retaddr
13653 ret
13654 ENDPROC(aesni_xts_crypt8)
13655
13656 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13657 index 246c670..466e2d6 100644
13658 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
13659 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13660 @@ -21,6 +21,7 @@
13661 */
13662
13663 #include <linux/linkage.h>
13664 +#include <asm/alternative-asm.h>
13665
13666 .file "blowfish-x86_64-asm.S"
13667 .text
13668 @@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
13669 jnz .L__enc_xor;
13670
13671 write_block();
13672 + pax_force_retaddr
13673 ret;
13674 .L__enc_xor:
13675 xor_block();
13676 + pax_force_retaddr
13677 ret;
13678 ENDPROC(__blowfish_enc_blk)
13679
13680 @@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
13681
13682 movq %r11, %rbp;
13683
13684 + pax_force_retaddr
13685 ret;
13686 ENDPROC(blowfish_dec_blk)
13687
13688 @@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
13689
13690 popq %rbx;
13691 popq %rbp;
13692 + pax_force_retaddr
13693 ret;
13694
13695 .L__enc_xor4:
13696 @@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
13697
13698 popq %rbx;
13699 popq %rbp;
13700 + pax_force_retaddr
13701 ret;
13702 ENDPROC(__blowfish_enc_blk_4way)
13703
13704 @@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
13705 popq %rbx;
13706 popq %rbp;
13707
13708 + pax_force_retaddr
13709 ret;
13710 ENDPROC(blowfish_dec_blk_4way)
13711 diff --git a/arch/x86/crypto/camellia-aesni-avx-asm_64.S b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13712 index ce71f92..1dce7ec 100644
13713 --- a/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13714 +++ b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13715 @@ -16,6 +16,7 @@
13716 */
13717
13718 #include <linux/linkage.h>
13719 +#include <asm/alternative-asm.h>
13720
13721 #define CAMELLIA_TABLE_BYTE_LEN 272
13722
13723 @@ -191,6 +192,7 @@ roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13724 roundsm16(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
13725 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, %xmm15,
13726 %rcx, (%r9));
13727 + pax_force_retaddr
13728 ret;
13729 ENDPROC(roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13730
13731 @@ -199,6 +201,7 @@ roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13732 roundsm16(%xmm4, %xmm5, %xmm6, %xmm7, %xmm0, %xmm1, %xmm2, %xmm3,
13733 %xmm12, %xmm13, %xmm14, %xmm15, %xmm8, %xmm9, %xmm10, %xmm11,
13734 %rax, (%r9));
13735 + pax_force_retaddr
13736 ret;
13737 ENDPROC(roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13738
13739 @@ -780,6 +783,7 @@ __camellia_enc_blk16:
13740 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13741 %xmm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 16(%rax));
13742
13743 + pax_force_retaddr
13744 ret;
13745
13746 .align 8
13747 @@ -865,6 +869,7 @@ __camellia_dec_blk16:
13748 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13749 %xmm15, (key_table)(CTX), (%rax), 1 * 16(%rax));
13750
13751 + pax_force_retaddr
13752 ret;
13753
13754 .align 8
13755 @@ -904,6 +909,7 @@ ENTRY(camellia_ecb_enc_16way)
13756 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13757 %xmm8, %rsi);
13758
13759 + pax_force_retaddr
13760 ret;
13761 ENDPROC(camellia_ecb_enc_16way)
13762
13763 @@ -932,6 +938,7 @@ ENTRY(camellia_ecb_dec_16way)
13764 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13765 %xmm8, %rsi);
13766
13767 + pax_force_retaddr
13768 ret;
13769 ENDPROC(camellia_ecb_dec_16way)
13770
13771 @@ -981,6 +988,7 @@ ENTRY(camellia_cbc_dec_16way)
13772 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13773 %xmm8, %rsi);
13774
13775 + pax_force_retaddr
13776 ret;
13777 ENDPROC(camellia_cbc_dec_16way)
13778
13779 @@ -1092,6 +1100,7 @@ ENTRY(camellia_ctr_16way)
13780 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13781 %xmm8, %rsi);
13782
13783 + pax_force_retaddr
13784 ret;
13785 ENDPROC(camellia_ctr_16way)
13786
13787 @@ -1234,6 +1243,7 @@ camellia_xts_crypt_16way:
13788 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13789 %xmm8, %rsi);
13790
13791 + pax_force_retaddr
13792 ret;
13793 ENDPROC(camellia_xts_crypt_16way)
13794
13795 diff --git a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13796 index 0e0b886..5a3123c 100644
13797 --- a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13798 +++ b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13799 @@ -11,6 +11,7 @@
13800 */
13801
13802 #include <linux/linkage.h>
13803 +#include <asm/alternative-asm.h>
13804
13805 #define CAMELLIA_TABLE_BYTE_LEN 272
13806
13807 @@ -230,6 +231,7 @@ roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13808 roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
13809 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
13810 %rcx, (%r9));
13811 + pax_force_retaddr
13812 ret;
13813 ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13814
13815 @@ -238,6 +240,7 @@ roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13816 roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
13817 %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
13818 %rax, (%r9));
13819 + pax_force_retaddr
13820 ret;
13821 ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13822
13823 @@ -820,6 +823,7 @@ __camellia_enc_blk32:
13824 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13825 %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
13826
13827 + pax_force_retaddr
13828 ret;
13829
13830 .align 8
13831 @@ -905,6 +909,7 @@ __camellia_dec_blk32:
13832 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13833 %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
13834
13835 + pax_force_retaddr
13836 ret;
13837
13838 .align 8
13839 @@ -948,6 +953,7 @@ ENTRY(camellia_ecb_enc_32way)
13840
13841 vzeroupper;
13842
13843 + pax_force_retaddr
13844 ret;
13845 ENDPROC(camellia_ecb_enc_32way)
13846
13847 @@ -980,6 +986,7 @@ ENTRY(camellia_ecb_dec_32way)
13848
13849 vzeroupper;
13850
13851 + pax_force_retaddr
13852 ret;
13853 ENDPROC(camellia_ecb_dec_32way)
13854
13855 @@ -1046,6 +1053,7 @@ ENTRY(camellia_cbc_dec_32way)
13856
13857 vzeroupper;
13858
13859 + pax_force_retaddr
13860 ret;
13861 ENDPROC(camellia_cbc_dec_32way)
13862
13863 @@ -1184,6 +1192,7 @@ ENTRY(camellia_ctr_32way)
13864
13865 vzeroupper;
13866
13867 + pax_force_retaddr
13868 ret;
13869 ENDPROC(camellia_ctr_32way)
13870
13871 @@ -1349,6 +1358,7 @@ camellia_xts_crypt_32way:
13872
13873 vzeroupper;
13874
13875 + pax_force_retaddr
13876 ret;
13877 ENDPROC(camellia_xts_crypt_32way)
13878
13879 diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
13880 index 310319c..db3d7b5 100644
13881 --- a/arch/x86/crypto/camellia-x86_64-asm_64.S
13882 +++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
13883 @@ -21,6 +21,7 @@
13884 */
13885
13886 #include <linux/linkage.h>
13887 +#include <asm/alternative-asm.h>
13888
13889 .file "camellia-x86_64-asm_64.S"
13890 .text
13891 @@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
13892 enc_outunpack(mov, RT1);
13893
13894 movq RRBP, %rbp;
13895 + pax_force_retaddr
13896 ret;
13897
13898 .L__enc_xor:
13899 enc_outunpack(xor, RT1);
13900
13901 movq RRBP, %rbp;
13902 + pax_force_retaddr
13903 ret;
13904 ENDPROC(__camellia_enc_blk)
13905
13906 @@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
13907 dec_outunpack();
13908
13909 movq RRBP, %rbp;
13910 + pax_force_retaddr
13911 ret;
13912 ENDPROC(camellia_dec_blk)
13913
13914 @@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
13915
13916 movq RRBP, %rbp;
13917 popq %rbx;
13918 + pax_force_retaddr
13919 ret;
13920
13921 .L__enc2_xor:
13922 @@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
13923
13924 movq RRBP, %rbp;
13925 popq %rbx;
13926 + pax_force_retaddr
13927 ret;
13928 ENDPROC(__camellia_enc_blk_2way)
13929
13930 @@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
13931
13932 movq RRBP, %rbp;
13933 movq RXOR, %rbx;
13934 + pax_force_retaddr
13935 ret;
13936 ENDPROC(camellia_dec_blk_2way)
13937 diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13938 index c35fd5d..2d8c7db 100644
13939 --- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13940 +++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13941 @@ -24,6 +24,7 @@
13942 */
13943
13944 #include <linux/linkage.h>
13945 +#include <asm/alternative-asm.h>
13946
13947 .file "cast5-avx-x86_64-asm_64.S"
13948
13949 @@ -281,6 +282,7 @@ __cast5_enc_blk16:
13950 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13951 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13952
13953 + pax_force_retaddr
13954 ret;
13955 ENDPROC(__cast5_enc_blk16)
13956
13957 @@ -352,6 +354,7 @@ __cast5_dec_blk16:
13958 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13959 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13960
13961 + pax_force_retaddr
13962 ret;
13963
13964 .L__skip_dec:
13965 @@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
13966 vmovdqu RR4, (6*4*4)(%r11);
13967 vmovdqu RL4, (7*4*4)(%r11);
13968
13969 + pax_force_retaddr
13970 ret;
13971 ENDPROC(cast5_ecb_enc_16way)
13972
13973 @@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
13974 vmovdqu RR4, (6*4*4)(%r11);
13975 vmovdqu RL4, (7*4*4)(%r11);
13976
13977 + pax_force_retaddr
13978 ret;
13979 ENDPROC(cast5_ecb_dec_16way)
13980
13981 @@ -430,10 +435,10 @@ ENTRY(cast5_cbc_dec_16way)
13982 * %rdx: src
13983 */
13984
13985 - pushq %r12;
13986 + pushq %r14;
13987
13988 movq %rsi, %r11;
13989 - movq %rdx, %r12;
13990 + movq %rdx, %r14;
13991
13992 vmovdqu (0*16)(%rdx), RL1;
13993 vmovdqu (1*16)(%rdx), RR1;
13994 @@ -447,16 +452,16 @@ ENTRY(cast5_cbc_dec_16way)
13995 call __cast5_dec_blk16;
13996
13997 /* xor with src */
13998 - vmovq (%r12), RX;
13999 + vmovq (%r14), RX;
14000 vpshufd $0x4f, RX, RX;
14001 vpxor RX, RR1, RR1;
14002 - vpxor 0*16+8(%r12), RL1, RL1;
14003 - vpxor 1*16+8(%r12), RR2, RR2;
14004 - vpxor 2*16+8(%r12), RL2, RL2;
14005 - vpxor 3*16+8(%r12), RR3, RR3;
14006 - vpxor 4*16+8(%r12), RL3, RL3;
14007 - vpxor 5*16+8(%r12), RR4, RR4;
14008 - vpxor 6*16+8(%r12), RL4, RL4;
14009 + vpxor 0*16+8(%r14), RL1, RL1;
14010 + vpxor 1*16+8(%r14), RR2, RR2;
14011 + vpxor 2*16+8(%r14), RL2, RL2;
14012 + vpxor 3*16+8(%r14), RR3, RR3;
14013 + vpxor 4*16+8(%r14), RL3, RL3;
14014 + vpxor 5*16+8(%r14), RR4, RR4;
14015 + vpxor 6*16+8(%r14), RL4, RL4;
14016
14017 vmovdqu RR1, (0*16)(%r11);
14018 vmovdqu RL1, (1*16)(%r11);
14019 @@ -467,8 +472,9 @@ ENTRY(cast5_cbc_dec_16way)
14020 vmovdqu RR4, (6*16)(%r11);
14021 vmovdqu RL4, (7*16)(%r11);
14022
14023 - popq %r12;
14024 + popq %r14;
14025
14026 + pax_force_retaddr
14027 ret;
14028 ENDPROC(cast5_cbc_dec_16way)
14029
14030 @@ -480,10 +486,10 @@ ENTRY(cast5_ctr_16way)
14031 * %rcx: iv (big endian, 64bit)
14032 */
14033
14034 - pushq %r12;
14035 + pushq %r14;
14036
14037 movq %rsi, %r11;
14038 - movq %rdx, %r12;
14039 + movq %rdx, %r14;
14040
14041 vpcmpeqd RTMP, RTMP, RTMP;
14042 vpsrldq $8, RTMP, RTMP; /* low: -1, high: 0 */
14043 @@ -523,14 +529,14 @@ ENTRY(cast5_ctr_16way)
14044 call __cast5_enc_blk16;
14045
14046 /* dst = src ^ iv */
14047 - vpxor (0*16)(%r12), RR1, RR1;
14048 - vpxor (1*16)(%r12), RL1, RL1;
14049 - vpxor (2*16)(%r12), RR2, RR2;
14050 - vpxor (3*16)(%r12), RL2, RL2;
14051 - vpxor (4*16)(%r12), RR3, RR3;
14052 - vpxor (5*16)(%r12), RL3, RL3;
14053 - vpxor (6*16)(%r12), RR4, RR4;
14054 - vpxor (7*16)(%r12), RL4, RL4;
14055 + vpxor (0*16)(%r14), RR1, RR1;
14056 + vpxor (1*16)(%r14), RL1, RL1;
14057 + vpxor (2*16)(%r14), RR2, RR2;
14058 + vpxor (3*16)(%r14), RL2, RL2;
14059 + vpxor (4*16)(%r14), RR3, RR3;
14060 + vpxor (5*16)(%r14), RL3, RL3;
14061 + vpxor (6*16)(%r14), RR4, RR4;
14062 + vpxor (7*16)(%r14), RL4, RL4;
14063 vmovdqu RR1, (0*16)(%r11);
14064 vmovdqu RL1, (1*16)(%r11);
14065 vmovdqu RR2, (2*16)(%r11);
14066 @@ -540,7 +546,8 @@ ENTRY(cast5_ctr_16way)
14067 vmovdqu RR4, (6*16)(%r11);
14068 vmovdqu RL4, (7*16)(%r11);
14069
14070 - popq %r12;
14071 + popq %r14;
14072
14073 + pax_force_retaddr
14074 ret;
14075 ENDPROC(cast5_ctr_16way)
14076 diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
14077 index e3531f8..e123f35 100644
14078 --- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
14079 +++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
14080 @@ -24,6 +24,7 @@
14081 */
14082
14083 #include <linux/linkage.h>
14084 +#include <asm/alternative-asm.h>
14085 #include "glue_helper-asm-avx.S"
14086
14087 .file "cast6-avx-x86_64-asm_64.S"
14088 @@ -295,6 +296,7 @@ __cast6_enc_blk8:
14089 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
14090 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
14091
14092 + pax_force_retaddr
14093 ret;
14094 ENDPROC(__cast6_enc_blk8)
14095
14096 @@ -340,6 +342,7 @@ __cast6_dec_blk8:
14097 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
14098 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
14099
14100 + pax_force_retaddr
14101 ret;
14102 ENDPROC(__cast6_dec_blk8)
14103
14104 @@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
14105
14106 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14107
14108 + pax_force_retaddr
14109 ret;
14110 ENDPROC(cast6_ecb_enc_8way)
14111
14112 @@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
14113
14114 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14115
14116 + pax_force_retaddr
14117 ret;
14118 ENDPROC(cast6_ecb_dec_8way)
14119
14120 @@ -386,19 +391,20 @@ ENTRY(cast6_cbc_dec_8way)
14121 * %rdx: src
14122 */
14123
14124 - pushq %r12;
14125 + pushq %r14;
14126
14127 movq %rsi, %r11;
14128 - movq %rdx, %r12;
14129 + movq %rdx, %r14;
14130
14131 load_8way(%rdx, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14132
14133 call __cast6_dec_blk8;
14134
14135 - store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14136 + store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14137
14138 - popq %r12;
14139 + popq %r14;
14140
14141 + pax_force_retaddr
14142 ret;
14143 ENDPROC(cast6_cbc_dec_8way)
14144
14145 @@ -410,20 +416,21 @@ ENTRY(cast6_ctr_8way)
14146 * %rcx: iv (little endian, 128bit)
14147 */
14148
14149 - pushq %r12;
14150 + pushq %r14;
14151
14152 movq %rsi, %r11;
14153 - movq %rdx, %r12;
14154 + movq %rdx, %r14;
14155
14156 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
14157 RD2, RX, RKR, RKM);
14158
14159 call __cast6_enc_blk8;
14160
14161 - store_ctr_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14162 + store_ctr_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14163
14164 - popq %r12;
14165 + popq %r14;
14166
14167 + pax_force_retaddr
14168 ret;
14169 ENDPROC(cast6_ctr_8way)
14170
14171 @@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
14172 /* dst <= regs xor IVs(in dst) */
14173 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14174
14175 + pax_force_retaddr
14176 ret;
14177 ENDPROC(cast6_xts_enc_8way)
14178
14179 @@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
14180 /* dst <= regs xor IVs(in dst) */
14181 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14182
14183 + pax_force_retaddr
14184 ret;
14185 ENDPROC(cast6_xts_dec_8way)
14186 diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
14187 index dbc4339..de6e120 100644
14188 --- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
14189 +++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
14190 @@ -45,6 +45,7 @@
14191
14192 #include <asm/inst.h>
14193 #include <linux/linkage.h>
14194 +#include <asm/alternative-asm.h>
14195
14196 ## ISCSI CRC 32 Implementation with crc32 and pclmulqdq Instruction
14197
14198 @@ -312,6 +313,7 @@ do_return:
14199 popq %rsi
14200 popq %rdi
14201 popq %rbx
14202 + pax_force_retaddr
14203 ret
14204
14205 ################################################################
14206 diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S
14207 index 5d1e007..098cb4f 100644
14208 --- a/arch/x86/crypto/ghash-clmulni-intel_asm.S
14209 +++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S
14210 @@ -18,6 +18,7 @@
14211
14212 #include <linux/linkage.h>
14213 #include <asm/inst.h>
14214 +#include <asm/alternative-asm.h>
14215
14216 .data
14217
14218 @@ -89,6 +90,7 @@ __clmul_gf128mul_ble:
14219 psrlq $1, T2
14220 pxor T2, T1
14221 pxor T1, DATA
14222 + pax_force_retaddr
14223 ret
14224 ENDPROC(__clmul_gf128mul_ble)
14225
14226 @@ -101,6 +103,7 @@ ENTRY(clmul_ghash_mul)
14227 call __clmul_gf128mul_ble
14228 PSHUFB_XMM BSWAP DATA
14229 movups DATA, (%rdi)
14230 + pax_force_retaddr
14231 ret
14232 ENDPROC(clmul_ghash_mul)
14233
14234 @@ -128,5 +131,6 @@ ENTRY(clmul_ghash_update)
14235 PSHUFB_XMM BSWAP DATA
14236 movups DATA, (%rdi)
14237 .Lupdate_just_ret:
14238 + pax_force_retaddr
14239 ret
14240 ENDPROC(clmul_ghash_update)
14241 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
14242 index 9279e0b..c4b3d2c 100644
14243 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
14244 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
14245 @@ -1,4 +1,5 @@
14246 #include <linux/linkage.h>
14247 +#include <asm/alternative-asm.h>
14248
14249 # enter salsa20_encrypt_bytes
14250 ENTRY(salsa20_encrypt_bytes)
14251 @@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
14252 add %r11,%rsp
14253 mov %rdi,%rax
14254 mov %rsi,%rdx
14255 + pax_force_retaddr
14256 ret
14257 # bytesatleast65:
14258 ._bytesatleast65:
14259 @@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
14260 add %r11,%rsp
14261 mov %rdi,%rax
14262 mov %rsi,%rdx
14263 + pax_force_retaddr
14264 ret
14265 ENDPROC(salsa20_keysetup)
14266
14267 @@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
14268 add %r11,%rsp
14269 mov %rdi,%rax
14270 mov %rsi,%rdx
14271 + pax_force_retaddr
14272 ret
14273 ENDPROC(salsa20_ivsetup)
14274 diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14275 index 2f202f4..d9164d6 100644
14276 --- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14277 +++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14278 @@ -24,6 +24,7 @@
14279 */
14280
14281 #include <linux/linkage.h>
14282 +#include <asm/alternative-asm.h>
14283 #include "glue_helper-asm-avx.S"
14284
14285 .file "serpent-avx-x86_64-asm_64.S"
14286 @@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
14287 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14288 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14289
14290 + pax_force_retaddr
14291 ret;
14292 ENDPROC(__serpent_enc_blk8_avx)
14293
14294 @@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
14295 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14296 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14297
14298 + pax_force_retaddr
14299 ret;
14300 ENDPROC(__serpent_dec_blk8_avx)
14301
14302 @@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
14303
14304 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14305
14306 + pax_force_retaddr
14307 ret;
14308 ENDPROC(serpent_ecb_enc_8way_avx)
14309
14310 @@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
14311
14312 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14313
14314 + pax_force_retaddr
14315 ret;
14316 ENDPROC(serpent_ecb_dec_8way_avx)
14317
14318 @@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
14319
14320 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14321
14322 + pax_force_retaddr
14323 ret;
14324 ENDPROC(serpent_cbc_dec_8way_avx)
14325
14326 @@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
14327
14328 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14329
14330 + pax_force_retaddr
14331 ret;
14332 ENDPROC(serpent_ctr_8way_avx)
14333
14334 @@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
14335 /* dst <= regs xor IVs(in dst) */
14336 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14337
14338 + pax_force_retaddr
14339 ret;
14340 ENDPROC(serpent_xts_enc_8way_avx)
14341
14342 @@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
14343 /* dst <= regs xor IVs(in dst) */
14344 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14345
14346 + pax_force_retaddr
14347 ret;
14348 ENDPROC(serpent_xts_dec_8way_avx)
14349 diff --git a/arch/x86/crypto/serpent-avx2-asm_64.S b/arch/x86/crypto/serpent-avx2-asm_64.S
14350 index b222085..abd483c 100644
14351 --- a/arch/x86/crypto/serpent-avx2-asm_64.S
14352 +++ b/arch/x86/crypto/serpent-avx2-asm_64.S
14353 @@ -15,6 +15,7 @@
14354 */
14355
14356 #include <linux/linkage.h>
14357 +#include <asm/alternative-asm.h>
14358 #include "glue_helper-asm-avx2.S"
14359
14360 .file "serpent-avx2-asm_64.S"
14361 @@ -610,6 +611,7 @@ __serpent_enc_blk16:
14362 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14363 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14364
14365 + pax_force_retaddr
14366 ret;
14367 ENDPROC(__serpent_enc_blk16)
14368
14369 @@ -664,6 +666,7 @@ __serpent_dec_blk16:
14370 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14371 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14372
14373 + pax_force_retaddr
14374 ret;
14375 ENDPROC(__serpent_dec_blk16)
14376
14377 @@ -684,6 +687,7 @@ ENTRY(serpent_ecb_enc_16way)
14378
14379 vzeroupper;
14380
14381 + pax_force_retaddr
14382 ret;
14383 ENDPROC(serpent_ecb_enc_16way)
14384
14385 @@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_16way)
14386
14387 vzeroupper;
14388
14389 + pax_force_retaddr
14390 ret;
14391 ENDPROC(serpent_ecb_dec_16way)
14392
14393 @@ -725,6 +730,7 @@ ENTRY(serpent_cbc_dec_16way)
14394
14395 vzeroupper;
14396
14397 + pax_force_retaddr
14398 ret;
14399 ENDPROC(serpent_cbc_dec_16way)
14400
14401 @@ -748,6 +754,7 @@ ENTRY(serpent_ctr_16way)
14402
14403 vzeroupper;
14404
14405 + pax_force_retaddr
14406 ret;
14407 ENDPROC(serpent_ctr_16way)
14408
14409 @@ -772,6 +779,7 @@ ENTRY(serpent_xts_enc_16way)
14410
14411 vzeroupper;
14412
14413 + pax_force_retaddr
14414 ret;
14415 ENDPROC(serpent_xts_enc_16way)
14416
14417 @@ -796,5 +804,6 @@ ENTRY(serpent_xts_dec_16way)
14418
14419 vzeroupper;
14420
14421 + pax_force_retaddr
14422 ret;
14423 ENDPROC(serpent_xts_dec_16way)
14424 diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14425 index acc066c..1559cc4 100644
14426 --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14427 +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14428 @@ -25,6 +25,7 @@
14429 */
14430
14431 #include <linux/linkage.h>
14432 +#include <asm/alternative-asm.h>
14433
14434 .file "serpent-sse2-x86_64-asm_64.S"
14435 .text
14436 @@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
14437 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14438 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14439
14440 + pax_force_retaddr
14441 ret;
14442
14443 .L__enc_xor8:
14444 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14445 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14446
14447 + pax_force_retaddr
14448 ret;
14449 ENDPROC(__serpent_enc_blk_8way)
14450
14451 @@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
14452 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14453 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14454
14455 + pax_force_retaddr
14456 ret;
14457 ENDPROC(serpent_dec_blk_8way)
14458 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
14459 index a410950..9dfe7ad 100644
14460 --- a/arch/x86/crypto/sha1_ssse3_asm.S
14461 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
14462 @@ -29,6 +29,7 @@
14463 */
14464
14465 #include <linux/linkage.h>
14466 +#include <asm/alternative-asm.h>
14467
14468 #define CTX %rdi // arg1
14469 #define BUF %rsi // arg2
14470 @@ -75,9 +76,9 @@
14471
14472 push %rbx
14473 push %rbp
14474 - push %r12
14475 + push %r14
14476
14477 - mov %rsp, %r12
14478 + mov %rsp, %r14
14479 sub $64, %rsp # allocate workspace
14480 and $~15, %rsp # align stack
14481
14482 @@ -99,11 +100,12 @@
14483 xor %rax, %rax
14484 rep stosq
14485
14486 - mov %r12, %rsp # deallocate workspace
14487 + mov %r14, %rsp # deallocate workspace
14488
14489 - pop %r12
14490 + pop %r14
14491 pop %rbp
14492 pop %rbx
14493 + pax_force_retaddr
14494 ret
14495
14496 ENDPROC(\name)
14497 diff --git a/arch/x86/crypto/sha256-avx-asm.S b/arch/x86/crypto/sha256-avx-asm.S
14498 index 642f156..51a513c 100644
14499 --- a/arch/x86/crypto/sha256-avx-asm.S
14500 +++ b/arch/x86/crypto/sha256-avx-asm.S
14501 @@ -49,6 +49,7 @@
14502
14503 #ifdef CONFIG_AS_AVX
14504 #include <linux/linkage.h>
14505 +#include <asm/alternative-asm.h>
14506
14507 ## assume buffers not aligned
14508 #define VMOVDQ vmovdqu
14509 @@ -460,6 +461,7 @@ done_hash:
14510 popq %r13
14511 popq %rbp
14512 popq %rbx
14513 + pax_force_retaddr
14514 ret
14515 ENDPROC(sha256_transform_avx)
14516
14517 diff --git a/arch/x86/crypto/sha256-avx2-asm.S b/arch/x86/crypto/sha256-avx2-asm.S
14518 index 9e86944..3795e6a 100644
14519 --- a/arch/x86/crypto/sha256-avx2-asm.S
14520 +++ b/arch/x86/crypto/sha256-avx2-asm.S
14521 @@ -50,6 +50,7 @@
14522
14523 #ifdef CONFIG_AS_AVX2
14524 #include <linux/linkage.h>
14525 +#include <asm/alternative-asm.h>
14526
14527 ## assume buffers not aligned
14528 #define VMOVDQ vmovdqu
14529 @@ -720,6 +721,7 @@ done_hash:
14530 popq %r12
14531 popq %rbp
14532 popq %rbx
14533 + pax_force_retaddr
14534 ret
14535 ENDPROC(sha256_transform_rorx)
14536
14537 diff --git a/arch/x86/crypto/sha256-ssse3-asm.S b/arch/x86/crypto/sha256-ssse3-asm.S
14538 index f833b74..8c62a9e 100644
14539 --- a/arch/x86/crypto/sha256-ssse3-asm.S
14540 +++ b/arch/x86/crypto/sha256-ssse3-asm.S
14541 @@ -47,6 +47,7 @@
14542 ########################################################################
14543
14544 #include <linux/linkage.h>
14545 +#include <asm/alternative-asm.h>
14546
14547 ## assume buffers not aligned
14548 #define MOVDQ movdqu
14549 @@ -471,6 +472,7 @@ done_hash:
14550 popq %rbp
14551 popq %rbx
14552
14553 + pax_force_retaddr
14554 ret
14555 ENDPROC(sha256_transform_ssse3)
14556
14557 diff --git a/arch/x86/crypto/sha512-avx-asm.S b/arch/x86/crypto/sha512-avx-asm.S
14558 index 974dde9..a823ff9 100644
14559 --- a/arch/x86/crypto/sha512-avx-asm.S
14560 +++ b/arch/x86/crypto/sha512-avx-asm.S
14561 @@ -49,6 +49,7 @@
14562
14563 #ifdef CONFIG_AS_AVX
14564 #include <linux/linkage.h>
14565 +#include <asm/alternative-asm.h>
14566
14567 .text
14568
14569 @@ -364,6 +365,7 @@ updateblock:
14570 mov frame_RSPSAVE(%rsp), %rsp
14571
14572 nowork:
14573 + pax_force_retaddr
14574 ret
14575 ENDPROC(sha512_transform_avx)
14576
14577 diff --git a/arch/x86/crypto/sha512-avx2-asm.S b/arch/x86/crypto/sha512-avx2-asm.S
14578 index 568b961..ed20c37 100644
14579 --- a/arch/x86/crypto/sha512-avx2-asm.S
14580 +++ b/arch/x86/crypto/sha512-avx2-asm.S
14581 @@ -51,6 +51,7 @@
14582
14583 #ifdef CONFIG_AS_AVX2
14584 #include <linux/linkage.h>
14585 +#include <asm/alternative-asm.h>
14586
14587 .text
14588
14589 @@ -678,6 +679,7 @@ done_hash:
14590
14591 # Restore Stack Pointer
14592 mov frame_RSPSAVE(%rsp), %rsp
14593 + pax_force_retaddr
14594 ret
14595 ENDPROC(sha512_transform_rorx)
14596
14597 diff --git a/arch/x86/crypto/sha512-ssse3-asm.S b/arch/x86/crypto/sha512-ssse3-asm.S
14598 index fb56855..6edd768 100644
14599 --- a/arch/x86/crypto/sha512-ssse3-asm.S
14600 +++ b/arch/x86/crypto/sha512-ssse3-asm.S
14601 @@ -48,6 +48,7 @@
14602 ########################################################################
14603
14604 #include <linux/linkage.h>
14605 +#include <asm/alternative-asm.h>
14606
14607 .text
14608
14609 @@ -363,6 +364,7 @@ updateblock:
14610 mov frame_RSPSAVE(%rsp), %rsp
14611
14612 nowork:
14613 + pax_force_retaddr
14614 ret
14615 ENDPROC(sha512_transform_ssse3)
14616
14617 diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14618 index 0505813..b067311 100644
14619 --- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14620 +++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14621 @@ -24,6 +24,7 @@
14622 */
14623
14624 #include <linux/linkage.h>
14625 +#include <asm/alternative-asm.h>
14626 #include "glue_helper-asm-avx.S"
14627
14628 .file "twofish-avx-x86_64-asm_64.S"
14629 @@ -284,6 +285,7 @@ __twofish_enc_blk8:
14630 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
14631 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
14632
14633 + pax_force_retaddr
14634 ret;
14635 ENDPROC(__twofish_enc_blk8)
14636
14637 @@ -324,6 +326,7 @@ __twofish_dec_blk8:
14638 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
14639 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
14640
14641 + pax_force_retaddr
14642 ret;
14643 ENDPROC(__twofish_dec_blk8)
14644
14645 @@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
14646
14647 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14648
14649 + pax_force_retaddr
14650 ret;
14651 ENDPROC(twofish_ecb_enc_8way)
14652
14653 @@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
14654
14655 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14656
14657 + pax_force_retaddr
14658 ret;
14659 ENDPROC(twofish_ecb_dec_8way)
14660
14661 @@ -370,19 +375,20 @@ ENTRY(twofish_cbc_dec_8way)
14662 * %rdx: src
14663 */
14664
14665 - pushq %r12;
14666 + pushq %r14;
14667
14668 movq %rsi, %r11;
14669 - movq %rdx, %r12;
14670 + movq %rdx, %r14;
14671
14672 load_8way(%rdx, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14673
14674 call __twofish_dec_blk8;
14675
14676 - store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14677 + store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14678
14679 - popq %r12;
14680 + popq %r14;
14681
14682 + pax_force_retaddr
14683 ret;
14684 ENDPROC(twofish_cbc_dec_8way)
14685
14686 @@ -394,20 +400,21 @@ ENTRY(twofish_ctr_8way)
14687 * %rcx: iv (little endian, 128bit)
14688 */
14689
14690 - pushq %r12;
14691 + pushq %r14;
14692
14693 movq %rsi, %r11;
14694 - movq %rdx, %r12;
14695 + movq %rdx, %r14;
14696
14697 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
14698 RD2, RX0, RX1, RY0);
14699
14700 call __twofish_enc_blk8;
14701
14702 - store_ctr_8way(%r12, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14703 + store_ctr_8way(%r14, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14704
14705 - popq %r12;
14706 + popq %r14;
14707
14708 + pax_force_retaddr
14709 ret;
14710 ENDPROC(twofish_ctr_8way)
14711
14712 @@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
14713 /* dst <= regs xor IVs(in dst) */
14714 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14715
14716 + pax_force_retaddr
14717 ret;
14718 ENDPROC(twofish_xts_enc_8way)
14719
14720 @@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
14721 /* dst <= regs xor IVs(in dst) */
14722 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14723
14724 + pax_force_retaddr
14725 ret;
14726 ENDPROC(twofish_xts_dec_8way)
14727 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14728 index 1c3b7ce..02f578d 100644
14729 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14730 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14731 @@ -21,6 +21,7 @@
14732 */
14733
14734 #include <linux/linkage.h>
14735 +#include <asm/alternative-asm.h>
14736
14737 .file "twofish-x86_64-asm-3way.S"
14738 .text
14739 @@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
14740 popq %r13;
14741 popq %r14;
14742 popq %r15;
14743 + pax_force_retaddr
14744 ret;
14745
14746 .L__enc_xor3:
14747 @@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
14748 popq %r13;
14749 popq %r14;
14750 popq %r15;
14751 + pax_force_retaddr
14752 ret;
14753 ENDPROC(__twofish_enc_blk_3way)
14754
14755 @@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
14756 popq %r13;
14757 popq %r14;
14758 popq %r15;
14759 + pax_force_retaddr
14760 ret;
14761 ENDPROC(twofish_dec_blk_3way)
14762 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
14763 index a039d21..524b8b2 100644
14764 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
14765 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
14766 @@ -22,6 +22,7 @@
14767
14768 #include <linux/linkage.h>
14769 #include <asm/asm-offsets.h>
14770 +#include <asm/alternative-asm.h>
14771
14772 #define a_offset 0
14773 #define b_offset 4
14774 @@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
14775
14776 popq R1
14777 movq $1,%rax
14778 + pax_force_retaddr
14779 ret
14780 ENDPROC(twofish_enc_blk)
14781
14782 @@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
14783
14784 popq R1
14785 movq $1,%rax
14786 + pax_force_retaddr
14787 ret
14788 ENDPROC(twofish_dec_blk)
14789 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
14790 index d21ff89..6da8e6e 100644
14791 --- a/arch/x86/ia32/ia32_aout.c
14792 +++ b/arch/x86/ia32/ia32_aout.c
14793 @@ -153,6 +153,8 @@ static int aout_core_dump(struct coredump_params *cprm)
14794 unsigned long dump_start, dump_size;
14795 struct user32 dump;
14796
14797 + memset(&dump, 0, sizeof(dump));
14798 +
14799 fs = get_fs();
14800 set_fs(KERNEL_DS);
14801 has_dumped = 1;
14802 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
14803 index f9e181a..b0df8b3 100644
14804 --- a/arch/x86/ia32/ia32_signal.c
14805 +++ b/arch/x86/ia32/ia32_signal.c
14806 @@ -218,7 +218,7 @@ asmlinkage long sys32_sigreturn(void)
14807 if (__get_user(set.sig[0], &frame->sc.oldmask)
14808 || (_COMPAT_NSIG_WORDS > 1
14809 && __copy_from_user((((char *) &set.sig) + 4),
14810 - &frame->extramask,
14811 + frame->extramask,
14812 sizeof(frame->extramask))))
14813 goto badframe;
14814
14815 @@ -338,7 +338,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
14816 sp -= frame_size;
14817 /* Align the stack pointer according to the i386 ABI,
14818 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
14819 - sp = ((sp + 4) & -16ul) - 4;
14820 + sp = ((sp - 12) & -16ul) - 4;
14821 return (void __user *) sp;
14822 }
14823
14824 @@ -386,7 +386,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14825 restorer = current->mm->context.vdso +
14826 selected_vdso32->sym___kernel_sigreturn;
14827 else
14828 - restorer = &frame->retcode;
14829 + restorer = frame->retcode;
14830 }
14831
14832 put_user_try {
14833 @@ -396,7 +396,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14834 * These are actually not used anymore, but left because some
14835 * gdb versions depend on them as a marker.
14836 */
14837 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14838 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14839 } put_user_catch(err);
14840
14841 if (err)
14842 @@ -438,7 +438,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14843 0xb8,
14844 __NR_ia32_rt_sigreturn,
14845 0x80cd,
14846 - 0,
14847 + 0
14848 };
14849
14850 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
14851 @@ -461,16 +461,19 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14852
14853 if (ksig->ka.sa.sa_flags & SA_RESTORER)
14854 restorer = ksig->ka.sa.sa_restorer;
14855 - else
14856 + else if (current->mm->context.vdso)
14857 + /* Return stub is in 32bit vsyscall page */
14858 restorer = current->mm->context.vdso +
14859 selected_vdso32->sym___kernel_rt_sigreturn;
14860 + else
14861 + restorer = frame->retcode;
14862 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
14863
14864 /*
14865 * Not actually used anymore, but left because some gdb
14866 * versions need it.
14867 */
14868 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14869 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14870 } put_user_catch(err);
14871
14872 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
14873 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
14874 index 4299eb0..fefe70e 100644
14875 --- a/arch/x86/ia32/ia32entry.S
14876 +++ b/arch/x86/ia32/ia32entry.S
14877 @@ -15,8 +15,10 @@
14878 #include <asm/irqflags.h>
14879 #include <asm/asm.h>
14880 #include <asm/smap.h>
14881 +#include <asm/pgtable.h>
14882 #include <linux/linkage.h>
14883 #include <linux/err.h>
14884 +#include <asm/alternative-asm.h>
14885
14886 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
14887 #include <linux/elf-em.h>
14888 @@ -62,12 +64,12 @@
14889 */
14890 .macro LOAD_ARGS32 offset, _r9=0
14891 .if \_r9
14892 - movl \offset+16(%rsp),%r9d
14893 + movl \offset+R9(%rsp),%r9d
14894 .endif
14895 - movl \offset+40(%rsp),%ecx
14896 - movl \offset+48(%rsp),%edx
14897 - movl \offset+56(%rsp),%esi
14898 - movl \offset+64(%rsp),%edi
14899 + movl \offset+RCX(%rsp),%ecx
14900 + movl \offset+RDX(%rsp),%edx
14901 + movl \offset+RSI(%rsp),%esi
14902 + movl \offset+RDI(%rsp),%edi
14903 movl %eax,%eax /* zero extension */
14904 .endm
14905
14906 @@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
14907 ENDPROC(native_irq_enable_sysexit)
14908 #endif
14909
14910 + .macro pax_enter_kernel_user
14911 + pax_set_fptr_mask
14912 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14913 + call pax_enter_kernel_user
14914 +#endif
14915 + .endm
14916 +
14917 + .macro pax_exit_kernel_user
14918 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14919 + call pax_exit_kernel_user
14920 +#endif
14921 +#ifdef CONFIG_PAX_RANDKSTACK
14922 + pushq %rax
14923 + pushq %r11
14924 + call pax_randomize_kstack
14925 + popq %r11
14926 + popq %rax
14927 +#endif
14928 + .endm
14929 +
14930 + .macro pax_erase_kstack
14931 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14932 + call pax_erase_kstack
14933 +#endif
14934 + .endm
14935 +
14936 /*
14937 * 32bit SYSENTER instruction entry.
14938 *
14939 @@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
14940 CFI_REGISTER rsp,rbp
14941 SWAPGS_UNSAFE_STACK
14942 movq PER_CPU_VAR(kernel_stack), %rsp
14943 - addq $(KERNEL_STACK_OFFSET),%rsp
14944 - /*
14945 - * No need to follow this irqs on/off section: the syscall
14946 - * disabled irqs, here we enable it straight after entry:
14947 - */
14948 - ENABLE_INTERRUPTS(CLBR_NONE)
14949 movl %ebp,%ebp /* zero extension */
14950 pushq_cfi $__USER32_DS
14951 /*CFI_REL_OFFSET ss,0*/
14952 @@ -135,24 +157,49 @@ ENTRY(ia32_sysenter_target)
14953 CFI_REL_OFFSET rsp,0
14954 pushfq_cfi
14955 /*CFI_REL_OFFSET rflags,0*/
14956 - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
14957 - CFI_REGISTER rip,r10
14958 + orl $X86_EFLAGS_IF,(%rsp)
14959 + GET_THREAD_INFO(%r11)
14960 + movl TI_sysenter_return(%r11), %r11d
14961 + CFI_REGISTER rip,r11
14962 pushq_cfi $__USER32_CS
14963 /*CFI_REL_OFFSET cs,0*/
14964 movl %eax, %eax
14965 - pushq_cfi %r10
14966 + pushq_cfi %r11
14967 CFI_REL_OFFSET rip,0
14968 pushq_cfi %rax
14969 cld
14970 SAVE_ARGS 0,1,0
14971 + pax_enter_kernel_user
14972 +
14973 +#ifdef CONFIG_PAX_RANDKSTACK
14974 + pax_erase_kstack
14975 +#endif
14976 +
14977 + /*
14978 + * No need to follow this irqs on/off section: the syscall
14979 + * disabled irqs, here we enable it straight after entry:
14980 + */
14981 + ENABLE_INTERRUPTS(CLBR_NONE)
14982 /* no need to do an access_ok check here because rbp has been
14983 32bit zero extended */
14984 +
14985 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14986 + addq pax_user_shadow_base,%rbp
14987 + ASM_PAX_OPEN_USERLAND
14988 +#endif
14989 +
14990 ASM_STAC
14991 1: movl (%rbp),%ebp
14992 _ASM_EXTABLE(1b,ia32_badarg)
14993 ASM_CLAC
14994 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14995 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14996 +
14997 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14998 + ASM_PAX_CLOSE_USERLAND
14999 +#endif
15000 +
15001 + GET_THREAD_INFO(%r11)
15002 + orl $TS_COMPAT,TI_status(%r11)
15003 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
15004 CFI_REMEMBER_STATE
15005 jnz sysenter_tracesys
15006 cmpq $(IA32_NR_syscalls-1),%rax
15007 @@ -162,15 +209,18 @@ sysenter_do_call:
15008 sysenter_dispatch:
15009 call *ia32_sys_call_table(,%rax,8)
15010 movq %rax,RAX-ARGOFFSET(%rsp)
15011 + GET_THREAD_INFO(%r11)
15012 DISABLE_INTERRUPTS(CLBR_NONE)
15013 TRACE_IRQS_OFF
15014 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15015 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
15016 jnz sysexit_audit
15017 sysexit_from_sys_call:
15018 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15019 + pax_exit_kernel_user
15020 + pax_erase_kstack
15021 + andl $~TS_COMPAT,TI_status(%r11)
15022 /* clear IF, that popfq doesn't enable interrupts early */
15023 - andl $~0x200,EFLAGS-R11(%rsp)
15024 - movl RIP-R11(%rsp),%edx /* User %eip */
15025 + andl $~X86_EFLAGS_IF,EFLAGS(%rsp)
15026 + movl RIP(%rsp),%edx /* User %eip */
15027 CFI_REGISTER rip,rdx
15028 RESTORE_ARGS 0,24,0,0,0,0
15029 xorq %r8,%r8
15030 @@ -193,6 +243,9 @@ sysexit_from_sys_call:
15031 movl %eax,%esi /* 2nd arg: syscall number */
15032 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
15033 call __audit_syscall_entry
15034 +
15035 + pax_erase_kstack
15036 +
15037 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
15038 cmpq $(IA32_NR_syscalls-1),%rax
15039 ja ia32_badsys
15040 @@ -204,7 +257,7 @@ sysexit_from_sys_call:
15041 .endm
15042
15043 .macro auditsys_exit exit
15044 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15045 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
15046 jnz ia32_ret_from_sys_call
15047 TRACE_IRQS_ON
15048 ENABLE_INTERRUPTS(CLBR_NONE)
15049 @@ -215,11 +268,12 @@ sysexit_from_sys_call:
15050 1: setbe %al /* 1 if error, 0 if not */
15051 movzbl %al,%edi /* zero-extend that into %edi */
15052 call __audit_syscall_exit
15053 + GET_THREAD_INFO(%r11)
15054 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
15055 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
15056 DISABLE_INTERRUPTS(CLBR_NONE)
15057 TRACE_IRQS_OFF
15058 - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15059 + testl %edi,TI_flags(%r11)
15060 jz \exit
15061 CLEAR_RREGS -ARGOFFSET
15062 jmp int_with_check
15063 @@ -237,7 +291,7 @@ sysexit_audit:
15064
15065 sysenter_tracesys:
15066 #ifdef CONFIG_AUDITSYSCALL
15067 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15068 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
15069 jz sysenter_auditsys
15070 #endif
15071 SAVE_REST
15072 @@ -249,6 +303,9 @@ sysenter_tracesys:
15073 RESTORE_REST
15074 cmpq $(IA32_NR_syscalls-1),%rax
15075 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
15076 +
15077 + pax_erase_kstack
15078 +
15079 jmp sysenter_do_call
15080 CFI_ENDPROC
15081 ENDPROC(ia32_sysenter_target)
15082 @@ -276,19 +333,25 @@ ENDPROC(ia32_sysenter_target)
15083 ENTRY(ia32_cstar_target)
15084 CFI_STARTPROC32 simple
15085 CFI_SIGNAL_FRAME
15086 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
15087 + CFI_DEF_CFA rsp,0
15088 CFI_REGISTER rip,rcx
15089 /*CFI_REGISTER rflags,r11*/
15090 SWAPGS_UNSAFE_STACK
15091 movl %esp,%r8d
15092 CFI_REGISTER rsp,r8
15093 movq PER_CPU_VAR(kernel_stack),%rsp
15094 + SAVE_ARGS 8*6,0,0
15095 + pax_enter_kernel_user
15096 +
15097 +#ifdef CONFIG_PAX_RANDKSTACK
15098 + pax_erase_kstack
15099 +#endif
15100 +
15101 /*
15102 * No need to follow this irqs on/off section: the syscall
15103 * disabled irqs and here we enable it straight after entry:
15104 */
15105 ENABLE_INTERRUPTS(CLBR_NONE)
15106 - SAVE_ARGS 8,0,0
15107 movl %eax,%eax /* zero extension */
15108 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
15109 movq %rcx,RIP-ARGOFFSET(%rsp)
15110 @@ -304,12 +367,25 @@ ENTRY(ia32_cstar_target)
15111 /* no need to do an access_ok check here because r8 has been
15112 32bit zero extended */
15113 /* hardware stack frame is complete now */
15114 +
15115 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15116 + ASM_PAX_OPEN_USERLAND
15117 + movq pax_user_shadow_base,%r8
15118 + addq RSP-ARGOFFSET(%rsp),%r8
15119 +#endif
15120 +
15121 ASM_STAC
15122 1: movl (%r8),%r9d
15123 _ASM_EXTABLE(1b,ia32_badarg)
15124 ASM_CLAC
15125 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15126 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15127 +
15128 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15129 + ASM_PAX_CLOSE_USERLAND
15130 +#endif
15131 +
15132 + GET_THREAD_INFO(%r11)
15133 + orl $TS_COMPAT,TI_status(%r11)
15134 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
15135 CFI_REMEMBER_STATE
15136 jnz cstar_tracesys
15137 cmpq $IA32_NR_syscalls-1,%rax
15138 @@ -319,13 +395,16 @@ cstar_do_call:
15139 cstar_dispatch:
15140 call *ia32_sys_call_table(,%rax,8)
15141 movq %rax,RAX-ARGOFFSET(%rsp)
15142 + GET_THREAD_INFO(%r11)
15143 DISABLE_INTERRUPTS(CLBR_NONE)
15144 TRACE_IRQS_OFF
15145 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15146 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
15147 jnz sysretl_audit
15148 sysretl_from_sys_call:
15149 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15150 - RESTORE_ARGS 0,-ARG_SKIP,0,0,0
15151 + pax_exit_kernel_user
15152 + pax_erase_kstack
15153 + andl $~TS_COMPAT,TI_status(%r11)
15154 + RESTORE_ARGS 0,-ORIG_RAX,0,0,0
15155 movl RIP-ARGOFFSET(%rsp),%ecx
15156 CFI_REGISTER rip,rcx
15157 movl EFLAGS-ARGOFFSET(%rsp),%r11d
15158 @@ -352,7 +431,7 @@ sysretl_audit:
15159
15160 cstar_tracesys:
15161 #ifdef CONFIG_AUDITSYSCALL
15162 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15163 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
15164 jz cstar_auditsys
15165 #endif
15166 xchgl %r9d,%ebp
15167 @@ -366,11 +445,19 @@ cstar_tracesys:
15168 xchgl %ebp,%r9d
15169 cmpq $(IA32_NR_syscalls-1),%rax
15170 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
15171 +
15172 + pax_erase_kstack
15173 +
15174 jmp cstar_do_call
15175 END(ia32_cstar_target)
15176
15177 ia32_badarg:
15178 ASM_CLAC
15179 +
15180 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15181 + ASM_PAX_CLOSE_USERLAND
15182 +#endif
15183 +
15184 movq $-EFAULT,%rax
15185 jmp ia32_sysret
15186 CFI_ENDPROC
15187 @@ -407,19 +494,26 @@ ENTRY(ia32_syscall)
15188 CFI_REL_OFFSET rip,RIP-RIP
15189 PARAVIRT_ADJUST_EXCEPTION_FRAME
15190 SWAPGS
15191 - /*
15192 - * No need to follow this irqs on/off section: the syscall
15193 - * disabled irqs and here we enable it straight after entry:
15194 - */
15195 - ENABLE_INTERRUPTS(CLBR_NONE)
15196 movl %eax,%eax
15197 pushq_cfi %rax
15198 cld
15199 /* note the registers are not zero extended to the sf.
15200 this could be a problem. */
15201 SAVE_ARGS 0,1,0
15202 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15203 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15204 + pax_enter_kernel_user
15205 +
15206 +#ifdef CONFIG_PAX_RANDKSTACK
15207 + pax_erase_kstack
15208 +#endif
15209 +
15210 + /*
15211 + * No need to follow this irqs on/off section: the syscall
15212 + * disabled irqs and here we enable it straight after entry:
15213 + */
15214 + ENABLE_INTERRUPTS(CLBR_NONE)
15215 + GET_THREAD_INFO(%r11)
15216 + orl $TS_COMPAT,TI_status(%r11)
15217 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
15218 jnz ia32_tracesys
15219 cmpq $(IA32_NR_syscalls-1),%rax
15220 ja ia32_badsys
15221 @@ -442,6 +536,9 @@ ia32_tracesys:
15222 RESTORE_REST
15223 cmpq $(IA32_NR_syscalls-1),%rax
15224 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
15225 +
15226 + pax_erase_kstack
15227 +
15228 jmp ia32_do_call
15229 END(ia32_syscall)
15230
15231 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
15232 index 8e0ceec..af13504 100644
15233 --- a/arch/x86/ia32/sys_ia32.c
15234 +++ b/arch/x86/ia32/sys_ia32.c
15235 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
15236 */
15237 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
15238 {
15239 - typeof(ubuf->st_uid) uid = 0;
15240 - typeof(ubuf->st_gid) gid = 0;
15241 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
15242 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
15243 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
15244 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
15245 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
15246 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
15247 index 372231c..51b537d 100644
15248 --- a/arch/x86/include/asm/alternative-asm.h
15249 +++ b/arch/x86/include/asm/alternative-asm.h
15250 @@ -18,6 +18,45 @@
15251 .endm
15252 #endif
15253
15254 +#ifdef KERNEXEC_PLUGIN
15255 + .macro pax_force_retaddr_bts rip=0
15256 + btsq $63,\rip(%rsp)
15257 + .endm
15258 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
15259 + .macro pax_force_retaddr rip=0, reload=0
15260 + btsq $63,\rip(%rsp)
15261 + .endm
15262 + .macro pax_force_fptr ptr
15263 + btsq $63,\ptr
15264 + .endm
15265 + .macro pax_set_fptr_mask
15266 + .endm
15267 +#endif
15268 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15269 + .macro pax_force_retaddr rip=0, reload=0
15270 + .if \reload
15271 + pax_set_fptr_mask
15272 + .endif
15273 + orq %r12,\rip(%rsp)
15274 + .endm
15275 + .macro pax_force_fptr ptr
15276 + orq %r12,\ptr
15277 + .endm
15278 + .macro pax_set_fptr_mask
15279 + movabs $0x8000000000000000,%r12
15280 + .endm
15281 +#endif
15282 +#else
15283 + .macro pax_force_retaddr rip=0, reload=0
15284 + .endm
15285 + .macro pax_force_fptr ptr
15286 + .endm
15287 + .macro pax_force_retaddr_bts rip=0
15288 + .endm
15289 + .macro pax_set_fptr_mask
15290 + .endm
15291 +#endif
15292 +
15293 .macro altinstruction_entry orig alt feature orig_len alt_len
15294 .long \orig - .
15295 .long \alt - .
15296 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
15297 index 0a3f9c9..c9d081d 100644
15298 --- a/arch/x86/include/asm/alternative.h
15299 +++ b/arch/x86/include/asm/alternative.h
15300 @@ -106,7 +106,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
15301 ".pushsection .discard,\"aw\",@progbits\n" \
15302 DISCARD_ENTRY(1) \
15303 ".popsection\n" \
15304 - ".pushsection .altinstr_replacement, \"ax\"\n" \
15305 + ".pushsection .altinstr_replacement, \"a\"\n" \
15306 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
15307 ".popsection"
15308
15309 @@ -120,7 +120,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
15310 DISCARD_ENTRY(1) \
15311 DISCARD_ENTRY(2) \
15312 ".popsection\n" \
15313 - ".pushsection .altinstr_replacement, \"ax\"\n" \
15314 + ".pushsection .altinstr_replacement, \"a\"\n" \
15315 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
15316 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
15317 ".popsection"
15318 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
15319 index 19b0eba..12254cd 100644
15320 --- a/arch/x86/include/asm/apic.h
15321 +++ b/arch/x86/include/asm/apic.h
15322 @@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
15323
15324 #ifdef CONFIG_X86_LOCAL_APIC
15325
15326 -extern unsigned int apic_verbosity;
15327 +extern int apic_verbosity;
15328 extern int local_apic_timer_c2_ok;
15329
15330 extern int disable_apic;
15331 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
15332 index 20370c6..a2eb9b0 100644
15333 --- a/arch/x86/include/asm/apm.h
15334 +++ b/arch/x86/include/asm/apm.h
15335 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
15336 __asm__ __volatile__(APM_DO_ZERO_SEGS
15337 "pushl %%edi\n\t"
15338 "pushl %%ebp\n\t"
15339 - "lcall *%%cs:apm_bios_entry\n\t"
15340 + "lcall *%%ss:apm_bios_entry\n\t"
15341 "setc %%al\n\t"
15342 "popl %%ebp\n\t"
15343 "popl %%edi\n\t"
15344 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
15345 __asm__ __volatile__(APM_DO_ZERO_SEGS
15346 "pushl %%edi\n\t"
15347 "pushl %%ebp\n\t"
15348 - "lcall *%%cs:apm_bios_entry\n\t"
15349 + "lcall *%%ss:apm_bios_entry\n\t"
15350 "setc %%bl\n\t"
15351 "popl %%ebp\n\t"
15352 "popl %%edi\n\t"
15353 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
15354 index 6dd1c7dd..2edd216 100644
15355 --- a/arch/x86/include/asm/atomic.h
15356 +++ b/arch/x86/include/asm/atomic.h
15357 @@ -24,7 +24,18 @@
15358 */
15359 static inline int atomic_read(const atomic_t *v)
15360 {
15361 - return (*(volatile int *)&(v)->counter);
15362 + return (*(volatile const int *)&(v)->counter);
15363 +}
15364 +
15365 +/**
15366 + * atomic_read_unchecked - read atomic variable
15367 + * @v: pointer of type atomic_unchecked_t
15368 + *
15369 + * Atomically reads the value of @v.
15370 + */
15371 +static inline int __intentional_overflow(-1) atomic_read_unchecked(const atomic_unchecked_t *v)
15372 +{
15373 + return (*(volatile const int *)&(v)->counter);
15374 }
15375
15376 /**
15377 @@ -40,6 +51,18 @@ static inline void atomic_set(atomic_t *v, int i)
15378 }
15379
15380 /**
15381 + * atomic_set_unchecked - set atomic variable
15382 + * @v: pointer of type atomic_unchecked_t
15383 + * @i: required value
15384 + *
15385 + * Atomically sets the value of @v to @i.
15386 + */
15387 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
15388 +{
15389 + v->counter = i;
15390 +}
15391 +
15392 +/**
15393 * atomic_add - add integer to atomic variable
15394 * @i: integer value to add
15395 * @v: pointer of type atomic_t
15396 @@ -48,7 +71,29 @@ static inline void atomic_set(atomic_t *v, int i)
15397 */
15398 static inline void atomic_add(int i, atomic_t *v)
15399 {
15400 - asm volatile(LOCK_PREFIX "addl %1,%0"
15401 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
15402 +
15403 +#ifdef CONFIG_PAX_REFCOUNT
15404 + "jno 0f\n"
15405 + LOCK_PREFIX "subl %1,%0\n"
15406 + "int $4\n0:\n"
15407 + _ASM_EXTABLE(0b, 0b)
15408 +#endif
15409 +
15410 + : "+m" (v->counter)
15411 + : "ir" (i));
15412 +}
15413 +
15414 +/**
15415 + * atomic_add_unchecked - add integer to atomic variable
15416 + * @i: integer value to add
15417 + * @v: pointer of type atomic_unchecked_t
15418 + *
15419 + * Atomically adds @i to @v.
15420 + */
15421 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
15422 +{
15423 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
15424 : "+m" (v->counter)
15425 : "ir" (i));
15426 }
15427 @@ -62,7 +107,29 @@ static inline void atomic_add(int i, atomic_t *v)
15428 */
15429 static inline void atomic_sub(int i, atomic_t *v)
15430 {
15431 - asm volatile(LOCK_PREFIX "subl %1,%0"
15432 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
15433 +
15434 +#ifdef CONFIG_PAX_REFCOUNT
15435 + "jno 0f\n"
15436 + LOCK_PREFIX "addl %1,%0\n"
15437 + "int $4\n0:\n"
15438 + _ASM_EXTABLE(0b, 0b)
15439 +#endif
15440 +
15441 + : "+m" (v->counter)
15442 + : "ir" (i));
15443 +}
15444 +
15445 +/**
15446 + * atomic_sub_unchecked - subtract integer from atomic variable
15447 + * @i: integer value to subtract
15448 + * @v: pointer of type atomic_unchecked_t
15449 + *
15450 + * Atomically subtracts @i from @v.
15451 + */
15452 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
15453 +{
15454 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
15455 : "+m" (v->counter)
15456 : "ir" (i));
15457 }
15458 @@ -78,7 +145,7 @@ static inline void atomic_sub(int i, atomic_t *v)
15459 */
15460 static inline int atomic_sub_and_test(int i, atomic_t *v)
15461 {
15462 - GEN_BINARY_RMWcc(LOCK_PREFIX "subl", v->counter, "er", i, "%0", "e");
15463 + GEN_BINARY_RMWcc(LOCK_PREFIX "subl", LOCK_PREFIX "addl", v->counter, "er", i, "%0", "e");
15464 }
15465
15466 /**
15467 @@ -89,7 +156,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
15468 */
15469 static inline void atomic_inc(atomic_t *v)
15470 {
15471 - asm volatile(LOCK_PREFIX "incl %0"
15472 + asm volatile(LOCK_PREFIX "incl %0\n"
15473 +
15474 +#ifdef CONFIG_PAX_REFCOUNT
15475 + "jno 0f\n"
15476 + LOCK_PREFIX "decl %0\n"
15477 + "int $4\n0:\n"
15478 + _ASM_EXTABLE(0b, 0b)
15479 +#endif
15480 +
15481 + : "+m" (v->counter));
15482 +}
15483 +
15484 +/**
15485 + * atomic_inc_unchecked - increment atomic variable
15486 + * @v: pointer of type atomic_unchecked_t
15487 + *
15488 + * Atomically increments @v by 1.
15489 + */
15490 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
15491 +{
15492 + asm volatile(LOCK_PREFIX "incl %0\n"
15493 : "+m" (v->counter));
15494 }
15495
15496 @@ -101,7 +188,27 @@ static inline void atomic_inc(atomic_t *v)
15497 */
15498 static inline void atomic_dec(atomic_t *v)
15499 {
15500 - asm volatile(LOCK_PREFIX "decl %0"
15501 + asm volatile(LOCK_PREFIX "decl %0\n"
15502 +
15503 +#ifdef CONFIG_PAX_REFCOUNT
15504 + "jno 0f\n"
15505 + LOCK_PREFIX "incl %0\n"
15506 + "int $4\n0:\n"
15507 + _ASM_EXTABLE(0b, 0b)
15508 +#endif
15509 +
15510 + : "+m" (v->counter));
15511 +}
15512 +
15513 +/**
15514 + * atomic_dec_unchecked - decrement atomic variable
15515 + * @v: pointer of type atomic_unchecked_t
15516 + *
15517 + * Atomically decrements @v by 1.
15518 + */
15519 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
15520 +{
15521 + asm volatile(LOCK_PREFIX "decl %0\n"
15522 : "+m" (v->counter));
15523 }
15524
15525 @@ -115,7 +222,7 @@ static inline void atomic_dec(atomic_t *v)
15526 */
15527 static inline int atomic_dec_and_test(atomic_t *v)
15528 {
15529 - GEN_UNARY_RMWcc(LOCK_PREFIX "decl", v->counter, "%0", "e");
15530 + GEN_UNARY_RMWcc(LOCK_PREFIX "decl", LOCK_PREFIX "incl", v->counter, "%0", "e");
15531 }
15532
15533 /**
15534 @@ -128,7 +235,20 @@ static inline int atomic_dec_and_test(atomic_t *v)
15535 */
15536 static inline int atomic_inc_and_test(atomic_t *v)
15537 {
15538 - GEN_UNARY_RMWcc(LOCK_PREFIX "incl", v->counter, "%0", "e");
15539 + GEN_UNARY_RMWcc(LOCK_PREFIX "incl", LOCK_PREFIX "decl", v->counter, "%0", "e");
15540 +}
15541 +
15542 +/**
15543 + * atomic_inc_and_test_unchecked - increment and test
15544 + * @v: pointer of type atomic_unchecked_t
15545 + *
15546 + * Atomically increments @v by 1
15547 + * and returns true if the result is zero, or false for all
15548 + * other cases.
15549 + */
15550 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
15551 +{
15552 + GEN_UNARY_RMWcc_unchecked(LOCK_PREFIX "incl", v->counter, "%0", "e");
15553 }
15554
15555 /**
15556 @@ -142,7 +262,7 @@ static inline int atomic_inc_and_test(atomic_t *v)
15557 */
15558 static inline int atomic_add_negative(int i, atomic_t *v)
15559 {
15560 - GEN_BINARY_RMWcc(LOCK_PREFIX "addl", v->counter, "er", i, "%0", "s");
15561 + GEN_BINARY_RMWcc(LOCK_PREFIX "addl", LOCK_PREFIX "subl", v->counter, "er", i, "%0", "s");
15562 }
15563
15564 /**
15565 @@ -154,6 +274,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
15566 */
15567 static inline int atomic_add_return(int i, atomic_t *v)
15568 {
15569 + return i + xadd_check_overflow(&v->counter, i);
15570 +}
15571 +
15572 +/**
15573 + * atomic_add_return_unchecked - add integer and return
15574 + * @i: integer value to add
15575 + * @v: pointer of type atomic_unchecked_t
15576 + *
15577 + * Atomically adds @i to @v and returns @i + @v
15578 + */
15579 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
15580 +{
15581 return i + xadd(&v->counter, i);
15582 }
15583
15584 @@ -170,9 +302,18 @@ static inline int atomic_sub_return(int i, atomic_t *v)
15585 }
15586
15587 #define atomic_inc_return(v) (atomic_add_return(1, v))
15588 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
15589 +{
15590 + return atomic_add_return_unchecked(1, v);
15591 +}
15592 #define atomic_dec_return(v) (atomic_sub_return(1, v))
15593
15594 -static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
15595 +static inline int __intentional_overflow(-1) atomic_cmpxchg(atomic_t *v, int old, int new)
15596 +{
15597 + return cmpxchg(&v->counter, old, new);
15598 +}
15599 +
15600 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
15601 {
15602 return cmpxchg(&v->counter, old, new);
15603 }
15604 @@ -182,6 +323,11 @@ static inline int atomic_xchg(atomic_t *v, int new)
15605 return xchg(&v->counter, new);
15606 }
15607
15608 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
15609 +{
15610 + return xchg(&v->counter, new);
15611 +}
15612 +
15613 /**
15614 * __atomic_add_unless - add unless the number is already a given value
15615 * @v: pointer of type atomic_t
15616 @@ -191,14 +337,27 @@ static inline int atomic_xchg(atomic_t *v, int new)
15617 * Atomically adds @a to @v, so long as @v was not already @u.
15618 * Returns the old value of @v.
15619 */
15620 -static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15621 +static inline int __intentional_overflow(-1) __atomic_add_unless(atomic_t *v, int a, int u)
15622 {
15623 - int c, old;
15624 + int c, old, new;
15625 c = atomic_read(v);
15626 for (;;) {
15627 - if (unlikely(c == (u)))
15628 + if (unlikely(c == u))
15629 break;
15630 - old = atomic_cmpxchg((v), c, c + (a));
15631 +
15632 + asm volatile("addl %2,%0\n"
15633 +
15634 +#ifdef CONFIG_PAX_REFCOUNT
15635 + "jno 0f\n"
15636 + "subl %2,%0\n"
15637 + "int $4\n0:\n"
15638 + _ASM_EXTABLE(0b, 0b)
15639 +#endif
15640 +
15641 + : "=r" (new)
15642 + : "0" (c), "ir" (a));
15643 +
15644 + old = atomic_cmpxchg(v, c, new);
15645 if (likely(old == c))
15646 break;
15647 c = old;
15648 @@ -207,6 +366,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15649 }
15650
15651 /**
15652 + * atomic_inc_not_zero_hint - increment if not null
15653 + * @v: pointer of type atomic_t
15654 + * @hint: probable value of the atomic before the increment
15655 + *
15656 + * This version of atomic_inc_not_zero() gives a hint of probable
15657 + * value of the atomic. This helps processor to not read the memory
15658 + * before doing the atomic read/modify/write cycle, lowering
15659 + * number of bus transactions on some arches.
15660 + *
15661 + * Returns: 0 if increment was not done, 1 otherwise.
15662 + */
15663 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
15664 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
15665 +{
15666 + int val, c = hint, new;
15667 +
15668 + /* sanity test, should be removed by compiler if hint is a constant */
15669 + if (!hint)
15670 + return __atomic_add_unless(v, 1, 0);
15671 +
15672 + do {
15673 + asm volatile("incl %0\n"
15674 +
15675 +#ifdef CONFIG_PAX_REFCOUNT
15676 + "jno 0f\n"
15677 + "decl %0\n"
15678 + "int $4\n0:\n"
15679 + _ASM_EXTABLE(0b, 0b)
15680 +#endif
15681 +
15682 + : "=r" (new)
15683 + : "0" (c));
15684 +
15685 + val = atomic_cmpxchg(v, c, new);
15686 + if (val == c)
15687 + return 1;
15688 + c = val;
15689 + } while (c);
15690 +
15691 + return 0;
15692 +}
15693 +
15694 +/**
15695 * atomic_inc_short - increment of a short integer
15696 * @v: pointer to type int
15697 *
15698 @@ -235,14 +437,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
15699 #endif
15700
15701 /* These are x86-specific, used by some header files */
15702 -#define atomic_clear_mask(mask, addr) \
15703 - asm volatile(LOCK_PREFIX "andl %0,%1" \
15704 - : : "r" (~(mask)), "m" (*(addr)) : "memory")
15705 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
15706 +{
15707 + asm volatile(LOCK_PREFIX "andl %1,%0"
15708 + : "+m" (v->counter)
15709 + : "r" (~(mask))
15710 + : "memory");
15711 +}
15712
15713 -#define atomic_set_mask(mask, addr) \
15714 - asm volatile(LOCK_PREFIX "orl %0,%1" \
15715 - : : "r" ((unsigned)(mask)), "m" (*(addr)) \
15716 - : "memory")
15717 +static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15718 +{
15719 + asm volatile(LOCK_PREFIX "andl %1,%0"
15720 + : "+m" (v->counter)
15721 + : "r" (~(mask))
15722 + : "memory");
15723 +}
15724 +
15725 +static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
15726 +{
15727 + asm volatile(LOCK_PREFIX "orl %1,%0"
15728 + : "+m" (v->counter)
15729 + : "r" (mask)
15730 + : "memory");
15731 +}
15732 +
15733 +static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15734 +{
15735 + asm volatile(LOCK_PREFIX "orl %1,%0"
15736 + : "+m" (v->counter)
15737 + : "r" (mask)
15738 + : "memory");
15739 +}
15740
15741 #ifdef CONFIG_X86_32
15742 # include <asm/atomic64_32.h>
15743 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
15744 index b154de7..bf18a5a 100644
15745 --- a/arch/x86/include/asm/atomic64_32.h
15746 +++ b/arch/x86/include/asm/atomic64_32.h
15747 @@ -12,6 +12,14 @@ typedef struct {
15748 u64 __aligned(8) counter;
15749 } atomic64_t;
15750
15751 +#ifdef CONFIG_PAX_REFCOUNT
15752 +typedef struct {
15753 + u64 __aligned(8) counter;
15754 +} atomic64_unchecked_t;
15755 +#else
15756 +typedef atomic64_t atomic64_unchecked_t;
15757 +#endif
15758 +
15759 #define ATOMIC64_INIT(val) { (val) }
15760
15761 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
15762 @@ -37,21 +45,31 @@ typedef struct {
15763 ATOMIC64_DECL_ONE(sym##_386)
15764
15765 ATOMIC64_DECL_ONE(add_386);
15766 +ATOMIC64_DECL_ONE(add_unchecked_386);
15767 ATOMIC64_DECL_ONE(sub_386);
15768 +ATOMIC64_DECL_ONE(sub_unchecked_386);
15769 ATOMIC64_DECL_ONE(inc_386);
15770 +ATOMIC64_DECL_ONE(inc_unchecked_386);
15771 ATOMIC64_DECL_ONE(dec_386);
15772 +ATOMIC64_DECL_ONE(dec_unchecked_386);
15773 #endif
15774
15775 #define alternative_atomic64(f, out, in...) \
15776 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
15777
15778 ATOMIC64_DECL(read);
15779 +ATOMIC64_DECL(read_unchecked);
15780 ATOMIC64_DECL(set);
15781 +ATOMIC64_DECL(set_unchecked);
15782 ATOMIC64_DECL(xchg);
15783 ATOMIC64_DECL(add_return);
15784 +ATOMIC64_DECL(add_return_unchecked);
15785 ATOMIC64_DECL(sub_return);
15786 +ATOMIC64_DECL(sub_return_unchecked);
15787 ATOMIC64_DECL(inc_return);
15788 +ATOMIC64_DECL(inc_return_unchecked);
15789 ATOMIC64_DECL(dec_return);
15790 +ATOMIC64_DECL(dec_return_unchecked);
15791 ATOMIC64_DECL(dec_if_positive);
15792 ATOMIC64_DECL(inc_not_zero);
15793 ATOMIC64_DECL(add_unless);
15794 @@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
15795 }
15796
15797 /**
15798 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
15799 + * @p: pointer to type atomic64_unchecked_t
15800 + * @o: expected value
15801 + * @n: new value
15802 + *
15803 + * Atomically sets @v to @n if it was equal to @o and returns
15804 + * the old value.
15805 + */
15806 +
15807 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
15808 +{
15809 + return cmpxchg64(&v->counter, o, n);
15810 +}
15811 +
15812 +/**
15813 * atomic64_xchg - xchg atomic64 variable
15814 * @v: pointer to type atomic64_t
15815 * @n: value to assign
15816 @@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
15817 }
15818
15819 /**
15820 + * atomic64_set_unchecked - set atomic64 variable
15821 + * @v: pointer to type atomic64_unchecked_t
15822 + * @n: value to assign
15823 + *
15824 + * Atomically sets the value of @v to @n.
15825 + */
15826 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
15827 +{
15828 + unsigned high = (unsigned)(i >> 32);
15829 + unsigned low = (unsigned)i;
15830 + alternative_atomic64(set, /* no output */,
15831 + "S" (v), "b" (low), "c" (high)
15832 + : "eax", "edx", "memory");
15833 +}
15834 +
15835 +/**
15836 * atomic64_read - read atomic64 variable
15837 * @v: pointer to type atomic64_t
15838 *
15839 @@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
15840 }
15841
15842 /**
15843 + * atomic64_read_unchecked - read atomic64 variable
15844 + * @v: pointer to type atomic64_unchecked_t
15845 + *
15846 + * Atomically reads the value of @v and returns it.
15847 + */
15848 +static inline long long __intentional_overflow(-1) atomic64_read_unchecked(atomic64_unchecked_t *v)
15849 +{
15850 + long long r;
15851 + alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
15852 + return r;
15853 + }
15854 +
15855 +/**
15856 * atomic64_add_return - add and return
15857 * @i: integer value to add
15858 * @v: pointer to type atomic64_t
15859 @@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
15860 return i;
15861 }
15862
15863 +/**
15864 + * atomic64_add_return_unchecked - add and return
15865 + * @i: integer value to add
15866 + * @v: pointer to type atomic64_unchecked_t
15867 + *
15868 + * Atomically adds @i to @v and returns @i + *@v
15869 + */
15870 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
15871 +{
15872 + alternative_atomic64(add_return_unchecked,
15873 + ASM_OUTPUT2("+A" (i), "+c" (v)),
15874 + ASM_NO_INPUT_CLOBBER("memory"));
15875 + return i;
15876 +}
15877 +
15878 /*
15879 * Other variants with different arithmetic operators:
15880 */
15881 @@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
15882 return a;
15883 }
15884
15885 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15886 +{
15887 + long long a;
15888 + alternative_atomic64(inc_return_unchecked, "=&A" (a),
15889 + "S" (v) : "memory", "ecx");
15890 + return a;
15891 +}
15892 +
15893 static inline long long atomic64_dec_return(atomic64_t *v)
15894 {
15895 long long a;
15896 @@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
15897 }
15898
15899 /**
15900 + * atomic64_add_unchecked - add integer to atomic64 variable
15901 + * @i: integer value to add
15902 + * @v: pointer to type atomic64_unchecked_t
15903 + *
15904 + * Atomically adds @i to @v.
15905 + */
15906 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
15907 +{
15908 + __alternative_atomic64(add_unchecked, add_return_unchecked,
15909 + ASM_OUTPUT2("+A" (i), "+c" (v)),
15910 + ASM_NO_INPUT_CLOBBER("memory"));
15911 + return i;
15912 +}
15913 +
15914 +/**
15915 * atomic64_sub - subtract the atomic64 variable
15916 * @i: integer value to subtract
15917 * @v: pointer to type atomic64_t
15918 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
15919 index 46e9052..ae45136 100644
15920 --- a/arch/x86/include/asm/atomic64_64.h
15921 +++ b/arch/x86/include/asm/atomic64_64.h
15922 @@ -18,7 +18,19 @@
15923 */
15924 static inline long atomic64_read(const atomic64_t *v)
15925 {
15926 - return (*(volatile long *)&(v)->counter);
15927 + return (*(volatile const long *)&(v)->counter);
15928 +}
15929 +
15930 +/**
15931 + * atomic64_read_unchecked - read atomic64 variable
15932 + * @v: pointer of type atomic64_unchecked_t
15933 + *
15934 + * Atomically reads the value of @v.
15935 + * Doesn't imply a read memory barrier.
15936 + */
15937 +static inline long __intentional_overflow(-1) atomic64_read_unchecked(const atomic64_unchecked_t *v)
15938 +{
15939 + return (*(volatile const long *)&(v)->counter);
15940 }
15941
15942 /**
15943 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
15944 }
15945
15946 /**
15947 + * atomic64_set_unchecked - set atomic64 variable
15948 + * @v: pointer to type atomic64_unchecked_t
15949 + * @i: required value
15950 + *
15951 + * Atomically sets the value of @v to @i.
15952 + */
15953 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
15954 +{
15955 + v->counter = i;
15956 +}
15957 +
15958 +/**
15959 * atomic64_add - add integer to atomic64 variable
15960 * @i: integer value to add
15961 * @v: pointer to type atomic64_t
15962 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
15963 */
15964 static inline void atomic64_add(long i, atomic64_t *v)
15965 {
15966 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
15967 +
15968 +#ifdef CONFIG_PAX_REFCOUNT
15969 + "jno 0f\n"
15970 + LOCK_PREFIX "subq %1,%0\n"
15971 + "int $4\n0:\n"
15972 + _ASM_EXTABLE(0b, 0b)
15973 +#endif
15974 +
15975 + : "=m" (v->counter)
15976 + : "er" (i), "m" (v->counter));
15977 +}
15978 +
15979 +/**
15980 + * atomic64_add_unchecked - add integer to atomic64 variable
15981 + * @i: integer value to add
15982 + * @v: pointer to type atomic64_unchecked_t
15983 + *
15984 + * Atomically adds @i to @v.
15985 + */
15986 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
15987 +{
15988 asm volatile(LOCK_PREFIX "addq %1,%0"
15989 : "=m" (v->counter)
15990 : "er" (i), "m" (v->counter));
15991 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
15992 */
15993 static inline void atomic64_sub(long i, atomic64_t *v)
15994 {
15995 - asm volatile(LOCK_PREFIX "subq %1,%0"
15996 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
15997 +
15998 +#ifdef CONFIG_PAX_REFCOUNT
15999 + "jno 0f\n"
16000 + LOCK_PREFIX "addq %1,%0\n"
16001 + "int $4\n0:\n"
16002 + _ASM_EXTABLE(0b, 0b)
16003 +#endif
16004 +
16005 + : "=m" (v->counter)
16006 + : "er" (i), "m" (v->counter));
16007 +}
16008 +
16009 +/**
16010 + * atomic64_sub_unchecked - subtract the atomic64 variable
16011 + * @i: integer value to subtract
16012 + * @v: pointer to type atomic64_unchecked_t
16013 + *
16014 + * Atomically subtracts @i from @v.
16015 + */
16016 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
16017 +{
16018 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
16019 : "=m" (v->counter)
16020 : "er" (i), "m" (v->counter));
16021 }
16022 @@ -72,7 +140,7 @@ static inline void atomic64_sub(long i, atomic64_t *v)
16023 */
16024 static inline int atomic64_sub_and_test(long i, atomic64_t *v)
16025 {
16026 - GEN_BINARY_RMWcc(LOCK_PREFIX "subq", v->counter, "er", i, "%0", "e");
16027 + GEN_BINARY_RMWcc(LOCK_PREFIX "subq", LOCK_PREFIX "addq", v->counter, "er", i, "%0", "e");
16028 }
16029
16030 /**
16031 @@ -83,6 +151,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
16032 */
16033 static inline void atomic64_inc(atomic64_t *v)
16034 {
16035 + asm volatile(LOCK_PREFIX "incq %0\n"
16036 +
16037 +#ifdef CONFIG_PAX_REFCOUNT
16038 + "jno 0f\n"
16039 + LOCK_PREFIX "decq %0\n"
16040 + "int $4\n0:\n"
16041 + _ASM_EXTABLE(0b, 0b)
16042 +#endif
16043 +
16044 + : "=m" (v->counter)
16045 + : "m" (v->counter));
16046 +}
16047 +
16048 +/**
16049 + * atomic64_inc_unchecked - increment atomic64 variable
16050 + * @v: pointer to type atomic64_unchecked_t
16051 + *
16052 + * Atomically increments @v by 1.
16053 + */
16054 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
16055 +{
16056 asm volatile(LOCK_PREFIX "incq %0"
16057 : "=m" (v->counter)
16058 : "m" (v->counter));
16059 @@ -96,7 +185,28 @@ static inline void atomic64_inc(atomic64_t *v)
16060 */
16061 static inline void atomic64_dec(atomic64_t *v)
16062 {
16063 - asm volatile(LOCK_PREFIX "decq %0"
16064 + asm volatile(LOCK_PREFIX "decq %0\n"
16065 +
16066 +#ifdef CONFIG_PAX_REFCOUNT
16067 + "jno 0f\n"
16068 + LOCK_PREFIX "incq %0\n"
16069 + "int $4\n0:\n"
16070 + _ASM_EXTABLE(0b, 0b)
16071 +#endif
16072 +
16073 + : "=m" (v->counter)
16074 + : "m" (v->counter));
16075 +}
16076 +
16077 +/**
16078 + * atomic64_dec_unchecked - decrement atomic64 variable
16079 + * @v: pointer to type atomic64_t
16080 + *
16081 + * Atomically decrements @v by 1.
16082 + */
16083 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
16084 +{
16085 + asm volatile(LOCK_PREFIX "decq %0\n"
16086 : "=m" (v->counter)
16087 : "m" (v->counter));
16088 }
16089 @@ -111,7 +221,7 @@ static inline void atomic64_dec(atomic64_t *v)
16090 */
16091 static inline int atomic64_dec_and_test(atomic64_t *v)
16092 {
16093 - GEN_UNARY_RMWcc(LOCK_PREFIX "decq", v->counter, "%0", "e");
16094 + GEN_UNARY_RMWcc(LOCK_PREFIX "decq", LOCK_PREFIX "incq", v->counter, "%0", "e");
16095 }
16096
16097 /**
16098 @@ -124,7 +234,7 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
16099 */
16100 static inline int atomic64_inc_and_test(atomic64_t *v)
16101 {
16102 - GEN_UNARY_RMWcc(LOCK_PREFIX "incq", v->counter, "%0", "e");
16103 + GEN_UNARY_RMWcc(LOCK_PREFIX "incq", LOCK_PREFIX "decq", v->counter, "%0", "e");
16104 }
16105
16106 /**
16107 @@ -138,7 +248,7 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
16108 */
16109 static inline int atomic64_add_negative(long i, atomic64_t *v)
16110 {
16111 - GEN_BINARY_RMWcc(LOCK_PREFIX "addq", v->counter, "er", i, "%0", "s");
16112 + GEN_BINARY_RMWcc(LOCK_PREFIX "addq", LOCK_PREFIX "subq", v->counter, "er", i, "%0", "s");
16113 }
16114
16115 /**
16116 @@ -150,6 +260,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
16117 */
16118 static inline long atomic64_add_return(long i, atomic64_t *v)
16119 {
16120 + return i + xadd_check_overflow(&v->counter, i);
16121 +}
16122 +
16123 +/**
16124 + * atomic64_add_return_unchecked - add and return
16125 + * @i: integer value to add
16126 + * @v: pointer to type atomic64_unchecked_t
16127 + *
16128 + * Atomically adds @i to @v and returns @i + @v
16129 + */
16130 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
16131 +{
16132 return i + xadd(&v->counter, i);
16133 }
16134
16135 @@ -159,6 +281,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
16136 }
16137
16138 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
16139 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
16140 +{
16141 + return atomic64_add_return_unchecked(1, v);
16142 +}
16143 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
16144
16145 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
16146 @@ -166,6 +292,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
16147 return cmpxchg(&v->counter, old, new);
16148 }
16149
16150 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
16151 +{
16152 + return cmpxchg(&v->counter, old, new);
16153 +}
16154 +
16155 static inline long atomic64_xchg(atomic64_t *v, long new)
16156 {
16157 return xchg(&v->counter, new);
16158 @@ -182,17 +313,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
16159 */
16160 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
16161 {
16162 - long c, old;
16163 + long c, old, new;
16164 c = atomic64_read(v);
16165 for (;;) {
16166 - if (unlikely(c == (u)))
16167 + if (unlikely(c == u))
16168 break;
16169 - old = atomic64_cmpxchg((v), c, c + (a));
16170 +
16171 + asm volatile("add %2,%0\n"
16172 +
16173 +#ifdef CONFIG_PAX_REFCOUNT
16174 + "jno 0f\n"
16175 + "sub %2,%0\n"
16176 + "int $4\n0:\n"
16177 + _ASM_EXTABLE(0b, 0b)
16178 +#endif
16179 +
16180 + : "=r" (new)
16181 + : "0" (c), "ir" (a));
16182 +
16183 + old = atomic64_cmpxchg(v, c, new);
16184 if (likely(old == c))
16185 break;
16186 c = old;
16187 }
16188 - return c != (u);
16189 + return c != u;
16190 }
16191
16192 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
16193 diff --git a/arch/x86/include/asm/barrier.h b/arch/x86/include/asm/barrier.h
16194 index 5c7198c..44180b5 100644
16195 --- a/arch/x86/include/asm/barrier.h
16196 +++ b/arch/x86/include/asm/barrier.h
16197 @@ -107,7 +107,7 @@
16198 do { \
16199 compiletime_assert_atomic_type(*p); \
16200 smp_mb(); \
16201 - ACCESS_ONCE(*p) = (v); \
16202 + ACCESS_ONCE_RW(*p) = (v); \
16203 } while (0)
16204
16205 #define smp_load_acquire(p) \
16206 @@ -124,7 +124,7 @@ do { \
16207 do { \
16208 compiletime_assert_atomic_type(*p); \
16209 barrier(); \
16210 - ACCESS_ONCE(*p) = (v); \
16211 + ACCESS_ONCE_RW(*p) = (v); \
16212 } while (0)
16213
16214 #define smp_load_acquire(p) \
16215 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
16216 index afcd35d..141b32d 100644
16217 --- a/arch/x86/include/asm/bitops.h
16218 +++ b/arch/x86/include/asm/bitops.h
16219 @@ -50,7 +50,7 @@
16220 * a mask operation on a byte.
16221 */
16222 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
16223 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
16224 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
16225 #define CONST_MASK(nr) (1 << ((nr) & 7))
16226
16227 /**
16228 @@ -203,7 +203,7 @@ static inline void change_bit(long nr, volatile unsigned long *addr)
16229 */
16230 static inline int test_and_set_bit(long nr, volatile unsigned long *addr)
16231 {
16232 - GEN_BINARY_RMWcc(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
16233 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
16234 }
16235
16236 /**
16237 @@ -249,7 +249,7 @@ static inline int __test_and_set_bit(long nr, volatile unsigned long *addr)
16238 */
16239 static inline int test_and_clear_bit(long nr, volatile unsigned long *addr)
16240 {
16241 - GEN_BINARY_RMWcc(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
16242 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
16243 }
16244
16245 /**
16246 @@ -302,7 +302,7 @@ static inline int __test_and_change_bit(long nr, volatile unsigned long *addr)
16247 */
16248 static inline int test_and_change_bit(long nr, volatile unsigned long *addr)
16249 {
16250 - GEN_BINARY_RMWcc(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
16251 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
16252 }
16253
16254 static __always_inline int constant_test_bit(long nr, const volatile unsigned long *addr)
16255 @@ -343,7 +343,7 @@ static int test_bit(int nr, const volatile unsigned long *addr);
16256 *
16257 * Undefined if no bit exists, so code should check against 0 first.
16258 */
16259 -static inline unsigned long __ffs(unsigned long word)
16260 +static inline unsigned long __intentional_overflow(-1) __ffs(unsigned long word)
16261 {
16262 asm("rep; bsf %1,%0"
16263 : "=r" (word)
16264 @@ -357,7 +357,7 @@ static inline unsigned long __ffs(unsigned long word)
16265 *
16266 * Undefined if no zero exists, so code should check against ~0UL first.
16267 */
16268 -static inline unsigned long ffz(unsigned long word)
16269 +static inline unsigned long __intentional_overflow(-1) ffz(unsigned long word)
16270 {
16271 asm("rep; bsf %1,%0"
16272 : "=r" (word)
16273 @@ -371,7 +371,7 @@ static inline unsigned long ffz(unsigned long word)
16274 *
16275 * Undefined if no set bit exists, so code should check against 0 first.
16276 */
16277 -static inline unsigned long __fls(unsigned long word)
16278 +static inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
16279 {
16280 asm("bsr %1,%0"
16281 : "=r" (word)
16282 @@ -434,7 +434,7 @@ static inline int ffs(int x)
16283 * set bit if value is nonzero. The last (most significant) bit is
16284 * at position 32.
16285 */
16286 -static inline int fls(int x)
16287 +static inline int __intentional_overflow(-1) fls(int x)
16288 {
16289 int r;
16290
16291 @@ -476,7 +476,7 @@ static inline int fls(int x)
16292 * at position 64.
16293 */
16294 #ifdef CONFIG_X86_64
16295 -static __always_inline int fls64(__u64 x)
16296 +static __always_inline __intentional_overflow(-1) int fls64(__u64 x)
16297 {
16298 int bitpos = -1;
16299 /*
16300 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
16301 index 4fa687a..60f2d39 100644
16302 --- a/arch/x86/include/asm/boot.h
16303 +++ b/arch/x86/include/asm/boot.h
16304 @@ -6,10 +6,15 @@
16305 #include <uapi/asm/boot.h>
16306
16307 /* Physical address where kernel should be loaded. */
16308 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
16309 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
16310 + (CONFIG_PHYSICAL_ALIGN - 1)) \
16311 & ~(CONFIG_PHYSICAL_ALIGN - 1))
16312
16313 +#ifndef __ASSEMBLY__
16314 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
16315 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
16316 +#endif
16317 +
16318 /* Minimum kernel alignment, as a power of two */
16319 #ifdef CONFIG_X86_64
16320 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
16321 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
16322 index 48f99f1..d78ebf9 100644
16323 --- a/arch/x86/include/asm/cache.h
16324 +++ b/arch/x86/include/asm/cache.h
16325 @@ -5,12 +5,13 @@
16326
16327 /* L1 cache line size */
16328 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
16329 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
16330 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
16331
16332 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
16333 +#define __read_only __attribute__((__section__(".data..read_only")))
16334
16335 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
16336 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
16337 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
16338
16339 #ifdef CONFIG_X86_VSMP
16340 #ifdef CONFIG_SMP
16341 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
16342 index 9863ee3..4a1f8e1 100644
16343 --- a/arch/x86/include/asm/cacheflush.h
16344 +++ b/arch/x86/include/asm/cacheflush.h
16345 @@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
16346 unsigned long pg_flags = pg->flags & _PGMT_MASK;
16347
16348 if (pg_flags == _PGMT_DEFAULT)
16349 - return -1;
16350 + return ~0UL;
16351 else if (pg_flags == _PGMT_WC)
16352 return _PAGE_CACHE_WC;
16353 else if (pg_flags == _PGMT_UC_MINUS)
16354 diff --git a/arch/x86/include/asm/calling.h b/arch/x86/include/asm/calling.h
16355 index cb4c73b..c473c29 100644
16356 --- a/arch/x86/include/asm/calling.h
16357 +++ b/arch/x86/include/asm/calling.h
16358 @@ -82,103 +82,113 @@ For 32-bit we have the following conventions - kernel is built with
16359 #define RSP 152
16360 #define SS 160
16361
16362 -#define ARGOFFSET R11
16363 -#define SWFRAME ORIG_RAX
16364 +#define ARGOFFSET R15
16365
16366 .macro SAVE_ARGS addskip=0, save_rcx=1, save_r891011=1
16367 - subq $9*8+\addskip, %rsp
16368 - CFI_ADJUST_CFA_OFFSET 9*8+\addskip
16369 - movq_cfi rdi, 8*8
16370 - movq_cfi rsi, 7*8
16371 - movq_cfi rdx, 6*8
16372 + subq $ORIG_RAX-ARGOFFSET+\addskip, %rsp
16373 + CFI_ADJUST_CFA_OFFSET ORIG_RAX-ARGOFFSET+\addskip
16374 + movq_cfi rdi, RDI
16375 + movq_cfi rsi, RSI
16376 + movq_cfi rdx, RDX
16377
16378 .if \save_rcx
16379 - movq_cfi rcx, 5*8
16380 + movq_cfi rcx, RCX
16381 .endif
16382
16383 - movq_cfi rax, 4*8
16384 + movq_cfi rax, RAX
16385
16386 .if \save_r891011
16387 - movq_cfi r8, 3*8
16388 - movq_cfi r9, 2*8
16389 - movq_cfi r10, 1*8
16390 - movq_cfi r11, 0*8
16391 + movq_cfi r8, R8
16392 + movq_cfi r9, R9
16393 + movq_cfi r10, R10
16394 + movq_cfi r11, R11
16395 .endif
16396
16397 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16398 + movq_cfi r12, R12
16399 +#endif
16400 +
16401 .endm
16402
16403 -#define ARG_SKIP (9*8)
16404 +#define ARG_SKIP ORIG_RAX
16405
16406 .macro RESTORE_ARGS rstor_rax=1, addskip=0, rstor_rcx=1, rstor_r11=1, \
16407 rstor_r8910=1, rstor_rdx=1
16408 +
16409 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16410 + movq_cfi_restore R12, r12
16411 +#endif
16412 +
16413 .if \rstor_r11
16414 - movq_cfi_restore 0*8, r11
16415 + movq_cfi_restore R11, r11
16416 .endif
16417
16418 .if \rstor_r8910
16419 - movq_cfi_restore 1*8, r10
16420 - movq_cfi_restore 2*8, r9
16421 - movq_cfi_restore 3*8, r8
16422 + movq_cfi_restore R10, r10
16423 + movq_cfi_restore R9, r9
16424 + movq_cfi_restore R8, r8
16425 .endif
16426
16427 .if \rstor_rax
16428 - movq_cfi_restore 4*8, rax
16429 + movq_cfi_restore RAX, rax
16430 .endif
16431
16432 .if \rstor_rcx
16433 - movq_cfi_restore 5*8, rcx
16434 + movq_cfi_restore RCX, rcx
16435 .endif
16436
16437 .if \rstor_rdx
16438 - movq_cfi_restore 6*8, rdx
16439 + movq_cfi_restore RDX, rdx
16440 .endif
16441
16442 - movq_cfi_restore 7*8, rsi
16443 - movq_cfi_restore 8*8, rdi
16444 + movq_cfi_restore RSI, rsi
16445 + movq_cfi_restore RDI, rdi
16446
16447 - .if ARG_SKIP+\addskip > 0
16448 - addq $ARG_SKIP+\addskip, %rsp
16449 - CFI_ADJUST_CFA_OFFSET -(ARG_SKIP+\addskip)
16450 + .if ORIG_RAX+\addskip > 0
16451 + addq $ORIG_RAX+\addskip, %rsp
16452 + CFI_ADJUST_CFA_OFFSET -(ORIG_RAX+\addskip)
16453 .endif
16454 .endm
16455
16456 - .macro LOAD_ARGS offset, skiprax=0
16457 - movq \offset(%rsp), %r11
16458 - movq \offset+8(%rsp), %r10
16459 - movq \offset+16(%rsp), %r9
16460 - movq \offset+24(%rsp), %r8
16461 - movq \offset+40(%rsp), %rcx
16462 - movq \offset+48(%rsp), %rdx
16463 - movq \offset+56(%rsp), %rsi
16464 - movq \offset+64(%rsp), %rdi
16465 + .macro LOAD_ARGS skiprax=0
16466 + movq R11(%rsp), %r11
16467 + movq R10(%rsp), %r10
16468 + movq R9(%rsp), %r9
16469 + movq R8(%rsp), %r8
16470 + movq RCX(%rsp), %rcx
16471 + movq RDX(%rsp), %rdx
16472 + movq RSI(%rsp), %rsi
16473 + movq RDI(%rsp), %rdi
16474 .if \skiprax
16475 .else
16476 - movq \offset+72(%rsp), %rax
16477 + movq RAX(%rsp), %rax
16478 .endif
16479 .endm
16480
16481 -#define REST_SKIP (6*8)
16482 -
16483 .macro SAVE_REST
16484 - subq $REST_SKIP, %rsp
16485 - CFI_ADJUST_CFA_OFFSET REST_SKIP
16486 - movq_cfi rbx, 5*8
16487 - movq_cfi rbp, 4*8
16488 - movq_cfi r12, 3*8
16489 - movq_cfi r13, 2*8
16490 - movq_cfi r14, 1*8
16491 - movq_cfi r15, 0*8
16492 + movq_cfi rbx, RBX
16493 + movq_cfi rbp, RBP
16494 +
16495 +#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16496 + movq_cfi r12, R12
16497 +#endif
16498 +
16499 + movq_cfi r13, R13
16500 + movq_cfi r14, R14
16501 + movq_cfi r15, R15
16502 .endm
16503
16504 .macro RESTORE_REST
16505 - movq_cfi_restore 0*8, r15
16506 - movq_cfi_restore 1*8, r14
16507 - movq_cfi_restore 2*8, r13
16508 - movq_cfi_restore 3*8, r12
16509 - movq_cfi_restore 4*8, rbp
16510 - movq_cfi_restore 5*8, rbx
16511 - addq $REST_SKIP, %rsp
16512 - CFI_ADJUST_CFA_OFFSET -(REST_SKIP)
16513 + movq_cfi_restore R15, r15
16514 + movq_cfi_restore R14, r14
16515 + movq_cfi_restore R13, r13
16516 +
16517 +#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16518 + movq_cfi_restore R12, r12
16519 +#endif
16520 +
16521 + movq_cfi_restore RBP, rbp
16522 + movq_cfi_restore RBX, rbx
16523 .endm
16524
16525 .macro SAVE_ALL
16526 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
16527 index f50de69..2b0a458 100644
16528 --- a/arch/x86/include/asm/checksum_32.h
16529 +++ b/arch/x86/include/asm/checksum_32.h
16530 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
16531 int len, __wsum sum,
16532 int *src_err_ptr, int *dst_err_ptr);
16533
16534 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
16535 + int len, __wsum sum,
16536 + int *src_err_ptr, int *dst_err_ptr);
16537 +
16538 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
16539 + int len, __wsum sum,
16540 + int *src_err_ptr, int *dst_err_ptr);
16541 +
16542 /*
16543 * Note: when you get a NULL pointer exception here this means someone
16544 * passed in an incorrect kernel address to one of these functions.
16545 @@ -53,7 +61,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
16546
16547 might_sleep();
16548 stac();
16549 - ret = csum_partial_copy_generic((__force void *)src, dst,
16550 + ret = csum_partial_copy_generic_from_user((__force void *)src, dst,
16551 len, sum, err_ptr, NULL);
16552 clac();
16553
16554 @@ -187,7 +195,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
16555 might_sleep();
16556 if (access_ok(VERIFY_WRITE, dst, len)) {
16557 stac();
16558 - ret = csum_partial_copy_generic(src, (__force void *)dst,
16559 + ret = csum_partial_copy_generic_to_user(src, (__force void *)dst,
16560 len, sum, NULL, err_ptr);
16561 clac();
16562 return ret;
16563 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
16564 index d47786a..2d8883e 100644
16565 --- a/arch/x86/include/asm/cmpxchg.h
16566 +++ b/arch/x86/include/asm/cmpxchg.h
16567 @@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
16568 __compiletime_error("Bad argument size for cmpxchg");
16569 extern void __xadd_wrong_size(void)
16570 __compiletime_error("Bad argument size for xadd");
16571 +extern void __xadd_check_overflow_wrong_size(void)
16572 + __compiletime_error("Bad argument size for xadd_check_overflow");
16573 extern void __add_wrong_size(void)
16574 __compiletime_error("Bad argument size for add");
16575 +extern void __add_check_overflow_wrong_size(void)
16576 + __compiletime_error("Bad argument size for add_check_overflow");
16577
16578 /*
16579 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
16580 @@ -67,6 +71,38 @@ extern void __add_wrong_size(void)
16581 __ret; \
16582 })
16583
16584 +#ifdef CONFIG_PAX_REFCOUNT
16585 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
16586 + ({ \
16587 + __typeof__ (*(ptr)) __ret = (arg); \
16588 + switch (sizeof(*(ptr))) { \
16589 + case __X86_CASE_L: \
16590 + asm volatile (lock #op "l %0, %1\n" \
16591 + "jno 0f\n" \
16592 + "mov %0,%1\n" \
16593 + "int $4\n0:\n" \
16594 + _ASM_EXTABLE(0b, 0b) \
16595 + : "+r" (__ret), "+m" (*(ptr)) \
16596 + : : "memory", "cc"); \
16597 + break; \
16598 + case __X86_CASE_Q: \
16599 + asm volatile (lock #op "q %q0, %1\n" \
16600 + "jno 0f\n" \
16601 + "mov %0,%1\n" \
16602 + "int $4\n0:\n" \
16603 + _ASM_EXTABLE(0b, 0b) \
16604 + : "+r" (__ret), "+m" (*(ptr)) \
16605 + : : "memory", "cc"); \
16606 + break; \
16607 + default: \
16608 + __ ## op ## _check_overflow_wrong_size(); \
16609 + } \
16610 + __ret; \
16611 + })
16612 +#else
16613 +#define __xchg_op_check_overflow(ptr, arg, op, lock) __xchg_op(ptr, arg, op, lock)
16614 +#endif
16615 +
16616 /*
16617 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
16618 * Since this is generally used to protect other memory information, we
16619 @@ -167,6 +203,9 @@ extern void __add_wrong_size(void)
16620 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
16621 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
16622
16623 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
16624 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
16625 +
16626 #define __add(ptr, inc, lock) \
16627 ({ \
16628 __typeof__ (*(ptr)) __ret = (inc); \
16629 diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
16630 index 59c6c40..5e0b22c 100644
16631 --- a/arch/x86/include/asm/compat.h
16632 +++ b/arch/x86/include/asm/compat.h
16633 @@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
16634 typedef u32 compat_uint_t;
16635 typedef u32 compat_ulong_t;
16636 typedef u64 __attribute__((aligned(4))) compat_u64;
16637 -typedef u32 compat_uptr_t;
16638 +typedef u32 __user compat_uptr_t;
16639
16640 struct compat_timespec {
16641 compat_time_t tv_sec;
16642 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
16643 index e265ff9..72c253b 100644
16644 --- a/arch/x86/include/asm/cpufeature.h
16645 +++ b/arch/x86/include/asm/cpufeature.h
16646 @@ -203,7 +203,7 @@
16647 #define X86_FEATURE_DECODEASSISTS (8*32+12) /* AMD Decode Assists support */
16648 #define X86_FEATURE_PAUSEFILTER (8*32+13) /* AMD filtered pause intercept */
16649 #define X86_FEATURE_PFTHRESHOLD (8*32+14) /* AMD pause filter threshold */
16650 -
16651 +#define X86_FEATURE_STRONGUDEREF (8*32+31) /* PaX PCID based strong UDEREF */
16652
16653 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
16654 #define X86_FEATURE_FSGSBASE (9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
16655 @@ -211,7 +211,7 @@
16656 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
16657 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
16658 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
16659 -#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
16660 +#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
16661 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
16662 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
16663 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
16664 @@ -359,6 +359,7 @@ extern const char * const x86_power_flags[32];
16665 #undef cpu_has_centaur_mcr
16666 #define cpu_has_centaur_mcr 0
16667
16668 +#define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID)
16669 #endif /* CONFIG_X86_64 */
16670
16671 #if __GNUC__ >= 4
16672 @@ -411,7 +412,8 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16673
16674 #ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS
16675 t_warn:
16676 - warn_pre_alternatives();
16677 + if (bit != X86_FEATURE_PCID && bit != X86_FEATURE_INVPCID)
16678 + warn_pre_alternatives();
16679 return false;
16680 #endif
16681
16682 @@ -431,7 +433,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16683 ".section .discard,\"aw\",@progbits\n"
16684 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16685 ".previous\n"
16686 - ".section .altinstr_replacement,\"ax\"\n"
16687 + ".section .altinstr_replacement,\"a\"\n"
16688 "3: movb $1,%0\n"
16689 "4:\n"
16690 ".previous\n"
16691 @@ -468,7 +470,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16692 " .byte 2b - 1b\n" /* src len */
16693 " .byte 4f - 3f\n" /* repl len */
16694 ".previous\n"
16695 - ".section .altinstr_replacement,\"ax\"\n"
16696 + ".section .altinstr_replacement,\"a\"\n"
16697 "3: .byte 0xe9\n .long %l[t_no] - 2b\n"
16698 "4:\n"
16699 ".previous\n"
16700 @@ -501,7 +503,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16701 ".section .discard,\"aw\",@progbits\n"
16702 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16703 ".previous\n"
16704 - ".section .altinstr_replacement,\"ax\"\n"
16705 + ".section .altinstr_replacement,\"a\"\n"
16706 "3: movb $0,%0\n"
16707 "4:\n"
16708 ".previous\n"
16709 @@ -515,7 +517,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16710 ".section .discard,\"aw\",@progbits\n"
16711 " .byte 0xff + (6f-5f) - (4b-3b)\n" /* size check */
16712 ".previous\n"
16713 - ".section .altinstr_replacement,\"ax\"\n"
16714 + ".section .altinstr_replacement,\"a\"\n"
16715 "5: movb $1,%0\n"
16716 "6:\n"
16717 ".previous\n"
16718 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
16719 index 50d033a..37deb26 100644
16720 --- a/arch/x86/include/asm/desc.h
16721 +++ b/arch/x86/include/asm/desc.h
16722 @@ -4,6 +4,7 @@
16723 #include <asm/desc_defs.h>
16724 #include <asm/ldt.h>
16725 #include <asm/mmu.h>
16726 +#include <asm/pgtable.h>
16727
16728 #include <linux/smp.h>
16729 #include <linux/percpu.h>
16730 @@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16731
16732 desc->type = (info->read_exec_only ^ 1) << 1;
16733 desc->type |= info->contents << 2;
16734 + desc->type |= info->seg_not_present ^ 1;
16735
16736 desc->s = 1;
16737 desc->dpl = 0x3;
16738 @@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16739 }
16740
16741 extern struct desc_ptr idt_descr;
16742 -extern gate_desc idt_table[];
16743 -extern struct desc_ptr debug_idt_descr;
16744 -extern gate_desc debug_idt_table[];
16745 -
16746 -struct gdt_page {
16747 - struct desc_struct gdt[GDT_ENTRIES];
16748 -} __attribute__((aligned(PAGE_SIZE)));
16749 -
16750 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
16751 +extern gate_desc idt_table[IDT_ENTRIES];
16752 +extern const struct desc_ptr debug_idt_descr;
16753 +extern gate_desc debug_idt_table[IDT_ENTRIES];
16754
16755 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
16756 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
16757 {
16758 - return per_cpu(gdt_page, cpu).gdt;
16759 + return cpu_gdt_table[cpu];
16760 }
16761
16762 #ifdef CONFIG_X86_64
16763 @@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
16764 unsigned long base, unsigned dpl, unsigned flags,
16765 unsigned short seg)
16766 {
16767 - gate->a = (seg << 16) | (base & 0xffff);
16768 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
16769 + gate->gate.offset_low = base;
16770 + gate->gate.seg = seg;
16771 + gate->gate.reserved = 0;
16772 + gate->gate.type = type;
16773 + gate->gate.s = 0;
16774 + gate->gate.dpl = dpl;
16775 + gate->gate.p = 1;
16776 + gate->gate.offset_high = base >> 16;
16777 }
16778
16779 #endif
16780 @@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
16781
16782 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
16783 {
16784 + pax_open_kernel();
16785 memcpy(&idt[entry], gate, sizeof(*gate));
16786 + pax_close_kernel();
16787 }
16788
16789 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
16790 {
16791 + pax_open_kernel();
16792 memcpy(&ldt[entry], desc, 8);
16793 + pax_close_kernel();
16794 }
16795
16796 static inline void
16797 @@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
16798 default: size = sizeof(*gdt); break;
16799 }
16800
16801 + pax_open_kernel();
16802 memcpy(&gdt[entry], desc, size);
16803 + pax_close_kernel();
16804 }
16805
16806 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
16807 @@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
16808
16809 static inline void native_load_tr_desc(void)
16810 {
16811 + pax_open_kernel();
16812 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
16813 + pax_close_kernel();
16814 }
16815
16816 static inline void native_load_gdt(const struct desc_ptr *dtr)
16817 @@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
16818 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
16819 unsigned int i;
16820
16821 + pax_open_kernel();
16822 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
16823 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
16824 + pax_close_kernel();
16825 }
16826
16827 #define _LDT_empty(info) \
16828 @@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
16829 preempt_enable();
16830 }
16831
16832 -static inline unsigned long get_desc_base(const struct desc_struct *desc)
16833 +static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
16834 {
16835 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
16836 }
16837 @@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
16838 }
16839
16840 #ifdef CONFIG_X86_64
16841 -static inline void set_nmi_gate(int gate, void *addr)
16842 +static inline void set_nmi_gate(int gate, const void *addr)
16843 {
16844 gate_desc s;
16845
16846 @@ -321,14 +334,14 @@ static inline void set_nmi_gate(int gate, void *addr)
16847 #endif
16848
16849 #ifdef CONFIG_TRACING
16850 -extern struct desc_ptr trace_idt_descr;
16851 -extern gate_desc trace_idt_table[];
16852 +extern const struct desc_ptr trace_idt_descr;
16853 +extern gate_desc trace_idt_table[IDT_ENTRIES];
16854 static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16855 {
16856 write_idt_entry(trace_idt_table, entry, gate);
16857 }
16858
16859 -static inline void _trace_set_gate(int gate, unsigned type, void *addr,
16860 +static inline void _trace_set_gate(int gate, unsigned type, const void *addr,
16861 unsigned dpl, unsigned ist, unsigned seg)
16862 {
16863 gate_desc s;
16864 @@ -348,7 +361,7 @@ static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16865 #define _trace_set_gate(gate, type, addr, dpl, ist, seg)
16866 #endif
16867
16868 -static inline void _set_gate(int gate, unsigned type, void *addr,
16869 +static inline void _set_gate(int gate, unsigned type, const void *addr,
16870 unsigned dpl, unsigned ist, unsigned seg)
16871 {
16872 gate_desc s;
16873 @@ -371,9 +384,9 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
16874 #define set_intr_gate(n, addr) \
16875 do { \
16876 BUG_ON((unsigned)n > 0xFF); \
16877 - _set_gate(n, GATE_INTERRUPT, (void *)addr, 0, 0, \
16878 + _set_gate(n, GATE_INTERRUPT, (const void *)addr, 0, 0, \
16879 __KERNEL_CS); \
16880 - _trace_set_gate(n, GATE_INTERRUPT, (void *)trace_##addr,\
16881 + _trace_set_gate(n, GATE_INTERRUPT, (const void *)trace_##addr,\
16882 0, 0, __KERNEL_CS); \
16883 } while (0)
16884
16885 @@ -401,19 +414,19 @@ static inline void alloc_system_vector(int vector)
16886 /*
16887 * This routine sets up an interrupt gate at directory privilege level 3.
16888 */
16889 -static inline void set_system_intr_gate(unsigned int n, void *addr)
16890 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
16891 {
16892 BUG_ON((unsigned)n > 0xFF);
16893 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
16894 }
16895
16896 -static inline void set_system_trap_gate(unsigned int n, void *addr)
16897 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
16898 {
16899 BUG_ON((unsigned)n > 0xFF);
16900 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
16901 }
16902
16903 -static inline void set_trap_gate(unsigned int n, void *addr)
16904 +static inline void set_trap_gate(unsigned int n, const void *addr)
16905 {
16906 BUG_ON((unsigned)n > 0xFF);
16907 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
16908 @@ -422,16 +435,16 @@ static inline void set_trap_gate(unsigned int n, void *addr)
16909 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
16910 {
16911 BUG_ON((unsigned)n > 0xFF);
16912 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
16913 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
16914 }
16915
16916 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
16917 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
16918 {
16919 BUG_ON((unsigned)n > 0xFF);
16920 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
16921 }
16922
16923 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
16924 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
16925 {
16926 BUG_ON((unsigned)n > 0xFF);
16927 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
16928 @@ -503,4 +516,17 @@ static inline void load_current_idt(void)
16929 else
16930 load_idt((const struct desc_ptr *)&idt_descr);
16931 }
16932 +
16933 +#ifdef CONFIG_X86_32
16934 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
16935 +{
16936 + struct desc_struct d;
16937 +
16938 + if (likely(limit))
16939 + limit = (limit - 1UL) >> PAGE_SHIFT;
16940 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
16941 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
16942 +}
16943 +#endif
16944 +
16945 #endif /* _ASM_X86_DESC_H */
16946 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
16947 index 278441f..b95a174 100644
16948 --- a/arch/x86/include/asm/desc_defs.h
16949 +++ b/arch/x86/include/asm/desc_defs.h
16950 @@ -31,6 +31,12 @@ struct desc_struct {
16951 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
16952 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
16953 };
16954 + struct {
16955 + u16 offset_low;
16956 + u16 seg;
16957 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
16958 + unsigned offset_high: 16;
16959 + } gate;
16960 };
16961 } __attribute__((packed));
16962
16963 diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
16964 index ced283a..ffe04cc 100644
16965 --- a/arch/x86/include/asm/div64.h
16966 +++ b/arch/x86/include/asm/div64.h
16967 @@ -39,7 +39,7 @@
16968 __mod; \
16969 })
16970
16971 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16972 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16973 {
16974 union {
16975 u64 v64;
16976 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
16977 index 1a055c8..a1701de 100644
16978 --- a/arch/x86/include/asm/elf.h
16979 +++ b/arch/x86/include/asm/elf.h
16980 @@ -75,9 +75,6 @@ typedef struct user_fxsr_struct elf_fpxregset_t;
16981
16982 #include <asm/vdso.h>
16983
16984 -#ifdef CONFIG_X86_64
16985 -extern unsigned int vdso64_enabled;
16986 -#endif
16987 #if defined(CONFIG_X86_32) || defined(CONFIG_COMPAT)
16988 extern unsigned int vdso32_enabled;
16989 #endif
16990 @@ -248,7 +245,25 @@ extern int force_personality32;
16991 the loader. We need to make sure that it is out of the way of the program
16992 that it will "exec", and that there is sufficient room for the brk. */
16993
16994 +#ifdef CONFIG_PAX_SEGMEXEC
16995 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
16996 +#else
16997 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
16998 +#endif
16999 +
17000 +#ifdef CONFIG_PAX_ASLR
17001 +#ifdef CONFIG_X86_32
17002 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
17003 +
17004 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
17005 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
17006 +#else
17007 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
17008 +
17009 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
17010 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
17011 +#endif
17012 +#endif
17013
17014 /* This yields a mask that user programs can use to figure out what
17015 instruction set this CPU supports. This could be done in user space,
17016 @@ -297,17 +312,13 @@ do { \
17017
17018 #define ARCH_DLINFO \
17019 do { \
17020 - if (vdso64_enabled) \
17021 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
17022 - (unsigned long __force)current->mm->context.vdso); \
17023 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
17024 } while (0)
17025
17026 /* As a historical oddity, the x32 and x86_64 vDSOs are controlled together. */
17027 #define ARCH_DLINFO_X32 \
17028 do { \
17029 - if (vdso64_enabled) \
17030 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
17031 - (unsigned long __force)current->mm->context.vdso); \
17032 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
17033 } while (0)
17034
17035 #define AT_SYSINFO 32
17036 @@ -322,10 +333,10 @@ else \
17037
17038 #endif /* !CONFIG_X86_32 */
17039
17040 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
17041 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
17042
17043 #define VDSO_ENTRY \
17044 - ((unsigned long)current->mm->context.vdso + \
17045 + (current->mm->context.vdso + \
17046 selected_vdso32->sym___kernel_vsyscall)
17047
17048 struct linux_binprm;
17049 @@ -337,9 +348,6 @@ extern int compat_arch_setup_additional_pages(struct linux_binprm *bprm,
17050 int uses_interp);
17051 #define compat_arch_setup_additional_pages compat_arch_setup_additional_pages
17052
17053 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
17054 -#define arch_randomize_brk arch_randomize_brk
17055 -
17056 /*
17057 * True on X86_32 or when emulating IA32 on X86_64
17058 */
17059 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
17060 index 77a99ac..39ff7f5 100644
17061 --- a/arch/x86/include/asm/emergency-restart.h
17062 +++ b/arch/x86/include/asm/emergency-restart.h
17063 @@ -1,6 +1,6 @@
17064 #ifndef _ASM_X86_EMERGENCY_RESTART_H
17065 #define _ASM_X86_EMERGENCY_RESTART_H
17066
17067 -extern void machine_emergency_restart(void);
17068 +extern void machine_emergency_restart(void) __noreturn;
17069
17070 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
17071 diff --git a/arch/x86/include/asm/floppy.h b/arch/x86/include/asm/floppy.h
17072 index 1c7eefe..d0e4702 100644
17073 --- a/arch/x86/include/asm/floppy.h
17074 +++ b/arch/x86/include/asm/floppy.h
17075 @@ -229,18 +229,18 @@ static struct fd_routine_l {
17076 int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
17077 } fd_routine[] = {
17078 {
17079 - request_dma,
17080 - free_dma,
17081 - get_dma_residue,
17082 - dma_mem_alloc,
17083 - hard_dma_setup
17084 + ._request_dma = request_dma,
17085 + ._free_dma = free_dma,
17086 + ._get_dma_residue = get_dma_residue,
17087 + ._dma_mem_alloc = dma_mem_alloc,
17088 + ._dma_setup = hard_dma_setup
17089 },
17090 {
17091 - vdma_request_dma,
17092 - vdma_nop,
17093 - vdma_get_dma_residue,
17094 - vdma_mem_alloc,
17095 - vdma_dma_setup
17096 + ._request_dma = vdma_request_dma,
17097 + ._free_dma = vdma_nop,
17098 + ._get_dma_residue = vdma_get_dma_residue,
17099 + ._dma_mem_alloc = vdma_mem_alloc,
17100 + ._dma_setup = vdma_dma_setup
17101 }
17102 };
17103
17104 diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
17105 index 115e368..76ecf6c 100644
17106 --- a/arch/x86/include/asm/fpu-internal.h
17107 +++ b/arch/x86/include/asm/fpu-internal.h
17108 @@ -124,8 +124,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
17109 #define user_insn(insn, output, input...) \
17110 ({ \
17111 int err; \
17112 + pax_open_userland(); \
17113 asm volatile(ASM_STAC "\n" \
17114 - "1:" #insn "\n\t" \
17115 + "1:" \
17116 + __copyuser_seg \
17117 + #insn "\n\t" \
17118 "2: " ASM_CLAC "\n" \
17119 ".section .fixup,\"ax\"\n" \
17120 "3: movl $-1,%[err]\n" \
17121 @@ -134,6 +137,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
17122 _ASM_EXTABLE(1b, 3b) \
17123 : [err] "=r" (err), output \
17124 : "0"(0), input); \
17125 + pax_close_userland(); \
17126 err; \
17127 })
17128
17129 @@ -298,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
17130 "fnclex\n\t"
17131 "emms\n\t"
17132 "fildl %P[addr]" /* set F?P to defined value */
17133 - : : [addr] "m" (tsk->thread.fpu.has_fpu));
17134 + : : [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
17135 }
17136
17137 return fpu_restore_checking(&tsk->thread.fpu);
17138 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
17139 index b4c1f54..e290c08 100644
17140 --- a/arch/x86/include/asm/futex.h
17141 +++ b/arch/x86/include/asm/futex.h
17142 @@ -12,6 +12,7 @@
17143 #include <asm/smap.h>
17144
17145 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
17146 + typecheck(u32 __user *, uaddr); \
17147 asm volatile("\t" ASM_STAC "\n" \
17148 "1:\t" insn "\n" \
17149 "2:\t" ASM_CLAC "\n" \
17150 @@ -20,15 +21,16 @@
17151 "\tjmp\t2b\n" \
17152 "\t.previous\n" \
17153 _ASM_EXTABLE(1b, 3b) \
17154 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
17155 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
17156 : "i" (-EFAULT), "0" (oparg), "1" (0))
17157
17158 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
17159 + typecheck(u32 __user *, uaddr); \
17160 asm volatile("\t" ASM_STAC "\n" \
17161 "1:\tmovl %2, %0\n" \
17162 "\tmovl\t%0, %3\n" \
17163 "\t" insn "\n" \
17164 - "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
17165 + "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
17166 "\tjnz\t1b\n" \
17167 "3:\t" ASM_CLAC "\n" \
17168 "\t.section .fixup,\"ax\"\n" \
17169 @@ -38,7 +40,7 @@
17170 _ASM_EXTABLE(1b, 4b) \
17171 _ASM_EXTABLE(2b, 4b) \
17172 : "=&a" (oldval), "=&r" (ret), \
17173 - "+m" (*uaddr), "=&r" (tem) \
17174 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
17175 : "r" (oparg), "i" (-EFAULT), "1" (0))
17176
17177 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
17178 @@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
17179
17180 pagefault_disable();
17181
17182 + pax_open_userland();
17183 switch (op) {
17184 case FUTEX_OP_SET:
17185 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
17186 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
17187 break;
17188 case FUTEX_OP_ADD:
17189 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
17190 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
17191 uaddr, oparg);
17192 break;
17193 case FUTEX_OP_OR:
17194 @@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
17195 default:
17196 ret = -ENOSYS;
17197 }
17198 + pax_close_userland();
17199
17200 pagefault_enable();
17201
17202 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
17203 index 4615906..788c817 100644
17204 --- a/arch/x86/include/asm/hw_irq.h
17205 +++ b/arch/x86/include/asm/hw_irq.h
17206 @@ -164,8 +164,8 @@ extern void setup_ioapic_dest(void);
17207 extern void enable_IO_APIC(void);
17208
17209 /* Statistics */
17210 -extern atomic_t irq_err_count;
17211 -extern atomic_t irq_mis_count;
17212 +extern atomic_unchecked_t irq_err_count;
17213 +extern atomic_unchecked_t irq_mis_count;
17214
17215 /* EISA */
17216 extern void eisa_set_level_irq(unsigned int irq);
17217 diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
17218 index a203659..9889f1c 100644
17219 --- a/arch/x86/include/asm/i8259.h
17220 +++ b/arch/x86/include/asm/i8259.h
17221 @@ -62,7 +62,7 @@ struct legacy_pic {
17222 void (*init)(int auto_eoi);
17223 int (*irq_pending)(unsigned int irq);
17224 void (*make_irq)(unsigned int irq);
17225 -};
17226 +} __do_const;
17227
17228 extern struct legacy_pic *legacy_pic;
17229 extern struct legacy_pic null_legacy_pic;
17230 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
17231 index b8237d8..3e8864e 100644
17232 --- a/arch/x86/include/asm/io.h
17233 +++ b/arch/x86/include/asm/io.h
17234 @@ -52,12 +52,12 @@ static inline void name(type val, volatile void __iomem *addr) \
17235 "m" (*(volatile type __force *)addr) barrier); }
17236
17237 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
17238 -build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
17239 -build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
17240 +build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
17241 +build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
17242
17243 build_mmio_read(__readb, "b", unsigned char, "=q", )
17244 -build_mmio_read(__readw, "w", unsigned short, "=r", )
17245 -build_mmio_read(__readl, "l", unsigned int, "=r", )
17246 +build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
17247 +build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
17248
17249 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
17250 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
17251 @@ -109,7 +109,7 @@ build_mmio_write(writeq, "q", unsigned long, "r", :"memory")
17252 * this function
17253 */
17254
17255 -static inline phys_addr_t virt_to_phys(volatile void *address)
17256 +static inline phys_addr_t __intentional_overflow(-1) virt_to_phys(volatile void *address)
17257 {
17258 return __pa(address);
17259 }
17260 @@ -185,7 +185,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
17261 return ioremap_nocache(offset, size);
17262 }
17263
17264 -extern void iounmap(volatile void __iomem *addr);
17265 +extern void iounmap(const volatile void __iomem *addr);
17266
17267 extern void set_iounmap_nonlazy(void);
17268
17269 @@ -195,6 +195,17 @@ extern void set_iounmap_nonlazy(void);
17270
17271 #include <linux/vmalloc.h>
17272
17273 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
17274 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
17275 +{
17276 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
17277 +}
17278 +
17279 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
17280 +{
17281 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
17282 +}
17283 +
17284 /*
17285 * Convert a virtual cached pointer to an uncached pointer
17286 */
17287 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
17288 index 0a8b519..80e7d5b 100644
17289 --- a/arch/x86/include/asm/irqflags.h
17290 +++ b/arch/x86/include/asm/irqflags.h
17291 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
17292 sti; \
17293 sysexit
17294
17295 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
17296 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
17297 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
17298 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
17299 +
17300 #else
17301 #define INTERRUPT_RETURN iret
17302 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
17303 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
17304 index 53cdfb2..d1369e6 100644
17305 --- a/arch/x86/include/asm/kprobes.h
17306 +++ b/arch/x86/include/asm/kprobes.h
17307 @@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
17308 #define RELATIVEJUMP_SIZE 5
17309 #define RELATIVECALL_OPCODE 0xe8
17310 #define RELATIVE_ADDR_SIZE 4
17311 -#define MAX_STACK_SIZE 64
17312 -#define MIN_STACK_SIZE(ADDR) \
17313 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
17314 - THREAD_SIZE - (unsigned long)(ADDR))) \
17315 - ? (MAX_STACK_SIZE) \
17316 - : (((unsigned long)current_thread_info()) + \
17317 - THREAD_SIZE - (unsigned long)(ADDR)))
17318 +#define MAX_STACK_SIZE 64UL
17319 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
17320
17321 #define flush_insn_slot(p) do { } while (0)
17322
17323 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
17324 index 4ad6560..75c7bdd 100644
17325 --- a/arch/x86/include/asm/local.h
17326 +++ b/arch/x86/include/asm/local.h
17327 @@ -10,33 +10,97 @@ typedef struct {
17328 atomic_long_t a;
17329 } local_t;
17330
17331 +typedef struct {
17332 + atomic_long_unchecked_t a;
17333 +} local_unchecked_t;
17334 +
17335 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
17336
17337 #define local_read(l) atomic_long_read(&(l)->a)
17338 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
17339 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
17340 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
17341
17342 static inline void local_inc(local_t *l)
17343 {
17344 - asm volatile(_ASM_INC "%0"
17345 + asm volatile(_ASM_INC "%0\n"
17346 +
17347 +#ifdef CONFIG_PAX_REFCOUNT
17348 + "jno 0f\n"
17349 + _ASM_DEC "%0\n"
17350 + "int $4\n0:\n"
17351 + _ASM_EXTABLE(0b, 0b)
17352 +#endif
17353 +
17354 + : "+m" (l->a.counter));
17355 +}
17356 +
17357 +static inline void local_inc_unchecked(local_unchecked_t *l)
17358 +{
17359 + asm volatile(_ASM_INC "%0\n"
17360 : "+m" (l->a.counter));
17361 }
17362
17363 static inline void local_dec(local_t *l)
17364 {
17365 - asm volatile(_ASM_DEC "%0"
17366 + asm volatile(_ASM_DEC "%0\n"
17367 +
17368 +#ifdef CONFIG_PAX_REFCOUNT
17369 + "jno 0f\n"
17370 + _ASM_INC "%0\n"
17371 + "int $4\n0:\n"
17372 + _ASM_EXTABLE(0b, 0b)
17373 +#endif
17374 +
17375 + : "+m" (l->a.counter));
17376 +}
17377 +
17378 +static inline void local_dec_unchecked(local_unchecked_t *l)
17379 +{
17380 + asm volatile(_ASM_DEC "%0\n"
17381 : "+m" (l->a.counter));
17382 }
17383
17384 static inline void local_add(long i, local_t *l)
17385 {
17386 - asm volatile(_ASM_ADD "%1,%0"
17387 + asm volatile(_ASM_ADD "%1,%0\n"
17388 +
17389 +#ifdef CONFIG_PAX_REFCOUNT
17390 + "jno 0f\n"
17391 + _ASM_SUB "%1,%0\n"
17392 + "int $4\n0:\n"
17393 + _ASM_EXTABLE(0b, 0b)
17394 +#endif
17395 +
17396 + : "+m" (l->a.counter)
17397 + : "ir" (i));
17398 +}
17399 +
17400 +static inline void local_add_unchecked(long i, local_unchecked_t *l)
17401 +{
17402 + asm volatile(_ASM_ADD "%1,%0\n"
17403 : "+m" (l->a.counter)
17404 : "ir" (i));
17405 }
17406
17407 static inline void local_sub(long i, local_t *l)
17408 {
17409 - asm volatile(_ASM_SUB "%1,%0"
17410 + asm volatile(_ASM_SUB "%1,%0\n"
17411 +
17412 +#ifdef CONFIG_PAX_REFCOUNT
17413 + "jno 0f\n"
17414 + _ASM_ADD "%1,%0\n"
17415 + "int $4\n0:\n"
17416 + _ASM_EXTABLE(0b, 0b)
17417 +#endif
17418 +
17419 + : "+m" (l->a.counter)
17420 + : "ir" (i));
17421 +}
17422 +
17423 +static inline void local_sub_unchecked(long i, local_unchecked_t *l)
17424 +{
17425 + asm volatile(_ASM_SUB "%1,%0\n"
17426 : "+m" (l->a.counter)
17427 : "ir" (i));
17428 }
17429 @@ -52,7 +116,7 @@ static inline void local_sub(long i, local_t *l)
17430 */
17431 static inline int local_sub_and_test(long i, local_t *l)
17432 {
17433 - GEN_BINARY_RMWcc(_ASM_SUB, l->a.counter, "er", i, "%0", "e");
17434 + GEN_BINARY_RMWcc(_ASM_SUB, _ASM_ADD, l->a.counter, "er", i, "%0", "e");
17435 }
17436
17437 /**
17438 @@ -65,7 +129,7 @@ static inline int local_sub_and_test(long i, local_t *l)
17439 */
17440 static inline int local_dec_and_test(local_t *l)
17441 {
17442 - GEN_UNARY_RMWcc(_ASM_DEC, l->a.counter, "%0", "e");
17443 + GEN_UNARY_RMWcc(_ASM_DEC, _ASM_INC, l->a.counter, "%0", "e");
17444 }
17445
17446 /**
17447 @@ -78,7 +142,7 @@ static inline int local_dec_and_test(local_t *l)
17448 */
17449 static inline int local_inc_and_test(local_t *l)
17450 {
17451 - GEN_UNARY_RMWcc(_ASM_INC, l->a.counter, "%0", "e");
17452 + GEN_UNARY_RMWcc(_ASM_INC, _ASM_DEC, l->a.counter, "%0", "e");
17453 }
17454
17455 /**
17456 @@ -92,7 +156,7 @@ static inline int local_inc_and_test(local_t *l)
17457 */
17458 static inline int local_add_negative(long i, local_t *l)
17459 {
17460 - GEN_BINARY_RMWcc(_ASM_ADD, l->a.counter, "er", i, "%0", "s");
17461 + GEN_BINARY_RMWcc(_ASM_ADD, _ASM_SUB, l->a.counter, "er", i, "%0", "s");
17462 }
17463
17464 /**
17465 @@ -105,6 +169,30 @@ static inline int local_add_negative(long i, local_t *l)
17466 static inline long local_add_return(long i, local_t *l)
17467 {
17468 long __i = i;
17469 + asm volatile(_ASM_XADD "%0, %1\n"
17470 +
17471 +#ifdef CONFIG_PAX_REFCOUNT
17472 + "jno 0f\n"
17473 + _ASM_MOV "%0,%1\n"
17474 + "int $4\n0:\n"
17475 + _ASM_EXTABLE(0b, 0b)
17476 +#endif
17477 +
17478 + : "+r" (i), "+m" (l->a.counter)
17479 + : : "memory");
17480 + return i + __i;
17481 +}
17482 +
17483 +/**
17484 + * local_add_return_unchecked - add and return
17485 + * @i: integer value to add
17486 + * @l: pointer to type local_unchecked_t
17487 + *
17488 + * Atomically adds @i to @l and returns @i + @l
17489 + */
17490 +static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
17491 +{
17492 + long __i = i;
17493 asm volatile(_ASM_XADD "%0, %1;"
17494 : "+r" (i), "+m" (l->a.counter)
17495 : : "memory");
17496 @@ -121,6 +209,8 @@ static inline long local_sub_return(long i, local_t *l)
17497
17498 #define local_cmpxchg(l, o, n) \
17499 (cmpxchg_local(&((l)->a.counter), (o), (n)))
17500 +#define local_cmpxchg_unchecked(l, o, n) \
17501 + (cmpxchg_local(&((l)->a.counter), (o), (n)))
17502 /* Always has a lock prefix */
17503 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
17504
17505 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
17506 new file mode 100644
17507 index 0000000..2bfd3ba
17508 --- /dev/null
17509 +++ b/arch/x86/include/asm/mman.h
17510 @@ -0,0 +1,15 @@
17511 +#ifndef _X86_MMAN_H
17512 +#define _X86_MMAN_H
17513 +
17514 +#include <uapi/asm/mman.h>
17515 +
17516 +#ifdef __KERNEL__
17517 +#ifndef __ASSEMBLY__
17518 +#ifdef CONFIG_X86_32
17519 +#define arch_mmap_check i386_mmap_check
17520 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
17521 +#endif
17522 +#endif
17523 +#endif
17524 +
17525 +#endif /* X86_MMAN_H */
17526 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
17527 index 876e74e..e20bfb1 100644
17528 --- a/arch/x86/include/asm/mmu.h
17529 +++ b/arch/x86/include/asm/mmu.h
17530 @@ -9,7 +9,7 @@
17531 * we put the segment information here.
17532 */
17533 typedef struct {
17534 - void *ldt;
17535 + struct desc_struct *ldt;
17536 int size;
17537
17538 #ifdef CONFIG_X86_64
17539 @@ -18,7 +18,19 @@ typedef struct {
17540 #endif
17541
17542 struct mutex lock;
17543 - void __user *vdso;
17544 + unsigned long vdso;
17545 +
17546 +#ifdef CONFIG_X86_32
17547 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
17548 + unsigned long user_cs_base;
17549 + unsigned long user_cs_limit;
17550 +
17551 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17552 + cpumask_t cpu_user_cs_mask;
17553 +#endif
17554 +
17555 +#endif
17556 +#endif
17557 } mm_context_t;
17558
17559 #ifdef CONFIG_SMP
17560 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
17561 index be12c53..07fd3ca 100644
17562 --- a/arch/x86/include/asm/mmu_context.h
17563 +++ b/arch/x86/include/asm/mmu_context.h
17564 @@ -24,6 +24,20 @@ void destroy_context(struct mm_struct *mm);
17565
17566 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
17567 {
17568 +
17569 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17570 + if (!(static_cpu_has(X86_FEATURE_PCID))) {
17571 + unsigned int i;
17572 + pgd_t *pgd;
17573 +
17574 + pax_open_kernel();
17575 + pgd = get_cpu_pgd(smp_processor_id(), kernel);
17576 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
17577 + set_pgd_batched(pgd+i, native_make_pgd(0));
17578 + pax_close_kernel();
17579 + }
17580 +#endif
17581 +
17582 #ifdef CONFIG_SMP
17583 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
17584 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
17585 @@ -34,16 +48,59 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17586 struct task_struct *tsk)
17587 {
17588 unsigned cpu = smp_processor_id();
17589 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17590 + int tlbstate = TLBSTATE_OK;
17591 +#endif
17592
17593 if (likely(prev != next)) {
17594 #ifdef CONFIG_SMP
17595 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17596 + tlbstate = this_cpu_read(cpu_tlbstate.state);
17597 +#endif
17598 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17599 this_cpu_write(cpu_tlbstate.active_mm, next);
17600 #endif
17601 cpumask_set_cpu(cpu, mm_cpumask(next));
17602
17603 /* Re-load page tables */
17604 +#ifdef CONFIG_PAX_PER_CPU_PGD
17605 + pax_open_kernel();
17606 +
17607 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17608 + if (static_cpu_has(X86_FEATURE_PCID))
17609 + __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17610 + else
17611 +#endif
17612 +
17613 + __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17614 + __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17615 + pax_close_kernel();
17616 + 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));
17617 +
17618 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17619 + if (static_cpu_has(X86_FEATURE_PCID)) {
17620 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
17621 + u64 descriptor[2];
17622 + descriptor[0] = PCID_USER;
17623 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17624 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17625 + descriptor[0] = PCID_KERNEL;
17626 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17627 + }
17628 + } else {
17629 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17630 + if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17631 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17632 + else
17633 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17634 + }
17635 + } else
17636 +#endif
17637 +
17638 + load_cr3(get_cpu_pgd(cpu, kernel));
17639 +#else
17640 load_cr3(next->pgd);
17641 +#endif
17642
17643 /* Stop flush ipis for the previous mm */
17644 cpumask_clear_cpu(cpu, mm_cpumask(prev));
17645 @@ -51,9 +108,67 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17646 /* Load the LDT, if the LDT is different: */
17647 if (unlikely(prev->context.ldt != next->context.ldt))
17648 load_LDT_nolock(&next->context);
17649 +
17650 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17651 + if (!(__supported_pte_mask & _PAGE_NX)) {
17652 + smp_mb__before_atomic();
17653 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
17654 + smp_mb__after_atomic();
17655 + cpu_set(cpu, next->context.cpu_user_cs_mask);
17656 + }
17657 +#endif
17658 +
17659 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17660 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
17661 + prev->context.user_cs_limit != next->context.user_cs_limit))
17662 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17663 +#ifdef CONFIG_SMP
17664 + else if (unlikely(tlbstate != TLBSTATE_OK))
17665 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17666 +#endif
17667 +#endif
17668 +
17669 }
17670 + else {
17671 +
17672 +#ifdef CONFIG_PAX_PER_CPU_PGD
17673 + pax_open_kernel();
17674 +
17675 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17676 + if (static_cpu_has(X86_FEATURE_PCID))
17677 + __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17678 + else
17679 +#endif
17680 +
17681 + __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17682 + __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17683 + pax_close_kernel();
17684 + 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));
17685 +
17686 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17687 + if (static_cpu_has(X86_FEATURE_PCID)) {
17688 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
17689 + u64 descriptor[2];
17690 + descriptor[0] = PCID_USER;
17691 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17692 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17693 + descriptor[0] = PCID_KERNEL;
17694 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17695 + }
17696 + } else {
17697 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17698 + if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17699 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17700 + else
17701 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17702 + }
17703 + } else
17704 +#endif
17705 +
17706 + load_cr3(get_cpu_pgd(cpu, kernel));
17707 +#endif
17708 +
17709 #ifdef CONFIG_SMP
17710 - else {
17711 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17712 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
17713
17714 @@ -70,11 +185,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17715 * tlb flush IPI delivery. We must reload CR3
17716 * to make sure to use no freed page tables.
17717 */
17718 +
17719 +#ifndef CONFIG_PAX_PER_CPU_PGD
17720 load_cr3(next->pgd);
17721 +#endif
17722 +
17723 load_LDT_nolock(&next->context);
17724 +
17725 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
17726 + if (!(__supported_pte_mask & _PAGE_NX))
17727 + cpu_set(cpu, next->context.cpu_user_cs_mask);
17728 +#endif
17729 +
17730 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17731 +#ifdef CONFIG_PAX_PAGEEXEC
17732 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
17733 +#endif
17734 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17735 +#endif
17736 +
17737 }
17738 +#endif
17739 }
17740 -#endif
17741 }
17742
17743 #define activate_mm(prev, next) \
17744 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
17745 index e3b7819..b257c64 100644
17746 --- a/arch/x86/include/asm/module.h
17747 +++ b/arch/x86/include/asm/module.h
17748 @@ -5,6 +5,7 @@
17749
17750 #ifdef CONFIG_X86_64
17751 /* X86_64 does not define MODULE_PROC_FAMILY */
17752 +#define MODULE_PROC_FAMILY ""
17753 #elif defined CONFIG_M486
17754 #define MODULE_PROC_FAMILY "486 "
17755 #elif defined CONFIG_M586
17756 @@ -57,8 +58,20 @@
17757 #error unknown processor family
17758 #endif
17759
17760 -#ifdef CONFIG_X86_32
17761 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
17762 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
17763 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
17764 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
17765 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
17766 +#else
17767 +#define MODULE_PAX_KERNEXEC ""
17768 #endif
17769
17770 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17771 +#define MODULE_PAX_UDEREF "UDEREF "
17772 +#else
17773 +#define MODULE_PAX_UDEREF ""
17774 +#endif
17775 +
17776 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
17777 +
17778 #endif /* _ASM_X86_MODULE_H */
17779 diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
17780 index 5f2fc44..106caa6 100644
17781 --- a/arch/x86/include/asm/nmi.h
17782 +++ b/arch/x86/include/asm/nmi.h
17783 @@ -36,26 +36,35 @@ enum {
17784
17785 typedef int (*nmi_handler_t)(unsigned int, struct pt_regs *);
17786
17787 +struct nmiaction;
17788 +
17789 +struct nmiwork {
17790 + const struct nmiaction *action;
17791 + u64 max_duration;
17792 + struct irq_work irq_work;
17793 +};
17794 +
17795 struct nmiaction {
17796 struct list_head list;
17797 nmi_handler_t handler;
17798 - u64 max_duration;
17799 - struct irq_work irq_work;
17800 unsigned long flags;
17801 const char *name;
17802 -};
17803 + struct nmiwork *work;
17804 +} __do_const;
17805
17806 #define register_nmi_handler(t, fn, fg, n, init...) \
17807 ({ \
17808 - static struct nmiaction init fn##_na = { \
17809 + static struct nmiwork fn##_nw; \
17810 + static const struct nmiaction init fn##_na = { \
17811 .handler = (fn), \
17812 .name = (n), \
17813 .flags = (fg), \
17814 + .work = &fn##_nw, \
17815 }; \
17816 __register_nmi_handler((t), &fn##_na); \
17817 })
17818
17819 -int __register_nmi_handler(unsigned int, struct nmiaction *);
17820 +int __register_nmi_handler(unsigned int, const struct nmiaction *);
17821
17822 void unregister_nmi_handler(unsigned int, const char *);
17823
17824 diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
17825 index 775873d..04cd306 100644
17826 --- a/arch/x86/include/asm/page.h
17827 +++ b/arch/x86/include/asm/page.h
17828 @@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
17829 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
17830
17831 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
17832 +#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
17833
17834 #define __boot_va(x) __va(x)
17835 #define __boot_pa(x) __pa(x)
17836 @@ -60,11 +61,21 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
17837 * virt_to_page(kaddr) returns a valid pointer if and only if
17838 * virt_addr_valid(kaddr) returns true.
17839 */
17840 -#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
17841 #define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT)
17842 extern bool __virt_addr_valid(unsigned long kaddr);
17843 #define virt_addr_valid(kaddr) __virt_addr_valid((unsigned long) (kaddr))
17844
17845 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
17846 +#define virt_to_page(kaddr) \
17847 + ({ \
17848 + const void *__kaddr = (const void *)(kaddr); \
17849 + BUG_ON(!virt_addr_valid(__kaddr)); \
17850 + pfn_to_page(__pa(__kaddr) >> PAGE_SHIFT); \
17851 + })
17852 +#else
17853 +#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
17854 +#endif
17855 +
17856 #endif /* __ASSEMBLY__ */
17857
17858 #include <asm-generic/memory_model.h>
17859 diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
17860 index 0f1ddee..e2fc3d1 100644
17861 --- a/arch/x86/include/asm/page_64.h
17862 +++ b/arch/x86/include/asm/page_64.h
17863 @@ -7,9 +7,9 @@
17864
17865 /* duplicated to the one in bootmem.h */
17866 extern unsigned long max_pfn;
17867 -extern unsigned long phys_base;
17868 +extern const unsigned long phys_base;
17869
17870 -static inline unsigned long __phys_addr_nodebug(unsigned long x)
17871 +static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
17872 {
17873 unsigned long y = x - __START_KERNEL_map;
17874
17875 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
17876 index cd6e1610..70f4418 100644
17877 --- a/arch/x86/include/asm/paravirt.h
17878 +++ b/arch/x86/include/asm/paravirt.h
17879 @@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
17880 return (pmd_t) { ret };
17881 }
17882
17883 -static inline pmdval_t pmd_val(pmd_t pmd)
17884 +static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
17885 {
17886 pmdval_t ret;
17887
17888 @@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
17889 val);
17890 }
17891
17892 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
17893 +{
17894 + pgdval_t val = native_pgd_val(pgd);
17895 +
17896 + if (sizeof(pgdval_t) > sizeof(long))
17897 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
17898 + val, (u64)val >> 32);
17899 + else
17900 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
17901 + val);
17902 +}
17903 +
17904 static inline void pgd_clear(pgd_t *pgdp)
17905 {
17906 set_pgd(pgdp, __pgd(0));
17907 @@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
17908 pv_mmu_ops.set_fixmap(idx, phys, flags);
17909 }
17910
17911 +#ifdef CONFIG_PAX_KERNEXEC
17912 +static inline unsigned long pax_open_kernel(void)
17913 +{
17914 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
17915 +}
17916 +
17917 +static inline unsigned long pax_close_kernel(void)
17918 +{
17919 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
17920 +}
17921 +#else
17922 +static inline unsigned long pax_open_kernel(void) { return 0; }
17923 +static inline unsigned long pax_close_kernel(void) { return 0; }
17924 +#endif
17925 +
17926 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
17927
17928 static __always_inline void __ticket_lock_spinning(struct arch_spinlock *lock,
17929 @@ -906,7 +933,7 @@ extern void default_banner(void);
17930
17931 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
17932 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
17933 -#define PARA_INDIRECT(addr) *%cs:addr
17934 +#define PARA_INDIRECT(addr) *%ss:addr
17935 #endif
17936
17937 #define INTERRUPT_RETURN \
17938 @@ -981,6 +1008,21 @@ extern void default_banner(void);
17939 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
17940 CLBR_NONE, \
17941 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
17942 +
17943 +#define GET_CR0_INTO_RDI \
17944 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
17945 + mov %rax,%rdi
17946 +
17947 +#define SET_RDI_INTO_CR0 \
17948 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
17949 +
17950 +#define GET_CR3_INTO_RDI \
17951 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
17952 + mov %rax,%rdi
17953 +
17954 +#define SET_RDI_INTO_CR3 \
17955 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
17956 +
17957 #endif /* CONFIG_X86_32 */
17958
17959 #endif /* __ASSEMBLY__ */
17960 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
17961 index 7549b8b..f0edfda 100644
17962 --- a/arch/x86/include/asm/paravirt_types.h
17963 +++ b/arch/x86/include/asm/paravirt_types.h
17964 @@ -84,7 +84,7 @@ struct pv_init_ops {
17965 */
17966 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
17967 unsigned long addr, unsigned len);
17968 -};
17969 +} __no_const __no_randomize_layout;
17970
17971
17972 struct pv_lazy_ops {
17973 @@ -92,13 +92,13 @@ struct pv_lazy_ops {
17974 void (*enter)(void);
17975 void (*leave)(void);
17976 void (*flush)(void);
17977 -};
17978 +} __no_randomize_layout;
17979
17980 struct pv_time_ops {
17981 unsigned long long (*sched_clock)(void);
17982 unsigned long long (*steal_clock)(int cpu);
17983 unsigned long (*get_tsc_khz)(void);
17984 -};
17985 +} __no_const __no_randomize_layout;
17986
17987 struct pv_cpu_ops {
17988 /* hooks for various privileged instructions */
17989 @@ -192,7 +192,7 @@ struct pv_cpu_ops {
17990
17991 void (*start_context_switch)(struct task_struct *prev);
17992 void (*end_context_switch)(struct task_struct *next);
17993 -};
17994 +} __no_const __no_randomize_layout;
17995
17996 struct pv_irq_ops {
17997 /*
17998 @@ -215,7 +215,7 @@ struct pv_irq_ops {
17999 #ifdef CONFIG_X86_64
18000 void (*adjust_exception_frame)(void);
18001 #endif
18002 -};
18003 +} __no_randomize_layout;
18004
18005 struct pv_apic_ops {
18006 #ifdef CONFIG_X86_LOCAL_APIC
18007 @@ -223,7 +223,7 @@ struct pv_apic_ops {
18008 unsigned long start_eip,
18009 unsigned long start_esp);
18010 #endif
18011 -};
18012 +} __no_const __no_randomize_layout;
18013
18014 struct pv_mmu_ops {
18015 unsigned long (*read_cr2)(void);
18016 @@ -313,6 +313,7 @@ struct pv_mmu_ops {
18017 struct paravirt_callee_save make_pud;
18018
18019 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
18020 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
18021 #endif /* PAGETABLE_LEVELS == 4 */
18022 #endif /* PAGETABLE_LEVELS >= 3 */
18023
18024 @@ -324,7 +325,13 @@ struct pv_mmu_ops {
18025 an mfn. We can tell which is which from the index. */
18026 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
18027 phys_addr_t phys, pgprot_t flags);
18028 -};
18029 +
18030 +#ifdef CONFIG_PAX_KERNEXEC
18031 + unsigned long (*pax_open_kernel)(void);
18032 + unsigned long (*pax_close_kernel)(void);
18033 +#endif
18034 +
18035 +} __no_randomize_layout;
18036
18037 struct arch_spinlock;
18038 #ifdef CONFIG_SMP
18039 @@ -336,11 +343,14 @@ typedef u16 __ticket_t;
18040 struct pv_lock_ops {
18041 struct paravirt_callee_save lock_spinning;
18042 void (*unlock_kick)(struct arch_spinlock *lock, __ticket_t ticket);
18043 -};
18044 +} __no_randomize_layout;
18045
18046 /* This contains all the paravirt structures: we get a convenient
18047 * number for each function using the offset which we use to indicate
18048 - * what to patch. */
18049 + * what to patch.
18050 + * shouldn't be randomized due to the "NEAT TRICK" in paravirt.c
18051 + */
18052 +
18053 struct paravirt_patch_template {
18054 struct pv_init_ops pv_init_ops;
18055 struct pv_time_ops pv_time_ops;
18056 @@ -349,7 +359,7 @@ struct paravirt_patch_template {
18057 struct pv_apic_ops pv_apic_ops;
18058 struct pv_mmu_ops pv_mmu_ops;
18059 struct pv_lock_ops pv_lock_ops;
18060 -};
18061 +} __no_randomize_layout;
18062
18063 extern struct pv_info pv_info;
18064 extern struct pv_init_ops pv_init_ops;
18065 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
18066 index c4412e9..90e88c5 100644
18067 --- a/arch/x86/include/asm/pgalloc.h
18068 +++ b/arch/x86/include/asm/pgalloc.h
18069 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
18070 pmd_t *pmd, pte_t *pte)
18071 {
18072 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
18073 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
18074 +}
18075 +
18076 +static inline void pmd_populate_user(struct mm_struct *mm,
18077 + pmd_t *pmd, pte_t *pte)
18078 +{
18079 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
18080 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
18081 }
18082
18083 @@ -108,12 +115,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
18084
18085 #ifdef CONFIG_X86_PAE
18086 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
18087 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
18088 +{
18089 + pud_populate(mm, pudp, pmd);
18090 +}
18091 #else /* !CONFIG_X86_PAE */
18092 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
18093 {
18094 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
18095 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
18096 }
18097 +
18098 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
18099 +{
18100 + paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
18101 + set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
18102 +}
18103 #endif /* CONFIG_X86_PAE */
18104
18105 #if PAGETABLE_LEVELS > 3
18106 @@ -123,6 +140,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
18107 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
18108 }
18109
18110 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
18111 +{
18112 + paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
18113 + set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
18114 +}
18115 +
18116 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
18117 {
18118 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
18119 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
18120 index 206a87f..1623b06 100644
18121 --- a/arch/x86/include/asm/pgtable-2level.h
18122 +++ b/arch/x86/include/asm/pgtable-2level.h
18123 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
18124
18125 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
18126 {
18127 + pax_open_kernel();
18128 *pmdp = pmd;
18129 + pax_close_kernel();
18130 }
18131
18132 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
18133 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
18134 index 81bb91b..9392125 100644
18135 --- a/arch/x86/include/asm/pgtable-3level.h
18136 +++ b/arch/x86/include/asm/pgtable-3level.h
18137 @@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
18138
18139 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
18140 {
18141 + pax_open_kernel();
18142 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
18143 + pax_close_kernel();
18144 }
18145
18146 static inline void native_set_pud(pud_t *pudp, pud_t pud)
18147 {
18148 + pax_open_kernel();
18149 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
18150 + pax_close_kernel();
18151 }
18152
18153 /*
18154 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
18155 index 0ec0560..f169e5b 100644
18156 --- a/arch/x86/include/asm/pgtable.h
18157 +++ b/arch/x86/include/asm/pgtable.h
18158 @@ -46,6 +46,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
18159
18160 #ifndef __PAGETABLE_PUD_FOLDED
18161 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
18162 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
18163 #define pgd_clear(pgd) native_pgd_clear(pgd)
18164 #endif
18165
18166 @@ -83,12 +84,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
18167
18168 #define arch_end_context_switch(prev) do {} while(0)
18169
18170 +#define pax_open_kernel() native_pax_open_kernel()
18171 +#define pax_close_kernel() native_pax_close_kernel()
18172 #endif /* CONFIG_PARAVIRT */
18173
18174 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
18175 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
18176 +
18177 +#ifdef CONFIG_PAX_KERNEXEC
18178 +static inline unsigned long native_pax_open_kernel(void)
18179 +{
18180 + unsigned long cr0;
18181 +
18182 + preempt_disable();
18183 + barrier();
18184 + cr0 = read_cr0() ^ X86_CR0_WP;
18185 + BUG_ON(cr0 & X86_CR0_WP);
18186 + write_cr0(cr0);
18187 + return cr0 ^ X86_CR0_WP;
18188 +}
18189 +
18190 +static inline unsigned long native_pax_close_kernel(void)
18191 +{
18192 + unsigned long cr0;
18193 +
18194 + cr0 = read_cr0() ^ X86_CR0_WP;
18195 + BUG_ON(!(cr0 & X86_CR0_WP));
18196 + write_cr0(cr0);
18197 + barrier();
18198 + preempt_enable_no_resched();
18199 + return cr0 ^ X86_CR0_WP;
18200 +}
18201 +#else
18202 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
18203 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
18204 +#endif
18205 +
18206 /*
18207 * The following only work if pte_present() is true.
18208 * Undefined behaviour if not..
18209 */
18210 +static inline int pte_user(pte_t pte)
18211 +{
18212 + return pte_val(pte) & _PAGE_USER;
18213 +}
18214 +
18215 static inline int pte_dirty(pte_t pte)
18216 {
18217 return pte_flags(pte) & _PAGE_DIRTY;
18218 @@ -131,8 +171,13 @@ static inline int pte_exec(pte_t pte)
18219
18220 static inline int pte_special(pte_t pte)
18221 {
18222 - return (pte_flags(pte) & (_PAGE_PRESENT|_PAGE_SPECIAL)) ==
18223 - (_PAGE_PRESENT|_PAGE_SPECIAL);
18224 + /*
18225 + * See CONFIG_NUMA_BALANCING pte_numa in include/asm-generic/pgtable.h.
18226 + * On x86 we have _PAGE_BIT_NUMA == _PAGE_BIT_GLOBAL+1 ==
18227 + * __PAGE_BIT_SOFTW1 == _PAGE_BIT_SPECIAL.
18228 + */
18229 + return (pte_flags(pte) & _PAGE_SPECIAL) &&
18230 + (pte_flags(pte) & (_PAGE_PRESENT|_PAGE_PROTNONE));
18231 }
18232
18233 static inline unsigned long pte_pfn(pte_t pte)
18234 @@ -150,6 +195,11 @@ static inline unsigned long pud_pfn(pud_t pud)
18235 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
18236 }
18237
18238 +static inline unsigned long pgd_pfn(pgd_t pgd)
18239 +{
18240 + return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
18241 +}
18242 +
18243 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
18244
18245 static inline int pmd_large(pmd_t pte)
18246 @@ -203,9 +253,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
18247 return pte_clear_flags(pte, _PAGE_RW);
18248 }
18249
18250 +static inline pte_t pte_mkread(pte_t pte)
18251 +{
18252 + return __pte(pte_val(pte) | _PAGE_USER);
18253 +}
18254 +
18255 static inline pte_t pte_mkexec(pte_t pte)
18256 {
18257 - return pte_clear_flags(pte, _PAGE_NX);
18258 +#ifdef CONFIG_X86_PAE
18259 + if (__supported_pte_mask & _PAGE_NX)
18260 + return pte_clear_flags(pte, _PAGE_NX);
18261 + else
18262 +#endif
18263 + return pte_set_flags(pte, _PAGE_USER);
18264 +}
18265 +
18266 +static inline pte_t pte_exprotect(pte_t pte)
18267 +{
18268 +#ifdef CONFIG_X86_PAE
18269 + if (__supported_pte_mask & _PAGE_NX)
18270 + return pte_set_flags(pte, _PAGE_NX);
18271 + else
18272 +#endif
18273 + return pte_clear_flags(pte, _PAGE_USER);
18274 }
18275
18276 static inline pte_t pte_mkdirty(pte_t pte)
18277 @@ -435,6 +505,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
18278 #endif
18279
18280 #ifndef __ASSEMBLY__
18281 +
18282 +#ifdef CONFIG_PAX_PER_CPU_PGD
18283 +extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
18284 +enum cpu_pgd_type {kernel = 0, user = 1};
18285 +static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
18286 +{
18287 + return cpu_pgd[cpu][type];
18288 +}
18289 +#endif
18290 +
18291 #include <linux/mm_types.h>
18292 #include <linux/mmdebug.h>
18293 #include <linux/log2.h>
18294 @@ -581,7 +661,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
18295 * Currently stuck as a macro due to indirect forward reference to
18296 * linux/mmzone.h's __section_mem_map_addr() definition:
18297 */
18298 -#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
18299 +#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
18300
18301 /* Find an entry in the second-level page table.. */
18302 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
18303 @@ -621,7 +701,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
18304 * Currently stuck as a macro due to indirect forward reference to
18305 * linux/mmzone.h's __section_mem_map_addr() definition:
18306 */
18307 -#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
18308 +#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
18309
18310 /* to find an entry in a page-table-directory. */
18311 static inline unsigned long pud_index(unsigned long address)
18312 @@ -636,7 +716,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
18313
18314 static inline int pgd_bad(pgd_t pgd)
18315 {
18316 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
18317 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
18318 }
18319
18320 static inline int pgd_none(pgd_t pgd)
18321 @@ -659,7 +739,12 @@ static inline int pgd_none(pgd_t pgd)
18322 * pgd_offset() returns a (pgd_t *)
18323 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
18324 */
18325 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
18326 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
18327 +
18328 +#ifdef CONFIG_PAX_PER_CPU_PGD
18329 +#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
18330 +#endif
18331 +
18332 /*
18333 * a shortcut which implies the use of the kernel's pgd, instead
18334 * of a process's
18335 @@ -670,6 +755,23 @@ static inline int pgd_none(pgd_t pgd)
18336 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
18337 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
18338
18339 +#ifdef CONFIG_X86_32
18340 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
18341 +#else
18342 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
18343 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
18344 +
18345 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18346 +#ifdef __ASSEMBLY__
18347 +#define pax_user_shadow_base pax_user_shadow_base(%rip)
18348 +#else
18349 +extern unsigned long pax_user_shadow_base;
18350 +extern pgdval_t clone_pgd_mask;
18351 +#endif
18352 +#endif
18353 +
18354 +#endif
18355 +
18356 #ifndef __ASSEMBLY__
18357
18358 extern int direct_gbpages;
18359 @@ -836,11 +938,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
18360 * dst and src can be on the same page, but the range must not overlap,
18361 * and must not cross a page boundary.
18362 */
18363 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
18364 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
18365 {
18366 - memcpy(dst, src, count * sizeof(pgd_t));
18367 + pax_open_kernel();
18368 + while (count--)
18369 + *dst++ = *src++;
18370 + pax_close_kernel();
18371 }
18372
18373 +#ifdef CONFIG_PAX_PER_CPU_PGD
18374 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
18375 +#endif
18376 +
18377 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18378 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
18379 +#else
18380 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
18381 +#endif
18382 +
18383 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
18384 static inline int page_level_shift(enum pg_level level)
18385 {
18386 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
18387 index 9ee3221..b979c6b 100644
18388 --- a/arch/x86/include/asm/pgtable_32.h
18389 +++ b/arch/x86/include/asm/pgtable_32.h
18390 @@ -25,9 +25,6 @@
18391 struct mm_struct;
18392 struct vm_area_struct;
18393
18394 -extern pgd_t swapper_pg_dir[1024];
18395 -extern pgd_t initial_page_table[1024];
18396 -
18397 static inline void pgtable_cache_init(void) { }
18398 static inline void check_pgt_cache(void) { }
18399 void paging_init(void);
18400 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
18401 # include <asm/pgtable-2level.h>
18402 #endif
18403
18404 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
18405 +extern pgd_t initial_page_table[PTRS_PER_PGD];
18406 +#ifdef CONFIG_X86_PAE
18407 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
18408 +#endif
18409 +
18410 #if defined(CONFIG_HIGHPTE)
18411 #define pte_offset_map(dir, address) \
18412 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
18413 @@ -62,12 +65,17 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
18414 /* Clear a kernel PTE and flush it from the TLB */
18415 #define kpte_clear_flush(ptep, vaddr) \
18416 do { \
18417 + pax_open_kernel(); \
18418 pte_clear(&init_mm, (vaddr), (ptep)); \
18419 + pax_close_kernel(); \
18420 __flush_tlb_one((vaddr)); \
18421 } while (0)
18422
18423 #endif /* !__ASSEMBLY__ */
18424
18425 +#define HAVE_ARCH_UNMAPPED_AREA
18426 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
18427 +
18428 /*
18429 * kern_addr_valid() is (1) for FLATMEM and (0) for
18430 * SPARSEMEM and DISCONTIGMEM
18431 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
18432 index ed5903b..c7fe163 100644
18433 --- a/arch/x86/include/asm/pgtable_32_types.h
18434 +++ b/arch/x86/include/asm/pgtable_32_types.h
18435 @@ -8,7 +8,7 @@
18436 */
18437 #ifdef CONFIG_X86_PAE
18438 # include <asm/pgtable-3level_types.h>
18439 -# define PMD_SIZE (1UL << PMD_SHIFT)
18440 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
18441 # define PMD_MASK (~(PMD_SIZE - 1))
18442 #else
18443 # include <asm/pgtable-2level_types.h>
18444 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
18445 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
18446 #endif
18447
18448 +#ifdef CONFIG_PAX_KERNEXEC
18449 +#ifndef __ASSEMBLY__
18450 +extern unsigned char MODULES_EXEC_VADDR[];
18451 +extern unsigned char MODULES_EXEC_END[];
18452 +#endif
18453 +#include <asm/boot.h>
18454 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
18455 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
18456 +#else
18457 +#define ktla_ktva(addr) (addr)
18458 +#define ktva_ktla(addr) (addr)
18459 +#endif
18460 +
18461 #define MODULES_VADDR VMALLOC_START
18462 #define MODULES_END VMALLOC_END
18463 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
18464 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
18465 index 5be9063..d62185b 100644
18466 --- a/arch/x86/include/asm/pgtable_64.h
18467 +++ b/arch/x86/include/asm/pgtable_64.h
18468 @@ -16,10 +16,14 @@
18469
18470 extern pud_t level3_kernel_pgt[512];
18471 extern pud_t level3_ident_pgt[512];
18472 +extern pud_t level3_vmalloc_start_pgt[512];
18473 +extern pud_t level3_vmalloc_end_pgt[512];
18474 +extern pud_t level3_vmemmap_pgt[512];
18475 +extern pud_t level2_vmemmap_pgt[512];
18476 extern pmd_t level2_kernel_pgt[512];
18477 extern pmd_t level2_fixmap_pgt[512];
18478 -extern pmd_t level2_ident_pgt[512];
18479 -extern pgd_t init_level4_pgt[];
18480 +extern pmd_t level2_ident_pgt[512*2];
18481 +extern pgd_t init_level4_pgt[512];
18482
18483 #define swapper_pg_dir init_level4_pgt
18484
18485 @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
18486
18487 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
18488 {
18489 + pax_open_kernel();
18490 *pmdp = pmd;
18491 + pax_close_kernel();
18492 }
18493
18494 static inline void native_pmd_clear(pmd_t *pmd)
18495 @@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
18496
18497 static inline void native_set_pud(pud_t *pudp, pud_t pud)
18498 {
18499 + pax_open_kernel();
18500 *pudp = pud;
18501 + pax_close_kernel();
18502 }
18503
18504 static inline void native_pud_clear(pud_t *pud)
18505 @@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
18506
18507 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
18508 {
18509 + pax_open_kernel();
18510 + *pgdp = pgd;
18511 + pax_close_kernel();
18512 +}
18513 +
18514 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
18515 +{
18516 *pgdp = pgd;
18517 }
18518
18519 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
18520 index 7166e25..baaa6fe 100644
18521 --- a/arch/x86/include/asm/pgtable_64_types.h
18522 +++ b/arch/x86/include/asm/pgtable_64_types.h
18523 @@ -61,9 +61,14 @@ typedef struct { pteval_t pte; } pte_t;
18524 #define MODULES_VADDR (__START_KERNEL_map + KERNEL_IMAGE_SIZE)
18525 #define MODULES_END _AC(0xffffffffff000000, UL)
18526 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
18527 +#define MODULES_EXEC_VADDR MODULES_VADDR
18528 +#define MODULES_EXEC_END MODULES_END
18529 #define ESPFIX_PGD_ENTRY _AC(-2, UL)
18530 #define ESPFIX_BASE_ADDR (ESPFIX_PGD_ENTRY << PGDIR_SHIFT)
18531
18532 +#define ktla_ktva(addr) (addr)
18533 +#define ktva_ktla(addr) (addr)
18534 +
18535 #define EARLY_DYNAMIC_PAGE_TABLES 64
18536
18537 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
18538 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
18539 index f216963..6bd7c21 100644
18540 --- a/arch/x86/include/asm/pgtable_types.h
18541 +++ b/arch/x86/include/asm/pgtable_types.h
18542 @@ -111,8 +111,10 @@
18543
18544 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
18545 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
18546 -#else
18547 +#elif defined(CONFIG_KMEMCHECK) || defined(CONFIG_MEM_SOFT_DIRTY)
18548 #define _PAGE_NX (_AT(pteval_t, 0))
18549 +#else
18550 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
18551 #endif
18552
18553 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
18554 @@ -151,6 +153,9 @@
18555 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
18556 _PAGE_ACCESSED)
18557
18558 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
18559 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
18560 +
18561 #define __PAGE_KERNEL_EXEC \
18562 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
18563 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
18564 @@ -161,7 +166,7 @@
18565 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
18566 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
18567 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
18568 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
18569 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
18570 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
18571 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
18572 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
18573 @@ -218,7 +223,7 @@
18574 #ifdef CONFIG_X86_64
18575 #define __PAGE_KERNEL_IDENT_LARGE_EXEC __PAGE_KERNEL_LARGE_EXEC
18576 #else
18577 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
18578 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
18579 #define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
18580 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
18581 #endif
18582 @@ -257,7 +262,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
18583 {
18584 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
18585 }
18586 +#endif
18587
18588 +#if PAGETABLE_LEVELS == 3
18589 +#include <asm-generic/pgtable-nopud.h>
18590 +#endif
18591 +
18592 +#if PAGETABLE_LEVELS == 2
18593 +#include <asm-generic/pgtable-nopmd.h>
18594 +#endif
18595 +
18596 +#ifndef __ASSEMBLY__
18597 #if PAGETABLE_LEVELS > 3
18598 typedef struct { pudval_t pud; } pud_t;
18599
18600 @@ -271,8 +286,6 @@ static inline pudval_t native_pud_val(pud_t pud)
18601 return pud.pud;
18602 }
18603 #else
18604 -#include <asm-generic/pgtable-nopud.h>
18605 -
18606 static inline pudval_t native_pud_val(pud_t pud)
18607 {
18608 return native_pgd_val(pud.pgd);
18609 @@ -292,8 +305,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
18610 return pmd.pmd;
18611 }
18612 #else
18613 -#include <asm-generic/pgtable-nopmd.h>
18614 -
18615 static inline pmdval_t native_pmd_val(pmd_t pmd)
18616 {
18617 return native_pgd_val(pmd.pud.pgd);
18618 @@ -333,7 +344,6 @@ typedef struct page *pgtable_t;
18619
18620 extern pteval_t __supported_pte_mask;
18621 extern void set_nx(void);
18622 -extern int nx_enabled;
18623
18624 #define pgprot_writecombine pgprot_writecombine
18625 extern pgprot_t pgprot_writecombine(pgprot_t prot);
18626 diff --git a/arch/x86/include/asm/preempt.h b/arch/x86/include/asm/preempt.h
18627 index 7024c12..71c46b9 100644
18628 --- a/arch/x86/include/asm/preempt.h
18629 +++ b/arch/x86/include/asm/preempt.h
18630 @@ -87,7 +87,7 @@ static __always_inline void __preempt_count_sub(int val)
18631 */
18632 static __always_inline bool __preempt_count_dec_and_test(void)
18633 {
18634 - GEN_UNARY_RMWcc("decl", __preempt_count, __percpu_arg(0), "e");
18635 + GEN_UNARY_RMWcc("decl", "incl", __preempt_count, __percpu_arg(0), "e");
18636 }
18637
18638 /*
18639 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
18640 index a4ea023..33aa874 100644
18641 --- a/arch/x86/include/asm/processor.h
18642 +++ b/arch/x86/include/asm/processor.h
18643 @@ -128,7 +128,7 @@ struct cpuinfo_x86 {
18644 /* Index into per_cpu list: */
18645 u16 cpu_index;
18646 u32 microcode;
18647 -} __attribute__((__aligned__(SMP_CACHE_BYTES)));
18648 +} __attribute__((__aligned__(SMP_CACHE_BYTES))) __randomize_layout;
18649
18650 #define X86_VENDOR_INTEL 0
18651 #define X86_VENDOR_CYRIX 1
18652 @@ -199,9 +199,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
18653 : "memory");
18654 }
18655
18656 +/* invpcid (%rdx),%rax */
18657 +#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
18658 +
18659 +#define INVPCID_SINGLE_ADDRESS 0UL
18660 +#define INVPCID_SINGLE_CONTEXT 1UL
18661 +#define INVPCID_ALL_GLOBAL 2UL
18662 +#define INVPCID_ALL_MONGLOBAL 3UL
18663 +
18664 +#define PCID_KERNEL 0UL
18665 +#define PCID_USER 1UL
18666 +#define PCID_NOFLUSH (1UL << 63)
18667 +
18668 static inline void load_cr3(pgd_t *pgdir)
18669 {
18670 - write_cr3(__pa(pgdir));
18671 + write_cr3(__pa(pgdir) | PCID_KERNEL);
18672 }
18673
18674 #ifdef CONFIG_X86_32
18675 @@ -283,7 +295,7 @@ struct tss_struct {
18676
18677 } ____cacheline_aligned;
18678
18679 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
18680 +extern struct tss_struct init_tss[NR_CPUS];
18681
18682 /*
18683 * Save the original ist values for checking stack pointers during debugging
18684 @@ -479,6 +491,7 @@ struct thread_struct {
18685 unsigned short ds;
18686 unsigned short fsindex;
18687 unsigned short gsindex;
18688 + unsigned short ss;
18689 #endif
18690 #ifdef CONFIG_X86_32
18691 unsigned long ip;
18692 @@ -588,29 +601,8 @@ static inline void load_sp0(struct tss_struct *tss,
18693 extern unsigned long mmu_cr4_features;
18694 extern u32 *trampoline_cr4_features;
18695
18696 -static inline void set_in_cr4(unsigned long mask)
18697 -{
18698 - unsigned long cr4;
18699 -
18700 - mmu_cr4_features |= mask;
18701 - if (trampoline_cr4_features)
18702 - *trampoline_cr4_features = mmu_cr4_features;
18703 - cr4 = read_cr4();
18704 - cr4 |= mask;
18705 - write_cr4(cr4);
18706 -}
18707 -
18708 -static inline void clear_in_cr4(unsigned long mask)
18709 -{
18710 - unsigned long cr4;
18711 -
18712 - mmu_cr4_features &= ~mask;
18713 - if (trampoline_cr4_features)
18714 - *trampoline_cr4_features = mmu_cr4_features;
18715 - cr4 = read_cr4();
18716 - cr4 &= ~mask;
18717 - write_cr4(cr4);
18718 -}
18719 +extern void set_in_cr4(unsigned long mask);
18720 +extern void clear_in_cr4(unsigned long mask);
18721
18722 typedef struct {
18723 unsigned long seg;
18724 @@ -836,11 +828,18 @@ static inline void spin_lock_prefetch(const void *x)
18725 */
18726 #define TASK_SIZE PAGE_OFFSET
18727 #define TASK_SIZE_MAX TASK_SIZE
18728 +
18729 +#ifdef CONFIG_PAX_SEGMEXEC
18730 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
18731 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
18732 +#else
18733 #define STACK_TOP TASK_SIZE
18734 -#define STACK_TOP_MAX STACK_TOP
18735 +#endif
18736 +
18737 +#define STACK_TOP_MAX TASK_SIZE
18738
18739 #define INIT_THREAD { \
18740 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
18741 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18742 .vm86_info = NULL, \
18743 .sysenter_cs = __KERNEL_CS, \
18744 .io_bitmap_ptr = NULL, \
18745 @@ -854,7 +853,7 @@ static inline void spin_lock_prefetch(const void *x)
18746 */
18747 #define INIT_TSS { \
18748 .x86_tss = { \
18749 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
18750 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18751 .ss0 = __KERNEL_DS, \
18752 .ss1 = __KERNEL_CS, \
18753 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
18754 @@ -865,11 +864,7 @@ static inline void spin_lock_prefetch(const void *x)
18755 extern unsigned long thread_saved_pc(struct task_struct *tsk);
18756
18757 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
18758 -#define KSTK_TOP(info) \
18759 -({ \
18760 - unsigned long *__ptr = (unsigned long *)(info); \
18761 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
18762 -})
18763 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
18764
18765 /*
18766 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
18767 @@ -884,7 +879,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18768 #define task_pt_regs(task) \
18769 ({ \
18770 struct pt_regs *__regs__; \
18771 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
18772 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
18773 __regs__ - 1; \
18774 })
18775
18776 @@ -894,13 +889,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18777 /*
18778 * User space process size. 47bits minus one guard page.
18779 */
18780 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
18781 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
18782
18783 /* This decides where the kernel will search for a free chunk of vm
18784 * space during mmap's.
18785 */
18786 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
18787 - 0xc0000000 : 0xFFFFe000)
18788 + 0xc0000000 : 0xFFFFf000)
18789
18790 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
18791 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
18792 @@ -911,11 +906,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18793 #define STACK_TOP_MAX TASK_SIZE_MAX
18794
18795 #define INIT_THREAD { \
18796 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18797 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18798 }
18799
18800 #define INIT_TSS { \
18801 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18802 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18803 }
18804
18805 /*
18806 @@ -943,6 +938,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
18807 */
18808 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
18809
18810 +#ifdef CONFIG_PAX_SEGMEXEC
18811 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
18812 +#endif
18813 +
18814 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
18815
18816 /* Get/set a process' ability to use the timestamp counter instruction */
18817 @@ -969,7 +968,7 @@ static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves)
18818 return 0;
18819 }
18820
18821 -extern unsigned long arch_align_stack(unsigned long sp);
18822 +#define arch_align_stack(x) ((x) & ~0xfUL)
18823 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
18824
18825 void default_idle(void);
18826 @@ -979,6 +978,6 @@ bool xen_set_default_idle(void);
18827 #define xen_set_default_idle 0
18828 #endif
18829
18830 -void stop_this_cpu(void *dummy);
18831 +void stop_this_cpu(void *dummy) __noreturn;
18832 void df_debug(struct pt_regs *regs, long error_code);
18833 #endif /* _ASM_X86_PROCESSOR_H */
18834 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
18835 index 6205f0c..688a3a9 100644
18836 --- a/arch/x86/include/asm/ptrace.h
18837 +++ b/arch/x86/include/asm/ptrace.h
18838 @@ -84,28 +84,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
18839 }
18840
18841 /*
18842 - * user_mode_vm(regs) determines whether a register set came from user mode.
18843 + * user_mode(regs) determines whether a register set came from user mode.
18844 * This is true if V8086 mode was enabled OR if the register set was from
18845 * protected mode with RPL-3 CS value. This tricky test checks that with
18846 * one comparison. Many places in the kernel can bypass this full check
18847 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
18848 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
18849 + * be used.
18850 */
18851 -static inline int user_mode(struct pt_regs *regs)
18852 +static inline int user_mode_novm(struct pt_regs *regs)
18853 {
18854 #ifdef CONFIG_X86_32
18855 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
18856 #else
18857 - return !!(regs->cs & 3);
18858 + return !!(regs->cs & SEGMENT_RPL_MASK);
18859 #endif
18860 }
18861
18862 -static inline int user_mode_vm(struct pt_regs *regs)
18863 +static inline int user_mode(struct pt_regs *regs)
18864 {
18865 #ifdef CONFIG_X86_32
18866 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
18867 USER_RPL;
18868 #else
18869 - return user_mode(regs);
18870 + return user_mode_novm(regs);
18871 #endif
18872 }
18873
18874 @@ -121,15 +122,16 @@ static inline int v8086_mode(struct pt_regs *regs)
18875 #ifdef CONFIG_X86_64
18876 static inline bool user_64bit_mode(struct pt_regs *regs)
18877 {
18878 + unsigned long cs = regs->cs & 0xffff;
18879 #ifndef CONFIG_PARAVIRT
18880 /*
18881 * On non-paravirt systems, this is the only long mode CPL 3
18882 * selector. We do not allow long mode selectors in the LDT.
18883 */
18884 - return regs->cs == __USER_CS;
18885 + return cs == __USER_CS;
18886 #else
18887 /* Headers are too twisted for this to go in paravirt.h. */
18888 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
18889 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
18890 #endif
18891 }
18892
18893 @@ -180,9 +182,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
18894 * Traps from the kernel do not save sp and ss.
18895 * Use the helper function to retrieve sp.
18896 */
18897 - if (offset == offsetof(struct pt_regs, sp) &&
18898 - regs->cs == __KERNEL_CS)
18899 - return kernel_stack_pointer(regs);
18900 + if (offset == offsetof(struct pt_regs, sp)) {
18901 + unsigned long cs = regs->cs & 0xffff;
18902 + if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
18903 + return kernel_stack_pointer(regs);
18904 + }
18905 #endif
18906 return *(unsigned long *)((unsigned long)regs + offset);
18907 }
18908 diff --git a/arch/x86/include/asm/qrwlock.h b/arch/x86/include/asm/qrwlock.h
18909 index 70f46f0..adfbdb4 100644
18910 --- a/arch/x86/include/asm/qrwlock.h
18911 +++ b/arch/x86/include/asm/qrwlock.h
18912 @@ -7,8 +7,8 @@
18913 #define queue_write_unlock queue_write_unlock
18914 static inline void queue_write_unlock(struct qrwlock *lock)
18915 {
18916 - barrier();
18917 - ACCESS_ONCE(*(u8 *)&lock->cnts) = 0;
18918 + barrier();
18919 + ACCESS_ONCE_RW(*(u8 *)&lock->cnts) = 0;
18920 }
18921 #endif
18922
18923 diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
18924 index 9c6b890..5305f53 100644
18925 --- a/arch/x86/include/asm/realmode.h
18926 +++ b/arch/x86/include/asm/realmode.h
18927 @@ -22,16 +22,14 @@ struct real_mode_header {
18928 #endif
18929 /* APM/BIOS reboot */
18930 u32 machine_real_restart_asm;
18931 -#ifdef CONFIG_X86_64
18932 u32 machine_real_restart_seg;
18933 -#endif
18934 };
18935
18936 /* This must match data at trampoline_32/64.S */
18937 struct trampoline_header {
18938 #ifdef CONFIG_X86_32
18939 u32 start;
18940 - u16 gdt_pad;
18941 + u16 boot_cs;
18942 u16 gdt_limit;
18943 u32 gdt_base;
18944 #else
18945 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
18946 index a82c4f1..ac45053 100644
18947 --- a/arch/x86/include/asm/reboot.h
18948 +++ b/arch/x86/include/asm/reboot.h
18949 @@ -6,13 +6,13 @@
18950 struct pt_regs;
18951
18952 struct machine_ops {
18953 - void (*restart)(char *cmd);
18954 - void (*halt)(void);
18955 - void (*power_off)(void);
18956 + void (* __noreturn restart)(char *cmd);
18957 + void (* __noreturn halt)(void);
18958 + void (* __noreturn power_off)(void);
18959 void (*shutdown)(void);
18960 void (*crash_shutdown)(struct pt_regs *);
18961 - void (*emergency_restart)(void);
18962 -};
18963 + void (* __noreturn emergency_restart)(void);
18964 +} __no_const;
18965
18966 extern struct machine_ops machine_ops;
18967
18968 diff --git a/arch/x86/include/asm/rmwcc.h b/arch/x86/include/asm/rmwcc.h
18969 index 8f7866a..e442f20 100644
18970 --- a/arch/x86/include/asm/rmwcc.h
18971 +++ b/arch/x86/include/asm/rmwcc.h
18972 @@ -3,7 +3,34 @@
18973
18974 #ifdef CC_HAVE_ASM_GOTO
18975
18976 -#define __GEN_RMWcc(fullop, var, cc, ...) \
18977 +#ifdef CONFIG_PAX_REFCOUNT
18978 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18979 +do { \
18980 + asm_volatile_goto (fullop \
18981 + ";jno 0f\n" \
18982 + fullantiop \
18983 + ";int $4\n0:\n" \
18984 + _ASM_EXTABLE(0b, 0b) \
18985 + ";j" cc " %l[cc_label]" \
18986 + : : "m" (var), ## __VA_ARGS__ \
18987 + : "memory" : cc_label); \
18988 + return 0; \
18989 +cc_label: \
18990 + return 1; \
18991 +} while (0)
18992 +#else
18993 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18994 +do { \
18995 + asm_volatile_goto (fullop ";j" cc " %l[cc_label]" \
18996 + : : "m" (var), ## __VA_ARGS__ \
18997 + : "memory" : cc_label); \
18998 + return 0; \
18999 +cc_label: \
19000 + return 1; \
19001 +} while (0)
19002 +#endif
19003 +
19004 +#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
19005 do { \
19006 asm_volatile_goto (fullop "; j" cc " %l[cc_label]" \
19007 : : "m" (var), ## __VA_ARGS__ \
19008 @@ -13,15 +40,46 @@ cc_label: \
19009 return 1; \
19010 } while (0)
19011
19012 -#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
19013 - __GEN_RMWcc(op " " arg0, var, cc)
19014 +#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
19015 + __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
19016
19017 -#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
19018 - __GEN_RMWcc(op " %1, " arg0, var, cc, vcon (val))
19019 +#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
19020 + __GEN_RMWcc_unchecked(op " " arg0, var, cc)
19021 +
19022 +#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
19023 + __GEN_RMWcc(op " %1, " arg0, antiop " %1, " arg0, var, cc, vcon (val))
19024 +
19025 +#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
19026 + __GEN_RMWcc_unchecked(op " %1, " arg0, var, cc, vcon (val))
19027
19028 #else /* !CC_HAVE_ASM_GOTO */
19029
19030 -#define __GEN_RMWcc(fullop, var, cc, ...) \
19031 +#ifdef CONFIG_PAX_REFCOUNT
19032 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
19033 +do { \
19034 + char c; \
19035 + asm volatile (fullop \
19036 + ";jno 0f\n" \
19037 + fullantiop \
19038 + ";int $4\n0:\n" \
19039 + _ASM_EXTABLE(0b, 0b) \
19040 + "; set" cc " %1" \
19041 + : "+m" (var), "=qm" (c) \
19042 + : __VA_ARGS__ : "memory"); \
19043 + return c != 0; \
19044 +} while (0)
19045 +#else
19046 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
19047 +do { \
19048 + char c; \
19049 + asm volatile (fullop "; set" cc " %1" \
19050 + : "+m" (var), "=qm" (c) \
19051 + : __VA_ARGS__ : "memory"); \
19052 + return c != 0; \
19053 +} while (0)
19054 +#endif
19055 +
19056 +#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
19057 do { \
19058 char c; \
19059 asm volatile (fullop "; set" cc " %1" \
19060 @@ -30,11 +88,17 @@ do { \
19061 return c != 0; \
19062 } while (0)
19063
19064 -#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
19065 - __GEN_RMWcc(op " " arg0, var, cc)
19066 +#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
19067 + __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
19068 +
19069 +#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
19070 + __GEN_RMWcc_unchecked(op " " arg0, var, cc)
19071 +
19072 +#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
19073 + __GEN_RMWcc(op " %2, " arg0, antiop " %2, " arg0, var, cc, vcon (val))
19074
19075 -#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
19076 - __GEN_RMWcc(op " %2, " arg0, var, cc, vcon (val))
19077 +#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
19078 + __GEN_RMWcc_unchecked(op " %2, " arg0, var, cc, vcon (val))
19079
19080 #endif /* CC_HAVE_ASM_GOTO */
19081
19082 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
19083 index cad82c9..2e5c5c1 100644
19084 --- a/arch/x86/include/asm/rwsem.h
19085 +++ b/arch/x86/include/asm/rwsem.h
19086 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
19087 {
19088 asm volatile("# beginning down_read\n\t"
19089 LOCK_PREFIX _ASM_INC "(%1)\n\t"
19090 +
19091 +#ifdef CONFIG_PAX_REFCOUNT
19092 + "jno 0f\n"
19093 + LOCK_PREFIX _ASM_DEC "(%1)\n"
19094 + "int $4\n0:\n"
19095 + _ASM_EXTABLE(0b, 0b)
19096 +#endif
19097 +
19098 /* adds 0x00000001 */
19099 " jns 1f\n"
19100 " call call_rwsem_down_read_failed\n"
19101 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
19102 "1:\n\t"
19103 " mov %1,%2\n\t"
19104 " add %3,%2\n\t"
19105 +
19106 +#ifdef CONFIG_PAX_REFCOUNT
19107 + "jno 0f\n"
19108 + "sub %3,%2\n"
19109 + "int $4\n0:\n"
19110 + _ASM_EXTABLE(0b, 0b)
19111 +#endif
19112 +
19113 " jle 2f\n\t"
19114 LOCK_PREFIX " cmpxchg %2,%0\n\t"
19115 " jnz 1b\n\t"
19116 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
19117 long tmp;
19118 asm volatile("# beginning down_write\n\t"
19119 LOCK_PREFIX " xadd %1,(%2)\n\t"
19120 +
19121 +#ifdef CONFIG_PAX_REFCOUNT
19122 + "jno 0f\n"
19123 + "mov %1,(%2)\n"
19124 + "int $4\n0:\n"
19125 + _ASM_EXTABLE(0b, 0b)
19126 +#endif
19127 +
19128 /* adds 0xffff0001, returns the old value */
19129 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
19130 /* was the active mask 0 before? */
19131 @@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
19132 long tmp;
19133 asm volatile("# beginning __up_read\n\t"
19134 LOCK_PREFIX " xadd %1,(%2)\n\t"
19135 +
19136 +#ifdef CONFIG_PAX_REFCOUNT
19137 + "jno 0f\n"
19138 + "mov %1,(%2)\n"
19139 + "int $4\n0:\n"
19140 + _ASM_EXTABLE(0b, 0b)
19141 +#endif
19142 +
19143 /* subtracts 1, returns the old value */
19144 " jns 1f\n\t"
19145 " call call_rwsem_wake\n" /* expects old value in %edx */
19146 @@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
19147 long tmp;
19148 asm volatile("# beginning __up_write\n\t"
19149 LOCK_PREFIX " xadd %1,(%2)\n\t"
19150 +
19151 +#ifdef CONFIG_PAX_REFCOUNT
19152 + "jno 0f\n"
19153 + "mov %1,(%2)\n"
19154 + "int $4\n0:\n"
19155 + _ASM_EXTABLE(0b, 0b)
19156 +#endif
19157 +
19158 /* subtracts 0xffff0001, returns the old value */
19159 " jns 1f\n\t"
19160 " call call_rwsem_wake\n" /* expects old value in %edx */
19161 @@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
19162 {
19163 asm volatile("# beginning __downgrade_write\n\t"
19164 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
19165 +
19166 +#ifdef CONFIG_PAX_REFCOUNT
19167 + "jno 0f\n"
19168 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
19169 + "int $4\n0:\n"
19170 + _ASM_EXTABLE(0b, 0b)
19171 +#endif
19172 +
19173 /*
19174 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
19175 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
19176 @@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
19177 */
19178 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
19179 {
19180 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
19181 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
19182 +
19183 +#ifdef CONFIG_PAX_REFCOUNT
19184 + "jno 0f\n"
19185 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
19186 + "int $4\n0:\n"
19187 + _ASM_EXTABLE(0b, 0b)
19188 +#endif
19189 +
19190 : "+m" (sem->count)
19191 : "er" (delta));
19192 }
19193 @@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
19194 */
19195 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
19196 {
19197 - return delta + xadd(&sem->count, delta);
19198 + return delta + xadd_check_overflow(&sem->count, delta);
19199 }
19200
19201 #endif /* __KERNEL__ */
19202 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
19203 index 6f1c3a8..7744f19 100644
19204 --- a/arch/x86/include/asm/segment.h
19205 +++ b/arch/x86/include/asm/segment.h
19206 @@ -64,10 +64,15 @@
19207 * 26 - ESPFIX small SS
19208 * 27 - per-cpu [ offset to per-cpu data area ]
19209 * 28 - stack_canary-20 [ for stack protector ]
19210 - * 29 - unused
19211 - * 30 - unused
19212 + * 29 - PCI BIOS CS
19213 + * 30 - PCI BIOS DS
19214 * 31 - TSS for double fault handler
19215 */
19216 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
19217 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
19218 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
19219 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
19220 +
19221 #define GDT_ENTRY_TLS_MIN 6
19222 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
19223
19224 @@ -79,6 +84,8 @@
19225
19226 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
19227
19228 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
19229 +
19230 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
19231
19232 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
19233 @@ -104,6 +111,12 @@
19234 #define __KERNEL_STACK_CANARY 0
19235 #endif
19236
19237 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
19238 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
19239 +
19240 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
19241 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
19242 +
19243 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
19244
19245 /*
19246 @@ -141,7 +154,7 @@
19247 */
19248
19249 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
19250 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
19251 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
19252
19253
19254 #else
19255 @@ -165,6 +178,8 @@
19256 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
19257 #define __USER32_DS __USER_DS
19258
19259 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
19260 +
19261 #define GDT_ENTRY_TSS 8 /* needs two entries */
19262 #define GDT_ENTRY_LDT 10 /* needs two entries */
19263 #define GDT_ENTRY_TLS_MIN 12
19264 @@ -173,6 +188,8 @@
19265 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
19266 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
19267
19268 +#define GDT_ENTRY_UDEREF_KERNEL_DS 16
19269 +
19270 /* TLS indexes for 64bit - hardcoded in arch_prctl */
19271 #define FS_TLS 0
19272 #define GS_TLS 1
19273 @@ -180,12 +197,14 @@
19274 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
19275 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
19276
19277 -#define GDT_ENTRIES 16
19278 +#define GDT_ENTRIES 17
19279
19280 #endif
19281
19282 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
19283 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
19284 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
19285 +#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
19286 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
19287 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
19288 #ifndef CONFIG_PARAVIRT
19289 @@ -268,7 +287,7 @@ static inline unsigned long get_limit(unsigned long segment)
19290 {
19291 unsigned long __limit;
19292 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
19293 - return __limit + 1;
19294 + return __limit;
19295 }
19296
19297 #endif /* !__ASSEMBLY__ */
19298 diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
19299 index 8d3120f..352b440 100644
19300 --- a/arch/x86/include/asm/smap.h
19301 +++ b/arch/x86/include/asm/smap.h
19302 @@ -25,11 +25,40 @@
19303
19304 #include <asm/alternative-asm.h>
19305
19306 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19307 +#define ASM_PAX_OPEN_USERLAND \
19308 + 661: jmp 663f; \
19309 + .pushsection .altinstr_replacement, "a" ; \
19310 + 662: pushq %rax; nop; \
19311 + .popsection ; \
19312 + .pushsection .altinstructions, "a" ; \
19313 + altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
19314 + .popsection ; \
19315 + call __pax_open_userland; \
19316 + popq %rax; \
19317 + 663:
19318 +
19319 +#define ASM_PAX_CLOSE_USERLAND \
19320 + 661: jmp 663f; \
19321 + .pushsection .altinstr_replacement, "a" ; \
19322 + 662: pushq %rax; nop; \
19323 + .popsection; \
19324 + .pushsection .altinstructions, "a" ; \
19325 + altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
19326 + .popsection; \
19327 + call __pax_close_userland; \
19328 + popq %rax; \
19329 + 663:
19330 +#else
19331 +#define ASM_PAX_OPEN_USERLAND
19332 +#define ASM_PAX_CLOSE_USERLAND
19333 +#endif
19334 +
19335 #ifdef CONFIG_X86_SMAP
19336
19337 #define ASM_CLAC \
19338 661: ASM_NOP3 ; \
19339 - .pushsection .altinstr_replacement, "ax" ; \
19340 + .pushsection .altinstr_replacement, "a" ; \
19341 662: __ASM_CLAC ; \
19342 .popsection ; \
19343 .pushsection .altinstructions, "a" ; \
19344 @@ -38,7 +67,7 @@
19345
19346 #define ASM_STAC \
19347 661: ASM_NOP3 ; \
19348 - .pushsection .altinstr_replacement, "ax" ; \
19349 + .pushsection .altinstr_replacement, "a" ; \
19350 662: __ASM_STAC ; \
19351 .popsection ; \
19352 .pushsection .altinstructions, "a" ; \
19353 @@ -56,6 +85,37 @@
19354
19355 #include <asm/alternative.h>
19356
19357 +#define __HAVE_ARCH_PAX_OPEN_USERLAND
19358 +#define __HAVE_ARCH_PAX_CLOSE_USERLAND
19359 +
19360 +extern void __pax_open_userland(void);
19361 +static __always_inline unsigned long pax_open_userland(void)
19362 +{
19363 +
19364 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19365 + asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
19366 + :
19367 + : [open] "i" (__pax_open_userland)
19368 + : "memory", "rax");
19369 +#endif
19370 +
19371 + return 0;
19372 +}
19373 +
19374 +extern void __pax_close_userland(void);
19375 +static __always_inline unsigned long pax_close_userland(void)
19376 +{
19377 +
19378 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19379 + asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
19380 + :
19381 + : [close] "i" (__pax_close_userland)
19382 + : "memory", "rax");
19383 +#endif
19384 +
19385 + return 0;
19386 +}
19387 +
19388 #ifdef CONFIG_X86_SMAP
19389
19390 static __always_inline void clac(void)
19391 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
19392 index 8cd27e0..7f05ec8 100644
19393 --- a/arch/x86/include/asm/smp.h
19394 +++ b/arch/x86/include/asm/smp.h
19395 @@ -35,7 +35,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
19396 /* cpus sharing the last level cache: */
19397 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
19398 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
19399 -DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
19400 +DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
19401
19402 static inline struct cpumask *cpu_sibling_mask(int cpu)
19403 {
19404 @@ -78,7 +78,7 @@ struct smp_ops {
19405
19406 void (*send_call_func_ipi)(const struct cpumask *mask);
19407 void (*send_call_func_single_ipi)(int cpu);
19408 -};
19409 +} __no_const;
19410
19411 /* Globals due to paravirt */
19412 extern void set_cpu_sibling_map(int cpu);
19413 @@ -190,14 +190,8 @@ extern unsigned disabled_cpus;
19414 extern int safe_smp_processor_id(void);
19415
19416 #elif defined(CONFIG_X86_64_SMP)
19417 -#define raw_smp_processor_id() (this_cpu_read(cpu_number))
19418 -
19419 -#define stack_smp_processor_id() \
19420 -({ \
19421 - struct thread_info *ti; \
19422 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
19423 - ti->cpu; \
19424 -})
19425 +#define raw_smp_processor_id() (this_cpu_read(cpu_number))
19426 +#define stack_smp_processor_id() raw_smp_processor_id()
19427 #define safe_smp_processor_id() smp_processor_id()
19428
19429 #endif
19430 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
19431 index 54f1c80..39362a5 100644
19432 --- a/arch/x86/include/asm/spinlock.h
19433 +++ b/arch/x86/include/asm/spinlock.h
19434 @@ -223,6 +223,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
19435 static inline void arch_read_lock(arch_rwlock_t *rw)
19436 {
19437 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
19438 +
19439 +#ifdef CONFIG_PAX_REFCOUNT
19440 + "jno 0f\n"
19441 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
19442 + "int $4\n0:\n"
19443 + _ASM_EXTABLE(0b, 0b)
19444 +#endif
19445 +
19446 "jns 1f\n"
19447 "call __read_lock_failed\n\t"
19448 "1:\n"
19449 @@ -232,6 +240,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
19450 static inline void arch_write_lock(arch_rwlock_t *rw)
19451 {
19452 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
19453 +
19454 +#ifdef CONFIG_PAX_REFCOUNT
19455 + "jno 0f\n"
19456 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
19457 + "int $4\n0:\n"
19458 + _ASM_EXTABLE(0b, 0b)
19459 +#endif
19460 +
19461 "jz 1f\n"
19462 "call __write_lock_failed\n\t"
19463 "1:\n"
19464 @@ -261,13 +277,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
19465
19466 static inline void arch_read_unlock(arch_rwlock_t *rw)
19467 {
19468 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
19469 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
19470 +
19471 +#ifdef CONFIG_PAX_REFCOUNT
19472 + "jno 0f\n"
19473 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
19474 + "int $4\n0:\n"
19475 + _ASM_EXTABLE(0b, 0b)
19476 +#endif
19477 +
19478 :"+m" (rw->lock) : : "memory");
19479 }
19480
19481 static inline void arch_write_unlock(arch_rwlock_t *rw)
19482 {
19483 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
19484 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
19485 +
19486 +#ifdef CONFIG_PAX_REFCOUNT
19487 + "jno 0f\n"
19488 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
19489 + "int $4\n0:\n"
19490 + _ASM_EXTABLE(0b, 0b)
19491 +#endif
19492 +
19493 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
19494 }
19495 #else
19496 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
19497 index 6a99859..03cb807 100644
19498 --- a/arch/x86/include/asm/stackprotector.h
19499 +++ b/arch/x86/include/asm/stackprotector.h
19500 @@ -47,7 +47,7 @@
19501 * head_32 for boot CPU and setup_per_cpu_areas() for others.
19502 */
19503 #define GDT_STACK_CANARY_INIT \
19504 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
19505 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
19506
19507 /*
19508 * Initialize the stackprotector canary value.
19509 @@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
19510
19511 static inline void load_stack_canary_segment(void)
19512 {
19513 -#ifdef CONFIG_X86_32
19514 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
19515 asm volatile ("mov %0, %%gs" : : "r" (0));
19516 #endif
19517 }
19518 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
19519 index 70bbe39..4ae2bd4 100644
19520 --- a/arch/x86/include/asm/stacktrace.h
19521 +++ b/arch/x86/include/asm/stacktrace.h
19522 @@ -11,28 +11,20 @@
19523
19524 extern int kstack_depth_to_print;
19525
19526 -struct thread_info;
19527 +struct task_struct;
19528 struct stacktrace_ops;
19529
19530 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
19531 - unsigned long *stack,
19532 - unsigned long bp,
19533 - const struct stacktrace_ops *ops,
19534 - void *data,
19535 - unsigned long *end,
19536 - int *graph);
19537 +typedef unsigned long walk_stack_t(struct task_struct *task,
19538 + void *stack_start,
19539 + unsigned long *stack,
19540 + unsigned long bp,
19541 + const struct stacktrace_ops *ops,
19542 + void *data,
19543 + unsigned long *end,
19544 + int *graph);
19545
19546 -extern unsigned long
19547 -print_context_stack(struct thread_info *tinfo,
19548 - unsigned long *stack, unsigned long bp,
19549 - const struct stacktrace_ops *ops, void *data,
19550 - unsigned long *end, int *graph);
19551 -
19552 -extern unsigned long
19553 -print_context_stack_bp(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 +extern walk_stack_t print_context_stack;
19558 +extern walk_stack_t print_context_stack_bp;
19559
19560 /* Generic stack tracer with callbacks */
19561
19562 @@ -40,7 +32,7 @@ struct stacktrace_ops {
19563 void (*address)(void *data, unsigned long address, int reliable);
19564 /* On negative return stop dumping */
19565 int (*stack)(void *data, char *name);
19566 - walk_stack_t walk_stack;
19567 + walk_stack_t *walk_stack;
19568 };
19569
19570 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
19571 diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
19572 index d7f3b3b..3cc39f1 100644
19573 --- a/arch/x86/include/asm/switch_to.h
19574 +++ b/arch/x86/include/asm/switch_to.h
19575 @@ -108,7 +108,7 @@ do { \
19576 "call __switch_to\n\t" \
19577 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
19578 __switch_canary \
19579 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
19580 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
19581 "movq %%rax,%%rdi\n\t" \
19582 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
19583 "jnz ret_from_fork\n\t" \
19584 @@ -119,7 +119,7 @@ do { \
19585 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
19586 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
19587 [_tif_fork] "i" (_TIF_FORK), \
19588 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
19589 + [thread_info] "m" (current_tinfo), \
19590 [current_task] "m" (current_task) \
19591 __switch_canary_iparam \
19592 : "memory", "cc" __EXTRA_CLOBBER)
19593 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
19594 index 8540538..4b0b5e9 100644
19595 --- a/arch/x86/include/asm/thread_info.h
19596 +++ b/arch/x86/include/asm/thread_info.h
19597 @@ -24,7 +24,6 @@ struct exec_domain;
19598 #include <linux/atomic.h>
19599
19600 struct thread_info {
19601 - struct task_struct *task; /* main task structure */
19602 struct exec_domain *exec_domain; /* execution domain */
19603 __u32 flags; /* low level flags */
19604 __u32 status; /* thread synchronous flags */
19605 @@ -33,13 +32,13 @@ struct thread_info {
19606 mm_segment_t addr_limit;
19607 struct restart_block restart_block;
19608 void __user *sysenter_return;
19609 + unsigned long lowest_stack;
19610 unsigned int sig_on_uaccess_error:1;
19611 unsigned int uaccess_err:1; /* uaccess failed */
19612 };
19613
19614 -#define INIT_THREAD_INFO(tsk) \
19615 +#define INIT_THREAD_INFO \
19616 { \
19617 - .task = &tsk, \
19618 .exec_domain = &default_exec_domain, \
19619 .flags = 0, \
19620 .cpu = 0, \
19621 @@ -50,7 +49,7 @@ struct thread_info {
19622 }, \
19623 }
19624
19625 -#define init_thread_info (init_thread_union.thread_info)
19626 +#define init_thread_info (init_thread_union.stack)
19627 #define init_stack (init_thread_union.stack)
19628
19629 #else /* !__ASSEMBLY__ */
19630 @@ -91,6 +90,7 @@ struct thread_info {
19631 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
19632 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
19633 #define TIF_X32 30 /* 32-bit native x86-64 binary */
19634 +#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
19635
19636 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
19637 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
19638 @@ -115,17 +115,18 @@ struct thread_info {
19639 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
19640 #define _TIF_ADDR32 (1 << TIF_ADDR32)
19641 #define _TIF_X32 (1 << TIF_X32)
19642 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
19643
19644 /* work to do in syscall_trace_enter() */
19645 #define _TIF_WORK_SYSCALL_ENTRY \
19646 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
19647 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
19648 - _TIF_NOHZ)
19649 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
19650
19651 /* work to do in syscall_trace_leave() */
19652 #define _TIF_WORK_SYSCALL_EXIT \
19653 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
19654 - _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
19655 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
19656
19657 /* work to do on interrupt/exception return */
19658 #define _TIF_WORK_MASK \
19659 @@ -136,7 +137,7 @@ struct thread_info {
19660 /* work to do on any return to user space */
19661 #define _TIF_ALLWORK_MASK \
19662 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
19663 - _TIF_NOHZ)
19664 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
19665
19666 /* Only used for 64 bit */
19667 #define _TIF_DO_NOTIFY_MASK \
19668 @@ -151,7 +152,6 @@ struct thread_info {
19669 #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW)
19670
19671 #define STACK_WARN (THREAD_SIZE/8)
19672 -#define KERNEL_STACK_OFFSET (5*(BITS_PER_LONG/8))
19673
19674 /*
19675 * macros/functions for gaining access to the thread information structure
19676 @@ -162,26 +162,18 @@ struct thread_info {
19677
19678 DECLARE_PER_CPU(unsigned long, kernel_stack);
19679
19680 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
19681 +
19682 static inline struct thread_info *current_thread_info(void)
19683 {
19684 - struct thread_info *ti;
19685 - ti = (void *)(this_cpu_read_stable(kernel_stack) +
19686 - KERNEL_STACK_OFFSET - THREAD_SIZE);
19687 - return ti;
19688 + return this_cpu_read_stable(current_tinfo);
19689 }
19690
19691 #else /* !__ASSEMBLY__ */
19692
19693 /* how to get the thread information struct from ASM */
19694 #define GET_THREAD_INFO(reg) \
19695 - _ASM_MOV PER_CPU_VAR(kernel_stack),reg ; \
19696 - _ASM_SUB $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg ;
19697 -
19698 -/*
19699 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
19700 - * a certain register (to be used in assembler memory operands).
19701 - */
19702 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
19703 + _ASM_MOV PER_CPU_VAR(current_tinfo),reg ;
19704
19705 #endif
19706
19707 @@ -237,5 +229,12 @@ static inline bool is_ia32_task(void)
19708 extern void arch_task_cache_init(void);
19709 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
19710 extern void arch_release_task_struct(struct task_struct *tsk);
19711 +
19712 +#define __HAVE_THREAD_FUNCTIONS
19713 +#define task_thread_info(task) (&(task)->tinfo)
19714 +#define task_stack_page(task) ((task)->stack)
19715 +#define setup_thread_stack(p, org) do {} while (0)
19716 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
19717 +
19718 #endif
19719 #endif /* _ASM_X86_THREAD_INFO_H */
19720 diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
19721 index 04905bf..49203ca 100644
19722 --- a/arch/x86/include/asm/tlbflush.h
19723 +++ b/arch/x86/include/asm/tlbflush.h
19724 @@ -17,18 +17,44 @@
19725
19726 static inline void __native_flush_tlb(void)
19727 {
19728 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
19729 + u64 descriptor[2];
19730 +
19731 + descriptor[0] = PCID_KERNEL;
19732 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_MONGLOBAL) : "memory");
19733 + return;
19734 + }
19735 +
19736 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19737 + if (static_cpu_has(X86_FEATURE_PCID)) {
19738 + unsigned int cpu = raw_get_cpu();
19739 +
19740 + native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
19741 + native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
19742 + raw_put_cpu_no_resched();
19743 + return;
19744 + }
19745 +#endif
19746 +
19747 native_write_cr3(native_read_cr3());
19748 }
19749
19750 static inline void __native_flush_tlb_global_irq_disabled(void)
19751 {
19752 - unsigned long cr4;
19753 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
19754 + u64 descriptor[2];
19755
19756 - cr4 = native_read_cr4();
19757 - /* clear PGE */
19758 - native_write_cr4(cr4 & ~X86_CR4_PGE);
19759 - /* write old PGE again and flush TLBs */
19760 - native_write_cr4(cr4);
19761 + descriptor[0] = PCID_KERNEL;
19762 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
19763 + } else {
19764 + unsigned long cr4;
19765 +
19766 + cr4 = native_read_cr4();
19767 + /* clear PGE */
19768 + native_write_cr4(cr4 & ~X86_CR4_PGE);
19769 + /* write old PGE again and flush TLBs */
19770 + native_write_cr4(cr4);
19771 + }
19772 }
19773
19774 static inline void __native_flush_tlb_global(void)
19775 @@ -49,6 +75,41 @@ static inline void __native_flush_tlb_global(void)
19776
19777 static inline void __native_flush_tlb_single(unsigned long addr)
19778 {
19779 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
19780 + u64 descriptor[2];
19781 +
19782 + descriptor[0] = PCID_KERNEL;
19783 + descriptor[1] = addr;
19784 +
19785 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19786 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
19787 + if (addr < TASK_SIZE_MAX)
19788 + descriptor[1] += pax_user_shadow_base;
19789 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19790 + }
19791 +
19792 + descriptor[0] = PCID_USER;
19793 + descriptor[1] = addr;
19794 +#endif
19795 +
19796 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19797 + return;
19798 + }
19799 +
19800 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19801 + if (static_cpu_has(X86_FEATURE_PCID)) {
19802 + unsigned int cpu = raw_get_cpu();
19803 +
19804 + native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
19805 + asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19806 + native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
19807 + raw_put_cpu_no_resched();
19808 +
19809 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
19810 + addr += pax_user_shadow_base;
19811 + }
19812 +#endif
19813 +
19814 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19815 }
19816
19817 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
19818 index 0d592e0..526f797 100644
19819 --- a/arch/x86/include/asm/uaccess.h
19820 +++ b/arch/x86/include/asm/uaccess.h
19821 @@ -7,6 +7,7 @@
19822 #include <linux/compiler.h>
19823 #include <linux/thread_info.h>
19824 #include <linux/string.h>
19825 +#include <linux/spinlock.h>
19826 #include <asm/asm.h>
19827 #include <asm/page.h>
19828 #include <asm/smap.h>
19829 @@ -29,7 +30,12 @@
19830
19831 #define get_ds() (KERNEL_DS)
19832 #define get_fs() (current_thread_info()->addr_limit)
19833 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19834 +void __set_fs(mm_segment_t x);
19835 +void set_fs(mm_segment_t x);
19836 +#else
19837 #define set_fs(x) (current_thread_info()->addr_limit = (x))
19838 +#endif
19839
19840 #define segment_eq(a, b) ((a).seg == (b).seg)
19841
19842 @@ -85,8 +91,36 @@ static inline bool __chk_range_not_ok(unsigned long addr, unsigned long size, un
19843 * checks that the pointer is in the user space range - after calling
19844 * this function, memory access functions may still return -EFAULT.
19845 */
19846 -#define access_ok(type, addr, size) \
19847 - likely(!__range_not_ok(addr, size, user_addr_max()))
19848 +extern int _cond_resched(void);
19849 +#define access_ok_noprefault(type, addr, size) (likely(!__range_not_ok(addr, size, user_addr_max())))
19850 +#define access_ok(type, addr, size) \
19851 +({ \
19852 + unsigned long __size = size; \
19853 + unsigned long __addr = (unsigned long)addr; \
19854 + bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
19855 + if (__ret_ao && __size) { \
19856 + unsigned long __addr_ao = __addr & PAGE_MASK; \
19857 + unsigned long __end_ao = __addr + __size - 1; \
19858 + if (unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
19859 + while (__addr_ao <= __end_ao) { \
19860 + char __c_ao; \
19861 + __addr_ao += PAGE_SIZE; \
19862 + if (__size > PAGE_SIZE) \
19863 + _cond_resched(); \
19864 + if (__get_user(__c_ao, (char __user *)__addr)) \
19865 + break; \
19866 + if (type != VERIFY_WRITE) { \
19867 + __addr = __addr_ao; \
19868 + continue; \
19869 + } \
19870 + if (__put_user(__c_ao, (char __user *)__addr)) \
19871 + break; \
19872 + __addr = __addr_ao; \
19873 + } \
19874 + } \
19875 + } \
19876 + __ret_ao; \
19877 +})
19878
19879 /*
19880 * The exception table consists of pairs of addresses relative to the
19881 @@ -176,10 +210,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19882 register __inttype(*(ptr)) __val_gu asm("%"_ASM_DX); \
19883 __chk_user_ptr(ptr); \
19884 might_fault(); \
19885 + pax_open_userland(); \
19886 asm volatile("call __get_user_%P3" \
19887 : "=a" (__ret_gu), "=r" (__val_gu) \
19888 : "0" (ptr), "i" (sizeof(*(ptr)))); \
19889 (x) = (__typeof__(*(ptr))) __val_gu; \
19890 + pax_close_userland(); \
19891 __ret_gu; \
19892 })
19893
19894 @@ -187,13 +223,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19895 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
19896 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
19897
19898 -
19899 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19900 +#define __copyuser_seg "gs;"
19901 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
19902 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
19903 +#else
19904 +#define __copyuser_seg
19905 +#define __COPYUSER_SET_ES
19906 +#define __COPYUSER_RESTORE_ES
19907 +#endif
19908
19909 #ifdef CONFIG_X86_32
19910 #define __put_user_asm_u64(x, addr, err, errret) \
19911 asm volatile(ASM_STAC "\n" \
19912 - "1: movl %%eax,0(%2)\n" \
19913 - "2: movl %%edx,4(%2)\n" \
19914 + "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
19915 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
19916 "3: " ASM_CLAC "\n" \
19917 ".section .fixup,\"ax\"\n" \
19918 "4: movl %3,%0\n" \
19919 @@ -206,8 +250,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19920
19921 #define __put_user_asm_ex_u64(x, addr) \
19922 asm volatile(ASM_STAC "\n" \
19923 - "1: movl %%eax,0(%1)\n" \
19924 - "2: movl %%edx,4(%1)\n" \
19925 + "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
19926 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
19927 "3: " ASM_CLAC "\n" \
19928 _ASM_EXTABLE_EX(1b, 2b) \
19929 _ASM_EXTABLE_EX(2b, 3b) \
19930 @@ -257,7 +301,8 @@ extern void __put_user_8(void);
19931 __typeof__(*(ptr)) __pu_val; \
19932 __chk_user_ptr(ptr); \
19933 might_fault(); \
19934 - __pu_val = x; \
19935 + __pu_val = (x); \
19936 + pax_open_userland(); \
19937 switch (sizeof(*(ptr))) { \
19938 case 1: \
19939 __put_user_x(1, __pu_val, ptr, __ret_pu); \
19940 @@ -275,6 +320,7 @@ extern void __put_user_8(void);
19941 __put_user_x(X, __pu_val, ptr, __ret_pu); \
19942 break; \
19943 } \
19944 + pax_close_userland(); \
19945 __ret_pu; \
19946 })
19947
19948 @@ -355,8 +401,10 @@ do { \
19949 } while (0)
19950
19951 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19952 +do { \
19953 + pax_open_userland(); \
19954 asm volatile(ASM_STAC "\n" \
19955 - "1: mov"itype" %2,%"rtype"1\n" \
19956 + "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
19957 "2: " ASM_CLAC "\n" \
19958 ".section .fixup,\"ax\"\n" \
19959 "3: mov %3,%0\n" \
19960 @@ -364,8 +412,10 @@ do { \
19961 " jmp 2b\n" \
19962 ".previous\n" \
19963 _ASM_EXTABLE(1b, 3b) \
19964 - : "=r" (err), ltype(x) \
19965 - : "m" (__m(addr)), "i" (errret), "0" (err))
19966 + : "=r" (err), ltype (x) \
19967 + : "m" (__m(addr)), "i" (errret), "0" (err)); \
19968 + pax_close_userland(); \
19969 +} while (0)
19970
19971 #define __get_user_size_ex(x, ptr, size) \
19972 do { \
19973 @@ -389,7 +439,7 @@ do { \
19974 } while (0)
19975
19976 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
19977 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
19978 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
19979 "2:\n" \
19980 _ASM_EXTABLE_EX(1b, 2b) \
19981 : ltype(x) : "m" (__m(addr)))
19982 @@ -406,13 +456,24 @@ do { \
19983 int __gu_err; \
19984 unsigned long __gu_val; \
19985 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
19986 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
19987 + (x) = (__typeof__(*(ptr)))__gu_val; \
19988 __gu_err; \
19989 })
19990
19991 /* FIXME: this hack is definitely wrong -AK */
19992 struct __large_struct { unsigned long buf[100]; };
19993 -#define __m(x) (*(struct __large_struct __user *)(x))
19994 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19995 +#define ____m(x) \
19996 +({ \
19997 + unsigned long ____x = (unsigned long)(x); \
19998 + if (____x < pax_user_shadow_base) \
19999 + ____x += pax_user_shadow_base; \
20000 + (typeof(x))____x; \
20001 +})
20002 +#else
20003 +#define ____m(x) (x)
20004 +#endif
20005 +#define __m(x) (*(struct __large_struct __user *)____m(x))
20006
20007 /*
20008 * Tell gcc we read from memory instead of writing: this is because
20009 @@ -420,8 +481,10 @@ struct __large_struct { unsigned long buf[100]; };
20010 * aliasing issues.
20011 */
20012 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
20013 +do { \
20014 + pax_open_userland(); \
20015 asm volatile(ASM_STAC "\n" \
20016 - "1: mov"itype" %"rtype"1,%2\n" \
20017 + "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
20018 "2: " ASM_CLAC "\n" \
20019 ".section .fixup,\"ax\"\n" \
20020 "3: mov %3,%0\n" \
20021 @@ -429,10 +492,12 @@ struct __large_struct { unsigned long buf[100]; };
20022 ".previous\n" \
20023 _ASM_EXTABLE(1b, 3b) \
20024 : "=r"(err) \
20025 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
20026 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
20027 + pax_close_userland(); \
20028 +} while (0)
20029
20030 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
20031 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
20032 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
20033 "2:\n" \
20034 _ASM_EXTABLE_EX(1b, 2b) \
20035 : : ltype(x), "m" (__m(addr)))
20036 @@ -442,11 +507,13 @@ struct __large_struct { unsigned long buf[100]; };
20037 */
20038 #define uaccess_try do { \
20039 current_thread_info()->uaccess_err = 0; \
20040 + pax_open_userland(); \
20041 stac(); \
20042 barrier();
20043
20044 #define uaccess_catch(err) \
20045 clac(); \
20046 + pax_close_userland(); \
20047 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
20048 } while (0)
20049
20050 @@ -471,8 +538,12 @@ struct __large_struct { unsigned long buf[100]; };
20051 * On error, the variable @x is set to zero.
20052 */
20053
20054 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20055 +#define __get_user(x, ptr) get_user((x), (ptr))
20056 +#else
20057 #define __get_user(x, ptr) \
20058 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
20059 +#endif
20060
20061 /**
20062 * __put_user: - Write a simple value into user space, with less checking.
20063 @@ -494,8 +565,12 @@ struct __large_struct { unsigned long buf[100]; };
20064 * Returns zero on success, or -EFAULT on error.
20065 */
20066
20067 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20068 +#define __put_user(x, ptr) put_user((x), (ptr))
20069 +#else
20070 #define __put_user(x, ptr) \
20071 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
20072 +#endif
20073
20074 #define __get_user_unaligned __get_user
20075 #define __put_user_unaligned __put_user
20076 @@ -513,7 +588,7 @@ struct __large_struct { unsigned long buf[100]; };
20077 #define get_user_ex(x, ptr) do { \
20078 unsigned long __gue_val; \
20079 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
20080 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
20081 + (x) = (__typeof__(*(ptr)))__gue_val; \
20082 } while (0)
20083
20084 #define put_user_try uaccess_try
20085 @@ -542,18 +617,19 @@ extern void __cmpxchg_wrong_size(void)
20086 __typeof__(ptr) __uval = (uval); \
20087 __typeof__(*(ptr)) __old = (old); \
20088 __typeof__(*(ptr)) __new = (new); \
20089 + pax_open_userland(); \
20090 switch (size) { \
20091 case 1: \
20092 { \
20093 asm volatile("\t" ASM_STAC "\n" \
20094 - "1:\t" LOCK_PREFIX "cmpxchgb %4, %2\n" \
20095 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgb %4, %2\n"\
20096 "2:\t" ASM_CLAC "\n" \
20097 "\t.section .fixup, \"ax\"\n" \
20098 "3:\tmov %3, %0\n" \
20099 "\tjmp 2b\n" \
20100 "\t.previous\n" \
20101 _ASM_EXTABLE(1b, 3b) \
20102 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
20103 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
20104 : "i" (-EFAULT), "q" (__new), "1" (__old) \
20105 : "memory" \
20106 ); \
20107 @@ -562,14 +638,14 @@ extern void __cmpxchg_wrong_size(void)
20108 case 2: \
20109 { \
20110 asm volatile("\t" ASM_STAC "\n" \
20111 - "1:\t" LOCK_PREFIX "cmpxchgw %4, %2\n" \
20112 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgw %4, %2\n"\
20113 "2:\t" ASM_CLAC "\n" \
20114 "\t.section .fixup, \"ax\"\n" \
20115 "3:\tmov %3, %0\n" \
20116 "\tjmp 2b\n" \
20117 "\t.previous\n" \
20118 _ASM_EXTABLE(1b, 3b) \
20119 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
20120 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
20121 : "i" (-EFAULT), "r" (__new), "1" (__old) \
20122 : "memory" \
20123 ); \
20124 @@ -578,14 +654,14 @@ extern void __cmpxchg_wrong_size(void)
20125 case 4: \
20126 { \
20127 asm volatile("\t" ASM_STAC "\n" \
20128 - "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n" \
20129 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"\
20130 "2:\t" ASM_CLAC "\n" \
20131 "\t.section .fixup, \"ax\"\n" \
20132 "3:\tmov %3, %0\n" \
20133 "\tjmp 2b\n" \
20134 "\t.previous\n" \
20135 _ASM_EXTABLE(1b, 3b) \
20136 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
20137 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
20138 : "i" (-EFAULT), "r" (__new), "1" (__old) \
20139 : "memory" \
20140 ); \
20141 @@ -597,14 +673,14 @@ extern void __cmpxchg_wrong_size(void)
20142 __cmpxchg_wrong_size(); \
20143 \
20144 asm volatile("\t" ASM_STAC "\n" \
20145 - "1:\t" LOCK_PREFIX "cmpxchgq %4, %2\n" \
20146 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgq %4, %2\n"\
20147 "2:\t" ASM_CLAC "\n" \
20148 "\t.section .fixup, \"ax\"\n" \
20149 "3:\tmov %3, %0\n" \
20150 "\tjmp 2b\n" \
20151 "\t.previous\n" \
20152 _ASM_EXTABLE(1b, 3b) \
20153 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
20154 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
20155 : "i" (-EFAULT), "r" (__new), "1" (__old) \
20156 : "memory" \
20157 ); \
20158 @@ -613,6 +689,7 @@ extern void __cmpxchg_wrong_size(void)
20159 default: \
20160 __cmpxchg_wrong_size(); \
20161 } \
20162 + pax_close_userland(); \
20163 *__uval = __old; \
20164 __ret; \
20165 })
20166 @@ -636,17 +713,6 @@ extern struct movsl_mask {
20167
20168 #define ARCH_HAS_NOCACHE_UACCESS 1
20169
20170 -#ifdef CONFIG_X86_32
20171 -# include <asm/uaccess_32.h>
20172 -#else
20173 -# include <asm/uaccess_64.h>
20174 -#endif
20175 -
20176 -unsigned long __must_check _copy_from_user(void *to, const void __user *from,
20177 - unsigned n);
20178 -unsigned long __must_check _copy_to_user(void __user *to, const void *from,
20179 - unsigned n);
20180 -
20181 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
20182 # define copy_user_diag __compiletime_error
20183 #else
20184 @@ -656,7 +722,7 @@ unsigned long __must_check _copy_to_user(void __user *to, const void *from,
20185 extern void copy_user_diag("copy_from_user() buffer size is too small")
20186 copy_from_user_overflow(void);
20187 extern void copy_user_diag("copy_to_user() buffer size is too small")
20188 -copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
20189 +copy_to_user_overflow(void);
20190
20191 #undef copy_user_diag
20192
20193 @@ -669,7 +735,7 @@ __copy_from_user_overflow(void) __asm__("copy_from_user_overflow");
20194
20195 extern void
20196 __compiletime_warning("copy_to_user() buffer size is not provably correct")
20197 -__copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
20198 +__copy_to_user_overflow(void) __asm__("copy_to_user_overflow");
20199 #define __copy_to_user_overflow(size, count) __copy_to_user_overflow()
20200
20201 #else
20202 @@ -684,10 +750,16 @@ __copy_from_user_overflow(int size, unsigned long count)
20203
20204 #endif
20205
20206 +#ifdef CONFIG_X86_32
20207 +# include <asm/uaccess_32.h>
20208 +#else
20209 +# include <asm/uaccess_64.h>
20210 +#endif
20211 +
20212 static inline unsigned long __must_check
20213 copy_from_user(void *to, const void __user *from, unsigned long n)
20214 {
20215 - int sz = __compiletime_object_size(to);
20216 + size_t sz = __compiletime_object_size(to);
20217
20218 might_fault();
20219
20220 @@ -709,12 +781,15 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
20221 * case, and do only runtime checking for non-constant sizes.
20222 */
20223
20224 - if (likely(sz < 0 || sz >= n))
20225 - n = _copy_from_user(to, from, n);
20226 - else if(__builtin_constant_p(n))
20227 - copy_from_user_overflow();
20228 - else
20229 - __copy_from_user_overflow(sz, n);
20230 + if (likely(sz != (size_t)-1 && sz < n)) {
20231 + if(__builtin_constant_p(n))
20232 + copy_from_user_overflow();
20233 + else
20234 + __copy_from_user_overflow(sz, n);
20235 + } else if (access_ok(VERIFY_READ, from, n))
20236 + n = __copy_from_user(to, from, n);
20237 + else if ((long)n > 0)
20238 + memset(to, 0, n);
20239
20240 return n;
20241 }
20242 @@ -722,17 +797,18 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
20243 static inline unsigned long __must_check
20244 copy_to_user(void __user *to, const void *from, unsigned long n)
20245 {
20246 - int sz = __compiletime_object_size(from);
20247 + size_t sz = __compiletime_object_size(from);
20248
20249 might_fault();
20250
20251 /* See the comment in copy_from_user() above. */
20252 - if (likely(sz < 0 || sz >= n))
20253 - n = _copy_to_user(to, from, n);
20254 - else if(__builtin_constant_p(n))
20255 - copy_to_user_overflow();
20256 - else
20257 - __copy_to_user_overflow(sz, n);
20258 + if (likely(sz != (size_t)-1 && sz < n)) {
20259 + if(__builtin_constant_p(n))
20260 + copy_to_user_overflow();
20261 + else
20262 + __copy_to_user_overflow(sz, n);
20263 + } else if (access_ok(VERIFY_WRITE, to, n))
20264 + n = __copy_to_user(to, from, n);
20265
20266 return n;
20267 }
20268 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
20269 index 3c03a5d..1071638 100644
20270 --- a/arch/x86/include/asm/uaccess_32.h
20271 +++ b/arch/x86/include/asm/uaccess_32.h
20272 @@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
20273 static __always_inline unsigned long __must_check
20274 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
20275 {
20276 + if ((long)n < 0)
20277 + return n;
20278 +
20279 + check_object_size(from, n, true);
20280 +
20281 if (__builtin_constant_p(n)) {
20282 unsigned long ret;
20283
20284 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
20285 __copy_to_user(void __user *to, const void *from, unsigned long n)
20286 {
20287 might_fault();
20288 +
20289 return __copy_to_user_inatomic(to, from, n);
20290 }
20291
20292 static __always_inline unsigned long
20293 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
20294 {
20295 + if ((long)n < 0)
20296 + return n;
20297 +
20298 /* Avoid zeroing the tail if the copy fails..
20299 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
20300 * but as the zeroing behaviour is only significant when n is not
20301 @@ -137,6 +146,12 @@ static __always_inline unsigned long
20302 __copy_from_user(void *to, const void __user *from, unsigned long n)
20303 {
20304 might_fault();
20305 +
20306 + if ((long)n < 0)
20307 + return n;
20308 +
20309 + check_object_size(to, n, false);
20310 +
20311 if (__builtin_constant_p(n)) {
20312 unsigned long ret;
20313
20314 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
20315 const void __user *from, unsigned long n)
20316 {
20317 might_fault();
20318 +
20319 + if ((long)n < 0)
20320 + return n;
20321 +
20322 if (__builtin_constant_p(n)) {
20323 unsigned long ret;
20324
20325 @@ -181,7 +200,10 @@ static __always_inline unsigned long
20326 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
20327 unsigned long n)
20328 {
20329 - return __copy_from_user_ll_nocache_nozero(to, from, n);
20330 + if ((long)n < 0)
20331 + return n;
20332 +
20333 + return __copy_from_user_ll_nocache_nozero(to, from, n);
20334 }
20335
20336 #endif /* _ASM_X86_UACCESS_32_H */
20337 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
20338 index 12a26b9..206c200 100644
20339 --- a/arch/x86/include/asm/uaccess_64.h
20340 +++ b/arch/x86/include/asm/uaccess_64.h
20341 @@ -10,6 +10,9 @@
20342 #include <asm/alternative.h>
20343 #include <asm/cpufeature.h>
20344 #include <asm/page.h>
20345 +#include <asm/pgtable.h>
20346 +
20347 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
20348
20349 /*
20350 * Copy To/From Userspace
20351 @@ -17,14 +20,14 @@
20352
20353 /* Handles exceptions in both to and from, but doesn't do access_ok */
20354 __must_check unsigned long
20355 -copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
20356 +copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
20357 __must_check unsigned long
20358 -copy_user_generic_string(void *to, const void *from, unsigned len);
20359 +copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
20360 __must_check unsigned long
20361 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
20362 +copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
20363
20364 static __always_inline __must_check unsigned long
20365 -copy_user_generic(void *to, const void *from, unsigned len)
20366 +copy_user_generic(void *to, const void *from, unsigned long len)
20367 {
20368 unsigned ret;
20369
20370 @@ -46,121 +49,170 @@ copy_user_generic(void *to, const void *from, unsigned len)
20371 }
20372
20373 __must_check unsigned long
20374 -copy_in_user(void __user *to, const void __user *from, unsigned len);
20375 +copy_in_user(void __user *to, const void __user *from, unsigned long len);
20376
20377 static __always_inline __must_check
20378 -int __copy_from_user_nocheck(void *dst, const void __user *src, unsigned size)
20379 +unsigned long __copy_from_user_nocheck(void *dst, const void __user *src, unsigned long size)
20380 {
20381 - int ret = 0;
20382 + size_t sz = __compiletime_object_size(dst);
20383 + unsigned ret = 0;
20384 +
20385 + if (size > INT_MAX)
20386 + return size;
20387 +
20388 + check_object_size(dst, size, false);
20389 +
20390 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20391 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20392 + return size;
20393 +#endif
20394 +
20395 + if (unlikely(sz != (size_t)-1 && sz < size)) {
20396 + if(__builtin_constant_p(size))
20397 + copy_from_user_overflow();
20398 + else
20399 + __copy_from_user_overflow(sz, size);
20400 + return size;
20401 + }
20402
20403 if (!__builtin_constant_p(size))
20404 - return copy_user_generic(dst, (__force void *)src, size);
20405 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
20406 switch (size) {
20407 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
20408 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
20409 ret, "b", "b", "=q", 1);
20410 return ret;
20411 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
20412 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
20413 ret, "w", "w", "=r", 2);
20414 return ret;
20415 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
20416 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
20417 ret, "l", "k", "=r", 4);
20418 return ret;
20419 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
20420 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20421 ret, "q", "", "=r", 8);
20422 return ret;
20423 case 10:
20424 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
20425 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20426 ret, "q", "", "=r", 10);
20427 if (unlikely(ret))
20428 return ret;
20429 __get_user_asm(*(u16 *)(8 + (char *)dst),
20430 - (u16 __user *)(8 + (char __user *)src),
20431 + (const u16 __user *)(8 + (const char __user *)src),
20432 ret, "w", "w", "=r", 2);
20433 return ret;
20434 case 16:
20435 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
20436 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20437 ret, "q", "", "=r", 16);
20438 if (unlikely(ret))
20439 return ret;
20440 __get_user_asm(*(u64 *)(8 + (char *)dst),
20441 - (u64 __user *)(8 + (char __user *)src),
20442 + (const u64 __user *)(8 + (const char __user *)src),
20443 ret, "q", "", "=r", 8);
20444 return ret;
20445 default:
20446 - return copy_user_generic(dst, (__force void *)src, size);
20447 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
20448 }
20449 }
20450
20451 static __always_inline __must_check
20452 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
20453 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
20454 {
20455 might_fault();
20456 return __copy_from_user_nocheck(dst, src, size);
20457 }
20458
20459 static __always_inline __must_check
20460 -int __copy_to_user_nocheck(void __user *dst, const void *src, unsigned size)
20461 +unsigned long __copy_to_user_nocheck(void __user *dst, const void *src, unsigned long size)
20462 {
20463 - int ret = 0;
20464 + size_t sz = __compiletime_object_size(src);
20465 + unsigned ret = 0;
20466 +
20467 + if (size > INT_MAX)
20468 + return size;
20469 +
20470 + check_object_size(src, size, true);
20471 +
20472 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20473 + if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
20474 + return size;
20475 +#endif
20476 +
20477 + if (unlikely(sz != (size_t)-1 && sz < size)) {
20478 + if(__builtin_constant_p(size))
20479 + copy_to_user_overflow();
20480 + else
20481 + __copy_to_user_overflow(sz, size);
20482 + return size;
20483 + }
20484
20485 if (!__builtin_constant_p(size))
20486 - return copy_user_generic((__force void *)dst, src, size);
20487 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
20488 switch (size) {
20489 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
20490 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
20491 ret, "b", "b", "iq", 1);
20492 return ret;
20493 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
20494 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
20495 ret, "w", "w", "ir", 2);
20496 return ret;
20497 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
20498 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
20499 ret, "l", "k", "ir", 4);
20500 return ret;
20501 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
20502 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20503 ret, "q", "", "er", 8);
20504 return ret;
20505 case 10:
20506 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
20507 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20508 ret, "q", "", "er", 10);
20509 if (unlikely(ret))
20510 return ret;
20511 asm("":::"memory");
20512 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
20513 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
20514 ret, "w", "w", "ir", 2);
20515 return ret;
20516 case 16:
20517 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
20518 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20519 ret, "q", "", "er", 16);
20520 if (unlikely(ret))
20521 return ret;
20522 asm("":::"memory");
20523 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
20524 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
20525 ret, "q", "", "er", 8);
20526 return ret;
20527 default:
20528 - return copy_user_generic((__force void *)dst, src, size);
20529 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
20530 }
20531 }
20532
20533 static __always_inline __must_check
20534 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
20535 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
20536 {
20537 might_fault();
20538 return __copy_to_user_nocheck(dst, src, size);
20539 }
20540
20541 static __always_inline __must_check
20542 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20543 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20544 {
20545 - int ret = 0;
20546 + unsigned ret = 0;
20547
20548 might_fault();
20549 +
20550 + if (size > INT_MAX)
20551 + return size;
20552 +
20553 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20554 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20555 + return size;
20556 + if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
20557 + return size;
20558 +#endif
20559 +
20560 if (!__builtin_constant_p(size))
20561 - return copy_user_generic((__force void *)dst,
20562 - (__force void *)src, size);
20563 + return copy_user_generic((__force_kernel void *)____m(dst),
20564 + (__force_kernel const void *)____m(src), size);
20565 switch (size) {
20566 case 1: {
20567 u8 tmp;
20568 - __get_user_asm(tmp, (u8 __user *)src,
20569 + __get_user_asm(tmp, (const u8 __user *)src,
20570 ret, "b", "b", "=q", 1);
20571 if (likely(!ret))
20572 __put_user_asm(tmp, (u8 __user *)dst,
20573 @@ -169,7 +221,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20574 }
20575 case 2: {
20576 u16 tmp;
20577 - __get_user_asm(tmp, (u16 __user *)src,
20578 + __get_user_asm(tmp, (const u16 __user *)src,
20579 ret, "w", "w", "=r", 2);
20580 if (likely(!ret))
20581 __put_user_asm(tmp, (u16 __user *)dst,
20582 @@ -179,7 +231,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20583
20584 case 4: {
20585 u32 tmp;
20586 - __get_user_asm(tmp, (u32 __user *)src,
20587 + __get_user_asm(tmp, (const u32 __user *)src,
20588 ret, "l", "k", "=r", 4);
20589 if (likely(!ret))
20590 __put_user_asm(tmp, (u32 __user *)dst,
20591 @@ -188,7 +240,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20592 }
20593 case 8: {
20594 u64 tmp;
20595 - __get_user_asm(tmp, (u64 __user *)src,
20596 + __get_user_asm(tmp, (const u64 __user *)src,
20597 ret, "q", "", "=r", 8);
20598 if (likely(!ret))
20599 __put_user_asm(tmp, (u64 __user *)dst,
20600 @@ -196,41 +248,58 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20601 return ret;
20602 }
20603 default:
20604 - return copy_user_generic((__force void *)dst,
20605 - (__force void *)src, size);
20606 + return copy_user_generic((__force_kernel void *)____m(dst),
20607 + (__force_kernel const void *)____m(src), size);
20608 }
20609 }
20610
20611 -static __must_check __always_inline int
20612 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
20613 +static __must_check __always_inline unsigned long
20614 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
20615 {
20616 return __copy_from_user_nocheck(dst, src, size);
20617 }
20618
20619 -static __must_check __always_inline int
20620 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
20621 +static __must_check __always_inline unsigned long
20622 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
20623 {
20624 return __copy_to_user_nocheck(dst, src, size);
20625 }
20626
20627 -extern long __copy_user_nocache(void *dst, const void __user *src,
20628 - unsigned size, int zerorest);
20629 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
20630 + unsigned long size, int zerorest);
20631
20632 -static inline int
20633 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
20634 +static inline unsigned long
20635 +__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
20636 {
20637 might_fault();
20638 +
20639 + if (size > INT_MAX)
20640 + return size;
20641 +
20642 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20643 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20644 + return size;
20645 +#endif
20646 +
20647 return __copy_user_nocache(dst, src, size, 1);
20648 }
20649
20650 -static inline int
20651 +static inline unsigned long
20652 __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
20653 - unsigned size)
20654 + unsigned long size)
20655 {
20656 + if (size > INT_MAX)
20657 + return size;
20658 +
20659 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20660 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20661 + return size;
20662 +#endif
20663 +
20664 return __copy_user_nocache(dst, src, size, 0);
20665 }
20666
20667 unsigned long
20668 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
20669 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
20670
20671 #endif /* _ASM_X86_UACCESS_64_H */
20672 diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
20673 index 5b238981..77fdd78 100644
20674 --- a/arch/x86/include/asm/word-at-a-time.h
20675 +++ b/arch/x86/include/asm/word-at-a-time.h
20676 @@ -11,7 +11,7 @@
20677 * and shift, for example.
20678 */
20679 struct word_at_a_time {
20680 - const unsigned long one_bits, high_bits;
20681 + unsigned long one_bits, high_bits;
20682 };
20683
20684 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
20685 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
20686 index e45e4da..44e8572 100644
20687 --- a/arch/x86/include/asm/x86_init.h
20688 +++ b/arch/x86/include/asm/x86_init.h
20689 @@ -129,7 +129,7 @@ struct x86_init_ops {
20690 struct x86_init_timers timers;
20691 struct x86_init_iommu iommu;
20692 struct x86_init_pci pci;
20693 -};
20694 +} __no_const;
20695
20696 /**
20697 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
20698 @@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
20699 void (*setup_percpu_clockev)(void);
20700 void (*early_percpu_clock_init)(void);
20701 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
20702 -};
20703 +} __no_const;
20704
20705 struct timespec;
20706
20707 @@ -168,7 +168,7 @@ struct x86_platform_ops {
20708 void (*save_sched_clock_state)(void);
20709 void (*restore_sched_clock_state)(void);
20710 void (*apic_post_init)(void);
20711 -};
20712 +} __no_const;
20713
20714 struct pci_dev;
20715 struct msi_msg;
20716 @@ -185,7 +185,7 @@ struct x86_msi_ops {
20717 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
20718 u32 (*msi_mask_irq)(struct msi_desc *desc, u32 mask, u32 flag);
20719 u32 (*msix_mask_irq)(struct msi_desc *desc, u32 flag);
20720 -};
20721 +} __no_const;
20722
20723 struct IO_APIC_route_entry;
20724 struct io_apic_irq_attr;
20725 @@ -206,7 +206,7 @@ struct x86_io_apic_ops {
20726 unsigned int destination, int vector,
20727 struct io_apic_irq_attr *attr);
20728 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
20729 -};
20730 +} __no_const;
20731
20732 extern struct x86_init_ops x86_init;
20733 extern struct x86_cpuinit_ops x86_cpuinit;
20734 diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
20735 index c949923..c22bfa4 100644
20736 --- a/arch/x86/include/asm/xen/page.h
20737 +++ b/arch/x86/include/asm/xen/page.h
20738 @@ -63,7 +63,7 @@ extern int m2p_remove_override(struct page *page,
20739 extern struct page *m2p_find_override(unsigned long mfn);
20740 extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn);
20741
20742 -static inline unsigned long pfn_to_mfn(unsigned long pfn)
20743 +static inline unsigned long __intentional_overflow(-1) pfn_to_mfn(unsigned long pfn)
20744 {
20745 unsigned long mfn;
20746
20747 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
20748 index d949ef2..479b9d1 100644
20749 --- a/arch/x86/include/asm/xsave.h
20750 +++ b/arch/x86/include/asm/xsave.h
20751 @@ -82,8 +82,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20752 if (unlikely(err))
20753 return -EFAULT;
20754
20755 + pax_open_userland();
20756 __asm__ __volatile__(ASM_STAC "\n"
20757 - "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
20758 + "1:"
20759 + __copyuser_seg
20760 + ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
20761 "2: " ASM_CLAC "\n"
20762 ".section .fixup,\"ax\"\n"
20763 "3: movl $-1,%[err]\n"
20764 @@ -93,18 +96,22 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20765 : [err] "=r" (err)
20766 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
20767 : "memory");
20768 + pax_close_userland();
20769 return err;
20770 }
20771
20772 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20773 {
20774 int err;
20775 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
20776 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
20777 u32 lmask = mask;
20778 u32 hmask = mask >> 32;
20779
20780 + pax_open_userland();
20781 __asm__ __volatile__(ASM_STAC "\n"
20782 - "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
20783 + "1:"
20784 + __copyuser_seg
20785 + ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
20786 "2: " ASM_CLAC "\n"
20787 ".section .fixup,\"ax\"\n"
20788 "3: movl $-1,%[err]\n"
20789 @@ -114,6 +121,7 @@ static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20790 : [err] "=r" (err)
20791 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
20792 : "memory"); /* memory required? */
20793 + pax_close_userland();
20794 return err;
20795 }
20796
20797 diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
20798 index bbae024..e1528f9 100644
20799 --- a/arch/x86/include/uapi/asm/e820.h
20800 +++ b/arch/x86/include/uapi/asm/e820.h
20801 @@ -63,7 +63,7 @@ struct e820map {
20802 #define ISA_START_ADDRESS 0xa0000
20803 #define ISA_END_ADDRESS 0x100000
20804
20805 -#define BIOS_BEGIN 0x000a0000
20806 +#define BIOS_BEGIN 0x000c0000
20807 #define BIOS_END 0x00100000
20808
20809 #define BIOS_ROM_BASE 0xffe00000
20810 diff --git a/arch/x86/include/uapi/asm/ptrace-abi.h b/arch/x86/include/uapi/asm/ptrace-abi.h
20811 index 7b0a55a..ad115bf 100644
20812 --- a/arch/x86/include/uapi/asm/ptrace-abi.h
20813 +++ b/arch/x86/include/uapi/asm/ptrace-abi.h
20814 @@ -49,7 +49,6 @@
20815 #define EFLAGS 144
20816 #define RSP 152
20817 #define SS 160
20818 -#define ARGOFFSET R11
20819 #endif /* __ASSEMBLY__ */
20820
20821 /* top of stack page */
20822 diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
20823 index 047f9ff..4ba5ea6 100644
20824 --- a/arch/x86/kernel/Makefile
20825 +++ b/arch/x86/kernel/Makefile
20826 @@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
20827 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
20828 obj-$(CONFIG_IRQ_WORK) += irq_work.o
20829 obj-y += probe_roms.o
20830 -obj-$(CONFIG_X86_32) += i386_ksyms_32.o
20831 +obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
20832 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
20833 obj-$(CONFIG_X86_64) += mcount_64.o
20834 obj-y += syscall_$(BITS).o vsyscall_gtod.o
20835 diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
20836 index 86281ff..e046fc2 100644
20837 --- a/arch/x86/kernel/acpi/boot.c
20838 +++ b/arch/x86/kernel/acpi/boot.c
20839 @@ -1296,7 +1296,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
20840 * If your system is blacklisted here, but you find that acpi=force
20841 * works for you, please contact linux-acpi@vger.kernel.org
20842 */
20843 -static struct dmi_system_id __initdata acpi_dmi_table[] = {
20844 +static const struct dmi_system_id __initconst acpi_dmi_table[] = {
20845 /*
20846 * Boxes that need ACPI disabled
20847 */
20848 @@ -1371,7 +1371,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
20849 };
20850
20851 /* second table for DMI checks that should run after early-quirks */
20852 -static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
20853 +static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
20854 /*
20855 * HP laptops which use a DSDT reporting as HP/SB400/10000,
20856 * which includes some code which overrides all temperature
20857 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
20858 index 3136820..e2c6577 100644
20859 --- a/arch/x86/kernel/acpi/sleep.c
20860 +++ b/arch/x86/kernel/acpi/sleep.c
20861 @@ -99,8 +99,12 @@ int x86_acpi_suspend_lowlevel(void)
20862 #else /* CONFIG_64BIT */
20863 #ifdef CONFIG_SMP
20864 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
20865 +
20866 + pax_open_kernel();
20867 early_gdt_descr.address =
20868 (unsigned long)get_cpu_gdt_table(smp_processor_id());
20869 + pax_close_kernel();
20870 +
20871 initial_gs = per_cpu_offset(smp_processor_id());
20872 #endif
20873 initial_code = (unsigned long)wakeup_long64;
20874 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
20875 index 665c6b7..eae4d56 100644
20876 --- a/arch/x86/kernel/acpi/wakeup_32.S
20877 +++ b/arch/x86/kernel/acpi/wakeup_32.S
20878 @@ -29,13 +29,11 @@ wakeup_pmode_return:
20879 # and restore the stack ... but you need gdt for this to work
20880 movl saved_context_esp, %esp
20881
20882 - movl %cs:saved_magic, %eax
20883 - cmpl $0x12345678, %eax
20884 + cmpl $0x12345678, saved_magic
20885 jne bogus_magic
20886
20887 # jump to place where we left off
20888 - movl saved_eip, %eax
20889 - jmp *%eax
20890 + jmp *(saved_eip)
20891
20892 bogus_magic:
20893 jmp bogus_magic
20894 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
20895 index 703130f..27a155d 100644
20896 --- a/arch/x86/kernel/alternative.c
20897 +++ b/arch/x86/kernel/alternative.c
20898 @@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
20899 */
20900 for (a = start; a < end; a++) {
20901 instr = (u8 *)&a->instr_offset + a->instr_offset;
20902 +
20903 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20904 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20905 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
20906 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20907 +#endif
20908 +
20909 replacement = (u8 *)&a->repl_offset + a->repl_offset;
20910 BUG_ON(a->replacementlen > a->instrlen);
20911 BUG_ON(a->instrlen > sizeof(insnbuf));
20912 @@ -284,6 +291,11 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
20913 add_nops(insnbuf + a->replacementlen,
20914 a->instrlen - a->replacementlen);
20915
20916 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20917 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
20918 + instr = ktva_ktla(instr);
20919 +#endif
20920 +
20921 text_poke_early(instr, insnbuf, a->instrlen);
20922 }
20923 }
20924 @@ -299,10 +311,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
20925 for (poff = start; poff < end; poff++) {
20926 u8 *ptr = (u8 *)poff + *poff;
20927
20928 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20929 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20930 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20931 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20932 +#endif
20933 +
20934 if (!*poff || ptr < text || ptr >= text_end)
20935 continue;
20936 /* turn DS segment override prefix into lock prefix */
20937 - if (*ptr == 0x3e)
20938 + if (*ktla_ktva(ptr) == 0x3e)
20939 text_poke(ptr, ((unsigned char []){0xf0}), 1);
20940 }
20941 mutex_unlock(&text_mutex);
20942 @@ -317,10 +335,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
20943 for (poff = start; poff < end; poff++) {
20944 u8 *ptr = (u8 *)poff + *poff;
20945
20946 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20947 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20948 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20949 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20950 +#endif
20951 +
20952 if (!*poff || ptr < text || ptr >= text_end)
20953 continue;
20954 /* turn lock prefix into DS segment override prefix */
20955 - if (*ptr == 0xf0)
20956 + if (*ktla_ktva(ptr) == 0xf0)
20957 text_poke(ptr, ((unsigned char []){0x3E}), 1);
20958 }
20959 mutex_unlock(&text_mutex);
20960 @@ -457,7 +481,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
20961
20962 BUG_ON(p->len > MAX_PATCH_LEN);
20963 /* prep the buffer with the original instructions */
20964 - memcpy(insnbuf, p->instr, p->len);
20965 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
20966 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
20967 (unsigned long)p->instr, p->len);
20968
20969 @@ -504,7 +528,7 @@ void __init alternative_instructions(void)
20970 if (!uniproc_patched || num_possible_cpus() == 1)
20971 free_init_pages("SMP alternatives",
20972 (unsigned long)__smp_locks,
20973 - (unsigned long)__smp_locks_end);
20974 + PAGE_ALIGN((unsigned long)__smp_locks_end));
20975 #endif
20976
20977 apply_paravirt(__parainstructions, __parainstructions_end);
20978 @@ -524,13 +548,17 @@ void __init alternative_instructions(void)
20979 * instructions. And on the local CPU you need to be protected again NMI or MCE
20980 * handlers seeing an inconsistent instruction while you patch.
20981 */
20982 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
20983 +void *__kprobes text_poke_early(void *addr, const void *opcode,
20984 size_t len)
20985 {
20986 unsigned long flags;
20987 local_irq_save(flags);
20988 - memcpy(addr, opcode, len);
20989 +
20990 + pax_open_kernel();
20991 + memcpy(ktla_ktva(addr), opcode, len);
20992 sync_core();
20993 + pax_close_kernel();
20994 +
20995 local_irq_restore(flags);
20996 /* Could also do a CLFLUSH here to speed up CPU recovery; but
20997 that causes hangs on some VIA CPUs. */
20998 @@ -552,36 +580,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
20999 */
21000 void *text_poke(void *addr, const void *opcode, size_t len)
21001 {
21002 - unsigned long flags;
21003 - char *vaddr;
21004 + unsigned char *vaddr = ktla_ktva(addr);
21005 struct page *pages[2];
21006 - int i;
21007 + size_t i;
21008
21009 if (!core_kernel_text((unsigned long)addr)) {
21010 - pages[0] = vmalloc_to_page(addr);
21011 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
21012 + pages[0] = vmalloc_to_page(vaddr);
21013 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
21014 } else {
21015 - pages[0] = virt_to_page(addr);
21016 + pages[0] = virt_to_page(vaddr);
21017 WARN_ON(!PageReserved(pages[0]));
21018 - pages[1] = virt_to_page(addr + PAGE_SIZE);
21019 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
21020 }
21021 BUG_ON(!pages[0]);
21022 - local_irq_save(flags);
21023 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
21024 - if (pages[1])
21025 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
21026 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
21027 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
21028 - clear_fixmap(FIX_TEXT_POKE0);
21029 - if (pages[1])
21030 - clear_fixmap(FIX_TEXT_POKE1);
21031 - local_flush_tlb();
21032 - sync_core();
21033 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
21034 - that causes hangs on some VIA CPUs. */
21035 + text_poke_early(addr, opcode, len);
21036 for (i = 0; i < len; i++)
21037 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
21038 - local_irq_restore(flags);
21039 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
21040 return addr;
21041 }
21042
21043 @@ -601,7 +615,7 @@ int poke_int3_handler(struct pt_regs *regs)
21044 if (likely(!bp_patching_in_progress))
21045 return 0;
21046
21047 - if (user_mode_vm(regs) || regs->ip != (unsigned long)bp_int3_addr)
21048 + if (user_mode(regs) || regs->ip != (unsigned long)bp_int3_addr)
21049 return 0;
21050
21051 /* set up the specified breakpoint handler */
21052 @@ -635,7 +649,7 @@ int poke_int3_handler(struct pt_regs *regs)
21053 */
21054 void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler)
21055 {
21056 - unsigned char int3 = 0xcc;
21057 + const unsigned char int3 = 0xcc;
21058
21059 bp_int3_handler = handler;
21060 bp_int3_addr = (u8 *)addr + sizeof(int3);
21061 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
21062 index ad28db7..c538b2c 100644
21063 --- a/arch/x86/kernel/apic/apic.c
21064 +++ b/arch/x86/kernel/apic/apic.c
21065 @@ -201,7 +201,7 @@ int first_system_vector = 0xfe;
21066 /*
21067 * Debug level, exported for io_apic.c
21068 */
21069 -unsigned int apic_verbosity;
21070 +int apic_verbosity;
21071
21072 int pic_mode;
21073
21074 @@ -2000,7 +2000,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
21075 apic_write(APIC_ESR, 0);
21076 v = apic_read(APIC_ESR);
21077 ack_APIC_irq();
21078 - atomic_inc(&irq_err_count);
21079 + atomic_inc_unchecked(&irq_err_count);
21080
21081 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x",
21082 smp_processor_id(), v);
21083 diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
21084 index 7c1b294..e71d27f 100644
21085 --- a/arch/x86/kernel/apic/apic_flat_64.c
21086 +++ b/arch/x86/kernel/apic/apic_flat_64.c
21087 @@ -154,7 +154,7 @@ static int flat_probe(void)
21088 return 1;
21089 }
21090
21091 -static struct apic apic_flat = {
21092 +static struct apic apic_flat __read_only = {
21093 .name = "flat",
21094 .probe = flat_probe,
21095 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
21096 @@ -268,7 +268,7 @@ static int physflat_probe(void)
21097 return 0;
21098 }
21099
21100 -static struct apic apic_physflat = {
21101 +static struct apic apic_physflat __read_only = {
21102
21103 .name = "physical flat",
21104 .probe = physflat_probe,
21105 diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
21106 index 8c7c982..a225910 100644
21107 --- a/arch/x86/kernel/apic/apic_noop.c
21108 +++ b/arch/x86/kernel/apic/apic_noop.c
21109 @@ -118,7 +118,7 @@ static void noop_apic_write(u32 reg, u32 v)
21110 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
21111 }
21112
21113 -struct apic apic_noop = {
21114 +struct apic apic_noop __read_only = {
21115 .name = "noop",
21116 .probe = noop_probe,
21117 .acpi_madt_oem_check = NULL,
21118 diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
21119 index e4840aa..e7d9dac 100644
21120 --- a/arch/x86/kernel/apic/bigsmp_32.c
21121 +++ b/arch/x86/kernel/apic/bigsmp_32.c
21122 @@ -152,7 +152,7 @@ static int probe_bigsmp(void)
21123 return dmi_bigsmp;
21124 }
21125
21126 -static struct apic apic_bigsmp = {
21127 +static struct apic apic_bigsmp __read_only = {
21128
21129 .name = "bigsmp",
21130 .probe = probe_bigsmp,
21131 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
21132 index 81e08ef..abc77e5 100644
21133 --- a/arch/x86/kernel/apic/io_apic.c
21134 +++ b/arch/x86/kernel/apic/io_apic.c
21135 @@ -1042,7 +1042,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
21136 }
21137 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
21138
21139 -void lock_vector_lock(void)
21140 +void lock_vector_lock(void) __acquires(vector_lock)
21141 {
21142 /* Used to the online set of cpus does not change
21143 * during assign_irq_vector.
21144 @@ -1050,7 +1050,7 @@ void lock_vector_lock(void)
21145 raw_spin_lock(&vector_lock);
21146 }
21147
21148 -void unlock_vector_lock(void)
21149 +void unlock_vector_lock(void) __releases(vector_lock)
21150 {
21151 raw_spin_unlock(&vector_lock);
21152 }
21153 @@ -2349,7 +2349,7 @@ static void ack_apic_edge(struct irq_data *data)
21154 ack_APIC_irq();
21155 }
21156
21157 -atomic_t irq_mis_count;
21158 +atomic_unchecked_t irq_mis_count;
21159
21160 #ifdef CONFIG_GENERIC_PENDING_IRQ
21161 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
21162 @@ -2490,7 +2490,7 @@ static void ack_apic_level(struct irq_data *data)
21163 * at the cpu.
21164 */
21165 if (!(v & (1 << (i & 0x1f)))) {
21166 - atomic_inc(&irq_mis_count);
21167 + atomic_inc_unchecked(&irq_mis_count);
21168
21169 eoi_ioapic_irq(irq, cfg);
21170 }
21171 diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
21172 index cceb352..a635fd8 100644
21173 --- a/arch/x86/kernel/apic/probe_32.c
21174 +++ b/arch/x86/kernel/apic/probe_32.c
21175 @@ -72,7 +72,7 @@ static int probe_default(void)
21176 return 1;
21177 }
21178
21179 -static struct apic apic_default = {
21180 +static struct apic apic_default __read_only = {
21181
21182 .name = "default",
21183 .probe = probe_default,
21184 diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
21185 index e66766b..1c008ba 100644
21186 --- a/arch/x86/kernel/apic/x2apic_cluster.c
21187 +++ b/arch/x86/kernel/apic/x2apic_cluster.c
21188 @@ -182,7 +182,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
21189 return notifier_from_errno(err);
21190 }
21191
21192 -static struct notifier_block __refdata x2apic_cpu_notifier = {
21193 +static struct notifier_block x2apic_cpu_notifier = {
21194 .notifier_call = update_clusterinfo,
21195 };
21196
21197 @@ -234,7 +234,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
21198 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
21199 }
21200
21201 -static struct apic apic_x2apic_cluster = {
21202 +static struct apic apic_x2apic_cluster __read_only = {
21203
21204 .name = "cluster x2apic",
21205 .probe = x2apic_cluster_probe,
21206 diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
21207 index 6d600eb..0300c00 100644
21208 --- a/arch/x86/kernel/apic/x2apic_phys.c
21209 +++ b/arch/x86/kernel/apic/x2apic_phys.c
21210 @@ -88,7 +88,7 @@ static int x2apic_phys_probe(void)
21211 return apic == &apic_x2apic_phys;
21212 }
21213
21214 -static struct apic apic_x2apic_phys = {
21215 +static struct apic apic_x2apic_phys __read_only = {
21216
21217 .name = "physical x2apic",
21218 .probe = x2apic_phys_probe,
21219 diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
21220 index 293b41d..4df25fd 100644
21221 --- a/arch/x86/kernel/apic/x2apic_uv_x.c
21222 +++ b/arch/x86/kernel/apic/x2apic_uv_x.c
21223 @@ -350,7 +350,7 @@ static int uv_probe(void)
21224 return apic == &apic_x2apic_uv_x;
21225 }
21226
21227 -static struct apic __refdata apic_x2apic_uv_x = {
21228 +static struct apic apic_x2apic_uv_x __read_only = {
21229
21230 .name = "UV large system",
21231 .probe = uv_probe,
21232 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
21233 index 5848744..56cb598 100644
21234 --- a/arch/x86/kernel/apm_32.c
21235 +++ b/arch/x86/kernel/apm_32.c
21236 @@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
21237 * This is for buggy BIOS's that refer to (real mode) segment 0x40
21238 * even though they are called in protected mode.
21239 */
21240 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
21241 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
21242 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
21243
21244 static const char driver_version[] = "1.16ac"; /* no spaces */
21245 @@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
21246 BUG_ON(cpu != 0);
21247 gdt = get_cpu_gdt_table(cpu);
21248 save_desc_40 = gdt[0x40 / 8];
21249 +
21250 + pax_open_kernel();
21251 gdt[0x40 / 8] = bad_bios_desc;
21252 + pax_close_kernel();
21253
21254 apm_irq_save(flags);
21255 APM_DO_SAVE_SEGS;
21256 @@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
21257 &call->esi);
21258 APM_DO_RESTORE_SEGS;
21259 apm_irq_restore(flags);
21260 +
21261 + pax_open_kernel();
21262 gdt[0x40 / 8] = save_desc_40;
21263 + pax_close_kernel();
21264 +
21265 put_cpu();
21266
21267 return call->eax & 0xff;
21268 @@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
21269 BUG_ON(cpu != 0);
21270 gdt = get_cpu_gdt_table(cpu);
21271 save_desc_40 = gdt[0x40 / 8];
21272 +
21273 + pax_open_kernel();
21274 gdt[0x40 / 8] = bad_bios_desc;
21275 + pax_close_kernel();
21276
21277 apm_irq_save(flags);
21278 APM_DO_SAVE_SEGS;
21279 @@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
21280 &call->eax);
21281 APM_DO_RESTORE_SEGS;
21282 apm_irq_restore(flags);
21283 +
21284 + pax_open_kernel();
21285 gdt[0x40 / 8] = save_desc_40;
21286 + pax_close_kernel();
21287 +
21288 put_cpu();
21289 return error;
21290 }
21291 @@ -2350,12 +2364,15 @@ static int __init apm_init(void)
21292 * code to that CPU.
21293 */
21294 gdt = get_cpu_gdt_table(0);
21295 +
21296 + pax_open_kernel();
21297 set_desc_base(&gdt[APM_CS >> 3],
21298 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
21299 set_desc_base(&gdt[APM_CS_16 >> 3],
21300 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
21301 set_desc_base(&gdt[APM_DS >> 3],
21302 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
21303 + pax_close_kernel();
21304
21305 proc_create("apm", 0, NULL, &apm_file_ops);
21306
21307 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
21308 index 9f6b934..cf5ffb3 100644
21309 --- a/arch/x86/kernel/asm-offsets.c
21310 +++ b/arch/x86/kernel/asm-offsets.c
21311 @@ -32,6 +32,8 @@ void common(void) {
21312 OFFSET(TI_flags, thread_info, flags);
21313 OFFSET(TI_status, thread_info, status);
21314 OFFSET(TI_addr_limit, thread_info, addr_limit);
21315 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
21316 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
21317
21318 BLANK();
21319 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
21320 @@ -52,8 +54,26 @@ void common(void) {
21321 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
21322 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
21323 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
21324 +
21325 +#ifdef CONFIG_PAX_KERNEXEC
21326 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
21327 #endif
21328
21329 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21330 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
21331 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
21332 +#ifdef CONFIG_X86_64
21333 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
21334 +#endif
21335 +#endif
21336 +
21337 +#endif
21338 +
21339 + BLANK();
21340 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
21341 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
21342 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
21343 +
21344 #ifdef CONFIG_XEN
21345 BLANK();
21346 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
21347 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
21348 index e7c798b..2b2019b 100644
21349 --- a/arch/x86/kernel/asm-offsets_64.c
21350 +++ b/arch/x86/kernel/asm-offsets_64.c
21351 @@ -77,6 +77,7 @@ int main(void)
21352 BLANK();
21353 #undef ENTRY
21354
21355 + DEFINE(TSS_size, sizeof(struct tss_struct));
21356 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
21357 BLANK();
21358
21359 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
21360 index 7fd54f0..0691410 100644
21361 --- a/arch/x86/kernel/cpu/Makefile
21362 +++ b/arch/x86/kernel/cpu/Makefile
21363 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
21364 CFLAGS_REMOVE_perf_event.o = -pg
21365 endif
21366
21367 -# Make sure load_percpu_segment has no stackprotector
21368 -nostackp := $(call cc-option, -fno-stack-protector)
21369 -CFLAGS_common.o := $(nostackp)
21370 -
21371 obj-y := intel_cacheinfo.o scattered.o topology.o
21372 obj-y += proc.o capflags.o powerflags.o common.o
21373 obj-y += rdrand.o
21374 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
21375 index ce8b8ff..d7d8851 100644
21376 --- a/arch/x86/kernel/cpu/amd.c
21377 +++ b/arch/x86/kernel/cpu/amd.c
21378 @@ -728,7 +728,7 @@ static void init_amd(struct cpuinfo_x86 *c)
21379 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
21380 {
21381 /* AMD errata T13 (order #21922) */
21382 - if ((c->x86 == 6)) {
21383 + if (c->x86 == 6) {
21384 /* Duron Rev A0 */
21385 if (c->x86_model == 3 && c->x86_mask == 0)
21386 size = 64;
21387 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
21388 index ef1b93f..150db65 100644
21389 --- a/arch/x86/kernel/cpu/common.c
21390 +++ b/arch/x86/kernel/cpu/common.c
21391 @@ -90,60 +90,6 @@ static const struct cpu_dev default_cpu = {
21392
21393 static const struct cpu_dev *this_cpu = &default_cpu;
21394
21395 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
21396 -#ifdef CONFIG_X86_64
21397 - /*
21398 - * We need valid kernel segments for data and code in long mode too
21399 - * IRET will check the segment types kkeil 2000/10/28
21400 - * Also sysret mandates a special GDT layout
21401 - *
21402 - * TLS descriptors are currently at a different place compared to i386.
21403 - * Hopefully nobody expects them at a fixed place (Wine?)
21404 - */
21405 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
21406 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
21407 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
21408 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
21409 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
21410 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
21411 -#else
21412 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
21413 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21414 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
21415 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
21416 - /*
21417 - * Segments used for calling PnP BIOS have byte granularity.
21418 - * They code segments and data segments have fixed 64k limits,
21419 - * the transfer segment sizes are set at run time.
21420 - */
21421 - /* 32-bit code */
21422 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
21423 - /* 16-bit code */
21424 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
21425 - /* 16-bit data */
21426 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
21427 - /* 16-bit data */
21428 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
21429 - /* 16-bit data */
21430 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
21431 - /*
21432 - * The APM segments have byte granularity and their bases
21433 - * are set at run time. All have 64k limits.
21434 - */
21435 - /* 32-bit code */
21436 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
21437 - /* 16-bit code */
21438 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
21439 - /* data */
21440 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
21441 -
21442 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21443 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21444 - GDT_STACK_CANARY_INIT
21445 -#endif
21446 -} };
21447 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
21448 -
21449 static int __init x86_xsave_setup(char *s)
21450 {
21451 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
21452 @@ -295,6 +241,59 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
21453 }
21454 }
21455
21456 +#ifdef CONFIG_X86_64
21457 +static __init int setup_disable_pcid(char *arg)
21458 +{
21459 + setup_clear_cpu_cap(X86_FEATURE_PCID);
21460 + setup_clear_cpu_cap(X86_FEATURE_INVPCID);
21461 +
21462 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21463 + if (clone_pgd_mask != ~(pgdval_t)0UL)
21464 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
21465 +#endif
21466 +
21467 + return 1;
21468 +}
21469 +__setup("nopcid", setup_disable_pcid);
21470 +
21471 +static void setup_pcid(struct cpuinfo_x86 *c)
21472 +{
21473 + if (!cpu_has(c, X86_FEATURE_PCID)) {
21474 + clear_cpu_cap(c, X86_FEATURE_INVPCID);
21475 +
21476 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21477 + if (clone_pgd_mask != ~(pgdval_t)0UL) {
21478 + pax_open_kernel();
21479 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
21480 + pax_close_kernel();
21481 + printk("PAX: slow and weak UDEREF enabled\n");
21482 + } else
21483 + printk("PAX: UDEREF disabled\n");
21484 +#endif
21485 +
21486 + return;
21487 + }
21488 +
21489 + printk("PAX: PCID detected\n");
21490 + set_in_cr4(X86_CR4_PCIDE);
21491 +
21492 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21493 + pax_open_kernel();
21494 + clone_pgd_mask = ~(pgdval_t)0UL;
21495 + pax_close_kernel();
21496 + if (pax_user_shadow_base)
21497 + printk("PAX: weak UDEREF enabled\n");
21498 + else {
21499 + set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
21500 + printk("PAX: strong UDEREF enabled\n");
21501 + }
21502 +#endif
21503 +
21504 + if (cpu_has(c, X86_FEATURE_INVPCID))
21505 + printk("PAX: INVPCID detected\n");
21506 +}
21507 +#endif
21508 +
21509 /*
21510 * Some CPU features depend on higher CPUID levels, which may not always
21511 * be available due to CPUID level capping or broken virtualization
21512 @@ -395,7 +394,7 @@ void switch_to_new_gdt(int cpu)
21513 {
21514 struct desc_ptr gdt_descr;
21515
21516 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
21517 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
21518 gdt_descr.size = GDT_SIZE - 1;
21519 load_gdt(&gdt_descr);
21520 /* Reload the per-cpu base */
21521 @@ -885,6 +884,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
21522 setup_smep(c);
21523 setup_smap(c);
21524
21525 +#ifdef CONFIG_X86_64
21526 + setup_pcid(c);
21527 +#endif
21528 +
21529 /*
21530 * The vendor-specific functions might have changed features.
21531 * Now we do "generic changes."
21532 @@ -893,6 +896,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
21533 /* Filter out anything that depends on CPUID levels we don't have */
21534 filter_cpuid_features(c, true);
21535
21536 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
21537 + setup_clear_cpu_cap(X86_FEATURE_SEP);
21538 +#endif
21539 +
21540 /* If the model name is still unset, do table lookup. */
21541 if (!c->x86_model_id[0]) {
21542 const char *p;
21543 @@ -973,7 +980,7 @@ static void syscall32_cpu_init(void)
21544 void enable_sep_cpu(void)
21545 {
21546 int cpu = get_cpu();
21547 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
21548 + struct tss_struct *tss = init_tss + cpu;
21549
21550 if (!boot_cpu_has(X86_FEATURE_SEP)) {
21551 put_cpu();
21552 @@ -1113,14 +1120,16 @@ static __init int setup_disablecpuid(char *arg)
21553 }
21554 __setup("clearcpuid=", setup_disablecpuid);
21555
21556 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
21557 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
21558 +
21559 DEFINE_PER_CPU(unsigned long, kernel_stack) =
21560 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
21561 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
21562 EXPORT_PER_CPU_SYMBOL(kernel_stack);
21563
21564 #ifdef CONFIG_X86_64
21565 -struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
21566 -struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
21567 - (unsigned long) debug_idt_table };
21568 +struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
21569 +const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
21570
21571 DEFINE_PER_CPU_FIRST(union irq_stack_union,
21572 irq_stack_union) __aligned(PAGE_SIZE) __visible;
21573 @@ -1283,7 +1292,7 @@ void cpu_init(void)
21574 load_ucode_ap();
21575
21576 cpu = stack_smp_processor_id();
21577 - t = &per_cpu(init_tss, cpu);
21578 + t = init_tss + cpu;
21579 oist = &per_cpu(orig_ist, cpu);
21580
21581 #ifdef CONFIG_NUMA
21582 @@ -1318,7 +1327,6 @@ void cpu_init(void)
21583 wrmsrl(MSR_KERNEL_GS_BASE, 0);
21584 barrier();
21585
21586 - x86_configure_nx();
21587 enable_x2apic();
21588
21589 /*
21590 @@ -1370,7 +1378,7 @@ void cpu_init(void)
21591 {
21592 int cpu = smp_processor_id();
21593 struct task_struct *curr = current;
21594 - struct tss_struct *t = &per_cpu(init_tss, cpu);
21595 + struct tss_struct *t = init_tss + cpu;
21596 struct thread_struct *thread = &curr->thread;
21597
21598 show_ucode_info_early();
21599 diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
21600 index 9c8f739..902a9c5 100644
21601 --- a/arch/x86/kernel/cpu/intel_cacheinfo.c
21602 +++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
21603 @@ -1026,6 +1026,22 @@ static struct attribute *default_attrs[] = {
21604 };
21605
21606 #ifdef CONFIG_AMD_NB
21607 +static struct attribute *default_attrs_amd_nb[] = {
21608 + &type.attr,
21609 + &level.attr,
21610 + &coherency_line_size.attr,
21611 + &physical_line_partition.attr,
21612 + &ways_of_associativity.attr,
21613 + &number_of_sets.attr,
21614 + &size.attr,
21615 + &shared_cpu_map.attr,
21616 + &shared_cpu_list.attr,
21617 + NULL,
21618 + NULL,
21619 + NULL,
21620 + NULL
21621 +};
21622 +
21623 static struct attribute **amd_l3_attrs(void)
21624 {
21625 static struct attribute **attrs;
21626 @@ -1036,18 +1052,7 @@ static struct attribute **amd_l3_attrs(void)
21627
21628 n = ARRAY_SIZE(default_attrs);
21629
21630 - if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
21631 - n += 2;
21632 -
21633 - if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
21634 - n += 1;
21635 -
21636 - attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
21637 - if (attrs == NULL)
21638 - return attrs = default_attrs;
21639 -
21640 - for (n = 0; default_attrs[n]; n++)
21641 - attrs[n] = default_attrs[n];
21642 + attrs = default_attrs_amd_nb;
21643
21644 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
21645 attrs[n++] = &cache_disable_0.attr;
21646 @@ -1098,6 +1103,13 @@ static struct kobj_type ktype_cache = {
21647 .default_attrs = default_attrs,
21648 };
21649
21650 +#ifdef CONFIG_AMD_NB
21651 +static struct kobj_type ktype_cache_amd_nb = {
21652 + .sysfs_ops = &sysfs_ops,
21653 + .default_attrs = default_attrs_amd_nb,
21654 +};
21655 +#endif
21656 +
21657 static struct kobj_type ktype_percpu_entry = {
21658 .sysfs_ops = &sysfs_ops,
21659 };
21660 @@ -1163,20 +1175,26 @@ static int cache_add_dev(struct device *dev)
21661 return retval;
21662 }
21663
21664 +#ifdef CONFIG_AMD_NB
21665 + amd_l3_attrs();
21666 +#endif
21667 +
21668 for (i = 0; i < num_cache_leaves; i++) {
21669 + struct kobj_type *ktype;
21670 +
21671 this_object = INDEX_KOBJECT_PTR(cpu, i);
21672 this_object->cpu = cpu;
21673 this_object->index = i;
21674
21675 this_leaf = CPUID4_INFO_IDX(cpu, i);
21676
21677 - ktype_cache.default_attrs = default_attrs;
21678 + ktype = &ktype_cache;
21679 #ifdef CONFIG_AMD_NB
21680 if (this_leaf->base.nb)
21681 - ktype_cache.default_attrs = amd_l3_attrs();
21682 + ktype = &ktype_cache_amd_nb;
21683 #endif
21684 retval = kobject_init_and_add(&(this_object->kobj),
21685 - &ktype_cache,
21686 + ktype,
21687 per_cpu(ici_cache_kobject, cpu),
21688 "index%1lu", i);
21689 if (unlikely(retval)) {
21690 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
21691 index 9a79c8d..158c2f1 100644
21692 --- a/arch/x86/kernel/cpu/mcheck/mce.c
21693 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
21694 @@ -45,6 +45,7 @@
21695 #include <asm/processor.h>
21696 #include <asm/mce.h>
21697 #include <asm/msr.h>
21698 +#include <asm/local.h>
21699
21700 #include "mce-internal.h"
21701
21702 @@ -259,7 +260,7 @@ static void print_mce(struct mce *m)
21703 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
21704 m->cs, m->ip);
21705
21706 - if (m->cs == __KERNEL_CS)
21707 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
21708 print_symbol("{%s}", m->ip);
21709 pr_cont("\n");
21710 }
21711 @@ -292,10 +293,10 @@ static void print_mce(struct mce *m)
21712
21713 #define PANIC_TIMEOUT 5 /* 5 seconds */
21714
21715 -static atomic_t mce_paniced;
21716 +static atomic_unchecked_t mce_paniced;
21717
21718 static int fake_panic;
21719 -static atomic_t mce_fake_paniced;
21720 +static atomic_unchecked_t mce_fake_paniced;
21721
21722 /* Panic in progress. Enable interrupts and wait for final IPI */
21723 static void wait_for_panic(void)
21724 @@ -319,7 +320,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21725 /*
21726 * Make sure only one CPU runs in machine check panic
21727 */
21728 - if (atomic_inc_return(&mce_paniced) > 1)
21729 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
21730 wait_for_panic();
21731 barrier();
21732
21733 @@ -327,7 +328,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21734 console_verbose();
21735 } else {
21736 /* Don't log too much for fake panic */
21737 - if (atomic_inc_return(&mce_fake_paniced) > 1)
21738 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
21739 return;
21740 }
21741 /* First print corrected ones that are still unlogged */
21742 @@ -366,7 +367,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21743 if (!fake_panic) {
21744 if (panic_timeout == 0)
21745 panic_timeout = mca_cfg.panic_timeout;
21746 - panic(msg);
21747 + panic("%s", msg);
21748 } else
21749 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
21750 }
21751 @@ -697,7 +698,7 @@ static int mce_timed_out(u64 *t)
21752 * might have been modified by someone else.
21753 */
21754 rmb();
21755 - if (atomic_read(&mce_paniced))
21756 + if (atomic_read_unchecked(&mce_paniced))
21757 wait_for_panic();
21758 if (!mca_cfg.monarch_timeout)
21759 goto out;
21760 @@ -1674,7 +1675,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
21761 }
21762
21763 /* Call the installed machine check handler for this CPU setup. */
21764 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
21765 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
21766 unexpected_machine_check;
21767
21768 /*
21769 @@ -1697,7 +1698,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21770 return;
21771 }
21772
21773 + pax_open_kernel();
21774 machine_check_vector = do_machine_check;
21775 + pax_close_kernel();
21776
21777 __mcheck_cpu_init_generic();
21778 __mcheck_cpu_init_vendor(c);
21779 @@ -1711,7 +1714,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21780 */
21781
21782 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
21783 -static int mce_chrdev_open_count; /* #times opened */
21784 +static local_t mce_chrdev_open_count; /* #times opened */
21785 static int mce_chrdev_open_exclu; /* already open exclusive? */
21786
21787 static int mce_chrdev_open(struct inode *inode, struct file *file)
21788 @@ -1719,7 +1722,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21789 spin_lock(&mce_chrdev_state_lock);
21790
21791 if (mce_chrdev_open_exclu ||
21792 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
21793 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
21794 spin_unlock(&mce_chrdev_state_lock);
21795
21796 return -EBUSY;
21797 @@ -1727,7 +1730,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21798
21799 if (file->f_flags & O_EXCL)
21800 mce_chrdev_open_exclu = 1;
21801 - mce_chrdev_open_count++;
21802 + local_inc(&mce_chrdev_open_count);
21803
21804 spin_unlock(&mce_chrdev_state_lock);
21805
21806 @@ -1738,7 +1741,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
21807 {
21808 spin_lock(&mce_chrdev_state_lock);
21809
21810 - mce_chrdev_open_count--;
21811 + local_dec(&mce_chrdev_open_count);
21812 mce_chrdev_open_exclu = 0;
21813
21814 spin_unlock(&mce_chrdev_state_lock);
21815 @@ -2414,7 +2417,7 @@ static __init void mce_init_banks(void)
21816
21817 for (i = 0; i < mca_cfg.banks; i++) {
21818 struct mce_bank *b = &mce_banks[i];
21819 - struct device_attribute *a = &b->attr;
21820 + device_attribute_no_const *a = &b->attr;
21821
21822 sysfs_attr_init(&a->attr);
21823 a->attr.name = b->attrname;
21824 @@ -2521,7 +2524,7 @@ struct dentry *mce_get_debugfs_dir(void)
21825 static void mce_reset(void)
21826 {
21827 cpu_missing = 0;
21828 - atomic_set(&mce_fake_paniced, 0);
21829 + atomic_set_unchecked(&mce_fake_paniced, 0);
21830 atomic_set(&mce_executing, 0);
21831 atomic_set(&mce_callin, 0);
21832 atomic_set(&global_nwo, 0);
21833 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
21834 index a304298..49b6d06 100644
21835 --- a/arch/x86/kernel/cpu/mcheck/p5.c
21836 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
21837 @@ -10,6 +10,7 @@
21838 #include <asm/processor.h>
21839 #include <asm/mce.h>
21840 #include <asm/msr.h>
21841 +#include <asm/pgtable.h>
21842
21843 /* By default disabled */
21844 int mce_p5_enabled __read_mostly;
21845 @@ -48,7 +49,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
21846 if (!cpu_has(c, X86_FEATURE_MCE))
21847 return;
21848
21849 + pax_open_kernel();
21850 machine_check_vector = pentium_machine_check;
21851 + pax_close_kernel();
21852 /* Make sure the vector pointer is visible before we enable MCEs: */
21853 wmb();
21854
21855 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
21856 index 7dc5564..1273569 100644
21857 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
21858 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
21859 @@ -9,6 +9,7 @@
21860 #include <asm/processor.h>
21861 #include <asm/mce.h>
21862 #include <asm/msr.h>
21863 +#include <asm/pgtable.h>
21864
21865 /* Machine check handler for WinChip C6: */
21866 static void winchip_machine_check(struct pt_regs *regs, long error_code)
21867 @@ -22,7 +23,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
21868 {
21869 u32 lo, hi;
21870
21871 + pax_open_kernel();
21872 machine_check_vector = winchip_machine_check;
21873 + pax_close_kernel();
21874 /* Make sure the vector pointer is visible before we enable MCEs: */
21875 wmb();
21876
21877 diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
21878 index dd9d619..86e1d81 100644
21879 --- a/arch/x86/kernel/cpu/microcode/core.c
21880 +++ b/arch/x86/kernel/cpu/microcode/core.c
21881 @@ -516,7 +516,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
21882 return NOTIFY_OK;
21883 }
21884
21885 -static struct notifier_block __refdata mc_cpu_notifier = {
21886 +static struct notifier_block mc_cpu_notifier = {
21887 .notifier_call = mc_cpu_callback,
21888 };
21889
21890 diff --git a/arch/x86/kernel/cpu/microcode/intel.c b/arch/x86/kernel/cpu/microcode/intel.c
21891 index a276fa7..e66810f 100644
21892 --- a/arch/x86/kernel/cpu/microcode/intel.c
21893 +++ b/arch/x86/kernel/cpu/microcode/intel.c
21894 @@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
21895
21896 static int get_ucode_user(void *to, const void *from, size_t n)
21897 {
21898 - return copy_from_user(to, from, n);
21899 + return copy_from_user(to, (const void __force_user *)from, n);
21900 }
21901
21902 static enum ucode_state
21903 request_microcode_user(int cpu, const void __user *buf, size_t size)
21904 {
21905 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
21906 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
21907 }
21908
21909 static void microcode_fini_cpu(int cpu)
21910 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
21911 index f961de9..8a9d332 100644
21912 --- a/arch/x86/kernel/cpu/mtrr/main.c
21913 +++ b/arch/x86/kernel/cpu/mtrr/main.c
21914 @@ -66,7 +66,7 @@ static DEFINE_MUTEX(mtrr_mutex);
21915 u64 size_or_mask, size_and_mask;
21916 static bool mtrr_aps_delayed_init;
21917
21918 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
21919 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
21920
21921 const struct mtrr_ops *mtrr_if;
21922
21923 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
21924 index df5e41f..816c719 100644
21925 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
21926 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
21927 @@ -25,7 +25,7 @@ struct mtrr_ops {
21928 int (*validate_add_page)(unsigned long base, unsigned long size,
21929 unsigned int type);
21930 int (*have_wrcomb)(void);
21931 -};
21932 +} __do_const;
21933
21934 extern int generic_get_free_region(unsigned long base, unsigned long size,
21935 int replace_reg);
21936 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
21937 index 2879ecd..bb8c80b 100644
21938 --- a/arch/x86/kernel/cpu/perf_event.c
21939 +++ b/arch/x86/kernel/cpu/perf_event.c
21940 @@ -1372,7 +1372,7 @@ static void __init pmu_check_apic(void)
21941
21942 }
21943
21944 -static struct attribute_group x86_pmu_format_group = {
21945 +static attribute_group_no_const x86_pmu_format_group = {
21946 .name = "format",
21947 .attrs = NULL,
21948 };
21949 @@ -1471,7 +1471,7 @@ static struct attribute *events_attr[] = {
21950 NULL,
21951 };
21952
21953 -static struct attribute_group x86_pmu_events_group = {
21954 +static attribute_group_no_const x86_pmu_events_group = {
21955 .name = "events",
21956 .attrs = events_attr,
21957 };
21958 @@ -1995,7 +1995,7 @@ static unsigned long get_segment_base(unsigned int segment)
21959 if (idx > GDT_ENTRIES)
21960 return 0;
21961
21962 - desc = __this_cpu_ptr(&gdt_page.gdt[0]);
21963 + desc = get_cpu_gdt_table(smp_processor_id());
21964 }
21965
21966 return get_desc_base(desc + idx);
21967 @@ -2085,7 +2085,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
21968 break;
21969
21970 perf_callchain_store(entry, frame.return_address);
21971 - fp = frame.next_frame;
21972 + fp = (const void __force_user *)frame.next_frame;
21973 }
21974 }
21975
21976 diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21977 index 639d128..e92d7e5 100644
21978 --- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21979 +++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21980 @@ -405,7 +405,7 @@ static void perf_iommu_del(struct perf_event *event, int flags)
21981 static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)
21982 {
21983 struct attribute **attrs;
21984 - struct attribute_group *attr_group;
21985 + attribute_group_no_const *attr_group;
21986 int i = 0, j;
21987
21988 while (amd_iommu_v2_event_descs[i].attr.attr.name)
21989 diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
21990 index 2502d0d..e5cc05c 100644
21991 --- a/arch/x86/kernel/cpu/perf_event_intel.c
21992 +++ b/arch/x86/kernel/cpu/perf_event_intel.c
21993 @@ -2353,10 +2353,10 @@ __init int intel_pmu_init(void)
21994 x86_pmu.num_counters_fixed = max((int)edx.split.num_counters_fixed, 3);
21995
21996 if (boot_cpu_has(X86_FEATURE_PDCM)) {
21997 - u64 capabilities;
21998 + u64 capabilities = x86_pmu.intel_cap.capabilities;
21999
22000 - rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
22001 - x86_pmu.intel_cap.capabilities = capabilities;
22002 + if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
22003 + x86_pmu.intel_cap.capabilities = capabilities;
22004 }
22005
22006 intel_ds_init();
22007 diff --git a/arch/x86/kernel/cpu/perf_event_intel_rapl.c b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
22008 index 619f769..d510008 100644
22009 --- a/arch/x86/kernel/cpu/perf_event_intel_rapl.c
22010 +++ b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
22011 @@ -449,7 +449,7 @@ static struct attribute *rapl_events_hsw_attr[] = {
22012 NULL,
22013 };
22014
22015 -static struct attribute_group rapl_pmu_events_group = {
22016 +static attribute_group_no_const rapl_pmu_events_group __read_only = {
22017 .name = "events",
22018 .attrs = NULL, /* patched at runtime */
22019 };
22020 diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
22021 index ae6552a..b5be2d3 100644
22022 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
22023 +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
22024 @@ -3694,7 +3694,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
22025 static int __init uncore_type_init(struct intel_uncore_type *type)
22026 {
22027 struct intel_uncore_pmu *pmus;
22028 - struct attribute_group *attr_group;
22029 + attribute_group_no_const *attr_group;
22030 struct attribute **attrs;
22031 int i, j;
22032
22033 diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
22034 index 90236f0..54cb20d 100644
22035 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
22036 +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
22037 @@ -503,7 +503,7 @@ struct intel_uncore_box {
22038 struct uncore_event_desc {
22039 struct kobj_attribute attr;
22040 const char *config;
22041 -};
22042 +} __do_const;
22043
22044 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
22045 { \
22046 diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
22047 index 3225ae6c..ee3c6db 100644
22048 --- a/arch/x86/kernel/cpuid.c
22049 +++ b/arch/x86/kernel/cpuid.c
22050 @@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
22051 return notifier_from_errno(err);
22052 }
22053
22054 -static struct notifier_block __refdata cpuid_class_cpu_notifier =
22055 +static struct notifier_block cpuid_class_cpu_notifier =
22056 {
22057 .notifier_call = cpuid_class_cpu_callback,
22058 };
22059 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
22060 index 507de80..ebaae2a 100644
22061 --- a/arch/x86/kernel/crash.c
22062 +++ b/arch/x86/kernel/crash.c
22063 @@ -58,7 +58,7 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
22064 #ifdef CONFIG_X86_32
22065 struct pt_regs fixed_regs;
22066
22067 - if (!user_mode_vm(regs)) {
22068 + if (!user_mode(regs)) {
22069 crash_fixup_ss_esp(&fixed_regs, regs);
22070 regs = &fixed_regs;
22071 }
22072 diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
22073 index afa64ad..dce67dd 100644
22074 --- a/arch/x86/kernel/crash_dump_64.c
22075 +++ b/arch/x86/kernel/crash_dump_64.c
22076 @@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
22077 return -ENOMEM;
22078
22079 if (userbuf) {
22080 - if (copy_to_user(buf, vaddr + offset, csize)) {
22081 + if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
22082 iounmap(vaddr);
22083 return -EFAULT;
22084 }
22085 diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
22086 index f6dfd93..892ade4 100644
22087 --- a/arch/x86/kernel/doublefault.c
22088 +++ b/arch/x86/kernel/doublefault.c
22089 @@ -12,7 +12,7 @@
22090
22091 #define DOUBLEFAULT_STACKSIZE (1024)
22092 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
22093 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
22094 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
22095
22096 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
22097
22098 @@ -22,7 +22,7 @@ static void doublefault_fn(void)
22099 unsigned long gdt, tss;
22100
22101 native_store_gdt(&gdt_desc);
22102 - gdt = gdt_desc.address;
22103 + gdt = (unsigned long)gdt_desc.address;
22104
22105 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
22106
22107 @@ -59,10 +59,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
22108 /* 0x2 bit is always set */
22109 .flags = X86_EFLAGS_SF | 0x2,
22110 .sp = STACK_START,
22111 - .es = __USER_DS,
22112 + .es = __KERNEL_DS,
22113 .cs = __KERNEL_CS,
22114 .ss = __KERNEL_DS,
22115 - .ds = __USER_DS,
22116 + .ds = __KERNEL_DS,
22117 .fs = __KERNEL_PERCPU,
22118
22119 .__cr3 = __pa_nodebug(swapper_pg_dir),
22120 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
22121 index b74ebc7..6dbb0c5 100644
22122 --- a/arch/x86/kernel/dumpstack.c
22123 +++ b/arch/x86/kernel/dumpstack.c
22124 @@ -2,6 +2,9 @@
22125 * Copyright (C) 1991, 1992 Linus Torvalds
22126 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
22127 */
22128 +#ifdef CONFIG_GRKERNSEC_HIDESYM
22129 +#define __INCLUDED_BY_HIDESYM 1
22130 +#endif
22131 #include <linux/kallsyms.h>
22132 #include <linux/kprobes.h>
22133 #include <linux/uaccess.h>
22134 @@ -40,16 +43,14 @@ void printk_address(unsigned long address)
22135 static void
22136 print_ftrace_graph_addr(unsigned long addr, void *data,
22137 const struct stacktrace_ops *ops,
22138 - struct thread_info *tinfo, int *graph)
22139 + struct task_struct *task, int *graph)
22140 {
22141 - struct task_struct *task;
22142 unsigned long ret_addr;
22143 int index;
22144
22145 if (addr != (unsigned long)return_to_handler)
22146 return;
22147
22148 - task = tinfo->task;
22149 index = task->curr_ret_stack;
22150
22151 if (!task->ret_stack || index < *graph)
22152 @@ -66,7 +67,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
22153 static inline void
22154 print_ftrace_graph_addr(unsigned long addr, void *data,
22155 const struct stacktrace_ops *ops,
22156 - struct thread_info *tinfo, int *graph)
22157 + struct task_struct *task, int *graph)
22158 { }
22159 #endif
22160
22161 @@ -77,10 +78,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
22162 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
22163 */
22164
22165 -static inline int valid_stack_ptr(struct thread_info *tinfo,
22166 - void *p, unsigned int size, void *end)
22167 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
22168 {
22169 - void *t = tinfo;
22170 if (end) {
22171 if (p < end && p >= (end-THREAD_SIZE))
22172 return 1;
22173 @@ -91,14 +90,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
22174 }
22175
22176 unsigned long
22177 -print_context_stack(struct thread_info *tinfo,
22178 +print_context_stack(struct task_struct *task, void *stack_start,
22179 unsigned long *stack, unsigned long bp,
22180 const struct stacktrace_ops *ops, void *data,
22181 unsigned long *end, int *graph)
22182 {
22183 struct stack_frame *frame = (struct stack_frame *)bp;
22184
22185 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
22186 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
22187 unsigned long addr;
22188
22189 addr = *stack;
22190 @@ -110,7 +109,7 @@ print_context_stack(struct thread_info *tinfo,
22191 } else {
22192 ops->address(data, addr, 0);
22193 }
22194 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
22195 + print_ftrace_graph_addr(addr, data, ops, task, graph);
22196 }
22197 stack++;
22198 }
22199 @@ -119,7 +118,7 @@ print_context_stack(struct thread_info *tinfo,
22200 EXPORT_SYMBOL_GPL(print_context_stack);
22201
22202 unsigned long
22203 -print_context_stack_bp(struct thread_info *tinfo,
22204 +print_context_stack_bp(struct task_struct *task, void *stack_start,
22205 unsigned long *stack, unsigned long bp,
22206 const struct stacktrace_ops *ops, void *data,
22207 unsigned long *end, int *graph)
22208 @@ -127,7 +126,7 @@ print_context_stack_bp(struct thread_info *tinfo,
22209 struct stack_frame *frame = (struct stack_frame *)bp;
22210 unsigned long *ret_addr = &frame->return_address;
22211
22212 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
22213 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
22214 unsigned long addr = *ret_addr;
22215
22216 if (!__kernel_text_address(addr))
22217 @@ -136,7 +135,7 @@ print_context_stack_bp(struct thread_info *tinfo,
22218 ops->address(data, addr, 1);
22219 frame = frame->next_frame;
22220 ret_addr = &frame->return_address;
22221 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
22222 + print_ftrace_graph_addr(addr, data, ops, task, graph);
22223 }
22224
22225 return (unsigned long)frame;
22226 @@ -155,7 +154,7 @@ static int print_trace_stack(void *data, char *name)
22227 static void print_trace_address(void *data, unsigned long addr, int reliable)
22228 {
22229 touch_nmi_watchdog();
22230 - printk(data);
22231 + printk("%s", (char *)data);
22232 printk_stack_address(addr, reliable);
22233 }
22234
22235 @@ -225,6 +224,8 @@ unsigned long oops_begin(void)
22236 EXPORT_SYMBOL_GPL(oops_begin);
22237 NOKPROBE_SYMBOL(oops_begin);
22238
22239 +extern void gr_handle_kernel_exploit(void);
22240 +
22241 void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
22242 {
22243 if (regs && kexec_should_crash(current))
22244 @@ -246,7 +247,10 @@ void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
22245 panic("Fatal exception in interrupt");
22246 if (panic_on_oops)
22247 panic("Fatal exception");
22248 - do_exit(signr);
22249 +
22250 + gr_handle_kernel_exploit();
22251 +
22252 + do_group_exit(signr);
22253 }
22254 NOKPROBE_SYMBOL(oops_end);
22255
22256 @@ -275,7 +279,7 @@ int __die(const char *str, struct pt_regs *regs, long err)
22257 print_modules();
22258 show_regs(regs);
22259 #ifdef CONFIG_X86_32
22260 - if (user_mode_vm(regs)) {
22261 + if (user_mode(regs)) {
22262 sp = regs->sp;
22263 ss = regs->ss & 0xffff;
22264 } else {
22265 @@ -304,7 +308,7 @@ void die(const char *str, struct pt_regs *regs, long err)
22266 unsigned long flags = oops_begin();
22267 int sig = SIGSEGV;
22268
22269 - if (!user_mode_vm(regs))
22270 + if (!user_mode(regs))
22271 report_bug(regs->ip, regs);
22272
22273 if (__die(str, regs, err))
22274 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
22275 index 5abd4cd..c65733b 100644
22276 --- a/arch/x86/kernel/dumpstack_32.c
22277 +++ b/arch/x86/kernel/dumpstack_32.c
22278 @@ -61,15 +61,14 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22279 bp = stack_frame(task, regs);
22280
22281 for (;;) {
22282 - struct thread_info *context;
22283 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
22284 void *end_stack;
22285
22286 end_stack = is_hardirq_stack(stack, cpu);
22287 if (!end_stack)
22288 end_stack = is_softirq_stack(stack, cpu);
22289
22290 - context = task_thread_info(task);
22291 - bp = ops->walk_stack(context, stack, bp, ops, data,
22292 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data,
22293 end_stack, &graph);
22294
22295 /* Stop if not on irq stack */
22296 @@ -123,27 +122,28 @@ void show_regs(struct pt_regs *regs)
22297 int i;
22298
22299 show_regs_print_info(KERN_EMERG);
22300 - __show_regs(regs, !user_mode_vm(regs));
22301 + __show_regs(regs, !user_mode(regs));
22302
22303 /*
22304 * When in-kernel, we also print out the stack and code at the
22305 * time of the fault..
22306 */
22307 - if (!user_mode_vm(regs)) {
22308 + if (!user_mode(regs)) {
22309 unsigned int code_prologue = code_bytes * 43 / 64;
22310 unsigned int code_len = code_bytes;
22311 unsigned char c;
22312 u8 *ip;
22313 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
22314
22315 pr_emerg("Stack:\n");
22316 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
22317
22318 pr_emerg("Code:");
22319
22320 - ip = (u8 *)regs->ip - code_prologue;
22321 + ip = (u8 *)regs->ip - code_prologue + cs_base;
22322 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
22323 /* try starting at IP */
22324 - ip = (u8 *)regs->ip;
22325 + ip = (u8 *)regs->ip + cs_base;
22326 code_len = code_len - code_prologue + 1;
22327 }
22328 for (i = 0; i < code_len; i++, ip++) {
22329 @@ -152,7 +152,7 @@ void show_regs(struct pt_regs *regs)
22330 pr_cont(" Bad EIP value.");
22331 break;
22332 }
22333 - if (ip == (u8 *)regs->ip)
22334 + if (ip == (u8 *)regs->ip + cs_base)
22335 pr_cont(" <%02x>", c);
22336 else
22337 pr_cont(" %02x", c);
22338 @@ -165,6 +165,7 @@ int is_valid_bugaddr(unsigned long ip)
22339 {
22340 unsigned short ud2;
22341
22342 + ip = ktla_ktva(ip);
22343 if (ip < PAGE_OFFSET)
22344 return 0;
22345 if (probe_kernel_address((unsigned short *)ip, ud2))
22346 @@ -172,3 +173,15 @@ int is_valid_bugaddr(unsigned long ip)
22347
22348 return ud2 == 0x0b0f;
22349 }
22350 +
22351 +#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
22352 +void pax_check_alloca(unsigned long size)
22353 +{
22354 + unsigned long sp = (unsigned long)&sp, stack_left;
22355 +
22356 + /* all kernel stacks are of the same size */
22357 + stack_left = sp & (THREAD_SIZE - 1);
22358 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
22359 +}
22360 +EXPORT_SYMBOL(pax_check_alloca);
22361 +#endif
22362 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
22363 index 1abcb50..6c8d702 100644
22364 --- a/arch/x86/kernel/dumpstack_64.c
22365 +++ b/arch/x86/kernel/dumpstack_64.c
22366 @@ -154,12 +154,12 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22367 const struct stacktrace_ops *ops, void *data)
22368 {
22369 const unsigned cpu = get_cpu();
22370 - struct thread_info *tinfo;
22371 unsigned long *irq_stack = (unsigned long *)per_cpu(irq_stack_ptr, cpu);
22372 unsigned long dummy;
22373 unsigned used = 0;
22374 int graph = 0;
22375 int done = 0;
22376 + void *stack_start;
22377
22378 if (!task)
22379 task = current;
22380 @@ -180,7 +180,6 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22381 * current stack address. If the stacks consist of nested
22382 * exceptions
22383 */
22384 - tinfo = task_thread_info(task);
22385 while (!done) {
22386 unsigned long *stack_end;
22387 enum stack_type stype;
22388 @@ -203,7 +202,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22389 if (ops->stack(data, id) < 0)
22390 break;
22391
22392 - bp = ops->walk_stack(tinfo, stack, bp, ops,
22393 + bp = ops->walk_stack(task, stack_end - EXCEPTION_STKSZ, stack, bp, ops,
22394 data, stack_end, &graph);
22395 ops->stack(data, "<EOE>");
22396 /*
22397 @@ -211,6 +210,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22398 * second-to-last pointer (index -2 to end) in the
22399 * exception stack:
22400 */
22401 + if ((u16)stack_end[-1] != __KERNEL_DS)
22402 + goto out;
22403 stack = (unsigned long *) stack_end[-2];
22404 done = 0;
22405 break;
22406 @@ -219,7 +220,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22407
22408 if (ops->stack(data, "IRQ") < 0)
22409 break;
22410 - bp = ops->walk_stack(tinfo, stack, bp,
22411 + bp = ops->walk_stack(task, irq_stack, stack, bp,
22412 ops, data, stack_end, &graph);
22413 /*
22414 * We link to the next stack (which would be
22415 @@ -241,7 +242,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22416 /*
22417 * This handles the process stack:
22418 */
22419 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
22420 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
22421 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
22422 +out:
22423 put_cpu();
22424 }
22425 EXPORT_SYMBOL(dump_trace);
22426 @@ -350,3 +353,50 @@ int is_valid_bugaddr(unsigned long ip)
22427
22428 return ud2 == 0x0b0f;
22429 }
22430 +
22431 +#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
22432 +void pax_check_alloca(unsigned long size)
22433 +{
22434 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
22435 + unsigned cpu, used;
22436 + char *id;
22437 +
22438 + /* check the process stack first */
22439 + stack_start = (unsigned long)task_stack_page(current);
22440 + stack_end = stack_start + THREAD_SIZE;
22441 + if (likely(stack_start <= sp && sp < stack_end)) {
22442 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
22443 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
22444 + return;
22445 + }
22446 +
22447 + cpu = get_cpu();
22448 +
22449 + /* check the irq stacks */
22450 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
22451 + stack_start = stack_end - IRQ_STACK_SIZE;
22452 + if (stack_start <= sp && sp < stack_end) {
22453 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
22454 + put_cpu();
22455 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
22456 + return;
22457 + }
22458 +
22459 + /* check the exception stacks */
22460 + used = 0;
22461 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
22462 + stack_start = stack_end - EXCEPTION_STKSZ;
22463 + if (stack_end && stack_start <= sp && sp < stack_end) {
22464 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
22465 + put_cpu();
22466 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
22467 + return;
22468 + }
22469 +
22470 + put_cpu();
22471 +
22472 + /* unknown stack */
22473 + BUG();
22474 +}
22475 +EXPORT_SYMBOL(pax_check_alloca);
22476 +#endif
22477 diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
22478 index 988c00a..4f673b6 100644
22479 --- a/arch/x86/kernel/e820.c
22480 +++ b/arch/x86/kernel/e820.c
22481 @@ -803,8 +803,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
22482
22483 static void early_panic(char *msg)
22484 {
22485 - early_printk(msg);
22486 - panic(msg);
22487 + early_printk("%s", msg);
22488 + panic("%s", msg);
22489 }
22490
22491 static int userdef __initdata;
22492 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
22493 index 01d1c18..8073693 100644
22494 --- a/arch/x86/kernel/early_printk.c
22495 +++ b/arch/x86/kernel/early_printk.c
22496 @@ -7,6 +7,7 @@
22497 #include <linux/pci_regs.h>
22498 #include <linux/pci_ids.h>
22499 #include <linux/errno.h>
22500 +#include <linux/sched.h>
22501 #include <asm/io.h>
22502 #include <asm/processor.h>
22503 #include <asm/fcntl.h>
22504 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
22505 index 0d0c9d4..f65b4f6 100644
22506 --- a/arch/x86/kernel/entry_32.S
22507 +++ b/arch/x86/kernel/entry_32.S
22508 @@ -177,13 +177,153 @@
22509 /*CFI_REL_OFFSET gs, PT_GS*/
22510 .endm
22511 .macro SET_KERNEL_GS reg
22512 +
22513 +#ifdef CONFIG_CC_STACKPROTECTOR
22514 movl $(__KERNEL_STACK_CANARY), \reg
22515 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
22516 + movl $(__USER_DS), \reg
22517 +#else
22518 + xorl \reg, \reg
22519 +#endif
22520 +
22521 movl \reg, %gs
22522 .endm
22523
22524 #endif /* CONFIG_X86_32_LAZY_GS */
22525
22526 -.macro SAVE_ALL
22527 +.macro pax_enter_kernel
22528 +#ifdef CONFIG_PAX_KERNEXEC
22529 + call pax_enter_kernel
22530 +#endif
22531 +.endm
22532 +
22533 +.macro pax_exit_kernel
22534 +#ifdef CONFIG_PAX_KERNEXEC
22535 + call pax_exit_kernel
22536 +#endif
22537 +.endm
22538 +
22539 +#ifdef CONFIG_PAX_KERNEXEC
22540 +ENTRY(pax_enter_kernel)
22541 +#ifdef CONFIG_PARAVIRT
22542 + pushl %eax
22543 + pushl %ecx
22544 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
22545 + mov %eax, %esi
22546 +#else
22547 + mov %cr0, %esi
22548 +#endif
22549 + bts $16, %esi
22550 + jnc 1f
22551 + mov %cs, %esi
22552 + cmp $__KERNEL_CS, %esi
22553 + jz 3f
22554 + ljmp $__KERNEL_CS, $3f
22555 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
22556 +2:
22557 +#ifdef CONFIG_PARAVIRT
22558 + mov %esi, %eax
22559 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
22560 +#else
22561 + mov %esi, %cr0
22562 +#endif
22563 +3:
22564 +#ifdef CONFIG_PARAVIRT
22565 + popl %ecx
22566 + popl %eax
22567 +#endif
22568 + ret
22569 +ENDPROC(pax_enter_kernel)
22570 +
22571 +ENTRY(pax_exit_kernel)
22572 +#ifdef CONFIG_PARAVIRT
22573 + pushl %eax
22574 + pushl %ecx
22575 +#endif
22576 + mov %cs, %esi
22577 + cmp $__KERNEXEC_KERNEL_CS, %esi
22578 + jnz 2f
22579 +#ifdef CONFIG_PARAVIRT
22580 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
22581 + mov %eax, %esi
22582 +#else
22583 + mov %cr0, %esi
22584 +#endif
22585 + btr $16, %esi
22586 + ljmp $__KERNEL_CS, $1f
22587 +1:
22588 +#ifdef CONFIG_PARAVIRT
22589 + mov %esi, %eax
22590 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
22591 +#else
22592 + mov %esi, %cr0
22593 +#endif
22594 +2:
22595 +#ifdef CONFIG_PARAVIRT
22596 + popl %ecx
22597 + popl %eax
22598 +#endif
22599 + ret
22600 +ENDPROC(pax_exit_kernel)
22601 +#endif
22602 +
22603 + .macro pax_erase_kstack
22604 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22605 + call pax_erase_kstack
22606 +#endif
22607 + .endm
22608 +
22609 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22610 +/*
22611 + * ebp: thread_info
22612 + */
22613 +ENTRY(pax_erase_kstack)
22614 + pushl %edi
22615 + pushl %ecx
22616 + pushl %eax
22617 +
22618 + mov TI_lowest_stack(%ebp), %edi
22619 + mov $-0xBEEF, %eax
22620 + std
22621 +
22622 +1: mov %edi, %ecx
22623 + and $THREAD_SIZE_asm - 1, %ecx
22624 + shr $2, %ecx
22625 + repne scasl
22626 + jecxz 2f
22627 +
22628 + cmp $2*16, %ecx
22629 + jc 2f
22630 +
22631 + mov $2*16, %ecx
22632 + repe scasl
22633 + jecxz 2f
22634 + jne 1b
22635 +
22636 +2: cld
22637 + mov %esp, %ecx
22638 + sub %edi, %ecx
22639 +
22640 + cmp $THREAD_SIZE_asm, %ecx
22641 + jb 3f
22642 + ud2
22643 +3:
22644 +
22645 + shr $2, %ecx
22646 + rep stosl
22647 +
22648 + mov TI_task_thread_sp0(%ebp), %edi
22649 + sub $128, %edi
22650 + mov %edi, TI_lowest_stack(%ebp)
22651 +
22652 + popl %eax
22653 + popl %ecx
22654 + popl %edi
22655 + ret
22656 +ENDPROC(pax_erase_kstack)
22657 +#endif
22658 +
22659 +.macro __SAVE_ALL _DS
22660 cld
22661 PUSH_GS
22662 pushl_cfi %fs
22663 @@ -206,7 +346,7 @@
22664 CFI_REL_OFFSET ecx, 0
22665 pushl_cfi %ebx
22666 CFI_REL_OFFSET ebx, 0
22667 - movl $(__USER_DS), %edx
22668 + movl $\_DS, %edx
22669 movl %edx, %ds
22670 movl %edx, %es
22671 movl $(__KERNEL_PERCPU), %edx
22672 @@ -214,6 +354,15 @@
22673 SET_KERNEL_GS %edx
22674 .endm
22675
22676 +.macro SAVE_ALL
22677 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22678 + __SAVE_ALL __KERNEL_DS
22679 + pax_enter_kernel
22680 +#else
22681 + __SAVE_ALL __USER_DS
22682 +#endif
22683 +.endm
22684 +
22685 .macro RESTORE_INT_REGS
22686 popl_cfi %ebx
22687 CFI_RESTORE ebx
22688 @@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
22689 popfl_cfi
22690 jmp syscall_exit
22691 CFI_ENDPROC
22692 -END(ret_from_fork)
22693 +ENDPROC(ret_from_fork)
22694
22695 ENTRY(ret_from_kernel_thread)
22696 CFI_STARTPROC
22697 @@ -340,7 +489,15 @@ ret_from_intr:
22698 andl $SEGMENT_RPL_MASK, %eax
22699 #endif
22700 cmpl $USER_RPL, %eax
22701 +
22702 +#ifdef CONFIG_PAX_KERNEXEC
22703 + jae resume_userspace
22704 +
22705 + pax_exit_kernel
22706 + jmp resume_kernel
22707 +#else
22708 jb resume_kernel # not returning to v8086 or userspace
22709 +#endif
22710
22711 ENTRY(resume_userspace)
22712 LOCKDEP_SYS_EXIT
22713 @@ -352,8 +509,8 @@ ENTRY(resume_userspace)
22714 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
22715 # int/exception return?
22716 jne work_pending
22717 - jmp restore_all
22718 -END(ret_from_exception)
22719 + jmp restore_all_pax
22720 +ENDPROC(ret_from_exception)
22721
22722 #ifdef CONFIG_PREEMPT
22723 ENTRY(resume_kernel)
22724 @@ -365,7 +522,7 @@ need_resched:
22725 jz restore_all
22726 call preempt_schedule_irq
22727 jmp need_resched
22728 -END(resume_kernel)
22729 +ENDPROC(resume_kernel)
22730 #endif
22731 CFI_ENDPROC
22732
22733 @@ -395,30 +552,45 @@ sysenter_past_esp:
22734 /*CFI_REL_OFFSET cs, 0*/
22735 /*
22736 * Push current_thread_info()->sysenter_return to the stack.
22737 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
22738 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
22739 */
22740 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
22741 + pushl_cfi $0
22742 CFI_REL_OFFSET eip, 0
22743
22744 pushl_cfi %eax
22745 SAVE_ALL
22746 + GET_THREAD_INFO(%ebp)
22747 + movl TI_sysenter_return(%ebp),%ebp
22748 + movl %ebp,PT_EIP(%esp)
22749 ENABLE_INTERRUPTS(CLBR_NONE)
22750
22751 /*
22752 * Load the potential sixth argument from user stack.
22753 * Careful about security.
22754 */
22755 + movl PT_OLDESP(%esp),%ebp
22756 +
22757 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22758 + mov PT_OLDSS(%esp),%ds
22759 +1: movl %ds:(%ebp),%ebp
22760 + push %ss
22761 + pop %ds
22762 +#else
22763 cmpl $__PAGE_OFFSET-3,%ebp
22764 jae syscall_fault
22765 ASM_STAC
22766 1: movl (%ebp),%ebp
22767 ASM_CLAC
22768 +#endif
22769 +
22770 movl %ebp,PT_EBP(%esp)
22771 _ASM_EXTABLE(1b,syscall_fault)
22772
22773 GET_THREAD_INFO(%ebp)
22774
22775 +#ifdef CONFIG_PAX_RANDKSTACK
22776 + pax_erase_kstack
22777 +#endif
22778 +
22779 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22780 jnz sysenter_audit
22781 sysenter_do_call:
22782 @@ -434,12 +606,24 @@ sysenter_after_call:
22783 testl $_TIF_ALLWORK_MASK, %ecx
22784 jne sysexit_audit
22785 sysenter_exit:
22786 +
22787 +#ifdef CONFIG_PAX_RANDKSTACK
22788 + pushl_cfi %eax
22789 + movl %esp, %eax
22790 + call pax_randomize_kstack
22791 + popl_cfi %eax
22792 +#endif
22793 +
22794 + pax_erase_kstack
22795 +
22796 /* if something modifies registers it must also disable sysexit */
22797 movl PT_EIP(%esp), %edx
22798 movl PT_OLDESP(%esp), %ecx
22799 xorl %ebp,%ebp
22800 TRACE_IRQS_ON
22801 1: mov PT_FS(%esp), %fs
22802 +2: mov PT_DS(%esp), %ds
22803 +3: mov PT_ES(%esp), %es
22804 PTGS_TO_GS
22805 ENABLE_INTERRUPTS_SYSEXIT
22806
22807 @@ -456,6 +640,9 @@ sysenter_audit:
22808 movl %eax,%edx /* 2nd arg: syscall number */
22809 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
22810 call __audit_syscall_entry
22811 +
22812 + pax_erase_kstack
22813 +
22814 pushl_cfi %ebx
22815 movl PT_EAX(%esp),%eax /* reload syscall number */
22816 jmp sysenter_do_call
22817 @@ -481,10 +668,16 @@ sysexit_audit:
22818
22819 CFI_ENDPROC
22820 .pushsection .fixup,"ax"
22821 -2: movl $0,PT_FS(%esp)
22822 +4: movl $0,PT_FS(%esp)
22823 + jmp 1b
22824 +5: movl $0,PT_DS(%esp)
22825 + jmp 1b
22826 +6: movl $0,PT_ES(%esp)
22827 jmp 1b
22828 .popsection
22829 - _ASM_EXTABLE(1b,2b)
22830 + _ASM_EXTABLE(1b,4b)
22831 + _ASM_EXTABLE(2b,5b)
22832 + _ASM_EXTABLE(3b,6b)
22833 PTGS_TO_GS_EX
22834 ENDPROC(ia32_sysenter_target)
22835
22836 @@ -495,6 +688,11 @@ ENTRY(system_call)
22837 pushl_cfi %eax # save orig_eax
22838 SAVE_ALL
22839 GET_THREAD_INFO(%ebp)
22840 +
22841 +#ifdef CONFIG_PAX_RANDKSTACK
22842 + pax_erase_kstack
22843 +#endif
22844 +
22845 # system call tracing in operation / emulation
22846 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22847 jnz syscall_trace_entry
22848 @@ -514,6 +712,15 @@ syscall_exit:
22849 testl $_TIF_ALLWORK_MASK, %ecx # current->work
22850 jne syscall_exit_work
22851
22852 +restore_all_pax:
22853 +
22854 +#ifdef CONFIG_PAX_RANDKSTACK
22855 + movl %esp, %eax
22856 + call pax_randomize_kstack
22857 +#endif
22858 +
22859 + pax_erase_kstack
22860 +
22861 restore_all:
22862 TRACE_IRQS_IRET
22863 restore_all_notrace:
22864 @@ -568,14 +775,34 @@ ldt_ss:
22865 * compensating for the offset by changing to the ESPFIX segment with
22866 * a base address that matches for the difference.
22867 */
22868 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
22869 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
22870 mov %esp, %edx /* load kernel esp */
22871 mov PT_OLDESP(%esp), %eax /* load userspace esp */
22872 mov %dx, %ax /* eax: new kernel esp */
22873 sub %eax, %edx /* offset (low word is 0) */
22874 +#ifdef CONFIG_SMP
22875 + movl PER_CPU_VAR(cpu_number), %ebx
22876 + shll $PAGE_SHIFT_asm, %ebx
22877 + addl $cpu_gdt_table, %ebx
22878 +#else
22879 + movl $cpu_gdt_table, %ebx
22880 +#endif
22881 shr $16, %edx
22882 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
22883 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
22884 +
22885 +#ifdef CONFIG_PAX_KERNEXEC
22886 + mov %cr0, %esi
22887 + btr $16, %esi
22888 + mov %esi, %cr0
22889 +#endif
22890 +
22891 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
22892 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
22893 +
22894 +#ifdef CONFIG_PAX_KERNEXEC
22895 + bts $16, %esi
22896 + mov %esi, %cr0
22897 +#endif
22898 +
22899 pushl_cfi $__ESPFIX_SS
22900 pushl_cfi %eax /* new kernel esp */
22901 /* Disable interrupts, but do not irqtrace this section: we
22902 @@ -605,20 +832,18 @@ work_resched:
22903 movl TI_flags(%ebp), %ecx
22904 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
22905 # than syscall tracing?
22906 - jz restore_all
22907 + jz restore_all_pax
22908 testb $_TIF_NEED_RESCHED, %cl
22909 jnz work_resched
22910
22911 work_notifysig: # deal with pending signals and
22912 # notify-resume requests
22913 + movl %esp, %eax
22914 #ifdef CONFIG_VM86
22915 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
22916 - movl %esp, %eax
22917 jne work_notifysig_v86 # returning to kernel-space or
22918 # vm86-space
22919 1:
22920 -#else
22921 - movl %esp, %eax
22922 #endif
22923 TRACE_IRQS_ON
22924 ENABLE_INTERRUPTS(CLBR_NONE)
22925 @@ -639,7 +864,7 @@ work_notifysig_v86:
22926 movl %eax, %esp
22927 jmp 1b
22928 #endif
22929 -END(work_pending)
22930 +ENDPROC(work_pending)
22931
22932 # perform syscall exit tracing
22933 ALIGN
22934 @@ -647,11 +872,14 @@ syscall_trace_entry:
22935 movl $-ENOSYS,PT_EAX(%esp)
22936 movl %esp, %eax
22937 call syscall_trace_enter
22938 +
22939 + pax_erase_kstack
22940 +
22941 /* What it returned is what we'll actually use. */
22942 cmpl $(NR_syscalls), %eax
22943 jnae syscall_call
22944 jmp syscall_exit
22945 -END(syscall_trace_entry)
22946 +ENDPROC(syscall_trace_entry)
22947
22948 # perform syscall exit tracing
22949 ALIGN
22950 @@ -664,26 +892,30 @@ syscall_exit_work:
22951 movl %esp, %eax
22952 call syscall_trace_leave
22953 jmp resume_userspace
22954 -END(syscall_exit_work)
22955 +ENDPROC(syscall_exit_work)
22956 CFI_ENDPROC
22957
22958 RING0_INT_FRAME # can't unwind into user space anyway
22959 syscall_fault:
22960 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22961 + push %ss
22962 + pop %ds
22963 +#endif
22964 ASM_CLAC
22965 GET_THREAD_INFO(%ebp)
22966 movl $-EFAULT,PT_EAX(%esp)
22967 jmp resume_userspace
22968 -END(syscall_fault)
22969 +ENDPROC(syscall_fault)
22970
22971 syscall_badsys:
22972 movl $-ENOSYS,%eax
22973 jmp syscall_after_call
22974 -END(syscall_badsys)
22975 +ENDPROC(syscall_badsys)
22976
22977 sysenter_badsys:
22978 movl $-ENOSYS,%eax
22979 jmp sysenter_after_call
22980 -END(syscall_badsys)
22981 +ENDPROC(sysenter_badsys)
22982 CFI_ENDPROC
22983
22984 .macro FIXUP_ESPFIX_STACK
22985 @@ -696,8 +928,15 @@ END(syscall_badsys)
22986 */
22987 #ifdef CONFIG_X86_ESPFIX32
22988 /* fixup the stack */
22989 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
22990 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
22991 +#ifdef CONFIG_SMP
22992 + movl PER_CPU_VAR(cpu_number), %ebx
22993 + shll $PAGE_SHIFT_asm, %ebx
22994 + addl $cpu_gdt_table, %ebx
22995 +#else
22996 + movl $cpu_gdt_table, %ebx
22997 +#endif
22998 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
22999 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
23000 shl $16, %eax
23001 addl %esp, %eax /* the adjusted stack pointer */
23002 pushl_cfi $__KERNEL_DS
23003 @@ -753,7 +992,7 @@ vector=vector+1
23004 .endr
23005 2: jmp common_interrupt
23006 .endr
23007 -END(irq_entries_start)
23008 +ENDPROC(irq_entries_start)
23009
23010 .previous
23011 END(interrupt)
23012 @@ -810,7 +1049,7 @@ ENTRY(coprocessor_error)
23013 pushl_cfi $do_coprocessor_error
23014 jmp error_code
23015 CFI_ENDPROC
23016 -END(coprocessor_error)
23017 +ENDPROC(coprocessor_error)
23018
23019 ENTRY(simd_coprocessor_error)
23020 RING0_INT_FRAME
23021 @@ -823,7 +1062,7 @@ ENTRY(simd_coprocessor_error)
23022 .section .altinstructions,"a"
23023 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
23024 .previous
23025 -.section .altinstr_replacement,"ax"
23026 +.section .altinstr_replacement,"a"
23027 663: pushl $do_simd_coprocessor_error
23028 664:
23029 .previous
23030 @@ -832,7 +1071,7 @@ ENTRY(simd_coprocessor_error)
23031 #endif
23032 jmp error_code
23033 CFI_ENDPROC
23034 -END(simd_coprocessor_error)
23035 +ENDPROC(simd_coprocessor_error)
23036
23037 ENTRY(device_not_available)
23038 RING0_INT_FRAME
23039 @@ -841,18 +1080,18 @@ ENTRY(device_not_available)
23040 pushl_cfi $do_device_not_available
23041 jmp error_code
23042 CFI_ENDPROC
23043 -END(device_not_available)
23044 +ENDPROC(device_not_available)
23045
23046 #ifdef CONFIG_PARAVIRT
23047 ENTRY(native_iret)
23048 iret
23049 _ASM_EXTABLE(native_iret, iret_exc)
23050 -END(native_iret)
23051 +ENDPROC(native_iret)
23052
23053 ENTRY(native_irq_enable_sysexit)
23054 sti
23055 sysexit
23056 -END(native_irq_enable_sysexit)
23057 +ENDPROC(native_irq_enable_sysexit)
23058 #endif
23059
23060 ENTRY(overflow)
23061 @@ -862,7 +1101,7 @@ ENTRY(overflow)
23062 pushl_cfi $do_overflow
23063 jmp error_code
23064 CFI_ENDPROC
23065 -END(overflow)
23066 +ENDPROC(overflow)
23067
23068 ENTRY(bounds)
23069 RING0_INT_FRAME
23070 @@ -871,7 +1110,7 @@ ENTRY(bounds)
23071 pushl_cfi $do_bounds
23072 jmp error_code
23073 CFI_ENDPROC
23074 -END(bounds)
23075 +ENDPROC(bounds)
23076
23077 ENTRY(invalid_op)
23078 RING0_INT_FRAME
23079 @@ -880,7 +1119,7 @@ ENTRY(invalid_op)
23080 pushl_cfi $do_invalid_op
23081 jmp error_code
23082 CFI_ENDPROC
23083 -END(invalid_op)
23084 +ENDPROC(invalid_op)
23085
23086 ENTRY(coprocessor_segment_overrun)
23087 RING0_INT_FRAME
23088 @@ -889,7 +1128,7 @@ ENTRY(coprocessor_segment_overrun)
23089 pushl_cfi $do_coprocessor_segment_overrun
23090 jmp error_code
23091 CFI_ENDPROC
23092 -END(coprocessor_segment_overrun)
23093 +ENDPROC(coprocessor_segment_overrun)
23094
23095 ENTRY(invalid_TSS)
23096 RING0_EC_FRAME
23097 @@ -897,7 +1136,7 @@ ENTRY(invalid_TSS)
23098 pushl_cfi $do_invalid_TSS
23099 jmp error_code
23100 CFI_ENDPROC
23101 -END(invalid_TSS)
23102 +ENDPROC(invalid_TSS)
23103
23104 ENTRY(segment_not_present)
23105 RING0_EC_FRAME
23106 @@ -905,7 +1144,7 @@ ENTRY(segment_not_present)
23107 pushl_cfi $do_segment_not_present
23108 jmp error_code
23109 CFI_ENDPROC
23110 -END(segment_not_present)
23111 +ENDPROC(segment_not_present)
23112
23113 ENTRY(stack_segment)
23114 RING0_EC_FRAME
23115 @@ -913,7 +1152,7 @@ ENTRY(stack_segment)
23116 pushl_cfi $do_stack_segment
23117 jmp error_code
23118 CFI_ENDPROC
23119 -END(stack_segment)
23120 +ENDPROC(stack_segment)
23121
23122 ENTRY(alignment_check)
23123 RING0_EC_FRAME
23124 @@ -921,7 +1160,7 @@ ENTRY(alignment_check)
23125 pushl_cfi $do_alignment_check
23126 jmp error_code
23127 CFI_ENDPROC
23128 -END(alignment_check)
23129 +ENDPROC(alignment_check)
23130
23131 ENTRY(divide_error)
23132 RING0_INT_FRAME
23133 @@ -930,7 +1169,7 @@ ENTRY(divide_error)
23134 pushl_cfi $do_divide_error
23135 jmp error_code
23136 CFI_ENDPROC
23137 -END(divide_error)
23138 +ENDPROC(divide_error)
23139
23140 #ifdef CONFIG_X86_MCE
23141 ENTRY(machine_check)
23142 @@ -940,7 +1179,7 @@ ENTRY(machine_check)
23143 pushl_cfi machine_check_vector
23144 jmp error_code
23145 CFI_ENDPROC
23146 -END(machine_check)
23147 +ENDPROC(machine_check)
23148 #endif
23149
23150 ENTRY(spurious_interrupt_bug)
23151 @@ -950,7 +1189,7 @@ ENTRY(spurious_interrupt_bug)
23152 pushl_cfi $do_spurious_interrupt_bug
23153 jmp error_code
23154 CFI_ENDPROC
23155 -END(spurious_interrupt_bug)
23156 +ENDPROC(spurious_interrupt_bug)
23157
23158 #ifdef CONFIG_XEN
23159 /* Xen doesn't set %esp to be precisely what the normal sysenter
23160 @@ -1056,7 +1295,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
23161
23162 ENTRY(mcount)
23163 ret
23164 -END(mcount)
23165 +ENDPROC(mcount)
23166
23167 ENTRY(ftrace_caller)
23168 cmpl $0, function_trace_stop
23169 @@ -1089,7 +1328,7 @@ ftrace_graph_call:
23170 .globl ftrace_stub
23171 ftrace_stub:
23172 ret
23173 -END(ftrace_caller)
23174 +ENDPROC(ftrace_caller)
23175
23176 ENTRY(ftrace_regs_caller)
23177 pushf /* push flags before compare (in cs location) */
23178 @@ -1193,7 +1432,7 @@ trace:
23179 popl %ecx
23180 popl %eax
23181 jmp ftrace_stub
23182 -END(mcount)
23183 +ENDPROC(mcount)
23184 #endif /* CONFIG_DYNAMIC_FTRACE */
23185 #endif /* CONFIG_FUNCTION_TRACER */
23186
23187 @@ -1211,7 +1450,7 @@ ENTRY(ftrace_graph_caller)
23188 popl %ecx
23189 popl %eax
23190 ret
23191 -END(ftrace_graph_caller)
23192 +ENDPROC(ftrace_graph_caller)
23193
23194 .globl return_to_handler
23195 return_to_handler:
23196 @@ -1272,15 +1511,18 @@ error_code:
23197 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
23198 REG_TO_PTGS %ecx
23199 SET_KERNEL_GS %ecx
23200 - movl $(__USER_DS), %ecx
23201 + movl $(__KERNEL_DS), %ecx
23202 movl %ecx, %ds
23203 movl %ecx, %es
23204 +
23205 + pax_enter_kernel
23206 +
23207 TRACE_IRQS_OFF
23208 movl %esp,%eax # pt_regs pointer
23209 call *%edi
23210 jmp ret_from_exception
23211 CFI_ENDPROC
23212 -END(page_fault)
23213 +ENDPROC(page_fault)
23214
23215 /*
23216 * Debug traps and NMI can happen at the one SYSENTER instruction
23217 @@ -1323,7 +1565,7 @@ debug_stack_correct:
23218 call do_debug
23219 jmp ret_from_exception
23220 CFI_ENDPROC
23221 -END(debug)
23222 +ENDPROC(debug)
23223
23224 /*
23225 * NMI is doubly nasty. It can happen _while_ we're handling
23226 @@ -1363,6 +1605,9 @@ nmi_stack_correct:
23227 xorl %edx,%edx # zero error code
23228 movl %esp,%eax # pt_regs pointer
23229 call do_nmi
23230 +
23231 + pax_exit_kernel
23232 +
23233 jmp restore_all_notrace
23234 CFI_ENDPROC
23235
23236 @@ -1400,13 +1645,16 @@ nmi_espfix_stack:
23237 FIXUP_ESPFIX_STACK # %eax == %esp
23238 xorl %edx,%edx # zero error code
23239 call do_nmi
23240 +
23241 + pax_exit_kernel
23242 +
23243 RESTORE_REGS
23244 lss 12+4(%esp), %esp # back to espfix stack
23245 CFI_ADJUST_CFA_OFFSET -24
23246 jmp irq_return
23247 #endif
23248 CFI_ENDPROC
23249 -END(nmi)
23250 +ENDPROC(nmi)
23251
23252 ENTRY(int3)
23253 RING0_INT_FRAME
23254 @@ -1419,14 +1667,14 @@ ENTRY(int3)
23255 call do_int3
23256 jmp ret_from_exception
23257 CFI_ENDPROC
23258 -END(int3)
23259 +ENDPROC(int3)
23260
23261 ENTRY(general_protection)
23262 RING0_EC_FRAME
23263 pushl_cfi $do_general_protection
23264 jmp error_code
23265 CFI_ENDPROC
23266 -END(general_protection)
23267 +ENDPROC(general_protection)
23268
23269 #ifdef CONFIG_KVM_GUEST
23270 ENTRY(async_page_fault)
23271 @@ -1435,6 +1683,6 @@ ENTRY(async_page_fault)
23272 pushl_cfi $do_async_page_fault
23273 jmp error_code
23274 CFI_ENDPROC
23275 -END(async_page_fault)
23276 +ENDPROC(async_page_fault)
23277 #endif
23278
23279 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
23280 index c844f08..b07ea0e 100644
23281 --- a/arch/x86/kernel/entry_64.S
23282 +++ b/arch/x86/kernel/entry_64.S
23283 @@ -59,6 +59,8 @@
23284 #include <asm/smap.h>
23285 #include <asm/pgtable_types.h>
23286 #include <linux/err.h>
23287 +#include <asm/pgtable.h>
23288 +#include <asm/alternative-asm.h>
23289
23290 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
23291 #include <linux/elf-em.h>
23292 @@ -81,6 +83,430 @@ ENTRY(native_usergs_sysret64)
23293 ENDPROC(native_usergs_sysret64)
23294 #endif /* CONFIG_PARAVIRT */
23295
23296 + .macro ljmpq sel, off
23297 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
23298 + .byte 0x48; ljmp *1234f(%rip)
23299 + .pushsection .rodata
23300 + .align 16
23301 + 1234: .quad \off; .word \sel
23302 + .popsection
23303 +#else
23304 + pushq $\sel
23305 + pushq $\off
23306 + lretq
23307 +#endif
23308 + .endm
23309 +
23310 + .macro pax_enter_kernel
23311 + pax_set_fptr_mask
23312 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23313 + call pax_enter_kernel
23314 +#endif
23315 + .endm
23316 +
23317 + .macro pax_exit_kernel
23318 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23319 + call pax_exit_kernel
23320 +#endif
23321 +
23322 + .endm
23323 +
23324 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23325 +ENTRY(pax_enter_kernel)
23326 + pushq %rdi
23327 +
23328 +#ifdef CONFIG_PARAVIRT
23329 + PV_SAVE_REGS(CLBR_RDI)
23330 +#endif
23331 +
23332 +#ifdef CONFIG_PAX_KERNEXEC
23333 + GET_CR0_INTO_RDI
23334 + bts $16,%rdi
23335 + jnc 3f
23336 + mov %cs,%edi
23337 + cmp $__KERNEL_CS,%edi
23338 + jnz 2f
23339 +1:
23340 +#endif
23341 +
23342 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23343 + 661: jmp 111f
23344 + .pushsection .altinstr_replacement, "a"
23345 + 662: ASM_NOP2
23346 + .popsection
23347 + .pushsection .altinstructions, "a"
23348 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23349 + .popsection
23350 + GET_CR3_INTO_RDI
23351 + cmp $0,%dil
23352 + jnz 112f
23353 + mov $__KERNEL_DS,%edi
23354 + mov %edi,%ss
23355 + jmp 111f
23356 +112: cmp $1,%dil
23357 + jz 113f
23358 + ud2
23359 +113: sub $4097,%rdi
23360 + bts $63,%rdi
23361 + SET_RDI_INTO_CR3
23362 + mov $__UDEREF_KERNEL_DS,%edi
23363 + mov %edi,%ss
23364 +111:
23365 +#endif
23366 +
23367 +#ifdef CONFIG_PARAVIRT
23368 + PV_RESTORE_REGS(CLBR_RDI)
23369 +#endif
23370 +
23371 + popq %rdi
23372 + pax_force_retaddr
23373 + retq
23374 +
23375 +#ifdef CONFIG_PAX_KERNEXEC
23376 +2: ljmpq __KERNEL_CS,1b
23377 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
23378 +4: SET_RDI_INTO_CR0
23379 + jmp 1b
23380 +#endif
23381 +ENDPROC(pax_enter_kernel)
23382 +
23383 +ENTRY(pax_exit_kernel)
23384 + pushq %rdi
23385 +
23386 +#ifdef CONFIG_PARAVIRT
23387 + PV_SAVE_REGS(CLBR_RDI)
23388 +#endif
23389 +
23390 +#ifdef CONFIG_PAX_KERNEXEC
23391 + mov %cs,%rdi
23392 + cmp $__KERNEXEC_KERNEL_CS,%edi
23393 + jz 2f
23394 + GET_CR0_INTO_RDI
23395 + bts $16,%rdi
23396 + jnc 4f
23397 +1:
23398 +#endif
23399 +
23400 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23401 + 661: jmp 111f
23402 + .pushsection .altinstr_replacement, "a"
23403 + 662: ASM_NOP2
23404 + .popsection
23405 + .pushsection .altinstructions, "a"
23406 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23407 + .popsection
23408 + mov %ss,%edi
23409 + cmp $__UDEREF_KERNEL_DS,%edi
23410 + jnz 111f
23411 + GET_CR3_INTO_RDI
23412 + cmp $0,%dil
23413 + jz 112f
23414 + ud2
23415 +112: add $4097,%rdi
23416 + bts $63,%rdi
23417 + SET_RDI_INTO_CR3
23418 + mov $__KERNEL_DS,%edi
23419 + mov %edi,%ss
23420 +111:
23421 +#endif
23422 +
23423 +#ifdef CONFIG_PARAVIRT
23424 + PV_RESTORE_REGS(CLBR_RDI);
23425 +#endif
23426 +
23427 + popq %rdi
23428 + pax_force_retaddr
23429 + retq
23430 +
23431 +#ifdef CONFIG_PAX_KERNEXEC
23432 +2: GET_CR0_INTO_RDI
23433 + btr $16,%rdi
23434 + jnc 4f
23435 + ljmpq __KERNEL_CS,3f
23436 +3: SET_RDI_INTO_CR0
23437 + jmp 1b
23438 +4: ud2
23439 + jmp 4b
23440 +#endif
23441 +ENDPROC(pax_exit_kernel)
23442 +#endif
23443 +
23444 + .macro pax_enter_kernel_user
23445 + pax_set_fptr_mask
23446 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23447 + call pax_enter_kernel_user
23448 +#endif
23449 + .endm
23450 +
23451 + .macro pax_exit_kernel_user
23452 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23453 + call pax_exit_kernel_user
23454 +#endif
23455 +#ifdef CONFIG_PAX_RANDKSTACK
23456 + pushq %rax
23457 + pushq %r11
23458 + call pax_randomize_kstack
23459 + popq %r11
23460 + popq %rax
23461 +#endif
23462 + .endm
23463 +
23464 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23465 +ENTRY(pax_enter_kernel_user)
23466 + pushq %rdi
23467 + pushq %rbx
23468 +
23469 +#ifdef CONFIG_PARAVIRT
23470 + PV_SAVE_REGS(CLBR_RDI)
23471 +#endif
23472 +
23473 + 661: jmp 111f
23474 + .pushsection .altinstr_replacement, "a"
23475 + 662: ASM_NOP2
23476 + .popsection
23477 + .pushsection .altinstructions, "a"
23478 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23479 + .popsection
23480 + GET_CR3_INTO_RDI
23481 + cmp $1,%dil
23482 + jnz 4f
23483 + sub $4097,%rdi
23484 + bts $63,%rdi
23485 + SET_RDI_INTO_CR3
23486 + jmp 3f
23487 +111:
23488 +
23489 + GET_CR3_INTO_RDI
23490 + mov %rdi,%rbx
23491 + add $__START_KERNEL_map,%rbx
23492 + sub phys_base(%rip),%rbx
23493 +
23494 +#ifdef CONFIG_PARAVIRT
23495 + cmpl $0, pv_info+PARAVIRT_enabled
23496 + jz 1f
23497 + pushq %rdi
23498 + i = 0
23499 + .rept USER_PGD_PTRS
23500 + mov i*8(%rbx),%rsi
23501 + mov $0,%sil
23502 + lea i*8(%rbx),%rdi
23503 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23504 + i = i + 1
23505 + .endr
23506 + popq %rdi
23507 + jmp 2f
23508 +1:
23509 +#endif
23510 +
23511 + i = 0
23512 + .rept USER_PGD_PTRS
23513 + movb $0,i*8(%rbx)
23514 + i = i + 1
23515 + .endr
23516 +
23517 +2: SET_RDI_INTO_CR3
23518 +
23519 +#ifdef CONFIG_PAX_KERNEXEC
23520 + GET_CR0_INTO_RDI
23521 + bts $16,%rdi
23522 + SET_RDI_INTO_CR0
23523 +#endif
23524 +
23525 +3:
23526 +
23527 +#ifdef CONFIG_PARAVIRT
23528 + PV_RESTORE_REGS(CLBR_RDI)
23529 +#endif
23530 +
23531 + popq %rbx
23532 + popq %rdi
23533 + pax_force_retaddr
23534 + retq
23535 +4: ud2
23536 +ENDPROC(pax_enter_kernel_user)
23537 +
23538 +ENTRY(pax_exit_kernel_user)
23539 + pushq %rdi
23540 + pushq %rbx
23541 +
23542 +#ifdef CONFIG_PARAVIRT
23543 + PV_SAVE_REGS(CLBR_RDI)
23544 +#endif
23545 +
23546 + GET_CR3_INTO_RDI
23547 + 661: jmp 1f
23548 + .pushsection .altinstr_replacement, "a"
23549 + 662: ASM_NOP2
23550 + .popsection
23551 + .pushsection .altinstructions, "a"
23552 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23553 + .popsection
23554 + cmp $0,%dil
23555 + jnz 3f
23556 + add $4097,%rdi
23557 + bts $63,%rdi
23558 + SET_RDI_INTO_CR3
23559 + jmp 2f
23560 +1:
23561 +
23562 + mov %rdi,%rbx
23563 +
23564 +#ifdef CONFIG_PAX_KERNEXEC
23565 + GET_CR0_INTO_RDI
23566 + btr $16,%rdi
23567 + jnc 3f
23568 + SET_RDI_INTO_CR0
23569 +#endif
23570 +
23571 + add $__START_KERNEL_map,%rbx
23572 + sub phys_base(%rip),%rbx
23573 +
23574 +#ifdef CONFIG_PARAVIRT
23575 + cmpl $0, pv_info+PARAVIRT_enabled
23576 + jz 1f
23577 + i = 0
23578 + .rept USER_PGD_PTRS
23579 + mov i*8(%rbx),%rsi
23580 + mov $0x67,%sil
23581 + lea i*8(%rbx),%rdi
23582 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23583 + i = i + 1
23584 + .endr
23585 + jmp 2f
23586 +1:
23587 +#endif
23588 +
23589 + i = 0
23590 + .rept USER_PGD_PTRS
23591 + movb $0x67,i*8(%rbx)
23592 + i = i + 1
23593 + .endr
23594 +2:
23595 +
23596 +#ifdef CONFIG_PARAVIRT
23597 + PV_RESTORE_REGS(CLBR_RDI)
23598 +#endif
23599 +
23600 + popq %rbx
23601 + popq %rdi
23602 + pax_force_retaddr
23603 + retq
23604 +3: ud2
23605 +ENDPROC(pax_exit_kernel_user)
23606 +#endif
23607 +
23608 + .macro pax_enter_kernel_nmi
23609 + pax_set_fptr_mask
23610 +
23611 +#ifdef CONFIG_PAX_KERNEXEC
23612 + GET_CR0_INTO_RDI
23613 + bts $16,%rdi
23614 + jc 110f
23615 + SET_RDI_INTO_CR0
23616 + or $2,%ebx
23617 +110:
23618 +#endif
23619 +
23620 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23621 + 661: jmp 111f
23622 + .pushsection .altinstr_replacement, "a"
23623 + 662: ASM_NOP2
23624 + .popsection
23625 + .pushsection .altinstructions, "a"
23626 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23627 + .popsection
23628 + GET_CR3_INTO_RDI
23629 + cmp $0,%dil
23630 + jz 111f
23631 + sub $4097,%rdi
23632 + or $4,%ebx
23633 + bts $63,%rdi
23634 + SET_RDI_INTO_CR3
23635 + mov $__UDEREF_KERNEL_DS,%edi
23636 + mov %edi,%ss
23637 +111:
23638 +#endif
23639 + .endm
23640 +
23641 + .macro pax_exit_kernel_nmi
23642 +#ifdef CONFIG_PAX_KERNEXEC
23643 + btr $1,%ebx
23644 + jnc 110f
23645 + GET_CR0_INTO_RDI
23646 + btr $16,%rdi
23647 + SET_RDI_INTO_CR0
23648 +110:
23649 +#endif
23650 +
23651 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23652 + btr $2,%ebx
23653 + jnc 111f
23654 + GET_CR3_INTO_RDI
23655 + add $4097,%rdi
23656 + bts $63,%rdi
23657 + SET_RDI_INTO_CR3
23658 + mov $__KERNEL_DS,%edi
23659 + mov %edi,%ss
23660 +111:
23661 +#endif
23662 + .endm
23663 +
23664 + .macro pax_erase_kstack
23665 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23666 + call pax_erase_kstack
23667 +#endif
23668 + .endm
23669 +
23670 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23671 +ENTRY(pax_erase_kstack)
23672 + pushq %rdi
23673 + pushq %rcx
23674 + pushq %rax
23675 + pushq %r11
23676 +
23677 + GET_THREAD_INFO(%r11)
23678 + mov TI_lowest_stack(%r11), %rdi
23679 + mov $-0xBEEF, %rax
23680 + std
23681 +
23682 +1: mov %edi, %ecx
23683 + and $THREAD_SIZE_asm - 1, %ecx
23684 + shr $3, %ecx
23685 + repne scasq
23686 + jecxz 2f
23687 +
23688 + cmp $2*8, %ecx
23689 + jc 2f
23690 +
23691 + mov $2*8, %ecx
23692 + repe scasq
23693 + jecxz 2f
23694 + jne 1b
23695 +
23696 +2: cld
23697 + mov %esp, %ecx
23698 + sub %edi, %ecx
23699 +
23700 + cmp $THREAD_SIZE_asm, %rcx
23701 + jb 3f
23702 + ud2
23703 +3:
23704 +
23705 + shr $3, %ecx
23706 + rep stosq
23707 +
23708 + mov TI_task_thread_sp0(%r11), %rdi
23709 + sub $256, %rdi
23710 + mov %rdi, TI_lowest_stack(%r11)
23711 +
23712 + popq %r11
23713 + popq %rax
23714 + popq %rcx
23715 + popq %rdi
23716 + pax_force_retaddr
23717 + ret
23718 +ENDPROC(pax_erase_kstack)
23719 +#endif
23720
23721 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
23722 #ifdef CONFIG_TRACE_IRQFLAGS
23723 @@ -117,7 +543,7 @@ ENDPROC(native_usergs_sysret64)
23724 .endm
23725
23726 .macro TRACE_IRQS_IRETQ_DEBUG offset=ARGOFFSET
23727 - bt $9,EFLAGS-\offset(%rsp) /* interrupts off? */
23728 + bt $X86_EFLAGS_IF_BIT,EFLAGS-\offset(%rsp) /* interrupts off? */
23729 jnc 1f
23730 TRACE_IRQS_ON_DEBUG
23731 1:
23732 @@ -155,27 +581,6 @@ ENDPROC(native_usergs_sysret64)
23733 movq \tmp,R11+\offset(%rsp)
23734 .endm
23735
23736 - .macro FAKE_STACK_FRAME child_rip
23737 - /* push in order ss, rsp, eflags, cs, rip */
23738 - xorl %eax, %eax
23739 - pushq_cfi $__KERNEL_DS /* ss */
23740 - /*CFI_REL_OFFSET ss,0*/
23741 - pushq_cfi %rax /* rsp */
23742 - CFI_REL_OFFSET rsp,0
23743 - pushq_cfi $(X86_EFLAGS_IF|X86_EFLAGS_FIXED) /* eflags - interrupts on */
23744 - /*CFI_REL_OFFSET rflags,0*/
23745 - pushq_cfi $__KERNEL_CS /* cs */
23746 - /*CFI_REL_OFFSET cs,0*/
23747 - pushq_cfi \child_rip /* rip */
23748 - CFI_REL_OFFSET rip,0
23749 - pushq_cfi %rax /* orig rax */
23750 - .endm
23751 -
23752 - .macro UNFAKE_STACK_FRAME
23753 - addq $8*6, %rsp
23754 - CFI_ADJUST_CFA_OFFSET -(6*8)
23755 - .endm
23756 -
23757 /*
23758 * initial frame state for interrupts (and exceptions without error code)
23759 */
23760 @@ -242,25 +647,26 @@ ENDPROC(native_usergs_sysret64)
23761 /* save partial stack frame */
23762 .macro SAVE_ARGS_IRQ
23763 cld
23764 - /* start from rbp in pt_regs and jump over */
23765 - movq_cfi rdi, (RDI-RBP)
23766 - movq_cfi rsi, (RSI-RBP)
23767 - movq_cfi rdx, (RDX-RBP)
23768 - movq_cfi rcx, (RCX-RBP)
23769 - movq_cfi rax, (RAX-RBP)
23770 - movq_cfi r8, (R8-RBP)
23771 - movq_cfi r9, (R9-RBP)
23772 - movq_cfi r10, (R10-RBP)
23773 - movq_cfi r11, (R11-RBP)
23774 + /* start from r15 in pt_regs and jump over */
23775 + movq_cfi rdi, RDI
23776 + movq_cfi rsi, RSI
23777 + movq_cfi rdx, RDX
23778 + movq_cfi rcx, RCX
23779 + movq_cfi rax, RAX
23780 + movq_cfi r8, R8
23781 + movq_cfi r9, R9
23782 + movq_cfi r10, R10
23783 + movq_cfi r11, R11
23784 + movq_cfi r12, R12
23785
23786 /* Save rbp so that we can unwind from get_irq_regs() */
23787 - movq_cfi rbp, 0
23788 + movq_cfi rbp, RBP
23789
23790 /* Save previous stack value */
23791 movq %rsp, %rsi
23792
23793 - leaq -RBP(%rsp),%rdi /* arg1 for handler */
23794 - testl $3, CS-RBP(%rsi)
23795 + movq %rsp,%rdi /* arg1 for handler */
23796 + testb $3, CS(%rsi)
23797 je 1f
23798 SWAPGS
23799 /*
23800 @@ -280,6 +686,18 @@ ENDPROC(native_usergs_sysret64)
23801 0x06 /* DW_OP_deref */, \
23802 0x08 /* DW_OP_const1u */, SS+8-RBP, \
23803 0x22 /* DW_OP_plus */
23804 +
23805 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23806 + testb $3, CS(%rdi)
23807 + jnz 1f
23808 + pax_enter_kernel
23809 + jmp 2f
23810 +1: pax_enter_kernel_user
23811 +2:
23812 +#else
23813 + pax_enter_kernel
23814 +#endif
23815 +
23816 /* We entered an interrupt context - irqs are off: */
23817 TRACE_IRQS_OFF
23818 .endm
23819 @@ -309,9 +727,52 @@ ENTRY(save_paranoid)
23820 js 1f /* negative -> in kernel */
23821 SWAPGS
23822 xorl %ebx,%ebx
23823 -1: ret
23824 +1:
23825 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23826 + testb $3, CS+8(%rsp)
23827 + jnz 1f
23828 + pax_enter_kernel
23829 + jmp 2f
23830 +1: pax_enter_kernel_user
23831 +2:
23832 +#else
23833 + pax_enter_kernel
23834 +#endif
23835 + pax_force_retaddr
23836 + ret
23837 CFI_ENDPROC
23838 -END(save_paranoid)
23839 +ENDPROC(save_paranoid)
23840 +
23841 +ENTRY(save_paranoid_nmi)
23842 + XCPT_FRAME 1 RDI+8
23843 + cld
23844 + movq_cfi rdi, RDI+8
23845 + movq_cfi rsi, RSI+8
23846 + movq_cfi rdx, RDX+8
23847 + movq_cfi rcx, RCX+8
23848 + movq_cfi rax, RAX+8
23849 + movq_cfi r8, R8+8
23850 + movq_cfi r9, R9+8
23851 + movq_cfi r10, R10+8
23852 + movq_cfi r11, R11+8
23853 + movq_cfi rbx, RBX+8
23854 + movq_cfi rbp, RBP+8
23855 + movq_cfi r12, R12+8
23856 + movq_cfi r13, R13+8
23857 + movq_cfi r14, R14+8
23858 + movq_cfi r15, R15+8
23859 + movl $1,%ebx
23860 + movl $MSR_GS_BASE,%ecx
23861 + rdmsr
23862 + testl %edx,%edx
23863 + js 1f /* negative -> in kernel */
23864 + SWAPGS
23865 + xorl %ebx,%ebx
23866 +1: pax_enter_kernel_nmi
23867 + pax_force_retaddr
23868 + ret
23869 + CFI_ENDPROC
23870 +ENDPROC(save_paranoid_nmi)
23871
23872 /*
23873 * A newly forked process directly context switches into this address.
23874 @@ -332,7 +793,7 @@ ENTRY(ret_from_fork)
23875
23876 RESTORE_REST
23877
23878 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23879 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23880 jz 1f
23881
23882 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
23883 @@ -342,15 +803,13 @@ ENTRY(ret_from_fork)
23884 jmp ret_from_sys_call # go to the SYSRET fastpath
23885
23886 1:
23887 - subq $REST_SKIP, %rsp # leave space for volatiles
23888 - CFI_ADJUST_CFA_OFFSET REST_SKIP
23889 movq %rbp, %rdi
23890 call *%rbx
23891 movl $0, RAX(%rsp)
23892 RESTORE_REST
23893 jmp int_ret_from_sys_call
23894 CFI_ENDPROC
23895 -END(ret_from_fork)
23896 +ENDPROC(ret_from_fork)
23897
23898 /*
23899 * System call entry. Up to 6 arguments in registers are supported.
23900 @@ -387,7 +846,7 @@ END(ret_from_fork)
23901 ENTRY(system_call)
23902 CFI_STARTPROC simple
23903 CFI_SIGNAL_FRAME
23904 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
23905 + CFI_DEF_CFA rsp,0
23906 CFI_REGISTER rip,rcx
23907 /*CFI_REGISTER rflags,r11*/
23908 SWAPGS_UNSAFE_STACK
23909 @@ -400,16 +859,23 @@ GLOBAL(system_call_after_swapgs)
23910
23911 movq %rsp,PER_CPU_VAR(old_rsp)
23912 movq PER_CPU_VAR(kernel_stack),%rsp
23913 + SAVE_ARGS 8*6,0
23914 + pax_enter_kernel_user
23915 +
23916 +#ifdef CONFIG_PAX_RANDKSTACK
23917 + pax_erase_kstack
23918 +#endif
23919 +
23920 /*
23921 * No need to follow this irqs off/on section - it's straight
23922 * and short:
23923 */
23924 ENABLE_INTERRUPTS(CLBR_NONE)
23925 - SAVE_ARGS 8,0
23926 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
23927 movq %rcx,RIP-ARGOFFSET(%rsp)
23928 CFI_REL_OFFSET rip,RIP-ARGOFFSET
23929 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23930 + GET_THREAD_INFO(%rcx)
23931 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
23932 jnz tracesys
23933 system_call_fastpath:
23934 #if __SYSCALL_MASK == ~0
23935 @@ -433,10 +899,13 @@ sysret_check:
23936 LOCKDEP_SYS_EXIT
23937 DISABLE_INTERRUPTS(CLBR_NONE)
23938 TRACE_IRQS_OFF
23939 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
23940 + GET_THREAD_INFO(%rcx)
23941 + movl TI_flags(%rcx),%edx
23942 andl %edi,%edx
23943 jnz sysret_careful
23944 CFI_REMEMBER_STATE
23945 + pax_exit_kernel_user
23946 + pax_erase_kstack
23947 /*
23948 * sysretq will re-enable interrupts:
23949 */
23950 @@ -495,6 +964,9 @@ auditsys:
23951 movq %rax,%rsi /* 2nd arg: syscall number */
23952 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
23953 call __audit_syscall_entry
23954 +
23955 + pax_erase_kstack
23956 +
23957 LOAD_ARGS 0 /* reload call-clobbered registers */
23958 jmp system_call_fastpath
23959
23960 @@ -516,7 +988,7 @@ sysret_audit:
23961 /* Do syscall tracing */
23962 tracesys:
23963 #ifdef CONFIG_AUDITSYSCALL
23964 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23965 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
23966 jz auditsys
23967 #endif
23968 SAVE_REST
23969 @@ -524,12 +996,15 @@ tracesys:
23970 FIXUP_TOP_OF_STACK %rdi
23971 movq %rsp,%rdi
23972 call syscall_trace_enter
23973 +
23974 + pax_erase_kstack
23975 +
23976 /*
23977 * Reload arg registers from stack in case ptrace changed them.
23978 * We don't reload %rax because syscall_trace_enter() returned
23979 * the value it wants us to use in the table lookup.
23980 */
23981 - LOAD_ARGS ARGOFFSET, 1
23982 + LOAD_ARGS 1
23983 RESTORE_REST
23984 #if __SYSCALL_MASK == ~0
23985 cmpq $__NR_syscall_max,%rax
23986 @@ -559,7 +1034,9 @@ GLOBAL(int_with_check)
23987 andl %edi,%edx
23988 jnz int_careful
23989 andl $~TS_COMPAT,TI_status(%rcx)
23990 - jmp retint_swapgs
23991 + pax_exit_kernel_user
23992 + pax_erase_kstack
23993 + jmp retint_swapgs_pax
23994
23995 /* Either reschedule or signal or syscall exit tracking needed. */
23996 /* First do a reschedule test. */
23997 @@ -605,7 +1082,7 @@ int_restore_rest:
23998 TRACE_IRQS_OFF
23999 jmp int_with_check
24000 CFI_ENDPROC
24001 -END(system_call)
24002 +ENDPROC(system_call)
24003
24004 .macro FORK_LIKE func
24005 ENTRY(stub_\func)
24006 @@ -618,9 +1095,10 @@ ENTRY(stub_\func)
24007 DEFAULT_FRAME 0 8 /* offset 8: return address */
24008 call sys_\func
24009 RESTORE_TOP_OF_STACK %r11, 8
24010 - ret $REST_SKIP /* pop extended registers */
24011 + pax_force_retaddr
24012 + ret
24013 CFI_ENDPROC
24014 -END(stub_\func)
24015 +ENDPROC(stub_\func)
24016 .endm
24017
24018 .macro FIXED_FRAME label,func
24019 @@ -630,9 +1108,10 @@ ENTRY(\label)
24020 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
24021 call \func
24022 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
24023 + pax_force_retaddr
24024 ret
24025 CFI_ENDPROC
24026 -END(\label)
24027 +ENDPROC(\label)
24028 .endm
24029
24030 FORK_LIKE clone
24031 @@ -640,19 +1119,6 @@ END(\label)
24032 FORK_LIKE vfork
24033 FIXED_FRAME stub_iopl, sys_iopl
24034
24035 -ENTRY(ptregscall_common)
24036 - DEFAULT_FRAME 1 8 /* offset 8: return address */
24037 - RESTORE_TOP_OF_STACK %r11, 8
24038 - movq_cfi_restore R15+8, r15
24039 - movq_cfi_restore R14+8, r14
24040 - movq_cfi_restore R13+8, r13
24041 - movq_cfi_restore R12+8, r12
24042 - movq_cfi_restore RBP+8, rbp
24043 - movq_cfi_restore RBX+8, rbx
24044 - ret $REST_SKIP /* pop extended registers */
24045 - CFI_ENDPROC
24046 -END(ptregscall_common)
24047 -
24048 ENTRY(stub_execve)
24049 CFI_STARTPROC
24050 addq $8, %rsp
24051 @@ -664,7 +1130,7 @@ ENTRY(stub_execve)
24052 RESTORE_REST
24053 jmp int_ret_from_sys_call
24054 CFI_ENDPROC
24055 -END(stub_execve)
24056 +ENDPROC(stub_execve)
24057
24058 /*
24059 * sigreturn is special because it needs to restore all registers on return.
24060 @@ -681,7 +1147,7 @@ ENTRY(stub_rt_sigreturn)
24061 RESTORE_REST
24062 jmp int_ret_from_sys_call
24063 CFI_ENDPROC
24064 -END(stub_rt_sigreturn)
24065 +ENDPROC(stub_rt_sigreturn)
24066
24067 #ifdef CONFIG_X86_X32_ABI
24068 ENTRY(stub_x32_rt_sigreturn)
24069 @@ -695,7 +1161,7 @@ ENTRY(stub_x32_rt_sigreturn)
24070 RESTORE_REST
24071 jmp int_ret_from_sys_call
24072 CFI_ENDPROC
24073 -END(stub_x32_rt_sigreturn)
24074 +ENDPROC(stub_x32_rt_sigreturn)
24075
24076 ENTRY(stub_x32_execve)
24077 CFI_STARTPROC
24078 @@ -709,7 +1175,7 @@ ENTRY(stub_x32_execve)
24079 RESTORE_REST
24080 jmp int_ret_from_sys_call
24081 CFI_ENDPROC
24082 -END(stub_x32_execve)
24083 +ENDPROC(stub_x32_execve)
24084
24085 #endif
24086
24087 @@ -746,7 +1212,7 @@ vector=vector+1
24088 2: jmp common_interrupt
24089 .endr
24090 CFI_ENDPROC
24091 -END(irq_entries_start)
24092 +ENDPROC(irq_entries_start)
24093
24094 .previous
24095 END(interrupt)
24096 @@ -763,8 +1229,8 @@ END(interrupt)
24097 /* 0(%rsp): ~(interrupt number) */
24098 .macro interrupt func
24099 /* reserve pt_regs for scratch regs and rbp */
24100 - subq $ORIG_RAX-RBP, %rsp
24101 - CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
24102 + subq $ORIG_RAX, %rsp
24103 + CFI_ADJUST_CFA_OFFSET ORIG_RAX
24104 SAVE_ARGS_IRQ
24105 call \func
24106 .endm
24107 @@ -787,14 +1253,14 @@ ret_from_intr:
24108
24109 /* Restore saved previous stack */
24110 popq %rsi
24111 - CFI_DEF_CFA rsi,SS+8-RBP /* reg/off reset after def_cfa_expr */
24112 - leaq ARGOFFSET-RBP(%rsi), %rsp
24113 + CFI_DEF_CFA rsi,SS+8 /* reg/off reset after def_cfa_expr */
24114 + movq %rsi, %rsp
24115 CFI_DEF_CFA_REGISTER rsp
24116 - CFI_ADJUST_CFA_OFFSET RBP-ARGOFFSET
24117 + CFI_ADJUST_CFA_OFFSET -ARGOFFSET
24118
24119 exit_intr:
24120 GET_THREAD_INFO(%rcx)
24121 - testl $3,CS-ARGOFFSET(%rsp)
24122 + testb $3,CS-ARGOFFSET(%rsp)
24123 je retint_kernel
24124
24125 /* Interrupt came from user space */
24126 @@ -816,12 +1282,16 @@ retint_swapgs: /* return to user-space */
24127 * The iretq could re-enable interrupts:
24128 */
24129 DISABLE_INTERRUPTS(CLBR_ANY)
24130 + pax_exit_kernel_user
24131 +retint_swapgs_pax:
24132 TRACE_IRQS_IRETQ
24133 SWAPGS
24134 jmp restore_args
24135
24136 retint_restore_args: /* return to kernel space */
24137 DISABLE_INTERRUPTS(CLBR_ANY)
24138 + pax_exit_kernel
24139 + pax_force_retaddr (RIP-ARGOFFSET)
24140 /*
24141 * The iretq could re-enable interrupts:
24142 */
24143 @@ -934,7 +1404,7 @@ ENTRY(retint_kernel)
24144 jmp exit_intr
24145 #endif
24146 CFI_ENDPROC
24147 -END(common_interrupt)
24148 +ENDPROC(common_interrupt)
24149
24150 /*
24151 * If IRET takes a fault on the espfix stack, then we
24152 @@ -956,13 +1426,13 @@ __do_double_fault:
24153 cmpq $native_irq_return_iret,%rax
24154 jne do_double_fault /* This shouldn't happen... */
24155 movq PER_CPU_VAR(kernel_stack),%rax
24156 - subq $(6*8-KERNEL_STACK_OFFSET),%rax /* Reset to original stack */
24157 + subq $(6*8),%rax /* Reset to original stack */
24158 movq %rax,RSP(%rdi)
24159 movq $0,(%rax) /* Missing (lost) #GP error code */
24160 movq $general_protection,RIP(%rdi)
24161 retq
24162 CFI_ENDPROC
24163 -END(__do_double_fault)
24164 +ENDPROC(__do_double_fault)
24165 #else
24166 # define __do_double_fault do_double_fault
24167 #endif
24168 @@ -979,7 +1449,7 @@ ENTRY(\sym)
24169 interrupt \do_sym
24170 jmp ret_from_intr
24171 CFI_ENDPROC
24172 -END(\sym)
24173 +ENDPROC(\sym)
24174 .endm
24175
24176 #ifdef CONFIG_TRACING
24177 @@ -1052,7 +1522,7 @@ apicinterrupt IRQ_WORK_VECTOR \
24178 /*
24179 * Exception entry points.
24180 */
24181 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
24182 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r13)
24183
24184 .macro idtentry sym do_sym has_error_code:req paranoid=0 shift_ist=-1
24185 ENTRY(\sym)
24186 @@ -1103,6 +1573,12 @@ ENTRY(\sym)
24187 .endif
24188
24189 .if \shift_ist != -1
24190 +#ifdef CONFIG_SMP
24191 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r13d
24192 + lea init_tss(%r13), %r13
24193 +#else
24194 + lea init_tss(%rip), %r13
24195 +#endif
24196 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\shift_ist)
24197 .endif
24198
24199 @@ -1119,7 +1595,7 @@ ENTRY(\sym)
24200 .endif
24201
24202 CFI_ENDPROC
24203 -END(\sym)
24204 +ENDPROC(\sym)
24205 .endm
24206
24207 #ifdef CONFIG_TRACING
24208 @@ -1160,9 +1636,10 @@ gs_change:
24209 2: mfence /* workaround */
24210 SWAPGS
24211 popfq_cfi
24212 + pax_force_retaddr
24213 ret
24214 CFI_ENDPROC
24215 -END(native_load_gs_index)
24216 +ENDPROC(native_load_gs_index)
24217
24218 _ASM_EXTABLE(gs_change,bad_gs)
24219 .section .fixup,"ax"
24220 @@ -1190,9 +1667,10 @@ ENTRY(do_softirq_own_stack)
24221 CFI_DEF_CFA_REGISTER rsp
24222 CFI_ADJUST_CFA_OFFSET -8
24223 decl PER_CPU_VAR(irq_count)
24224 + pax_force_retaddr
24225 ret
24226 CFI_ENDPROC
24227 -END(do_softirq_own_stack)
24228 +ENDPROC(do_softirq_own_stack)
24229
24230 #ifdef CONFIG_XEN
24231 idtentry xen_hypervisor_callback xen_do_hypervisor_callback has_error_code=0
24232 @@ -1230,7 +1708,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
24233 decl PER_CPU_VAR(irq_count)
24234 jmp error_exit
24235 CFI_ENDPROC
24236 -END(xen_do_hypervisor_callback)
24237 +ENDPROC(xen_do_hypervisor_callback)
24238
24239 /*
24240 * Hypervisor uses this for application faults while it executes.
24241 @@ -1289,7 +1767,7 @@ ENTRY(xen_failsafe_callback)
24242 SAVE_ALL
24243 jmp error_exit
24244 CFI_ENDPROC
24245 -END(xen_failsafe_callback)
24246 +ENDPROC(xen_failsafe_callback)
24247
24248 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
24249 xen_hvm_callback_vector xen_evtchn_do_upcall
24250 @@ -1336,18 +1814,33 @@ ENTRY(paranoid_exit)
24251 DEFAULT_FRAME
24252 DISABLE_INTERRUPTS(CLBR_NONE)
24253 TRACE_IRQS_OFF_DEBUG
24254 - testl %ebx,%ebx /* swapgs needed? */
24255 + testl $1,%ebx /* swapgs needed? */
24256 jnz paranoid_restore
24257 - testl $3,CS(%rsp)
24258 + testb $3,CS(%rsp)
24259 jnz paranoid_userspace
24260 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24261 + pax_exit_kernel
24262 + TRACE_IRQS_IRETQ 0
24263 + SWAPGS_UNSAFE_STACK
24264 + RESTORE_ALL 8
24265 + pax_force_retaddr_bts
24266 + jmp irq_return
24267 +#endif
24268 paranoid_swapgs:
24269 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24270 + pax_exit_kernel_user
24271 +#else
24272 + pax_exit_kernel
24273 +#endif
24274 TRACE_IRQS_IRETQ 0
24275 SWAPGS_UNSAFE_STACK
24276 RESTORE_ALL 8
24277 jmp irq_return
24278 paranoid_restore:
24279 + pax_exit_kernel
24280 TRACE_IRQS_IRETQ_DEBUG 0
24281 RESTORE_ALL 8
24282 + pax_force_retaddr_bts
24283 jmp irq_return
24284 paranoid_userspace:
24285 GET_THREAD_INFO(%rcx)
24286 @@ -1376,7 +1869,7 @@ paranoid_schedule:
24287 TRACE_IRQS_OFF
24288 jmp paranoid_userspace
24289 CFI_ENDPROC
24290 -END(paranoid_exit)
24291 +ENDPROC(paranoid_exit)
24292
24293 /*
24294 * Exception entry point. This expects an error code/orig_rax on the stack.
24295 @@ -1403,12 +1896,23 @@ ENTRY(error_entry)
24296 movq_cfi r14, R14+8
24297 movq_cfi r15, R15+8
24298 xorl %ebx,%ebx
24299 - testl $3,CS+8(%rsp)
24300 + testb $3,CS+8(%rsp)
24301 je error_kernelspace
24302 error_swapgs:
24303 SWAPGS
24304 error_sti:
24305 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24306 + testb $3, CS+8(%rsp)
24307 + jnz 1f
24308 + pax_enter_kernel
24309 + jmp 2f
24310 +1: pax_enter_kernel_user
24311 +2:
24312 +#else
24313 + pax_enter_kernel
24314 +#endif
24315 TRACE_IRQS_OFF
24316 + pax_force_retaddr
24317 ret
24318
24319 /*
24320 @@ -1435,7 +1939,7 @@ bstep_iret:
24321 movq %rcx,RIP+8(%rsp)
24322 jmp error_swapgs
24323 CFI_ENDPROC
24324 -END(error_entry)
24325 +ENDPROC(error_entry)
24326
24327
24328 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
24329 @@ -1446,7 +1950,7 @@ ENTRY(error_exit)
24330 DISABLE_INTERRUPTS(CLBR_NONE)
24331 TRACE_IRQS_OFF
24332 GET_THREAD_INFO(%rcx)
24333 - testl %eax,%eax
24334 + testl $1,%eax
24335 jne retint_kernel
24336 LOCKDEP_SYS_EXIT_IRQ
24337 movl TI_flags(%rcx),%edx
24338 @@ -1455,7 +1959,7 @@ ENTRY(error_exit)
24339 jnz retint_careful
24340 jmp retint_swapgs
24341 CFI_ENDPROC
24342 -END(error_exit)
24343 +ENDPROC(error_exit)
24344
24345 /*
24346 * Test if a given stack is an NMI stack or not.
24347 @@ -1513,9 +2017,11 @@ ENTRY(nmi)
24348 * If %cs was not the kernel segment, then the NMI triggered in user
24349 * space, which means it is definitely not nested.
24350 */
24351 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
24352 + je 1f
24353 cmpl $__KERNEL_CS, 16(%rsp)
24354 jne first_nmi
24355 -
24356 +1:
24357 /*
24358 * Check the special variable on the stack to see if NMIs are
24359 * executing.
24360 @@ -1549,8 +2055,7 @@ nested_nmi:
24361
24362 1:
24363 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
24364 - leaq -1*8(%rsp), %rdx
24365 - movq %rdx, %rsp
24366 + subq $8, %rsp
24367 CFI_ADJUST_CFA_OFFSET 1*8
24368 leaq -10*8(%rsp), %rdx
24369 pushq_cfi $__KERNEL_DS
24370 @@ -1568,6 +2073,7 @@ nested_nmi_out:
24371 CFI_RESTORE rdx
24372
24373 /* No need to check faults here */
24374 +# pax_force_retaddr_bts
24375 INTERRUPT_RETURN
24376
24377 CFI_RESTORE_STATE
24378 @@ -1664,13 +2170,13 @@ end_repeat_nmi:
24379 subq $ORIG_RAX-R15, %rsp
24380 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
24381 /*
24382 - * Use save_paranoid to handle SWAPGS, but no need to use paranoid_exit
24383 + * Use save_paranoid_nmi to handle SWAPGS, but no need to use paranoid_exit
24384 * as we should not be calling schedule in NMI context.
24385 * Even with normal interrupts enabled. An NMI should not be
24386 * setting NEED_RESCHED or anything that normal interrupts and
24387 * exceptions might do.
24388 */
24389 - call save_paranoid
24390 + call save_paranoid_nmi
24391 DEFAULT_FRAME 0
24392
24393 /*
24394 @@ -1680,9 +2186,9 @@ end_repeat_nmi:
24395 * NMI itself takes a page fault, the page fault that was preempted
24396 * will read the information from the NMI page fault and not the
24397 * origin fault. Save it off and restore it if it changes.
24398 - * Use the r12 callee-saved register.
24399 + * Use the r13 callee-saved register.
24400 */
24401 - movq %cr2, %r12
24402 + movq %cr2, %r13
24403
24404 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
24405 movq %rsp,%rdi
24406 @@ -1691,29 +2197,34 @@ end_repeat_nmi:
24407
24408 /* Did the NMI take a page fault? Restore cr2 if it did */
24409 movq %cr2, %rcx
24410 - cmpq %rcx, %r12
24411 + cmpq %rcx, %r13
24412 je 1f
24413 - movq %r12, %cr2
24414 + movq %r13, %cr2
24415 1:
24416
24417 - testl %ebx,%ebx /* swapgs needed? */
24418 + testl $1,%ebx /* swapgs needed? */
24419 jnz nmi_restore
24420 nmi_swapgs:
24421 SWAPGS_UNSAFE_STACK
24422 nmi_restore:
24423 + pax_exit_kernel_nmi
24424 /* Pop the extra iret frame at once */
24425 RESTORE_ALL 6*8
24426 + testb $3, 8(%rsp)
24427 + jnz 1f
24428 + pax_force_retaddr_bts
24429 +1:
24430
24431 /* Clear the NMI executing stack variable */
24432 movq $0, 5*8(%rsp)
24433 jmp irq_return
24434 CFI_ENDPROC
24435 -END(nmi)
24436 +ENDPROC(nmi)
24437
24438 ENTRY(ignore_sysret)
24439 CFI_STARTPROC
24440 mov $-ENOSYS,%eax
24441 sysret
24442 CFI_ENDPROC
24443 -END(ignore_sysret)
24444 +ENDPROC(ignore_sysret)
24445
24446 diff --git a/arch/x86/kernel/espfix_64.c b/arch/x86/kernel/espfix_64.c
24447 index 94d857f..bf1f0bf 100644
24448 --- a/arch/x86/kernel/espfix_64.c
24449 +++ b/arch/x86/kernel/espfix_64.c
24450 @@ -197,7 +197,7 @@ void init_espfix_ap(void)
24451 set_pte(&pte_p[n*PTE_STRIDE], pte);
24452
24453 /* Job is done for this CPU and any CPU which shares this page */
24454 - ACCESS_ONCE(espfix_pages[page]) = stack_page;
24455 + ACCESS_ONCE_RW(espfix_pages[page]) = stack_page;
24456
24457 unlock_done:
24458 mutex_unlock(&espfix_init_mutex);
24459 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
24460 index cbc4a91..b38ee45 100644
24461 --- a/arch/x86/kernel/ftrace.c
24462 +++ b/arch/x86/kernel/ftrace.c
24463 @@ -88,7 +88,7 @@ static unsigned long text_ip_addr(unsigned long ip)
24464 * kernel identity mapping to modify code.
24465 */
24466 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
24467 - ip = (unsigned long)__va(__pa_symbol(ip));
24468 + ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
24469
24470 return ip;
24471 }
24472 @@ -104,6 +104,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
24473 {
24474 unsigned char replaced[MCOUNT_INSN_SIZE];
24475
24476 + ip = ktla_ktva(ip);
24477 +
24478 /*
24479 * Note: Due to modules and __init, code can
24480 * disappear and change, we need to protect against faulting
24481 @@ -229,7 +231,7 @@ static int update_ftrace_func(unsigned long ip, void *new)
24482 unsigned char old[MCOUNT_INSN_SIZE];
24483 int ret;
24484
24485 - memcpy(old, (void *)ip, MCOUNT_INSN_SIZE);
24486 + memcpy(old, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE);
24487
24488 ftrace_update_func = ip;
24489 /* Make sure the breakpoints see the ftrace_update_func update */
24490 @@ -310,7 +312,7 @@ static int add_break(unsigned long ip, const char *old)
24491 unsigned char replaced[MCOUNT_INSN_SIZE];
24492 unsigned char brk = BREAKPOINT_INSTRUCTION;
24493
24494 - if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
24495 + if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
24496 return -EFAULT;
24497
24498 /* Make sure it is what we expect it to be */
24499 diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
24500 index eda1a86..8f6df48 100644
24501 --- a/arch/x86/kernel/head64.c
24502 +++ b/arch/x86/kernel/head64.c
24503 @@ -67,12 +67,12 @@ again:
24504 pgd = *pgd_p;
24505
24506 /*
24507 - * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
24508 - * critical -- __PAGE_OFFSET would point us back into the dynamic
24509 + * The use of __early_va rather than __va here is critical:
24510 + * __va would point us back into the dynamic
24511 * range and we might end up looping forever...
24512 */
24513 if (pgd)
24514 - pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24515 + pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
24516 else {
24517 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24518 reset_early_page_tables();
24519 @@ -82,13 +82,13 @@ again:
24520 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
24521 for (i = 0; i < PTRS_PER_PUD; i++)
24522 pud_p[i] = 0;
24523 - *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24524 + *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
24525 }
24526 pud_p += pud_index(address);
24527 pud = *pud_p;
24528
24529 if (pud)
24530 - pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24531 + pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
24532 else {
24533 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24534 reset_early_page_tables();
24535 @@ -98,7 +98,7 @@ again:
24536 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
24537 for (i = 0; i < PTRS_PER_PMD; i++)
24538 pmd_p[i] = 0;
24539 - *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24540 + *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
24541 }
24542 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
24543 pmd_p[pmd_index(address)] = pmd;
24544 @@ -175,7 +175,6 @@ asmlinkage __visible void __init x86_64_start_kernel(char * real_mode_data)
24545 if (console_loglevel >= CONSOLE_LOGLEVEL_DEBUG)
24546 early_printk("Kernel alive\n");
24547
24548 - clear_page(init_level4_pgt);
24549 /* set init_level4_pgt kernel high mapping*/
24550 init_level4_pgt[511] = early_level4_pgt[511];
24551
24552 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
24553 index f36bd42..0ab4474 100644
24554 --- a/arch/x86/kernel/head_32.S
24555 +++ b/arch/x86/kernel/head_32.S
24556 @@ -26,6 +26,12 @@
24557 /* Physical address */
24558 #define pa(X) ((X) - __PAGE_OFFSET)
24559
24560 +#ifdef CONFIG_PAX_KERNEXEC
24561 +#define ta(X) (X)
24562 +#else
24563 +#define ta(X) ((X) - __PAGE_OFFSET)
24564 +#endif
24565 +
24566 /*
24567 * References to members of the new_cpu_data structure.
24568 */
24569 @@ -55,11 +61,7 @@
24570 * and small than max_low_pfn, otherwise will waste some page table entries
24571 */
24572
24573 -#if PTRS_PER_PMD > 1
24574 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
24575 -#else
24576 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
24577 -#endif
24578 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
24579
24580 /* Number of possible pages in the lowmem region */
24581 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
24582 @@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
24583 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24584
24585 /*
24586 + * Real beginning of normal "text" segment
24587 + */
24588 +ENTRY(stext)
24589 +ENTRY(_stext)
24590 +
24591 +/*
24592 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
24593 * %esi points to the real-mode code as a 32-bit pointer.
24594 * CS and DS must be 4 GB flat segments, but we don't depend on
24595 @@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24596 * can.
24597 */
24598 __HEAD
24599 +
24600 +#ifdef CONFIG_PAX_KERNEXEC
24601 + jmp startup_32
24602 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
24603 +.fill PAGE_SIZE-5,1,0xcc
24604 +#endif
24605 +
24606 ENTRY(startup_32)
24607 movl pa(stack_start),%ecx
24608
24609 @@ -106,6 +121,59 @@ ENTRY(startup_32)
24610 2:
24611 leal -__PAGE_OFFSET(%ecx),%esp
24612
24613 +#ifdef CONFIG_SMP
24614 + movl $pa(cpu_gdt_table),%edi
24615 + movl $__per_cpu_load,%eax
24616 + movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
24617 + rorl $16,%eax
24618 + movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
24619 + movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
24620 + movl $__per_cpu_end - 1,%eax
24621 + subl $__per_cpu_start,%eax
24622 + movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
24623 +#endif
24624 +
24625 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24626 + movl $NR_CPUS,%ecx
24627 + movl $pa(cpu_gdt_table),%edi
24628 +1:
24629 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
24630 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
24631 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
24632 + addl $PAGE_SIZE_asm,%edi
24633 + loop 1b
24634 +#endif
24635 +
24636 +#ifdef CONFIG_PAX_KERNEXEC
24637 + movl $pa(boot_gdt),%edi
24638 + movl $__LOAD_PHYSICAL_ADDR,%eax
24639 + movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
24640 + rorl $16,%eax
24641 + movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
24642 + movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
24643 + rorl $16,%eax
24644 +
24645 + ljmp $(__BOOT_CS),$1f
24646 +1:
24647 +
24648 + movl $NR_CPUS,%ecx
24649 + movl $pa(cpu_gdt_table),%edi
24650 + addl $__PAGE_OFFSET,%eax
24651 +1:
24652 + movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
24653 + movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
24654 + movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
24655 + movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
24656 + rorl $16,%eax
24657 + movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
24658 + movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
24659 + movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
24660 + movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
24661 + rorl $16,%eax
24662 + addl $PAGE_SIZE_asm,%edi
24663 + loop 1b
24664 +#endif
24665 +
24666 /*
24667 * Clear BSS first so that there are no surprises...
24668 */
24669 @@ -201,8 +269,11 @@ ENTRY(startup_32)
24670 movl %eax, pa(max_pfn_mapped)
24671
24672 /* Do early initialization of the fixmap area */
24673 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24674 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
24675 +#ifdef CONFIG_COMPAT_VDSO
24676 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
24677 +#else
24678 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
24679 +#endif
24680 #else /* Not PAE */
24681
24682 page_pde_offset = (__PAGE_OFFSET >> 20);
24683 @@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24684 movl %eax, pa(max_pfn_mapped)
24685
24686 /* Do early initialization of the fixmap area */
24687 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24688 - movl %eax,pa(initial_page_table+0xffc)
24689 +#ifdef CONFIG_COMPAT_VDSO
24690 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
24691 +#else
24692 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
24693 +#endif
24694 #endif
24695
24696 #ifdef CONFIG_PARAVIRT
24697 @@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24698 cmpl $num_subarch_entries, %eax
24699 jae bad_subarch
24700
24701 - movl pa(subarch_entries)(,%eax,4), %eax
24702 - subl $__PAGE_OFFSET, %eax
24703 - jmp *%eax
24704 + jmp *pa(subarch_entries)(,%eax,4)
24705
24706 bad_subarch:
24707 WEAK(lguest_entry)
24708 @@ -261,10 +333,10 @@ WEAK(xen_entry)
24709 __INITDATA
24710
24711 subarch_entries:
24712 - .long default_entry /* normal x86/PC */
24713 - .long lguest_entry /* lguest hypervisor */
24714 - .long xen_entry /* Xen hypervisor */
24715 - .long default_entry /* Moorestown MID */
24716 + .long ta(default_entry) /* normal x86/PC */
24717 + .long ta(lguest_entry) /* lguest hypervisor */
24718 + .long ta(xen_entry) /* Xen hypervisor */
24719 + .long ta(default_entry) /* Moorestown MID */
24720 num_subarch_entries = (. - subarch_entries) / 4
24721 .previous
24722 #else
24723 @@ -354,6 +426,7 @@ default_entry:
24724 movl pa(mmu_cr4_features),%eax
24725 movl %eax,%cr4
24726
24727 +#ifdef CONFIG_X86_PAE
24728 testb $X86_CR4_PAE, %al # check if PAE is enabled
24729 jz enable_paging
24730
24731 @@ -382,6 +455,9 @@ default_entry:
24732 /* Make changes effective */
24733 wrmsr
24734
24735 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
24736 +#endif
24737 +
24738 enable_paging:
24739
24740 /*
24741 @@ -449,14 +525,20 @@ is486:
24742 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
24743 movl %eax,%ss # after changing gdt.
24744
24745 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
24746 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
24747 movl %eax,%ds
24748 movl %eax,%es
24749
24750 movl $(__KERNEL_PERCPU), %eax
24751 movl %eax,%fs # set this cpu's percpu
24752
24753 +#ifdef CONFIG_CC_STACKPROTECTOR
24754 movl $(__KERNEL_STACK_CANARY),%eax
24755 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
24756 + movl $(__USER_DS),%eax
24757 +#else
24758 + xorl %eax,%eax
24759 +#endif
24760 movl %eax,%gs
24761
24762 xorl %eax,%eax # Clear LDT
24763 @@ -512,8 +594,11 @@ setup_once:
24764 * relocation. Manually set base address in stack canary
24765 * segment descriptor.
24766 */
24767 - movl $gdt_page,%eax
24768 + movl $cpu_gdt_table,%eax
24769 movl $stack_canary,%ecx
24770 +#ifdef CONFIG_SMP
24771 + addl $__per_cpu_load,%ecx
24772 +#endif
24773 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
24774 shrl $16, %ecx
24775 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
24776 @@ -548,7 +633,7 @@ ENTRY(early_idt_handler)
24777 cmpl $2,(%esp) # X86_TRAP_NMI
24778 je is_nmi # Ignore NMI
24779
24780 - cmpl $2,%ss:early_recursion_flag
24781 + cmpl $1,%ss:early_recursion_flag
24782 je hlt_loop
24783 incl %ss:early_recursion_flag
24784
24785 @@ -586,8 +671,8 @@ ENTRY(early_idt_handler)
24786 pushl (20+6*4)(%esp) /* trapno */
24787 pushl $fault_msg
24788 call printk
24789 -#endif
24790 call dump_stack
24791 +#endif
24792 hlt_loop:
24793 hlt
24794 jmp hlt_loop
24795 @@ -607,8 +692,11 @@ ENDPROC(early_idt_handler)
24796 /* This is the default interrupt "handler" :-) */
24797 ALIGN
24798 ignore_int:
24799 - cld
24800 #ifdef CONFIG_PRINTK
24801 + cmpl $2,%ss:early_recursion_flag
24802 + je hlt_loop
24803 + incl %ss:early_recursion_flag
24804 + cld
24805 pushl %eax
24806 pushl %ecx
24807 pushl %edx
24808 @@ -617,9 +705,6 @@ ignore_int:
24809 movl $(__KERNEL_DS),%eax
24810 movl %eax,%ds
24811 movl %eax,%es
24812 - cmpl $2,early_recursion_flag
24813 - je hlt_loop
24814 - incl early_recursion_flag
24815 pushl 16(%esp)
24816 pushl 24(%esp)
24817 pushl 32(%esp)
24818 @@ -653,29 +738,34 @@ ENTRY(setup_once_ref)
24819 /*
24820 * BSS section
24821 */
24822 -__PAGE_ALIGNED_BSS
24823 - .align PAGE_SIZE
24824 #ifdef CONFIG_X86_PAE
24825 +.section .initial_pg_pmd,"a",@progbits
24826 initial_pg_pmd:
24827 .fill 1024*KPMDS,4,0
24828 #else
24829 +.section .initial_page_table,"a",@progbits
24830 ENTRY(initial_page_table)
24831 .fill 1024,4,0
24832 #endif
24833 +.section .initial_pg_fixmap,"a",@progbits
24834 initial_pg_fixmap:
24835 .fill 1024,4,0
24836 +.section .empty_zero_page,"a",@progbits
24837 ENTRY(empty_zero_page)
24838 .fill 4096,1,0
24839 +.section .swapper_pg_dir,"a",@progbits
24840 ENTRY(swapper_pg_dir)
24841 +#ifdef CONFIG_X86_PAE
24842 + .fill 4,8,0
24843 +#else
24844 .fill 1024,4,0
24845 +#endif
24846
24847 /*
24848 * This starts the data section.
24849 */
24850 #ifdef CONFIG_X86_PAE
24851 -__PAGE_ALIGNED_DATA
24852 - /* Page-aligned for the benefit of paravirt? */
24853 - .align PAGE_SIZE
24854 +.section .initial_page_table,"a",@progbits
24855 ENTRY(initial_page_table)
24856 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
24857 # if KPMDS == 3
24858 @@ -694,12 +784,20 @@ ENTRY(initial_page_table)
24859 # error "Kernel PMDs should be 1, 2 or 3"
24860 # endif
24861 .align PAGE_SIZE /* needs to be page-sized too */
24862 +
24863 +#ifdef CONFIG_PAX_PER_CPU_PGD
24864 +ENTRY(cpu_pgd)
24865 + .rept 2*NR_CPUS
24866 + .fill 4,8,0
24867 + .endr
24868 +#endif
24869 +
24870 #endif
24871
24872 .data
24873 .balign 4
24874 ENTRY(stack_start)
24875 - .long init_thread_union+THREAD_SIZE
24876 + .long init_thread_union+THREAD_SIZE-8
24877
24878 __INITRODATA
24879 int_msg:
24880 @@ -727,7 +825,7 @@ fault_msg:
24881 * segment size, and 32-bit linear address value:
24882 */
24883
24884 - .data
24885 +.section .rodata,"a",@progbits
24886 .globl boot_gdt_descr
24887 .globl idt_descr
24888
24889 @@ -736,7 +834,7 @@ fault_msg:
24890 .word 0 # 32 bit align gdt_desc.address
24891 boot_gdt_descr:
24892 .word __BOOT_DS+7
24893 - .long boot_gdt - __PAGE_OFFSET
24894 + .long pa(boot_gdt)
24895
24896 .word 0 # 32-bit align idt_desc.address
24897 idt_descr:
24898 @@ -747,7 +845,7 @@ idt_descr:
24899 .word 0 # 32 bit align gdt_desc.address
24900 ENTRY(early_gdt_descr)
24901 .word GDT_ENTRIES*8-1
24902 - .long gdt_page /* Overwritten for secondary CPUs */
24903 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
24904
24905 /*
24906 * The boot_gdt must mirror the equivalent in setup.S and is
24907 @@ -756,5 +854,65 @@ ENTRY(early_gdt_descr)
24908 .align L1_CACHE_BYTES
24909 ENTRY(boot_gdt)
24910 .fill GDT_ENTRY_BOOT_CS,8,0
24911 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
24912 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
24913 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
24914 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
24915 +
24916 + .align PAGE_SIZE_asm
24917 +ENTRY(cpu_gdt_table)
24918 + .rept NR_CPUS
24919 + .quad 0x0000000000000000 /* NULL descriptor */
24920 + .quad 0x0000000000000000 /* 0x0b reserved */
24921 + .quad 0x0000000000000000 /* 0x13 reserved */
24922 + .quad 0x0000000000000000 /* 0x1b reserved */
24923 +
24924 +#ifdef CONFIG_PAX_KERNEXEC
24925 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
24926 +#else
24927 + .quad 0x0000000000000000 /* 0x20 unused */
24928 +#endif
24929 +
24930 + .quad 0x0000000000000000 /* 0x28 unused */
24931 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
24932 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
24933 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
24934 + .quad 0x0000000000000000 /* 0x4b reserved */
24935 + .quad 0x0000000000000000 /* 0x53 reserved */
24936 + .quad 0x0000000000000000 /* 0x5b reserved */
24937 +
24938 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
24939 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
24940 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
24941 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
24942 +
24943 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
24944 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
24945 +
24946 + /*
24947 + * Segments used for calling PnP BIOS have byte granularity.
24948 + * The code segments and data segments have fixed 64k limits,
24949 + * the transfer segment sizes are set at run time.
24950 + */
24951 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
24952 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
24953 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
24954 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
24955 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
24956 +
24957 + /*
24958 + * The APM segments have byte granularity and their bases
24959 + * are set at run time. All have 64k limits.
24960 + */
24961 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
24962 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
24963 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
24964 +
24965 + .quad 0x00c093000000ffff /* 0xd0 - ESPFIX SS */
24966 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
24967 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
24968 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
24969 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
24970 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
24971 +
24972 + /* Be sure this is zeroed to avoid false validations in Xen */
24973 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
24974 + .endr
24975 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
24976 index a468c0a..c7dec74 100644
24977 --- a/arch/x86/kernel/head_64.S
24978 +++ b/arch/x86/kernel/head_64.S
24979 @@ -20,6 +20,8 @@
24980 #include <asm/processor-flags.h>
24981 #include <asm/percpu.h>
24982 #include <asm/nops.h>
24983 +#include <asm/cpufeature.h>
24984 +#include <asm/alternative-asm.h>
24985
24986 #ifdef CONFIG_PARAVIRT
24987 #include <asm/asm-offsets.h>
24988 @@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
24989 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
24990 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
24991 L3_START_KERNEL = pud_index(__START_KERNEL_map)
24992 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
24993 +L3_VMALLOC_START = pud_index(VMALLOC_START)
24994 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
24995 +L3_VMALLOC_END = pud_index(VMALLOC_END)
24996 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
24997 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
24998
24999 .text
25000 __HEAD
25001 @@ -89,11 +97,24 @@ startup_64:
25002 * Fixup the physical addresses in the page table
25003 */
25004 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
25005 + addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
25006 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
25007 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
25008 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
25009 + addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
25010
25011 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
25012 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
25013 + addq %rbp, level3_ident_pgt + (0*8)(%rip)
25014 +#ifndef CONFIG_XEN
25015 + addq %rbp, level3_ident_pgt + (1*8)(%rip)
25016 +#endif
25017 +
25018 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
25019 +
25020 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
25021 + addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
25022
25023 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
25024 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
25025
25026 /*
25027 * Set up the identity mapping for the switchover. These
25028 @@ -177,8 +198,8 @@ ENTRY(secondary_startup_64)
25029 movq $(init_level4_pgt - __START_KERNEL_map), %rax
25030 1:
25031
25032 - /* Enable PAE mode and PGE */
25033 - movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
25034 + /* Enable PAE mode and PSE/PGE */
25035 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
25036 movq %rcx, %cr4
25037
25038 /* Setup early boot stage 4 level pagetables. */
25039 @@ -199,10 +220,19 @@ ENTRY(secondary_startup_64)
25040 movl $MSR_EFER, %ecx
25041 rdmsr
25042 btsl $_EFER_SCE, %eax /* Enable System Call */
25043 - btl $20,%edi /* No Execute supported? */
25044 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
25045 jnc 1f
25046 btsl $_EFER_NX, %eax
25047 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
25048 +#ifndef CONFIG_EFI
25049 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_PAGE_OFFSET(%rip)
25050 +#endif
25051 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_START(%rip)
25052 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_END(%rip)
25053 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMEMMAP_START(%rip)
25054 + btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*506(%rip)
25055 + btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*507(%rip)
25056 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
25057 1: wrmsr /* Make changes effective */
25058
25059 /* Setup cr0 */
25060 @@ -282,6 +312,7 @@ ENTRY(secondary_startup_64)
25061 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
25062 * address given in m16:64.
25063 */
25064 + pax_set_fptr_mask
25065 movq initial_code(%rip),%rax
25066 pushq $0 # fake return address to stop unwinder
25067 pushq $__KERNEL_CS # set correct cs
25068 @@ -313,7 +344,7 @@ ENDPROC(start_cpu0)
25069 .quad INIT_PER_CPU_VAR(irq_stack_union)
25070
25071 GLOBAL(stack_start)
25072 - .quad init_thread_union+THREAD_SIZE-8
25073 + .quad init_thread_union+THREAD_SIZE-16
25074 .word 0
25075 __FINITDATA
25076
25077 @@ -391,7 +422,7 @@ ENTRY(early_idt_handler)
25078 call dump_stack
25079 #ifdef CONFIG_KALLSYMS
25080 leaq early_idt_ripmsg(%rip),%rdi
25081 - movq 40(%rsp),%rsi # %rip again
25082 + movq 88(%rsp),%rsi # %rip again
25083 call __print_symbol
25084 #endif
25085 #endif /* EARLY_PRINTK */
25086 @@ -420,6 +451,7 @@ ENDPROC(early_idt_handler)
25087 early_recursion_flag:
25088 .long 0
25089
25090 + .section .rodata,"a",@progbits
25091 #ifdef CONFIG_EARLY_PRINTK
25092 early_idt_msg:
25093 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
25094 @@ -447,29 +479,52 @@ NEXT_PAGE(early_level4_pgt)
25095 NEXT_PAGE(early_dynamic_pgts)
25096 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
25097
25098 - .data
25099 + .section .rodata,"a",@progbits
25100
25101 -#ifndef CONFIG_XEN
25102 NEXT_PAGE(init_level4_pgt)
25103 - .fill 512,8,0
25104 -#else
25105 -NEXT_PAGE(init_level4_pgt)
25106 - .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
25107 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
25108 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
25109 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
25110 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
25111 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
25112 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
25113 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
25114 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
25115 .org init_level4_pgt + L4_START_KERNEL*8, 0
25116 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
25117 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
25118
25119 +#ifdef CONFIG_PAX_PER_CPU_PGD
25120 +NEXT_PAGE(cpu_pgd)
25121 + .rept 2*NR_CPUS
25122 + .fill 512,8,0
25123 + .endr
25124 +#endif
25125 +
25126 NEXT_PAGE(level3_ident_pgt)
25127 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
25128 +#ifdef CONFIG_XEN
25129 .fill 511, 8, 0
25130 +#else
25131 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
25132 + .fill 510,8,0
25133 +#endif
25134 +
25135 +NEXT_PAGE(level3_vmalloc_start_pgt)
25136 + .fill 512,8,0
25137 +
25138 +NEXT_PAGE(level3_vmalloc_end_pgt)
25139 + .fill 512,8,0
25140 +
25141 +NEXT_PAGE(level3_vmemmap_pgt)
25142 + .fill L3_VMEMMAP_START,8,0
25143 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
25144 +
25145 NEXT_PAGE(level2_ident_pgt)
25146 - /* Since I easily can, map the first 1G.
25147 + /* Since I easily can, map the first 2G.
25148 * Don't set NX because code runs from these pages.
25149 */
25150 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
25151 -#endif
25152 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
25153
25154 NEXT_PAGE(level3_kernel_pgt)
25155 .fill L3_START_KERNEL,8,0
25156 @@ -477,6 +532,9 @@ NEXT_PAGE(level3_kernel_pgt)
25157 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
25158 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
25159
25160 +NEXT_PAGE(level2_vmemmap_pgt)
25161 + .fill 512,8,0
25162 +
25163 NEXT_PAGE(level2_kernel_pgt)
25164 /*
25165 * 512 MB kernel mapping. We spend a full page on this pagetable
25166 @@ -494,28 +552,64 @@ NEXT_PAGE(level2_kernel_pgt)
25167 NEXT_PAGE(level2_fixmap_pgt)
25168 .fill 506,8,0
25169 .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
25170 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
25171 - .fill 5,8,0
25172 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
25173 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
25174 + .fill 4,8,0
25175
25176 NEXT_PAGE(level1_fixmap_pgt)
25177 .fill 512,8,0
25178
25179 +NEXT_PAGE(level1_vsyscall_pgt)
25180 + .fill 512,8,0
25181 +
25182 #undef PMDS
25183
25184 - .data
25185 + .align PAGE_SIZE
25186 +ENTRY(cpu_gdt_table)
25187 + .rept NR_CPUS
25188 + .quad 0x0000000000000000 /* NULL descriptor */
25189 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
25190 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
25191 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
25192 + .quad 0x00cffb000000ffff /* __USER32_CS */
25193 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
25194 + .quad 0x00affb000000ffff /* __USER_CS */
25195 +
25196 +#ifdef CONFIG_PAX_KERNEXEC
25197 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
25198 +#else
25199 + .quad 0x0 /* unused */
25200 +#endif
25201 +
25202 + .quad 0,0 /* TSS */
25203 + .quad 0,0 /* LDT */
25204 + .quad 0,0,0 /* three TLS descriptors */
25205 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
25206 + /* asm/segment.h:GDT_ENTRIES must match this */
25207 +
25208 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25209 + .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
25210 +#else
25211 + .quad 0x0 /* unused */
25212 +#endif
25213 +
25214 + /* zero the remaining page */
25215 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
25216 + .endr
25217 +
25218 .align 16
25219 .globl early_gdt_descr
25220 early_gdt_descr:
25221 .word GDT_ENTRIES*8-1
25222 early_gdt_descr_base:
25223 - .quad INIT_PER_CPU_VAR(gdt_page)
25224 + .quad cpu_gdt_table
25225
25226 ENTRY(phys_base)
25227 /* This must match the first entry in level2_kernel_pgt */
25228 .quad 0x0000000000000000
25229
25230 #include "../../x86/xen/xen-head.S"
25231 -
25232 - __PAGE_ALIGNED_BSS
25233 +
25234 + .section .rodata,"a",@progbits
25235 NEXT_PAGE(empty_zero_page)
25236 .skip PAGE_SIZE
25237 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
25238 index 05fd74f..c3548b1 100644
25239 --- a/arch/x86/kernel/i386_ksyms_32.c
25240 +++ b/arch/x86/kernel/i386_ksyms_32.c
25241 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
25242 EXPORT_SYMBOL(cmpxchg8b_emu);
25243 #endif
25244
25245 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
25246 +
25247 /* Networking helper routines. */
25248 EXPORT_SYMBOL(csum_partial_copy_generic);
25249 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
25250 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
25251
25252 EXPORT_SYMBOL(__get_user_1);
25253 EXPORT_SYMBOL(__get_user_2);
25254 @@ -44,3 +48,11 @@ EXPORT_SYMBOL(___preempt_schedule);
25255 EXPORT_SYMBOL(___preempt_schedule_context);
25256 #endif
25257 #endif
25258 +
25259 +#ifdef CONFIG_PAX_KERNEXEC
25260 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
25261 +#endif
25262 +
25263 +#ifdef CONFIG_PAX_PER_CPU_PGD
25264 +EXPORT_SYMBOL(cpu_pgd);
25265 +#endif
25266 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
25267 index d5dd808..b6432cf 100644
25268 --- a/arch/x86/kernel/i387.c
25269 +++ b/arch/x86/kernel/i387.c
25270 @@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
25271 static inline bool interrupted_user_mode(void)
25272 {
25273 struct pt_regs *regs = get_irq_regs();
25274 - return regs && user_mode_vm(regs);
25275 + return regs && user_mode(regs);
25276 }
25277
25278 /*
25279 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
25280 index 8af8171..f8c1169 100644
25281 --- a/arch/x86/kernel/i8259.c
25282 +++ b/arch/x86/kernel/i8259.c
25283 @@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
25284 static void make_8259A_irq(unsigned int irq)
25285 {
25286 disable_irq_nosync(irq);
25287 - io_apic_irqs &= ~(1<<irq);
25288 + io_apic_irqs &= ~(1UL<<irq);
25289 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
25290 i8259A_chip.name);
25291 enable_irq(irq);
25292 @@ -209,7 +209,7 @@ spurious_8259A_irq:
25293 "spurious 8259A interrupt: IRQ%d.\n", irq);
25294 spurious_irq_mask |= irqmask;
25295 }
25296 - atomic_inc(&irq_err_count);
25297 + atomic_inc_unchecked(&irq_err_count);
25298 /*
25299 * Theoretically we do not have to handle this IRQ,
25300 * but in Linux this does not cause problems and is
25301 @@ -350,14 +350,16 @@ static void init_8259A(int auto_eoi)
25302 /* (slave's support for AEOI in flat mode is to be investigated) */
25303 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
25304
25305 + pax_open_kernel();
25306 if (auto_eoi)
25307 /*
25308 * In AEOI mode we just have to mask the interrupt
25309 * when acking.
25310 */
25311 - i8259A_chip.irq_mask_ack = disable_8259A_irq;
25312 + *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
25313 else
25314 - i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
25315 + *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
25316 + pax_close_kernel();
25317
25318 udelay(100); /* wait for 8259A to initialize */
25319
25320 diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
25321 index a979b5b..1d6db75 100644
25322 --- a/arch/x86/kernel/io_delay.c
25323 +++ b/arch/x86/kernel/io_delay.c
25324 @@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
25325 * Quirk table for systems that misbehave (lock up, etc.) if port
25326 * 0x80 is used:
25327 */
25328 -static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
25329 +static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
25330 {
25331 .callback = dmi_io_delay_0xed_port,
25332 .ident = "Compaq Presario V6000",
25333 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
25334 index 4ddaf66..49d5c18 100644
25335 --- a/arch/x86/kernel/ioport.c
25336 +++ b/arch/x86/kernel/ioport.c
25337 @@ -6,6 +6,7 @@
25338 #include <linux/sched.h>
25339 #include <linux/kernel.h>
25340 #include <linux/capability.h>
25341 +#include <linux/security.h>
25342 #include <linux/errno.h>
25343 #include <linux/types.h>
25344 #include <linux/ioport.h>
25345 @@ -30,6 +31,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
25346 return -EINVAL;
25347 if (turn_on && !capable(CAP_SYS_RAWIO))
25348 return -EPERM;
25349 +#ifdef CONFIG_GRKERNSEC_IO
25350 + if (turn_on && grsec_disable_privio) {
25351 + gr_handle_ioperm();
25352 + return -ENODEV;
25353 + }
25354 +#endif
25355
25356 /*
25357 * If it's the first ioperm() call in this thread's lifetime, set the
25358 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
25359 * because the ->io_bitmap_max value must match the bitmap
25360 * contents:
25361 */
25362 - tss = &per_cpu(init_tss, get_cpu());
25363 + tss = init_tss + get_cpu();
25364
25365 if (turn_on)
25366 bitmap_clear(t->io_bitmap_ptr, from, num);
25367 @@ -105,6 +112,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
25368 if (level > old) {
25369 if (!capable(CAP_SYS_RAWIO))
25370 return -EPERM;
25371 +#ifdef CONFIG_GRKERNSEC_IO
25372 + if (grsec_disable_privio) {
25373 + gr_handle_iopl();
25374 + return -ENODEV;
25375 + }
25376 +#endif
25377 }
25378 regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
25379 t->iopl = level << 12;
25380 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
25381 index 922d285..6d20692 100644
25382 --- a/arch/x86/kernel/irq.c
25383 +++ b/arch/x86/kernel/irq.c
25384 @@ -22,7 +22,7 @@
25385 #define CREATE_TRACE_POINTS
25386 #include <asm/trace/irq_vectors.h>
25387
25388 -atomic_t irq_err_count;
25389 +atomic_unchecked_t irq_err_count;
25390
25391 /* Function pointer for generic interrupt vector handling */
25392 void (*x86_platform_ipi_callback)(void) = NULL;
25393 @@ -132,9 +132,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
25394 seq_printf(p, "%10u ", irq_stats(j)->irq_hv_callback_count);
25395 seq_printf(p, " Hypervisor callback interrupts\n");
25396 #endif
25397 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
25398 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
25399 #if defined(CONFIG_X86_IO_APIC)
25400 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
25401 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
25402 #endif
25403 return 0;
25404 }
25405 @@ -174,7 +174,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
25406
25407 u64 arch_irq_stat(void)
25408 {
25409 - u64 sum = atomic_read(&irq_err_count);
25410 + u64 sum = atomic_read_unchecked(&irq_err_count);
25411 return sum;
25412 }
25413
25414 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
25415 index 63ce838..2ea3e06 100644
25416 --- a/arch/x86/kernel/irq_32.c
25417 +++ b/arch/x86/kernel/irq_32.c
25418 @@ -29,6 +29,8 @@ EXPORT_PER_CPU_SYMBOL(irq_regs);
25419
25420 #ifdef CONFIG_DEBUG_STACKOVERFLOW
25421
25422 +extern void gr_handle_kernel_exploit(void);
25423 +
25424 int sysctl_panic_on_stackoverflow __read_mostly;
25425
25426 /* Debugging check for stack overflow: is there less than 1KB free? */
25427 @@ -39,13 +41,14 @@ static int check_stack_overflow(void)
25428 __asm__ __volatile__("andl %%esp,%0" :
25429 "=r" (sp) : "0" (THREAD_SIZE - 1));
25430
25431 - return sp < (sizeof(struct thread_info) + STACK_WARN);
25432 + return sp < STACK_WARN;
25433 }
25434
25435 static void print_stack_overflow(void)
25436 {
25437 printk(KERN_WARNING "low stack detected by irq handler\n");
25438 dump_stack();
25439 + gr_handle_kernel_exploit();
25440 if (sysctl_panic_on_stackoverflow)
25441 panic("low stack detected by irq handler - check messages\n");
25442 }
25443 @@ -84,10 +87,9 @@ static inline void *current_stack(void)
25444 static inline int
25445 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25446 {
25447 - struct irq_stack *curstk, *irqstk;
25448 + struct irq_stack *irqstk;
25449 u32 *isp, *prev_esp, arg1, arg2;
25450
25451 - curstk = (struct irq_stack *) current_stack();
25452 irqstk = __this_cpu_read(hardirq_stack);
25453
25454 /*
25455 @@ -96,15 +98,19 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25456 * handler) we can't do that and just have to keep using the
25457 * current stack (which is the irq stack already after all)
25458 */
25459 - if (unlikely(curstk == irqstk))
25460 + if (unlikely((void *)current_stack_pointer - (void *)irqstk < THREAD_SIZE))
25461 return 0;
25462
25463 - isp = (u32 *) ((char *)irqstk + sizeof(*irqstk));
25464 + isp = (u32 *) ((char *)irqstk + sizeof(*irqstk) - 8);
25465
25466 /* Save the next esp at the bottom of the stack */
25467 prev_esp = (u32 *)irqstk;
25468 *prev_esp = current_stack_pointer;
25469
25470 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25471 + __set_fs(MAKE_MM_SEG(0));
25472 +#endif
25473 +
25474 if (unlikely(overflow))
25475 call_on_stack(print_stack_overflow, isp);
25476
25477 @@ -115,6 +121,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25478 : "0" (irq), "1" (desc), "2" (isp),
25479 "D" (desc->handle_irq)
25480 : "memory", "cc", "ecx");
25481 +
25482 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25483 + __set_fs(current_thread_info()->addr_limit);
25484 +#endif
25485 +
25486 return 1;
25487 }
25488
25489 @@ -123,32 +134,18 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25490 */
25491 void irq_ctx_init(int cpu)
25492 {
25493 - struct irq_stack *irqstk;
25494 -
25495 if (per_cpu(hardirq_stack, cpu))
25496 return;
25497
25498 - irqstk = page_address(alloc_pages_node(cpu_to_node(cpu),
25499 - THREADINFO_GFP,
25500 - THREAD_SIZE_ORDER));
25501 - per_cpu(hardirq_stack, cpu) = irqstk;
25502 -
25503 - irqstk = page_address(alloc_pages_node(cpu_to_node(cpu),
25504 - THREADINFO_GFP,
25505 - THREAD_SIZE_ORDER));
25506 - per_cpu(softirq_stack, cpu) = irqstk;
25507 -
25508 - printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
25509 - cpu, per_cpu(hardirq_stack, cpu), per_cpu(softirq_stack, cpu));
25510 + per_cpu(hardirq_stack, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
25511 + per_cpu(softirq_stack, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
25512 }
25513
25514 void do_softirq_own_stack(void)
25515 {
25516 - struct thread_info *curstk;
25517 struct irq_stack *irqstk;
25518 u32 *isp, *prev_esp;
25519
25520 - curstk = current_stack();
25521 irqstk = __this_cpu_read(softirq_stack);
25522
25523 /* build the stack frame on the softirq stack */
25524 @@ -158,7 +155,16 @@ void do_softirq_own_stack(void)
25525 prev_esp = (u32 *)irqstk;
25526 *prev_esp = current_stack_pointer;
25527
25528 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25529 + __set_fs(MAKE_MM_SEG(0));
25530 +#endif
25531 +
25532 call_on_stack(__do_softirq, isp);
25533 +
25534 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25535 + __set_fs(current_thread_info()->addr_limit);
25536 +#endif
25537 +
25538 }
25539
25540 bool handle_irq(unsigned irq, struct pt_regs *regs)
25541 @@ -172,7 +178,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
25542 if (unlikely(!desc))
25543 return false;
25544
25545 - if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25546 + if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25547 if (unlikely(overflow))
25548 print_stack_overflow();
25549 desc->handle_irq(irq, desc);
25550 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
25551 index 4d1c746..55a22d6 100644
25552 --- a/arch/x86/kernel/irq_64.c
25553 +++ b/arch/x86/kernel/irq_64.c
25554 @@ -26,6 +26,8 @@ EXPORT_PER_CPU_SYMBOL(irq_stat);
25555 DEFINE_PER_CPU(struct pt_regs *, irq_regs);
25556 EXPORT_PER_CPU_SYMBOL(irq_regs);
25557
25558 +extern void gr_handle_kernel_exploit(void);
25559 +
25560 int sysctl_panic_on_stackoverflow;
25561
25562 /*
25563 @@ -44,7 +46,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25564 u64 estack_top, estack_bottom;
25565 u64 curbase = (u64)task_stack_page(current);
25566
25567 - if (user_mode_vm(regs))
25568 + if (user_mode(regs))
25569 return;
25570
25571 if (regs->sp >= curbase + sizeof(struct thread_info) +
25572 @@ -69,6 +71,8 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25573 irq_stack_top, irq_stack_bottom,
25574 estack_top, estack_bottom);
25575
25576 + gr_handle_kernel_exploit();
25577 +
25578 if (sysctl_panic_on_stackoverflow)
25579 panic("low stack detected by irq handler - check messages\n");
25580 #endif
25581 diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
25582 index 26d5a55..a01160a 100644
25583 --- a/arch/x86/kernel/jump_label.c
25584 +++ b/arch/x86/kernel/jump_label.c
25585 @@ -51,7 +51,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25586 * Jump label is enabled for the first time.
25587 * So we expect a default_nop...
25588 */
25589 - if (unlikely(memcmp((void *)entry->code, default_nop, 5)
25590 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5)
25591 != 0))
25592 bug_at((void *)entry->code, __LINE__);
25593 } else {
25594 @@ -59,7 +59,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25595 * ...otherwise expect an ideal_nop. Otherwise
25596 * something went horribly wrong.
25597 */
25598 - if (unlikely(memcmp((void *)entry->code, ideal_nop, 5)
25599 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), ideal_nop, 5)
25600 != 0))
25601 bug_at((void *)entry->code, __LINE__);
25602 }
25603 @@ -75,13 +75,13 @@ static void __jump_label_transform(struct jump_entry *entry,
25604 * are converting the default nop to the ideal nop.
25605 */
25606 if (init) {
25607 - if (unlikely(memcmp((void *)entry->code, default_nop, 5) != 0))
25608 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5) != 0))
25609 bug_at((void *)entry->code, __LINE__);
25610 } else {
25611 code.jump = 0xe9;
25612 code.offset = entry->target -
25613 (entry->code + JUMP_LABEL_NOP_SIZE);
25614 - if (unlikely(memcmp((void *)entry->code, &code, 5) != 0))
25615 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), &code, 5) != 0))
25616 bug_at((void *)entry->code, __LINE__);
25617 }
25618 memcpy(&code, ideal_nops[NOP_ATOMIC5], JUMP_LABEL_NOP_SIZE);
25619 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
25620 index 7ec1d5f..5a7d130 100644
25621 --- a/arch/x86/kernel/kgdb.c
25622 +++ b/arch/x86/kernel/kgdb.c
25623 @@ -126,11 +126,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
25624 #ifdef CONFIG_X86_32
25625 switch (regno) {
25626 case GDB_SS:
25627 - if (!user_mode_vm(regs))
25628 + if (!user_mode(regs))
25629 *(unsigned long *)mem = __KERNEL_DS;
25630 break;
25631 case GDB_SP:
25632 - if (!user_mode_vm(regs))
25633 + if (!user_mode(regs))
25634 *(unsigned long *)mem = kernel_stack_pointer(regs);
25635 break;
25636 case GDB_GS:
25637 @@ -228,7 +228,10 @@ static void kgdb_correct_hw_break(void)
25638 bp->attr.bp_addr = breakinfo[breakno].addr;
25639 bp->attr.bp_len = breakinfo[breakno].len;
25640 bp->attr.bp_type = breakinfo[breakno].type;
25641 - info->address = breakinfo[breakno].addr;
25642 + if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
25643 + info->address = ktla_ktva(breakinfo[breakno].addr);
25644 + else
25645 + info->address = breakinfo[breakno].addr;
25646 info->len = breakinfo[breakno].len;
25647 info->type = breakinfo[breakno].type;
25648 val = arch_install_hw_breakpoint(bp);
25649 @@ -475,12 +478,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
25650 case 'k':
25651 /* clear the trace bit */
25652 linux_regs->flags &= ~X86_EFLAGS_TF;
25653 - atomic_set(&kgdb_cpu_doing_single_step, -1);
25654 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
25655
25656 /* set the trace bit if we're stepping */
25657 if (remcomInBuffer[0] == 's') {
25658 linux_regs->flags |= X86_EFLAGS_TF;
25659 - atomic_set(&kgdb_cpu_doing_single_step,
25660 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
25661 raw_smp_processor_id());
25662 }
25663
25664 @@ -545,7 +548,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
25665
25666 switch (cmd) {
25667 case DIE_DEBUG:
25668 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
25669 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
25670 if (user_mode(regs))
25671 return single_step_cont(regs, args);
25672 break;
25673 @@ -750,11 +753,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25674 #endif /* CONFIG_DEBUG_RODATA */
25675
25676 bpt->type = BP_BREAKPOINT;
25677 - err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
25678 + err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
25679 BREAK_INSTR_SIZE);
25680 if (err)
25681 return err;
25682 - err = probe_kernel_write((char *)bpt->bpt_addr,
25683 + err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25684 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
25685 #ifdef CONFIG_DEBUG_RODATA
25686 if (!err)
25687 @@ -767,7 +770,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25688 return -EBUSY;
25689 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
25690 BREAK_INSTR_SIZE);
25691 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25692 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25693 if (err)
25694 return err;
25695 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
25696 @@ -792,13 +795,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
25697 if (mutex_is_locked(&text_mutex))
25698 goto knl_write;
25699 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
25700 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25701 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25702 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
25703 goto knl_write;
25704 return err;
25705 knl_write:
25706 #endif /* CONFIG_DEBUG_RODATA */
25707 - return probe_kernel_write((char *)bpt->bpt_addr,
25708 + return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25709 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
25710 }
25711
25712 diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
25713 index 67e6d19..731ed28 100644
25714 --- a/arch/x86/kernel/kprobes/core.c
25715 +++ b/arch/x86/kernel/kprobes/core.c
25716 @@ -120,9 +120,12 @@ __synthesize_relative_insn(void *from, void *to, u8 op)
25717 s32 raddr;
25718 } __packed *insn;
25719
25720 - insn = (struct __arch_relative_insn *)from;
25721 + insn = (struct __arch_relative_insn *)ktla_ktva(from);
25722 +
25723 + pax_open_kernel();
25724 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
25725 insn->op = op;
25726 + pax_close_kernel();
25727 }
25728
25729 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
25730 @@ -168,7 +171,7 @@ int can_boost(kprobe_opcode_t *opcodes)
25731 kprobe_opcode_t opcode;
25732 kprobe_opcode_t *orig_opcodes = opcodes;
25733
25734 - if (search_exception_tables((unsigned long)opcodes))
25735 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
25736 return 0; /* Page fault may occur on this address. */
25737
25738 retry:
25739 @@ -242,9 +245,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
25740 * for the first byte, we can recover the original instruction
25741 * from it and kp->opcode.
25742 */
25743 - memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25744 + memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25745 buf[0] = kp->opcode;
25746 - return (unsigned long)buf;
25747 + return ktva_ktla((unsigned long)buf);
25748 }
25749
25750 /*
25751 @@ -336,7 +339,9 @@ int __copy_instruction(u8 *dest, u8 *src)
25752 /* Another subsystem puts a breakpoint, failed to recover */
25753 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
25754 return 0;
25755 + pax_open_kernel();
25756 memcpy(dest, insn.kaddr, insn.length);
25757 + pax_close_kernel();
25758
25759 #ifdef CONFIG_X86_64
25760 if (insn_rip_relative(&insn)) {
25761 @@ -363,7 +368,9 @@ int __copy_instruction(u8 *dest, u8 *src)
25762 return 0;
25763 }
25764 disp = (u8 *) dest + insn_offset_displacement(&insn);
25765 + pax_open_kernel();
25766 *(s32 *) disp = (s32) newdisp;
25767 + pax_close_kernel();
25768 }
25769 #endif
25770 return insn.length;
25771 @@ -505,7 +512,7 @@ static void setup_singlestep(struct kprobe *p, struct pt_regs *regs,
25772 * nor set current_kprobe, because it doesn't use single
25773 * stepping.
25774 */
25775 - regs->ip = (unsigned long)p->ainsn.insn;
25776 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25777 preempt_enable_no_resched();
25778 return;
25779 }
25780 @@ -522,9 +529,9 @@ static void setup_singlestep(struct kprobe *p, struct pt_regs *regs,
25781 regs->flags &= ~X86_EFLAGS_IF;
25782 /* single step inline if the instruction is an int3 */
25783 if (p->opcode == BREAKPOINT_INSTRUCTION)
25784 - regs->ip = (unsigned long)p->addr;
25785 + regs->ip = ktla_ktva((unsigned long)p->addr);
25786 else
25787 - regs->ip = (unsigned long)p->ainsn.insn;
25788 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25789 }
25790 NOKPROBE_SYMBOL(setup_singlestep);
25791
25792 @@ -574,7 +581,7 @@ int kprobe_int3_handler(struct pt_regs *regs)
25793 struct kprobe *p;
25794 struct kprobe_ctlblk *kcb;
25795
25796 - if (user_mode_vm(regs))
25797 + if (user_mode(regs))
25798 return 0;
25799
25800 addr = (kprobe_opcode_t *)(regs->ip - sizeof(kprobe_opcode_t));
25801 @@ -609,7 +616,7 @@ int kprobe_int3_handler(struct pt_regs *regs)
25802 setup_singlestep(p, regs, kcb, 0);
25803 return 1;
25804 }
25805 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
25806 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
25807 /*
25808 * The breakpoint instruction was removed right
25809 * after we hit it. Another cpu has removed
25810 @@ -656,6 +663,9 @@ static void __used kretprobe_trampoline_holder(void)
25811 " movq %rax, 152(%rsp)\n"
25812 RESTORE_REGS_STRING
25813 " popfq\n"
25814 +#ifdef KERNEXEC_PLUGIN
25815 + " btsq $63,(%rsp)\n"
25816 +#endif
25817 #else
25818 " pushf\n"
25819 SAVE_REGS_STRING
25820 @@ -796,7 +806,7 @@ static void resume_execution(struct kprobe *p, struct pt_regs *regs,
25821 struct kprobe_ctlblk *kcb)
25822 {
25823 unsigned long *tos = stack_addr(regs);
25824 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
25825 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
25826 unsigned long orig_ip = (unsigned long)p->addr;
25827 kprobe_opcode_t *insn = p->ainsn.insn;
25828
25829 @@ -979,7 +989,7 @@ int kprobe_exceptions_notify(struct notifier_block *self, unsigned long val,
25830 struct die_args *args = data;
25831 int ret = NOTIFY_DONE;
25832
25833 - if (args->regs && user_mode_vm(args->regs))
25834 + if (args->regs && user_mode(args->regs))
25835 return ret;
25836
25837 if (val == DIE_GPF) {
25838 diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
25839 index f304773..551e63c 100644
25840 --- a/arch/x86/kernel/kprobes/opt.c
25841 +++ b/arch/x86/kernel/kprobes/opt.c
25842 @@ -79,6 +79,7 @@ found:
25843 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
25844 static void synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
25845 {
25846 + pax_open_kernel();
25847 #ifdef CONFIG_X86_64
25848 *addr++ = 0x48;
25849 *addr++ = 0xbf;
25850 @@ -86,6 +87,7 @@ static void synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
25851 *addr++ = 0xb8;
25852 #endif
25853 *(unsigned long *)addr = val;
25854 + pax_close_kernel();
25855 }
25856
25857 asm (
25858 @@ -337,7 +339,7 @@ int arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25859 * Verify if the address gap is in 2GB range, because this uses
25860 * a relative jump.
25861 */
25862 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
25863 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
25864 if (abs(rel) > 0x7fffffff)
25865 return -ERANGE;
25866
25867 @@ -352,16 +354,18 @@ int arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25868 op->optinsn.size = ret;
25869
25870 /* Copy arch-dep-instance from template */
25871 - memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
25872 + pax_open_kernel();
25873 + memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
25874 + pax_close_kernel();
25875
25876 /* Set probe information */
25877 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
25878
25879 /* Set probe function call */
25880 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
25881 + synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
25882
25883 /* Set returning jmp instruction at the tail of out-of-line buffer */
25884 - synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
25885 + synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
25886 (u8 *)op->kp.addr + op->optinsn.size);
25887
25888 flush_icache_range((unsigned long) buf,
25889 @@ -386,7 +390,7 @@ void arch_optimize_kprobes(struct list_head *oplist)
25890 WARN_ON(kprobe_disabled(&op->kp));
25891
25892 /* Backup instructions which will be replaced by jump address */
25893 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
25894 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
25895 RELATIVE_ADDR_SIZE);
25896
25897 insn_buf[0] = RELATIVEJUMP_OPCODE;
25898 @@ -434,7 +438,7 @@ int setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
25899 /* This kprobe is really able to run optimized path. */
25900 op = container_of(p, struct optimized_kprobe, kp);
25901 /* Detour through copied instructions */
25902 - regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
25903 + regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
25904 if (!reenter)
25905 reset_current_kprobe();
25906 preempt_enable_no_resched();
25907 diff --git a/arch/x86/kernel/ksysfs.c b/arch/x86/kernel/ksysfs.c
25908 index c2bedae..25e7ab60 100644
25909 --- a/arch/x86/kernel/ksysfs.c
25910 +++ b/arch/x86/kernel/ksysfs.c
25911 @@ -184,7 +184,7 @@ out:
25912
25913 static struct kobj_attribute type_attr = __ATTR_RO(type);
25914
25915 -static struct bin_attribute data_attr = {
25916 +static bin_attribute_no_const data_attr __read_only = {
25917 .attr = {
25918 .name = "data",
25919 .mode = S_IRUGO,
25920 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
25921 index c37886d..d851d32 100644
25922 --- a/arch/x86/kernel/ldt.c
25923 +++ b/arch/x86/kernel/ldt.c
25924 @@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
25925 if (reload) {
25926 #ifdef CONFIG_SMP
25927 preempt_disable();
25928 - load_LDT(pc);
25929 + load_LDT_nolock(pc);
25930 if (!cpumask_equal(mm_cpumask(current->mm),
25931 cpumask_of(smp_processor_id())))
25932 smp_call_function(flush_ldt, current->mm, 1);
25933 preempt_enable();
25934 #else
25935 - load_LDT(pc);
25936 + load_LDT_nolock(pc);
25937 #endif
25938 }
25939 if (oldsize) {
25940 @@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
25941 return err;
25942
25943 for (i = 0; i < old->size; i++)
25944 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
25945 + write_ldt_entry(new->ldt, i, old->ldt + i);
25946 return 0;
25947 }
25948
25949 @@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
25950 retval = copy_ldt(&mm->context, &old_mm->context);
25951 mutex_unlock(&old_mm->context.lock);
25952 }
25953 +
25954 + if (tsk == current) {
25955 + mm->context.vdso = 0;
25956 +
25957 +#ifdef CONFIG_X86_32
25958 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25959 + mm->context.user_cs_base = 0UL;
25960 + mm->context.user_cs_limit = ~0UL;
25961 +
25962 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
25963 + cpus_clear(mm->context.cpu_user_cs_mask);
25964 +#endif
25965 +
25966 +#endif
25967 +#endif
25968 +
25969 + }
25970 +
25971 return retval;
25972 }
25973
25974 @@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
25975 }
25976 }
25977
25978 +#ifdef CONFIG_PAX_SEGMEXEC
25979 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
25980 + error = -EINVAL;
25981 + goto out_unlock;
25982 + }
25983 +#endif
25984 +
25985 if (!IS_ENABLED(CONFIG_X86_16BIT) && !ldt_info.seg_32bit) {
25986 error = -EINVAL;
25987 goto out_unlock;
25988 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
25989 index 1667b1d..16492c5 100644
25990 --- a/arch/x86/kernel/machine_kexec_32.c
25991 +++ b/arch/x86/kernel/machine_kexec_32.c
25992 @@ -25,7 +25,7 @@
25993 #include <asm/cacheflush.h>
25994 #include <asm/debugreg.h>
25995
25996 -static void set_idt(void *newidt, __u16 limit)
25997 +static void set_idt(struct desc_struct *newidt, __u16 limit)
25998 {
25999 struct desc_ptr curidt;
26000
26001 @@ -37,7 +37,7 @@ static void set_idt(void *newidt, __u16 limit)
26002 }
26003
26004
26005 -static void set_gdt(void *newgdt, __u16 limit)
26006 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
26007 {
26008 struct desc_ptr curgdt;
26009
26010 @@ -215,7 +215,7 @@ void machine_kexec(struct kimage *image)
26011 }
26012
26013 control_page = page_address(image->control_code_page);
26014 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
26015 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
26016
26017 relocate_kernel_ptr = control_page;
26018 page_list[PA_CONTROL_PAGE] = __pa(control_page);
26019 diff --git a/arch/x86/kernel/mcount_64.S b/arch/x86/kernel/mcount_64.S
26020 index c050a01..5774072 100644
26021 --- a/arch/x86/kernel/mcount_64.S
26022 +++ b/arch/x86/kernel/mcount_64.S
26023 @@ -7,7 +7,7 @@
26024 #include <linux/linkage.h>
26025 #include <asm/ptrace.h>
26026 #include <asm/ftrace.h>
26027 -
26028 +#include <asm/alternative-asm.h>
26029
26030 .code64
26031 .section .entry.text, "ax"
26032 @@ -24,8 +24,9 @@
26033 #ifdef CONFIG_DYNAMIC_FTRACE
26034
26035 ENTRY(function_hook)
26036 + pax_force_retaddr
26037 retq
26038 -END(function_hook)
26039 +ENDPROC(function_hook)
26040
26041 /* skip is set if stack has been adjusted */
26042 .macro ftrace_caller_setup skip=0
26043 @@ -66,8 +67,9 @@ GLOBAL(ftrace_graph_call)
26044 #endif
26045
26046 GLOBAL(ftrace_stub)
26047 + pax_force_retaddr
26048 retq
26049 -END(ftrace_caller)
26050 +ENDPROC(ftrace_caller)
26051
26052 ENTRY(ftrace_regs_caller)
26053 /* Save the current flags before compare (in SS location)*/
26054 @@ -135,7 +137,7 @@ ftrace_restore_flags:
26055 popfq
26056 jmp ftrace_stub
26057
26058 -END(ftrace_regs_caller)
26059 +ENDPROC(ftrace_regs_caller)
26060
26061
26062 #else /* ! CONFIG_DYNAMIC_FTRACE */
26063 @@ -156,6 +158,7 @@ ENTRY(function_hook)
26064 #endif
26065
26066 GLOBAL(ftrace_stub)
26067 + pax_force_retaddr
26068 retq
26069
26070 trace:
26071 @@ -169,12 +172,13 @@ trace:
26072 #endif
26073 subq $MCOUNT_INSN_SIZE, %rdi
26074
26075 + pax_force_fptr ftrace_trace_function
26076 call *ftrace_trace_function
26077
26078 MCOUNT_RESTORE_FRAME
26079
26080 jmp ftrace_stub
26081 -END(function_hook)
26082 +ENDPROC(function_hook)
26083 #endif /* CONFIG_DYNAMIC_FTRACE */
26084 #endif /* CONFIG_FUNCTION_TRACER */
26085
26086 @@ -196,8 +200,9 @@ ENTRY(ftrace_graph_caller)
26087
26088 MCOUNT_RESTORE_FRAME
26089
26090 + pax_force_retaddr
26091 retq
26092 -END(ftrace_graph_caller)
26093 +ENDPROC(ftrace_graph_caller)
26094
26095 GLOBAL(return_to_handler)
26096 subq $24, %rsp
26097 @@ -213,5 +218,7 @@ GLOBAL(return_to_handler)
26098 movq 8(%rsp), %rdx
26099 movq (%rsp), %rax
26100 addq $24, %rsp
26101 + pax_force_fptr %rdi
26102 jmp *%rdi
26103 +ENDPROC(return_to_handler)
26104 #endif
26105 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
26106 index e69f988..da078ea 100644
26107 --- a/arch/x86/kernel/module.c
26108 +++ b/arch/x86/kernel/module.c
26109 @@ -81,17 +81,62 @@ static unsigned long int get_module_load_offset(void)
26110 }
26111 #endif
26112
26113 -void *module_alloc(unsigned long size)
26114 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
26115 {
26116 - if (PAGE_ALIGN(size) > MODULES_LEN)
26117 + if (!size || PAGE_ALIGN(size) > MODULES_LEN)
26118 return NULL;
26119 return __vmalloc_node_range(size, 1,
26120 MODULES_VADDR + get_module_load_offset(),
26121 - MODULES_END, GFP_KERNEL | __GFP_HIGHMEM,
26122 - PAGE_KERNEL_EXEC, NUMA_NO_NODE,
26123 + MODULES_END, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO,
26124 + prot, NUMA_NO_NODE,
26125 __builtin_return_address(0));
26126 }
26127
26128 +void *module_alloc(unsigned long size)
26129 +{
26130 +
26131 +#ifdef CONFIG_PAX_KERNEXEC
26132 + return __module_alloc(size, PAGE_KERNEL);
26133 +#else
26134 + return __module_alloc(size, PAGE_KERNEL_EXEC);
26135 +#endif
26136 +
26137 +}
26138 +
26139 +#ifdef CONFIG_PAX_KERNEXEC
26140 +#ifdef CONFIG_X86_32
26141 +void *module_alloc_exec(unsigned long size)
26142 +{
26143 + struct vm_struct *area;
26144 +
26145 + if (size == 0)
26146 + return NULL;
26147 +
26148 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
26149 +return area ? area->addr : NULL;
26150 +}
26151 +EXPORT_SYMBOL(module_alloc_exec);
26152 +
26153 +void module_free_exec(struct module *mod, void *module_region)
26154 +{
26155 + vunmap(module_region);
26156 +}
26157 +EXPORT_SYMBOL(module_free_exec);
26158 +#else
26159 +void module_free_exec(struct module *mod, void *module_region)
26160 +{
26161 + module_free(mod, module_region);
26162 +}
26163 +EXPORT_SYMBOL(module_free_exec);
26164 +
26165 +void *module_alloc_exec(unsigned long size)
26166 +{
26167 + return __module_alloc(size, PAGE_KERNEL_RX);
26168 +}
26169 +EXPORT_SYMBOL(module_alloc_exec);
26170 +#endif
26171 +#endif
26172 +
26173 #ifdef CONFIG_X86_32
26174 int apply_relocate(Elf32_Shdr *sechdrs,
26175 const char *strtab,
26176 @@ -102,14 +147,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
26177 unsigned int i;
26178 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
26179 Elf32_Sym *sym;
26180 - uint32_t *location;
26181 + uint32_t *plocation, location;
26182
26183 DEBUGP("Applying relocate section %u to %u\n",
26184 relsec, sechdrs[relsec].sh_info);
26185 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
26186 /* This is where to make the change */
26187 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
26188 - + rel[i].r_offset;
26189 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
26190 + location = (uint32_t)plocation;
26191 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
26192 + plocation = ktla_ktva((void *)plocation);
26193 /* This is the symbol it is referring to. Note that all
26194 undefined symbols have been resolved. */
26195 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
26196 @@ -118,11 +165,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
26197 switch (ELF32_R_TYPE(rel[i].r_info)) {
26198 case R_386_32:
26199 /* We add the value into the location given */
26200 - *location += sym->st_value;
26201 + pax_open_kernel();
26202 + *plocation += sym->st_value;
26203 + pax_close_kernel();
26204 break;
26205 case R_386_PC32:
26206 /* Add the value, subtract its position */
26207 - *location += sym->st_value - (uint32_t)location;
26208 + pax_open_kernel();
26209 + *plocation += sym->st_value - location;
26210 + pax_close_kernel();
26211 break;
26212 default:
26213 pr_err("%s: Unknown relocation: %u\n",
26214 @@ -167,21 +218,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
26215 case R_X86_64_NONE:
26216 break;
26217 case R_X86_64_64:
26218 + pax_open_kernel();
26219 *(u64 *)loc = val;
26220 + pax_close_kernel();
26221 break;
26222 case R_X86_64_32:
26223 + pax_open_kernel();
26224 *(u32 *)loc = val;
26225 + pax_close_kernel();
26226 if (val != *(u32 *)loc)
26227 goto overflow;
26228 break;
26229 case R_X86_64_32S:
26230 + pax_open_kernel();
26231 *(s32 *)loc = val;
26232 + pax_close_kernel();
26233 if ((s64)val != *(s32 *)loc)
26234 goto overflow;
26235 break;
26236 case R_X86_64_PC32:
26237 val -= (u64)loc;
26238 + pax_open_kernel();
26239 *(u32 *)loc = val;
26240 + pax_close_kernel();
26241 +
26242 #if 0
26243 if ((s64)val != *(s32 *)loc)
26244 goto overflow;
26245 diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
26246 index c9603ac..9f88728 100644
26247 --- a/arch/x86/kernel/msr.c
26248 +++ b/arch/x86/kernel/msr.c
26249 @@ -37,6 +37,7 @@
26250 #include <linux/notifier.h>
26251 #include <linux/uaccess.h>
26252 #include <linux/gfp.h>
26253 +#include <linux/grsecurity.h>
26254
26255 #include <asm/processor.h>
26256 #include <asm/msr.h>
26257 @@ -103,6 +104,11 @@ static ssize_t msr_write(struct file *file, const char __user *buf,
26258 int err = 0;
26259 ssize_t bytes = 0;
26260
26261 +#ifdef CONFIG_GRKERNSEC_KMEM
26262 + gr_handle_msr_write();
26263 + return -EPERM;
26264 +#endif
26265 +
26266 if (count % 8)
26267 return -EINVAL; /* Invalid chunk size */
26268
26269 @@ -150,6 +156,10 @@ static long msr_ioctl(struct file *file, unsigned int ioc, unsigned long arg)
26270 err = -EBADF;
26271 break;
26272 }
26273 +#ifdef CONFIG_GRKERNSEC_KMEM
26274 + gr_handle_msr_write();
26275 + return -EPERM;
26276 +#endif
26277 if (copy_from_user(&regs, uregs, sizeof regs)) {
26278 err = -EFAULT;
26279 break;
26280 @@ -233,7 +243,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
26281 return notifier_from_errno(err);
26282 }
26283
26284 -static struct notifier_block __refdata msr_class_cpu_notifier = {
26285 +static struct notifier_block msr_class_cpu_notifier = {
26286 .notifier_call = msr_class_cpu_callback,
26287 };
26288
26289 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
26290 index c3e985d..110a36a 100644
26291 --- a/arch/x86/kernel/nmi.c
26292 +++ b/arch/x86/kernel/nmi.c
26293 @@ -98,16 +98,16 @@ fs_initcall(nmi_warning_debugfs);
26294
26295 static void nmi_max_handler(struct irq_work *w)
26296 {
26297 - struct nmiaction *a = container_of(w, struct nmiaction, irq_work);
26298 + struct nmiwork *n = container_of(w, struct nmiwork, irq_work);
26299 int remainder_ns, decimal_msecs;
26300 - u64 whole_msecs = ACCESS_ONCE(a->max_duration);
26301 + u64 whole_msecs = ACCESS_ONCE(n->max_duration);
26302
26303 remainder_ns = do_div(whole_msecs, (1000 * 1000));
26304 decimal_msecs = remainder_ns / 1000;
26305
26306 printk_ratelimited(KERN_INFO
26307 "INFO: NMI handler (%ps) took too long to run: %lld.%03d msecs\n",
26308 - a->handler, whole_msecs, decimal_msecs);
26309 + n->action->handler, whole_msecs, decimal_msecs);
26310 }
26311
26312 static int nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
26313 @@ -134,11 +134,11 @@ static int nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
26314 delta = sched_clock() - delta;
26315 trace_nmi_handler(a->handler, (int)delta, thishandled);
26316
26317 - if (delta < nmi_longest_ns || delta < a->max_duration)
26318 + if (delta < nmi_longest_ns || delta < a->work->max_duration)
26319 continue;
26320
26321 - a->max_duration = delta;
26322 - irq_work_queue(&a->irq_work);
26323 + a->work->max_duration = delta;
26324 + irq_work_queue(&a->work->irq_work);
26325 }
26326
26327 rcu_read_unlock();
26328 @@ -148,7 +148,7 @@ static int nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
26329 }
26330 NOKPROBE_SYMBOL(nmi_handle);
26331
26332 -int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26333 +int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
26334 {
26335 struct nmi_desc *desc = nmi_to_desc(type);
26336 unsigned long flags;
26337 @@ -156,7 +156,8 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26338 if (!action->handler)
26339 return -EINVAL;
26340
26341 - init_irq_work(&action->irq_work, nmi_max_handler);
26342 + action->work->action = action;
26343 + init_irq_work(&action->work->irq_work, nmi_max_handler);
26344
26345 spin_lock_irqsave(&desc->lock, flags);
26346
26347 @@ -174,9 +175,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26348 * event confuses some handlers (kdump uses this flag)
26349 */
26350 if (action->flags & NMI_FLAG_FIRST)
26351 - list_add_rcu(&action->list, &desc->head);
26352 + pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
26353 else
26354 - list_add_tail_rcu(&action->list, &desc->head);
26355 + pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
26356
26357 spin_unlock_irqrestore(&desc->lock, flags);
26358 return 0;
26359 @@ -199,7 +200,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
26360 if (!strcmp(n->name, name)) {
26361 WARN(in_nmi(),
26362 "Trying to free NMI (%s) from NMI context!\n", n->name);
26363 - list_del_rcu(&n->list);
26364 + pax_list_del_rcu((struct list_head *)&n->list);
26365 break;
26366 }
26367 }
26368 @@ -528,6 +529,17 @@ static inline void nmi_nesting_postprocess(void)
26369 dotraplinkage notrace void
26370 do_nmi(struct pt_regs *regs, long error_code)
26371 {
26372 +
26373 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26374 + if (!user_mode(regs)) {
26375 + unsigned long cs = regs->cs & 0xFFFF;
26376 + unsigned long ip = ktva_ktla(regs->ip);
26377 +
26378 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
26379 + regs->ip = ip;
26380 + }
26381 +#endif
26382 +
26383 nmi_nesting_preprocess(regs);
26384
26385 nmi_enter();
26386 diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
26387 index 6d9582e..f746287 100644
26388 --- a/arch/x86/kernel/nmi_selftest.c
26389 +++ b/arch/x86/kernel/nmi_selftest.c
26390 @@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
26391 {
26392 /* trap all the unknown NMIs we may generate */
26393 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
26394 - __initdata);
26395 + __initconst);
26396 }
26397
26398 static void __init cleanup_nmi_testsuite(void)
26399 @@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
26400 unsigned long timeout;
26401
26402 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
26403 - NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
26404 + NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
26405 nmi_fail = FAILURE;
26406 return;
26407 }
26408 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
26409 index bbb6c73..24a58ef 100644
26410 --- a/arch/x86/kernel/paravirt-spinlocks.c
26411 +++ b/arch/x86/kernel/paravirt-spinlocks.c
26412 @@ -8,7 +8,7 @@
26413
26414 #include <asm/paravirt.h>
26415
26416 -struct pv_lock_ops pv_lock_ops = {
26417 +struct pv_lock_ops pv_lock_ops __read_only = {
26418 #ifdef CONFIG_SMP
26419 .lock_spinning = __PV_IS_CALLEE_SAVE(paravirt_nop),
26420 .unlock_kick = paravirt_nop,
26421 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
26422 index 548d25f..f8fb99c 100644
26423 --- a/arch/x86/kernel/paravirt.c
26424 +++ b/arch/x86/kernel/paravirt.c
26425 @@ -56,6 +56,9 @@ u64 _paravirt_ident_64(u64 x)
26426 {
26427 return x;
26428 }
26429 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
26430 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
26431 +#endif
26432
26433 void __init default_banner(void)
26434 {
26435 @@ -142,16 +145,20 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
26436
26437 if (opfunc == NULL)
26438 /* If there's no function, patch it with a ud2a (BUG) */
26439 - ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
26440 - else if (opfunc == _paravirt_nop)
26441 + ret = paravirt_patch_insns(insnbuf, len, ktva_ktla(ud2a), ud2a+sizeof(ud2a));
26442 + else if (opfunc == (void *)_paravirt_nop)
26443 /* If the operation is a nop, then nop the callsite */
26444 ret = paravirt_patch_nop();
26445
26446 /* identity functions just return their single argument */
26447 - else if (opfunc == _paravirt_ident_32)
26448 + else if (opfunc == (void *)_paravirt_ident_32)
26449 ret = paravirt_patch_ident_32(insnbuf, len);
26450 - else if (opfunc == _paravirt_ident_64)
26451 + else if (opfunc == (void *)_paravirt_ident_64)
26452 ret = paravirt_patch_ident_64(insnbuf, len);
26453 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
26454 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
26455 + ret = paravirt_patch_ident_64(insnbuf, len);
26456 +#endif
26457
26458 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
26459 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
26460 @@ -176,7 +183,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
26461 if (insn_len > len || start == NULL)
26462 insn_len = len;
26463 else
26464 - memcpy(insnbuf, start, insn_len);
26465 + memcpy(insnbuf, ktla_ktva(start), insn_len);
26466
26467 return insn_len;
26468 }
26469 @@ -300,7 +307,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
26470 return this_cpu_read(paravirt_lazy_mode);
26471 }
26472
26473 -struct pv_info pv_info = {
26474 +struct pv_info pv_info __read_only = {
26475 .name = "bare hardware",
26476 .paravirt_enabled = 0,
26477 .kernel_rpl = 0,
26478 @@ -311,16 +318,16 @@ struct pv_info pv_info = {
26479 #endif
26480 };
26481
26482 -struct pv_init_ops pv_init_ops = {
26483 +struct pv_init_ops pv_init_ops __read_only = {
26484 .patch = native_patch,
26485 };
26486
26487 -struct pv_time_ops pv_time_ops = {
26488 +struct pv_time_ops pv_time_ops __read_only = {
26489 .sched_clock = native_sched_clock,
26490 .steal_clock = native_steal_clock,
26491 };
26492
26493 -__visible struct pv_irq_ops pv_irq_ops = {
26494 +__visible struct pv_irq_ops pv_irq_ops __read_only = {
26495 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
26496 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
26497 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
26498 @@ -332,7 +339,7 @@ __visible struct pv_irq_ops pv_irq_ops = {
26499 #endif
26500 };
26501
26502 -__visible struct pv_cpu_ops pv_cpu_ops = {
26503 +__visible struct pv_cpu_ops pv_cpu_ops __read_only = {
26504 .cpuid = native_cpuid,
26505 .get_debugreg = native_get_debugreg,
26506 .set_debugreg = native_set_debugreg,
26507 @@ -395,21 +402,26 @@ NOKPROBE_SYMBOL(native_get_debugreg);
26508 NOKPROBE_SYMBOL(native_set_debugreg);
26509 NOKPROBE_SYMBOL(native_load_idt);
26510
26511 -struct pv_apic_ops pv_apic_ops = {
26512 +struct pv_apic_ops pv_apic_ops __read_only= {
26513 #ifdef CONFIG_X86_LOCAL_APIC
26514 .startup_ipi_hook = paravirt_nop,
26515 #endif
26516 };
26517
26518 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
26519 +#ifdef CONFIG_X86_32
26520 +#ifdef CONFIG_X86_PAE
26521 +/* 64-bit pagetable entries */
26522 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
26523 +#else
26524 /* 32-bit pagetable entries */
26525 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
26526 +#endif
26527 #else
26528 /* 64-bit pagetable entries */
26529 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
26530 #endif
26531
26532 -struct pv_mmu_ops pv_mmu_ops = {
26533 +struct pv_mmu_ops pv_mmu_ops __read_only = {
26534
26535 .read_cr2 = native_read_cr2,
26536 .write_cr2 = native_write_cr2,
26537 @@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
26538 .make_pud = PTE_IDENT,
26539
26540 .set_pgd = native_set_pgd,
26541 + .set_pgd_batched = native_set_pgd_batched,
26542 #endif
26543 #endif /* PAGETABLE_LEVELS >= 3 */
26544
26545 @@ -479,6 +492,12 @@ struct pv_mmu_ops pv_mmu_ops = {
26546 },
26547
26548 .set_fixmap = native_set_fixmap,
26549 +
26550 +#ifdef CONFIG_PAX_KERNEXEC
26551 + .pax_open_kernel = native_pax_open_kernel,
26552 + .pax_close_kernel = native_pax_close_kernel,
26553 +#endif
26554 +
26555 };
26556
26557 EXPORT_SYMBOL_GPL(pv_time_ops);
26558 diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
26559 index 0497f71..7186c0d 100644
26560 --- a/arch/x86/kernel/pci-calgary_64.c
26561 +++ b/arch/x86/kernel/pci-calgary_64.c
26562 @@ -1347,7 +1347,7 @@ static void __init get_tce_space_from_tar(void)
26563 tce_space = be64_to_cpu(readq(target));
26564 tce_space = tce_space & TAR_SW_BITS;
26565
26566 - tce_space = tce_space & (~specified_table_size);
26567 + tce_space = tce_space & (~(unsigned long)specified_table_size);
26568 info->tce_space = (u64 *)__va(tce_space);
26569 }
26570 }
26571 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
26572 index 35ccf75..7a15747 100644
26573 --- a/arch/x86/kernel/pci-iommu_table.c
26574 +++ b/arch/x86/kernel/pci-iommu_table.c
26575 @@ -2,7 +2,7 @@
26576 #include <asm/iommu_table.h>
26577 #include <linux/string.h>
26578 #include <linux/kallsyms.h>
26579 -
26580 +#include <linux/sched.h>
26581
26582 #define DEBUG 1
26583
26584 diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
26585 index 77dd0ad..9ec4723 100644
26586 --- a/arch/x86/kernel/pci-swiotlb.c
26587 +++ b/arch/x86/kernel/pci-swiotlb.c
26588 @@ -33,7 +33,7 @@ void x86_swiotlb_free_coherent(struct device *dev, size_t size,
26589 struct dma_attrs *attrs)
26590 {
26591 if (is_swiotlb_buffer(dma_to_phys(dev, dma_addr)))
26592 - swiotlb_free_coherent(dev, size, vaddr, dma_addr);
26593 + swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
26594 else
26595 dma_generic_free_coherent(dev, size, vaddr, dma_addr, attrs);
26596 }
26597 diff --git a/arch/x86/kernel/preempt.S b/arch/x86/kernel/preempt.S
26598 index ca7f0d5..8996469 100644
26599 --- a/arch/x86/kernel/preempt.S
26600 +++ b/arch/x86/kernel/preempt.S
26601 @@ -3,12 +3,14 @@
26602 #include <asm/dwarf2.h>
26603 #include <asm/asm.h>
26604 #include <asm/calling.h>
26605 +#include <asm/alternative-asm.h>
26606
26607 ENTRY(___preempt_schedule)
26608 CFI_STARTPROC
26609 SAVE_ALL
26610 call preempt_schedule
26611 RESTORE_ALL
26612 + pax_force_retaddr
26613 ret
26614 CFI_ENDPROC
26615
26616 @@ -19,6 +21,7 @@ ENTRY(___preempt_schedule_context)
26617 SAVE_ALL
26618 call preempt_schedule_context
26619 RESTORE_ALL
26620 + pax_force_retaddr
26621 ret
26622 CFI_ENDPROC
26623
26624 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
26625 index 4505e2a..ae28b0d 100644
26626 --- a/arch/x86/kernel/process.c
26627 +++ b/arch/x86/kernel/process.c
26628 @@ -36,7 +36,8 @@
26629 * section. Since TSS's are completely CPU-local, we want them
26630 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
26631 */
26632 -__visible DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
26633 +struct tss_struct init_tss[NR_CPUS] __visible ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
26634 +EXPORT_SYMBOL(init_tss);
26635
26636 #ifdef CONFIG_X86_64
26637 static DEFINE_PER_CPU(unsigned char, is_idle);
26638 @@ -92,7 +93,7 @@ void arch_task_cache_init(void)
26639 task_xstate_cachep =
26640 kmem_cache_create("task_xstate", xstate_size,
26641 __alignof__(union thread_xstate),
26642 - SLAB_PANIC | SLAB_NOTRACK, NULL);
26643 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
26644 }
26645
26646 /*
26647 @@ -105,7 +106,7 @@ void exit_thread(void)
26648 unsigned long *bp = t->io_bitmap_ptr;
26649
26650 if (bp) {
26651 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
26652 + struct tss_struct *tss = init_tss + get_cpu();
26653
26654 t->io_bitmap_ptr = NULL;
26655 clear_thread_flag(TIF_IO_BITMAP);
26656 @@ -125,6 +126,9 @@ void flush_thread(void)
26657 {
26658 struct task_struct *tsk = current;
26659
26660 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
26661 + loadsegment(gs, 0);
26662 +#endif
26663 flush_ptrace_hw_breakpoint(tsk);
26664 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
26665 drop_init_fpu(tsk);
26666 @@ -271,7 +275,7 @@ static void __exit_idle(void)
26667 void exit_idle(void)
26668 {
26669 /* idle loop has pid 0 */
26670 - if (current->pid)
26671 + if (task_pid_nr(current))
26672 return;
26673 __exit_idle();
26674 }
26675 @@ -324,7 +328,7 @@ bool xen_set_default_idle(void)
26676 return ret;
26677 }
26678 #endif
26679 -void stop_this_cpu(void *dummy)
26680 +__noreturn void stop_this_cpu(void *dummy)
26681 {
26682 local_irq_disable();
26683 /*
26684 @@ -453,16 +457,37 @@ static int __init idle_setup(char *str)
26685 }
26686 early_param("idle", idle_setup);
26687
26688 -unsigned long arch_align_stack(unsigned long sp)
26689 +#ifdef CONFIG_PAX_RANDKSTACK
26690 +void pax_randomize_kstack(struct pt_regs *regs)
26691 {
26692 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
26693 - sp -= get_random_int() % 8192;
26694 - return sp & ~0xf;
26695 -}
26696 + struct thread_struct *thread = &current->thread;
26697 + unsigned long time;
26698
26699 -unsigned long arch_randomize_brk(struct mm_struct *mm)
26700 -{
26701 - unsigned long range_end = mm->brk + 0x02000000;
26702 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
26703 -}
26704 + if (!randomize_va_space)
26705 + return;
26706 +
26707 + if (v8086_mode(regs))
26708 + return;
26709
26710 + rdtscl(time);
26711 +
26712 + /* P4 seems to return a 0 LSB, ignore it */
26713 +#ifdef CONFIG_MPENTIUM4
26714 + time &= 0x3EUL;
26715 + time <<= 2;
26716 +#elif defined(CONFIG_X86_64)
26717 + time &= 0xFUL;
26718 + time <<= 4;
26719 +#else
26720 + time &= 0x1FUL;
26721 + time <<= 3;
26722 +#endif
26723 +
26724 + thread->sp0 ^= time;
26725 + load_sp0(init_tss + smp_processor_id(), thread);
26726 +
26727 +#ifdef CONFIG_X86_64
26728 + this_cpu_write(kernel_stack, thread->sp0);
26729 +#endif
26730 +}
26731 +#endif
26732 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
26733 index 7bc86bb..0ea06e8 100644
26734 --- a/arch/x86/kernel/process_32.c
26735 +++ b/arch/x86/kernel/process_32.c
26736 @@ -64,6 +64,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
26737 unsigned long thread_saved_pc(struct task_struct *tsk)
26738 {
26739 return ((unsigned long *)tsk->thread.sp)[3];
26740 +//XXX return tsk->thread.eip;
26741 }
26742
26743 void __show_regs(struct pt_regs *regs, int all)
26744 @@ -73,19 +74,18 @@ void __show_regs(struct pt_regs *regs, int all)
26745 unsigned long sp;
26746 unsigned short ss, gs;
26747
26748 - if (user_mode_vm(regs)) {
26749 + if (user_mode(regs)) {
26750 sp = regs->sp;
26751 ss = regs->ss & 0xffff;
26752 - gs = get_user_gs(regs);
26753 } else {
26754 sp = kernel_stack_pointer(regs);
26755 savesegment(ss, ss);
26756 - savesegment(gs, gs);
26757 }
26758 + gs = get_user_gs(regs);
26759
26760 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
26761 (u16)regs->cs, regs->ip, regs->flags,
26762 - smp_processor_id());
26763 + raw_smp_processor_id());
26764 print_symbol("EIP is at %s\n", regs->ip);
26765
26766 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
26767 @@ -132,20 +132,21 @@ void release_thread(struct task_struct *dead_task)
26768 int copy_thread(unsigned long clone_flags, unsigned long sp,
26769 unsigned long arg, struct task_struct *p)
26770 {
26771 - struct pt_regs *childregs = task_pt_regs(p);
26772 + struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
26773 struct task_struct *tsk;
26774 int err;
26775
26776 p->thread.sp = (unsigned long) childregs;
26777 p->thread.sp0 = (unsigned long) (childregs+1);
26778 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26779
26780 if (unlikely(p->flags & PF_KTHREAD)) {
26781 /* kernel thread */
26782 memset(childregs, 0, sizeof(struct pt_regs));
26783 p->thread.ip = (unsigned long) ret_from_kernel_thread;
26784 - task_user_gs(p) = __KERNEL_STACK_CANARY;
26785 - childregs->ds = __USER_DS;
26786 - childregs->es = __USER_DS;
26787 + savesegment(gs, childregs->gs);
26788 + childregs->ds = __KERNEL_DS;
26789 + childregs->es = __KERNEL_DS;
26790 childregs->fs = __KERNEL_PERCPU;
26791 childregs->bx = sp; /* function */
26792 childregs->bp = arg;
26793 @@ -252,7 +253,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26794 struct thread_struct *prev = &prev_p->thread,
26795 *next = &next_p->thread;
26796 int cpu = smp_processor_id();
26797 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
26798 + struct tss_struct *tss = init_tss + cpu;
26799 fpu_switch_t fpu;
26800
26801 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
26802 @@ -276,6 +277,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26803 */
26804 lazy_save_gs(prev->gs);
26805
26806 +#ifdef CONFIG_PAX_MEMORY_UDEREF
26807 + __set_fs(task_thread_info(next_p)->addr_limit);
26808 +#endif
26809 +
26810 /*
26811 * Load the per-thread Thread-Local Storage descriptor.
26812 */
26813 @@ -314,9 +319,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26814 */
26815 arch_end_context_switch(next_p);
26816
26817 - this_cpu_write(kernel_stack,
26818 - (unsigned long)task_stack_page(next_p) +
26819 - THREAD_SIZE - KERNEL_STACK_OFFSET);
26820 + this_cpu_write(current_task, next_p);
26821 + this_cpu_write(current_tinfo, &next_p->tinfo);
26822 + this_cpu_write(kernel_stack, next->sp0);
26823
26824 /*
26825 * Restore %gs if needed (which is common)
26826 @@ -326,8 +331,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26827
26828 switch_fpu_finish(next_p, fpu);
26829
26830 - this_cpu_write(current_task, next_p);
26831 -
26832 return prev_p;
26833 }
26834
26835 @@ -357,4 +360,3 @@ unsigned long get_wchan(struct task_struct *p)
26836 } while (count++ < 16);
26837 return 0;
26838 }
26839 -
26840 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
26841 index ca5b02d..c0b2f6a 100644
26842 --- a/arch/x86/kernel/process_64.c
26843 +++ b/arch/x86/kernel/process_64.c
26844 @@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26845 struct pt_regs *childregs;
26846 struct task_struct *me = current;
26847
26848 - p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
26849 + p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
26850 childregs = task_pt_regs(p);
26851 p->thread.sp = (unsigned long) childregs;
26852 p->thread.usersp = me->thread.usersp;
26853 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26854 set_tsk_thread_flag(p, TIF_FORK);
26855 p->thread.fpu_counter = 0;
26856 p->thread.io_bitmap_ptr = NULL;
26857 @@ -172,6 +173,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26858 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
26859 savesegment(es, p->thread.es);
26860 savesegment(ds, p->thread.ds);
26861 + savesegment(ss, p->thread.ss);
26862 + BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
26863 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
26864
26865 if (unlikely(p->flags & PF_KTHREAD)) {
26866 @@ -280,7 +283,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26867 struct thread_struct *prev = &prev_p->thread;
26868 struct thread_struct *next = &next_p->thread;
26869 int cpu = smp_processor_id();
26870 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
26871 + struct tss_struct *tss = init_tss + cpu;
26872 unsigned fsindex, gsindex;
26873 fpu_switch_t fpu;
26874
26875 @@ -303,6 +306,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26876 if (unlikely(next->ds | prev->ds))
26877 loadsegment(ds, next->ds);
26878
26879 + savesegment(ss, prev->ss);
26880 + if (unlikely(next->ss != prev->ss))
26881 + loadsegment(ss, next->ss);
26882
26883 /* We must save %fs and %gs before load_TLS() because
26884 * %fs and %gs may be cleared by load_TLS().
26885 @@ -362,6 +368,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26886 prev->usersp = this_cpu_read(old_rsp);
26887 this_cpu_write(old_rsp, next->usersp);
26888 this_cpu_write(current_task, next_p);
26889 + this_cpu_write(current_tinfo, &next_p->tinfo);
26890
26891 /*
26892 * If it were not for PREEMPT_ACTIVE we could guarantee that the
26893 @@ -371,9 +378,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26894 task_thread_info(prev_p)->saved_preempt_count = this_cpu_read(__preempt_count);
26895 this_cpu_write(__preempt_count, task_thread_info(next_p)->saved_preempt_count);
26896
26897 - this_cpu_write(kernel_stack,
26898 - (unsigned long)task_stack_page(next_p) +
26899 - THREAD_SIZE - KERNEL_STACK_OFFSET);
26900 + this_cpu_write(kernel_stack, next->sp0);
26901
26902 /*
26903 * Now maybe reload the debug registers and handle I/O bitmaps
26904 @@ -443,12 +448,11 @@ unsigned long get_wchan(struct task_struct *p)
26905 if (!p || p == current || p->state == TASK_RUNNING)
26906 return 0;
26907 stack = (unsigned long)task_stack_page(p);
26908 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
26909 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
26910 return 0;
26911 fp = *(u64 *)(p->thread.sp);
26912 do {
26913 - if (fp < (unsigned long)stack ||
26914 - fp >= (unsigned long)stack+THREAD_SIZE)
26915 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
26916 return 0;
26917 ip = *(u64 *)(fp+8);
26918 if (!in_sched_functions(ip))
26919 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
26920 index 678c0ad..2fc2a7b 100644
26921 --- a/arch/x86/kernel/ptrace.c
26922 +++ b/arch/x86/kernel/ptrace.c
26923 @@ -186,10 +186,10 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
26924 unsigned long sp = (unsigned long)&regs->sp;
26925 u32 *prev_esp;
26926
26927 - if (context == (sp & ~(THREAD_SIZE - 1)))
26928 + if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
26929 return sp;
26930
26931 - prev_esp = (u32 *)(context);
26932 + prev_esp = *(u32 **)(context);
26933 if (prev_esp)
26934 return (unsigned long)prev_esp;
26935
26936 @@ -452,6 +452,20 @@ static int putreg(struct task_struct *child,
26937 if (child->thread.gs != value)
26938 return do_arch_prctl(child, ARCH_SET_GS, value);
26939 return 0;
26940 +
26941 + case offsetof(struct user_regs_struct,ip):
26942 + /*
26943 + * Protect against any attempt to set ip to an
26944 + * impossible address. There are dragons lurking if the
26945 + * address is noncanonical. (This explicitly allows
26946 + * setting ip to TASK_SIZE_MAX, because user code can do
26947 + * that all by itself by running off the end of its
26948 + * address space.
26949 + */
26950 + if (value > TASK_SIZE_MAX)
26951 + return -EIO;
26952 + break;
26953 +
26954 #endif
26955 }
26956
26957 @@ -588,7 +602,7 @@ static void ptrace_triggered(struct perf_event *bp,
26958 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
26959 {
26960 int i;
26961 - int dr7 = 0;
26962 + unsigned long dr7 = 0;
26963 struct arch_hw_breakpoint *info;
26964
26965 for (i = 0; i < HBP_NUM; i++) {
26966 @@ -822,7 +836,7 @@ long arch_ptrace(struct task_struct *child, long request,
26967 unsigned long addr, unsigned long data)
26968 {
26969 int ret;
26970 - unsigned long __user *datap = (unsigned long __user *)data;
26971 + unsigned long __user *datap = (__force unsigned long __user *)data;
26972
26973 switch (request) {
26974 /* read the word at location addr in the USER area. */
26975 @@ -907,14 +921,14 @@ long arch_ptrace(struct task_struct *child, long request,
26976 if ((int) addr < 0)
26977 return -EIO;
26978 ret = do_get_thread_area(child, addr,
26979 - (struct user_desc __user *)data);
26980 + (__force struct user_desc __user *) data);
26981 break;
26982
26983 case PTRACE_SET_THREAD_AREA:
26984 if ((int) addr < 0)
26985 return -EIO;
26986 ret = do_set_thread_area(child, addr,
26987 - (struct user_desc __user *)data, 0);
26988 + (__force struct user_desc __user *) data, 0);
26989 break;
26990 #endif
26991
26992 @@ -1292,7 +1306,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
26993
26994 #ifdef CONFIG_X86_64
26995
26996 -static struct user_regset x86_64_regsets[] __read_mostly = {
26997 +static user_regset_no_const x86_64_regsets[] __read_only = {
26998 [REGSET_GENERAL] = {
26999 .core_note_type = NT_PRSTATUS,
27000 .n = sizeof(struct user_regs_struct) / sizeof(long),
27001 @@ -1333,7 +1347,7 @@ static const struct user_regset_view user_x86_64_view = {
27002 #endif /* CONFIG_X86_64 */
27003
27004 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
27005 -static struct user_regset x86_32_regsets[] __read_mostly = {
27006 +static user_regset_no_const x86_32_regsets[] __read_only = {
27007 [REGSET_GENERAL] = {
27008 .core_note_type = NT_PRSTATUS,
27009 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
27010 @@ -1386,7 +1400,7 @@ static const struct user_regset_view user_x86_32_view = {
27011 */
27012 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
27013
27014 -void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
27015 +void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
27016 {
27017 #ifdef CONFIG_X86_64
27018 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
27019 @@ -1421,7 +1435,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
27020 memset(info, 0, sizeof(*info));
27021 info->si_signo = SIGTRAP;
27022 info->si_code = si_code;
27023 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
27024 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
27025 }
27026
27027 void user_single_step_siginfo(struct task_struct *tsk,
27028 @@ -1450,6 +1464,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
27029 # define IS_IA32 0
27030 #endif
27031
27032 +#ifdef CONFIG_GRKERNSEC_SETXID
27033 +extern void gr_delayed_cred_worker(void);
27034 +#endif
27035 +
27036 /*
27037 * We must return the syscall number to actually look up in the table.
27038 * This can be -1L to skip running any syscall at all.
27039 @@ -1460,6 +1478,11 @@ long syscall_trace_enter(struct pt_regs *regs)
27040
27041 user_exit();
27042
27043 +#ifdef CONFIG_GRKERNSEC_SETXID
27044 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
27045 + gr_delayed_cred_worker();
27046 +#endif
27047 +
27048 /*
27049 * If we stepped into a sysenter/syscall insn, it trapped in
27050 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
27051 @@ -1515,6 +1538,11 @@ void syscall_trace_leave(struct pt_regs *regs)
27052 */
27053 user_exit();
27054
27055 +#ifdef CONFIG_GRKERNSEC_SETXID
27056 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
27057 + gr_delayed_cred_worker();
27058 +#endif
27059 +
27060 audit_syscall_exit(regs);
27061
27062 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
27063 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
27064 index 2f355d2..e75ed0a 100644
27065 --- a/arch/x86/kernel/pvclock.c
27066 +++ b/arch/x86/kernel/pvclock.c
27067 @@ -51,11 +51,11 @@ void pvclock_touch_watchdogs(void)
27068 reset_hung_task_detector();
27069 }
27070
27071 -static atomic64_t last_value = ATOMIC64_INIT(0);
27072 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
27073
27074 void pvclock_resume(void)
27075 {
27076 - atomic64_set(&last_value, 0);
27077 + atomic64_set_unchecked(&last_value, 0);
27078 }
27079
27080 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
27081 @@ -105,11 +105,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
27082 * updating at the same time, and one of them could be slightly behind,
27083 * making the assumption that last_value always go forward fail to hold.
27084 */
27085 - last = atomic64_read(&last_value);
27086 + last = atomic64_read_unchecked(&last_value);
27087 do {
27088 if (ret < last)
27089 return last;
27090 - last = atomic64_cmpxchg(&last_value, last, ret);
27091 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
27092 } while (unlikely(last != ret));
27093
27094 return ret;
27095 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
27096 index 52b1157..c6e67c4 100644
27097 --- a/arch/x86/kernel/reboot.c
27098 +++ b/arch/x86/kernel/reboot.c
27099 @@ -68,6 +68,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
27100
27101 void __noreturn machine_real_restart(unsigned int type)
27102 {
27103 +
27104 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
27105 + struct desc_struct *gdt;
27106 +#endif
27107 +
27108 local_irq_disable();
27109
27110 /*
27111 @@ -95,7 +100,29 @@ void __noreturn machine_real_restart(unsigned int type)
27112
27113 /* Jump to the identity-mapped low memory code */
27114 #ifdef CONFIG_X86_32
27115 - asm volatile("jmpl *%0" : :
27116 +
27117 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
27118 + gdt = get_cpu_gdt_table(smp_processor_id());
27119 + pax_open_kernel();
27120 +#ifdef CONFIG_PAX_MEMORY_UDEREF
27121 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
27122 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
27123 + loadsegment(ds, __KERNEL_DS);
27124 + loadsegment(es, __KERNEL_DS);
27125 + loadsegment(ss, __KERNEL_DS);
27126 +#endif
27127 +#ifdef CONFIG_PAX_KERNEXEC
27128 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
27129 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
27130 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
27131 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
27132 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
27133 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
27134 +#endif
27135 + pax_close_kernel();
27136 +#endif
27137 +
27138 + asm volatile("ljmpl *%0" : :
27139 "rm" (real_mode_header->machine_real_restart_asm),
27140 "a" (type));
27141 #else
27142 @@ -486,7 +513,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
27143 * This means that this function can never return, it can misbehave
27144 * by not rebooting properly and hanging.
27145 */
27146 -static void native_machine_emergency_restart(void)
27147 +static void __noreturn native_machine_emergency_restart(void)
27148 {
27149 int i;
27150 int attempt = 0;
27151 @@ -610,13 +637,13 @@ void native_machine_shutdown(void)
27152 #endif
27153 }
27154
27155 -static void __machine_emergency_restart(int emergency)
27156 +static void __noreturn __machine_emergency_restart(int emergency)
27157 {
27158 reboot_emergency = emergency;
27159 machine_ops.emergency_restart();
27160 }
27161
27162 -static void native_machine_restart(char *__unused)
27163 +static void __noreturn native_machine_restart(char *__unused)
27164 {
27165 pr_notice("machine restart\n");
27166
27167 @@ -625,7 +652,7 @@ static void native_machine_restart(char *__unused)
27168 __machine_emergency_restart(0);
27169 }
27170
27171 -static void native_machine_halt(void)
27172 +static void __noreturn native_machine_halt(void)
27173 {
27174 /* Stop other cpus and apics */
27175 machine_shutdown();
27176 @@ -635,7 +662,7 @@ static void native_machine_halt(void)
27177 stop_this_cpu(NULL);
27178 }
27179
27180 -static void native_machine_power_off(void)
27181 +static void __noreturn native_machine_power_off(void)
27182 {
27183 if (pm_power_off) {
27184 if (!reboot_force)
27185 @@ -644,9 +671,10 @@ static void native_machine_power_off(void)
27186 }
27187 /* A fallback in case there is no PM info available */
27188 tboot_shutdown(TB_SHUTDOWN_HALT);
27189 + unreachable();
27190 }
27191
27192 -struct machine_ops machine_ops = {
27193 +struct machine_ops machine_ops __read_only = {
27194 .power_off = native_machine_power_off,
27195 .shutdown = native_machine_shutdown,
27196 .emergency_restart = native_machine_emergency_restart,
27197 diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
27198 index c8e41e9..64049ef 100644
27199 --- a/arch/x86/kernel/reboot_fixups_32.c
27200 +++ b/arch/x86/kernel/reboot_fixups_32.c
27201 @@ -57,7 +57,7 @@ struct device_fixup {
27202 unsigned int vendor;
27203 unsigned int device;
27204 void (*reboot_fixup)(struct pci_dev *);
27205 -};
27206 +} __do_const;
27207
27208 /*
27209 * PCI ids solely used for fixups_table go here
27210 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
27211 index 3fd2c69..a444264 100644
27212 --- a/arch/x86/kernel/relocate_kernel_64.S
27213 +++ b/arch/x86/kernel/relocate_kernel_64.S
27214 @@ -96,8 +96,7 @@ relocate_kernel:
27215
27216 /* jump to identity mapped page */
27217 addq $(identity_mapped - relocate_kernel), %r8
27218 - pushq %r8
27219 - ret
27220 + jmp *%r8
27221
27222 identity_mapped:
27223 /* set return address to 0 if not preserving context */
27224 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
27225 index 78a0e62..5c2e510 100644
27226 --- a/arch/x86/kernel/setup.c
27227 +++ b/arch/x86/kernel/setup.c
27228 @@ -110,6 +110,7 @@
27229 #include <asm/mce.h>
27230 #include <asm/alternative.h>
27231 #include <asm/prom.h>
27232 +#include <asm/boot.h>
27233
27234 /*
27235 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
27236 @@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
27237 #endif
27238
27239
27240 -#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
27241 -__visible unsigned long mmu_cr4_features;
27242 +#ifdef CONFIG_X86_64
27243 +__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
27244 +#elif defined(CONFIG_X86_PAE)
27245 +__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
27246 #else
27247 -__visible unsigned long mmu_cr4_features = X86_CR4_PAE;
27248 +__visible unsigned long mmu_cr4_features __read_only;
27249 #endif
27250
27251 +void set_in_cr4(unsigned long mask)
27252 +{
27253 + unsigned long cr4 = read_cr4();
27254 +
27255 + if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
27256 + return;
27257 +
27258 + pax_open_kernel();
27259 + mmu_cr4_features |= mask;
27260 + pax_close_kernel();
27261 +
27262 + if (trampoline_cr4_features)
27263 + *trampoline_cr4_features = mmu_cr4_features;
27264 + cr4 |= mask;
27265 + write_cr4(cr4);
27266 +}
27267 +EXPORT_SYMBOL(set_in_cr4);
27268 +
27269 +void clear_in_cr4(unsigned long mask)
27270 +{
27271 + unsigned long cr4 = read_cr4();
27272 +
27273 + if (!(cr4 & mask) && cr4 == mmu_cr4_features)
27274 + return;
27275 +
27276 + pax_open_kernel();
27277 + mmu_cr4_features &= ~mask;
27278 + pax_close_kernel();
27279 +
27280 + if (trampoline_cr4_features)
27281 + *trampoline_cr4_features = mmu_cr4_features;
27282 + cr4 &= ~mask;
27283 + write_cr4(cr4);
27284 +}
27285 +EXPORT_SYMBOL(clear_in_cr4);
27286 +
27287 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
27288 int bootloader_type, bootloader_version;
27289
27290 @@ -772,7 +811,7 @@ static void __init trim_bios_range(void)
27291 * area (640->1Mb) as ram even though it is not.
27292 * take them out.
27293 */
27294 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
27295 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
27296
27297 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
27298 }
27299 @@ -780,7 +819,7 @@ static void __init trim_bios_range(void)
27300 /* called before trim_bios_range() to spare extra sanitize */
27301 static void __init e820_add_kernel_range(void)
27302 {
27303 - u64 start = __pa_symbol(_text);
27304 + u64 start = __pa_symbol(ktla_ktva(_text));
27305 u64 size = __pa_symbol(_end) - start;
27306
27307 /*
27308 @@ -856,8 +895,12 @@ dump_kernel_offset(struct notifier_block *self, unsigned long v, void *p)
27309
27310 void __init setup_arch(char **cmdline_p)
27311 {
27312 +#ifdef CONFIG_X86_32
27313 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
27314 +#else
27315 memblock_reserve(__pa_symbol(_text),
27316 (unsigned long)__bss_stop - (unsigned long)_text);
27317 +#endif
27318
27319 early_reserve_initrd();
27320
27321 @@ -946,14 +989,14 @@ void __init setup_arch(char **cmdline_p)
27322
27323 if (!boot_params.hdr.root_flags)
27324 root_mountflags &= ~MS_RDONLY;
27325 - init_mm.start_code = (unsigned long) _text;
27326 - init_mm.end_code = (unsigned long) _etext;
27327 + init_mm.start_code = ktla_ktva((unsigned long) _text);
27328 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
27329 init_mm.end_data = (unsigned long) _edata;
27330 init_mm.brk = _brk_end;
27331
27332 - code_resource.start = __pa_symbol(_text);
27333 - code_resource.end = __pa_symbol(_etext)-1;
27334 - data_resource.start = __pa_symbol(_etext);
27335 + code_resource.start = __pa_symbol(ktla_ktva(_text));
27336 + code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
27337 + data_resource.start = __pa_symbol(_sdata);
27338 data_resource.end = __pa_symbol(_edata)-1;
27339 bss_resource.start = __pa_symbol(__bss_start);
27340 bss_resource.end = __pa_symbol(__bss_stop)-1;
27341 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
27342 index 5cdff03..80fa283 100644
27343 --- a/arch/x86/kernel/setup_percpu.c
27344 +++ b/arch/x86/kernel/setup_percpu.c
27345 @@ -21,19 +21,17 @@
27346 #include <asm/cpu.h>
27347 #include <asm/stackprotector.h>
27348
27349 -DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
27350 +#ifdef CONFIG_SMP
27351 +DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
27352 EXPORT_PER_CPU_SYMBOL(cpu_number);
27353 +#endif
27354
27355 -#ifdef CONFIG_X86_64
27356 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
27357 -#else
27358 -#define BOOT_PERCPU_OFFSET 0
27359 -#endif
27360
27361 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
27362 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
27363
27364 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
27365 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
27366 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
27367 };
27368 EXPORT_SYMBOL(__per_cpu_offset);
27369 @@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
27370 {
27371 #ifdef CONFIG_NEED_MULTIPLE_NODES
27372 pg_data_t *last = NULL;
27373 - unsigned int cpu;
27374 + int cpu;
27375
27376 for_each_possible_cpu(cpu) {
27377 int node = early_cpu_to_node(cpu);
27378 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
27379 {
27380 #ifdef CONFIG_X86_32
27381 struct desc_struct gdt;
27382 + unsigned long base = per_cpu_offset(cpu);
27383
27384 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
27385 - 0x2 | DESCTYPE_S, 0x8);
27386 - gdt.s = 1;
27387 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
27388 + 0x83 | DESCTYPE_S, 0xC);
27389 write_gdt_entry(get_cpu_gdt_table(cpu),
27390 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
27391 #endif
27392 @@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
27393 /* alrighty, percpu areas up and running */
27394 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
27395 for_each_possible_cpu(cpu) {
27396 +#ifdef CONFIG_CC_STACKPROTECTOR
27397 +#ifdef CONFIG_X86_32
27398 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
27399 +#endif
27400 +#endif
27401 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
27402 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
27403 per_cpu(cpu_number, cpu) = cpu;
27404 @@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
27405 */
27406 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
27407 #endif
27408 +#ifdef CONFIG_CC_STACKPROTECTOR
27409 +#ifdef CONFIG_X86_32
27410 + if (!cpu)
27411 + per_cpu(stack_canary.canary, cpu) = canary;
27412 +#endif
27413 +#endif
27414 /*
27415 * Up to this point, the boot CPU has been using .init.data
27416 * area. Reload any changed state for the boot CPU.
27417 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
27418 index 2851d63..83bf567 100644
27419 --- a/arch/x86/kernel/signal.c
27420 +++ b/arch/x86/kernel/signal.c
27421 @@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
27422 * Align the stack pointer according to the i386 ABI,
27423 * i.e. so that on function entry ((sp + 4) & 15) == 0.
27424 */
27425 - sp = ((sp + 4) & -16ul) - 4;
27426 + sp = ((sp - 12) & -16ul) - 4;
27427 #else /* !CONFIG_X86_32 */
27428 sp = round_down(sp, 16) - 8;
27429 #endif
27430 @@ -298,10 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
27431 }
27432
27433 if (current->mm->context.vdso)
27434 - restorer = current->mm->context.vdso +
27435 - selected_vdso32->sym___kernel_sigreturn;
27436 + restorer = (void __force_user *)(current->mm->context.vdso + selected_vdso32->sym___kernel_sigreturn);
27437 else
27438 - restorer = &frame->retcode;
27439 + restorer = (void __user *)&frame->retcode;
27440 if (ksig->ka.sa.sa_flags & SA_RESTORER)
27441 restorer = ksig->ka.sa.sa_restorer;
27442
27443 @@ -315,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
27444 * reasons and because gdb uses it as a signature to notice
27445 * signal handler stack frames.
27446 */
27447 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
27448 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
27449
27450 if (err)
27451 return -EFAULT;
27452 @@ -362,8 +361,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
27453 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
27454
27455 /* Set up to return from userspace. */
27456 - restorer = current->mm->context.vdso +
27457 - selected_vdso32->sym___kernel_rt_sigreturn;
27458 + if (current->mm->context.vdso)
27459 + restorer = (void __force_user *)(current->mm->context.vdso + selected_vdso32->sym___kernel_rt_sigreturn);
27460 + else
27461 + restorer = (void __user *)&frame->retcode;
27462 if (ksig->ka.sa.sa_flags & SA_RESTORER)
27463 restorer = ksig->ka.sa.sa_restorer;
27464 put_user_ex(restorer, &frame->pretcode);
27465 @@ -375,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
27466 * reasons and because gdb uses it as a signature to notice
27467 * signal handler stack frames.
27468 */
27469 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
27470 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
27471 } put_user_catch(err);
27472
27473 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
27474 @@ -611,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
27475 {
27476 int usig = signr_convert(ksig->sig);
27477 sigset_t *set = sigmask_to_save();
27478 - compat_sigset_t *cset = (compat_sigset_t *) set;
27479 + sigset_t sigcopy;
27480 + compat_sigset_t *cset;
27481 +
27482 + sigcopy = *set;
27483 +
27484 + cset = (compat_sigset_t *) &sigcopy;
27485
27486 /* Set up the stack frame */
27487 if (is_ia32_frame()) {
27488 @@ -622,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
27489 } else if (is_x32_frame()) {
27490 return x32_setup_rt_frame(ksig, cset, regs);
27491 } else {
27492 - return __setup_rt_frame(ksig->sig, ksig, set, regs);
27493 + return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
27494 }
27495 }
27496
27497 diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
27498 index be8e1bd..a3d93fa 100644
27499 --- a/arch/x86/kernel/smp.c
27500 +++ b/arch/x86/kernel/smp.c
27501 @@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
27502
27503 __setup("nonmi_ipi", nonmi_ipi_setup);
27504
27505 -struct smp_ops smp_ops = {
27506 +struct smp_ops smp_ops __read_only = {
27507 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
27508 .smp_prepare_cpus = native_smp_prepare_cpus,
27509 .smp_cpus_done = native_smp_cpus_done,
27510 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
27511 index 5492798..a3bd4f2 100644
27512 --- a/arch/x86/kernel/smpboot.c
27513 +++ b/arch/x86/kernel/smpboot.c
27514 @@ -230,14 +230,17 @@ static void notrace start_secondary(void *unused)
27515
27516 enable_start_cpu0 = 0;
27517
27518 -#ifdef CONFIG_X86_32
27519 + /* otherwise gcc will move up smp_processor_id before the cpu_init */
27520 + barrier();
27521 +
27522 /* switch away from the initial page table */
27523 +#ifdef CONFIG_PAX_PER_CPU_PGD
27524 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
27525 +#else
27526 load_cr3(swapper_pg_dir);
27527 +#endif
27528 __flush_tlb_all();
27529 -#endif
27530
27531 - /* otherwise gcc will move up smp_processor_id before the cpu_init */
27532 - barrier();
27533 /*
27534 * Check TSC synchronization with the BP:
27535 */
27536 @@ -764,8 +767,9 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
27537 alternatives_enable_smp();
27538
27539 idle->thread.sp = (unsigned long) (((struct pt_regs *)
27540 - (THREAD_SIZE + task_stack_page(idle))) - 1);
27541 + (THREAD_SIZE - 16 + task_stack_page(idle))) - 1);
27542 per_cpu(current_task, cpu) = idle;
27543 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
27544
27545 #ifdef CONFIG_X86_32
27546 /* Stack for startup_32 can be just as for start_secondary onwards */
27547 @@ -774,10 +778,10 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
27548 clear_tsk_thread_flag(idle, TIF_FORK);
27549 initial_gs = per_cpu_offset(cpu);
27550 #endif
27551 - per_cpu(kernel_stack, cpu) =
27552 - (unsigned long)task_stack_page(idle) -
27553 - KERNEL_STACK_OFFSET + THREAD_SIZE;
27554 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27555 + pax_open_kernel();
27556 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
27557 + pax_close_kernel();
27558 initial_code = (unsigned long)start_secondary;
27559 stack_start = idle->thread.sp;
27560
27561 @@ -923,6 +927,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
27562 /* the FPU context is blank, nobody can own it */
27563 __cpu_disable_lazy_restore(cpu);
27564
27565 +#ifdef CONFIG_PAX_PER_CPU_PGD
27566 + clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
27567 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27568 + KERNEL_PGD_PTRS);
27569 + clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
27570 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27571 + KERNEL_PGD_PTRS);
27572 +#endif
27573 +
27574 err = do_boot_cpu(apicid, cpu, tidle);
27575 if (err) {
27576 pr_err("do_boot_cpu failed(%d) to wakeup CPU#%u\n", err, cpu);
27577 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
27578 index 9b4d51d..5d28b58 100644
27579 --- a/arch/x86/kernel/step.c
27580 +++ b/arch/x86/kernel/step.c
27581 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
27582 struct desc_struct *desc;
27583 unsigned long base;
27584
27585 - seg &= ~7UL;
27586 + seg >>= 3;
27587
27588 mutex_lock(&child->mm->context.lock);
27589 - if (unlikely((seg >> 3) >= child->mm->context.size))
27590 + if (unlikely(seg >= child->mm->context.size))
27591 addr = -1L; /* bogus selector, access would fault */
27592 else {
27593 desc = child->mm->context.ldt + seg;
27594 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
27595 addr += base;
27596 }
27597 mutex_unlock(&child->mm->context.lock);
27598 - }
27599 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
27600 + addr = ktla_ktva(addr);
27601
27602 return addr;
27603 }
27604 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
27605 unsigned char opcode[15];
27606 unsigned long addr = convert_ip_to_linear(child, regs);
27607
27608 + if (addr == -EINVAL)
27609 + return 0;
27610 +
27611 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
27612 for (i = 0; i < copied; i++) {
27613 switch (opcode[i]) {
27614 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
27615 new file mode 100644
27616 index 0000000..5877189
27617 --- /dev/null
27618 +++ b/arch/x86/kernel/sys_i386_32.c
27619 @@ -0,0 +1,189 @@
27620 +/*
27621 + * This file contains various random system calls that
27622 + * have a non-standard calling sequence on the Linux/i386
27623 + * platform.
27624 + */
27625 +
27626 +#include <linux/errno.h>
27627 +#include <linux/sched.h>
27628 +#include <linux/mm.h>
27629 +#include <linux/fs.h>
27630 +#include <linux/smp.h>
27631 +#include <linux/sem.h>
27632 +#include <linux/msg.h>
27633 +#include <linux/shm.h>
27634 +#include <linux/stat.h>
27635 +#include <linux/syscalls.h>
27636 +#include <linux/mman.h>
27637 +#include <linux/file.h>
27638 +#include <linux/utsname.h>
27639 +#include <linux/ipc.h>
27640 +#include <linux/elf.h>
27641 +
27642 +#include <linux/uaccess.h>
27643 +#include <linux/unistd.h>
27644 +
27645 +#include <asm/syscalls.h>
27646 +
27647 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
27648 +{
27649 + unsigned long pax_task_size = TASK_SIZE;
27650 +
27651 +#ifdef CONFIG_PAX_SEGMEXEC
27652 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
27653 + pax_task_size = SEGMEXEC_TASK_SIZE;
27654 +#endif
27655 +
27656 + if (flags & MAP_FIXED)
27657 + if (len > pax_task_size || addr > pax_task_size - len)
27658 + return -EINVAL;
27659 +
27660 + return 0;
27661 +}
27662 +
27663 +/*
27664 + * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
27665 + */
27666 +static unsigned long get_align_mask(void)
27667 +{
27668 + if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
27669 + return 0;
27670 +
27671 + if (!(current->flags & PF_RANDOMIZE))
27672 + return 0;
27673 +
27674 + return va_align.mask;
27675 +}
27676 +
27677 +unsigned long
27678 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
27679 + unsigned long len, unsigned long pgoff, unsigned long flags)
27680 +{
27681 + struct mm_struct *mm = current->mm;
27682 + struct vm_area_struct *vma;
27683 + unsigned long pax_task_size = TASK_SIZE;
27684 + struct vm_unmapped_area_info info;
27685 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27686 +
27687 +#ifdef CONFIG_PAX_SEGMEXEC
27688 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
27689 + pax_task_size = SEGMEXEC_TASK_SIZE;
27690 +#endif
27691 +
27692 + pax_task_size -= PAGE_SIZE;
27693 +
27694 + if (len > pax_task_size)
27695 + return -ENOMEM;
27696 +
27697 + if (flags & MAP_FIXED)
27698 + return addr;
27699 +
27700 +#ifdef CONFIG_PAX_RANDMMAP
27701 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27702 +#endif
27703 +
27704 + if (addr) {
27705 + addr = PAGE_ALIGN(addr);
27706 + if (pax_task_size - len >= addr) {
27707 + vma = find_vma(mm, addr);
27708 + if (check_heap_stack_gap(vma, addr, len, offset))
27709 + return addr;
27710 + }
27711 + }
27712 +
27713 + info.flags = 0;
27714 + info.length = len;
27715 + info.align_mask = filp ? get_align_mask() : 0;
27716 + info.align_offset = pgoff << PAGE_SHIFT;
27717 + info.threadstack_offset = offset;
27718 +
27719 +#ifdef CONFIG_PAX_PAGEEXEC
27720 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
27721 + info.low_limit = 0x00110000UL;
27722 + info.high_limit = mm->start_code;
27723 +
27724 +#ifdef CONFIG_PAX_RANDMMAP
27725 + if (mm->pax_flags & MF_PAX_RANDMMAP)
27726 + info.low_limit += mm->delta_mmap & 0x03FFF000UL;
27727 +#endif
27728 +
27729 + if (info.low_limit < info.high_limit) {
27730 + addr = vm_unmapped_area(&info);
27731 + if (!IS_ERR_VALUE(addr))
27732 + return addr;
27733 + }
27734 + } else
27735 +#endif
27736 +
27737 + info.low_limit = mm->mmap_base;
27738 + info.high_limit = pax_task_size;
27739 +
27740 + return vm_unmapped_area(&info);
27741 +}
27742 +
27743 +unsigned long
27744 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27745 + const unsigned long len, const unsigned long pgoff,
27746 + const unsigned long flags)
27747 +{
27748 + struct vm_area_struct *vma;
27749 + struct mm_struct *mm = current->mm;
27750 + unsigned long addr = addr0, pax_task_size = TASK_SIZE;
27751 + struct vm_unmapped_area_info info;
27752 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27753 +
27754 +#ifdef CONFIG_PAX_SEGMEXEC
27755 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
27756 + pax_task_size = SEGMEXEC_TASK_SIZE;
27757 +#endif
27758 +
27759 + pax_task_size -= PAGE_SIZE;
27760 +
27761 + /* requested length too big for entire address space */
27762 + if (len > pax_task_size)
27763 + return -ENOMEM;
27764 +
27765 + if (flags & MAP_FIXED)
27766 + return addr;
27767 +
27768 +#ifdef CONFIG_PAX_PAGEEXEC
27769 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
27770 + goto bottomup;
27771 +#endif
27772 +
27773 +#ifdef CONFIG_PAX_RANDMMAP
27774 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27775 +#endif
27776 +
27777 + /* requesting a specific address */
27778 + if (addr) {
27779 + addr = PAGE_ALIGN(addr);
27780 + if (pax_task_size - len >= addr) {
27781 + vma = find_vma(mm, addr);
27782 + if (check_heap_stack_gap(vma, addr, len, offset))
27783 + return addr;
27784 + }
27785 + }
27786 +
27787 + info.flags = VM_UNMAPPED_AREA_TOPDOWN;
27788 + info.length = len;
27789 + info.low_limit = PAGE_SIZE;
27790 + info.high_limit = mm->mmap_base;
27791 + info.align_mask = filp ? get_align_mask() : 0;
27792 + info.align_offset = pgoff << PAGE_SHIFT;
27793 + info.threadstack_offset = offset;
27794 +
27795 + addr = vm_unmapped_area(&info);
27796 + if (!(addr & ~PAGE_MASK))
27797 + return addr;
27798 + VM_BUG_ON(addr != -ENOMEM);
27799 +
27800 +bottomup:
27801 + /*
27802 + * A failed mmap() very likely causes application failure,
27803 + * so fall back to the bottom-up function here. This scenario
27804 + * can happen with large stack limits and large mmap()
27805 + * allocations.
27806 + */
27807 + return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
27808 +}
27809 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
27810 index 30277e2..5664a29 100644
27811 --- a/arch/x86/kernel/sys_x86_64.c
27812 +++ b/arch/x86/kernel/sys_x86_64.c
27813 @@ -81,8 +81,8 @@ out:
27814 return error;
27815 }
27816
27817 -static void find_start_end(unsigned long flags, unsigned long *begin,
27818 - unsigned long *end)
27819 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
27820 + unsigned long *begin, unsigned long *end)
27821 {
27822 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
27823 unsigned long new_begin;
27824 @@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
27825 *begin = new_begin;
27826 }
27827 } else {
27828 - *begin = current->mm->mmap_legacy_base;
27829 + *begin = mm->mmap_legacy_base;
27830 *end = TASK_SIZE;
27831 }
27832 }
27833 @@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27834 struct vm_area_struct *vma;
27835 struct vm_unmapped_area_info info;
27836 unsigned long begin, end;
27837 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27838
27839 if (flags & MAP_FIXED)
27840 return addr;
27841
27842 - find_start_end(flags, &begin, &end);
27843 + find_start_end(mm, flags, &begin, &end);
27844
27845 if (len > end)
27846 return -ENOMEM;
27847
27848 +#ifdef CONFIG_PAX_RANDMMAP
27849 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27850 +#endif
27851 +
27852 if (addr) {
27853 addr = PAGE_ALIGN(addr);
27854 vma = find_vma(mm, addr);
27855 - if (end - len >= addr &&
27856 - (!vma || addr + len <= vma->vm_start))
27857 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27858 return addr;
27859 }
27860
27861 @@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27862 info.high_limit = end;
27863 info.align_mask = filp ? get_align_mask() : 0;
27864 info.align_offset = pgoff << PAGE_SHIFT;
27865 + info.threadstack_offset = offset;
27866 return vm_unmapped_area(&info);
27867 }
27868
27869 @@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27870 struct mm_struct *mm = current->mm;
27871 unsigned long addr = addr0;
27872 struct vm_unmapped_area_info info;
27873 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27874
27875 /* requested length too big for entire address space */
27876 if (len > TASK_SIZE)
27877 @@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27878 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
27879 goto bottomup;
27880
27881 +#ifdef CONFIG_PAX_RANDMMAP
27882 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27883 +#endif
27884 +
27885 /* requesting a specific address */
27886 if (addr) {
27887 addr = PAGE_ALIGN(addr);
27888 vma = find_vma(mm, addr);
27889 - if (TASK_SIZE - len >= addr &&
27890 - (!vma || addr + len <= vma->vm_start))
27891 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27892 return addr;
27893 }
27894
27895 @@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27896 info.high_limit = mm->mmap_base;
27897 info.align_mask = filp ? get_align_mask() : 0;
27898 info.align_offset = pgoff << PAGE_SHIFT;
27899 + info.threadstack_offset = offset;
27900 addr = vm_unmapped_area(&info);
27901 if (!(addr & ~PAGE_MASK))
27902 return addr;
27903 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
27904 index 91a4496..bb87552 100644
27905 --- a/arch/x86/kernel/tboot.c
27906 +++ b/arch/x86/kernel/tboot.c
27907 @@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
27908
27909 void tboot_shutdown(u32 shutdown_type)
27910 {
27911 - void (*shutdown)(void);
27912 + void (* __noreturn shutdown)(void);
27913
27914 if (!tboot_enabled())
27915 return;
27916 @@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
27917
27918 switch_to_tboot_pt();
27919
27920 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
27921 + shutdown = (void *)(unsigned long)tboot->shutdown_entry;
27922 shutdown();
27923
27924 /* should not reach here */
27925 @@ -310,7 +310,7 @@ static int tboot_extended_sleep(u8 sleep_state, u32 val_a, u32 val_b)
27926 return -ENODEV;
27927 }
27928
27929 -static atomic_t ap_wfs_count;
27930 +static atomic_unchecked_t ap_wfs_count;
27931
27932 static int tboot_wait_for_aps(int num_aps)
27933 {
27934 @@ -334,9 +334,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
27935 {
27936 switch (action) {
27937 case CPU_DYING:
27938 - atomic_inc(&ap_wfs_count);
27939 + atomic_inc_unchecked(&ap_wfs_count);
27940 if (num_online_cpus() == 1)
27941 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
27942 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
27943 return NOTIFY_BAD;
27944 break;
27945 }
27946 @@ -422,7 +422,7 @@ static __init int tboot_late_init(void)
27947
27948 tboot_create_trampoline();
27949
27950 - atomic_set(&ap_wfs_count, 0);
27951 + atomic_set_unchecked(&ap_wfs_count, 0);
27952 register_hotcpu_notifier(&tboot_cpu_notifier);
27953
27954 #ifdef CONFIG_DEBUG_FS
27955 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
27956 index bf7ef5c..59d0ac9 100644
27957 --- a/arch/x86/kernel/time.c
27958 +++ b/arch/x86/kernel/time.c
27959 @@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
27960 {
27961 unsigned long pc = instruction_pointer(regs);
27962
27963 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
27964 + if (!user_mode(regs) && in_lock_functions(pc)) {
27965 #ifdef CONFIG_FRAME_POINTER
27966 - return *(unsigned long *)(regs->bp + sizeof(long));
27967 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
27968 #else
27969 unsigned long *sp =
27970 (unsigned long *)kernel_stack_pointer(regs);
27971 @@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
27972 * or above a saved flags. Eflags has bits 22-31 zero,
27973 * kernel addresses don't.
27974 */
27975 +
27976 +#ifdef CONFIG_PAX_KERNEXEC
27977 + return ktla_ktva(sp[0]);
27978 +#else
27979 if (sp[0] >> 22)
27980 return sp[0];
27981 if (sp[1] >> 22)
27982 return sp[1];
27983 #endif
27984 +
27985 +#endif
27986 }
27987 return pc;
27988 }
27989 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
27990 index f7fec09..9991981 100644
27991 --- a/arch/x86/kernel/tls.c
27992 +++ b/arch/x86/kernel/tls.c
27993 @@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
27994 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
27995 return -EINVAL;
27996
27997 +#ifdef CONFIG_PAX_SEGMEXEC
27998 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
27999 + return -EINVAL;
28000 +#endif
28001 +
28002 set_tls_desc(p, idx, &info, 1);
28003
28004 return 0;
28005 @@ -200,7 +205,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
28006
28007 if (kbuf)
28008 info = kbuf;
28009 - else if (__copy_from_user(infobuf, ubuf, count))
28010 + else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
28011 return -EFAULT;
28012 else
28013 info = infobuf;
28014 diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
28015 index 1c113db..287b42e 100644
28016 --- a/arch/x86/kernel/tracepoint.c
28017 +++ b/arch/x86/kernel/tracepoint.c
28018 @@ -9,11 +9,11 @@
28019 #include <linux/atomic.h>
28020
28021 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
28022 -struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
28023 +const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
28024 (unsigned long) trace_idt_table };
28025
28026 /* No need to be aligned, but done to keep all IDTs defined the same way. */
28027 -gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
28028 +gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
28029
28030 static int trace_irq_vector_refcount;
28031 static DEFINE_MUTEX(irq_vector_mutex);
28032 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
28033 index 0d0e922..0886373 100644
28034 --- a/arch/x86/kernel/traps.c
28035 +++ b/arch/x86/kernel/traps.c
28036 @@ -67,7 +67,7 @@
28037 #include <asm/proto.h>
28038
28039 /* No need to be aligned, but done to keep all IDTs defined the same way. */
28040 -gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
28041 +gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
28042 #else
28043 #include <asm/processor-flags.h>
28044 #include <asm/setup.h>
28045 @@ -76,7 +76,7 @@ asmlinkage int system_call(void);
28046 #endif
28047
28048 /* Must be page-aligned because the real IDT is used in a fixmap. */
28049 -gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
28050 +gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
28051
28052 DECLARE_BITMAP(used_vectors, NR_VECTORS);
28053 EXPORT_SYMBOL_GPL(used_vectors);
28054 @@ -108,11 +108,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
28055 }
28056
28057 static nokprobe_inline int
28058 -do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
28059 +do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
28060 struct pt_regs *regs, long error_code)
28061 {
28062 #ifdef CONFIG_X86_32
28063 - if (regs->flags & X86_VM_MASK) {
28064 + if (v8086_mode(regs)) {
28065 /*
28066 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
28067 * On nmi (interrupt 2), do_trap should not be called.
28068 @@ -125,12 +125,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
28069 return -1;
28070 }
28071 #endif
28072 - if (!user_mode(regs)) {
28073 + if (!user_mode_novm(regs)) {
28074 if (!fixup_exception(regs)) {
28075 tsk->thread.error_code = error_code;
28076 tsk->thread.trap_nr = trapnr;
28077 +
28078 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28079 + if (trapnr == X86_TRAP_SS && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
28080 + str = "PAX: suspicious stack segment fault";
28081 +#endif
28082 +
28083 die(str, regs, error_code);
28084 }
28085 +
28086 +#ifdef CONFIG_PAX_REFCOUNT
28087 + if (trapnr == X86_TRAP_OF)
28088 + pax_report_refcount_overflow(regs);
28089 +#endif
28090 +
28091 return 0;
28092 }
28093
28094 @@ -169,7 +181,7 @@ static siginfo_t *fill_trap_info(struct pt_regs *regs, int signr, int trapnr,
28095 }
28096
28097 static void
28098 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
28099 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
28100 long error_code, siginfo_t *info)
28101 {
28102 struct task_struct *tsk = current;
28103 @@ -193,7 +205,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
28104 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
28105 printk_ratelimit()) {
28106 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
28107 - tsk->comm, tsk->pid, str,
28108 + tsk->comm, task_pid_nr(tsk), str,
28109 regs->ip, regs->sp, error_code);
28110 print_vma_addr(" in ", regs->ip);
28111 pr_cont("\n");
28112 @@ -266,6 +278,11 @@ dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code)
28113 tsk->thread.error_code = error_code;
28114 tsk->thread.trap_nr = X86_TRAP_DF;
28115
28116 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
28117 + if ((unsigned long)tsk->stack - regs->sp <= PAGE_SIZE)
28118 + die("grsec: kernel stack overflow detected", regs, error_code);
28119 +#endif
28120 +
28121 #ifdef CONFIG_DOUBLEFAULT
28122 df_debug(regs, error_code);
28123 #endif
28124 @@ -288,7 +305,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
28125 conditional_sti(regs);
28126
28127 #ifdef CONFIG_X86_32
28128 - if (regs->flags & X86_VM_MASK) {
28129 + if (v8086_mode(regs)) {
28130 local_irq_enable();
28131 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
28132 goto exit;
28133 @@ -296,18 +313,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
28134 #endif
28135
28136 tsk = current;
28137 - if (!user_mode(regs)) {
28138 + if (!user_mode_novm(regs)) {
28139 if (fixup_exception(regs))
28140 goto exit;
28141
28142 tsk->thread.error_code = error_code;
28143 tsk->thread.trap_nr = X86_TRAP_GP;
28144 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
28145 - X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
28146 + X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
28147 +
28148 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28149 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
28150 + die("PAX: suspicious general protection fault", regs, error_code);
28151 + else
28152 +#endif
28153 +
28154 die("general protection fault", regs, error_code);
28155 + }
28156 goto exit;
28157 }
28158
28159 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
28160 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
28161 + struct mm_struct *mm = tsk->mm;
28162 + unsigned long limit;
28163 +
28164 + down_write(&mm->mmap_sem);
28165 + limit = mm->context.user_cs_limit;
28166 + if (limit < TASK_SIZE) {
28167 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
28168 + up_write(&mm->mmap_sem);
28169 + return;
28170 + }
28171 + up_write(&mm->mmap_sem);
28172 + }
28173 +#endif
28174 +
28175 tsk->thread.error_code = error_code;
28176 tsk->thread.trap_nr = X86_TRAP_GP;
28177
28178 @@ -481,7 +522,7 @@ dotraplinkage void do_debug(struct pt_regs *regs, long error_code)
28179 /* It's safe to allow irq's after DR6 has been saved */
28180 preempt_conditional_sti(regs);
28181
28182 - if (regs->flags & X86_VM_MASK) {
28183 + if (v8086_mode(regs)) {
28184 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
28185 X86_TRAP_DB);
28186 preempt_conditional_cli(regs);
28187 @@ -496,7 +537,7 @@ dotraplinkage void do_debug(struct pt_regs *regs, long error_code)
28188 * We already checked v86 mode above, so we can check for kernel mode
28189 * by just checking the CPL of CS.
28190 */
28191 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
28192 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
28193 tsk->thread.debugreg6 &= ~DR_STEP;
28194 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
28195 regs->flags &= ~X86_EFLAGS_TF;
28196 @@ -529,7 +570,7 @@ static void math_error(struct pt_regs *regs, int error_code, int trapnr)
28197 return;
28198 conditional_sti(regs);
28199
28200 - if (!user_mode_vm(regs))
28201 + if (!user_mode(regs))
28202 {
28203 if (!fixup_exception(regs)) {
28204 task->thread.error_code = error_code;
28205 diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
28206 index ea03031..34a5cdda 100644
28207 --- a/arch/x86/kernel/tsc.c
28208 +++ b/arch/x86/kernel/tsc.c
28209 @@ -150,7 +150,7 @@ static void cyc2ns_write_end(int cpu, struct cyc2ns_data *data)
28210 */
28211 smp_wmb();
28212
28213 - ACCESS_ONCE(c2n->head) = data;
28214 + ACCESS_ONCE_RW(c2n->head) = data;
28215 }
28216
28217 /*
28218 diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
28219 index 5d1cbfe..2a21feb 100644
28220 --- a/arch/x86/kernel/uprobes.c
28221 +++ b/arch/x86/kernel/uprobes.c
28222 @@ -845,7 +845,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
28223 int ret = NOTIFY_DONE;
28224
28225 /* We are only interested in userspace traps */
28226 - if (regs && !user_mode_vm(regs))
28227 + if (regs && !user_mode(regs))
28228 return NOTIFY_DONE;
28229
28230 switch (val) {
28231 @@ -919,7 +919,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
28232
28233 if (nleft != rasize) {
28234 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
28235 - "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
28236 + "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
28237
28238 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
28239 }
28240 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
28241 index b9242ba..50c5edd 100644
28242 --- a/arch/x86/kernel/verify_cpu.S
28243 +++ b/arch/x86/kernel/verify_cpu.S
28244 @@ -20,6 +20,7 @@
28245 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
28246 * arch/x86/kernel/trampoline_64.S: secondary processor verification
28247 * arch/x86/kernel/head_32.S: processor startup
28248 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
28249 *
28250 * verify_cpu, returns the status of longmode and SSE in register %eax.
28251 * 0: Success 1: Failure
28252 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
28253 index e8edcf5..27f9344 100644
28254 --- a/arch/x86/kernel/vm86_32.c
28255 +++ b/arch/x86/kernel/vm86_32.c
28256 @@ -44,6 +44,7 @@
28257 #include <linux/ptrace.h>
28258 #include <linux/audit.h>
28259 #include <linux/stddef.h>
28260 +#include <linux/grsecurity.h>
28261
28262 #include <asm/uaccess.h>
28263 #include <asm/io.h>
28264 @@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
28265 do_exit(SIGSEGV);
28266 }
28267
28268 - tss = &per_cpu(init_tss, get_cpu());
28269 + tss = init_tss + get_cpu();
28270 current->thread.sp0 = current->thread.saved_sp0;
28271 current->thread.sysenter_cs = __KERNEL_CS;
28272 load_sp0(tss, &current->thread);
28273 @@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
28274
28275 if (tsk->thread.saved_sp0)
28276 return -EPERM;
28277 +
28278 +#ifdef CONFIG_GRKERNSEC_VM86
28279 + if (!capable(CAP_SYS_RAWIO)) {
28280 + gr_handle_vm86();
28281 + return -EPERM;
28282 + }
28283 +#endif
28284 +
28285 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
28286 offsetof(struct kernel_vm86_struct, vm86plus) -
28287 sizeof(info.regs));
28288 @@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
28289 int tmp;
28290 struct vm86plus_struct __user *v86;
28291
28292 +#ifdef CONFIG_GRKERNSEC_VM86
28293 + if (!capable(CAP_SYS_RAWIO)) {
28294 + gr_handle_vm86();
28295 + return -EPERM;
28296 + }
28297 +#endif
28298 +
28299 tsk = current;
28300 switch (cmd) {
28301 case VM86_REQUEST_IRQ:
28302 @@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
28303 tsk->thread.saved_fs = info->regs32->fs;
28304 tsk->thread.saved_gs = get_user_gs(info->regs32);
28305
28306 - tss = &per_cpu(init_tss, get_cpu());
28307 + tss = init_tss + get_cpu();
28308 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
28309 if (cpu_has_sep)
28310 tsk->thread.sysenter_cs = 0;
28311 @@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
28312 goto cannot_handle;
28313 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
28314 goto cannot_handle;
28315 - intr_ptr = (unsigned long __user *) (i << 2);
28316 + intr_ptr = (__force unsigned long __user *) (i << 2);
28317 if (get_user(segoffs, intr_ptr))
28318 goto cannot_handle;
28319 if ((segoffs >> 16) == BIOSSEG)
28320 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
28321 index 49edf2d..c0d1362 100644
28322 --- a/arch/x86/kernel/vmlinux.lds.S
28323 +++ b/arch/x86/kernel/vmlinux.lds.S
28324 @@ -26,6 +26,13 @@
28325 #include <asm/page_types.h>
28326 #include <asm/cache.h>
28327 #include <asm/boot.h>
28328 +#include <asm/segment.h>
28329 +
28330 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28331 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
28332 +#else
28333 +#define __KERNEL_TEXT_OFFSET 0
28334 +#endif
28335
28336 #undef i386 /* in case the preprocessor is a 32bit one */
28337
28338 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
28339
28340 PHDRS {
28341 text PT_LOAD FLAGS(5); /* R_E */
28342 +#ifdef CONFIG_X86_32
28343 + module PT_LOAD FLAGS(5); /* R_E */
28344 +#endif
28345 +#ifdef CONFIG_XEN
28346 + rodata PT_LOAD FLAGS(5); /* R_E */
28347 +#else
28348 + rodata PT_LOAD FLAGS(4); /* R__ */
28349 +#endif
28350 data PT_LOAD FLAGS(6); /* RW_ */
28351 -#ifdef CONFIG_X86_64
28352 + init.begin PT_LOAD FLAGS(6); /* RW_ */
28353 #ifdef CONFIG_SMP
28354 percpu PT_LOAD FLAGS(6); /* RW_ */
28355 #endif
28356 + text.init PT_LOAD FLAGS(5); /* R_E */
28357 + text.exit PT_LOAD FLAGS(5); /* R_E */
28358 init PT_LOAD FLAGS(7); /* RWE */
28359 -#endif
28360 note PT_NOTE FLAGS(0); /* ___ */
28361 }
28362
28363 SECTIONS
28364 {
28365 #ifdef CONFIG_X86_32
28366 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
28367 - phys_startup_32 = startup_32 - LOAD_OFFSET;
28368 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
28369 #else
28370 - . = __START_KERNEL;
28371 - phys_startup_64 = startup_64 - LOAD_OFFSET;
28372 + . = __START_KERNEL;
28373 #endif
28374
28375 /* Text and read-only data */
28376 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
28377 - _text = .;
28378 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
28379 /* bootstrapping code */
28380 +#ifdef CONFIG_X86_32
28381 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28382 +#else
28383 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28384 +#endif
28385 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28386 + _text = .;
28387 HEAD_TEXT
28388 . = ALIGN(8);
28389 _stext = .;
28390 @@ -104,13 +124,47 @@ SECTIONS
28391 IRQENTRY_TEXT
28392 *(.fixup)
28393 *(.gnu.warning)
28394 - /* End of text section */
28395 - _etext = .;
28396 } :text = 0x9090
28397
28398 - NOTES :text :note
28399 + . += __KERNEL_TEXT_OFFSET;
28400
28401 - EXCEPTION_TABLE(16) :text = 0x9090
28402 +#ifdef CONFIG_X86_32
28403 + . = ALIGN(PAGE_SIZE);
28404 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
28405 +
28406 +#ifdef CONFIG_PAX_KERNEXEC
28407 + MODULES_EXEC_VADDR = .;
28408 + BYTE(0)
28409 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
28410 + . = ALIGN(HPAGE_SIZE) - 1;
28411 + MODULES_EXEC_END = .;
28412 +#endif
28413 +
28414 + } :module
28415 +#endif
28416 +
28417 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
28418 + /* End of text section */
28419 + BYTE(0)
28420 + _etext = . - __KERNEL_TEXT_OFFSET;
28421 + }
28422 +
28423 +#ifdef CONFIG_X86_32
28424 + . = ALIGN(PAGE_SIZE);
28425 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
28426 + . = ALIGN(PAGE_SIZE);
28427 + *(.empty_zero_page)
28428 + *(.initial_pg_fixmap)
28429 + *(.initial_pg_pmd)
28430 + *(.initial_page_table)
28431 + *(.swapper_pg_dir)
28432 + } :rodata
28433 +#endif
28434 +
28435 + . = ALIGN(PAGE_SIZE);
28436 + NOTES :rodata :note
28437 +
28438 + EXCEPTION_TABLE(16) :rodata
28439
28440 #if defined(CONFIG_DEBUG_RODATA)
28441 /* .text should occupy whole number of pages */
28442 @@ -122,16 +176,20 @@ SECTIONS
28443
28444 /* Data */
28445 .data : AT(ADDR(.data) - LOAD_OFFSET) {
28446 +
28447 +#ifdef CONFIG_PAX_KERNEXEC
28448 + . = ALIGN(HPAGE_SIZE);
28449 +#else
28450 + . = ALIGN(PAGE_SIZE);
28451 +#endif
28452 +
28453 /* Start of data section */
28454 _sdata = .;
28455
28456 /* init_task */
28457 INIT_TASK_DATA(THREAD_SIZE)
28458
28459 -#ifdef CONFIG_X86_32
28460 - /* 32 bit has nosave before _edata */
28461 NOSAVE_DATA
28462 -#endif
28463
28464 PAGE_ALIGNED_DATA(PAGE_SIZE)
28465
28466 @@ -174,12 +232,19 @@ SECTIONS
28467 . = ALIGN(__vvar_page + PAGE_SIZE, PAGE_SIZE);
28468
28469 /* Init code and data - will be freed after init */
28470 - . = ALIGN(PAGE_SIZE);
28471 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
28472 + BYTE(0)
28473 +
28474 +#ifdef CONFIG_PAX_KERNEXEC
28475 + . = ALIGN(HPAGE_SIZE);
28476 +#else
28477 + . = ALIGN(PAGE_SIZE);
28478 +#endif
28479 +
28480 __init_begin = .; /* paired with __init_end */
28481 - }
28482 + } :init.begin
28483
28484 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
28485 +#ifdef CONFIG_SMP
28486 /*
28487 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
28488 * output PHDR, so the next output section - .init.text - should
28489 @@ -188,12 +253,27 @@ SECTIONS
28490 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
28491 #endif
28492
28493 - INIT_TEXT_SECTION(PAGE_SIZE)
28494 -#ifdef CONFIG_X86_64
28495 - :init
28496 -#endif
28497 + . = ALIGN(PAGE_SIZE);
28498 + init_begin = .;
28499 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
28500 + VMLINUX_SYMBOL(_sinittext) = .;
28501 + INIT_TEXT
28502 + VMLINUX_SYMBOL(_einittext) = .;
28503 + . = ALIGN(PAGE_SIZE);
28504 + } :text.init
28505
28506 - INIT_DATA_SECTION(16)
28507 + /*
28508 + * .exit.text is discard at runtime, not link time, to deal with
28509 + * references from .altinstructions and .eh_frame
28510 + */
28511 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
28512 + EXIT_TEXT
28513 + . = ALIGN(16);
28514 + } :text.exit
28515 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
28516 +
28517 + . = ALIGN(PAGE_SIZE);
28518 + INIT_DATA_SECTION(16) :init
28519
28520 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
28521 __x86_cpu_dev_start = .;
28522 @@ -264,19 +344,12 @@ SECTIONS
28523 }
28524
28525 . = ALIGN(8);
28526 - /*
28527 - * .exit.text is discard at runtime, not link time, to deal with
28528 - * references from .altinstructions and .eh_frame
28529 - */
28530 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
28531 - EXIT_TEXT
28532 - }
28533
28534 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
28535 EXIT_DATA
28536 }
28537
28538 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
28539 +#ifndef CONFIG_SMP
28540 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
28541 #endif
28542
28543 @@ -295,16 +368,10 @@ SECTIONS
28544 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
28545 __smp_locks = .;
28546 *(.smp_locks)
28547 - . = ALIGN(PAGE_SIZE);
28548 __smp_locks_end = .;
28549 + . = ALIGN(PAGE_SIZE);
28550 }
28551
28552 -#ifdef CONFIG_X86_64
28553 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
28554 - NOSAVE_DATA
28555 - }
28556 -#endif
28557 -
28558 /* BSS */
28559 . = ALIGN(PAGE_SIZE);
28560 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
28561 @@ -320,6 +387,7 @@ SECTIONS
28562 __brk_base = .;
28563 . += 64 * 1024; /* 64k alignment slop space */
28564 *(.brk_reservation) /* areas brk users have reserved */
28565 + . = ALIGN(HPAGE_SIZE);
28566 __brk_limit = .;
28567 }
28568
28569 @@ -346,13 +414,12 @@ SECTIONS
28570 * for the boot processor.
28571 */
28572 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
28573 -INIT_PER_CPU(gdt_page);
28574 INIT_PER_CPU(irq_stack_union);
28575
28576 /*
28577 * Build-time check on the image size:
28578 */
28579 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
28580 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
28581 "kernel image bigger than KERNEL_IMAGE_SIZE");
28582
28583 #ifdef CONFIG_SMP
28584 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
28585 index ea5b570..960e4da 100644
28586 --- a/arch/x86/kernel/vsyscall_64.c
28587 +++ b/arch/x86/kernel/vsyscall_64.c
28588 @@ -54,15 +54,13 @@
28589
28590 DEFINE_VVAR(int, vgetcpu_mode);
28591
28592 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
28593 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
28594
28595 static int __init vsyscall_setup(char *str)
28596 {
28597 if (str) {
28598 if (!strcmp("emulate", str))
28599 vsyscall_mode = EMULATE;
28600 - else if (!strcmp("native", str))
28601 - vsyscall_mode = NATIVE;
28602 else if (!strcmp("none", str))
28603 vsyscall_mode = NONE;
28604 else
28605 @@ -279,8 +277,7 @@ do_ret:
28606 return true;
28607
28608 sigsegv:
28609 - force_sig(SIGSEGV, current);
28610 - return true;
28611 + do_group_exit(SIGKILL);
28612 }
28613
28614 /*
28615 @@ -331,10 +328,7 @@ void __init map_vsyscall(void)
28616 extern char __vsyscall_page;
28617 unsigned long physaddr_vsyscall = __pa_symbol(&__vsyscall_page);
28618
28619 - __set_fixmap(VSYSCALL_PAGE, physaddr_vsyscall,
28620 - vsyscall_mode == NATIVE
28621 - ? PAGE_KERNEL_VSYSCALL
28622 - : PAGE_KERNEL_VVAR);
28623 + __set_fixmap(VSYSCALL_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
28624 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_PAGE) !=
28625 (unsigned long)VSYSCALL_ADDR);
28626 }
28627 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
28628 index 04068192..4d75aa6 100644
28629 --- a/arch/x86/kernel/x8664_ksyms_64.c
28630 +++ b/arch/x86/kernel/x8664_ksyms_64.c
28631 @@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
28632 EXPORT_SYMBOL(copy_user_generic_unrolled);
28633 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
28634 EXPORT_SYMBOL(__copy_user_nocache);
28635 -EXPORT_SYMBOL(_copy_from_user);
28636 -EXPORT_SYMBOL(_copy_to_user);
28637
28638 EXPORT_SYMBOL(copy_page);
28639 EXPORT_SYMBOL(clear_page);
28640 @@ -73,3 +71,7 @@ EXPORT_SYMBOL(___preempt_schedule);
28641 EXPORT_SYMBOL(___preempt_schedule_context);
28642 #endif
28643 #endif
28644 +
28645 +#ifdef CONFIG_PAX_PER_CPU_PGD
28646 +EXPORT_SYMBOL(cpu_pgd);
28647 +#endif
28648 diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
28649 index e48b674..a451dd9 100644
28650 --- a/arch/x86/kernel/x86_init.c
28651 +++ b/arch/x86/kernel/x86_init.c
28652 @@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
28653 static void default_nmi_init(void) { };
28654 static int default_i8042_detect(void) { return 1; };
28655
28656 -struct x86_platform_ops x86_platform = {
28657 +struct x86_platform_ops x86_platform __read_only = {
28658 .calibrate_tsc = native_calibrate_tsc,
28659 .get_wallclock = mach_get_cmos_time,
28660 .set_wallclock = mach_set_rtc_mmss,
28661 @@ -109,7 +109,7 @@ struct x86_platform_ops x86_platform = {
28662 EXPORT_SYMBOL_GPL(x86_platform);
28663
28664 #if defined(CONFIG_PCI_MSI)
28665 -struct x86_msi_ops x86_msi = {
28666 +struct x86_msi_ops x86_msi __read_only = {
28667 .setup_msi_irqs = native_setup_msi_irqs,
28668 .compose_msi_msg = native_compose_msi_msg,
28669 .teardown_msi_irq = native_teardown_msi_irq,
28670 @@ -150,7 +150,7 @@ u32 arch_msix_mask_irq(struct msi_desc *desc, u32 flag)
28671 }
28672 #endif
28673
28674 -struct x86_io_apic_ops x86_io_apic_ops = {
28675 +struct x86_io_apic_ops x86_io_apic_ops __read_only = {
28676 .init = native_io_apic_init_mappings,
28677 .read = native_io_apic_read,
28678 .write = native_io_apic_write,
28679 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
28680 index a4b451c..8dfe1ad 100644
28681 --- a/arch/x86/kernel/xsave.c
28682 +++ b/arch/x86/kernel/xsave.c
28683 @@ -164,18 +164,18 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28684
28685 /* Setup the bytes not touched by the [f]xsave and reserved for SW. */
28686 sw_bytes = ia32_frame ? &fx_sw_reserved_ia32 : &fx_sw_reserved;
28687 - err = __copy_to_user(&x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
28688 + err = __copy_to_user(x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
28689
28690 if (!use_xsave())
28691 return err;
28692
28693 - err |= __put_user(FP_XSTATE_MAGIC2, (__u32 *)(buf + xstate_size));
28694 + err |= __put_user(FP_XSTATE_MAGIC2, (__u32 __user *)(buf + xstate_size));
28695
28696 /*
28697 * Read the xstate_bv which we copied (directly from the cpu or
28698 * from the state in task struct) to the user buffers.
28699 */
28700 - err |= __get_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28701 + err |= __get_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28702
28703 /*
28704 * For legacy compatible, we always set FP/SSE bits in the bit
28705 @@ -190,7 +190,7 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28706 */
28707 xstate_bv |= XSTATE_FPSSE;
28708
28709 - err |= __put_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28710 + err |= __put_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28711
28712 return err;
28713 }
28714 @@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
28715 {
28716 int err;
28717
28718 + buf = (struct xsave_struct __user *)____m(buf);
28719 if (use_xsave())
28720 err = xsave_user(buf);
28721 else if (use_fxsr())
28722 @@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
28723 */
28724 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
28725 {
28726 + buf = (void __user *)____m(buf);
28727 if (use_xsave()) {
28728 if ((unsigned long)buf % 64 || fx_only) {
28729 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
28730 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
28731 index 38a0afe..94421a9 100644
28732 --- a/arch/x86/kvm/cpuid.c
28733 +++ b/arch/x86/kvm/cpuid.c
28734 @@ -166,15 +166,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
28735 struct kvm_cpuid2 *cpuid,
28736 struct kvm_cpuid_entry2 __user *entries)
28737 {
28738 - int r;
28739 + int r, i;
28740
28741 r = -E2BIG;
28742 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
28743 goto out;
28744 r = -EFAULT;
28745 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
28746 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28747 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28748 goto out;
28749 + for (i = 0; i < cpuid->nent; ++i) {
28750 + struct kvm_cpuid_entry2 cpuid_entry;
28751 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
28752 + goto out;
28753 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
28754 + }
28755 vcpu->arch.cpuid_nent = cpuid->nent;
28756 kvm_apic_set_version(vcpu);
28757 kvm_x86_ops->cpuid_update(vcpu);
28758 @@ -189,15 +194,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
28759 struct kvm_cpuid2 *cpuid,
28760 struct kvm_cpuid_entry2 __user *entries)
28761 {
28762 - int r;
28763 + int r, i;
28764
28765 r = -E2BIG;
28766 if (cpuid->nent < vcpu->arch.cpuid_nent)
28767 goto out;
28768 r = -EFAULT;
28769 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
28770 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28771 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28772 goto out;
28773 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
28774 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
28775 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
28776 + goto out;
28777 + }
28778 return 0;
28779
28780 out:
28781 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
28782 index 0069118..c28ec0a 100644
28783 --- a/arch/x86/kvm/lapic.c
28784 +++ b/arch/x86/kvm/lapic.c
28785 @@ -55,7 +55,7 @@
28786 #define APIC_BUS_CYCLE_NS 1
28787
28788 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
28789 -#define apic_debug(fmt, arg...)
28790 +#define apic_debug(fmt, arg...) do {} while (0)
28791
28792 #define APIC_LVT_NUM 6
28793 /* 14 is the version for Xeon and Pentium 8.4.8*/
28794 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
28795 index 4107765..d9eb358 100644
28796 --- a/arch/x86/kvm/paging_tmpl.h
28797 +++ b/arch/x86/kvm/paging_tmpl.h
28798 @@ -331,7 +331,7 @@ retry_walk:
28799 if (unlikely(kvm_is_error_hva(host_addr)))
28800 goto error;
28801
28802 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
28803 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
28804 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
28805 goto error;
28806 walker->ptep_user[walker->level - 1] = ptep_user;
28807 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
28808 index b5e994a..35b5866 100644
28809 --- a/arch/x86/kvm/svm.c
28810 +++ b/arch/x86/kvm/svm.c
28811 @@ -3541,7 +3541,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
28812 int cpu = raw_smp_processor_id();
28813
28814 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
28815 +
28816 + pax_open_kernel();
28817 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
28818 + pax_close_kernel();
28819 +
28820 load_TR_desc();
28821 }
28822
28823 @@ -3942,6 +3946,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
28824 #endif
28825 #endif
28826
28827 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28828 + __set_fs(current_thread_info()->addr_limit);
28829 +#endif
28830 +
28831 reload_tss(vcpu);
28832
28833 local_irq_disable();
28834 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
28835 index 801332e..eeff1cc 100644
28836 --- a/arch/x86/kvm/vmx.c
28837 +++ b/arch/x86/kvm/vmx.c
28838 @@ -1339,12 +1339,12 @@ static void vmcs_write64(unsigned long field, u64 value)
28839 #endif
28840 }
28841
28842 -static void vmcs_clear_bits(unsigned long field, u32 mask)
28843 +static void vmcs_clear_bits(unsigned long field, unsigned long mask)
28844 {
28845 vmcs_writel(field, vmcs_readl(field) & ~mask);
28846 }
28847
28848 -static void vmcs_set_bits(unsigned long field, u32 mask)
28849 +static void vmcs_set_bits(unsigned long field, unsigned long mask)
28850 {
28851 vmcs_writel(field, vmcs_readl(field) | mask);
28852 }
28853 @@ -1604,7 +1604,11 @@ static void reload_tss(void)
28854 struct desc_struct *descs;
28855
28856 descs = (void *)gdt->address;
28857 +
28858 + pax_open_kernel();
28859 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
28860 + pax_close_kernel();
28861 +
28862 load_TR_desc();
28863 }
28864
28865 @@ -1832,6 +1836,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
28866 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
28867 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
28868
28869 +#ifdef CONFIG_PAX_PER_CPU_PGD
28870 + vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28871 +#endif
28872 +
28873 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
28874 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
28875 vmx->loaded_vmcs->cpu = cpu;
28876 @@ -2121,7 +2129,7 @@ static void setup_msrs(struct vcpu_vmx *vmx)
28877 * reads and returns guest's timestamp counter "register"
28878 * guest_tsc = host_tsc + tsc_offset -- 21.3
28879 */
28880 -static u64 guest_read_tsc(void)
28881 +static u64 __intentional_overflow(-1) guest_read_tsc(void)
28882 {
28883 u64 host_tsc, tsc_offset;
28884
28885 @@ -3093,8 +3101,11 @@ static __init int hardware_setup(void)
28886 if (!cpu_has_vmx_flexpriority())
28887 flexpriority_enabled = 0;
28888
28889 - if (!cpu_has_vmx_tpr_shadow())
28890 - kvm_x86_ops->update_cr8_intercept = NULL;
28891 + if (!cpu_has_vmx_tpr_shadow()) {
28892 + pax_open_kernel();
28893 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28894 + pax_close_kernel();
28895 + }
28896
28897 if (enable_ept && !cpu_has_vmx_ept_2m_page())
28898 kvm_disable_largepages();
28899 @@ -3105,13 +3116,15 @@ static __init int hardware_setup(void)
28900 if (!cpu_has_vmx_apicv())
28901 enable_apicv = 0;
28902
28903 + pax_open_kernel();
28904 if (enable_apicv)
28905 - kvm_x86_ops->update_cr8_intercept = NULL;
28906 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28907 else {
28908 - kvm_x86_ops->hwapic_irr_update = NULL;
28909 - kvm_x86_ops->deliver_posted_interrupt = NULL;
28910 - kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28911 + *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
28912 + *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
28913 + *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28914 }
28915 + pax_close_kernel();
28916
28917 if (nested)
28918 nested_vmx_setup_ctls_msrs();
28919 @@ -4221,7 +4234,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28920
28921 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
28922 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
28923 +
28924 +#ifndef CONFIG_PAX_PER_CPU_PGD
28925 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28926 +#endif
28927
28928 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
28929 #ifdef CONFIG_X86_64
28930 @@ -4243,7 +4259,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28931 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
28932 vmx->host_idt_base = dt.address;
28933
28934 - vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
28935 + vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
28936
28937 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
28938 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
28939 @@ -7413,6 +7429,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28940 "jmp 2f \n\t"
28941 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
28942 "2: "
28943 +
28944 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28945 + "ljmp %[cs],$3f\n\t"
28946 + "3: "
28947 +#endif
28948 +
28949 /* Save guest registers, load host registers, keep flags */
28950 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
28951 "pop %0 \n\t"
28952 @@ -7465,6 +7487,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28953 #endif
28954 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
28955 [wordsize]"i"(sizeof(ulong))
28956 +
28957 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28958 + ,[cs]"i"(__KERNEL_CS)
28959 +#endif
28960 +
28961 : "cc", "memory"
28962 #ifdef CONFIG_X86_64
28963 , "rax", "rbx", "rdi", "rsi"
28964 @@ -7478,7 +7505,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28965 if (debugctlmsr)
28966 update_debugctlmsr(debugctlmsr);
28967
28968 -#ifndef CONFIG_X86_64
28969 +#ifdef CONFIG_X86_32
28970 /*
28971 * The sysexit path does not restore ds/es, so we must set them to
28972 * a reasonable value ourselves.
28973 @@ -7487,8 +7514,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28974 * may be executed in interrupt context, which saves and restore segments
28975 * around it, nullifying its effect.
28976 */
28977 - loadsegment(ds, __USER_DS);
28978 - loadsegment(es, __USER_DS);
28979 + loadsegment(ds, __KERNEL_DS);
28980 + loadsegment(es, __KERNEL_DS);
28981 + loadsegment(ss, __KERNEL_DS);
28982 +
28983 +#ifdef CONFIG_PAX_KERNEXEC
28984 + loadsegment(fs, __KERNEL_PERCPU);
28985 +#endif
28986 +
28987 +#ifdef CONFIG_PAX_MEMORY_UDEREF
28988 + __set_fs(current_thread_info()->addr_limit);
28989 +#endif
28990 +
28991 #endif
28992
28993 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
28994 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
28995 index ef432f8..a630659 100644
28996 --- a/arch/x86/kvm/x86.c
28997 +++ b/arch/x86/kvm/x86.c
28998 @@ -1808,8 +1808,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
28999 {
29000 struct kvm *kvm = vcpu->kvm;
29001 int lm = is_long_mode(vcpu);
29002 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
29003 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
29004 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
29005 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
29006 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
29007 : kvm->arch.xen_hvm_config.blob_size_32;
29008 u32 page_num = data & ~PAGE_MASK;
29009 @@ -2729,6 +2729,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
29010 if (n < msr_list.nmsrs)
29011 goto out;
29012 r = -EFAULT;
29013 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
29014 + goto out;
29015 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
29016 num_msrs_to_save * sizeof(u32)))
29017 goto out;
29018 @@ -5567,7 +5569,7 @@ static struct notifier_block pvclock_gtod_notifier = {
29019 };
29020 #endif
29021
29022 -int kvm_arch_init(void *opaque)
29023 +int kvm_arch_init(const void *opaque)
29024 {
29025 int r;
29026 struct kvm_x86_ops *ops = opaque;
29027 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
29028 index aae9413..d11e829 100644
29029 --- a/arch/x86/lguest/boot.c
29030 +++ b/arch/x86/lguest/boot.c
29031 @@ -1206,9 +1206,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
29032 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
29033 * Launcher to reboot us.
29034 */
29035 -static void lguest_restart(char *reason)
29036 +static __noreturn void lguest_restart(char *reason)
29037 {
29038 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
29039 + BUG();
29040 }
29041
29042 /*G:050
29043 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
29044 index 00933d5..3a64af9 100644
29045 --- a/arch/x86/lib/atomic64_386_32.S
29046 +++ b/arch/x86/lib/atomic64_386_32.S
29047 @@ -48,6 +48,10 @@ BEGIN(read)
29048 movl (v), %eax
29049 movl 4(v), %edx
29050 RET_ENDP
29051 +BEGIN(read_unchecked)
29052 + movl (v), %eax
29053 + movl 4(v), %edx
29054 +RET_ENDP
29055 #undef v
29056
29057 #define v %esi
29058 @@ -55,6 +59,10 @@ BEGIN(set)
29059 movl %ebx, (v)
29060 movl %ecx, 4(v)
29061 RET_ENDP
29062 +BEGIN(set_unchecked)
29063 + movl %ebx, (v)
29064 + movl %ecx, 4(v)
29065 +RET_ENDP
29066 #undef v
29067
29068 #define v %esi
29069 @@ -70,6 +78,20 @@ RET_ENDP
29070 BEGIN(add)
29071 addl %eax, (v)
29072 adcl %edx, 4(v)
29073 +
29074 +#ifdef CONFIG_PAX_REFCOUNT
29075 + jno 0f
29076 + subl %eax, (v)
29077 + sbbl %edx, 4(v)
29078 + int $4
29079 +0:
29080 + _ASM_EXTABLE(0b, 0b)
29081 +#endif
29082 +
29083 +RET_ENDP
29084 +BEGIN(add_unchecked)
29085 + addl %eax, (v)
29086 + adcl %edx, 4(v)
29087 RET_ENDP
29088 #undef v
29089
29090 @@ -77,6 +99,24 @@ RET_ENDP
29091 BEGIN(add_return)
29092 addl (v), %eax
29093 adcl 4(v), %edx
29094 +
29095 +#ifdef CONFIG_PAX_REFCOUNT
29096 + into
29097 +1234:
29098 + _ASM_EXTABLE(1234b, 2f)
29099 +#endif
29100 +
29101 + movl %eax, (v)
29102 + movl %edx, 4(v)
29103 +
29104 +#ifdef CONFIG_PAX_REFCOUNT
29105 +2:
29106 +#endif
29107 +
29108 +RET_ENDP
29109 +BEGIN(add_return_unchecked)
29110 + addl (v), %eax
29111 + adcl 4(v), %edx
29112 movl %eax, (v)
29113 movl %edx, 4(v)
29114 RET_ENDP
29115 @@ -86,6 +126,20 @@ RET_ENDP
29116 BEGIN(sub)
29117 subl %eax, (v)
29118 sbbl %edx, 4(v)
29119 +
29120 +#ifdef CONFIG_PAX_REFCOUNT
29121 + jno 0f
29122 + addl %eax, (v)
29123 + adcl %edx, 4(v)
29124 + int $4
29125 +0:
29126 + _ASM_EXTABLE(0b, 0b)
29127 +#endif
29128 +
29129 +RET_ENDP
29130 +BEGIN(sub_unchecked)
29131 + subl %eax, (v)
29132 + sbbl %edx, 4(v)
29133 RET_ENDP
29134 #undef v
29135
29136 @@ -96,6 +150,27 @@ BEGIN(sub_return)
29137 sbbl $0, %edx
29138 addl (v), %eax
29139 adcl 4(v), %edx
29140 +
29141 +#ifdef CONFIG_PAX_REFCOUNT
29142 + into
29143 +1234:
29144 + _ASM_EXTABLE(1234b, 2f)
29145 +#endif
29146 +
29147 + movl %eax, (v)
29148 + movl %edx, 4(v)
29149 +
29150 +#ifdef CONFIG_PAX_REFCOUNT
29151 +2:
29152 +#endif
29153 +
29154 +RET_ENDP
29155 +BEGIN(sub_return_unchecked)
29156 + negl %edx
29157 + negl %eax
29158 + sbbl $0, %edx
29159 + addl (v), %eax
29160 + adcl 4(v), %edx
29161 movl %eax, (v)
29162 movl %edx, 4(v)
29163 RET_ENDP
29164 @@ -105,6 +180,20 @@ RET_ENDP
29165 BEGIN(inc)
29166 addl $1, (v)
29167 adcl $0, 4(v)
29168 +
29169 +#ifdef CONFIG_PAX_REFCOUNT
29170 + jno 0f
29171 + subl $1, (v)
29172 + sbbl $0, 4(v)
29173 + int $4
29174 +0:
29175 + _ASM_EXTABLE(0b, 0b)
29176 +#endif
29177 +
29178 +RET_ENDP
29179 +BEGIN(inc_unchecked)
29180 + addl $1, (v)
29181 + adcl $0, 4(v)
29182 RET_ENDP
29183 #undef v
29184
29185 @@ -114,6 +203,26 @@ BEGIN(inc_return)
29186 movl 4(v), %edx
29187 addl $1, %eax
29188 adcl $0, %edx
29189 +
29190 +#ifdef CONFIG_PAX_REFCOUNT
29191 + into
29192 +1234:
29193 + _ASM_EXTABLE(1234b, 2f)
29194 +#endif
29195 +
29196 + movl %eax, (v)
29197 + movl %edx, 4(v)
29198 +
29199 +#ifdef CONFIG_PAX_REFCOUNT
29200 +2:
29201 +#endif
29202 +
29203 +RET_ENDP
29204 +BEGIN(inc_return_unchecked)
29205 + movl (v), %eax
29206 + movl 4(v), %edx
29207 + addl $1, %eax
29208 + adcl $0, %edx
29209 movl %eax, (v)
29210 movl %edx, 4(v)
29211 RET_ENDP
29212 @@ -123,6 +232,20 @@ RET_ENDP
29213 BEGIN(dec)
29214 subl $1, (v)
29215 sbbl $0, 4(v)
29216 +
29217 +#ifdef CONFIG_PAX_REFCOUNT
29218 + jno 0f
29219 + addl $1, (v)
29220 + adcl $0, 4(v)
29221 + int $4
29222 +0:
29223 + _ASM_EXTABLE(0b, 0b)
29224 +#endif
29225 +
29226 +RET_ENDP
29227 +BEGIN(dec_unchecked)
29228 + subl $1, (v)
29229 + sbbl $0, 4(v)
29230 RET_ENDP
29231 #undef v
29232
29233 @@ -132,6 +255,26 @@ BEGIN(dec_return)
29234 movl 4(v), %edx
29235 subl $1, %eax
29236 sbbl $0, %edx
29237 +
29238 +#ifdef CONFIG_PAX_REFCOUNT
29239 + into
29240 +1234:
29241 + _ASM_EXTABLE(1234b, 2f)
29242 +#endif
29243 +
29244 + movl %eax, (v)
29245 + movl %edx, 4(v)
29246 +
29247 +#ifdef CONFIG_PAX_REFCOUNT
29248 +2:
29249 +#endif
29250 +
29251 +RET_ENDP
29252 +BEGIN(dec_return_unchecked)
29253 + movl (v), %eax
29254 + movl 4(v), %edx
29255 + subl $1, %eax
29256 + sbbl $0, %edx
29257 movl %eax, (v)
29258 movl %edx, 4(v)
29259 RET_ENDP
29260 @@ -143,6 +286,13 @@ BEGIN(add_unless)
29261 adcl %edx, %edi
29262 addl (v), %eax
29263 adcl 4(v), %edx
29264 +
29265 +#ifdef CONFIG_PAX_REFCOUNT
29266 + into
29267 +1234:
29268 + _ASM_EXTABLE(1234b, 2f)
29269 +#endif
29270 +
29271 cmpl %eax, %ecx
29272 je 3f
29273 1:
29274 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
29275 1:
29276 addl $1, %eax
29277 adcl $0, %edx
29278 +
29279 +#ifdef CONFIG_PAX_REFCOUNT
29280 + into
29281 +1234:
29282 + _ASM_EXTABLE(1234b, 2f)
29283 +#endif
29284 +
29285 movl %eax, (v)
29286 movl %edx, 4(v)
29287 movl $1, %eax
29288 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
29289 movl 4(v), %edx
29290 subl $1, %eax
29291 sbbl $0, %edx
29292 +
29293 +#ifdef CONFIG_PAX_REFCOUNT
29294 + into
29295 +1234:
29296 + _ASM_EXTABLE(1234b, 1f)
29297 +#endif
29298 +
29299 js 1f
29300 movl %eax, (v)
29301 movl %edx, 4(v)
29302 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
29303 index f5cc9eb..51fa319 100644
29304 --- a/arch/x86/lib/atomic64_cx8_32.S
29305 +++ b/arch/x86/lib/atomic64_cx8_32.S
29306 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
29307 CFI_STARTPROC
29308
29309 read64 %ecx
29310 + pax_force_retaddr
29311 ret
29312 CFI_ENDPROC
29313 ENDPROC(atomic64_read_cx8)
29314
29315 +ENTRY(atomic64_read_unchecked_cx8)
29316 + CFI_STARTPROC
29317 +
29318 + read64 %ecx
29319 + pax_force_retaddr
29320 + ret
29321 + CFI_ENDPROC
29322 +ENDPROC(atomic64_read_unchecked_cx8)
29323 +
29324 ENTRY(atomic64_set_cx8)
29325 CFI_STARTPROC
29326
29327 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
29328 cmpxchg8b (%esi)
29329 jne 1b
29330
29331 + pax_force_retaddr
29332 ret
29333 CFI_ENDPROC
29334 ENDPROC(atomic64_set_cx8)
29335
29336 +ENTRY(atomic64_set_unchecked_cx8)
29337 + CFI_STARTPROC
29338 +
29339 +1:
29340 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
29341 + * are atomic on 586 and newer */
29342 + cmpxchg8b (%esi)
29343 + jne 1b
29344 +
29345 + pax_force_retaddr
29346 + ret
29347 + CFI_ENDPROC
29348 +ENDPROC(atomic64_set_unchecked_cx8)
29349 +
29350 ENTRY(atomic64_xchg_cx8)
29351 CFI_STARTPROC
29352
29353 @@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
29354 cmpxchg8b (%esi)
29355 jne 1b
29356
29357 + pax_force_retaddr
29358 ret
29359 CFI_ENDPROC
29360 ENDPROC(atomic64_xchg_cx8)
29361
29362 -.macro addsub_return func ins insc
29363 -ENTRY(atomic64_\func\()_return_cx8)
29364 +.macro addsub_return func ins insc unchecked=""
29365 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
29366 CFI_STARTPROC
29367 SAVE ebp
29368 SAVE ebx
29369 @@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
29370 movl %edx, %ecx
29371 \ins\()l %esi, %ebx
29372 \insc\()l %edi, %ecx
29373 +
29374 +.ifb \unchecked
29375 +#ifdef CONFIG_PAX_REFCOUNT
29376 + into
29377 +2:
29378 + _ASM_EXTABLE(2b, 3f)
29379 +#endif
29380 +.endif
29381 +
29382 LOCK_PREFIX
29383 cmpxchg8b (%ebp)
29384 jne 1b
29385 -
29386 -10:
29387 movl %ebx, %eax
29388 movl %ecx, %edx
29389 +
29390 +.ifb \unchecked
29391 +#ifdef CONFIG_PAX_REFCOUNT
29392 +3:
29393 +#endif
29394 +.endif
29395 +
29396 RESTORE edi
29397 RESTORE esi
29398 RESTORE ebx
29399 RESTORE ebp
29400 + pax_force_retaddr
29401 ret
29402 CFI_ENDPROC
29403 -ENDPROC(atomic64_\func\()_return_cx8)
29404 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
29405 .endm
29406
29407 addsub_return add add adc
29408 addsub_return sub sub sbb
29409 +addsub_return add add adc _unchecked
29410 +addsub_return sub sub sbb _unchecked
29411
29412 -.macro incdec_return func ins insc
29413 -ENTRY(atomic64_\func\()_return_cx8)
29414 +.macro incdec_return func ins insc unchecked=""
29415 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
29416 CFI_STARTPROC
29417 SAVE ebx
29418
29419 @@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
29420 movl %edx, %ecx
29421 \ins\()l $1, %ebx
29422 \insc\()l $0, %ecx
29423 +
29424 +.ifb \unchecked
29425 +#ifdef CONFIG_PAX_REFCOUNT
29426 + into
29427 +2:
29428 + _ASM_EXTABLE(2b, 3f)
29429 +#endif
29430 +.endif
29431 +
29432 LOCK_PREFIX
29433 cmpxchg8b (%esi)
29434 jne 1b
29435
29436 -10:
29437 movl %ebx, %eax
29438 movl %ecx, %edx
29439 +
29440 +.ifb \unchecked
29441 +#ifdef CONFIG_PAX_REFCOUNT
29442 +3:
29443 +#endif
29444 +.endif
29445 +
29446 RESTORE ebx
29447 + pax_force_retaddr
29448 ret
29449 CFI_ENDPROC
29450 -ENDPROC(atomic64_\func\()_return_cx8)
29451 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
29452 .endm
29453
29454 incdec_return inc add adc
29455 incdec_return dec sub sbb
29456 +incdec_return inc add adc _unchecked
29457 +incdec_return dec sub sbb _unchecked
29458
29459 ENTRY(atomic64_dec_if_positive_cx8)
29460 CFI_STARTPROC
29461 @@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
29462 movl %edx, %ecx
29463 subl $1, %ebx
29464 sbb $0, %ecx
29465 +
29466 +#ifdef CONFIG_PAX_REFCOUNT
29467 + into
29468 +1234:
29469 + _ASM_EXTABLE(1234b, 2f)
29470 +#endif
29471 +
29472 js 2f
29473 LOCK_PREFIX
29474 cmpxchg8b (%esi)
29475 @@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
29476 movl %ebx, %eax
29477 movl %ecx, %edx
29478 RESTORE ebx
29479 + pax_force_retaddr
29480 ret
29481 CFI_ENDPROC
29482 ENDPROC(atomic64_dec_if_positive_cx8)
29483 @@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
29484 movl %edx, %ecx
29485 addl %ebp, %ebx
29486 adcl %edi, %ecx
29487 +
29488 +#ifdef CONFIG_PAX_REFCOUNT
29489 + into
29490 +1234:
29491 + _ASM_EXTABLE(1234b, 3f)
29492 +#endif
29493 +
29494 LOCK_PREFIX
29495 cmpxchg8b (%esi)
29496 jne 1b
29497 @@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
29498 CFI_ADJUST_CFA_OFFSET -8
29499 RESTORE ebx
29500 RESTORE ebp
29501 + pax_force_retaddr
29502 ret
29503 4:
29504 cmpl %edx, 4(%esp)
29505 @@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
29506 xorl %ecx, %ecx
29507 addl $1, %ebx
29508 adcl %edx, %ecx
29509 +
29510 +#ifdef CONFIG_PAX_REFCOUNT
29511 + into
29512 +1234:
29513 + _ASM_EXTABLE(1234b, 3f)
29514 +#endif
29515 +
29516 LOCK_PREFIX
29517 cmpxchg8b (%esi)
29518 jne 1b
29519 @@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
29520 movl $1, %eax
29521 3:
29522 RESTORE ebx
29523 + pax_force_retaddr
29524 ret
29525 CFI_ENDPROC
29526 ENDPROC(atomic64_inc_not_zero_cx8)
29527 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
29528 index e78b8ee..7e173a8 100644
29529 --- a/arch/x86/lib/checksum_32.S
29530 +++ b/arch/x86/lib/checksum_32.S
29531 @@ -29,7 +29,8 @@
29532 #include <asm/dwarf2.h>
29533 #include <asm/errno.h>
29534 #include <asm/asm.h>
29535 -
29536 +#include <asm/segment.h>
29537 +
29538 /*
29539 * computes a partial checksum, e.g. for TCP/UDP fragments
29540 */
29541 @@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
29542
29543 #define ARGBASE 16
29544 #define FP 12
29545 -
29546 -ENTRY(csum_partial_copy_generic)
29547 +
29548 +ENTRY(csum_partial_copy_generic_to_user)
29549 CFI_STARTPROC
29550 +
29551 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29552 + pushl_cfi %gs
29553 + popl_cfi %es
29554 + jmp csum_partial_copy_generic
29555 +#endif
29556 +
29557 +ENTRY(csum_partial_copy_generic_from_user)
29558 +
29559 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29560 + pushl_cfi %gs
29561 + popl_cfi %ds
29562 +#endif
29563 +
29564 +ENTRY(csum_partial_copy_generic)
29565 subl $4,%esp
29566 CFI_ADJUST_CFA_OFFSET 4
29567 pushl_cfi %edi
29568 @@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
29569 jmp 4f
29570 SRC(1: movw (%esi), %bx )
29571 addl $2, %esi
29572 -DST( movw %bx, (%edi) )
29573 +DST( movw %bx, %es:(%edi) )
29574 addl $2, %edi
29575 addw %bx, %ax
29576 adcl $0, %eax
29577 @@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
29578 SRC(1: movl (%esi), %ebx )
29579 SRC( movl 4(%esi), %edx )
29580 adcl %ebx, %eax
29581 -DST( movl %ebx, (%edi) )
29582 +DST( movl %ebx, %es:(%edi) )
29583 adcl %edx, %eax
29584 -DST( movl %edx, 4(%edi) )
29585 +DST( movl %edx, %es:4(%edi) )
29586
29587 SRC( movl 8(%esi), %ebx )
29588 SRC( movl 12(%esi), %edx )
29589 adcl %ebx, %eax
29590 -DST( movl %ebx, 8(%edi) )
29591 +DST( movl %ebx, %es:8(%edi) )
29592 adcl %edx, %eax
29593 -DST( movl %edx, 12(%edi) )
29594 +DST( movl %edx, %es:12(%edi) )
29595
29596 SRC( movl 16(%esi), %ebx )
29597 SRC( movl 20(%esi), %edx )
29598 adcl %ebx, %eax
29599 -DST( movl %ebx, 16(%edi) )
29600 +DST( movl %ebx, %es:16(%edi) )
29601 adcl %edx, %eax
29602 -DST( movl %edx, 20(%edi) )
29603 +DST( movl %edx, %es:20(%edi) )
29604
29605 SRC( movl 24(%esi), %ebx )
29606 SRC( movl 28(%esi), %edx )
29607 adcl %ebx, %eax
29608 -DST( movl %ebx, 24(%edi) )
29609 +DST( movl %ebx, %es:24(%edi) )
29610 adcl %edx, %eax
29611 -DST( movl %edx, 28(%edi) )
29612 +DST( movl %edx, %es:28(%edi) )
29613
29614 lea 32(%esi), %esi
29615 lea 32(%edi), %edi
29616 @@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
29617 shrl $2, %edx # This clears CF
29618 SRC(3: movl (%esi), %ebx )
29619 adcl %ebx, %eax
29620 -DST( movl %ebx, (%edi) )
29621 +DST( movl %ebx, %es:(%edi) )
29622 lea 4(%esi), %esi
29623 lea 4(%edi), %edi
29624 dec %edx
29625 @@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
29626 jb 5f
29627 SRC( movw (%esi), %cx )
29628 leal 2(%esi), %esi
29629 -DST( movw %cx, (%edi) )
29630 +DST( movw %cx, %es:(%edi) )
29631 leal 2(%edi), %edi
29632 je 6f
29633 shll $16,%ecx
29634 SRC(5: movb (%esi), %cl )
29635 -DST( movb %cl, (%edi) )
29636 +DST( movb %cl, %es:(%edi) )
29637 6: addl %ecx, %eax
29638 adcl $0, %eax
29639 7:
29640 @@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
29641
29642 6001:
29643 movl ARGBASE+20(%esp), %ebx # src_err_ptr
29644 - movl $-EFAULT, (%ebx)
29645 + movl $-EFAULT, %ss:(%ebx)
29646
29647 # zero the complete destination - computing the rest
29648 # is too much work
29649 @@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
29650
29651 6002:
29652 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29653 - movl $-EFAULT,(%ebx)
29654 + movl $-EFAULT,%ss:(%ebx)
29655 jmp 5000b
29656
29657 .previous
29658
29659 + pushl_cfi %ss
29660 + popl_cfi %ds
29661 + pushl_cfi %ss
29662 + popl_cfi %es
29663 popl_cfi %ebx
29664 CFI_RESTORE ebx
29665 popl_cfi %esi
29666 @@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
29667 popl_cfi %ecx # equivalent to addl $4,%esp
29668 ret
29669 CFI_ENDPROC
29670 -ENDPROC(csum_partial_copy_generic)
29671 +ENDPROC(csum_partial_copy_generic_to_user)
29672
29673 #else
29674
29675 /* Version for PentiumII/PPro */
29676
29677 #define ROUND1(x) \
29678 + nop; nop; nop; \
29679 SRC(movl x(%esi), %ebx ) ; \
29680 addl %ebx, %eax ; \
29681 - DST(movl %ebx, x(%edi) ) ;
29682 + DST(movl %ebx, %es:x(%edi)) ;
29683
29684 #define ROUND(x) \
29685 + nop; nop; nop; \
29686 SRC(movl x(%esi), %ebx ) ; \
29687 adcl %ebx, %eax ; \
29688 - DST(movl %ebx, x(%edi) ) ;
29689 + DST(movl %ebx, %es:x(%edi)) ;
29690
29691 #define ARGBASE 12
29692 -
29693 -ENTRY(csum_partial_copy_generic)
29694 +
29695 +ENTRY(csum_partial_copy_generic_to_user)
29696 CFI_STARTPROC
29697 +
29698 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29699 + pushl_cfi %gs
29700 + popl_cfi %es
29701 + jmp csum_partial_copy_generic
29702 +#endif
29703 +
29704 +ENTRY(csum_partial_copy_generic_from_user)
29705 +
29706 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29707 + pushl_cfi %gs
29708 + popl_cfi %ds
29709 +#endif
29710 +
29711 +ENTRY(csum_partial_copy_generic)
29712 pushl_cfi %ebx
29713 CFI_REL_OFFSET ebx, 0
29714 pushl_cfi %edi
29715 @@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
29716 subl %ebx, %edi
29717 lea -1(%esi),%edx
29718 andl $-32,%edx
29719 - lea 3f(%ebx,%ebx), %ebx
29720 + lea 3f(%ebx,%ebx,2), %ebx
29721 testl %esi, %esi
29722 jmp *%ebx
29723 1: addl $64,%esi
29724 @@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
29725 jb 5f
29726 SRC( movw (%esi), %dx )
29727 leal 2(%esi), %esi
29728 -DST( movw %dx, (%edi) )
29729 +DST( movw %dx, %es:(%edi) )
29730 leal 2(%edi), %edi
29731 je 6f
29732 shll $16,%edx
29733 5:
29734 SRC( movb (%esi), %dl )
29735 -DST( movb %dl, (%edi) )
29736 +DST( movb %dl, %es:(%edi) )
29737 6: addl %edx, %eax
29738 adcl $0, %eax
29739 7:
29740 .section .fixup, "ax"
29741 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
29742 - movl $-EFAULT, (%ebx)
29743 + movl $-EFAULT, %ss:(%ebx)
29744 # zero the complete destination (computing the rest is too much work)
29745 movl ARGBASE+8(%esp),%edi # dst
29746 movl ARGBASE+12(%esp),%ecx # len
29747 @@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
29748 rep; stosb
29749 jmp 7b
29750 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29751 - movl $-EFAULT, (%ebx)
29752 + movl $-EFAULT, %ss:(%ebx)
29753 jmp 7b
29754 .previous
29755
29756 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29757 + pushl_cfi %ss
29758 + popl_cfi %ds
29759 + pushl_cfi %ss
29760 + popl_cfi %es
29761 +#endif
29762 +
29763 popl_cfi %esi
29764 CFI_RESTORE esi
29765 popl_cfi %edi
29766 @@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
29767 CFI_RESTORE ebx
29768 ret
29769 CFI_ENDPROC
29770 -ENDPROC(csum_partial_copy_generic)
29771 +ENDPROC(csum_partial_copy_generic_to_user)
29772
29773 #undef ROUND
29774 #undef ROUND1
29775 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
29776 index f2145cf..cea889d 100644
29777 --- a/arch/x86/lib/clear_page_64.S
29778 +++ b/arch/x86/lib/clear_page_64.S
29779 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
29780 movl $4096/8,%ecx
29781 xorl %eax,%eax
29782 rep stosq
29783 + pax_force_retaddr
29784 ret
29785 CFI_ENDPROC
29786 ENDPROC(clear_page_c)
29787 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
29788 movl $4096,%ecx
29789 xorl %eax,%eax
29790 rep stosb
29791 + pax_force_retaddr
29792 ret
29793 CFI_ENDPROC
29794 ENDPROC(clear_page_c_e)
29795 @@ -43,6 +45,7 @@ ENTRY(clear_page)
29796 leaq 64(%rdi),%rdi
29797 jnz .Lloop
29798 nop
29799 + pax_force_retaddr
29800 ret
29801 CFI_ENDPROC
29802 .Lclear_page_end:
29803 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
29804
29805 #include <asm/cpufeature.h>
29806
29807 - .section .altinstr_replacement,"ax"
29808 + .section .altinstr_replacement,"a"
29809 1: .byte 0xeb /* jmp <disp8> */
29810 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
29811 2: .byte 0xeb /* jmp <disp8> */
29812 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
29813 index 1e572c5..2a162cd 100644
29814 --- a/arch/x86/lib/cmpxchg16b_emu.S
29815 +++ b/arch/x86/lib/cmpxchg16b_emu.S
29816 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
29817
29818 popf
29819 mov $1, %al
29820 + pax_force_retaddr
29821 ret
29822
29823 not_same:
29824 popf
29825 xor %al,%al
29826 + pax_force_retaddr
29827 ret
29828
29829 CFI_ENDPROC
29830 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
29831 index 176cca6..e0d658e 100644
29832 --- a/arch/x86/lib/copy_page_64.S
29833 +++ b/arch/x86/lib/copy_page_64.S
29834 @@ -9,6 +9,7 @@ copy_page_rep:
29835 CFI_STARTPROC
29836 movl $4096/8, %ecx
29837 rep movsq
29838 + pax_force_retaddr
29839 ret
29840 CFI_ENDPROC
29841 ENDPROC(copy_page_rep)
29842 @@ -24,8 +25,8 @@ ENTRY(copy_page)
29843 CFI_ADJUST_CFA_OFFSET 2*8
29844 movq %rbx, (%rsp)
29845 CFI_REL_OFFSET rbx, 0
29846 - movq %r12, 1*8(%rsp)
29847 - CFI_REL_OFFSET r12, 1*8
29848 + movq %r13, 1*8(%rsp)
29849 + CFI_REL_OFFSET r13, 1*8
29850
29851 movl $(4096/64)-5, %ecx
29852 .p2align 4
29853 @@ -38,7 +39,7 @@ ENTRY(copy_page)
29854 movq 0x8*4(%rsi), %r9
29855 movq 0x8*5(%rsi), %r10
29856 movq 0x8*6(%rsi), %r11
29857 - movq 0x8*7(%rsi), %r12
29858 + movq 0x8*7(%rsi), %r13
29859
29860 prefetcht0 5*64(%rsi)
29861
29862 @@ -49,7 +50,7 @@ ENTRY(copy_page)
29863 movq %r9, 0x8*4(%rdi)
29864 movq %r10, 0x8*5(%rdi)
29865 movq %r11, 0x8*6(%rdi)
29866 - movq %r12, 0x8*7(%rdi)
29867 + movq %r13, 0x8*7(%rdi)
29868
29869 leaq 64 (%rsi), %rsi
29870 leaq 64 (%rdi), %rdi
29871 @@ -68,7 +69,7 @@ ENTRY(copy_page)
29872 movq 0x8*4(%rsi), %r9
29873 movq 0x8*5(%rsi), %r10
29874 movq 0x8*6(%rsi), %r11
29875 - movq 0x8*7(%rsi), %r12
29876 + movq 0x8*7(%rsi), %r13
29877
29878 movq %rax, 0x8*0(%rdi)
29879 movq %rbx, 0x8*1(%rdi)
29880 @@ -77,7 +78,7 @@ ENTRY(copy_page)
29881 movq %r9, 0x8*4(%rdi)
29882 movq %r10, 0x8*5(%rdi)
29883 movq %r11, 0x8*6(%rdi)
29884 - movq %r12, 0x8*7(%rdi)
29885 + movq %r13, 0x8*7(%rdi)
29886
29887 leaq 64(%rdi), %rdi
29888 leaq 64(%rsi), %rsi
29889 @@ -85,10 +86,11 @@ ENTRY(copy_page)
29890
29891 movq (%rsp), %rbx
29892 CFI_RESTORE rbx
29893 - movq 1*8(%rsp), %r12
29894 - CFI_RESTORE r12
29895 + movq 1*8(%rsp), %r13
29896 + CFI_RESTORE r13
29897 addq $2*8, %rsp
29898 CFI_ADJUST_CFA_OFFSET -2*8
29899 + pax_force_retaddr
29900 ret
29901 .Lcopy_page_end:
29902 CFI_ENDPROC
29903 @@ -99,7 +101,7 @@ ENDPROC(copy_page)
29904
29905 #include <asm/cpufeature.h>
29906
29907 - .section .altinstr_replacement,"ax"
29908 + .section .altinstr_replacement,"a"
29909 1: .byte 0xeb /* jmp <disp8> */
29910 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
29911 2:
29912 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
29913 index dee945d..a84067b 100644
29914 --- a/arch/x86/lib/copy_user_64.S
29915 +++ b/arch/x86/lib/copy_user_64.S
29916 @@ -18,31 +18,7 @@
29917 #include <asm/alternative-asm.h>
29918 #include <asm/asm.h>
29919 #include <asm/smap.h>
29920 -
29921 -/*
29922 - * By placing feature2 after feature1 in altinstructions section, we logically
29923 - * implement:
29924 - * If CPU has feature2, jmp to alt2 is used
29925 - * else if CPU has feature1, jmp to alt1 is used
29926 - * else jmp to orig is used.
29927 - */
29928 - .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
29929 -0:
29930 - .byte 0xe9 /* 32bit jump */
29931 - .long \orig-1f /* by default jump to orig */
29932 -1:
29933 - .section .altinstr_replacement,"ax"
29934 -2: .byte 0xe9 /* near jump with 32bit immediate */
29935 - .long \alt1-1b /* offset */ /* or alternatively to alt1 */
29936 -3: .byte 0xe9 /* near jump with 32bit immediate */
29937 - .long \alt2-1b /* offset */ /* or alternatively to alt2 */
29938 - .previous
29939 -
29940 - .section .altinstructions,"a"
29941 - altinstruction_entry 0b,2b,\feature1,5,5
29942 - altinstruction_entry 0b,3b,\feature2,5,5
29943 - .previous
29944 - .endm
29945 +#include <asm/pgtable.h>
29946
29947 .macro ALIGN_DESTINATION
29948 #ifdef FIX_ALIGNMENT
29949 @@ -70,52 +46,6 @@
29950 #endif
29951 .endm
29952
29953 -/* Standard copy_to_user with segment limit checking */
29954 -ENTRY(_copy_to_user)
29955 - CFI_STARTPROC
29956 - GET_THREAD_INFO(%rax)
29957 - movq %rdi,%rcx
29958 - addq %rdx,%rcx
29959 - jc bad_to_user
29960 - cmpq TI_addr_limit(%rax),%rcx
29961 - ja bad_to_user
29962 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29963 - copy_user_generic_unrolled,copy_user_generic_string, \
29964 - copy_user_enhanced_fast_string
29965 - CFI_ENDPROC
29966 -ENDPROC(_copy_to_user)
29967 -
29968 -/* Standard copy_from_user with segment limit checking */
29969 -ENTRY(_copy_from_user)
29970 - CFI_STARTPROC
29971 - GET_THREAD_INFO(%rax)
29972 - movq %rsi,%rcx
29973 - addq %rdx,%rcx
29974 - jc bad_from_user
29975 - cmpq TI_addr_limit(%rax),%rcx
29976 - ja bad_from_user
29977 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29978 - copy_user_generic_unrolled,copy_user_generic_string, \
29979 - copy_user_enhanced_fast_string
29980 - CFI_ENDPROC
29981 -ENDPROC(_copy_from_user)
29982 -
29983 - .section .fixup,"ax"
29984 - /* must zero dest */
29985 -ENTRY(bad_from_user)
29986 -bad_from_user:
29987 - CFI_STARTPROC
29988 - movl %edx,%ecx
29989 - xorl %eax,%eax
29990 - rep
29991 - stosb
29992 -bad_to_user:
29993 - movl %edx,%eax
29994 - ret
29995 - CFI_ENDPROC
29996 -ENDPROC(bad_from_user)
29997 - .previous
29998 -
29999 /*
30000 * copy_user_generic_unrolled - memory copy with exception handling.
30001 * This version is for CPUs like P4 that don't have efficient micro
30002 @@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
30003 */
30004 ENTRY(copy_user_generic_unrolled)
30005 CFI_STARTPROC
30006 + ASM_PAX_OPEN_USERLAND
30007 ASM_STAC
30008 cmpl $8,%edx
30009 jb 20f /* less then 8 bytes, go to byte copy loop */
30010 @@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
30011 jnz 21b
30012 23: xor %eax,%eax
30013 ASM_CLAC
30014 + ASM_PAX_CLOSE_USERLAND
30015 + pax_force_retaddr
30016 ret
30017
30018 .section .fixup,"ax"
30019 @@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
30020 */
30021 ENTRY(copy_user_generic_string)
30022 CFI_STARTPROC
30023 + ASM_PAX_OPEN_USERLAND
30024 ASM_STAC
30025 cmpl $8,%edx
30026 jb 2f /* less than 8 bytes, go to byte copy loop */
30027 @@ -249,6 +183,8 @@ ENTRY(copy_user_generic_string)
30028 movsb
30029 xorl %eax,%eax
30030 ASM_CLAC
30031 + ASM_PAX_CLOSE_USERLAND
30032 + pax_force_retaddr
30033 ret
30034
30035 .section .fixup,"ax"
30036 @@ -276,12 +212,15 @@ ENDPROC(copy_user_generic_string)
30037 */
30038 ENTRY(copy_user_enhanced_fast_string)
30039 CFI_STARTPROC
30040 + ASM_PAX_OPEN_USERLAND
30041 ASM_STAC
30042 movl %edx,%ecx
30043 1: rep
30044 movsb
30045 xorl %eax,%eax
30046 ASM_CLAC
30047 + ASM_PAX_CLOSE_USERLAND
30048 + pax_force_retaddr
30049 ret
30050
30051 .section .fixup,"ax"
30052 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
30053 index 6a4f43c..c70fb52 100644
30054 --- a/arch/x86/lib/copy_user_nocache_64.S
30055 +++ b/arch/x86/lib/copy_user_nocache_64.S
30056 @@ -8,6 +8,7 @@
30057
30058 #include <linux/linkage.h>
30059 #include <asm/dwarf2.h>
30060 +#include <asm/alternative-asm.h>
30061
30062 #define FIX_ALIGNMENT 1
30063
30064 @@ -16,6 +17,7 @@
30065 #include <asm/thread_info.h>
30066 #include <asm/asm.h>
30067 #include <asm/smap.h>
30068 +#include <asm/pgtable.h>
30069
30070 .macro ALIGN_DESTINATION
30071 #ifdef FIX_ALIGNMENT
30072 @@ -49,6 +51,16 @@
30073 */
30074 ENTRY(__copy_user_nocache)
30075 CFI_STARTPROC
30076 +
30077 +#ifdef CONFIG_PAX_MEMORY_UDEREF
30078 + mov pax_user_shadow_base,%rcx
30079 + cmp %rcx,%rsi
30080 + jae 1f
30081 + add %rcx,%rsi
30082 +1:
30083 +#endif
30084 +
30085 + ASM_PAX_OPEN_USERLAND
30086 ASM_STAC
30087 cmpl $8,%edx
30088 jb 20f /* less then 8 bytes, go to byte copy loop */
30089 @@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
30090 jnz 21b
30091 23: xorl %eax,%eax
30092 ASM_CLAC
30093 + ASM_PAX_CLOSE_USERLAND
30094 sfence
30095 + pax_force_retaddr
30096 ret
30097
30098 .section .fixup,"ax"
30099 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
30100 index 2419d5f..fe52d0e 100644
30101 --- a/arch/x86/lib/csum-copy_64.S
30102 +++ b/arch/x86/lib/csum-copy_64.S
30103 @@ -9,6 +9,7 @@
30104 #include <asm/dwarf2.h>
30105 #include <asm/errno.h>
30106 #include <asm/asm.h>
30107 +#include <asm/alternative-asm.h>
30108
30109 /*
30110 * Checksum copy with exception handling.
30111 @@ -56,8 +57,8 @@ ENTRY(csum_partial_copy_generic)
30112 CFI_ADJUST_CFA_OFFSET 7*8
30113 movq %rbx, 2*8(%rsp)
30114 CFI_REL_OFFSET rbx, 2*8
30115 - movq %r12, 3*8(%rsp)
30116 - CFI_REL_OFFSET r12, 3*8
30117 + movq %r15, 3*8(%rsp)
30118 + CFI_REL_OFFSET r15, 3*8
30119 movq %r14, 4*8(%rsp)
30120 CFI_REL_OFFSET r14, 4*8
30121 movq %r13, 5*8(%rsp)
30122 @@ -72,16 +73,16 @@ ENTRY(csum_partial_copy_generic)
30123 movl %edx, %ecx
30124
30125 xorl %r9d, %r9d
30126 - movq %rcx, %r12
30127 + movq %rcx, %r15
30128
30129 - shrq $6, %r12
30130 + shrq $6, %r15
30131 jz .Lhandle_tail /* < 64 */
30132
30133 clc
30134
30135 /* main loop. clear in 64 byte blocks */
30136 /* r9: zero, r8: temp2, rbx: temp1, rax: sum, rcx: saved length */
30137 - /* r11: temp3, rdx: temp4, r12 loopcnt */
30138 + /* r11: temp3, rdx: temp4, r15 loopcnt */
30139 /* r10: temp5, rbp: temp6, r14 temp7, r13 temp8 */
30140 .p2align 4
30141 .Lloop:
30142 @@ -115,7 +116,7 @@ ENTRY(csum_partial_copy_generic)
30143 adcq %r14, %rax
30144 adcq %r13, %rax
30145
30146 - decl %r12d
30147 + decl %r15d
30148
30149 dest
30150 movq %rbx, (%rsi)
30151 @@ -210,8 +211,8 @@ ENTRY(csum_partial_copy_generic)
30152 .Lende:
30153 movq 2*8(%rsp), %rbx
30154 CFI_RESTORE rbx
30155 - movq 3*8(%rsp), %r12
30156 - CFI_RESTORE r12
30157 + movq 3*8(%rsp), %r15
30158 + CFI_RESTORE r15
30159 movq 4*8(%rsp), %r14
30160 CFI_RESTORE r14
30161 movq 5*8(%rsp), %r13
30162 @@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
30163 CFI_RESTORE rbp
30164 addq $7*8, %rsp
30165 CFI_ADJUST_CFA_OFFSET -7*8
30166 + pax_force_retaddr
30167 ret
30168 CFI_RESTORE_STATE
30169
30170 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
30171 index 7609e0e..b449b98 100644
30172 --- a/arch/x86/lib/csum-wrappers_64.c
30173 +++ b/arch/x86/lib/csum-wrappers_64.c
30174 @@ -53,10 +53,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
30175 len -= 2;
30176 }
30177 }
30178 + pax_open_userland();
30179 stac();
30180 - isum = csum_partial_copy_generic((__force const void *)src,
30181 + isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
30182 dst, len, isum, errp, NULL);
30183 clac();
30184 + pax_close_userland();
30185 if (unlikely(*errp))
30186 goto out_err;
30187
30188 @@ -110,10 +112,12 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
30189 }
30190
30191 *errp = 0;
30192 + pax_open_userland();
30193 stac();
30194 - ret = csum_partial_copy_generic(src, (void __force *)dst,
30195 + ret = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
30196 len, isum, NULL, errp);
30197 clac();
30198 + pax_close_userland();
30199 return ret;
30200 }
30201 EXPORT_SYMBOL(csum_partial_copy_to_user);
30202 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
30203 index a451235..1daa956 100644
30204 --- a/arch/x86/lib/getuser.S
30205 +++ b/arch/x86/lib/getuser.S
30206 @@ -33,17 +33,40 @@
30207 #include <asm/thread_info.h>
30208 #include <asm/asm.h>
30209 #include <asm/smap.h>
30210 +#include <asm/segment.h>
30211 +#include <asm/pgtable.h>
30212 +#include <asm/alternative-asm.h>
30213 +
30214 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
30215 +#define __copyuser_seg gs;
30216 +#else
30217 +#define __copyuser_seg
30218 +#endif
30219
30220 .text
30221 ENTRY(__get_user_1)
30222 CFI_STARTPROC
30223 +
30224 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30225 GET_THREAD_INFO(%_ASM_DX)
30226 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30227 jae bad_get_user
30228 ASM_STAC
30229 -1: movzbl (%_ASM_AX),%edx
30230 +
30231 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30232 + mov pax_user_shadow_base,%_ASM_DX
30233 + cmp %_ASM_DX,%_ASM_AX
30234 + jae 1234f
30235 + add %_ASM_DX,%_ASM_AX
30236 +1234:
30237 +#endif
30238 +
30239 +#endif
30240 +
30241 +1: __copyuser_seg movzbl (%_ASM_AX),%edx
30242 xor %eax,%eax
30243 ASM_CLAC
30244 + pax_force_retaddr
30245 ret
30246 CFI_ENDPROC
30247 ENDPROC(__get_user_1)
30248 @@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
30249 ENTRY(__get_user_2)
30250 CFI_STARTPROC
30251 add $1,%_ASM_AX
30252 +
30253 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30254 jc bad_get_user
30255 GET_THREAD_INFO(%_ASM_DX)
30256 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30257 jae bad_get_user
30258 ASM_STAC
30259 -2: movzwl -1(%_ASM_AX),%edx
30260 +
30261 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30262 + mov pax_user_shadow_base,%_ASM_DX
30263 + cmp %_ASM_DX,%_ASM_AX
30264 + jae 1234f
30265 + add %_ASM_DX,%_ASM_AX
30266 +1234:
30267 +#endif
30268 +
30269 +#endif
30270 +
30271 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
30272 xor %eax,%eax
30273 ASM_CLAC
30274 + pax_force_retaddr
30275 ret
30276 CFI_ENDPROC
30277 ENDPROC(__get_user_2)
30278 @@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
30279 ENTRY(__get_user_4)
30280 CFI_STARTPROC
30281 add $3,%_ASM_AX
30282 +
30283 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30284 jc bad_get_user
30285 GET_THREAD_INFO(%_ASM_DX)
30286 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30287 jae bad_get_user
30288 ASM_STAC
30289 -3: movl -3(%_ASM_AX),%edx
30290 +
30291 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30292 + mov pax_user_shadow_base,%_ASM_DX
30293 + cmp %_ASM_DX,%_ASM_AX
30294 + jae 1234f
30295 + add %_ASM_DX,%_ASM_AX
30296 +1234:
30297 +#endif
30298 +
30299 +#endif
30300 +
30301 +3: __copyuser_seg movl -3(%_ASM_AX),%edx
30302 xor %eax,%eax
30303 ASM_CLAC
30304 + pax_force_retaddr
30305 ret
30306 CFI_ENDPROC
30307 ENDPROC(__get_user_4)
30308 @@ -86,10 +137,20 @@ ENTRY(__get_user_8)
30309 GET_THREAD_INFO(%_ASM_DX)
30310 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30311 jae bad_get_user
30312 +
30313 +#ifdef CONFIG_PAX_MEMORY_UDEREF
30314 + mov pax_user_shadow_base,%_ASM_DX
30315 + cmp %_ASM_DX,%_ASM_AX
30316 + jae 1234f
30317 + add %_ASM_DX,%_ASM_AX
30318 +1234:
30319 +#endif
30320 +
30321 ASM_STAC
30322 4: movq -7(%_ASM_AX),%rdx
30323 xor %eax,%eax
30324 ASM_CLAC
30325 + pax_force_retaddr
30326 ret
30327 #else
30328 add $7,%_ASM_AX
30329 @@ -98,10 +159,11 @@ ENTRY(__get_user_8)
30330 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30331 jae bad_get_user_8
30332 ASM_STAC
30333 -4: movl -7(%_ASM_AX),%edx
30334 -5: movl -3(%_ASM_AX),%ecx
30335 +4: __copyuser_seg movl -7(%_ASM_AX),%edx
30336 +5: __copyuser_seg movl -3(%_ASM_AX),%ecx
30337 xor %eax,%eax
30338 ASM_CLAC
30339 + pax_force_retaddr
30340 ret
30341 #endif
30342 CFI_ENDPROC
30343 @@ -113,6 +175,7 @@ bad_get_user:
30344 xor %edx,%edx
30345 mov $(-EFAULT),%_ASM_AX
30346 ASM_CLAC
30347 + pax_force_retaddr
30348 ret
30349 CFI_ENDPROC
30350 END(bad_get_user)
30351 @@ -124,6 +187,7 @@ bad_get_user_8:
30352 xor %ecx,%ecx
30353 mov $(-EFAULT),%_ASM_AX
30354 ASM_CLAC
30355 + pax_force_retaddr
30356 ret
30357 CFI_ENDPROC
30358 END(bad_get_user_8)
30359 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
30360 index 54fcffe..7be149e 100644
30361 --- a/arch/x86/lib/insn.c
30362 +++ b/arch/x86/lib/insn.c
30363 @@ -20,8 +20,10 @@
30364
30365 #ifdef __KERNEL__
30366 #include <linux/string.h>
30367 +#include <asm/pgtable_types.h>
30368 #else
30369 #include <string.h>
30370 +#define ktla_ktva(addr) addr
30371 #endif
30372 #include <asm/inat.h>
30373 #include <asm/insn.h>
30374 @@ -53,8 +55,8 @@
30375 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
30376 {
30377 memset(insn, 0, sizeof(*insn));
30378 - insn->kaddr = kaddr;
30379 - insn->next_byte = kaddr;
30380 + insn->kaddr = ktla_ktva(kaddr);
30381 + insn->next_byte = ktla_ktva(kaddr);
30382 insn->x86_64 = x86_64 ? 1 : 0;
30383 insn->opnd_bytes = 4;
30384 if (x86_64)
30385 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
30386 index 05a95e7..326f2fa 100644
30387 --- a/arch/x86/lib/iomap_copy_64.S
30388 +++ b/arch/x86/lib/iomap_copy_64.S
30389 @@ -17,6 +17,7 @@
30390
30391 #include <linux/linkage.h>
30392 #include <asm/dwarf2.h>
30393 +#include <asm/alternative-asm.h>
30394
30395 /*
30396 * override generic version in lib/iomap_copy.c
30397 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
30398 CFI_STARTPROC
30399 movl %edx,%ecx
30400 rep movsd
30401 + pax_force_retaddr
30402 ret
30403 CFI_ENDPROC
30404 ENDPROC(__iowrite32_copy)
30405 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
30406 index 56313a3..0db417e 100644
30407 --- a/arch/x86/lib/memcpy_64.S
30408 +++ b/arch/x86/lib/memcpy_64.S
30409 @@ -24,7 +24,7 @@
30410 * This gets patched over the unrolled variant (below) via the
30411 * alternative instructions framework:
30412 */
30413 - .section .altinstr_replacement, "ax", @progbits
30414 + .section .altinstr_replacement, "a", @progbits
30415 .Lmemcpy_c:
30416 movq %rdi, %rax
30417 movq %rdx, %rcx
30418 @@ -33,6 +33,7 @@
30419 rep movsq
30420 movl %edx, %ecx
30421 rep movsb
30422 + pax_force_retaddr
30423 ret
30424 .Lmemcpy_e:
30425 .previous
30426 @@ -44,11 +45,12 @@
30427 * This gets patched over the unrolled variant (below) via the
30428 * alternative instructions framework:
30429 */
30430 - .section .altinstr_replacement, "ax", @progbits
30431 + .section .altinstr_replacement, "a", @progbits
30432 .Lmemcpy_c_e:
30433 movq %rdi, %rax
30434 movq %rdx, %rcx
30435 rep movsb
30436 + pax_force_retaddr
30437 ret
30438 .Lmemcpy_e_e:
30439 .previous
30440 @@ -136,6 +138,7 @@ ENTRY(memcpy)
30441 movq %r9, 1*8(%rdi)
30442 movq %r10, -2*8(%rdi, %rdx)
30443 movq %r11, -1*8(%rdi, %rdx)
30444 + pax_force_retaddr
30445 retq
30446 .p2align 4
30447 .Lless_16bytes:
30448 @@ -148,6 +151,7 @@ ENTRY(memcpy)
30449 movq -1*8(%rsi, %rdx), %r9
30450 movq %r8, 0*8(%rdi)
30451 movq %r9, -1*8(%rdi, %rdx)
30452 + pax_force_retaddr
30453 retq
30454 .p2align 4
30455 .Lless_8bytes:
30456 @@ -161,6 +165,7 @@ ENTRY(memcpy)
30457 movl -4(%rsi, %rdx), %r8d
30458 movl %ecx, (%rdi)
30459 movl %r8d, -4(%rdi, %rdx)
30460 + pax_force_retaddr
30461 retq
30462 .p2align 4
30463 .Lless_3bytes:
30464 @@ -179,6 +184,7 @@ ENTRY(memcpy)
30465 movb %cl, (%rdi)
30466
30467 .Lend:
30468 + pax_force_retaddr
30469 retq
30470 CFI_ENDPROC
30471 ENDPROC(memcpy)
30472 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
30473 index 65268a6..dd1de11 100644
30474 --- a/arch/x86/lib/memmove_64.S
30475 +++ b/arch/x86/lib/memmove_64.S
30476 @@ -202,14 +202,16 @@ ENTRY(memmove)
30477 movb (%rsi), %r11b
30478 movb %r11b, (%rdi)
30479 13:
30480 + pax_force_retaddr
30481 retq
30482 CFI_ENDPROC
30483
30484 - .section .altinstr_replacement,"ax"
30485 + .section .altinstr_replacement,"a"
30486 .Lmemmove_begin_forward_efs:
30487 /* Forward moving data. */
30488 movq %rdx, %rcx
30489 rep movsb
30490 + pax_force_retaddr
30491 retq
30492 .Lmemmove_end_forward_efs:
30493 .previous
30494 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
30495 index 2dcb380..2eb79fe 100644
30496 --- a/arch/x86/lib/memset_64.S
30497 +++ b/arch/x86/lib/memset_64.S
30498 @@ -16,7 +16,7 @@
30499 *
30500 * rax original destination
30501 */
30502 - .section .altinstr_replacement, "ax", @progbits
30503 + .section .altinstr_replacement, "a", @progbits
30504 .Lmemset_c:
30505 movq %rdi,%r9
30506 movq %rdx,%rcx
30507 @@ -30,6 +30,7 @@
30508 movl %edx,%ecx
30509 rep stosb
30510 movq %r9,%rax
30511 + pax_force_retaddr
30512 ret
30513 .Lmemset_e:
30514 .previous
30515 @@ -45,13 +46,14 @@
30516 *
30517 * rax original destination
30518 */
30519 - .section .altinstr_replacement, "ax", @progbits
30520 + .section .altinstr_replacement, "a", @progbits
30521 .Lmemset_c_e:
30522 movq %rdi,%r9
30523 movb %sil,%al
30524 movq %rdx,%rcx
30525 rep stosb
30526 movq %r9,%rax
30527 + pax_force_retaddr
30528 ret
30529 .Lmemset_e_e:
30530 .previous
30531 @@ -118,6 +120,7 @@ ENTRY(__memset)
30532
30533 .Lende:
30534 movq %r10,%rax
30535 + pax_force_retaddr
30536 ret
30537
30538 CFI_RESTORE_STATE
30539 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
30540 index c9f2d9b..e7fd2c0 100644
30541 --- a/arch/x86/lib/mmx_32.c
30542 +++ b/arch/x86/lib/mmx_32.c
30543 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
30544 {
30545 void *p;
30546 int i;
30547 + unsigned long cr0;
30548
30549 if (unlikely(in_interrupt()))
30550 return __memcpy(to, from, len);
30551 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
30552 kernel_fpu_begin();
30553
30554 __asm__ __volatile__ (
30555 - "1: prefetch (%0)\n" /* This set is 28 bytes */
30556 - " prefetch 64(%0)\n"
30557 - " prefetch 128(%0)\n"
30558 - " prefetch 192(%0)\n"
30559 - " prefetch 256(%0)\n"
30560 + "1: prefetch (%1)\n" /* This set is 28 bytes */
30561 + " prefetch 64(%1)\n"
30562 + " prefetch 128(%1)\n"
30563 + " prefetch 192(%1)\n"
30564 + " prefetch 256(%1)\n"
30565 "2: \n"
30566 ".section .fixup, \"ax\"\n"
30567 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30568 + "3: \n"
30569 +
30570 +#ifdef CONFIG_PAX_KERNEXEC
30571 + " movl %%cr0, %0\n"
30572 + " movl %0, %%eax\n"
30573 + " andl $0xFFFEFFFF, %%eax\n"
30574 + " movl %%eax, %%cr0\n"
30575 +#endif
30576 +
30577 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30578 +
30579 +#ifdef CONFIG_PAX_KERNEXEC
30580 + " movl %0, %%cr0\n"
30581 +#endif
30582 +
30583 " jmp 2b\n"
30584 ".previous\n"
30585 _ASM_EXTABLE(1b, 3b)
30586 - : : "r" (from));
30587 + : "=&r" (cr0) : "r" (from) : "ax");
30588
30589 for ( ; i > 5; i--) {
30590 __asm__ __volatile__ (
30591 - "1: prefetch 320(%0)\n"
30592 - "2: movq (%0), %%mm0\n"
30593 - " movq 8(%0), %%mm1\n"
30594 - " movq 16(%0), %%mm2\n"
30595 - " movq 24(%0), %%mm3\n"
30596 - " movq %%mm0, (%1)\n"
30597 - " movq %%mm1, 8(%1)\n"
30598 - " movq %%mm2, 16(%1)\n"
30599 - " movq %%mm3, 24(%1)\n"
30600 - " movq 32(%0), %%mm0\n"
30601 - " movq 40(%0), %%mm1\n"
30602 - " movq 48(%0), %%mm2\n"
30603 - " movq 56(%0), %%mm3\n"
30604 - " movq %%mm0, 32(%1)\n"
30605 - " movq %%mm1, 40(%1)\n"
30606 - " movq %%mm2, 48(%1)\n"
30607 - " movq %%mm3, 56(%1)\n"
30608 + "1: prefetch 320(%1)\n"
30609 + "2: movq (%1), %%mm0\n"
30610 + " movq 8(%1), %%mm1\n"
30611 + " movq 16(%1), %%mm2\n"
30612 + " movq 24(%1), %%mm3\n"
30613 + " movq %%mm0, (%2)\n"
30614 + " movq %%mm1, 8(%2)\n"
30615 + " movq %%mm2, 16(%2)\n"
30616 + " movq %%mm3, 24(%2)\n"
30617 + " movq 32(%1), %%mm0\n"
30618 + " movq 40(%1), %%mm1\n"
30619 + " movq 48(%1), %%mm2\n"
30620 + " movq 56(%1), %%mm3\n"
30621 + " movq %%mm0, 32(%2)\n"
30622 + " movq %%mm1, 40(%2)\n"
30623 + " movq %%mm2, 48(%2)\n"
30624 + " movq %%mm3, 56(%2)\n"
30625 ".section .fixup, \"ax\"\n"
30626 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30627 + "3:\n"
30628 +
30629 +#ifdef CONFIG_PAX_KERNEXEC
30630 + " movl %%cr0, %0\n"
30631 + " movl %0, %%eax\n"
30632 + " andl $0xFFFEFFFF, %%eax\n"
30633 + " movl %%eax, %%cr0\n"
30634 +#endif
30635 +
30636 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30637 +
30638 +#ifdef CONFIG_PAX_KERNEXEC
30639 + " movl %0, %%cr0\n"
30640 +#endif
30641 +
30642 " jmp 2b\n"
30643 ".previous\n"
30644 _ASM_EXTABLE(1b, 3b)
30645 - : : "r" (from), "r" (to) : "memory");
30646 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30647
30648 from += 64;
30649 to += 64;
30650 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
30651 static void fast_copy_page(void *to, void *from)
30652 {
30653 int i;
30654 + unsigned long cr0;
30655
30656 kernel_fpu_begin();
30657
30658 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
30659 * but that is for later. -AV
30660 */
30661 __asm__ __volatile__(
30662 - "1: prefetch (%0)\n"
30663 - " prefetch 64(%0)\n"
30664 - " prefetch 128(%0)\n"
30665 - " prefetch 192(%0)\n"
30666 - " prefetch 256(%0)\n"
30667 + "1: prefetch (%1)\n"
30668 + " prefetch 64(%1)\n"
30669 + " prefetch 128(%1)\n"
30670 + " prefetch 192(%1)\n"
30671 + " prefetch 256(%1)\n"
30672 "2: \n"
30673 ".section .fixup, \"ax\"\n"
30674 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30675 + "3: \n"
30676 +
30677 +#ifdef CONFIG_PAX_KERNEXEC
30678 + " movl %%cr0, %0\n"
30679 + " movl %0, %%eax\n"
30680 + " andl $0xFFFEFFFF, %%eax\n"
30681 + " movl %%eax, %%cr0\n"
30682 +#endif
30683 +
30684 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30685 +
30686 +#ifdef CONFIG_PAX_KERNEXEC
30687 + " movl %0, %%cr0\n"
30688 +#endif
30689 +
30690 " jmp 2b\n"
30691 ".previous\n"
30692 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
30693 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30694
30695 for (i = 0; i < (4096-320)/64; i++) {
30696 __asm__ __volatile__ (
30697 - "1: prefetch 320(%0)\n"
30698 - "2: movq (%0), %%mm0\n"
30699 - " movntq %%mm0, (%1)\n"
30700 - " movq 8(%0), %%mm1\n"
30701 - " movntq %%mm1, 8(%1)\n"
30702 - " movq 16(%0), %%mm2\n"
30703 - " movntq %%mm2, 16(%1)\n"
30704 - " movq 24(%0), %%mm3\n"
30705 - " movntq %%mm3, 24(%1)\n"
30706 - " movq 32(%0), %%mm4\n"
30707 - " movntq %%mm4, 32(%1)\n"
30708 - " movq 40(%0), %%mm5\n"
30709 - " movntq %%mm5, 40(%1)\n"
30710 - " movq 48(%0), %%mm6\n"
30711 - " movntq %%mm6, 48(%1)\n"
30712 - " movq 56(%0), %%mm7\n"
30713 - " movntq %%mm7, 56(%1)\n"
30714 + "1: prefetch 320(%1)\n"
30715 + "2: movq (%1), %%mm0\n"
30716 + " movntq %%mm0, (%2)\n"
30717 + " movq 8(%1), %%mm1\n"
30718 + " movntq %%mm1, 8(%2)\n"
30719 + " movq 16(%1), %%mm2\n"
30720 + " movntq %%mm2, 16(%2)\n"
30721 + " movq 24(%1), %%mm3\n"
30722 + " movntq %%mm3, 24(%2)\n"
30723 + " movq 32(%1), %%mm4\n"
30724 + " movntq %%mm4, 32(%2)\n"
30725 + " movq 40(%1), %%mm5\n"
30726 + " movntq %%mm5, 40(%2)\n"
30727 + " movq 48(%1), %%mm6\n"
30728 + " movntq %%mm6, 48(%2)\n"
30729 + " movq 56(%1), %%mm7\n"
30730 + " movntq %%mm7, 56(%2)\n"
30731 ".section .fixup, \"ax\"\n"
30732 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30733 + "3:\n"
30734 +
30735 +#ifdef CONFIG_PAX_KERNEXEC
30736 + " movl %%cr0, %0\n"
30737 + " movl %0, %%eax\n"
30738 + " andl $0xFFFEFFFF, %%eax\n"
30739 + " movl %%eax, %%cr0\n"
30740 +#endif
30741 +
30742 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30743 +
30744 +#ifdef CONFIG_PAX_KERNEXEC
30745 + " movl %0, %%cr0\n"
30746 +#endif
30747 +
30748 " jmp 2b\n"
30749 ".previous\n"
30750 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
30751 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30752
30753 from += 64;
30754 to += 64;
30755 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
30756 static void fast_copy_page(void *to, void *from)
30757 {
30758 int i;
30759 + unsigned long cr0;
30760
30761 kernel_fpu_begin();
30762
30763 __asm__ __volatile__ (
30764 - "1: prefetch (%0)\n"
30765 - " prefetch 64(%0)\n"
30766 - " prefetch 128(%0)\n"
30767 - " prefetch 192(%0)\n"
30768 - " prefetch 256(%0)\n"
30769 + "1: prefetch (%1)\n"
30770 + " prefetch 64(%1)\n"
30771 + " prefetch 128(%1)\n"
30772 + " prefetch 192(%1)\n"
30773 + " prefetch 256(%1)\n"
30774 "2: \n"
30775 ".section .fixup, \"ax\"\n"
30776 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30777 + "3: \n"
30778 +
30779 +#ifdef CONFIG_PAX_KERNEXEC
30780 + " movl %%cr0, %0\n"
30781 + " movl %0, %%eax\n"
30782 + " andl $0xFFFEFFFF, %%eax\n"
30783 + " movl %%eax, %%cr0\n"
30784 +#endif
30785 +
30786 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30787 +
30788 +#ifdef CONFIG_PAX_KERNEXEC
30789 + " movl %0, %%cr0\n"
30790 +#endif
30791 +
30792 " jmp 2b\n"
30793 ".previous\n"
30794 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
30795 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30796
30797 for (i = 0; i < 4096/64; i++) {
30798 __asm__ __volatile__ (
30799 - "1: prefetch 320(%0)\n"
30800 - "2: movq (%0), %%mm0\n"
30801 - " movq 8(%0), %%mm1\n"
30802 - " movq 16(%0), %%mm2\n"
30803 - " movq 24(%0), %%mm3\n"
30804 - " movq %%mm0, (%1)\n"
30805 - " movq %%mm1, 8(%1)\n"
30806 - " movq %%mm2, 16(%1)\n"
30807 - " movq %%mm3, 24(%1)\n"
30808 - " movq 32(%0), %%mm0\n"
30809 - " movq 40(%0), %%mm1\n"
30810 - " movq 48(%0), %%mm2\n"
30811 - " movq 56(%0), %%mm3\n"
30812 - " movq %%mm0, 32(%1)\n"
30813 - " movq %%mm1, 40(%1)\n"
30814 - " movq %%mm2, 48(%1)\n"
30815 - " movq %%mm3, 56(%1)\n"
30816 + "1: prefetch 320(%1)\n"
30817 + "2: movq (%1), %%mm0\n"
30818 + " movq 8(%1), %%mm1\n"
30819 + " movq 16(%1), %%mm2\n"
30820 + " movq 24(%1), %%mm3\n"
30821 + " movq %%mm0, (%2)\n"
30822 + " movq %%mm1, 8(%2)\n"
30823 + " movq %%mm2, 16(%2)\n"
30824 + " movq %%mm3, 24(%2)\n"
30825 + " movq 32(%1), %%mm0\n"
30826 + " movq 40(%1), %%mm1\n"
30827 + " movq 48(%1), %%mm2\n"
30828 + " movq 56(%1), %%mm3\n"
30829 + " movq %%mm0, 32(%2)\n"
30830 + " movq %%mm1, 40(%2)\n"
30831 + " movq %%mm2, 48(%2)\n"
30832 + " movq %%mm3, 56(%2)\n"
30833 ".section .fixup, \"ax\"\n"
30834 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30835 + "3:\n"
30836 +
30837 +#ifdef CONFIG_PAX_KERNEXEC
30838 + " movl %%cr0, %0\n"
30839 + " movl %0, %%eax\n"
30840 + " andl $0xFFFEFFFF, %%eax\n"
30841 + " movl %%eax, %%cr0\n"
30842 +#endif
30843 +
30844 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30845 +
30846 +#ifdef CONFIG_PAX_KERNEXEC
30847 + " movl %0, %%cr0\n"
30848 +#endif
30849 +
30850 " jmp 2b\n"
30851 ".previous\n"
30852 _ASM_EXTABLE(1b, 3b)
30853 - : : "r" (from), "r" (to) : "memory");
30854 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30855
30856 from += 64;
30857 to += 64;
30858 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
30859 index f6d13ee..d789440 100644
30860 --- a/arch/x86/lib/msr-reg.S
30861 +++ b/arch/x86/lib/msr-reg.S
30862 @@ -3,6 +3,7 @@
30863 #include <asm/dwarf2.h>
30864 #include <asm/asm.h>
30865 #include <asm/msr.h>
30866 +#include <asm/alternative-asm.h>
30867
30868 #ifdef CONFIG_X86_64
30869 /*
30870 @@ -37,6 +38,7 @@ ENTRY(\op\()_safe_regs)
30871 movl %edi, 28(%r10)
30872 popq_cfi %rbp
30873 popq_cfi %rbx
30874 + pax_force_retaddr
30875 ret
30876 3:
30877 CFI_RESTORE_STATE
30878 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
30879 index fc6ba17..d4d989d 100644
30880 --- a/arch/x86/lib/putuser.S
30881 +++ b/arch/x86/lib/putuser.S
30882 @@ -16,7 +16,9 @@
30883 #include <asm/errno.h>
30884 #include <asm/asm.h>
30885 #include <asm/smap.h>
30886 -
30887 +#include <asm/segment.h>
30888 +#include <asm/pgtable.h>
30889 +#include <asm/alternative-asm.h>
30890
30891 /*
30892 * __put_user_X
30893 @@ -30,57 +32,125 @@
30894 * as they get called from within inline assembly.
30895 */
30896
30897 -#define ENTER CFI_STARTPROC ; \
30898 - GET_THREAD_INFO(%_ASM_BX)
30899 -#define EXIT ASM_CLAC ; \
30900 - ret ; \
30901 +#define ENTER CFI_STARTPROC
30902 +#define EXIT ASM_CLAC ; \
30903 + pax_force_retaddr ; \
30904 + ret ; \
30905 CFI_ENDPROC
30906
30907 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30908 +#define _DEST %_ASM_CX,%_ASM_BX
30909 +#else
30910 +#define _DEST %_ASM_CX
30911 +#endif
30912 +
30913 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
30914 +#define __copyuser_seg gs;
30915 +#else
30916 +#define __copyuser_seg
30917 +#endif
30918 +
30919 .text
30920 ENTRY(__put_user_1)
30921 ENTER
30922 +
30923 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30924 + GET_THREAD_INFO(%_ASM_BX)
30925 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
30926 jae bad_put_user
30927 ASM_STAC
30928 -1: movb %al,(%_ASM_CX)
30929 +
30930 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30931 + mov pax_user_shadow_base,%_ASM_BX
30932 + cmp %_ASM_BX,%_ASM_CX
30933 + jb 1234f
30934 + xor %ebx,%ebx
30935 +1234:
30936 +#endif
30937 +
30938 +#endif
30939 +
30940 +1: __copyuser_seg movb %al,(_DEST)
30941 xor %eax,%eax
30942 EXIT
30943 ENDPROC(__put_user_1)
30944
30945 ENTRY(__put_user_2)
30946 ENTER
30947 +
30948 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30949 + GET_THREAD_INFO(%_ASM_BX)
30950 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30951 sub $1,%_ASM_BX
30952 cmp %_ASM_BX,%_ASM_CX
30953 jae bad_put_user
30954 ASM_STAC
30955 -2: movw %ax,(%_ASM_CX)
30956 +
30957 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30958 + mov pax_user_shadow_base,%_ASM_BX
30959 + cmp %_ASM_BX,%_ASM_CX
30960 + jb 1234f
30961 + xor %ebx,%ebx
30962 +1234:
30963 +#endif
30964 +
30965 +#endif
30966 +
30967 +2: __copyuser_seg movw %ax,(_DEST)
30968 xor %eax,%eax
30969 EXIT
30970 ENDPROC(__put_user_2)
30971
30972 ENTRY(__put_user_4)
30973 ENTER
30974 +
30975 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30976 + GET_THREAD_INFO(%_ASM_BX)
30977 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30978 sub $3,%_ASM_BX
30979 cmp %_ASM_BX,%_ASM_CX
30980 jae bad_put_user
30981 ASM_STAC
30982 -3: movl %eax,(%_ASM_CX)
30983 +
30984 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30985 + mov pax_user_shadow_base,%_ASM_BX
30986 + cmp %_ASM_BX,%_ASM_CX
30987 + jb 1234f
30988 + xor %ebx,%ebx
30989 +1234:
30990 +#endif
30991 +
30992 +#endif
30993 +
30994 +3: __copyuser_seg movl %eax,(_DEST)
30995 xor %eax,%eax
30996 EXIT
30997 ENDPROC(__put_user_4)
30998
30999 ENTRY(__put_user_8)
31000 ENTER
31001 +
31002 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
31003 + GET_THREAD_INFO(%_ASM_BX)
31004 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
31005 sub $7,%_ASM_BX
31006 cmp %_ASM_BX,%_ASM_CX
31007 jae bad_put_user
31008 ASM_STAC
31009 -4: mov %_ASM_AX,(%_ASM_CX)
31010 +
31011 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31012 + mov pax_user_shadow_base,%_ASM_BX
31013 + cmp %_ASM_BX,%_ASM_CX
31014 + jb 1234f
31015 + xor %ebx,%ebx
31016 +1234:
31017 +#endif
31018 +
31019 +#endif
31020 +
31021 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
31022 #ifdef CONFIG_X86_32
31023 -5: movl %edx,4(%_ASM_CX)
31024 +5: __copyuser_seg movl %edx,4(_DEST)
31025 #endif
31026 xor %eax,%eax
31027 EXIT
31028 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
31029 index 1cad221..de671ee 100644
31030 --- a/arch/x86/lib/rwlock.S
31031 +++ b/arch/x86/lib/rwlock.S
31032 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
31033 FRAME
31034 0: LOCK_PREFIX
31035 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
31036 +
31037 +#ifdef CONFIG_PAX_REFCOUNT
31038 + jno 1234f
31039 + LOCK_PREFIX
31040 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
31041 + int $4
31042 +1234:
31043 + _ASM_EXTABLE(1234b, 1234b)
31044 +#endif
31045 +
31046 1: rep; nop
31047 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
31048 jne 1b
31049 LOCK_PREFIX
31050 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
31051 +
31052 +#ifdef CONFIG_PAX_REFCOUNT
31053 + jno 1234f
31054 + LOCK_PREFIX
31055 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
31056 + int $4
31057 +1234:
31058 + _ASM_EXTABLE(1234b, 1234b)
31059 +#endif
31060 +
31061 jnz 0b
31062 ENDFRAME
31063 + pax_force_retaddr
31064 ret
31065 CFI_ENDPROC
31066 END(__write_lock_failed)
31067 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
31068 FRAME
31069 0: LOCK_PREFIX
31070 READ_LOCK_SIZE(inc) (%__lock_ptr)
31071 +
31072 +#ifdef CONFIG_PAX_REFCOUNT
31073 + jno 1234f
31074 + LOCK_PREFIX
31075 + READ_LOCK_SIZE(dec) (%__lock_ptr)
31076 + int $4
31077 +1234:
31078 + _ASM_EXTABLE(1234b, 1234b)
31079 +#endif
31080 +
31081 1: rep; nop
31082 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
31083 js 1b
31084 LOCK_PREFIX
31085 READ_LOCK_SIZE(dec) (%__lock_ptr)
31086 +
31087 +#ifdef CONFIG_PAX_REFCOUNT
31088 + jno 1234f
31089 + LOCK_PREFIX
31090 + READ_LOCK_SIZE(inc) (%__lock_ptr)
31091 + int $4
31092 +1234:
31093 + _ASM_EXTABLE(1234b, 1234b)
31094 +#endif
31095 +
31096 js 0b
31097 ENDFRAME
31098 + pax_force_retaddr
31099 ret
31100 CFI_ENDPROC
31101 END(__read_lock_failed)
31102 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
31103 index 5dff5f0..cadebf4 100644
31104 --- a/arch/x86/lib/rwsem.S
31105 +++ b/arch/x86/lib/rwsem.S
31106 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
31107 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
31108 CFI_RESTORE __ASM_REG(dx)
31109 restore_common_regs
31110 + pax_force_retaddr
31111 ret
31112 CFI_ENDPROC
31113 ENDPROC(call_rwsem_down_read_failed)
31114 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
31115 movq %rax,%rdi
31116 call rwsem_down_write_failed
31117 restore_common_regs
31118 + pax_force_retaddr
31119 ret
31120 CFI_ENDPROC
31121 ENDPROC(call_rwsem_down_write_failed)
31122 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
31123 movq %rax,%rdi
31124 call rwsem_wake
31125 restore_common_regs
31126 -1: ret
31127 +1: pax_force_retaddr
31128 + ret
31129 CFI_ENDPROC
31130 ENDPROC(call_rwsem_wake)
31131
31132 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
31133 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
31134 CFI_RESTORE __ASM_REG(dx)
31135 restore_common_regs
31136 + pax_force_retaddr
31137 ret
31138 CFI_ENDPROC
31139 ENDPROC(call_rwsem_downgrade_wake)
31140 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
31141 index 92d9fea..b2762c8 100644
31142 --- a/arch/x86/lib/thunk_64.S
31143 +++ b/arch/x86/lib/thunk_64.S
31144 @@ -9,6 +9,7 @@
31145 #include <asm/dwarf2.h>
31146 #include <asm/calling.h>
31147 #include <asm/asm.h>
31148 +#include <asm/alternative-asm.h>
31149
31150 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
31151 .macro THUNK name, func, put_ret_addr_in_rdi=0
31152 @@ -16,11 +17,11 @@
31153 \name:
31154 CFI_STARTPROC
31155
31156 - /* this one pushes 9 elems, the next one would be %rIP */
31157 - SAVE_ARGS
31158 + /* this one pushes 15+1 elems, the next one would be %rIP */
31159 + SAVE_ARGS 8
31160
31161 .if \put_ret_addr_in_rdi
31162 - movq_cfi_restore 9*8, rdi
31163 + movq_cfi_restore RIP, rdi
31164 .endif
31165
31166 call \func
31167 @@ -40,9 +41,10 @@
31168
31169 /* SAVE_ARGS below is used only for the .cfi directives it contains. */
31170 CFI_STARTPROC
31171 - SAVE_ARGS
31172 + SAVE_ARGS 8
31173 restore:
31174 - RESTORE_ARGS
31175 + RESTORE_ARGS 1,8
31176 + pax_force_retaddr
31177 ret
31178 CFI_ENDPROC
31179 _ASM_NOKPROBE(restore)
31180 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
31181 index e2f5e21..4b22130 100644
31182 --- a/arch/x86/lib/usercopy_32.c
31183 +++ b/arch/x86/lib/usercopy_32.c
31184 @@ -42,11 +42,13 @@ do { \
31185 int __d0; \
31186 might_fault(); \
31187 __asm__ __volatile__( \
31188 + __COPYUSER_SET_ES \
31189 ASM_STAC "\n" \
31190 "0: rep; stosl\n" \
31191 " movl %2,%0\n" \
31192 "1: rep; stosb\n" \
31193 "2: " ASM_CLAC "\n" \
31194 + __COPYUSER_RESTORE_ES \
31195 ".section .fixup,\"ax\"\n" \
31196 "3: lea 0(%2,%0,4),%0\n" \
31197 " jmp 2b\n" \
31198 @@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
31199
31200 #ifdef CONFIG_X86_INTEL_USERCOPY
31201 static unsigned long
31202 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
31203 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
31204 {
31205 int d0, d1;
31206 __asm__ __volatile__(
31207 @@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
31208 " .align 2,0x90\n"
31209 "3: movl 0(%4), %%eax\n"
31210 "4: movl 4(%4), %%edx\n"
31211 - "5: movl %%eax, 0(%3)\n"
31212 - "6: movl %%edx, 4(%3)\n"
31213 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
31214 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
31215 "7: movl 8(%4), %%eax\n"
31216 "8: movl 12(%4),%%edx\n"
31217 - "9: movl %%eax, 8(%3)\n"
31218 - "10: movl %%edx, 12(%3)\n"
31219 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
31220 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
31221 "11: movl 16(%4), %%eax\n"
31222 "12: movl 20(%4), %%edx\n"
31223 - "13: movl %%eax, 16(%3)\n"
31224 - "14: movl %%edx, 20(%3)\n"
31225 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
31226 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
31227 "15: movl 24(%4), %%eax\n"
31228 "16: movl 28(%4), %%edx\n"
31229 - "17: movl %%eax, 24(%3)\n"
31230 - "18: movl %%edx, 28(%3)\n"
31231 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
31232 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
31233 "19: movl 32(%4), %%eax\n"
31234 "20: movl 36(%4), %%edx\n"
31235 - "21: movl %%eax, 32(%3)\n"
31236 - "22: movl %%edx, 36(%3)\n"
31237 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
31238 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
31239 "23: movl 40(%4), %%eax\n"
31240 "24: movl 44(%4), %%edx\n"
31241 - "25: movl %%eax, 40(%3)\n"
31242 - "26: movl %%edx, 44(%3)\n"
31243 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
31244 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
31245 "27: movl 48(%4), %%eax\n"
31246 "28: movl 52(%4), %%edx\n"
31247 - "29: movl %%eax, 48(%3)\n"
31248 - "30: movl %%edx, 52(%3)\n"
31249 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
31250 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
31251 "31: movl 56(%4), %%eax\n"
31252 "32: movl 60(%4), %%edx\n"
31253 - "33: movl %%eax, 56(%3)\n"
31254 - "34: movl %%edx, 60(%3)\n"
31255 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
31256 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
31257 " addl $-64, %0\n"
31258 " addl $64, %4\n"
31259 " addl $64, %3\n"
31260 @@ -149,10 +151,116 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
31261 " shrl $2, %0\n"
31262 " andl $3, %%eax\n"
31263 " cld\n"
31264 + __COPYUSER_SET_ES
31265 "99: rep; movsl\n"
31266 "36: movl %%eax, %0\n"
31267 "37: rep; movsb\n"
31268 "100:\n"
31269 + __COPYUSER_RESTORE_ES
31270 + ".section .fixup,\"ax\"\n"
31271 + "101: lea 0(%%eax,%0,4),%0\n"
31272 + " jmp 100b\n"
31273 + ".previous\n"
31274 + _ASM_EXTABLE(1b,100b)
31275 + _ASM_EXTABLE(2b,100b)
31276 + _ASM_EXTABLE(3b,100b)
31277 + _ASM_EXTABLE(4b,100b)
31278 + _ASM_EXTABLE(5b,100b)
31279 + _ASM_EXTABLE(6b,100b)
31280 + _ASM_EXTABLE(7b,100b)
31281 + _ASM_EXTABLE(8b,100b)
31282 + _ASM_EXTABLE(9b,100b)
31283 + _ASM_EXTABLE(10b,100b)
31284 + _ASM_EXTABLE(11b,100b)
31285 + _ASM_EXTABLE(12b,100b)
31286 + _ASM_EXTABLE(13b,100b)
31287 + _ASM_EXTABLE(14b,100b)
31288 + _ASM_EXTABLE(15b,100b)
31289 + _ASM_EXTABLE(16b,100b)
31290 + _ASM_EXTABLE(17b,100b)
31291 + _ASM_EXTABLE(18b,100b)
31292 + _ASM_EXTABLE(19b,100b)
31293 + _ASM_EXTABLE(20b,100b)
31294 + _ASM_EXTABLE(21b,100b)
31295 + _ASM_EXTABLE(22b,100b)
31296 + _ASM_EXTABLE(23b,100b)
31297 + _ASM_EXTABLE(24b,100b)
31298 + _ASM_EXTABLE(25b,100b)
31299 + _ASM_EXTABLE(26b,100b)
31300 + _ASM_EXTABLE(27b,100b)
31301 + _ASM_EXTABLE(28b,100b)
31302 + _ASM_EXTABLE(29b,100b)
31303 + _ASM_EXTABLE(30b,100b)
31304 + _ASM_EXTABLE(31b,100b)
31305 + _ASM_EXTABLE(32b,100b)
31306 + _ASM_EXTABLE(33b,100b)
31307 + _ASM_EXTABLE(34b,100b)
31308 + _ASM_EXTABLE(35b,100b)
31309 + _ASM_EXTABLE(36b,100b)
31310 + _ASM_EXTABLE(37b,100b)
31311 + _ASM_EXTABLE(99b,101b)
31312 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
31313 + : "1"(to), "2"(from), "0"(size)
31314 + : "eax", "edx", "memory");
31315 + return size;
31316 +}
31317 +
31318 +static unsigned long
31319 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
31320 +{
31321 + int d0, d1;
31322 + __asm__ __volatile__(
31323 + " .align 2,0x90\n"
31324 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
31325 + " cmpl $67, %0\n"
31326 + " jbe 3f\n"
31327 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
31328 + " .align 2,0x90\n"
31329 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
31330 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
31331 + "5: movl %%eax, 0(%3)\n"
31332 + "6: movl %%edx, 4(%3)\n"
31333 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
31334 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
31335 + "9: movl %%eax, 8(%3)\n"
31336 + "10: movl %%edx, 12(%3)\n"
31337 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
31338 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
31339 + "13: movl %%eax, 16(%3)\n"
31340 + "14: movl %%edx, 20(%3)\n"
31341 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
31342 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
31343 + "17: movl %%eax, 24(%3)\n"
31344 + "18: movl %%edx, 28(%3)\n"
31345 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
31346 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
31347 + "21: movl %%eax, 32(%3)\n"
31348 + "22: movl %%edx, 36(%3)\n"
31349 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
31350 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
31351 + "25: movl %%eax, 40(%3)\n"
31352 + "26: movl %%edx, 44(%3)\n"
31353 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
31354 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
31355 + "29: movl %%eax, 48(%3)\n"
31356 + "30: movl %%edx, 52(%3)\n"
31357 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
31358 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
31359 + "33: movl %%eax, 56(%3)\n"
31360 + "34: movl %%edx, 60(%3)\n"
31361 + " addl $-64, %0\n"
31362 + " addl $64, %4\n"
31363 + " addl $64, %3\n"
31364 + " cmpl $63, %0\n"
31365 + " ja 1b\n"
31366 + "35: movl %0, %%eax\n"
31367 + " shrl $2, %0\n"
31368 + " andl $3, %%eax\n"
31369 + " cld\n"
31370 + "99: rep; "__copyuser_seg" movsl\n"
31371 + "36: movl %%eax, %0\n"
31372 + "37: rep; "__copyuser_seg" movsb\n"
31373 + "100:\n"
31374 ".section .fixup,\"ax\"\n"
31375 "101: lea 0(%%eax,%0,4),%0\n"
31376 " jmp 100b\n"
31377 @@ -207,41 +315,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
31378 int d0, d1;
31379 __asm__ __volatile__(
31380 " .align 2,0x90\n"
31381 - "0: movl 32(%4), %%eax\n"
31382 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31383 " cmpl $67, %0\n"
31384 " jbe 2f\n"
31385 - "1: movl 64(%4), %%eax\n"
31386 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31387 " .align 2,0x90\n"
31388 - "2: movl 0(%4), %%eax\n"
31389 - "21: movl 4(%4), %%edx\n"
31390 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31391 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31392 " movl %%eax, 0(%3)\n"
31393 " movl %%edx, 4(%3)\n"
31394 - "3: movl 8(%4), %%eax\n"
31395 - "31: movl 12(%4),%%edx\n"
31396 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31397 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31398 " movl %%eax, 8(%3)\n"
31399 " movl %%edx, 12(%3)\n"
31400 - "4: movl 16(%4), %%eax\n"
31401 - "41: movl 20(%4), %%edx\n"
31402 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31403 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31404 " movl %%eax, 16(%3)\n"
31405 " movl %%edx, 20(%3)\n"
31406 - "10: movl 24(%4), %%eax\n"
31407 - "51: movl 28(%4), %%edx\n"
31408 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31409 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31410 " movl %%eax, 24(%3)\n"
31411 " movl %%edx, 28(%3)\n"
31412 - "11: movl 32(%4), %%eax\n"
31413 - "61: movl 36(%4), %%edx\n"
31414 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31415 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31416 " movl %%eax, 32(%3)\n"
31417 " movl %%edx, 36(%3)\n"
31418 - "12: movl 40(%4), %%eax\n"
31419 - "71: movl 44(%4), %%edx\n"
31420 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31421 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31422 " movl %%eax, 40(%3)\n"
31423 " movl %%edx, 44(%3)\n"
31424 - "13: movl 48(%4), %%eax\n"
31425 - "81: movl 52(%4), %%edx\n"
31426 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31427 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31428 " movl %%eax, 48(%3)\n"
31429 " movl %%edx, 52(%3)\n"
31430 - "14: movl 56(%4), %%eax\n"
31431 - "91: movl 60(%4), %%edx\n"
31432 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31433 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31434 " movl %%eax, 56(%3)\n"
31435 " movl %%edx, 60(%3)\n"
31436 " addl $-64, %0\n"
31437 @@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
31438 " shrl $2, %0\n"
31439 " andl $3, %%eax\n"
31440 " cld\n"
31441 - "6: rep; movsl\n"
31442 + "6: rep; "__copyuser_seg" movsl\n"
31443 " movl %%eax,%0\n"
31444 - "7: rep; movsb\n"
31445 + "7: rep; "__copyuser_seg" movsb\n"
31446 "8:\n"
31447 ".section .fixup,\"ax\"\n"
31448 "9: lea 0(%%eax,%0,4),%0\n"
31449 @@ -305,41 +413,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
31450
31451 __asm__ __volatile__(
31452 " .align 2,0x90\n"
31453 - "0: movl 32(%4), %%eax\n"
31454 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31455 " cmpl $67, %0\n"
31456 " jbe 2f\n"
31457 - "1: movl 64(%4), %%eax\n"
31458 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31459 " .align 2,0x90\n"
31460 - "2: movl 0(%4), %%eax\n"
31461 - "21: movl 4(%4), %%edx\n"
31462 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31463 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31464 " movnti %%eax, 0(%3)\n"
31465 " movnti %%edx, 4(%3)\n"
31466 - "3: movl 8(%4), %%eax\n"
31467 - "31: movl 12(%4),%%edx\n"
31468 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31469 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31470 " movnti %%eax, 8(%3)\n"
31471 " movnti %%edx, 12(%3)\n"
31472 - "4: movl 16(%4), %%eax\n"
31473 - "41: movl 20(%4), %%edx\n"
31474 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31475 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31476 " movnti %%eax, 16(%3)\n"
31477 " movnti %%edx, 20(%3)\n"
31478 - "10: movl 24(%4), %%eax\n"
31479 - "51: movl 28(%4), %%edx\n"
31480 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31481 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31482 " movnti %%eax, 24(%3)\n"
31483 " movnti %%edx, 28(%3)\n"
31484 - "11: movl 32(%4), %%eax\n"
31485 - "61: movl 36(%4), %%edx\n"
31486 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31487 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31488 " movnti %%eax, 32(%3)\n"
31489 " movnti %%edx, 36(%3)\n"
31490 - "12: movl 40(%4), %%eax\n"
31491 - "71: movl 44(%4), %%edx\n"
31492 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31493 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31494 " movnti %%eax, 40(%3)\n"
31495 " movnti %%edx, 44(%3)\n"
31496 - "13: movl 48(%4), %%eax\n"
31497 - "81: movl 52(%4), %%edx\n"
31498 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31499 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31500 " movnti %%eax, 48(%3)\n"
31501 " movnti %%edx, 52(%3)\n"
31502 - "14: movl 56(%4), %%eax\n"
31503 - "91: movl 60(%4), %%edx\n"
31504 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31505 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31506 " movnti %%eax, 56(%3)\n"
31507 " movnti %%edx, 60(%3)\n"
31508 " addl $-64, %0\n"
31509 @@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
31510 " shrl $2, %0\n"
31511 " andl $3, %%eax\n"
31512 " cld\n"
31513 - "6: rep; movsl\n"
31514 + "6: rep; "__copyuser_seg" movsl\n"
31515 " movl %%eax,%0\n"
31516 - "7: rep; movsb\n"
31517 + "7: rep; "__copyuser_seg" movsb\n"
31518 "8:\n"
31519 ".section .fixup,\"ax\"\n"
31520 "9: lea 0(%%eax,%0,4),%0\n"
31521 @@ -399,41 +507,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
31522
31523 __asm__ __volatile__(
31524 " .align 2,0x90\n"
31525 - "0: movl 32(%4), %%eax\n"
31526 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31527 " cmpl $67, %0\n"
31528 " jbe 2f\n"
31529 - "1: movl 64(%4), %%eax\n"
31530 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31531 " .align 2,0x90\n"
31532 - "2: movl 0(%4), %%eax\n"
31533 - "21: movl 4(%4), %%edx\n"
31534 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31535 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31536 " movnti %%eax, 0(%3)\n"
31537 " movnti %%edx, 4(%3)\n"
31538 - "3: movl 8(%4), %%eax\n"
31539 - "31: movl 12(%4),%%edx\n"
31540 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31541 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31542 " movnti %%eax, 8(%3)\n"
31543 " movnti %%edx, 12(%3)\n"
31544 - "4: movl 16(%4), %%eax\n"
31545 - "41: movl 20(%4), %%edx\n"
31546 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31547 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31548 " movnti %%eax, 16(%3)\n"
31549 " movnti %%edx, 20(%3)\n"
31550 - "10: movl 24(%4), %%eax\n"
31551 - "51: movl 28(%4), %%edx\n"
31552 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31553 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31554 " movnti %%eax, 24(%3)\n"
31555 " movnti %%edx, 28(%3)\n"
31556 - "11: movl 32(%4), %%eax\n"
31557 - "61: movl 36(%4), %%edx\n"
31558 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31559 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31560 " movnti %%eax, 32(%3)\n"
31561 " movnti %%edx, 36(%3)\n"
31562 - "12: movl 40(%4), %%eax\n"
31563 - "71: movl 44(%4), %%edx\n"
31564 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31565 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31566 " movnti %%eax, 40(%3)\n"
31567 " movnti %%edx, 44(%3)\n"
31568 - "13: movl 48(%4), %%eax\n"
31569 - "81: movl 52(%4), %%edx\n"
31570 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31571 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31572 " movnti %%eax, 48(%3)\n"
31573 " movnti %%edx, 52(%3)\n"
31574 - "14: movl 56(%4), %%eax\n"
31575 - "91: movl 60(%4), %%edx\n"
31576 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31577 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31578 " movnti %%eax, 56(%3)\n"
31579 " movnti %%edx, 60(%3)\n"
31580 " addl $-64, %0\n"
31581 @@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
31582 " shrl $2, %0\n"
31583 " andl $3, %%eax\n"
31584 " cld\n"
31585 - "6: rep; movsl\n"
31586 + "6: rep; "__copyuser_seg" movsl\n"
31587 " movl %%eax,%0\n"
31588 - "7: rep; movsb\n"
31589 + "7: rep; "__copyuser_seg" movsb\n"
31590 "8:\n"
31591 ".section .fixup,\"ax\"\n"
31592 "9: lea 0(%%eax,%0,4),%0\n"
31593 @@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
31594 */
31595 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
31596 unsigned long size);
31597 -unsigned long __copy_user_intel(void __user *to, const void *from,
31598 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
31599 + unsigned long size);
31600 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
31601 unsigned long size);
31602 unsigned long __copy_user_zeroing_intel_nocache(void *to,
31603 const void __user *from, unsigned long size);
31604 #endif /* CONFIG_X86_INTEL_USERCOPY */
31605
31606 /* Generic arbitrary sized copy. */
31607 -#define __copy_user(to, from, size) \
31608 +#define __copy_user(to, from, size, prefix, set, restore) \
31609 do { \
31610 int __d0, __d1, __d2; \
31611 __asm__ __volatile__( \
31612 + set \
31613 " cmp $7,%0\n" \
31614 " jbe 1f\n" \
31615 " movl %1,%0\n" \
31616 " negl %0\n" \
31617 " andl $7,%0\n" \
31618 " subl %0,%3\n" \
31619 - "4: rep; movsb\n" \
31620 + "4: rep; "prefix"movsb\n" \
31621 " movl %3,%0\n" \
31622 " shrl $2,%0\n" \
31623 " andl $3,%3\n" \
31624 " .align 2,0x90\n" \
31625 - "0: rep; movsl\n" \
31626 + "0: rep; "prefix"movsl\n" \
31627 " movl %3,%0\n" \
31628 - "1: rep; movsb\n" \
31629 + "1: rep; "prefix"movsb\n" \
31630 "2:\n" \
31631 + restore \
31632 ".section .fixup,\"ax\"\n" \
31633 "5: addl %3,%0\n" \
31634 " jmp 2b\n" \
31635 @@ -538,14 +650,14 @@ do { \
31636 " negl %0\n" \
31637 " andl $7,%0\n" \
31638 " subl %0,%3\n" \
31639 - "4: rep; movsb\n" \
31640 + "4: rep; "__copyuser_seg"movsb\n" \
31641 " movl %3,%0\n" \
31642 " shrl $2,%0\n" \
31643 " andl $3,%3\n" \
31644 " .align 2,0x90\n" \
31645 - "0: rep; movsl\n" \
31646 + "0: rep; "__copyuser_seg"movsl\n" \
31647 " movl %3,%0\n" \
31648 - "1: rep; movsb\n" \
31649 + "1: rep; "__copyuser_seg"movsb\n" \
31650 "2:\n" \
31651 ".section .fixup,\"ax\"\n" \
31652 "5: addl %3,%0\n" \
31653 @@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
31654 {
31655 stac();
31656 if (movsl_is_ok(to, from, n))
31657 - __copy_user(to, from, n);
31658 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
31659 else
31660 - n = __copy_user_intel(to, from, n);
31661 + n = __generic_copy_to_user_intel(to, from, n);
31662 clac();
31663 return n;
31664 }
31665 @@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
31666 {
31667 stac();
31668 if (movsl_is_ok(to, from, n))
31669 - __copy_user(to, from, n);
31670 + __copy_user(to, from, n, __copyuser_seg, "", "");
31671 else
31672 - n = __copy_user_intel((void __user *)to,
31673 - (const void *)from, n);
31674 + n = __generic_copy_from_user_intel(to, from, n);
31675 clac();
31676 return n;
31677 }
31678 @@ -632,58 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
31679 if (n > 64 && cpu_has_xmm2)
31680 n = __copy_user_intel_nocache(to, from, n);
31681 else
31682 - __copy_user(to, from, n);
31683 + __copy_user(to, from, n, __copyuser_seg, "", "");
31684 #else
31685 - __copy_user(to, from, n);
31686 + __copy_user(to, from, n, __copyuser_seg, "", "");
31687 #endif
31688 clac();
31689 return n;
31690 }
31691 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
31692
31693 -/**
31694 - * copy_to_user: - Copy a block of data into user space.
31695 - * @to: Destination address, in user space.
31696 - * @from: Source address, in kernel space.
31697 - * @n: Number of bytes to copy.
31698 - *
31699 - * Context: User context only. This function may sleep.
31700 - *
31701 - * Copy data from kernel space to user space.
31702 - *
31703 - * Returns number of bytes that could not be copied.
31704 - * On success, this will be zero.
31705 - */
31706 -unsigned long _copy_to_user(void __user *to, const void *from, unsigned n)
31707 +#ifdef CONFIG_PAX_MEMORY_UDEREF
31708 +void __set_fs(mm_segment_t x)
31709 {
31710 - if (access_ok(VERIFY_WRITE, to, n))
31711 - n = __copy_to_user(to, from, n);
31712 - return n;
31713 + switch (x.seg) {
31714 + case 0:
31715 + loadsegment(gs, 0);
31716 + break;
31717 + case TASK_SIZE_MAX:
31718 + loadsegment(gs, __USER_DS);
31719 + break;
31720 + case -1UL:
31721 + loadsegment(gs, __KERNEL_DS);
31722 + break;
31723 + default:
31724 + BUG();
31725 + }
31726 }
31727 -EXPORT_SYMBOL(_copy_to_user);
31728 +EXPORT_SYMBOL(__set_fs);
31729
31730 -/**
31731 - * copy_from_user: - Copy a block of data from user space.
31732 - * @to: Destination address, in kernel space.
31733 - * @from: Source address, in user space.
31734 - * @n: Number of bytes to copy.
31735 - *
31736 - * Context: User context only. This function may sleep.
31737 - *
31738 - * Copy data from user space to kernel space.
31739 - *
31740 - * Returns number of bytes that could not be copied.
31741 - * On success, this will be zero.
31742 - *
31743 - * If some data could not be copied, this function will pad the copied
31744 - * data to the requested size using zero bytes.
31745 - */
31746 -unsigned long _copy_from_user(void *to, const void __user *from, unsigned n)
31747 +void set_fs(mm_segment_t x)
31748 {
31749 - if (access_ok(VERIFY_READ, from, n))
31750 - n = __copy_from_user(to, from, n);
31751 - else
31752 - memset(to, 0, n);
31753 - return n;
31754 + current_thread_info()->addr_limit = x;
31755 + __set_fs(x);
31756 }
31757 -EXPORT_SYMBOL(_copy_from_user);
31758 +EXPORT_SYMBOL(set_fs);
31759 +#endif
31760 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
31761 index c905e89..01ab928 100644
31762 --- a/arch/x86/lib/usercopy_64.c
31763 +++ b/arch/x86/lib/usercopy_64.c
31764 @@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31765 might_fault();
31766 /* no memory constraint because it doesn't change any memory gcc knows
31767 about */
31768 + pax_open_userland();
31769 stac();
31770 asm volatile(
31771 " testq %[size8],%[size8]\n"
31772 @@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31773 _ASM_EXTABLE(0b,3b)
31774 _ASM_EXTABLE(1b,2b)
31775 : [size8] "=&c"(size), [dst] "=&D" (__d0)
31776 - : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
31777 + : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
31778 [zero] "r" (0UL), [eight] "r" (8UL));
31779 clac();
31780 + pax_close_userland();
31781 return size;
31782 }
31783 EXPORT_SYMBOL(__clear_user);
31784 @@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
31785 }
31786 EXPORT_SYMBOL(clear_user);
31787
31788 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
31789 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
31790 {
31791 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
31792 - return copy_user_generic((__force void *)to, (__force void *)from, len);
31793 - }
31794 - return len;
31795 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
31796 + return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
31797 + return len;
31798 }
31799 EXPORT_SYMBOL(copy_in_user);
31800
31801 @@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
31802 * it is not necessary to optimize tail handling.
31803 */
31804 __visible unsigned long
31805 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31806 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
31807 {
31808 char c;
31809 unsigned zero_len;
31810
31811 + clac();
31812 + pax_close_userland();
31813 for (; len; --len, to++) {
31814 if (__get_user_nocheck(c, from++, sizeof(char)))
31815 break;
31816 @@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31817 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
31818 if (__put_user_nocheck(c, to++, sizeof(char)))
31819 break;
31820 - clac();
31821 return len;
31822 }
31823 diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
31824 index 6a19ad9..1c48f9a 100644
31825 --- a/arch/x86/mm/Makefile
31826 +++ b/arch/x86/mm/Makefile
31827 @@ -30,3 +30,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
31828 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
31829
31830 obj-$(CONFIG_MEMTEST) += memtest.o
31831 +
31832 +quote:="
31833 +obj-$(CONFIG_X86_64) += uderef_64.o
31834 +CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
31835 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
31836 index 903ec1e..c4166b2 100644
31837 --- a/arch/x86/mm/extable.c
31838 +++ b/arch/x86/mm/extable.c
31839 @@ -6,12 +6,24 @@
31840 static inline unsigned long
31841 ex_insn_addr(const struct exception_table_entry *x)
31842 {
31843 - return (unsigned long)&x->insn + x->insn;
31844 + unsigned long reloc = 0;
31845 +
31846 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31847 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31848 +#endif
31849 +
31850 + return (unsigned long)&x->insn + x->insn + reloc;
31851 }
31852 static inline unsigned long
31853 ex_fixup_addr(const struct exception_table_entry *x)
31854 {
31855 - return (unsigned long)&x->fixup + x->fixup;
31856 + unsigned long reloc = 0;
31857 +
31858 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31859 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31860 +#endif
31861 +
31862 + return (unsigned long)&x->fixup + x->fixup + reloc;
31863 }
31864
31865 int fixup_exception(struct pt_regs *regs)
31866 @@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
31867 unsigned long new_ip;
31868
31869 #ifdef CONFIG_PNPBIOS
31870 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
31871 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
31872 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
31873 extern u32 pnp_bios_is_utter_crap;
31874 pnp_bios_is_utter_crap = 1;
31875 @@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
31876 i += 4;
31877 p->fixup -= i;
31878 i += 4;
31879 +
31880 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31881 + BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
31882 + p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31883 + p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31884 +#endif
31885 +
31886 }
31887 }
31888
31889 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
31890 index 3664279..c6a7830 100644
31891 --- a/arch/x86/mm/fault.c
31892 +++ b/arch/x86/mm/fault.c
31893 @@ -14,12 +14,19 @@
31894 #include <linux/hugetlb.h> /* hstate_index_to_shift */
31895 #include <linux/prefetch.h> /* prefetchw */
31896 #include <linux/context_tracking.h> /* exception_enter(), ... */
31897 +#include <linux/unistd.h>
31898 +#include <linux/compiler.h>
31899
31900 #include <asm/traps.h> /* dotraplinkage, ... */
31901 #include <asm/pgalloc.h> /* pgd_*(), ... */
31902 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
31903 #include <asm/fixmap.h> /* VSYSCALL_ADDR */
31904 #include <asm/vsyscall.h> /* emulate_vsyscall */
31905 +#include <asm/tlbflush.h>
31906 +
31907 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31908 +#include <asm/stacktrace.h>
31909 +#endif
31910
31911 #define CREATE_TRACE_POINTS
31912 #include <asm/trace/exceptions.h>
31913 @@ -60,7 +67,7 @@ static nokprobe_inline int kprobes_fault(struct pt_regs *regs)
31914 int ret = 0;
31915
31916 /* kprobe_running() needs smp_processor_id() */
31917 - if (kprobes_built_in() && !user_mode_vm(regs)) {
31918 + if (kprobes_built_in() && !user_mode(regs)) {
31919 preempt_disable();
31920 if (kprobe_running() && kprobe_fault_handler(regs, 14))
31921 ret = 1;
31922 @@ -121,7 +128,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
31923 return !instr_lo || (instr_lo>>1) == 1;
31924 case 0x00:
31925 /* Prefetch instruction is 0x0F0D or 0x0F18 */
31926 - if (probe_kernel_address(instr, opcode))
31927 + if (user_mode(regs)) {
31928 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31929 + return 0;
31930 + } else if (probe_kernel_address(instr, opcode))
31931 return 0;
31932
31933 *prefetch = (instr_lo == 0xF) &&
31934 @@ -155,7 +165,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
31935 while (instr < max_instr) {
31936 unsigned char opcode;
31937
31938 - if (probe_kernel_address(instr, opcode))
31939 + if (user_mode(regs)) {
31940 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31941 + break;
31942 + } else if (probe_kernel_address(instr, opcode))
31943 break;
31944
31945 instr++;
31946 @@ -186,6 +199,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
31947 force_sig_info(si_signo, &info, tsk);
31948 }
31949
31950 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31951 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
31952 +#endif
31953 +
31954 +#ifdef CONFIG_PAX_EMUTRAMP
31955 +static int pax_handle_fetch_fault(struct pt_regs *regs);
31956 +#endif
31957 +
31958 +#ifdef CONFIG_PAX_PAGEEXEC
31959 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
31960 +{
31961 + pgd_t *pgd;
31962 + pud_t *pud;
31963 + pmd_t *pmd;
31964 +
31965 + pgd = pgd_offset(mm, address);
31966 + if (!pgd_present(*pgd))
31967 + return NULL;
31968 + pud = pud_offset(pgd, address);
31969 + if (!pud_present(*pud))
31970 + return NULL;
31971 + pmd = pmd_offset(pud, address);
31972 + if (!pmd_present(*pmd))
31973 + return NULL;
31974 + return pmd;
31975 +}
31976 +#endif
31977 +
31978 DEFINE_SPINLOCK(pgd_lock);
31979 LIST_HEAD(pgd_list);
31980
31981 @@ -236,10 +277,27 @@ void vmalloc_sync_all(void)
31982 for (address = VMALLOC_START & PMD_MASK;
31983 address >= TASK_SIZE && address < FIXADDR_TOP;
31984 address += PMD_SIZE) {
31985 +
31986 +#ifdef CONFIG_PAX_PER_CPU_PGD
31987 + unsigned long cpu;
31988 +#else
31989 struct page *page;
31990 +#endif
31991
31992 spin_lock(&pgd_lock);
31993 +
31994 +#ifdef CONFIG_PAX_PER_CPU_PGD
31995 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
31996 + pgd_t *pgd = get_cpu_pgd(cpu, user);
31997 + pmd_t *ret;
31998 +
31999 + ret = vmalloc_sync_one(pgd, address);
32000 + if (!ret)
32001 + break;
32002 + pgd = get_cpu_pgd(cpu, kernel);
32003 +#else
32004 list_for_each_entry(page, &pgd_list, lru) {
32005 + pgd_t *pgd;
32006 spinlock_t *pgt_lock;
32007 pmd_t *ret;
32008
32009 @@ -247,8 +305,14 @@ void vmalloc_sync_all(void)
32010 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
32011
32012 spin_lock(pgt_lock);
32013 - ret = vmalloc_sync_one(page_address(page), address);
32014 + pgd = page_address(page);
32015 +#endif
32016 +
32017 + ret = vmalloc_sync_one(pgd, address);
32018 +
32019 +#ifndef CONFIG_PAX_PER_CPU_PGD
32020 spin_unlock(pgt_lock);
32021 +#endif
32022
32023 if (!ret)
32024 break;
32025 @@ -282,6 +346,12 @@ static noinline int vmalloc_fault(unsigned long address)
32026 * an interrupt in the middle of a task switch..
32027 */
32028 pgd_paddr = read_cr3();
32029 +
32030 +#ifdef CONFIG_PAX_PER_CPU_PGD
32031 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
32032 + vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
32033 +#endif
32034 +
32035 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
32036 if (!pmd_k)
32037 return -1;
32038 @@ -378,11 +448,25 @@ static noinline int vmalloc_fault(unsigned long address)
32039 * happen within a race in page table update. In the later
32040 * case just flush:
32041 */
32042 - pgd = pgd_offset(current->active_mm, address);
32043 +
32044 pgd_ref = pgd_offset_k(address);
32045 if (pgd_none(*pgd_ref))
32046 return -1;
32047
32048 +#ifdef CONFIG_PAX_PER_CPU_PGD
32049 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
32050 + pgd = pgd_offset_cpu(smp_processor_id(), user, address);
32051 + if (pgd_none(*pgd)) {
32052 + set_pgd(pgd, *pgd_ref);
32053 + arch_flush_lazy_mmu_mode();
32054 + } else {
32055 + BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
32056 + }
32057 + pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
32058 +#else
32059 + pgd = pgd_offset(current->active_mm, address);
32060 +#endif
32061 +
32062 if (pgd_none(*pgd)) {
32063 set_pgd(pgd, *pgd_ref);
32064 arch_flush_lazy_mmu_mode();
32065 @@ -549,7 +633,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
32066 static int is_errata100(struct pt_regs *regs, unsigned long address)
32067 {
32068 #ifdef CONFIG_X86_64
32069 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
32070 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
32071 return 1;
32072 #endif
32073 return 0;
32074 @@ -576,7 +660,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
32075 }
32076
32077 static const char nx_warning[] = KERN_CRIT
32078 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
32079 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
32080
32081 static void
32082 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
32083 @@ -585,7 +669,7 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
32084 if (!oops_may_print())
32085 return;
32086
32087 - if (error_code & PF_INSTR) {
32088 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
32089 unsigned int level;
32090 pgd_t *pgd;
32091 pte_t *pte;
32092 @@ -596,9 +680,21 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
32093 pte = lookup_address_in_pgd(pgd, address, &level);
32094
32095 if (pte && pte_present(*pte) && !pte_exec(*pte))
32096 - printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
32097 + printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
32098 }
32099
32100 +#ifdef CONFIG_PAX_KERNEXEC
32101 + if (init_mm.start_code <= address && address < init_mm.end_code) {
32102 + if (current->signal->curr_ip)
32103 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
32104 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
32105 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
32106 + else
32107 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
32108 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
32109 + }
32110 +#endif
32111 +
32112 printk(KERN_ALERT "BUG: unable to handle kernel ");
32113 if (address < PAGE_SIZE)
32114 printk(KERN_CONT "NULL pointer dereference");
32115 @@ -779,6 +875,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
32116 return;
32117 }
32118 #endif
32119 +
32120 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32121 + if (pax_is_fetch_fault(regs, error_code, address)) {
32122 +
32123 +#ifdef CONFIG_PAX_EMUTRAMP
32124 + switch (pax_handle_fetch_fault(regs)) {
32125 + case 2:
32126 + return;
32127 + }
32128 +#endif
32129 +
32130 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
32131 + do_group_exit(SIGKILL);
32132 + }
32133 +#endif
32134 +
32135 /* Kernel addresses are always protection faults: */
32136 if (address >= TASK_SIZE)
32137 error_code |= PF_PROT;
32138 @@ -864,7 +976,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
32139 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
32140 printk(KERN_ERR
32141 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
32142 - tsk->comm, tsk->pid, address);
32143 + tsk->comm, task_pid_nr(tsk), address);
32144 code = BUS_MCEERR_AR;
32145 }
32146 #endif
32147 @@ -918,6 +1030,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
32148 return 1;
32149 }
32150
32151 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
32152 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
32153 +{
32154 + pte_t *pte;
32155 + pmd_t *pmd;
32156 + spinlock_t *ptl;
32157 + unsigned char pte_mask;
32158 +
32159 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
32160 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
32161 + return 0;
32162 +
32163 + /* PaX: it's our fault, let's handle it if we can */
32164 +
32165 + /* PaX: take a look at read faults before acquiring any locks */
32166 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
32167 + /* instruction fetch attempt from a protected page in user mode */
32168 + up_read(&mm->mmap_sem);
32169 +
32170 +#ifdef CONFIG_PAX_EMUTRAMP
32171 + switch (pax_handle_fetch_fault(regs)) {
32172 + case 2:
32173 + return 1;
32174 + }
32175 +#endif
32176 +
32177 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
32178 + do_group_exit(SIGKILL);
32179 + }
32180 +
32181 + pmd = pax_get_pmd(mm, address);
32182 + if (unlikely(!pmd))
32183 + return 0;
32184 +
32185 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
32186 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
32187 + pte_unmap_unlock(pte, ptl);
32188 + return 0;
32189 + }
32190 +
32191 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
32192 + /* write attempt to a protected page in user mode */
32193 + pte_unmap_unlock(pte, ptl);
32194 + return 0;
32195 + }
32196 +
32197 +#ifdef CONFIG_SMP
32198 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
32199 +#else
32200 + if (likely(address > get_limit(regs->cs)))
32201 +#endif
32202 + {
32203 + set_pte(pte, pte_mkread(*pte));
32204 + __flush_tlb_one(address);
32205 + pte_unmap_unlock(pte, ptl);
32206 + up_read(&mm->mmap_sem);
32207 + return 1;
32208 + }
32209 +
32210 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
32211 +
32212 + /*
32213 + * PaX: fill DTLB with user rights and retry
32214 + */
32215 + __asm__ __volatile__ (
32216 + "orb %2,(%1)\n"
32217 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
32218 +/*
32219 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
32220 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
32221 + * page fault when examined during a TLB load attempt. this is true not only
32222 + * for PTEs holding a non-present entry but also present entries that will
32223 + * raise a page fault (such as those set up by PaX, or the copy-on-write
32224 + * mechanism). in effect it means that we do *not* need to flush the TLBs
32225 + * for our target pages since their PTEs are simply not in the TLBs at all.
32226 +
32227 + * the best thing in omitting it is that we gain around 15-20% speed in the
32228 + * fast path of the page fault handler and can get rid of tracing since we
32229 + * can no longer flush unintended entries.
32230 + */
32231 + "invlpg (%0)\n"
32232 +#endif
32233 + __copyuser_seg"testb $0,(%0)\n"
32234 + "xorb %3,(%1)\n"
32235 + :
32236 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
32237 + : "memory", "cc");
32238 + pte_unmap_unlock(pte, ptl);
32239 + up_read(&mm->mmap_sem);
32240 + return 1;
32241 +}
32242 +#endif
32243 +
32244 /*
32245 * Handle a spurious fault caused by a stale TLB entry.
32246 *
32247 @@ -985,6 +1190,9 @@ int show_unhandled_signals = 1;
32248 static inline int
32249 access_error(unsigned long error_code, struct vm_area_struct *vma)
32250 {
32251 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
32252 + return 1;
32253 +
32254 if (error_code & PF_WRITE) {
32255 /* write, present and write, not present: */
32256 if (unlikely(!(vma->vm_flags & VM_WRITE)))
32257 @@ -1019,7 +1227,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
32258 if (error_code & PF_USER)
32259 return false;
32260
32261 - if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
32262 + if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
32263 return false;
32264
32265 return true;
32266 @@ -1047,6 +1255,22 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
32267 tsk = current;
32268 mm = tsk->mm;
32269
32270 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
32271 + if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
32272 + if (!search_exception_tables(regs->ip)) {
32273 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
32274 + bad_area_nosemaphore(regs, error_code, address);
32275 + return;
32276 + }
32277 + if (address < pax_user_shadow_base) {
32278 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
32279 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
32280 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
32281 + } else
32282 + address -= pax_user_shadow_base;
32283 + }
32284 +#endif
32285 +
32286 /*
32287 * Detect and handle instructions that would cause a page fault for
32288 * both a tracked kernel page and a userspace page.
32289 @@ -1124,7 +1348,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
32290 * User-mode registers count as a user access even for any
32291 * potential system fault or CPU buglet:
32292 */
32293 - if (user_mode_vm(regs)) {
32294 + if (user_mode(regs)) {
32295 local_irq_enable();
32296 error_code |= PF_USER;
32297 flags |= FAULT_FLAG_USER;
32298 @@ -1171,6 +1395,11 @@ retry:
32299 might_sleep();
32300 }
32301
32302 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
32303 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
32304 + return;
32305 +#endif
32306 +
32307 vma = find_vma(mm, address);
32308 if (unlikely(!vma)) {
32309 bad_area(regs, error_code, address);
32310 @@ -1182,18 +1411,24 @@ retry:
32311 bad_area(regs, error_code, address);
32312 return;
32313 }
32314 - if (error_code & PF_USER) {
32315 - /*
32316 - * Accessing the stack below %sp is always a bug.
32317 - * The large cushion allows instructions like enter
32318 - * and pusha to work. ("enter $65535, $31" pushes
32319 - * 32 pointers and then decrements %sp by 65535.)
32320 - */
32321 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
32322 - bad_area(regs, error_code, address);
32323 - return;
32324 - }
32325 + /*
32326 + * Accessing the stack below %sp is always a bug.
32327 + * The large cushion allows instructions like enter
32328 + * and pusha to work. ("enter $65535, $31" pushes
32329 + * 32 pointers and then decrements %sp by 65535.)
32330 + */
32331 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
32332 + bad_area(regs, error_code, address);
32333 + return;
32334 }
32335 +
32336 +#ifdef CONFIG_PAX_SEGMEXEC
32337 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
32338 + bad_area(regs, error_code, address);
32339 + return;
32340 + }
32341 +#endif
32342 +
32343 if (unlikely(expand_stack(vma, address))) {
32344 bad_area(regs, error_code, address);
32345 return;
32346 @@ -1309,3 +1544,292 @@ trace_do_page_fault(struct pt_regs *regs, unsigned long error_code)
32347 }
32348 NOKPROBE_SYMBOL(trace_do_page_fault);
32349 #endif /* CONFIG_TRACING */
32350 +
32351 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32352 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
32353 +{
32354 + struct mm_struct *mm = current->mm;
32355 + unsigned long ip = regs->ip;
32356 +
32357 + if (v8086_mode(regs))
32358 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
32359 +
32360 +#ifdef CONFIG_PAX_PAGEEXEC
32361 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
32362 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
32363 + return true;
32364 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
32365 + return true;
32366 + return false;
32367 + }
32368 +#endif
32369 +
32370 +#ifdef CONFIG_PAX_SEGMEXEC
32371 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
32372 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
32373 + return true;
32374 + return false;
32375 + }
32376 +#endif
32377 +
32378 + return false;
32379 +}
32380 +#endif
32381 +
32382 +#ifdef CONFIG_PAX_EMUTRAMP
32383 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
32384 +{
32385 + int err;
32386 +
32387 + do { /* PaX: libffi trampoline emulation */
32388 + unsigned char mov, jmp;
32389 + unsigned int addr1, addr2;
32390 +
32391 +#ifdef CONFIG_X86_64
32392 + if ((regs->ip + 9) >> 32)
32393 + break;
32394 +#endif
32395 +
32396 + err = get_user(mov, (unsigned char __user *)regs->ip);
32397 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32398 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
32399 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32400 +
32401 + if (err)
32402 + break;
32403 +
32404 + if (mov == 0xB8 && jmp == 0xE9) {
32405 + regs->ax = addr1;
32406 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
32407 + return 2;
32408 + }
32409 + } while (0);
32410 +
32411 + do { /* PaX: gcc trampoline emulation #1 */
32412 + unsigned char mov1, mov2;
32413 + unsigned short jmp;
32414 + unsigned int addr1, addr2;
32415 +
32416 +#ifdef CONFIG_X86_64
32417 + if ((regs->ip + 11) >> 32)
32418 + break;
32419 +#endif
32420 +
32421 + err = get_user(mov1, (unsigned char __user *)regs->ip);
32422 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32423 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
32424 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32425 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
32426 +
32427 + if (err)
32428 + break;
32429 +
32430 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
32431 + regs->cx = addr1;
32432 + regs->ax = addr2;
32433 + regs->ip = addr2;
32434 + return 2;
32435 + }
32436 + } while (0);
32437 +
32438 + do { /* PaX: gcc trampoline emulation #2 */
32439 + unsigned char mov, jmp;
32440 + unsigned int addr1, addr2;
32441 +
32442 +#ifdef CONFIG_X86_64
32443 + if ((regs->ip + 9) >> 32)
32444 + break;
32445 +#endif
32446 +
32447 + err = get_user(mov, (unsigned char __user *)regs->ip);
32448 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32449 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
32450 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32451 +
32452 + if (err)
32453 + break;
32454 +
32455 + if (mov == 0xB9 && jmp == 0xE9) {
32456 + regs->cx = addr1;
32457 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
32458 + return 2;
32459 + }
32460 + } while (0);
32461 +
32462 + return 1; /* PaX in action */
32463 +}
32464 +
32465 +#ifdef CONFIG_X86_64
32466 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
32467 +{
32468 + int err;
32469 +
32470 + do { /* PaX: libffi trampoline emulation */
32471 + unsigned short mov1, mov2, jmp1;
32472 + unsigned char stcclc, jmp2;
32473 + unsigned long addr1, addr2;
32474 +
32475 + err = get_user(mov1, (unsigned short __user *)regs->ip);
32476 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
32477 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
32478 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
32479 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
32480 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
32481 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
32482 +
32483 + if (err)
32484 + break;
32485 +
32486 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32487 + regs->r11 = addr1;
32488 + regs->r10 = addr2;
32489 + if (stcclc == 0xF8)
32490 + regs->flags &= ~X86_EFLAGS_CF;
32491 + else
32492 + regs->flags |= X86_EFLAGS_CF;
32493 + regs->ip = addr1;
32494 + return 2;
32495 + }
32496 + } while (0);
32497 +
32498 + do { /* PaX: gcc trampoline emulation #1 */
32499 + unsigned short mov1, mov2, jmp1;
32500 + unsigned char jmp2;
32501 + unsigned int addr1;
32502 + unsigned long addr2;
32503 +
32504 + err = get_user(mov1, (unsigned short __user *)regs->ip);
32505 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
32506 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
32507 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
32508 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
32509 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
32510 +
32511 + if (err)
32512 + break;
32513 +
32514 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32515 + regs->r11 = addr1;
32516 + regs->r10 = addr2;
32517 + regs->ip = addr1;
32518 + return 2;
32519 + }
32520 + } while (0);
32521 +
32522 + do { /* PaX: gcc trampoline emulation #2 */
32523 + unsigned short mov1, mov2, jmp1;
32524 + unsigned char jmp2;
32525 + unsigned long addr1, addr2;
32526 +
32527 + err = get_user(mov1, (unsigned short __user *)regs->ip);
32528 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
32529 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
32530 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
32531 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
32532 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
32533 +
32534 + if (err)
32535 + break;
32536 +
32537 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32538 + regs->r11 = addr1;
32539 + regs->r10 = addr2;
32540 + regs->ip = addr1;
32541 + return 2;
32542 + }
32543 + } while (0);
32544 +
32545 + return 1; /* PaX in action */
32546 +}
32547 +#endif
32548 +
32549 +/*
32550 + * PaX: decide what to do with offenders (regs->ip = fault address)
32551 + *
32552 + * returns 1 when task should be killed
32553 + * 2 when gcc trampoline was detected
32554 + */
32555 +static int pax_handle_fetch_fault(struct pt_regs *regs)
32556 +{
32557 + if (v8086_mode(regs))
32558 + return 1;
32559 +
32560 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
32561 + return 1;
32562 +
32563 +#ifdef CONFIG_X86_32
32564 + return pax_handle_fetch_fault_32(regs);
32565 +#else
32566 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
32567 + return pax_handle_fetch_fault_32(regs);
32568 + else
32569 + return pax_handle_fetch_fault_64(regs);
32570 +#endif
32571 +}
32572 +#endif
32573 +
32574 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32575 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
32576 +{
32577 + long i;
32578 +
32579 + printk(KERN_ERR "PAX: bytes at PC: ");
32580 + for (i = 0; i < 20; i++) {
32581 + unsigned char c;
32582 + if (get_user(c, (unsigned char __force_user *)pc+i))
32583 + printk(KERN_CONT "?? ");
32584 + else
32585 + printk(KERN_CONT "%02x ", c);
32586 + }
32587 + printk("\n");
32588 +
32589 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
32590 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
32591 + unsigned long c;
32592 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
32593 +#ifdef CONFIG_X86_32
32594 + printk(KERN_CONT "???????? ");
32595 +#else
32596 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
32597 + printk(KERN_CONT "???????? ???????? ");
32598 + else
32599 + printk(KERN_CONT "???????????????? ");
32600 +#endif
32601 + } else {
32602 +#ifdef CONFIG_X86_64
32603 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
32604 + printk(KERN_CONT "%08x ", (unsigned int)c);
32605 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
32606 + } else
32607 +#endif
32608 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
32609 + }
32610 + }
32611 + printk("\n");
32612 +}
32613 +#endif
32614 +
32615 +/**
32616 + * probe_kernel_write(): safely attempt to write to a location
32617 + * @dst: address to write to
32618 + * @src: pointer to the data that shall be written
32619 + * @size: size of the data chunk
32620 + *
32621 + * Safely write to address @dst from the buffer at @src. If a kernel fault
32622 + * happens, handle that and return -EFAULT.
32623 + */
32624 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
32625 +{
32626 + long ret;
32627 + mm_segment_t old_fs = get_fs();
32628 +
32629 + set_fs(KERNEL_DS);
32630 + pagefault_disable();
32631 + pax_open_kernel();
32632 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
32633 + pax_close_kernel();
32634 + pagefault_enable();
32635 + set_fs(old_fs);
32636 +
32637 + return ret ? -EFAULT : 0;
32638 +}
32639 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
32640 index 207d9aef..69030980 100644
32641 --- a/arch/x86/mm/gup.c
32642 +++ b/arch/x86/mm/gup.c
32643 @@ -268,7 +268,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
32644 addr = start;
32645 len = (unsigned long) nr_pages << PAGE_SHIFT;
32646 end = start + len;
32647 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
32648 + if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
32649 (void __user *)start, len)))
32650 return 0;
32651
32652 @@ -344,6 +344,10 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
32653 goto slow_irqon;
32654 #endif
32655
32656 + if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
32657 + (void __user *)start, len)))
32658 + return 0;
32659 +
32660 /*
32661 * XXX: batch / limit 'nr', to avoid large irq off latency
32662 * needs some instrumenting to determine the common sizes used by
32663 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
32664 index 4500142..53a363c 100644
32665 --- a/arch/x86/mm/highmem_32.c
32666 +++ b/arch/x86/mm/highmem_32.c
32667 @@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
32668 idx = type + KM_TYPE_NR*smp_processor_id();
32669 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
32670 BUG_ON(!pte_none(*(kmap_pte-idx)));
32671 +
32672 + pax_open_kernel();
32673 set_pte(kmap_pte-idx, mk_pte(page, prot));
32674 + pax_close_kernel();
32675 +
32676 arch_flush_lazy_mmu_mode();
32677
32678 return (void *)vaddr;
32679 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
32680 index 8b977eb..4732c33 100644
32681 --- a/arch/x86/mm/hugetlbpage.c
32682 +++ b/arch/x86/mm/hugetlbpage.c
32683 @@ -80,23 +80,24 @@ int pud_huge(pud_t pud)
32684 #ifdef CONFIG_HUGETLB_PAGE
32685 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
32686 unsigned long addr, unsigned long len,
32687 - unsigned long pgoff, unsigned long flags)
32688 + unsigned long pgoff, unsigned long flags, unsigned long offset)
32689 {
32690 struct hstate *h = hstate_file(file);
32691 struct vm_unmapped_area_info info;
32692 -
32693 +
32694 info.flags = 0;
32695 info.length = len;
32696 info.low_limit = current->mm->mmap_legacy_base;
32697 info.high_limit = TASK_SIZE;
32698 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32699 info.align_offset = 0;
32700 + info.threadstack_offset = offset;
32701 return vm_unmapped_area(&info);
32702 }
32703
32704 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32705 unsigned long addr0, unsigned long len,
32706 - unsigned long pgoff, unsigned long flags)
32707 + unsigned long pgoff, unsigned long flags, unsigned long offset)
32708 {
32709 struct hstate *h = hstate_file(file);
32710 struct vm_unmapped_area_info info;
32711 @@ -108,6 +109,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32712 info.high_limit = current->mm->mmap_base;
32713 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32714 info.align_offset = 0;
32715 + info.threadstack_offset = offset;
32716 addr = vm_unmapped_area(&info);
32717
32718 /*
32719 @@ -120,6 +122,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32720 VM_BUG_ON(addr != -ENOMEM);
32721 info.flags = 0;
32722 info.low_limit = TASK_UNMAPPED_BASE;
32723 +
32724 +#ifdef CONFIG_PAX_RANDMMAP
32725 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
32726 + info.low_limit += current->mm->delta_mmap;
32727 +#endif
32728 +
32729 info.high_limit = TASK_SIZE;
32730 addr = vm_unmapped_area(&info);
32731 }
32732 @@ -134,10 +142,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32733 struct hstate *h = hstate_file(file);
32734 struct mm_struct *mm = current->mm;
32735 struct vm_area_struct *vma;
32736 + unsigned long pax_task_size = TASK_SIZE;
32737 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
32738
32739 if (len & ~huge_page_mask(h))
32740 return -EINVAL;
32741 - if (len > TASK_SIZE)
32742 +
32743 +#ifdef CONFIG_PAX_SEGMEXEC
32744 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
32745 + pax_task_size = SEGMEXEC_TASK_SIZE;
32746 +#endif
32747 +
32748 + pax_task_size -= PAGE_SIZE;
32749 +
32750 + if (len > pax_task_size)
32751 return -ENOMEM;
32752
32753 if (flags & MAP_FIXED) {
32754 @@ -146,19 +164,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32755 return addr;
32756 }
32757
32758 +#ifdef CONFIG_PAX_RANDMMAP
32759 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
32760 +#endif
32761 +
32762 if (addr) {
32763 addr = ALIGN(addr, huge_page_size(h));
32764 vma = find_vma(mm, addr);
32765 - if (TASK_SIZE - len >= addr &&
32766 - (!vma || addr + len <= vma->vm_start))
32767 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
32768 return addr;
32769 }
32770 if (mm->get_unmapped_area == arch_get_unmapped_area)
32771 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
32772 - pgoff, flags);
32773 + pgoff, flags, offset);
32774 else
32775 return hugetlb_get_unmapped_area_topdown(file, addr, len,
32776 - pgoff, flags);
32777 + pgoff, flags, offset);
32778 }
32779 #endif /* CONFIG_HUGETLB_PAGE */
32780
32781 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
32782 index f971306..e83e0f6 100644
32783 --- a/arch/x86/mm/init.c
32784 +++ b/arch/x86/mm/init.c
32785 @@ -4,6 +4,7 @@
32786 #include <linux/swap.h>
32787 #include <linux/memblock.h>
32788 #include <linux/bootmem.h> /* for max_low_pfn */
32789 +#include <linux/tboot.h>
32790
32791 #include <asm/cacheflush.h>
32792 #include <asm/e820.h>
32793 @@ -17,6 +18,8 @@
32794 #include <asm/proto.h>
32795 #include <asm/dma.h> /* for MAX_DMA_PFN */
32796 #include <asm/microcode.h>
32797 +#include <asm/desc.h>
32798 +#include <asm/bios_ebda.h>
32799
32800 #include "mm_internal.h"
32801
32802 @@ -563,7 +566,18 @@ void __init init_mem_mapping(void)
32803 early_ioremap_page_table_range_init();
32804 #endif
32805
32806 +#ifdef CONFIG_PAX_PER_CPU_PGD
32807 + clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
32808 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32809 + KERNEL_PGD_PTRS);
32810 + clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
32811 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32812 + KERNEL_PGD_PTRS);
32813 + load_cr3(get_cpu_pgd(0, kernel));
32814 +#else
32815 load_cr3(swapper_pg_dir);
32816 +#endif
32817 +
32818 __flush_tlb_all();
32819
32820 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
32821 @@ -579,10 +593,40 @@ void __init init_mem_mapping(void)
32822 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
32823 * mmio resources as well as potential bios/acpi data regions.
32824 */
32825 +
32826 +#ifdef CONFIG_GRKERNSEC_KMEM
32827 +static unsigned int ebda_start __read_only;
32828 +static unsigned int ebda_end __read_only;
32829 +#endif
32830 +
32831 int devmem_is_allowed(unsigned long pagenr)
32832 {
32833 - if (pagenr < 256)
32834 +#ifdef CONFIG_GRKERNSEC_KMEM
32835 + /* allow BDA */
32836 + if (!pagenr)
32837 return 1;
32838 + /* allow EBDA */
32839 + if (pagenr >= ebda_start && pagenr < ebda_end)
32840 + return 1;
32841 + /* if tboot is in use, allow access to its hardcoded serial log range */
32842 + if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
32843 + return 1;
32844 +#else
32845 + if (!pagenr)
32846 + return 1;
32847 +#ifdef CONFIG_VM86
32848 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
32849 + return 1;
32850 +#endif
32851 +#endif
32852 +
32853 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
32854 + return 1;
32855 +#ifdef CONFIG_GRKERNSEC_KMEM
32856 + /* throw out everything else below 1MB */
32857 + if (pagenr <= 256)
32858 + return 0;
32859 +#endif
32860 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
32861 return 0;
32862 if (!page_is_ram(pagenr))
32863 @@ -628,8 +672,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
32864 #endif
32865 }
32866
32867 +#ifdef CONFIG_GRKERNSEC_KMEM
32868 +static inline void gr_init_ebda(void)
32869 +{
32870 + unsigned int ebda_addr;
32871 + unsigned int ebda_size = 0;
32872 +
32873 + ebda_addr = get_bios_ebda();
32874 + if (ebda_addr) {
32875 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
32876 + ebda_size <<= 10;
32877 + }
32878 + if (ebda_addr && ebda_size) {
32879 + ebda_start = ebda_addr >> PAGE_SHIFT;
32880 + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
32881 + } else {
32882 + ebda_start = 0x9f000 >> PAGE_SHIFT;
32883 + ebda_end = 0xa0000 >> PAGE_SHIFT;
32884 + }
32885 +}
32886 +#else
32887 +static inline void gr_init_ebda(void) { }
32888 +#endif
32889 +
32890 void free_initmem(void)
32891 {
32892 +#ifdef CONFIG_PAX_KERNEXEC
32893 +#ifdef CONFIG_X86_32
32894 + /* PaX: limit KERNEL_CS to actual size */
32895 + unsigned long addr, limit;
32896 + struct desc_struct d;
32897 + int cpu;
32898 +#else
32899 + pgd_t *pgd;
32900 + pud_t *pud;
32901 + pmd_t *pmd;
32902 + unsigned long addr, end;
32903 +#endif
32904 +#endif
32905 +
32906 + gr_init_ebda();
32907 +
32908 +#ifdef CONFIG_PAX_KERNEXEC
32909 +#ifdef CONFIG_X86_32
32910 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
32911 + limit = (limit - 1UL) >> PAGE_SHIFT;
32912 +
32913 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
32914 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
32915 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
32916 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
32917 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
32918 + }
32919 +
32920 + /* PaX: make KERNEL_CS read-only */
32921 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
32922 + if (!paravirt_enabled())
32923 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
32924 +/*
32925 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
32926 + pgd = pgd_offset_k(addr);
32927 + pud = pud_offset(pgd, addr);
32928 + pmd = pmd_offset(pud, addr);
32929 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32930 + }
32931 +*/
32932 +#ifdef CONFIG_X86_PAE
32933 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
32934 +/*
32935 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
32936 + pgd = pgd_offset_k(addr);
32937 + pud = pud_offset(pgd, addr);
32938 + pmd = pmd_offset(pud, addr);
32939 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32940 + }
32941 +*/
32942 +#endif
32943 +
32944 +#ifdef CONFIG_MODULES
32945 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
32946 +#endif
32947 +
32948 +#else
32949 + /* PaX: make kernel code/rodata read-only, rest non-executable */
32950 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
32951 + pgd = pgd_offset_k(addr);
32952 + pud = pud_offset(pgd, addr);
32953 + pmd = pmd_offset(pud, addr);
32954 + if (!pmd_present(*pmd))
32955 + continue;
32956 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
32957 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32958 + else
32959 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32960 + }
32961 +
32962 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
32963 + end = addr + KERNEL_IMAGE_SIZE;
32964 + for (; addr < end; addr += PMD_SIZE) {
32965 + pgd = pgd_offset_k(addr);
32966 + pud = pud_offset(pgd, addr);
32967 + pmd = pmd_offset(pud, addr);
32968 + if (!pmd_present(*pmd))
32969 + continue;
32970 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
32971 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32972 + }
32973 +#endif
32974 +
32975 + flush_tlb_all();
32976 +#endif
32977 +
32978 free_init_pages("unused kernel",
32979 (unsigned long)(&__init_begin),
32980 (unsigned long)(&__init_end));
32981 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
32982 index e395048..cd38278 100644
32983 --- a/arch/x86/mm/init_32.c
32984 +++ b/arch/x86/mm/init_32.c
32985 @@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
32986 bool __read_mostly __vmalloc_start_set = false;
32987
32988 /*
32989 - * Creates a middle page table and puts a pointer to it in the
32990 - * given global directory entry. This only returns the gd entry
32991 - * in non-PAE compilation mode, since the middle layer is folded.
32992 - */
32993 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
32994 -{
32995 - pud_t *pud;
32996 - pmd_t *pmd_table;
32997 -
32998 -#ifdef CONFIG_X86_PAE
32999 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
33000 - pmd_table = (pmd_t *)alloc_low_page();
33001 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
33002 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
33003 - pud = pud_offset(pgd, 0);
33004 - BUG_ON(pmd_table != pmd_offset(pud, 0));
33005 -
33006 - return pmd_table;
33007 - }
33008 -#endif
33009 - pud = pud_offset(pgd, 0);
33010 - pmd_table = pmd_offset(pud, 0);
33011 -
33012 - return pmd_table;
33013 -}
33014 -
33015 -/*
33016 * Create a page table and place a pointer to it in a middle page
33017 * directory entry:
33018 */
33019 @@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
33020 pte_t *page_table = (pte_t *)alloc_low_page();
33021
33022 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
33023 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
33024 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
33025 +#else
33026 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
33027 +#endif
33028 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
33029 }
33030
33031 return pte_offset_kernel(pmd, 0);
33032 }
33033
33034 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
33035 +{
33036 + pud_t *pud;
33037 + pmd_t *pmd_table;
33038 +
33039 + pud = pud_offset(pgd, 0);
33040 + pmd_table = pmd_offset(pud, 0);
33041 +
33042 + return pmd_table;
33043 +}
33044 +
33045 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
33046 {
33047 int pgd_idx = pgd_index(vaddr);
33048 @@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
33049 int pgd_idx, pmd_idx;
33050 unsigned long vaddr;
33051 pgd_t *pgd;
33052 + pud_t *pud;
33053 pmd_t *pmd;
33054 pte_t *pte = NULL;
33055 unsigned long count = page_table_range_init_count(start, end);
33056 @@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
33057 pgd = pgd_base + pgd_idx;
33058
33059 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
33060 - pmd = one_md_table_init(pgd);
33061 - pmd = pmd + pmd_index(vaddr);
33062 + pud = pud_offset(pgd, vaddr);
33063 + pmd = pmd_offset(pud, vaddr);
33064 +
33065 +#ifdef CONFIG_X86_PAE
33066 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
33067 +#endif
33068 +
33069 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
33070 pmd++, pmd_idx++) {
33071 pte = page_table_kmap_check(one_page_table_init(pmd),
33072 @@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
33073 }
33074 }
33075
33076 -static inline int is_kernel_text(unsigned long addr)
33077 +static inline int is_kernel_text(unsigned long start, unsigned long end)
33078 {
33079 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
33080 - return 1;
33081 - return 0;
33082 + if ((start >= ktla_ktva((unsigned long)_etext) ||
33083 + end <= ktla_ktva((unsigned long)_stext)) &&
33084 + (start >= ktla_ktva((unsigned long)_einittext) ||
33085 + end <= ktla_ktva((unsigned long)_sinittext)) &&
33086 +
33087 +#ifdef CONFIG_ACPI_SLEEP
33088 + (start >= (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
33089 +#endif
33090 +
33091 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
33092 + return 0;
33093 + return 1;
33094 }
33095
33096 /*
33097 @@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
33098 unsigned long last_map_addr = end;
33099 unsigned long start_pfn, end_pfn;
33100 pgd_t *pgd_base = swapper_pg_dir;
33101 - int pgd_idx, pmd_idx, pte_ofs;
33102 + unsigned int pgd_idx, pmd_idx, pte_ofs;
33103 unsigned long pfn;
33104 pgd_t *pgd;
33105 + pud_t *pud;
33106 pmd_t *pmd;
33107 pte_t *pte;
33108 unsigned pages_2m, pages_4k;
33109 @@ -291,8 +295,13 @@ repeat:
33110 pfn = start_pfn;
33111 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
33112 pgd = pgd_base + pgd_idx;
33113 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
33114 - pmd = one_md_table_init(pgd);
33115 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
33116 + pud = pud_offset(pgd, 0);
33117 + pmd = pmd_offset(pud, 0);
33118 +
33119 +#ifdef CONFIG_X86_PAE
33120 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
33121 +#endif
33122
33123 if (pfn >= end_pfn)
33124 continue;
33125 @@ -304,14 +313,13 @@ repeat:
33126 #endif
33127 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
33128 pmd++, pmd_idx++) {
33129 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
33130 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
33131
33132 /*
33133 * Map with big pages if possible, otherwise
33134 * create normal page tables:
33135 */
33136 if (use_pse) {
33137 - unsigned int addr2;
33138 pgprot_t prot = PAGE_KERNEL_LARGE;
33139 /*
33140 * first pass will use the same initial
33141 @@ -322,11 +330,7 @@ repeat:
33142 _PAGE_PSE);
33143
33144 pfn &= PMD_MASK >> PAGE_SHIFT;
33145 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
33146 - PAGE_OFFSET + PAGE_SIZE-1;
33147 -
33148 - if (is_kernel_text(addr) ||
33149 - is_kernel_text(addr2))
33150 + if (is_kernel_text(address, address + PMD_SIZE))
33151 prot = PAGE_KERNEL_LARGE_EXEC;
33152
33153 pages_2m++;
33154 @@ -343,7 +347,7 @@ repeat:
33155 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
33156 pte += pte_ofs;
33157 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
33158 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
33159 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
33160 pgprot_t prot = PAGE_KERNEL;
33161 /*
33162 * first pass will use the same initial
33163 @@ -351,7 +355,7 @@ repeat:
33164 */
33165 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
33166
33167 - if (is_kernel_text(addr))
33168 + if (is_kernel_text(address, address + PAGE_SIZE))
33169 prot = PAGE_KERNEL_EXEC;
33170
33171 pages_4k++;
33172 @@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
33173
33174 pud = pud_offset(pgd, va);
33175 pmd = pmd_offset(pud, va);
33176 - if (!pmd_present(*pmd))
33177 + if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
33178 break;
33179
33180 /* should not be large page here */
33181 @@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
33182
33183 static void __init pagetable_init(void)
33184 {
33185 - pgd_t *pgd_base = swapper_pg_dir;
33186 -
33187 - permanent_kmaps_init(pgd_base);
33188 + permanent_kmaps_init(swapper_pg_dir);
33189 }
33190
33191 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
33192 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
33193 EXPORT_SYMBOL_GPL(__supported_pte_mask);
33194
33195 /* user-defined highmem size */
33196 @@ -787,10 +789,10 @@ void __init mem_init(void)
33197 ((unsigned long)&__init_end -
33198 (unsigned long)&__init_begin) >> 10,
33199
33200 - (unsigned long)&_etext, (unsigned long)&_edata,
33201 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
33202 + (unsigned long)&_sdata, (unsigned long)&_edata,
33203 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
33204
33205 - (unsigned long)&_text, (unsigned long)&_etext,
33206 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
33207 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
33208
33209 /*
33210 @@ -883,6 +885,7 @@ void set_kernel_text_rw(void)
33211 if (!kernel_set_to_readonly)
33212 return;
33213
33214 + start = ktla_ktva(start);
33215 pr_debug("Set kernel text: %lx - %lx for read write\n",
33216 start, start+size);
33217
33218 @@ -897,6 +900,7 @@ void set_kernel_text_ro(void)
33219 if (!kernel_set_to_readonly)
33220 return;
33221
33222 + start = ktla_ktva(start);
33223 pr_debug("Set kernel text: %lx - %lx for read only\n",
33224 start, start+size);
33225
33226 @@ -925,6 +929,7 @@ void mark_rodata_ro(void)
33227 unsigned long start = PFN_ALIGN(_text);
33228 unsigned long size = PFN_ALIGN(_etext) - start;
33229
33230 + start = ktla_ktva(start);
33231 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
33232 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
33233 size >> 10);
33234 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
33235 index df1a992..94c272c 100644
33236 --- a/arch/x86/mm/init_64.c
33237 +++ b/arch/x86/mm/init_64.c
33238 @@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
33239 * around without checking the pgd every time.
33240 */
33241
33242 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
33243 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
33244 EXPORT_SYMBOL_GPL(__supported_pte_mask);
33245
33246 int force_personality32;
33247 @@ -184,12 +184,29 @@ void sync_global_pgds(unsigned long start, unsigned long end)
33248
33249 for (address = start; address <= end; address += PGDIR_SIZE) {
33250 const pgd_t *pgd_ref = pgd_offset_k(address);
33251 +
33252 +#ifdef CONFIG_PAX_PER_CPU_PGD
33253 + unsigned long cpu;
33254 +#else
33255 struct page *page;
33256 +#endif
33257
33258 if (pgd_none(*pgd_ref))
33259 continue;
33260
33261 spin_lock(&pgd_lock);
33262 +
33263 +#ifdef CONFIG_PAX_PER_CPU_PGD
33264 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
33265 + pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
33266 +
33267 + if (pgd_none(*pgd))
33268 + set_pgd(pgd, *pgd_ref);
33269 + else
33270 + BUG_ON(pgd_page_vaddr(*pgd)
33271 + != pgd_page_vaddr(*pgd_ref));
33272 + pgd = pgd_offset_cpu(cpu, kernel, address);
33273 +#else
33274 list_for_each_entry(page, &pgd_list, lru) {
33275 pgd_t *pgd;
33276 spinlock_t *pgt_lock;
33277 @@ -198,6 +215,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
33278 /* the pgt_lock only for Xen */
33279 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
33280 spin_lock(pgt_lock);
33281 +#endif
33282
33283 if (pgd_none(*pgd))
33284 set_pgd(pgd, *pgd_ref);
33285 @@ -205,7 +223,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
33286 BUG_ON(pgd_page_vaddr(*pgd)
33287 != pgd_page_vaddr(*pgd_ref));
33288
33289 +#ifndef CONFIG_PAX_PER_CPU_PGD
33290 spin_unlock(pgt_lock);
33291 +#endif
33292 +
33293 }
33294 spin_unlock(&pgd_lock);
33295 }
33296 @@ -238,7 +259,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
33297 {
33298 if (pgd_none(*pgd)) {
33299 pud_t *pud = (pud_t *)spp_getpage();
33300 - pgd_populate(&init_mm, pgd, pud);
33301 + pgd_populate_kernel(&init_mm, pgd, pud);
33302 if (pud != pud_offset(pgd, 0))
33303 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
33304 pud, pud_offset(pgd, 0));
33305 @@ -250,7 +271,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
33306 {
33307 if (pud_none(*pud)) {
33308 pmd_t *pmd = (pmd_t *) spp_getpage();
33309 - pud_populate(&init_mm, pud, pmd);
33310 + pud_populate_kernel(&init_mm, pud, pmd);
33311 if (pmd != pmd_offset(pud, 0))
33312 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
33313 pmd, pmd_offset(pud, 0));
33314 @@ -279,7 +300,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
33315 pmd = fill_pmd(pud, vaddr);
33316 pte = fill_pte(pmd, vaddr);
33317
33318 + pax_open_kernel();
33319 set_pte(pte, new_pte);
33320 + pax_close_kernel();
33321
33322 /*
33323 * It's enough to flush this one mapping.
33324 @@ -338,14 +361,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
33325 pgd = pgd_offset_k((unsigned long)__va(phys));
33326 if (pgd_none(*pgd)) {
33327 pud = (pud_t *) spp_getpage();
33328 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
33329 - _PAGE_USER));
33330 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
33331 }
33332 pud = pud_offset(pgd, (unsigned long)__va(phys));
33333 if (pud_none(*pud)) {
33334 pmd = (pmd_t *) spp_getpage();
33335 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
33336 - _PAGE_USER));
33337 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
33338 }
33339 pmd = pmd_offset(pud, phys);
33340 BUG_ON(!pmd_none(*pmd));
33341 @@ -586,7 +607,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
33342 prot);
33343
33344 spin_lock(&init_mm.page_table_lock);
33345 - pud_populate(&init_mm, pud, pmd);
33346 + pud_populate_kernel(&init_mm, pud, pmd);
33347 spin_unlock(&init_mm.page_table_lock);
33348 }
33349 __flush_tlb_all();
33350 @@ -627,7 +648,7 @@ kernel_physical_mapping_init(unsigned long start,
33351 page_size_mask);
33352
33353 spin_lock(&init_mm.page_table_lock);
33354 - pgd_populate(&init_mm, pgd, pud);
33355 + pgd_populate_kernel(&init_mm, pgd, pud);
33356 spin_unlock(&init_mm.page_table_lock);
33357 pgd_changed = true;
33358 }
33359 @@ -1195,8 +1216,8 @@ static struct vm_operations_struct gate_vma_ops = {
33360 static struct vm_area_struct gate_vma = {
33361 .vm_start = VSYSCALL_ADDR,
33362 .vm_end = VSYSCALL_ADDR + PAGE_SIZE,
33363 - .vm_page_prot = PAGE_READONLY_EXEC,
33364 - .vm_flags = VM_READ | VM_EXEC,
33365 + .vm_page_prot = PAGE_READONLY,
33366 + .vm_flags = VM_READ,
33367 .vm_ops = &gate_vma_ops,
33368 };
33369
33370 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
33371 index 7b179b4..6bd17777 100644
33372 --- a/arch/x86/mm/iomap_32.c
33373 +++ b/arch/x86/mm/iomap_32.c
33374 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
33375 type = kmap_atomic_idx_push();
33376 idx = type + KM_TYPE_NR * smp_processor_id();
33377 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
33378 +
33379 + pax_open_kernel();
33380 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
33381 + pax_close_kernel();
33382 +
33383 arch_flush_lazy_mmu_mode();
33384
33385 return (void *)vaddr;
33386 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
33387 index baff1da..2816ef4 100644
33388 --- a/arch/x86/mm/ioremap.c
33389 +++ b/arch/x86/mm/ioremap.c
33390 @@ -56,8 +56,8 @@ static int __ioremap_check_ram(unsigned long start_pfn, unsigned long nr_pages,
33391 unsigned long i;
33392
33393 for (i = 0; i < nr_pages; ++i)
33394 - if (pfn_valid(start_pfn + i) &&
33395 - !PageReserved(pfn_to_page(start_pfn + i)))
33396 + if (pfn_valid(start_pfn + i) && (start_pfn + i >= 0x100 ||
33397 + !PageReserved(pfn_to_page(start_pfn + i))))
33398 return 1;
33399
33400 WARN_ONCE(1, "ioremap on RAM pfn 0x%lx\n", start_pfn);
33401 @@ -268,7 +268,7 @@ EXPORT_SYMBOL(ioremap_prot);
33402 *
33403 * Caller must ensure there is only one unmapping for the same pointer.
33404 */
33405 -void iounmap(volatile void __iomem *addr)
33406 +void iounmap(const volatile void __iomem *addr)
33407 {
33408 struct vm_struct *p, *o;
33409
33410 @@ -322,6 +322,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
33411
33412 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
33413 if (page_is_ram(start >> PAGE_SHIFT))
33414 +#ifdef CONFIG_HIGHMEM
33415 + if ((start >> PAGE_SHIFT) < max_low_pfn)
33416 +#endif
33417 return __va(phys);
33418
33419 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
33420 @@ -334,13 +337,16 @@ void *xlate_dev_mem_ptr(unsigned long phys)
33421 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
33422 {
33423 if (page_is_ram(phys >> PAGE_SHIFT))
33424 +#ifdef CONFIG_HIGHMEM
33425 + if ((phys >> PAGE_SHIFT) < max_low_pfn)
33426 +#endif
33427 return;
33428
33429 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
33430 return;
33431 }
33432
33433 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
33434 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
33435
33436 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
33437 {
33438 @@ -376,8 +382,7 @@ void __init early_ioremap_init(void)
33439 early_ioremap_setup();
33440
33441 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
33442 - memset(bm_pte, 0, sizeof(bm_pte));
33443 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
33444 + pmd_populate_user(&init_mm, pmd, bm_pte);
33445
33446 /*
33447 * The boot-ioremap range spans multiple pmds, for which
33448 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
33449 index dd89a13..d77bdcc 100644
33450 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
33451 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
33452 @@ -628,9 +628,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
33453 * memory (e.g. tracked pages)? For now, we need this to avoid
33454 * invoking kmemcheck for PnP BIOS calls.
33455 */
33456 - if (regs->flags & X86_VM_MASK)
33457 + if (v8086_mode(regs))
33458 return false;
33459 - if (regs->cs != __KERNEL_CS)
33460 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
33461 return false;
33462
33463 pte = kmemcheck_pte_lookup(address);
33464 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
33465 index 25e7e13..1964579 100644
33466 --- a/arch/x86/mm/mmap.c
33467 +++ b/arch/x86/mm/mmap.c
33468 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
33469 * Leave an at least ~128 MB hole with possible stack randomization.
33470 */
33471 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
33472 -#define MAX_GAP (TASK_SIZE/6*5)
33473 +#define MAX_GAP (pax_task_size/6*5)
33474
33475 static int mmap_is_legacy(void)
33476 {
33477 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
33478 return rnd << PAGE_SHIFT;
33479 }
33480
33481 -static unsigned long mmap_base(void)
33482 +static unsigned long mmap_base(struct mm_struct *mm)
33483 {
33484 unsigned long gap = rlimit(RLIMIT_STACK);
33485 + unsigned long pax_task_size = TASK_SIZE;
33486 +
33487 +#ifdef CONFIG_PAX_SEGMEXEC
33488 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
33489 + pax_task_size = SEGMEXEC_TASK_SIZE;
33490 +#endif
33491
33492 if (gap < MIN_GAP)
33493 gap = MIN_GAP;
33494 else if (gap > MAX_GAP)
33495 gap = MAX_GAP;
33496
33497 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
33498 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
33499 }
33500
33501 /*
33502 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
33503 * does, but not when emulating X86_32
33504 */
33505 -static unsigned long mmap_legacy_base(void)
33506 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
33507 {
33508 - if (mmap_is_ia32())
33509 + if (mmap_is_ia32()) {
33510 +
33511 +#ifdef CONFIG_PAX_SEGMEXEC
33512 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
33513 + return SEGMEXEC_TASK_UNMAPPED_BASE;
33514 + else
33515 +#endif
33516 +
33517 return TASK_UNMAPPED_BASE;
33518 - else
33519 + } else
33520 return TASK_UNMAPPED_BASE + mmap_rnd();
33521 }
33522
33523 @@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
33524 */
33525 void arch_pick_mmap_layout(struct mm_struct *mm)
33526 {
33527 - mm->mmap_legacy_base = mmap_legacy_base();
33528 - mm->mmap_base = mmap_base();
33529 + mm->mmap_legacy_base = mmap_legacy_base(mm);
33530 + mm->mmap_base = mmap_base(mm);
33531 +
33532 +#ifdef CONFIG_PAX_RANDMMAP
33533 + if (mm->pax_flags & MF_PAX_RANDMMAP) {
33534 + mm->mmap_legacy_base += mm->delta_mmap;
33535 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
33536 + }
33537 +#endif
33538
33539 if (mmap_is_legacy()) {
33540 mm->mmap_base = mm->mmap_legacy_base;
33541 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
33542 index 0057a7a..95c7edd 100644
33543 --- a/arch/x86/mm/mmio-mod.c
33544 +++ b/arch/x86/mm/mmio-mod.c
33545 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
33546 break;
33547 default:
33548 {
33549 - unsigned char *ip = (unsigned char *)instptr;
33550 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
33551 my_trace->opcode = MMIO_UNKNOWN_OP;
33552 my_trace->width = 0;
33553 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
33554 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
33555 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
33556 void __iomem *addr)
33557 {
33558 - static atomic_t next_id;
33559 + static atomic_unchecked_t next_id;
33560 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
33561 /* These are page-unaligned. */
33562 struct mmiotrace_map map = {
33563 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
33564 .private = trace
33565 },
33566 .phys = offset,
33567 - .id = atomic_inc_return(&next_id)
33568 + .id = atomic_inc_return_unchecked(&next_id)
33569 };
33570 map.map_id = trace->id;
33571
33572 @@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
33573 ioremap_trace_core(offset, size, addr);
33574 }
33575
33576 -static void iounmap_trace_core(volatile void __iomem *addr)
33577 +static void iounmap_trace_core(const volatile void __iomem *addr)
33578 {
33579 struct mmiotrace_map map = {
33580 .phys = 0,
33581 @@ -328,7 +328,7 @@ not_enabled:
33582 }
33583 }
33584
33585 -void mmiotrace_iounmap(volatile void __iomem *addr)
33586 +void mmiotrace_iounmap(const volatile void __iomem *addr)
33587 {
33588 might_sleep();
33589 if (is_enabled()) /* recheck and proper locking in *_core() */
33590 diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
33591 index a32b706..efb308b 100644
33592 --- a/arch/x86/mm/numa.c
33593 +++ b/arch/x86/mm/numa.c
33594 @@ -478,7 +478,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
33595 return true;
33596 }
33597
33598 -static int __init numa_register_memblks(struct numa_meminfo *mi)
33599 +static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
33600 {
33601 unsigned long uninitialized_var(pfn_align);
33602 int i, nid;
33603 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
33604 index ae242a7..1c7998f 100644
33605 --- a/arch/x86/mm/pageattr.c
33606 +++ b/arch/x86/mm/pageattr.c
33607 @@ -262,7 +262,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33608 */
33609 #ifdef CONFIG_PCI_BIOS
33610 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
33611 - pgprot_val(forbidden) |= _PAGE_NX;
33612 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33613 #endif
33614
33615 /*
33616 @@ -270,9 +270,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33617 * Does not cover __inittext since that is gone later on. On
33618 * 64bit we do not enforce !NX on the low mapping
33619 */
33620 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
33621 - pgprot_val(forbidden) |= _PAGE_NX;
33622 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
33623 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33624
33625 +#ifdef CONFIG_DEBUG_RODATA
33626 /*
33627 * The .rodata section needs to be read-only. Using the pfn
33628 * catches all aliases.
33629 @@ -280,6 +281,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33630 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
33631 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
33632 pgprot_val(forbidden) |= _PAGE_RW;
33633 +#endif
33634
33635 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
33636 /*
33637 @@ -318,6 +320,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33638 }
33639 #endif
33640
33641 +#ifdef CONFIG_PAX_KERNEXEC
33642 + if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
33643 + pgprot_val(forbidden) |= _PAGE_RW;
33644 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33645 + }
33646 +#endif
33647 +
33648 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
33649
33650 return prot;
33651 @@ -420,23 +429,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
33652 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
33653 {
33654 /* change init_mm */
33655 + pax_open_kernel();
33656 set_pte_atomic(kpte, pte);
33657 +
33658 #ifdef CONFIG_X86_32
33659 if (!SHARED_KERNEL_PMD) {
33660 +
33661 +#ifdef CONFIG_PAX_PER_CPU_PGD
33662 + unsigned long cpu;
33663 +#else
33664 struct page *page;
33665 +#endif
33666
33667 +#ifdef CONFIG_PAX_PER_CPU_PGD
33668 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
33669 + pgd_t *pgd = get_cpu_pgd(cpu, kernel);
33670 +#else
33671 list_for_each_entry(page, &pgd_list, lru) {
33672 - pgd_t *pgd;
33673 + pgd_t *pgd = (pgd_t *)page_address(page);
33674 +#endif
33675 +
33676 pud_t *pud;
33677 pmd_t *pmd;
33678
33679 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
33680 + pgd += pgd_index(address);
33681 pud = pud_offset(pgd, address);
33682 pmd = pmd_offset(pud, address);
33683 set_pte_atomic((pte_t *)pmd, pte);
33684 }
33685 }
33686 #endif
33687 + pax_close_kernel();
33688 }
33689
33690 static int
33691 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
33692 index 6574388..87e9bef 100644
33693 --- a/arch/x86/mm/pat.c
33694 +++ b/arch/x86/mm/pat.c
33695 @@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
33696
33697 if (!entry) {
33698 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
33699 - current->comm, current->pid, start, end - 1);
33700 + current->comm, task_pid_nr(current), start, end - 1);
33701 return -EINVAL;
33702 }
33703
33704 @@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33705
33706 while (cursor < to) {
33707 if (!devmem_is_allowed(pfn)) {
33708 - printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
33709 - current->comm, from, to - 1);
33710 + printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
33711 + current->comm, from, to - 1, cursor);
33712 return 0;
33713 }
33714 cursor += PAGE_SIZE;
33715 @@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
33716 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
33717 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
33718 "for [mem %#010Lx-%#010Lx]\n",
33719 - current->comm, current->pid,
33720 + current->comm, task_pid_nr(current),
33721 cattr_name(flags),
33722 base, (unsigned long long)(base + size-1));
33723 return -EINVAL;
33724 @@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33725 flags = lookup_memtype(paddr);
33726 if (want_flags != flags) {
33727 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
33728 - current->comm, current->pid,
33729 + current->comm, task_pid_nr(current),
33730 cattr_name(want_flags),
33731 (unsigned long long)paddr,
33732 (unsigned long long)(paddr + size - 1),
33733 @@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33734 free_memtype(paddr, paddr + size);
33735 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
33736 " for [mem %#010Lx-%#010Lx], got %s\n",
33737 - current->comm, current->pid,
33738 + current->comm, task_pid_nr(current),
33739 cattr_name(want_flags),
33740 (unsigned long long)paddr,
33741 (unsigned long long)(paddr + size - 1),
33742 diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
33743 index 415f6c4..d319983 100644
33744 --- a/arch/x86/mm/pat_rbtree.c
33745 +++ b/arch/x86/mm/pat_rbtree.c
33746 @@ -160,7 +160,7 @@ success:
33747
33748 failure:
33749 printk(KERN_INFO "%s:%d conflicting memory types "
33750 - "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
33751 + "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
33752 end, cattr_name(found_type), cattr_name(match->type));
33753 return -EBUSY;
33754 }
33755 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
33756 index 9f0614d..92ae64a 100644
33757 --- a/arch/x86/mm/pf_in.c
33758 +++ b/arch/x86/mm/pf_in.c
33759 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
33760 int i;
33761 enum reason_type rv = OTHERS;
33762
33763 - p = (unsigned char *)ins_addr;
33764 + p = (unsigned char *)ktla_ktva(ins_addr);
33765 p += skip_prefix(p, &prf);
33766 p += get_opcode(p, &opcode);
33767
33768 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
33769 struct prefix_bits prf;
33770 int i;
33771
33772 - p = (unsigned char *)ins_addr;
33773 + p = (unsigned char *)ktla_ktva(ins_addr);
33774 p += skip_prefix(p, &prf);
33775 p += get_opcode(p, &opcode);
33776
33777 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
33778 struct prefix_bits prf;
33779 int i;
33780
33781 - p = (unsigned char *)ins_addr;
33782 + p = (unsigned char *)ktla_ktva(ins_addr);
33783 p += skip_prefix(p, &prf);
33784 p += get_opcode(p, &opcode);
33785
33786 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
33787 struct prefix_bits prf;
33788 int i;
33789
33790 - p = (unsigned char *)ins_addr;
33791 + p = (unsigned char *)ktla_ktva(ins_addr);
33792 p += skip_prefix(p, &prf);
33793 p += get_opcode(p, &opcode);
33794 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
33795 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
33796 struct prefix_bits prf;
33797 int i;
33798
33799 - p = (unsigned char *)ins_addr;
33800 + p = (unsigned char *)ktla_ktva(ins_addr);
33801 p += skip_prefix(p, &prf);
33802 p += get_opcode(p, &opcode);
33803 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
33804 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
33805 index 6fb6927..4fc13c0 100644
33806 --- a/arch/x86/mm/pgtable.c
33807 +++ b/arch/x86/mm/pgtable.c
33808 @@ -97,10 +97,71 @@ static inline void pgd_list_del(pgd_t *pgd)
33809 list_del(&page->lru);
33810 }
33811
33812 -#define UNSHARED_PTRS_PER_PGD \
33813 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33814 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33815 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
33816
33817 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
33818 +{
33819 + unsigned int count = USER_PGD_PTRS;
33820
33821 + if (!pax_user_shadow_base)
33822 + return;
33823 +
33824 + while (count--)
33825 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
33826 +}
33827 +#endif
33828 +
33829 +#ifdef CONFIG_PAX_PER_CPU_PGD
33830 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
33831 +{
33832 + unsigned int count = USER_PGD_PTRS;
33833 +
33834 + while (count--) {
33835 + pgd_t pgd;
33836 +
33837 +#ifdef CONFIG_X86_64
33838 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
33839 +#else
33840 + pgd = *src++;
33841 +#endif
33842 +
33843 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33844 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
33845 +#endif
33846 +
33847 + *dst++ = pgd;
33848 + }
33849 +
33850 +}
33851 +#endif
33852 +
33853 +#ifdef CONFIG_X86_64
33854 +#define pxd_t pud_t
33855 +#define pyd_t pgd_t
33856 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
33857 +#define pgtable_pxd_page_ctor(page) true
33858 +#define pgtable_pxd_page_dtor(page)
33859 +#define pxd_free(mm, pud) pud_free((mm), (pud))
33860 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
33861 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
33862 +#define PYD_SIZE PGDIR_SIZE
33863 +#else
33864 +#define pxd_t pmd_t
33865 +#define pyd_t pud_t
33866 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
33867 +#define pgtable_pxd_page_ctor(page) pgtable_pmd_page_ctor(page)
33868 +#define pgtable_pxd_page_dtor(page) pgtable_pmd_page_dtor(page)
33869 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
33870 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
33871 +#define pyd_offset(mm, address) pud_offset((mm), (address))
33872 +#define PYD_SIZE PUD_SIZE
33873 +#endif
33874 +
33875 +#ifdef CONFIG_PAX_PER_CPU_PGD
33876 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
33877 +static inline void pgd_dtor(pgd_t *pgd) {}
33878 +#else
33879 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
33880 {
33881 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
33882 @@ -141,6 +202,7 @@ static void pgd_dtor(pgd_t *pgd)
33883 pgd_list_del(pgd);
33884 spin_unlock(&pgd_lock);
33885 }
33886 +#endif
33887
33888 /*
33889 * List of all pgd's needed for non-PAE so it can invalidate entries
33890 @@ -153,7 +215,7 @@ static void pgd_dtor(pgd_t *pgd)
33891 * -- nyc
33892 */
33893
33894 -#ifdef CONFIG_X86_PAE
33895 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
33896 /*
33897 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
33898 * updating the top-level pagetable entries to guarantee the
33899 @@ -165,7 +227,7 @@ static void pgd_dtor(pgd_t *pgd)
33900 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
33901 * and initialize the kernel pmds here.
33902 */
33903 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
33904 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33905
33906 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33907 {
33908 @@ -183,43 +245,45 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33909 */
33910 flush_tlb_mm(mm);
33911 }
33912 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
33913 +#define PREALLOCATED_PXDS USER_PGD_PTRS
33914 #else /* !CONFIG_X86_PAE */
33915
33916 /* No need to prepopulate any pagetable entries in non-PAE modes. */
33917 -#define PREALLOCATED_PMDS 0
33918 +#define PREALLOCATED_PXDS 0
33919
33920 #endif /* CONFIG_X86_PAE */
33921
33922 -static void free_pmds(pmd_t *pmds[])
33923 +static void free_pxds(pxd_t *pxds[])
33924 {
33925 int i;
33926
33927 - for(i = 0; i < PREALLOCATED_PMDS; i++)
33928 - if (pmds[i]) {
33929 - pgtable_pmd_page_dtor(virt_to_page(pmds[i]));
33930 - free_page((unsigned long)pmds[i]);
33931 + for(i = 0; i < PREALLOCATED_PXDS; i++)
33932 + if (pxds[i]) {
33933 + pgtable_pxd_page_dtor(virt_to_page(pxds[i]));
33934 + free_page((unsigned long)pxds[i]);
33935 }
33936 }
33937
33938 -static int preallocate_pmds(pmd_t *pmds[])
33939 +static int preallocate_pxds(pxd_t *pxds[])
33940 {
33941 int i;
33942 bool failed = false;
33943
33944 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
33945 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
33946 - if (!pmd)
33947 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
33948 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
33949 + if (!pxd)
33950 failed = true;
33951 - if (pmd && !pgtable_pmd_page_ctor(virt_to_page(pmd))) {
33952 - free_page((unsigned long)pmd);
33953 - pmd = NULL;
33954 + if (pxd && !pgtable_pxd_page_ctor(virt_to_page(pxd))) {
33955 + free_page((unsigned long)pxd);
33956 + pxd = NULL;
33957 failed = true;
33958 }
33959 - pmds[i] = pmd;
33960 + pxds[i] = pxd;
33961 }
33962
33963 if (failed) {
33964 - free_pmds(pmds);
33965 + free_pxds(pxds);
33966 return -ENOMEM;
33967 }
33968
33969 @@ -232,49 +296,52 @@ static int preallocate_pmds(pmd_t *pmds[])
33970 * preallocate which never got a corresponding vma will need to be
33971 * freed manually.
33972 */
33973 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
33974 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
33975 {
33976 int i;
33977
33978 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
33979 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
33980 pgd_t pgd = pgdp[i];
33981
33982 if (pgd_val(pgd) != 0) {
33983 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
33984 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
33985
33986 - pgdp[i] = native_make_pgd(0);
33987 + set_pgd(pgdp + i, native_make_pgd(0));
33988
33989 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
33990 - pmd_free(mm, pmd);
33991 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
33992 + pxd_free(mm, pxd);
33993 }
33994 }
33995 }
33996
33997 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
33998 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
33999 {
34000 - pud_t *pud;
34001 + pyd_t *pyd;
34002 int i;
34003
34004 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
34005 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
34006 return;
34007
34008 - pud = pud_offset(pgd, 0);
34009 -
34010 - for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
34011 - pmd_t *pmd = pmds[i];
34012 +#ifdef CONFIG_X86_64
34013 + pyd = pyd_offset(mm, 0L);
34014 +#else
34015 + pyd = pyd_offset(pgd, 0L);
34016 +#endif
34017
34018 + for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
34019 + pxd_t *pxd = pxds[i];
34020 if (i >= KERNEL_PGD_BOUNDARY)
34021 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
34022 - sizeof(pmd_t) * PTRS_PER_PMD);
34023 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
34024 + sizeof(pxd_t) * PTRS_PER_PMD);
34025
34026 - pud_populate(mm, pud, pmd);
34027 + pyd_populate(mm, pyd, pxd);
34028 }
34029 }
34030
34031 pgd_t *pgd_alloc(struct mm_struct *mm)
34032 {
34033 pgd_t *pgd;
34034 - pmd_t *pmds[PREALLOCATED_PMDS];
34035 + pxd_t *pxds[PREALLOCATED_PXDS];
34036
34037 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
34038
34039 @@ -283,11 +350,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
34040
34041 mm->pgd = pgd;
34042
34043 - if (preallocate_pmds(pmds) != 0)
34044 + if (preallocate_pxds(pxds) != 0)
34045 goto out_free_pgd;
34046
34047 if (paravirt_pgd_alloc(mm) != 0)
34048 - goto out_free_pmds;
34049 + goto out_free_pxds;
34050
34051 /*
34052 * Make sure that pre-populating the pmds is atomic with
34053 @@ -297,14 +364,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
34054 spin_lock(&pgd_lock);
34055
34056 pgd_ctor(mm, pgd);
34057 - pgd_prepopulate_pmd(mm, pgd, pmds);
34058 + pgd_prepopulate_pxd(mm, pgd, pxds);
34059
34060 spin_unlock(&pgd_lock);
34061
34062 return pgd;
34063
34064 -out_free_pmds:
34065 - free_pmds(pmds);
34066 +out_free_pxds:
34067 + free_pxds(pxds);
34068 out_free_pgd:
34069 free_page((unsigned long)pgd);
34070 out:
34071 @@ -313,7 +380,7 @@ out:
34072
34073 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
34074 {
34075 - pgd_mop_up_pmds(mm, pgd);
34076 + pgd_mop_up_pxds(mm, pgd);
34077 pgd_dtor(pgd);
34078 paravirt_pgd_free(mm, pgd);
34079 free_page((unsigned long)pgd);
34080 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
34081 index 4dd8cf6..f9d143e 100644
34082 --- a/arch/x86/mm/pgtable_32.c
34083 +++ b/arch/x86/mm/pgtable_32.c
34084 @@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
34085 return;
34086 }
34087 pte = pte_offset_kernel(pmd, vaddr);
34088 +
34089 + pax_open_kernel();
34090 if (pte_val(pteval))
34091 set_pte_at(&init_mm, vaddr, pte, pteval);
34092 else
34093 pte_clear(&init_mm, vaddr, pte);
34094 + pax_close_kernel();
34095
34096 /*
34097 * It's enough to flush this one mapping.
34098 diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
34099 index e666cbb..61788c45 100644
34100 --- a/arch/x86/mm/physaddr.c
34101 +++ b/arch/x86/mm/physaddr.c
34102 @@ -10,7 +10,7 @@
34103 #ifdef CONFIG_X86_64
34104
34105 #ifdef CONFIG_DEBUG_VIRTUAL
34106 -unsigned long __phys_addr(unsigned long x)
34107 +unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
34108 {
34109 unsigned long y = x - __START_KERNEL_map;
34110
34111 @@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
34112 #else
34113
34114 #ifdef CONFIG_DEBUG_VIRTUAL
34115 -unsigned long __phys_addr(unsigned long x)
34116 +unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
34117 {
34118 unsigned long phys_addr = x - PAGE_OFFSET;
34119 /* VMALLOC_* aren't constants */
34120 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
34121 index 90555bf..f5f1828 100644
34122 --- a/arch/x86/mm/setup_nx.c
34123 +++ b/arch/x86/mm/setup_nx.c
34124 @@ -5,8 +5,10 @@
34125 #include <asm/pgtable.h>
34126 #include <asm/proto.h>
34127
34128 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
34129 static int disable_nx;
34130
34131 +#ifndef CONFIG_PAX_PAGEEXEC
34132 /*
34133 * noexec = on|off
34134 *
34135 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
34136 return 0;
34137 }
34138 early_param("noexec", noexec_setup);
34139 +#endif
34140 +
34141 +#endif
34142
34143 void x86_configure_nx(void)
34144 {
34145 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
34146 if (cpu_has_nx && !disable_nx)
34147 __supported_pte_mask |= _PAGE_NX;
34148 else
34149 +#endif
34150 __supported_pte_mask &= ~_PAGE_NX;
34151 }
34152
34153 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
34154 index dd8dda1..9e9b0f6 100644
34155 --- a/arch/x86/mm/tlb.c
34156 +++ b/arch/x86/mm/tlb.c
34157 @@ -48,7 +48,11 @@ void leave_mm(int cpu)
34158 BUG();
34159 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
34160 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
34161 +
34162 +#ifndef CONFIG_PAX_PER_CPU_PGD
34163 load_cr3(swapper_pg_dir);
34164 +#endif
34165 +
34166 }
34167 }
34168 EXPORT_SYMBOL_GPL(leave_mm);
34169 diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
34170 new file mode 100644
34171 index 0000000..dace51c
34172 --- /dev/null
34173 +++ b/arch/x86/mm/uderef_64.c
34174 @@ -0,0 +1,37 @@
34175 +#include <linux/mm.h>
34176 +#include <asm/pgtable.h>
34177 +#include <asm/uaccess.h>
34178 +
34179 +#ifdef CONFIG_PAX_MEMORY_UDEREF
34180 +/* PaX: due to the special call convention these functions must
34181 + * - remain leaf functions under all configurations,
34182 + * - never be called directly, only dereferenced from the wrappers.
34183 + */
34184 +void __pax_open_userland(void)
34185 +{
34186 + unsigned int cpu;
34187 +
34188 + if (unlikely(!segment_eq(get_fs(), USER_DS)))
34189 + return;
34190 +
34191 + cpu = raw_get_cpu();
34192 + BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
34193 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
34194 + raw_put_cpu_no_resched();
34195 +}
34196 +EXPORT_SYMBOL(__pax_open_userland);
34197 +
34198 +void __pax_close_userland(void)
34199 +{
34200 + unsigned int cpu;
34201 +
34202 + if (unlikely(!segment_eq(get_fs(), USER_DS)))
34203 + return;
34204 +
34205 + cpu = raw_get_cpu();
34206 + BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
34207 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
34208 + raw_put_cpu_no_resched();
34209 +}
34210 +EXPORT_SYMBOL(__pax_close_userland);
34211 +#endif
34212 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
34213 index 6440221..f746de8 100644
34214 --- a/arch/x86/net/bpf_jit.S
34215 +++ b/arch/x86/net/bpf_jit.S
34216 @@ -9,19 +9,17 @@
34217 */
34218 #include <linux/linkage.h>
34219 #include <asm/dwarf2.h>
34220 +#include <asm/alternative-asm.h>
34221
34222 /*
34223 * Calling convention :
34224 - * rbx : skb pointer (callee saved)
34225 + * rdi : skb pointer
34226 * esi : offset of byte(s) to fetch in skb (can be scratched)
34227 - * r10 : copy of skb->data
34228 + * r8 : copy of skb->data
34229 * r9d : hlen = skb->len - skb->data_len
34230 */
34231 -#define SKBDATA %r10
34232 +#define SKBDATA %r8
34233 #define SKF_MAX_NEG_OFF $(-0x200000) /* SKF_LL_OFF from filter.h */
34234 -#define MAX_BPF_STACK (512 /* from filter.h */ + \
34235 - 32 /* space for rbx,r13,r14,r15 */ + \
34236 - 8 /* space for skb_copy_bits */)
34237
34238 sk_load_word:
34239 .globl sk_load_word
34240 @@ -38,6 +36,7 @@ sk_load_word_positive_offset:
34241 jle bpf_slow_path_word
34242 mov (SKBDATA,%rsi),%eax
34243 bswap %eax /* ntohl() */
34244 + pax_force_retaddr
34245 ret
34246
34247 sk_load_half:
34248 @@ -55,6 +54,7 @@ sk_load_half_positive_offset:
34249 jle bpf_slow_path_half
34250 movzwl (SKBDATA,%rsi),%eax
34251 rol $8,%ax # ntohs()
34252 + pax_force_retaddr
34253 ret
34254
34255 sk_load_byte:
34256 @@ -69,45 +69,83 @@ sk_load_byte_positive_offset:
34257 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
34258 jle bpf_slow_path_byte
34259 movzbl (SKBDATA,%rsi),%eax
34260 + pax_force_retaddr
34261 + ret
34262 +
34263 +/**
34264 + * sk_load_byte_msh - BPF_S_LDX_B_MSH helper
34265 + *
34266 + * Implements BPF_S_LDX_B_MSH : ldxb 4*([offset]&0xf)
34267 + * Must preserve A accumulator (%eax)
34268 + * Inputs : %esi is the offset value
34269 + */
34270 +sk_load_byte_msh:
34271 + .globl sk_load_byte_msh
34272 + test %esi,%esi
34273 + js bpf_slow_path_byte_msh_neg
34274 +
34275 +sk_load_byte_msh_positive_offset:
34276 + .globl sk_load_byte_msh_positive_offset
34277 + cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte_msh */
34278 + jle bpf_slow_path_byte_msh
34279 + movzbl (SKBDATA,%rsi),%ebx
34280 + and $15,%bl
34281 + shl $2,%bl
34282 + pax_force_retaddr
34283 ret
34284
34285 /* rsi contains offset and can be scratched */
34286 #define bpf_slow_path_common(LEN) \
34287 - mov %rbx, %rdi; /* arg1 == skb */ \
34288 + push %rdi; /* save skb */ \
34289 push %r9; \
34290 push SKBDATA; \
34291 /* rsi already has offset */ \
34292 mov $LEN,%ecx; /* len */ \
34293 - lea - MAX_BPF_STACK + 32(%rbp),%rdx; \
34294 + lea -12(%rbp),%rdx; \
34295 call skb_copy_bits; \
34296 test %eax,%eax; \
34297 pop SKBDATA; \
34298 - pop %r9;
34299 + pop %r9; \
34300 + pop %rdi
34301
34302
34303 bpf_slow_path_word:
34304 bpf_slow_path_common(4)
34305 js bpf_error
34306 - mov - MAX_BPF_STACK + 32(%rbp),%eax
34307 + mov -12(%rbp),%eax
34308 bswap %eax
34309 + pax_force_retaddr
34310 ret
34311
34312 bpf_slow_path_half:
34313 bpf_slow_path_common(2)
34314 js bpf_error
34315 - mov - MAX_BPF_STACK + 32(%rbp),%ax
34316 + mov -12(%rbp),%ax
34317 rol $8,%ax
34318 movzwl %ax,%eax
34319 + pax_force_retaddr
34320 ret
34321
34322 bpf_slow_path_byte:
34323 bpf_slow_path_common(1)
34324 js bpf_error
34325 - movzbl - MAX_BPF_STACK + 32(%rbp),%eax
34326 + movzbl -12(%rbp),%eax
34327 + pax_force_retaddr
34328 + ret
34329 +
34330 +bpf_slow_path_byte_msh:
34331 + xchg %eax,%ebx /* dont lose A , X is about to be scratched */
34332 + bpf_slow_path_common(1)
34333 + js bpf_error
34334 + movzbl -12(%rbp),%eax
34335 + and $15,%al
34336 + shl $2,%al
34337 + xchg %eax,%ebx
34338 + pax_force_retaddr
34339 ret
34340
34341 #define sk_negative_common(SIZE) \
34342 - mov %rbx, %rdi; /* arg1 == skb */ \
34343 + push %rdi; /* save skb */ \
34344 push %r9; \
34345 push SKBDATA; \
34346 /* rsi already has offset */ \
34347 @@ -116,8 +154,10 @@ bpf_slow_path_byte:
34348 test %rax,%rax; \
34349 pop SKBDATA; \
34350 pop %r9; \
34351 + pop %rdi; \
34352 jz bpf_error
34353
34354 +
34355 bpf_slow_path_word_neg:
34356 cmp SKF_MAX_NEG_OFF, %esi /* test range */
34357 jl bpf_error /* offset lower -> error */
34358 @@ -126,6 +166,7 @@ sk_load_word_negative_offset:
34359 sk_negative_common(4)
34360 mov (%rax), %eax
34361 bswap %eax
34362 + pax_force_retaddr
34363 ret
34364
34365 bpf_slow_path_half_neg:
34366 @@ -137,6 +178,7 @@ sk_load_half_negative_offset:
34367 mov (%rax),%ax
34368 rol $8,%ax
34369 movzwl %ax,%eax
34370 + pax_force_retaddr
34371 ret
34372
34373 bpf_slow_path_byte_neg:
34374 @@ -146,14 +188,27 @@ sk_load_byte_negative_offset:
34375 .globl sk_load_byte_negative_offset
34376 sk_negative_common(1)
34377 movzbl (%rax), %eax
34378 + pax_force_retaddr
34379 + ret
34380 +
34381 +bpf_slow_path_byte_msh_neg:
34382 + cmp SKF_MAX_NEG_OFF, %esi
34383 + jl bpf_error
34384 +sk_load_byte_msh_negative_offset:
34385 + .globl sk_load_byte_msh_negative_offset
34386 + xchg %eax,%ebx /* dont lose A , X is about to be scratched */
34387 + sk_negative_common(1)
34388 + movzbl (%rax),%eax
34389 + and $15,%al
34390 + shl $2,%al
34391 + xchg %eax,%ebx
34392 + pax_force_retaddr
34393 ret
34394
34395 bpf_error:
34396 # force a return 0 from jit handler
34397 - xor %eax,%eax
34398 - mov - MAX_BPF_STACK(%rbp),%rbx
34399 - mov - MAX_BPF_STACK + 8(%rbp),%r13
34400 - mov - MAX_BPF_STACK + 16(%rbp),%r14
34401 - mov - MAX_BPF_STACK + 24(%rbp),%r15
34402 + xor %eax,%eax
34403 + mov -8(%rbp),%rbx
34404 leaveq
34405 + pax_force_retaddr
34406 ret
34407 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
34408 index 99bef86..bdfb5c6 100644
34409 --- a/arch/x86/net/bpf_jit_comp.c
34410 +++ b/arch/x86/net/bpf_jit_comp.c
34411 @@ -1,7 +1,6 @@
34412 /* bpf_jit_comp.c : BPF JIT compiler
34413 *
34414 * Copyright (C) 2011-2013 Eric Dumazet (eric.dumazet@gmail.com)
34415 - * Internal BPF Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com
34416 *
34417 * This program is free software; you can redistribute it and/or
34418 * modify it under the terms of the GNU General Public License
34419 @@ -15,16 +14,28 @@
34420 #include <linux/if_vlan.h>
34421 #include <linux/random.h>
34422
34423 +/*
34424 + * Conventions :
34425 + * EAX : BPF A accumulator
34426 + * EBX : BPF X accumulator
34427 + * RDI : pointer to skb (first argument given to JIT function)
34428 + * RBP : frame pointer (even if CONFIG_FRAME_POINTER=n)
34429 + * ECX,EDX,ESI : scratch registers
34430 + * r9d : skb->len - skb->data_len (headlen)
34431 + * r8 : skb->data
34432 + * -8(RBP) : saved RBX value
34433 + * -16(RBP)..-80(RBP) : BPF_MEMWORDS values
34434 + */
34435 int bpf_jit_enable __read_mostly;
34436
34437 /*
34438 * assembly code in arch/x86/net/bpf_jit.S
34439 */
34440 -extern u8 sk_load_word[], sk_load_half[], sk_load_byte[];
34441 +extern u8 sk_load_word[], sk_load_half[], sk_load_byte[], sk_load_byte_msh[];
34442 extern u8 sk_load_word_positive_offset[], sk_load_half_positive_offset[];
34443 -extern u8 sk_load_byte_positive_offset[];
34444 +extern u8 sk_load_byte_positive_offset[], sk_load_byte_msh_positive_offset[];
34445 extern u8 sk_load_word_negative_offset[], sk_load_half_negative_offset[];
34446 -extern u8 sk_load_byte_negative_offset[];
34447 +extern u8 sk_load_byte_negative_offset[], sk_load_byte_msh_negative_offset[];
34448
34449 static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
34450 {
34451 @@ -39,50 +50,113 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
34452 return ptr + len;
34453 }
34454
34455 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34456 +#define MAX_INSTR_CODE_SIZE 96
34457 +#else
34458 +#define MAX_INSTR_CODE_SIZE 64
34459 +#endif
34460 +
34461 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
34462
34463 #define EMIT1(b1) EMIT(b1, 1)
34464 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
34465 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
34466 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
34467 -#define EMIT1_off32(b1, off) \
34468 - do {EMIT1(b1); EMIT(off, 4); } while (0)
34469 -#define EMIT2_off32(b1, b2, off) \
34470 - do {EMIT2(b1, b2); EMIT(off, 4); } while (0)
34471 -#define EMIT3_off32(b1, b2, b3, off) \
34472 - do {EMIT3(b1, b2, b3); EMIT(off, 4); } while (0)
34473 -#define EMIT4_off32(b1, b2, b3, b4, off) \
34474 - do {EMIT4(b1, b2, b3, b4); EMIT(off, 4); } while (0)
34475 +
34476 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34477 +/* original constant will appear in ecx */
34478 +#define DILUTE_CONST_SEQUENCE(_off, _key) \
34479 +do { \
34480 + /* mov ecx, randkey */ \
34481 + EMIT1(0xb9); \
34482 + EMIT(_key, 4); \
34483 + /* xor ecx, randkey ^ off */ \
34484 + EMIT2(0x81, 0xf1); \
34485 + EMIT((_key) ^ (_off), 4); \
34486 +} while (0)
34487 +
34488 +#define EMIT1_off32(b1, _off) \
34489 +do { \
34490 + switch (b1) { \
34491 + case 0x05: /* add eax, imm32 */ \
34492 + case 0x2d: /* sub eax, imm32 */ \
34493 + case 0x25: /* and eax, imm32 */ \
34494 + case 0x0d: /* or eax, imm32 */ \
34495 + case 0xb8: /* mov eax, imm32 */ \
34496 + case 0x35: /* xor eax, imm32 */ \
34497 + case 0x3d: /* cmp eax, imm32 */ \
34498 + case 0xa9: /* test eax, imm32 */ \
34499 + DILUTE_CONST_SEQUENCE(_off, randkey); \
34500 + EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
34501 + break; \
34502 + case 0xbb: /* mov ebx, imm32 */ \
34503 + DILUTE_CONST_SEQUENCE(_off, randkey); \
34504 + /* mov ebx, ecx */ \
34505 + EMIT2(0x89, 0xcb); \
34506 + break; \
34507 + case 0xbe: /* mov esi, imm32 */ \
34508 + DILUTE_CONST_SEQUENCE(_off, randkey); \
34509 + /* mov esi, ecx */ \
34510 + EMIT2(0x89, 0xce); \
34511 + break; \
34512 + case 0xe8: /* call rel imm32, always to known funcs */ \
34513 + EMIT1(b1); \
34514 + EMIT(_off, 4); \
34515 + break; \
34516 + case 0xe9: /* jmp rel imm32 */ \
34517 + EMIT1(b1); \
34518 + EMIT(_off, 4); \
34519 + /* prevent fall-through, we're not called if off = 0 */ \
34520 + EMIT(0xcccccccc, 4); \
34521 + EMIT(0xcccccccc, 4); \
34522 + break; \
34523 + default: \
34524 + BUILD_BUG(); \
34525 + } \
34526 +} while (0)
34527 +
34528 +#define EMIT2_off32(b1, b2, _off) \
34529 +do { \
34530 + if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
34531 + EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
34532 + EMIT(randkey, 4); \
34533 + EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
34534 + EMIT((_off) - randkey, 4); \
34535 + } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
34536 + DILUTE_CONST_SEQUENCE(_off, randkey); \
34537 + /* imul eax, ecx */ \
34538 + EMIT3(0x0f, 0xaf, 0xc1); \
34539 + } else { \
34540 + BUILD_BUG(); \
34541 + } \
34542 +} while (0)
34543 +#else
34544 +#define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
34545 +#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
34546 +#endif
34547 +
34548 +#define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
34549 +#define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
34550
34551 static inline bool is_imm8(int value)
34552 {
34553 return value <= 127 && value >= -128;
34554 }
34555
34556 -static inline bool is_simm32(s64 value)
34557 +static inline bool is_near(int offset)
34558 {
34559 - return value == (s64) (s32) value;
34560 + return offset <= 127 && offset >= -128;
34561 }
34562
34563 -/* mov dst, src */
34564 -#define EMIT_mov(DST, SRC) \
34565 - do {if (DST != SRC) \
34566 - EMIT3(add_2mod(0x48, DST, SRC), 0x89, add_2reg(0xC0, DST, SRC)); \
34567 - } while (0)
34568 -
34569 -static int bpf_size_to_x86_bytes(int bpf_size)
34570 -{
34571 - if (bpf_size == BPF_W)
34572 - return 4;
34573 - else if (bpf_size == BPF_H)
34574 - return 2;
34575 - else if (bpf_size == BPF_B)
34576 - return 1;
34577 - else if (bpf_size == BPF_DW)
34578 - return 4; /* imm32 */
34579 - else
34580 - return 0;
34581 -}
34582 +#define EMIT_JMP(offset) \
34583 +do { \
34584 + if (offset) { \
34585 + if (is_near(offset)) \
34586 + EMIT2(0xeb, offset); /* jmp .+off8 */ \
34587 + else \
34588 + EMIT1_off32(0xe9, offset); /* jmp .+off32 */ \
34589 + } \
34590 +} while (0)
34591
34592 /* list of x86 cond jumps opcodes (. + s8)
34593 * Add 0x10 (and an extra 0x0f) to generate far jumps (. + s32)
34594 @@ -93,8 +167,46 @@ static int bpf_size_to_x86_bytes(int bpf_size)
34595 #define X86_JNE 0x75
34596 #define X86_JBE 0x76
34597 #define X86_JA 0x77
34598 -#define X86_JGE 0x7D
34599 -#define X86_JG 0x7F
34600 +
34601 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34602 +#define APPEND_FLOW_VERIFY() \
34603 +do { \
34604 + /* mov ecx, randkey */ \
34605 + EMIT1(0xb9); \
34606 + EMIT(randkey, 4); \
34607 + /* cmp ecx, randkey */ \
34608 + EMIT2(0x81, 0xf9); \
34609 + EMIT(randkey, 4); \
34610 + /* jz after 8 int 3s */ \
34611 + EMIT2(0x74, 0x08); \
34612 + EMIT(0xcccccccc, 4); \
34613 + EMIT(0xcccccccc, 4); \
34614 +} while (0)
34615 +#else
34616 +#define APPEND_FLOW_VERIFY() do { } while (0)
34617 +#endif
34618 +
34619 +#define EMIT_COND_JMP(op, offset) \
34620 +do { \
34621 + if (is_near(offset)) \
34622 + EMIT2(op, offset); /* jxx .+off8 */ \
34623 + else { \
34624 + EMIT2(0x0f, op + 0x10); \
34625 + EMIT(offset, 4); /* jxx .+off32 */ \
34626 + APPEND_FLOW_VERIFY(); \
34627 + } \
34628 +} while (0)
34629 +
34630 +#define COND_SEL(CODE, TOP, FOP) \
34631 + case CODE: \
34632 + t_op = TOP; \
34633 + f_op = FOP; \
34634 + goto cond_branch
34635 +
34636 +
34637 +#define SEEN_DATAREF 1 /* might call external helpers */
34638 +#define SEEN_XREG 2 /* ebx is used */
34639 +#define SEEN_MEM 4 /* use mem[] for temporary storage */
34640
34641 static inline void bpf_flush_icache(void *start, void *end)
34642 {
34643 @@ -109,804 +221,646 @@ static inline void bpf_flush_icache(void *start, void *end)
34644 #define CHOOSE_LOAD_FUNC(K, func) \
34645 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
34646
34647 -struct bpf_binary_header {
34648 - unsigned int pages;
34649 - /* Note : for security reasons, bpf code will follow a randomly
34650 - * sized amount of int3 instructions
34651 - */
34652 - u8 image[];
34653 -};
34654 +/* Helper to find the offset of pkt_type in sk_buff
34655 + * We want to make sure its still a 3bit field starting at a byte boundary.
34656 + */
34657 +#define PKT_TYPE_MAX 7
34658 +static int pkt_type_offset(void)
34659 +{
34660 + struct sk_buff skb_probe = {
34661 + .pkt_type = ~0,
34662 + };
34663 + char *ct = (char *)&skb_probe;
34664 + unsigned int off;
34665
34666 -static struct bpf_binary_header *bpf_alloc_binary(unsigned int proglen,
34667 + for (off = 0; off < sizeof(struct sk_buff); off++) {
34668 + if (ct[off] == PKT_TYPE_MAX)
34669 + return off;
34670 + }
34671 + pr_err_once("Please fix pkt_type_offset(), as pkt_type couldn't be found\n");
34672 + return -1;
34673 +}
34674 +
34675 +/* Note : for security reasons, bpf code will follow a randomly
34676 + * sized amount of int3 instructions
34677 + */
34678 +static u8 *bpf_alloc_binary(unsigned int proglen,
34679 u8 **image_ptr)
34680 {
34681 unsigned int sz, hole;
34682 - struct bpf_binary_header *header;
34683 + u8 *header;
34684
34685 /* Most of BPF filters are really small,
34686 * but if some of them fill a page, allow at least
34687 * 128 extra bytes to insert a random section of int3
34688 */
34689 - sz = round_up(proglen + sizeof(*header) + 128, PAGE_SIZE);
34690 - header = module_alloc(sz);
34691 + sz = round_up(proglen + 128, PAGE_SIZE);
34692 + header = module_alloc_exec(sz);
34693 if (!header)
34694 return NULL;
34695
34696 + pax_open_kernel();
34697 memset(header, 0xcc, sz); /* fill whole space with int3 instructions */
34698 + pax_close_kernel();
34699
34700 - header->pages = sz / PAGE_SIZE;
34701 - hole = min(sz - (proglen + sizeof(*header)), PAGE_SIZE - sizeof(*header));
34702 + hole = PAGE_SIZE - (proglen & ~PAGE_MASK);
34703
34704 /* insert a random number of int3 instructions before BPF code */
34705 - *image_ptr = &header->image[prandom_u32() % hole];
34706 + *image_ptr = &header[prandom_u32() % hole];
34707 return header;
34708 }
34709
34710 -/* pick a register outside of BPF range for JIT internal work */
34711 -#define AUX_REG (MAX_BPF_REG + 1)
34712 -
34713 -/* the following table maps BPF registers to x64 registers.
34714 - * x64 register r12 is unused, since if used as base address register
34715 - * in load/store instructions, it always needs an extra byte of encoding
34716 - */
34717 -static const int reg2hex[] = {
34718 - [BPF_REG_0] = 0, /* rax */
34719 - [BPF_REG_1] = 7, /* rdi */
34720 - [BPF_REG_2] = 6, /* rsi */
34721 - [BPF_REG_3] = 2, /* rdx */
34722 - [BPF_REG_4] = 1, /* rcx */
34723 - [BPF_REG_5] = 0, /* r8 */
34724 - [BPF_REG_6] = 3, /* rbx callee saved */
34725 - [BPF_REG_7] = 5, /* r13 callee saved */
34726 - [BPF_REG_8] = 6, /* r14 callee saved */
34727 - [BPF_REG_9] = 7, /* r15 callee saved */
34728 - [BPF_REG_FP] = 5, /* rbp readonly */
34729 - [AUX_REG] = 3, /* r11 temp register */
34730 -};
34731 -
34732 -/* is_ereg() == true if BPF register 'reg' maps to x64 r8..r15
34733 - * which need extra byte of encoding.
34734 - * rax,rcx,...,rbp have simpler encoding
34735 - */
34736 -static inline bool is_ereg(u32 reg)
34737 -{
34738 - if (reg == BPF_REG_5 || reg == AUX_REG ||
34739 - (reg >= BPF_REG_7 && reg <= BPF_REG_9))
34740 - return true;
34741 - else
34742 - return false;
34743 -}
34744 -
34745 -/* add modifiers if 'reg' maps to x64 registers r8..r15 */
34746 -static inline u8 add_1mod(u8 byte, u32 reg)
34747 -{
34748 - if (is_ereg(reg))
34749 - byte |= 1;
34750 - return byte;
34751 -}
34752 -
34753 -static inline u8 add_2mod(u8 byte, u32 r1, u32 r2)
34754 -{
34755 - if (is_ereg(r1))
34756 - byte |= 1;
34757 - if (is_ereg(r2))
34758 - byte |= 4;
34759 - return byte;
34760 -}
34761 -
34762 -/* encode 'dst_reg' register into x64 opcode 'byte' */
34763 -static inline u8 add_1reg(u8 byte, u32 dst_reg)
34764 -{
34765 - return byte + reg2hex[dst_reg];
34766 -}
34767 -
34768 -/* encode 'dst_reg' and 'src_reg' registers into x64 opcode 'byte' */
34769 -static inline u8 add_2reg(u8 byte, u32 dst_reg, u32 src_reg)
34770 -{
34771 - return byte + reg2hex[dst_reg] + (reg2hex[src_reg] << 3);
34772 -}
34773 -
34774 -struct jit_context {
34775 - unsigned int cleanup_addr; /* epilogue code offset */
34776 - bool seen_ld_abs;
34777 -};
34778 -
34779 -static int do_jit(struct sk_filter *bpf_prog, int *addrs, u8 *image,
34780 - int oldproglen, struct jit_context *ctx)
34781 -{
34782 - struct sock_filter_int *insn = bpf_prog->insnsi;
34783 - int insn_cnt = bpf_prog->len;
34784 - u8 temp[64];
34785 - int i;
34786 - int proglen = 0;
34787 - u8 *prog = temp;
34788 - int stacksize = MAX_BPF_STACK +
34789 - 32 /* space for rbx, r13, r14, r15 */ +
34790 - 8 /* space for skb_copy_bits() buffer */;
34791 -
34792 - EMIT1(0x55); /* push rbp */
34793 - EMIT3(0x48, 0x89, 0xE5); /* mov rbp,rsp */
34794 -
34795 - /* sub rsp, stacksize */
34796 - EMIT3_off32(0x48, 0x81, 0xEC, stacksize);
34797 -
34798 - /* all classic BPF filters use R6(rbx) save it */
34799 -
34800 - /* mov qword ptr [rbp-X],rbx */
34801 - EMIT3_off32(0x48, 0x89, 0x9D, -stacksize);
34802 -
34803 - /* sk_convert_filter() maps classic BPF register X to R7 and uses R8
34804 - * as temporary, so all tcpdump filters need to spill/fill R7(r13) and
34805 - * R8(r14). R9(r15) spill could be made conditional, but there is only
34806 - * one 'bpf_error' return path out of helper functions inside bpf_jit.S
34807 - * The overhead of extra spill is negligible for any filter other
34808 - * than synthetic ones. Therefore not worth adding complexity.
34809 - */
34810 -
34811 - /* mov qword ptr [rbp-X],r13 */
34812 - EMIT3_off32(0x4C, 0x89, 0xAD, -stacksize + 8);
34813 - /* mov qword ptr [rbp-X],r14 */
34814 - EMIT3_off32(0x4C, 0x89, 0xB5, -stacksize + 16);
34815 - /* mov qword ptr [rbp-X],r15 */
34816 - EMIT3_off32(0x4C, 0x89, 0xBD, -stacksize + 24);
34817 -
34818 - /* clear A and X registers */
34819 - EMIT2(0x31, 0xc0); /* xor eax, eax */
34820 - EMIT3(0x4D, 0x31, 0xED); /* xor r13, r13 */
34821 -
34822 - if (ctx->seen_ld_abs) {
34823 - /* r9d : skb->len - skb->data_len (headlen)
34824 - * r10 : skb->data
34825 - */
34826 - if (is_imm8(offsetof(struct sk_buff, len)))
34827 - /* mov %r9d, off8(%rdi) */
34828 - EMIT4(0x44, 0x8b, 0x4f,
34829 - offsetof(struct sk_buff, len));
34830 - else
34831 - /* mov %r9d, off32(%rdi) */
34832 - EMIT3_off32(0x44, 0x8b, 0x8f,
34833 - offsetof(struct sk_buff, len));
34834 -
34835 - if (is_imm8(offsetof(struct sk_buff, data_len)))
34836 - /* sub %r9d, off8(%rdi) */
34837 - EMIT4(0x44, 0x2b, 0x4f,
34838 - offsetof(struct sk_buff, data_len));
34839 - else
34840 - EMIT3_off32(0x44, 0x2b, 0x8f,
34841 - offsetof(struct sk_buff, data_len));
34842 -
34843 - if (is_imm8(offsetof(struct sk_buff, data)))
34844 - /* mov %r10, off8(%rdi) */
34845 - EMIT4(0x4c, 0x8b, 0x57,
34846 - offsetof(struct sk_buff, data));
34847 - else
34848 - /* mov %r10, off32(%rdi) */
34849 - EMIT3_off32(0x4c, 0x8b, 0x97,
34850 - offsetof(struct sk_buff, data));
34851 - }
34852 -
34853 - for (i = 0; i < insn_cnt; i++, insn++) {
34854 - const s32 imm32 = insn->imm;
34855 - u32 dst_reg = insn->dst_reg;
34856 - u32 src_reg = insn->src_reg;
34857 - u8 b1 = 0, b2 = 0, b3 = 0;
34858 - s64 jmp_offset;
34859 - u8 jmp_cond;
34860 - int ilen;
34861 - u8 *func;
34862 -
34863 - switch (insn->code) {
34864 - /* ALU */
34865 - case BPF_ALU | BPF_ADD | BPF_X:
34866 - case BPF_ALU | BPF_SUB | BPF_X:
34867 - case BPF_ALU | BPF_AND | BPF_X:
34868 - case BPF_ALU | BPF_OR | BPF_X:
34869 - case BPF_ALU | BPF_XOR | BPF_X:
34870 - case BPF_ALU64 | BPF_ADD | BPF_X:
34871 - case BPF_ALU64 | BPF_SUB | BPF_X:
34872 - case BPF_ALU64 | BPF_AND | BPF_X:
34873 - case BPF_ALU64 | BPF_OR | BPF_X:
34874 - case BPF_ALU64 | BPF_XOR | BPF_X:
34875 - switch (BPF_OP(insn->code)) {
34876 - case BPF_ADD: b2 = 0x01; break;
34877 - case BPF_SUB: b2 = 0x29; break;
34878 - case BPF_AND: b2 = 0x21; break;
34879 - case BPF_OR: b2 = 0x09; break;
34880 - case BPF_XOR: b2 = 0x31; break;
34881 - }
34882 - if (BPF_CLASS(insn->code) == BPF_ALU64)
34883 - EMIT1(add_2mod(0x48, dst_reg, src_reg));
34884 - else if (is_ereg(dst_reg) || is_ereg(src_reg))
34885 - EMIT1(add_2mod(0x40, dst_reg, src_reg));
34886 - EMIT2(b2, add_2reg(0xC0, dst_reg, src_reg));
34887 - break;
34888 -
34889 - /* mov dst, src */
34890 - case BPF_ALU64 | BPF_MOV | BPF_X:
34891 - EMIT_mov(dst_reg, src_reg);
34892 - break;
34893 -
34894 - /* mov32 dst, src */
34895 - case BPF_ALU | BPF_MOV | BPF_X:
34896 - if (is_ereg(dst_reg) || is_ereg(src_reg))
34897 - EMIT1(add_2mod(0x40, dst_reg, src_reg));
34898 - EMIT2(0x89, add_2reg(0xC0, dst_reg, src_reg));
34899 - break;
34900 -
34901 - /* neg dst */
34902 - case BPF_ALU | BPF_NEG:
34903 - case BPF_ALU64 | BPF_NEG:
34904 - if (BPF_CLASS(insn->code) == BPF_ALU64)
34905 - EMIT1(add_1mod(0x48, dst_reg));
34906 - else if (is_ereg(dst_reg))
34907 - EMIT1(add_1mod(0x40, dst_reg));
34908 - EMIT2(0xF7, add_1reg(0xD8, dst_reg));
34909 - break;
34910 -
34911 - case BPF_ALU | BPF_ADD | BPF_K:
34912 - case BPF_ALU | BPF_SUB | BPF_K:
34913 - case BPF_ALU | BPF_AND | BPF_K:
34914 - case BPF_ALU | BPF_OR | BPF_K:
34915 - case BPF_ALU | BPF_XOR | BPF_K:
34916 - case BPF_ALU64 | BPF_ADD | BPF_K:
34917 - case BPF_ALU64 | BPF_SUB | BPF_K:
34918 - case BPF_ALU64 | BPF_AND | BPF_K:
34919 - case BPF_ALU64 | BPF_OR | BPF_K:
34920 - case BPF_ALU64 | BPF_XOR | BPF_K:
34921 - if (BPF_CLASS(insn->code) == BPF_ALU64)
34922 - EMIT1(add_1mod(0x48, dst_reg));
34923 - else if (is_ereg(dst_reg))
34924 - EMIT1(add_1mod(0x40, dst_reg));
34925 -
34926 - switch (BPF_OP(insn->code)) {
34927 - case BPF_ADD: b3 = 0xC0; break;
34928 - case BPF_SUB: b3 = 0xE8; break;
34929 - case BPF_AND: b3 = 0xE0; break;
34930 - case BPF_OR: b3 = 0xC8; break;
34931 - case BPF_XOR: b3 = 0xF0; break;
34932 - }
34933 -
34934 - if (is_imm8(imm32))
34935 - EMIT3(0x83, add_1reg(b3, dst_reg), imm32);
34936 - else
34937 - EMIT2_off32(0x81, add_1reg(b3, dst_reg), imm32);
34938 - break;
34939 -
34940 - case BPF_ALU64 | BPF_MOV | BPF_K:
34941 - /* optimization: if imm32 is positive,
34942 - * use 'mov eax, imm32' (which zero-extends imm32)
34943 - * to save 2 bytes
34944 - */
34945 - if (imm32 < 0) {
34946 - /* 'mov rax, imm32' sign extends imm32 */
34947 - b1 = add_1mod(0x48, dst_reg);
34948 - b2 = 0xC7;
34949 - b3 = 0xC0;
34950 - EMIT3_off32(b1, b2, add_1reg(b3, dst_reg), imm32);
34951 - break;
34952 - }
34953 -
34954 - case BPF_ALU | BPF_MOV | BPF_K:
34955 - /* mov %eax, imm32 */
34956 - if (is_ereg(dst_reg))
34957 - EMIT1(add_1mod(0x40, dst_reg));
34958 - EMIT1_off32(add_1reg(0xB8, dst_reg), imm32);
34959 - break;
34960 -
34961 - /* dst %= src, dst /= src, dst %= imm32, dst /= imm32 */
34962 - case BPF_ALU | BPF_MOD | BPF_X:
34963 - case BPF_ALU | BPF_DIV | BPF_X:
34964 - case BPF_ALU | BPF_MOD | BPF_K:
34965 - case BPF_ALU | BPF_DIV | BPF_K:
34966 - case BPF_ALU64 | BPF_MOD | BPF_X:
34967 - case BPF_ALU64 | BPF_DIV | BPF_X:
34968 - case BPF_ALU64 | BPF_MOD | BPF_K:
34969 - case BPF_ALU64 | BPF_DIV | BPF_K:
34970 - EMIT1(0x50); /* push rax */
34971 - EMIT1(0x52); /* push rdx */
34972 -
34973 - if (BPF_SRC(insn->code) == BPF_X)
34974 - /* mov r11, src_reg */
34975 - EMIT_mov(AUX_REG, src_reg);
34976 - else
34977 - /* mov r11, imm32 */
34978 - EMIT3_off32(0x49, 0xC7, 0xC3, imm32);
34979 -
34980 - /* mov rax, dst_reg */
34981 - EMIT_mov(BPF_REG_0, dst_reg);
34982 -
34983 - /* xor edx, edx
34984 - * equivalent to 'xor rdx, rdx', but one byte less
34985 - */
34986 - EMIT2(0x31, 0xd2);
34987 -
34988 - if (BPF_SRC(insn->code) == BPF_X) {
34989 - /* if (src_reg == 0) return 0 */
34990 -
34991 - /* cmp r11, 0 */
34992 - EMIT4(0x49, 0x83, 0xFB, 0x00);
34993 -
34994 - /* jne .+9 (skip over pop, pop, xor and jmp) */
34995 - EMIT2(X86_JNE, 1 + 1 + 2 + 5);
34996 - EMIT1(0x5A); /* pop rdx */
34997 - EMIT1(0x58); /* pop rax */
34998 - EMIT2(0x31, 0xc0); /* xor eax, eax */
34999 -
35000 - /* jmp cleanup_addr
35001 - * addrs[i] - 11, because there are 11 bytes
35002 - * after this insn: div, mov, pop, pop, mov
35003 - */
35004 - jmp_offset = ctx->cleanup_addr - (addrs[i] - 11);
35005 - EMIT1_off32(0xE9, jmp_offset);
35006 - }
35007 -
35008 - if (BPF_CLASS(insn->code) == BPF_ALU64)
35009 - /* div r11 */
35010 - EMIT3(0x49, 0xF7, 0xF3);
35011 - else
35012 - /* div r11d */
35013 - EMIT3(0x41, 0xF7, 0xF3);
35014 -
35015 - if (BPF_OP(insn->code) == BPF_MOD)
35016 - /* mov r11, rdx */
35017 - EMIT3(0x49, 0x89, 0xD3);
35018 - else
35019 - /* mov r11, rax */
35020 - EMIT3(0x49, 0x89, 0xC3);
35021 -
35022 - EMIT1(0x5A); /* pop rdx */
35023 - EMIT1(0x58); /* pop rax */
35024 -
35025 - /* mov dst_reg, r11 */
35026 - EMIT_mov(dst_reg, AUX_REG);
35027 - break;
35028 -
35029 - case BPF_ALU | BPF_MUL | BPF_K:
35030 - case BPF_ALU | BPF_MUL | BPF_X:
35031 - case BPF_ALU64 | BPF_MUL | BPF_K:
35032 - case BPF_ALU64 | BPF_MUL | BPF_X:
35033 - EMIT1(0x50); /* push rax */
35034 - EMIT1(0x52); /* push rdx */
35035 -
35036 - /* mov r11, dst_reg */
35037 - EMIT_mov(AUX_REG, dst_reg);
35038 -
35039 - if (BPF_SRC(insn->code) == BPF_X)
35040 - /* mov rax, src_reg */
35041 - EMIT_mov(BPF_REG_0, src_reg);
35042 - else
35043 - /* mov rax, imm32 */
35044 - EMIT3_off32(0x48, 0xC7, 0xC0, imm32);
35045 -
35046 - if (BPF_CLASS(insn->code) == BPF_ALU64)
35047 - EMIT1(add_1mod(0x48, AUX_REG));
35048 - else if (is_ereg(AUX_REG))
35049 - EMIT1(add_1mod(0x40, AUX_REG));
35050 - /* mul(q) r11 */
35051 - EMIT2(0xF7, add_1reg(0xE0, AUX_REG));
35052 -
35053 - /* mov r11, rax */
35054 - EMIT_mov(AUX_REG, BPF_REG_0);
35055 -
35056 - EMIT1(0x5A); /* pop rdx */
35057 - EMIT1(0x58); /* pop rax */
35058 -
35059 - /* mov dst_reg, r11 */
35060 - EMIT_mov(dst_reg, AUX_REG);
35061 - break;
35062 -
35063 - /* shifts */
35064 - case BPF_ALU | BPF_LSH | BPF_K:
35065 - case BPF_ALU | BPF_RSH | BPF_K:
35066 - case BPF_ALU | BPF_ARSH | BPF_K:
35067 - case BPF_ALU64 | BPF_LSH | BPF_K:
35068 - case BPF_ALU64 | BPF_RSH | BPF_K:
35069 - case BPF_ALU64 | BPF_ARSH | BPF_K:
35070 - if (BPF_CLASS(insn->code) == BPF_ALU64)
35071 - EMIT1(add_1mod(0x48, dst_reg));
35072 - else if (is_ereg(dst_reg))
35073 - EMIT1(add_1mod(0x40, dst_reg));
35074 -
35075 - switch (BPF_OP(insn->code)) {
35076 - case BPF_LSH: b3 = 0xE0; break;
35077 - case BPF_RSH: b3 = 0xE8; break;
35078 - case BPF_ARSH: b3 = 0xF8; break;
35079 - }
35080 - EMIT3(0xC1, add_1reg(b3, dst_reg), imm32);
35081 - break;
35082 -
35083 - case BPF_ALU | BPF_END | BPF_FROM_BE:
35084 - switch (imm32) {
35085 - case 16:
35086 - /* emit 'ror %ax, 8' to swap lower 2 bytes */
35087 - EMIT1(0x66);
35088 - if (is_ereg(dst_reg))
35089 - EMIT1(0x41);
35090 - EMIT3(0xC1, add_1reg(0xC8, dst_reg), 8);
35091 - break;
35092 - case 32:
35093 - /* emit 'bswap eax' to swap lower 4 bytes */
35094 - if (is_ereg(dst_reg))
35095 - EMIT2(0x41, 0x0F);
35096 - else
35097 - EMIT1(0x0F);
35098 - EMIT1(add_1reg(0xC8, dst_reg));
35099 - break;
35100 - case 64:
35101 - /* emit 'bswap rax' to swap 8 bytes */
35102 - EMIT3(add_1mod(0x48, dst_reg), 0x0F,
35103 - add_1reg(0xC8, dst_reg));
35104 - break;
35105 - }
35106 - break;
35107 -
35108 - case BPF_ALU | BPF_END | BPF_FROM_LE:
35109 - break;
35110 -
35111 - /* ST: *(u8*)(dst_reg + off) = imm */
35112 - case BPF_ST | BPF_MEM | BPF_B:
35113 - if (is_ereg(dst_reg))
35114 - EMIT2(0x41, 0xC6);
35115 - else
35116 - EMIT1(0xC6);
35117 - goto st;
35118 - case BPF_ST | BPF_MEM | BPF_H:
35119 - if (is_ereg(dst_reg))
35120 - EMIT3(0x66, 0x41, 0xC7);
35121 - else
35122 - EMIT2(0x66, 0xC7);
35123 - goto st;
35124 - case BPF_ST | BPF_MEM | BPF_W:
35125 - if (is_ereg(dst_reg))
35126 - EMIT2(0x41, 0xC7);
35127 - else
35128 - EMIT1(0xC7);
35129 - goto st;
35130 - case BPF_ST | BPF_MEM | BPF_DW:
35131 - EMIT2(add_1mod(0x48, dst_reg), 0xC7);
35132 -
35133 -st: if (is_imm8(insn->off))
35134 - EMIT2(add_1reg(0x40, dst_reg), insn->off);
35135 - else
35136 - EMIT1_off32(add_1reg(0x80, dst_reg), insn->off);
35137 -
35138 - EMIT(imm32, bpf_size_to_x86_bytes(BPF_SIZE(insn->code)));
35139 - break;
35140 -
35141 - /* STX: *(u8*)(dst_reg + off) = src_reg */
35142 - case BPF_STX | BPF_MEM | BPF_B:
35143 - /* emit 'mov byte ptr [rax + off], al' */
35144 - if (is_ereg(dst_reg) || is_ereg(src_reg) ||
35145 - /* have to add extra byte for x86 SIL, DIL regs */
35146 - src_reg == BPF_REG_1 || src_reg == BPF_REG_2)
35147 - EMIT2(add_2mod(0x40, dst_reg, src_reg), 0x88);
35148 - else
35149 - EMIT1(0x88);
35150 - goto stx;
35151 - case BPF_STX | BPF_MEM | BPF_H:
35152 - if (is_ereg(dst_reg) || is_ereg(src_reg))
35153 - EMIT3(0x66, add_2mod(0x40, dst_reg, src_reg), 0x89);
35154 - else
35155 - EMIT2(0x66, 0x89);
35156 - goto stx;
35157 - case BPF_STX | BPF_MEM | BPF_W:
35158 - if (is_ereg(dst_reg) || is_ereg(src_reg))
35159 - EMIT2(add_2mod(0x40, dst_reg, src_reg), 0x89);
35160 - else
35161 - EMIT1(0x89);
35162 - goto stx;
35163 - case BPF_STX | BPF_MEM | BPF_DW:
35164 - EMIT2(add_2mod(0x48, dst_reg, src_reg), 0x89);
35165 -stx: if (is_imm8(insn->off))
35166 - EMIT2(add_2reg(0x40, dst_reg, src_reg), insn->off);
35167 - else
35168 - EMIT1_off32(add_2reg(0x80, dst_reg, src_reg),
35169 - insn->off);
35170 - break;
35171 -
35172 - /* LDX: dst_reg = *(u8*)(src_reg + off) */
35173 - case BPF_LDX | BPF_MEM | BPF_B:
35174 - /* emit 'movzx rax, byte ptr [rax + off]' */
35175 - EMIT3(add_2mod(0x48, src_reg, dst_reg), 0x0F, 0xB6);
35176 - goto ldx;
35177 - case BPF_LDX | BPF_MEM | BPF_H:
35178 - /* emit 'movzx rax, word ptr [rax + off]' */
35179 - EMIT3(add_2mod(0x48, src_reg, dst_reg), 0x0F, 0xB7);
35180 - goto ldx;
35181 - case BPF_LDX | BPF_MEM | BPF_W:
35182 - /* emit 'mov eax, dword ptr [rax+0x14]' */
35183 - if (is_ereg(dst_reg) || is_ereg(src_reg))
35184 - EMIT2(add_2mod(0x40, src_reg, dst_reg), 0x8B);
35185 - else
35186 - EMIT1(0x8B);
35187 - goto ldx;
35188 - case BPF_LDX | BPF_MEM | BPF_DW:
35189 - /* emit 'mov rax, qword ptr [rax+0x14]' */
35190 - EMIT2(add_2mod(0x48, src_reg, dst_reg), 0x8B);
35191 -ldx: /* if insn->off == 0 we can save one extra byte, but
35192 - * special case of x86 r13 which always needs an offset
35193 - * is not worth the hassle
35194 - */
35195 - if (is_imm8(insn->off))
35196 - EMIT2(add_2reg(0x40, src_reg, dst_reg), insn->off);
35197 - else
35198 - EMIT1_off32(add_2reg(0x80, src_reg, dst_reg),
35199 - insn->off);
35200 - break;
35201 -
35202 - /* STX XADD: lock *(u32*)(dst_reg + off) += src_reg */
35203 - case BPF_STX | BPF_XADD | BPF_W:
35204 - /* emit 'lock add dword ptr [rax + off], eax' */
35205 - if (is_ereg(dst_reg) || is_ereg(src_reg))
35206 - EMIT3(0xF0, add_2mod(0x40, dst_reg, src_reg), 0x01);
35207 - else
35208 - EMIT2(0xF0, 0x01);
35209 - goto xadd;
35210 - case BPF_STX | BPF_XADD | BPF_DW:
35211 - EMIT3(0xF0, add_2mod(0x48, dst_reg, src_reg), 0x01);
35212 -xadd: if (is_imm8(insn->off))
35213 - EMIT2(add_2reg(0x40, dst_reg, src_reg), insn->off);
35214 - else
35215 - EMIT1_off32(add_2reg(0x80, dst_reg, src_reg),
35216 - insn->off);
35217 - break;
35218 -
35219 - /* call */
35220 - case BPF_JMP | BPF_CALL:
35221 - func = (u8 *) __bpf_call_base + imm32;
35222 - jmp_offset = func - (image + addrs[i]);
35223 - if (ctx->seen_ld_abs) {
35224 - EMIT2(0x41, 0x52); /* push %r10 */
35225 - EMIT2(0x41, 0x51); /* push %r9 */
35226 - /* need to adjust jmp offset, since
35227 - * pop %r9, pop %r10 take 4 bytes after call insn
35228 - */
35229 - jmp_offset += 4;
35230 - }
35231 - if (!imm32 || !is_simm32(jmp_offset)) {
35232 - pr_err("unsupported bpf func %d addr %p image %p\n",
35233 - imm32, func, image);
35234 - return -EINVAL;
35235 - }
35236 - EMIT1_off32(0xE8, jmp_offset);
35237 - if (ctx->seen_ld_abs) {
35238 - EMIT2(0x41, 0x59); /* pop %r9 */
35239 - EMIT2(0x41, 0x5A); /* pop %r10 */
35240 - }
35241 - break;
35242 -
35243 - /* cond jump */
35244 - case BPF_JMP | BPF_JEQ | BPF_X:
35245 - case BPF_JMP | BPF_JNE | BPF_X:
35246 - case BPF_JMP | BPF_JGT | BPF_X:
35247 - case BPF_JMP | BPF_JGE | BPF_X:
35248 - case BPF_JMP | BPF_JSGT | BPF_X:
35249 - case BPF_JMP | BPF_JSGE | BPF_X:
35250 - /* cmp dst_reg, src_reg */
35251 - EMIT3(add_2mod(0x48, dst_reg, src_reg), 0x39,
35252 - add_2reg(0xC0, dst_reg, src_reg));
35253 - goto emit_cond_jmp;
35254 -
35255 - case BPF_JMP | BPF_JSET | BPF_X:
35256 - /* test dst_reg, src_reg */
35257 - EMIT3(add_2mod(0x48, dst_reg, src_reg), 0x85,
35258 - add_2reg(0xC0, dst_reg, src_reg));
35259 - goto emit_cond_jmp;
35260 -
35261 - case BPF_JMP | BPF_JSET | BPF_K:
35262 - /* test dst_reg, imm32 */
35263 - EMIT1(add_1mod(0x48, dst_reg));
35264 - EMIT2_off32(0xF7, add_1reg(0xC0, dst_reg), imm32);
35265 - goto emit_cond_jmp;
35266 -
35267 - case BPF_JMP | BPF_JEQ | BPF_K:
35268 - case BPF_JMP | BPF_JNE | BPF_K:
35269 - case BPF_JMP | BPF_JGT | BPF_K:
35270 - case BPF_JMP | BPF_JGE | BPF_K:
35271 - case BPF_JMP | BPF_JSGT | BPF_K:
35272 - case BPF_JMP | BPF_JSGE | BPF_K:
35273 - /* cmp dst_reg, imm8/32 */
35274 - EMIT1(add_1mod(0x48, dst_reg));
35275 -
35276 - if (is_imm8(imm32))
35277 - EMIT3(0x83, add_1reg(0xF8, dst_reg), imm32);
35278 - else
35279 - EMIT2_off32(0x81, add_1reg(0xF8, dst_reg), imm32);
35280 -
35281 -emit_cond_jmp: /* convert BPF opcode to x86 */
35282 - switch (BPF_OP(insn->code)) {
35283 - case BPF_JEQ:
35284 - jmp_cond = X86_JE;
35285 - break;
35286 - case BPF_JSET:
35287 - case BPF_JNE:
35288 - jmp_cond = X86_JNE;
35289 - break;
35290 - case BPF_JGT:
35291 - /* GT is unsigned '>', JA in x86 */
35292 - jmp_cond = X86_JA;
35293 - break;
35294 - case BPF_JGE:
35295 - /* GE is unsigned '>=', JAE in x86 */
35296 - jmp_cond = X86_JAE;
35297 - break;
35298 - case BPF_JSGT:
35299 - /* signed '>', GT in x86 */
35300 - jmp_cond = X86_JG;
35301 - break;
35302 - case BPF_JSGE:
35303 - /* signed '>=', GE in x86 */
35304 - jmp_cond = X86_JGE;
35305 - break;
35306 - default: /* to silence gcc warning */
35307 - return -EFAULT;
35308 - }
35309 - jmp_offset = addrs[i + insn->off] - addrs[i];
35310 - if (is_imm8(jmp_offset)) {
35311 - EMIT2(jmp_cond, jmp_offset);
35312 - } else if (is_simm32(jmp_offset)) {
35313 - EMIT2_off32(0x0F, jmp_cond + 0x10, jmp_offset);
35314 - } else {
35315 - pr_err("cond_jmp gen bug %llx\n", jmp_offset);
35316 - return -EFAULT;
35317 - }
35318 -
35319 - break;
35320 -
35321 - case BPF_JMP | BPF_JA:
35322 - jmp_offset = addrs[i + insn->off] - addrs[i];
35323 - if (!jmp_offset)
35324 - /* optimize out nop jumps */
35325 - break;
35326 -emit_jmp:
35327 - if (is_imm8(jmp_offset)) {
35328 - EMIT2(0xEB, jmp_offset);
35329 - } else if (is_simm32(jmp_offset)) {
35330 - EMIT1_off32(0xE9, jmp_offset);
35331 - } else {
35332 - pr_err("jmp gen bug %llx\n", jmp_offset);
35333 - return -EFAULT;
35334 - }
35335 - break;
35336 -
35337 - case BPF_LD | BPF_IND | BPF_W:
35338 - func = sk_load_word;
35339 - goto common_load;
35340 - case BPF_LD | BPF_ABS | BPF_W:
35341 - func = CHOOSE_LOAD_FUNC(imm32, sk_load_word);
35342 -common_load: ctx->seen_ld_abs = true;
35343 - jmp_offset = func - (image + addrs[i]);
35344 - if (!func || !is_simm32(jmp_offset)) {
35345 - pr_err("unsupported bpf func %d addr %p image %p\n",
35346 - imm32, func, image);
35347 - return -EINVAL;
35348 - }
35349 - if (BPF_MODE(insn->code) == BPF_ABS) {
35350 - /* mov %esi, imm32 */
35351 - EMIT1_off32(0xBE, imm32);
35352 - } else {
35353 - /* mov %rsi, src_reg */
35354 - EMIT_mov(BPF_REG_2, src_reg);
35355 - if (imm32) {
35356 - if (is_imm8(imm32))
35357 - /* add %esi, imm8 */
35358 - EMIT3(0x83, 0xC6, imm32);
35359 - else
35360 - /* add %esi, imm32 */
35361 - EMIT2_off32(0x81, 0xC6, imm32);
35362 - }
35363 - }
35364 - /* skb pointer is in R6 (%rbx), it will be copied into
35365 - * %rdi if skb_copy_bits() call is necessary.
35366 - * sk_load_* helpers also use %r10 and %r9d.
35367 - * See bpf_jit.S
35368 - */
35369 - EMIT1_off32(0xE8, jmp_offset); /* call */
35370 - break;
35371 -
35372 - case BPF_LD | BPF_IND | BPF_H:
35373 - func = sk_load_half;
35374 - goto common_load;
35375 - case BPF_LD | BPF_ABS | BPF_H:
35376 - func = CHOOSE_LOAD_FUNC(imm32, sk_load_half);
35377 - goto common_load;
35378 - case BPF_LD | BPF_IND | BPF_B:
35379 - func = sk_load_byte;
35380 - goto common_load;
35381 - case BPF_LD | BPF_ABS | BPF_B:
35382 - func = CHOOSE_LOAD_FUNC(imm32, sk_load_byte);
35383 - goto common_load;
35384 -
35385 - case BPF_JMP | BPF_EXIT:
35386 - if (i != insn_cnt - 1) {
35387 - jmp_offset = ctx->cleanup_addr - addrs[i];
35388 - goto emit_jmp;
35389 - }
35390 - /* update cleanup_addr */
35391 - ctx->cleanup_addr = proglen;
35392 - /* mov rbx, qword ptr [rbp-X] */
35393 - EMIT3_off32(0x48, 0x8B, 0x9D, -stacksize);
35394 - /* mov r13, qword ptr [rbp-X] */
35395 - EMIT3_off32(0x4C, 0x8B, 0xAD, -stacksize + 8);
35396 - /* mov r14, qword ptr [rbp-X] */
35397 - EMIT3_off32(0x4C, 0x8B, 0xB5, -stacksize + 16);
35398 - /* mov r15, qword ptr [rbp-X] */
35399 - EMIT3_off32(0x4C, 0x8B, 0xBD, -stacksize + 24);
35400 -
35401 - EMIT1(0xC9); /* leave */
35402 - EMIT1(0xC3); /* ret */
35403 - break;
35404 -
35405 - default:
35406 - /* By design x64 JIT should support all BPF instructions
35407 - * This error will be seen if new instruction was added
35408 - * to interpreter, but not to JIT
35409 - * or if there is junk in sk_filter
35410 - */
35411 - pr_err("bpf_jit: unknown opcode %02x\n", insn->code);
35412 - return -EINVAL;
35413 - }
35414 -
35415 - ilen = prog - temp;
35416 - if (image) {
35417 - if (unlikely(proglen + ilen > oldproglen)) {
35418 - pr_err("bpf_jit_compile fatal error\n");
35419 - return -EFAULT;
35420 - }
35421 - memcpy(image + proglen, temp, ilen);
35422 - }
35423 - proglen += ilen;
35424 - addrs[i] = proglen;
35425 - prog = temp;
35426 - }
35427 - return proglen;
35428 -}
35429 -
35430 -void bpf_jit_compile(struct sk_filter *prog)
35431 -{
35432 -}
35433 -
35434 -void bpf_int_jit_compile(struct sk_filter *prog)
35435 -{
35436 - struct bpf_binary_header *header = NULL;
35437 - int proglen, oldproglen = 0;
35438 - struct jit_context ctx = {};
35439 +void bpf_jit_compile(struct sk_filter *fp)
35440 +{
35441 + u8 temp[MAX_INSTR_CODE_SIZE];
35442 + u8 *prog;
35443 + unsigned int proglen, oldproglen = 0;
35444 + int ilen, i;
35445 + int t_offset, f_offset;
35446 + u8 t_op, f_op, seen = 0, pass;
35447 u8 *image = NULL;
35448 - int *addrs;
35449 - int pass;
35450 - int i;
35451 + u8 *header = NULL;
35452 + u8 *func;
35453 + int pc_ret0 = -1; /* bpf index of first RET #0 instruction (if any) */
35454 + unsigned int cleanup_addr; /* epilogue code offset */
35455 + unsigned int *addrs;
35456 + const struct sock_filter *filter = fp->insns;
35457 + int flen = fp->len;
35458 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
35459 + unsigned int randkey;
35460 +#endif
35461
35462 if (!bpf_jit_enable)
35463 return;
35464
35465 - if (!prog || !prog->len)
35466 - return;
35467 -
35468 - addrs = kmalloc(prog->len * sizeof(*addrs), GFP_KERNEL);
35469 - if (!addrs)
35470 + addrs = kmalloc(flen * sizeof(*addrs), GFP_KERNEL);
35471 + if (addrs == NULL)
35472 return;
35473
35474 /* Before first pass, make a rough estimation of addrs[]
35475 - * each bpf instruction is translated to less than 64 bytes
35476 + * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
35477 */
35478 - for (proglen = 0, i = 0; i < prog->len; i++) {
35479 - proglen += 64;
35480 + for (proglen = 0, i = 0; i < flen; i++) {
35481 + proglen += MAX_INSTR_CODE_SIZE;
35482 addrs[i] = proglen;
35483 }
35484 - ctx.cleanup_addr = proglen;
35485 + cleanup_addr = proglen; /* epilogue address */
35486
35487 for (pass = 0; pass < 10; pass++) {
35488 - proglen = do_jit(prog, addrs, image, oldproglen, &ctx);
35489 - if (proglen <= 0) {
35490 - image = NULL;
35491 - if (header)
35492 - module_free(NULL, header);
35493 - goto out;
35494 + u8 seen_or_pass0 = (pass == 0) ? (SEEN_XREG | SEEN_DATAREF | SEEN_MEM) : seen;
35495 + /* no prologue/epilogue for trivial filters (RET something) */
35496 + proglen = 0;
35497 + prog = temp;
35498 +
35499 + if (seen_or_pass0) {
35500 + EMIT4(0x55, 0x48, 0x89, 0xe5); /* push %rbp; mov %rsp,%rbp */
35501 + EMIT4(0x48, 0x83, 0xec, 96); /* subq $96,%rsp */
35502 + /* note : must save %rbx in case bpf_error is hit */
35503 + if (seen_or_pass0 & (SEEN_XREG | SEEN_DATAREF))
35504 + EMIT4(0x48, 0x89, 0x5d, 0xf8); /* mov %rbx, -8(%rbp) */
35505 + if (seen_or_pass0 & SEEN_XREG)
35506 + CLEAR_X(); /* make sure we dont leek kernel memory */
35507 +
35508 + /*
35509 + * If this filter needs to access skb data,
35510 + * loads r9 and r8 with :
35511 + * r9 = skb->len - skb->data_len
35512 + * r8 = skb->data
35513 + */
35514 + if (seen_or_pass0 & SEEN_DATAREF) {
35515 + if (offsetof(struct sk_buff, len) <= 127)
35516 + /* mov off8(%rdi),%r9d */
35517 + EMIT4(0x44, 0x8b, 0x4f, offsetof(struct sk_buff, len));
35518 + else {
35519 + /* mov off32(%rdi),%r9d */
35520 + EMIT3(0x44, 0x8b, 0x8f);
35521 + EMIT(offsetof(struct sk_buff, len), 4);
35522 + }
35523 + if (is_imm8(offsetof(struct sk_buff, data_len)))
35524 + /* sub off8(%rdi),%r9d */
35525 + EMIT4(0x44, 0x2b, 0x4f, offsetof(struct sk_buff, data_len));
35526 + else {
35527 + EMIT3(0x44, 0x2b, 0x8f);
35528 + EMIT(offsetof(struct sk_buff, data_len), 4);
35529 + }
35530 +
35531 + if (is_imm8(offsetof(struct sk_buff, data)))
35532 + /* mov off8(%rdi),%r8 */
35533 + EMIT4(0x4c, 0x8b, 0x47, offsetof(struct sk_buff, data));
35534 + else {
35535 + /* mov off32(%rdi),%r8 */
35536 + EMIT3(0x4c, 0x8b, 0x87);
35537 + EMIT(offsetof(struct sk_buff, data), 4);
35538 + }
35539 + }
35540 }
35541 +
35542 + switch (filter[0].code) {
35543 + case BPF_S_RET_K:
35544 + case BPF_S_LD_W_LEN:
35545 + case BPF_S_ANC_PROTOCOL:
35546 + case BPF_S_ANC_IFINDEX:
35547 + case BPF_S_ANC_MARK:
35548 + case BPF_S_ANC_RXHASH:
35549 + case BPF_S_ANC_CPU:
35550 + case BPF_S_ANC_VLAN_TAG:
35551 + case BPF_S_ANC_VLAN_TAG_PRESENT:
35552 + case BPF_S_ANC_QUEUE:
35553 + case BPF_S_ANC_PKTTYPE:
35554 + case BPF_S_LD_W_ABS:
35555 + case BPF_S_LD_H_ABS:
35556 + case BPF_S_LD_B_ABS:
35557 + /* first instruction sets A register (or is RET 'constant') */
35558 + break;
35559 + default:
35560 + /* make sure we dont leak kernel information to user */
35561 + CLEAR_A(); /* A = 0 */
35562 + }
35563 +
35564 + for (i = 0; i < flen; i++) {
35565 + unsigned int K = filter[i].k;
35566 +
35567 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
35568 + randkey = prandom_u32();
35569 +#endif
35570 +
35571 + switch (filter[i].code) {
35572 + case BPF_S_ALU_ADD_X: /* A += X; */
35573 + seen |= SEEN_XREG;
35574 + EMIT2(0x01, 0xd8); /* add %ebx,%eax */
35575 + break;
35576 + case BPF_S_ALU_ADD_K: /* A += K; */
35577 + if (!K)
35578 + break;
35579 + if (is_imm8(K))
35580 + EMIT3(0x83, 0xc0, K); /* add imm8,%eax */
35581 + else
35582 + EMIT1_off32(0x05, K); /* add imm32,%eax */
35583 + break;
35584 + case BPF_S_ALU_SUB_X: /* A -= X; */
35585 + seen |= SEEN_XREG;
35586 + EMIT2(0x29, 0xd8); /* sub %ebx,%eax */
35587 + break;
35588 + case BPF_S_ALU_SUB_K: /* A -= K */
35589 + if (!K)
35590 + break;
35591 + if (is_imm8(K))
35592 + EMIT3(0x83, 0xe8, K); /* sub imm8,%eax */
35593 + else
35594 + EMIT1_off32(0x2d, K); /* sub imm32,%eax */
35595 + break;
35596 + case BPF_S_ALU_MUL_X: /* A *= X; */
35597 + seen |= SEEN_XREG;
35598 + EMIT3(0x0f, 0xaf, 0xc3); /* imul %ebx,%eax */
35599 + break;
35600 + case BPF_S_ALU_MUL_K: /* A *= K */
35601 + if (is_imm8(K))
35602 + EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
35603 + else
35604 + EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
35605 + break;
35606 + case BPF_S_ALU_DIV_X: /* A /= X; */
35607 + seen |= SEEN_XREG;
35608 + EMIT2(0x85, 0xdb); /* test %ebx,%ebx */
35609 + if (pc_ret0 > 0) {
35610 + /* addrs[pc_ret0 - 1] is start address of target
35611 + * (addrs[i] - 4) is the address following this jmp
35612 + * ("xor %edx,%edx; div %ebx" being 4 bytes long)
35613 + */
35614 + EMIT_COND_JMP(X86_JE, addrs[pc_ret0 - 1] -
35615 + (addrs[i] - 4));
35616 + } else {
35617 + EMIT_COND_JMP(X86_JNE, 2 + 5);
35618 + CLEAR_A();
35619 + EMIT1_off32(0xe9, cleanup_addr - (addrs[i] - 4)); /* jmp .+off32 */
35620 + }
35621 + EMIT4(0x31, 0xd2, 0xf7, 0xf3); /* xor %edx,%edx; div %ebx */
35622 + break;
35623 + case BPF_S_ALU_MOD_X: /* A %= X; */
35624 + seen |= SEEN_XREG;
35625 + EMIT2(0x85, 0xdb); /* test %ebx,%ebx */
35626 + if (pc_ret0 > 0) {
35627 + /* addrs[pc_ret0 - 1] is start address of target
35628 + * (addrs[i] - 6) is the address following this jmp
35629 + * ("xor %edx,%edx; div %ebx;mov %edx,%eax" being 6 bytes long)
35630 + */
35631 + EMIT_COND_JMP(X86_JE, addrs[pc_ret0 - 1] -
35632 + (addrs[i] - 6));
35633 + } else {
35634 + EMIT_COND_JMP(X86_JNE, 2 + 5);
35635 + CLEAR_A();
35636 + EMIT1_off32(0xe9, cleanup_addr - (addrs[i] - 6)); /* jmp .+off32 */
35637 + }
35638 + EMIT2(0x31, 0xd2); /* xor %edx,%edx */
35639 + EMIT2(0xf7, 0xf3); /* div %ebx */
35640 + EMIT2(0x89, 0xd0); /* mov %edx,%eax */
35641 + break;
35642 + case BPF_S_ALU_MOD_K: /* A %= K; */
35643 + if (K == 1) {
35644 + CLEAR_A();
35645 + break;
35646 + }
35647 + EMIT2(0x31, 0xd2); /* xor %edx,%edx */
35648 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
35649 + DILUTE_CONST_SEQUENCE(K, randkey);
35650 +#else
35651 + EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
35652 +#endif
35653 + EMIT2(0xf7, 0xf1); /* div %ecx */
35654 + EMIT2(0x89, 0xd0); /* mov %edx,%eax */
35655 + break;
35656 + case BPF_S_ALU_DIV_K: /* A /= K */
35657 + if (K == 1)
35658 + break;
35659 + EMIT2(0x31, 0xd2); /* xor %edx,%edx */
35660 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
35661 + DILUTE_CONST_SEQUENCE(K, randkey);
35662 +#else
35663 + EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
35664 +#endif
35665 + EMIT2(0xf7, 0xf1); /* div %ecx */
35666 + break;
35667 + case BPF_S_ALU_AND_X:
35668 + seen |= SEEN_XREG;
35669 + EMIT2(0x21, 0xd8); /* and %ebx,%eax */
35670 + break;
35671 + case BPF_S_ALU_AND_K:
35672 + if (K >= 0xFFFFFF00) {
35673 + EMIT2(0x24, K & 0xFF); /* and imm8,%al */
35674 + } else if (K >= 0xFFFF0000) {
35675 + EMIT2(0x66, 0x25); /* and imm16,%ax */
35676 + EMIT(K, 2);
35677 + } else {
35678 + EMIT1_off32(0x25, K); /* and imm32,%eax */
35679 + }
35680 + break;
35681 + case BPF_S_ALU_OR_X:
35682 + seen |= SEEN_XREG;
35683 + EMIT2(0x09, 0xd8); /* or %ebx,%eax */
35684 + break;
35685 + case BPF_S_ALU_OR_K:
35686 + if (is_imm8(K))
35687 + EMIT3(0x83, 0xc8, K); /* or imm8,%eax */
35688 + else
35689 + EMIT1_off32(0x0d, K); /* or imm32,%eax */
35690 + break;
35691 + case BPF_S_ANC_ALU_XOR_X: /* A ^= X; */
35692 + case BPF_S_ALU_XOR_X:
35693 + seen |= SEEN_XREG;
35694 + EMIT2(0x31, 0xd8); /* xor %ebx,%eax */
35695 + break;
35696 + case BPF_S_ALU_XOR_K: /* A ^= K; */
35697 + if (K == 0)
35698 + break;
35699 + if (is_imm8(K))
35700 + EMIT3(0x83, 0xf0, K); /* xor imm8,%eax */
35701 + else
35702 + EMIT1_off32(0x35, K); /* xor imm32,%eax */
35703 + break;
35704 + case BPF_S_ALU_LSH_X: /* A <<= X; */
35705 + seen |= SEEN_XREG;
35706 + EMIT4(0x89, 0xd9, 0xd3, 0xe0); /* mov %ebx,%ecx; shl %cl,%eax */
35707 + break;
35708 + case BPF_S_ALU_LSH_K:
35709 + if (K == 0)
35710 + break;
35711 + else if (K == 1)
35712 + EMIT2(0xd1, 0xe0); /* shl %eax */
35713 + else
35714 + EMIT3(0xc1, 0xe0, K);
35715 + break;
35716 + case BPF_S_ALU_RSH_X: /* A >>= X; */
35717 + seen |= SEEN_XREG;
35718 + EMIT4(0x89, 0xd9, 0xd3, 0xe8); /* mov %ebx,%ecx; shr %cl,%eax */
35719 + break;
35720 + case BPF_S_ALU_RSH_K: /* A >>= K; */
35721 + if (K == 0)
35722 + break;
35723 + else if (K == 1)
35724 + EMIT2(0xd1, 0xe8); /* shr %eax */
35725 + else
35726 + EMIT3(0xc1, 0xe8, K);
35727 + break;
35728 + case BPF_S_ALU_NEG:
35729 + EMIT2(0xf7, 0xd8); /* neg %eax */
35730 + break;
35731 + case BPF_S_RET_K:
35732 + if (!K) {
35733 + if (pc_ret0 == -1)
35734 + pc_ret0 = i;
35735 + CLEAR_A();
35736 + } else {
35737 + EMIT1_off32(0xb8, K); /* mov $imm32,%eax */
35738 + }
35739 + /* fallinto */
35740 + case BPF_S_RET_A:
35741 + if (seen_or_pass0) {
35742 + if (i != flen - 1) {
35743 + EMIT_JMP(cleanup_addr - addrs[i]);
35744 + break;
35745 + }
35746 + if (seen_or_pass0 & SEEN_XREG)
35747 + EMIT4(0x48, 0x8b, 0x5d, 0xf8); /* mov -8(%rbp),%rbx */
35748 + EMIT1(0xc9); /* leaveq */
35749 + }
35750 + EMIT1(0xc3); /* ret */
35751 + break;
35752 + case BPF_S_MISC_TAX: /* X = A */
35753 + seen |= SEEN_XREG;
35754 + EMIT2(0x89, 0xc3); /* mov %eax,%ebx */
35755 + break;
35756 + case BPF_S_MISC_TXA: /* A = X */
35757 + seen |= SEEN_XREG;
35758 + EMIT2(0x89, 0xd8); /* mov %ebx,%eax */
35759 + break;
35760 + case BPF_S_LD_IMM: /* A = K */
35761 + if (!K)
35762 + CLEAR_A();
35763 + else
35764 + EMIT1_off32(0xb8, K); /* mov $imm32,%eax */
35765 + break;
35766 + case BPF_S_LDX_IMM: /* X = K */
35767 + seen |= SEEN_XREG;
35768 + if (!K)
35769 + CLEAR_X();
35770 + else
35771 + EMIT1_off32(0xbb, K); /* mov $imm32,%ebx */
35772 + break;
35773 + case BPF_S_LD_MEM: /* A = mem[K] : mov off8(%rbp),%eax */
35774 + seen |= SEEN_MEM;
35775 + EMIT3(0x8b, 0x45, 0xf0 - K*4);
35776 + break;
35777 + case BPF_S_LDX_MEM: /* X = mem[K] : mov off8(%rbp),%ebx */
35778 + seen |= SEEN_XREG | SEEN_MEM;
35779 + EMIT3(0x8b, 0x5d, 0xf0 - K*4);
35780 + break;
35781 + case BPF_S_ST: /* mem[K] = A : mov %eax,off8(%rbp) */
35782 + seen |= SEEN_MEM;
35783 + EMIT3(0x89, 0x45, 0xf0 - K*4);
35784 + break;
35785 + case BPF_S_STX: /* mem[K] = X : mov %ebx,off8(%rbp) */
35786 + seen |= SEEN_XREG | SEEN_MEM;
35787 + EMIT3(0x89, 0x5d, 0xf0 - K*4);
35788 + break;
35789 + case BPF_S_LD_W_LEN: /* A = skb->len; */
35790 + BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, len) != 4);
35791 + if (is_imm8(offsetof(struct sk_buff, len)))
35792 + /* mov off8(%rdi),%eax */
35793 + EMIT3(0x8b, 0x47, offsetof(struct sk_buff, len));
35794 + else {
35795 + EMIT2(0x8b, 0x87);
35796 + EMIT(offsetof(struct sk_buff, len), 4);
35797 + }
35798 + break;
35799 + case BPF_S_LDX_W_LEN: /* X = skb->len; */
35800 + seen |= SEEN_XREG;
35801 + if (is_imm8(offsetof(struct sk_buff, len)))
35802 + /* mov off8(%rdi),%ebx */
35803 + EMIT3(0x8b, 0x5f, offsetof(struct sk_buff, len));
35804 + else {
35805 + EMIT2(0x8b, 0x9f);
35806 + EMIT(offsetof(struct sk_buff, len), 4);
35807 + }
35808 + break;
35809 + case BPF_S_ANC_PROTOCOL: /* A = ntohs(skb->protocol); */
35810 + BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, protocol) != 2);
35811 + if (is_imm8(offsetof(struct sk_buff, protocol))) {
35812 + /* movzwl off8(%rdi),%eax */
35813 + EMIT4(0x0f, 0xb7, 0x47, offsetof(struct sk_buff, protocol));
35814 + } else {
35815 + EMIT3(0x0f, 0xb7, 0x87); /* movzwl off32(%rdi),%eax */
35816 + EMIT(offsetof(struct sk_buff, protocol), 4);
35817 + }
35818 + EMIT2(0x86, 0xc4); /* ntohs() : xchg %al,%ah */
35819 + break;
35820 + case BPF_S_ANC_IFINDEX:
35821 + if (is_imm8(offsetof(struct sk_buff, dev))) {
35822 + /* movq off8(%rdi),%rax */
35823 + EMIT4(0x48, 0x8b, 0x47, offsetof(struct sk_buff, dev));
35824 + } else {
35825 + EMIT3(0x48, 0x8b, 0x87); /* movq off32(%rdi),%rax */
35826 + EMIT(offsetof(struct sk_buff, dev), 4);
35827 + }
35828 + EMIT3(0x48, 0x85, 0xc0); /* test %rax,%rax */
35829 + EMIT_COND_JMP(X86_JE, cleanup_addr - (addrs[i] - 6));
35830 + BUILD_BUG_ON(FIELD_SIZEOF(struct net_device, ifindex) != 4);
35831 + EMIT2(0x8b, 0x80); /* mov off32(%rax),%eax */
35832 + EMIT(offsetof(struct net_device, ifindex), 4);
35833 + break;
35834 + case BPF_S_ANC_MARK:
35835 + BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, mark) != 4);
35836 + if (is_imm8(offsetof(struct sk_buff, mark))) {
35837 + /* mov off8(%rdi),%eax */
35838 + EMIT3(0x8b, 0x47, offsetof(struct sk_buff, mark));
35839 + } else {
35840 + EMIT2(0x8b, 0x87);
35841 + EMIT(offsetof(struct sk_buff, mark), 4);
35842 + }
35843 + break;
35844 + case BPF_S_ANC_RXHASH:
35845 + BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, hash) != 4);
35846 + if (is_imm8(offsetof(struct sk_buff, hash))) {
35847 + /* mov off8(%rdi),%eax */
35848 + EMIT3(0x8b, 0x47, offsetof(struct sk_buff, hash));
35849 + } else {
35850 + EMIT2(0x8b, 0x87);
35851 + EMIT(offsetof(struct sk_buff, hash), 4);
35852 + }
35853 + break;
35854 + case BPF_S_ANC_QUEUE:
35855 + BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, queue_mapping) != 2);
35856 + if (is_imm8(offsetof(struct sk_buff, queue_mapping))) {
35857 + /* movzwl off8(%rdi),%eax */
35858 + EMIT4(0x0f, 0xb7, 0x47, offsetof(struct sk_buff, queue_mapping));
35859 + } else {
35860 + EMIT3(0x0f, 0xb7, 0x87); /* movzwl off32(%rdi),%eax */
35861 + EMIT(offsetof(struct sk_buff, queue_mapping), 4);
35862 + }
35863 + break;
35864 + case BPF_S_ANC_CPU:
35865 +#ifdef CONFIG_SMP
35866 + EMIT4(0x65, 0x8b, 0x04, 0x25); /* mov %gs:off32,%eax */
35867 + EMIT((u32)(unsigned long)&cpu_number, 4); /* A = smp_processor_id(); */
35868 +#else
35869 + CLEAR_A();
35870 +#endif
35871 + break;
35872 + case BPF_S_ANC_VLAN_TAG:
35873 + case BPF_S_ANC_VLAN_TAG_PRESENT:
35874 + BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, vlan_tci) != 2);
35875 + if (is_imm8(offsetof(struct sk_buff, vlan_tci))) {
35876 + /* movzwl off8(%rdi),%eax */
35877 + EMIT4(0x0f, 0xb7, 0x47, offsetof(struct sk_buff, vlan_tci));
35878 + } else {
35879 + EMIT3(0x0f, 0xb7, 0x87); /* movzwl off32(%rdi),%eax */
35880 + EMIT(offsetof(struct sk_buff, vlan_tci), 4);
35881 + }
35882 + BUILD_BUG_ON(VLAN_TAG_PRESENT != 0x1000);
35883 + if (filter[i].code == BPF_S_ANC_VLAN_TAG) {
35884 + EMIT3(0x80, 0xe4, 0xef); /* and $0xef,%ah */
35885 + } else {
35886 + EMIT3(0xc1, 0xe8, 0x0c); /* shr $0xc,%eax */
35887 + EMIT3(0x83, 0xe0, 0x01); /* and $0x1,%eax */
35888 + }
35889 + break;
35890 + case BPF_S_ANC_PKTTYPE:
35891 + {
35892 + int off = pkt_type_offset();
35893 +
35894 + if (off < 0)
35895 + goto out;
35896 + if (is_imm8(off)) {
35897 + /* movzbl off8(%rdi),%eax */
35898 + EMIT4(0x0f, 0xb6, 0x47, off);
35899 + } else {
35900 + /* movbl off32(%rdi),%eax */
35901 + EMIT3(0x0f, 0xb6, 0x87);
35902 + EMIT(off, 4);
35903 + }
35904 + EMIT3(0x83, 0xe0, PKT_TYPE_MAX); /* and $0x7,%eax */
35905 + break;
35906 + }
35907 + case BPF_S_LD_W_ABS:
35908 + func = CHOOSE_LOAD_FUNC(K, sk_load_word);
35909 +common_load: seen |= SEEN_DATAREF;
35910 + t_offset = func - (image + addrs[i]);
35911 + EMIT1_off32(0xbe, K); /* mov imm32,%esi */
35912 + EMIT1_off32(0xe8, t_offset); /* call */
35913 + break;
35914 + case BPF_S_LD_H_ABS:
35915 + func = CHOOSE_LOAD_FUNC(K, sk_load_half);
35916 + goto common_load;
35917 + case BPF_S_LD_B_ABS:
35918 + func = CHOOSE_LOAD_FUNC(K, sk_load_byte);
35919 + goto common_load;
35920 + case BPF_S_LDX_B_MSH:
35921 + func = CHOOSE_LOAD_FUNC(K, sk_load_byte_msh);
35922 + seen |= SEEN_DATAREF | SEEN_XREG;
35923 + t_offset = func - (image + addrs[i]);
35924 + EMIT1_off32(0xbe, K); /* mov imm32,%esi */
35925 + EMIT1_off32(0xe8, t_offset); /* call sk_load_byte_msh */
35926 + break;
35927 + case BPF_S_LD_W_IND:
35928 + func = sk_load_word;
35929 +common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
35930 + t_offset = func - (image + addrs[i]);
35931 + if (K) {
35932 + if (is_imm8(K)) {
35933 + EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
35934 + } else {
35935 + EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
35936 + }
35937 + } else {
35938 + EMIT2(0x89,0xde); /* mov %ebx,%esi */
35939 + }
35940 + EMIT1_off32(0xe8, t_offset); /* call sk_load_xxx_ind */
35941 + break;
35942 + case BPF_S_LD_H_IND:
35943 + func = sk_load_half;
35944 + goto common_load_ind;
35945 + case BPF_S_LD_B_IND:
35946 + func = sk_load_byte;
35947 + goto common_load_ind;
35948 + case BPF_S_JMP_JA:
35949 + t_offset = addrs[i + K] - addrs[i];
35950 + EMIT_JMP(t_offset);
35951 + break;
35952 + COND_SEL(BPF_S_JMP_JGT_K, X86_JA, X86_JBE);
35953 + COND_SEL(BPF_S_JMP_JGE_K, X86_JAE, X86_JB);
35954 + COND_SEL(BPF_S_JMP_JEQ_K, X86_JE, X86_JNE);
35955 + COND_SEL(BPF_S_JMP_JSET_K,X86_JNE, X86_JE);
35956 + COND_SEL(BPF_S_JMP_JGT_X, X86_JA, X86_JBE);
35957 + COND_SEL(BPF_S_JMP_JGE_X, X86_JAE, X86_JB);
35958 + COND_SEL(BPF_S_JMP_JEQ_X, X86_JE, X86_JNE);
35959 + COND_SEL(BPF_S_JMP_JSET_X,X86_JNE, X86_JE);
35960 +
35961 +cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
35962 + t_offset = addrs[i + filter[i].jt] - addrs[i];
35963 +
35964 + /* same targets, can avoid doing the test :) */
35965 + if (filter[i].jt == filter[i].jf) {
35966 + EMIT_JMP(t_offset);
35967 + break;
35968 + }
35969 +
35970 + switch (filter[i].code) {
35971 + case BPF_S_JMP_JGT_X:
35972 + case BPF_S_JMP_JGE_X:
35973 + case BPF_S_JMP_JEQ_X:
35974 + seen |= SEEN_XREG;
35975 + EMIT2(0x39, 0xd8); /* cmp %ebx,%eax */
35976 + break;
35977 + case BPF_S_JMP_JSET_X:
35978 + seen |= SEEN_XREG;
35979 + EMIT2(0x85, 0xd8); /* test %ebx,%eax */
35980 + break;
35981 + case BPF_S_JMP_JEQ_K:
35982 + if (K == 0) {
35983 + EMIT2(0x85, 0xc0); /* test %eax,%eax */
35984 + break;
35985 + }
35986 + case BPF_S_JMP_JGT_K:
35987 + case BPF_S_JMP_JGE_K:
35988 + if (K <= 127)
35989 + EMIT3(0x83, 0xf8, K); /* cmp imm8,%eax */
35990 + else
35991 + EMIT1_off32(0x3d, K); /* cmp imm32,%eax */
35992 + break;
35993 + case BPF_S_JMP_JSET_K:
35994 + if (K <= 0xFF)
35995 + EMIT2(0xa8, K); /* test imm8,%al */
35996 + else if (!(K & 0xFFFF00FF))
35997 + EMIT3(0xf6, 0xc4, K >> 8); /* test imm8,%ah */
35998 + else if (K <= 0xFFFF) {
35999 + EMIT2(0x66, 0xa9); /* test imm16,%ax */
36000 + EMIT(K, 2);
36001 + } else {
36002 + EMIT1_off32(0xa9, K); /* test imm32,%eax */
36003 + }
36004 + break;
36005 + }
36006 + if (filter[i].jt != 0) {
36007 + if (filter[i].jf && f_offset)
36008 + t_offset += is_near(f_offset) ? 2 : 5;
36009 + EMIT_COND_JMP(t_op, t_offset);
36010 + if (filter[i].jf)
36011 + EMIT_JMP(f_offset);
36012 + break;
36013 + }
36014 + EMIT_COND_JMP(f_op, f_offset);
36015 + break;
36016 + default:
36017 + /* hmm, too complex filter, give up with jit compiler */
36018 + goto out;
36019 + }
36020 + ilen = prog - temp;
36021 + if (image) {
36022 + if (unlikely(proglen + ilen > oldproglen)) {
36023 + pr_err("bpb_jit_compile fatal error\n");
36024 + kfree(addrs);
36025 + module_free_exec(NULL, image);
36026 + return;
36027 + }
36028 + pax_open_kernel();
36029 + memcpy(image + proglen, temp, ilen);
36030 + pax_close_kernel();
36031 + }
36032 + proglen += ilen;
36033 + addrs[i] = proglen;
36034 + prog = temp;
36035 + }
36036 + /* last bpf instruction is always a RET :
36037 + * use it to give the cleanup instruction(s) addr
36038 + */
36039 + cleanup_addr = proglen - 1; /* ret */
36040 + if (seen_or_pass0)
36041 + cleanup_addr -= 1; /* leaveq */
36042 + if (seen_or_pass0 & SEEN_XREG)
36043 + cleanup_addr -= 4; /* mov -8(%rbp),%rbx */
36044 +
36045 if (image) {
36046 if (proglen != oldproglen)
36047 - pr_err("bpf_jit: proglen=%d != oldproglen=%d\n",
36048 - proglen, oldproglen);
36049 + pr_err("bpb_jit_compile proglen=%u != oldproglen=%u\n", proglen, oldproglen);
36050 break;
36051 }
36052 if (proglen == oldproglen) {
36053 @@ -918,32 +872,30 @@ void bpf_int_jit_compile(struct sk_filter *prog)
36054 }
36055
36056 if (bpf_jit_enable > 1)
36057 - bpf_jit_dump(prog->len, proglen, 0, image);
36058 + bpf_jit_dump(flen, proglen, pass, image);
36059
36060 if (image) {
36061 bpf_flush_icache(header, image + proglen);
36062 - set_memory_ro((unsigned long)header, header->pages);
36063 - prog->bpf_func = (void *)image;
36064 - prog->jited = 1;
36065 + fp->bpf_func = (void *)image;
36066 }
36067 out:
36068 kfree(addrs);
36069 + return;
36070 }
36071
36072 static void bpf_jit_free_deferred(struct work_struct *work)
36073 {
36074 struct sk_filter *fp = container_of(work, struct sk_filter, work);
36075 unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
36076 - struct bpf_binary_header *header = (void *)addr;
36077
36078 - set_memory_rw(addr, header->pages);
36079 - module_free(NULL, header);
36080 + set_memory_rw(addr, 1);
36081 + module_free_exec(NULL, (void *)addr);
36082 kfree(fp);
36083 }
36084
36085 void bpf_jit_free(struct sk_filter *fp)
36086 {
36087 - if (fp->jited) {
36088 + if (fp->bpf_func != sk_run_filter) {
36089 INIT_WORK(&fp->work, bpf_jit_free_deferred);
36090 schedule_work(&fp->work);
36091 } else {
36092 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
36093 index 5d04be5..2beeaa2 100644
36094 --- a/arch/x86/oprofile/backtrace.c
36095 +++ b/arch/x86/oprofile/backtrace.c
36096 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
36097 struct stack_frame_ia32 *fp;
36098 unsigned long bytes;
36099
36100 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
36101 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
36102 if (bytes != 0)
36103 return NULL;
36104
36105 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
36106 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
36107
36108 oprofile_add_trace(bufhead[0].return_address);
36109
36110 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
36111 struct stack_frame bufhead[2];
36112 unsigned long bytes;
36113
36114 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
36115 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
36116 if (bytes != 0)
36117 return NULL;
36118
36119 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
36120 {
36121 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
36122
36123 - if (!user_mode_vm(regs)) {
36124 + if (!user_mode(regs)) {
36125 unsigned long stack = kernel_stack_pointer(regs);
36126 if (depth)
36127 dump_trace(NULL, regs, (unsigned long *)stack, 0,
36128 diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
36129 index 379e8bd..6386e09 100644
36130 --- a/arch/x86/oprofile/nmi_int.c
36131 +++ b/arch/x86/oprofile/nmi_int.c
36132 @@ -23,6 +23,7 @@
36133 #include <asm/nmi.h>
36134 #include <asm/msr.h>
36135 #include <asm/apic.h>
36136 +#include <asm/pgtable.h>
36137
36138 #include "op_counter.h"
36139 #include "op_x86_model.h"
36140 @@ -785,8 +786,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
36141 if (ret)
36142 return ret;
36143
36144 - if (!model->num_virt_counters)
36145 - model->num_virt_counters = model->num_counters;
36146 + if (!model->num_virt_counters) {
36147 + pax_open_kernel();
36148 + *(unsigned int *)&model->num_virt_counters = model->num_counters;
36149 + pax_close_kernel();
36150 + }
36151
36152 mux_init(ops);
36153
36154 diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
36155 index 50d86c0..7985318 100644
36156 --- a/arch/x86/oprofile/op_model_amd.c
36157 +++ b/arch/x86/oprofile/op_model_amd.c
36158 @@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
36159 num_counters = AMD64_NUM_COUNTERS;
36160 }
36161
36162 - op_amd_spec.num_counters = num_counters;
36163 - op_amd_spec.num_controls = num_counters;
36164 - op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
36165 + pax_open_kernel();
36166 + *(unsigned int *)&op_amd_spec.num_counters = num_counters;
36167 + *(unsigned int *)&op_amd_spec.num_controls = num_counters;
36168 + *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
36169 + pax_close_kernel();
36170
36171 return 0;
36172 }
36173 diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
36174 index d90528e..0127e2b 100644
36175 --- a/arch/x86/oprofile/op_model_ppro.c
36176 +++ b/arch/x86/oprofile/op_model_ppro.c
36177 @@ -19,6 +19,7 @@
36178 #include <asm/msr.h>
36179 #include <asm/apic.h>
36180 #include <asm/nmi.h>
36181 +#include <asm/pgtable.h>
36182
36183 #include "op_x86_model.h"
36184 #include "op_counter.h"
36185 @@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
36186
36187 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
36188
36189 - op_arch_perfmon_spec.num_counters = num_counters;
36190 - op_arch_perfmon_spec.num_controls = num_counters;
36191 + pax_open_kernel();
36192 + *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
36193 + *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
36194 + pax_close_kernel();
36195 }
36196
36197 static int arch_perfmon_init(struct oprofile_operations *ignore)
36198 diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
36199 index 71e8a67..6a313bb 100644
36200 --- a/arch/x86/oprofile/op_x86_model.h
36201 +++ b/arch/x86/oprofile/op_x86_model.h
36202 @@ -52,7 +52,7 @@ struct op_x86_model_spec {
36203 void (*switch_ctrl)(struct op_x86_model_spec const *model,
36204 struct op_msrs const * const msrs);
36205 #endif
36206 -};
36207 +} __do_const;
36208
36209 struct op_counter_config;
36210
36211 diff --git a/arch/x86/pci/intel_mid_pci.c b/arch/x86/pci/intel_mid_pci.c
36212 index 84b9d67..260e5ff 100644
36213 --- a/arch/x86/pci/intel_mid_pci.c
36214 +++ b/arch/x86/pci/intel_mid_pci.c
36215 @@ -245,7 +245,7 @@ int __init intel_mid_pci_init(void)
36216 pr_info("Intel MID platform detected, using MID PCI ops\n");
36217 pci_mmcfg_late_init();
36218 pcibios_enable_irq = intel_mid_pci_irq_enable;
36219 - pci_root_ops = intel_mid_pci_ops;
36220 + memcpy((void *)&pci_root_ops, &intel_mid_pci_ops, sizeof pci_root_ops);
36221 pci_soc_mode = 1;
36222 /* Continue with standard init */
36223 return 1;
36224 diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
36225 index 84112f5..6334d60 100644
36226 --- a/arch/x86/pci/irq.c
36227 +++ b/arch/x86/pci/irq.c
36228 @@ -50,7 +50,7 @@ struct irq_router {
36229 struct irq_router_handler {
36230 u16 vendor;
36231 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
36232 -};
36233 +} __do_const;
36234
36235 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
36236 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
36237 @@ -790,7 +790,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
36238 return 0;
36239 }
36240
36241 -static __initdata struct irq_router_handler pirq_routers[] = {
36242 +static __initconst const struct irq_router_handler pirq_routers[] = {
36243 { PCI_VENDOR_ID_INTEL, intel_router_probe },
36244 { PCI_VENDOR_ID_AL, ali_router_probe },
36245 { PCI_VENDOR_ID_ITE, ite_router_probe },
36246 @@ -817,7 +817,7 @@ static struct pci_dev *pirq_router_dev;
36247 static void __init pirq_find_router(struct irq_router *r)
36248 {
36249 struct irq_routing_table *rt = pirq_table;
36250 - struct irq_router_handler *h;
36251 + const struct irq_router_handler *h;
36252
36253 #ifdef CONFIG_PCI_BIOS
36254 if (!rt->signature) {
36255 @@ -1090,7 +1090,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
36256 return 0;
36257 }
36258
36259 -static struct dmi_system_id __initdata pciirq_dmi_table[] = {
36260 +static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
36261 {
36262 .callback = fix_broken_hp_bios_irq9,
36263 .ident = "HP Pavilion N5400 Series Laptop",
36264 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
36265 index c77b24a..c979855 100644
36266 --- a/arch/x86/pci/pcbios.c
36267 +++ b/arch/x86/pci/pcbios.c
36268 @@ -79,7 +79,7 @@ union bios32 {
36269 static struct {
36270 unsigned long address;
36271 unsigned short segment;
36272 -} bios32_indirect = { 0, __KERNEL_CS };
36273 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
36274
36275 /*
36276 * Returns the entry point for the given service, NULL on error
36277 @@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
36278 unsigned long length; /* %ecx */
36279 unsigned long entry; /* %edx */
36280 unsigned long flags;
36281 + struct desc_struct d, *gdt;
36282
36283 local_irq_save(flags);
36284 - __asm__("lcall *(%%edi); cld"
36285 +
36286 + gdt = get_cpu_gdt_table(smp_processor_id());
36287 +
36288 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
36289 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
36290 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
36291 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
36292 +
36293 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
36294 : "=a" (return_code),
36295 "=b" (address),
36296 "=c" (length),
36297 "=d" (entry)
36298 : "0" (service),
36299 "1" (0),
36300 - "D" (&bios32_indirect));
36301 + "D" (&bios32_indirect),
36302 + "r"(__PCIBIOS_DS)
36303 + : "memory");
36304 +
36305 + pax_open_kernel();
36306 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
36307 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
36308 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
36309 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
36310 + pax_close_kernel();
36311 +
36312 local_irq_restore(flags);
36313
36314 switch (return_code) {
36315 - case 0:
36316 - return address + entry;
36317 - case 0x80: /* Not present */
36318 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
36319 - return 0;
36320 - default: /* Shouldn't happen */
36321 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
36322 - service, return_code);
36323 + case 0: {
36324 + int cpu;
36325 + unsigned char flags;
36326 +
36327 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
36328 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
36329 + printk(KERN_WARNING "bios32_service: not valid\n");
36330 return 0;
36331 + }
36332 + address = address + PAGE_OFFSET;
36333 + length += 16UL; /* some BIOSs underreport this... */
36334 + flags = 4;
36335 + if (length >= 64*1024*1024) {
36336 + length >>= PAGE_SHIFT;
36337 + flags |= 8;
36338 + }
36339 +
36340 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
36341 + gdt = get_cpu_gdt_table(cpu);
36342 + pack_descriptor(&d, address, length, 0x9b, flags);
36343 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
36344 + pack_descriptor(&d, address, length, 0x93, flags);
36345 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
36346 + }
36347 + return entry;
36348 + }
36349 + case 0x80: /* Not present */
36350 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
36351 + return 0;
36352 + default: /* Shouldn't happen */
36353 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
36354 + service, return_code);
36355 + return 0;
36356 }
36357 }
36358
36359 static struct {
36360 unsigned long address;
36361 unsigned short segment;
36362 -} pci_indirect = { 0, __KERNEL_CS };
36363 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
36364
36365 -static int pci_bios_present;
36366 +static int pci_bios_present __read_only;
36367
36368 static int check_pcibios(void)
36369 {
36370 @@ -131,11 +174,13 @@ static int check_pcibios(void)
36371 unsigned long flags, pcibios_entry;
36372
36373 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
36374 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
36375 + pci_indirect.address = pcibios_entry;
36376
36377 local_irq_save(flags);
36378 - __asm__(
36379 - "lcall *(%%edi); cld\n\t"
36380 + __asm__("movw %w6, %%ds\n\t"
36381 + "lcall *%%ss:(%%edi); cld\n\t"
36382 + "push %%ss\n\t"
36383 + "pop %%ds\n\t"
36384 "jc 1f\n\t"
36385 "xor %%ah, %%ah\n"
36386 "1:"
36387 @@ -144,7 +189,8 @@ static int check_pcibios(void)
36388 "=b" (ebx),
36389 "=c" (ecx)
36390 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
36391 - "D" (&pci_indirect)
36392 + "D" (&pci_indirect),
36393 + "r" (__PCIBIOS_DS)
36394 : "memory");
36395 local_irq_restore(flags);
36396
36397 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
36398
36399 switch (len) {
36400 case 1:
36401 - __asm__("lcall *(%%esi); cld\n\t"
36402 + __asm__("movw %w6, %%ds\n\t"
36403 + "lcall *%%ss:(%%esi); cld\n\t"
36404 + "push %%ss\n\t"
36405 + "pop %%ds\n\t"
36406 "jc 1f\n\t"
36407 "xor %%ah, %%ah\n"
36408 "1:"
36409 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
36410 : "1" (PCIBIOS_READ_CONFIG_BYTE),
36411 "b" (bx),
36412 "D" ((long)reg),
36413 - "S" (&pci_indirect));
36414 + "S" (&pci_indirect),
36415 + "r" (__PCIBIOS_DS));
36416 /*
36417 * Zero-extend the result beyond 8 bits, do not trust the
36418 * BIOS having done it:
36419 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
36420 *value &= 0xff;
36421 break;
36422 case 2:
36423 - __asm__("lcall *(%%esi); cld\n\t"
36424 + __asm__("movw %w6, %%ds\n\t"
36425 + "lcall *%%ss:(%%esi); cld\n\t"
36426 + "push %%ss\n\t"
36427 + "pop %%ds\n\t"
36428 "jc 1f\n\t"
36429 "xor %%ah, %%ah\n"
36430 "1:"
36431 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
36432 : "1" (PCIBIOS_READ_CONFIG_WORD),
36433 "b" (bx),
36434 "D" ((long)reg),
36435 - "S" (&pci_indirect));
36436 + "S" (&pci_indirect),
36437 + "r" (__PCIBIOS_DS));
36438 /*
36439 * Zero-extend the result beyond 16 bits, do not trust the
36440 * BIOS having done it:
36441 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
36442 *value &= 0xffff;
36443 break;
36444 case 4:
36445 - __asm__("lcall *(%%esi); cld\n\t"
36446 + __asm__("movw %w6, %%ds\n\t"
36447 + "lcall *%%ss:(%%esi); cld\n\t"
36448 + "push %%ss\n\t"
36449 + "pop %%ds\n\t"
36450 "jc 1f\n\t"
36451 "xor %%ah, %%ah\n"
36452 "1:"
36453 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
36454 : "1" (PCIBIOS_READ_CONFIG_DWORD),
36455 "b" (bx),
36456 "D" ((long)reg),
36457 - "S" (&pci_indirect));
36458 + "S" (&pci_indirect),
36459 + "r" (__PCIBIOS_DS));
36460 break;
36461 }
36462
36463 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
36464
36465 switch (len) {
36466 case 1:
36467 - __asm__("lcall *(%%esi); cld\n\t"
36468 + __asm__("movw %w6, %%ds\n\t"
36469 + "lcall *%%ss:(%%esi); cld\n\t"
36470 + "push %%ss\n\t"
36471 + "pop %%ds\n\t"
36472 "jc 1f\n\t"
36473 "xor %%ah, %%ah\n"
36474 "1:"
36475 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
36476 "c" (value),
36477 "b" (bx),
36478 "D" ((long)reg),
36479 - "S" (&pci_indirect));
36480 + "S" (&pci_indirect),
36481 + "r" (__PCIBIOS_DS));
36482 break;
36483 case 2:
36484 - __asm__("lcall *(%%esi); cld\n\t"
36485 + __asm__("movw %w6, %%ds\n\t"
36486 + "lcall *%%ss:(%%esi); cld\n\t"
36487 + "push %%ss\n\t"
36488 + "pop %%ds\n\t"
36489 "jc 1f\n\t"
36490 "xor %%ah, %%ah\n"
36491 "1:"
36492 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
36493 "c" (value),
36494 "b" (bx),
36495 "D" ((long)reg),
36496 - "S" (&pci_indirect));
36497 + "S" (&pci_indirect),
36498 + "r" (__PCIBIOS_DS));
36499 break;
36500 case 4:
36501 - __asm__("lcall *(%%esi); cld\n\t"
36502 + __asm__("movw %w6, %%ds\n\t"
36503 + "lcall *%%ss:(%%esi); cld\n\t"
36504 + "push %%ss\n\t"
36505 + "pop %%ds\n\t"
36506 "jc 1f\n\t"
36507 "xor %%ah, %%ah\n"
36508 "1:"
36509 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
36510 "c" (value),
36511 "b" (bx),
36512 "D" ((long)reg),
36513 - "S" (&pci_indirect));
36514 + "S" (&pci_indirect),
36515 + "r" (__PCIBIOS_DS));
36516 break;
36517 }
36518
36519 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
36520
36521 DBG("PCI: Fetching IRQ routing table... ");
36522 __asm__("push %%es\n\t"
36523 + "movw %w8, %%ds\n\t"
36524 "push %%ds\n\t"
36525 "pop %%es\n\t"
36526 - "lcall *(%%esi); cld\n\t"
36527 + "lcall *%%ss:(%%esi); cld\n\t"
36528 "pop %%es\n\t"
36529 + "push %%ss\n\t"
36530 + "pop %%ds\n"
36531 "jc 1f\n\t"
36532 "xor %%ah, %%ah\n"
36533 "1:"
36534 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
36535 "1" (0),
36536 "D" ((long) &opt),
36537 "S" (&pci_indirect),
36538 - "m" (opt)
36539 + "m" (opt),
36540 + "r" (__PCIBIOS_DS)
36541 : "memory");
36542 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
36543 if (ret & 0xff00)
36544 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
36545 {
36546 int ret;
36547
36548 - __asm__("lcall *(%%esi); cld\n\t"
36549 + __asm__("movw %w5, %%ds\n\t"
36550 + "lcall *%%ss:(%%esi); cld\n\t"
36551 + "push %%ss\n\t"
36552 + "pop %%ds\n"
36553 "jc 1f\n\t"
36554 "xor %%ah, %%ah\n"
36555 "1:"
36556 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
36557 : "0" (PCIBIOS_SET_PCI_HW_INT),
36558 "b" ((dev->bus->number << 8) | dev->devfn),
36559 "c" ((irq << 8) | (pin + 10)),
36560 - "S" (&pci_indirect));
36561 + "S" (&pci_indirect),
36562 + "r" (__PCIBIOS_DS));
36563 return !(ret & 0xff00);
36564 }
36565 EXPORT_SYMBOL(pcibios_set_irq_routing);
36566 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
36567 index 9ee3491..872192f 100644
36568 --- a/arch/x86/platform/efi/efi_32.c
36569 +++ b/arch/x86/platform/efi/efi_32.c
36570 @@ -59,11 +59,22 @@ void efi_call_phys_prelog(void)
36571 {
36572 struct desc_ptr gdt_descr;
36573
36574 +#ifdef CONFIG_PAX_KERNEXEC
36575 + struct desc_struct d;
36576 +#endif
36577 +
36578 local_irq_save(efi_rt_eflags);
36579
36580 load_cr3(initial_page_table);
36581 __flush_tlb_all();
36582
36583 +#ifdef CONFIG_PAX_KERNEXEC
36584 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
36585 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
36586 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
36587 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
36588 +#endif
36589 +
36590 gdt_descr.address = __pa(get_cpu_gdt_table(0));
36591 gdt_descr.size = GDT_SIZE - 1;
36592 load_gdt(&gdt_descr);
36593 @@ -73,11 +84,24 @@ void efi_call_phys_epilog(void)
36594 {
36595 struct desc_ptr gdt_descr;
36596
36597 +#ifdef CONFIG_PAX_KERNEXEC
36598 + struct desc_struct d;
36599 +
36600 + memset(&d, 0, sizeof d);
36601 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
36602 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
36603 +#endif
36604 +
36605 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
36606 gdt_descr.size = GDT_SIZE - 1;
36607 load_gdt(&gdt_descr);
36608
36609 +#ifdef CONFIG_PAX_PER_CPU_PGD
36610 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
36611 +#else
36612 load_cr3(swapper_pg_dir);
36613 +#endif
36614 +
36615 __flush_tlb_all();
36616
36617 local_irq_restore(efi_rt_eflags);
36618 diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
36619 index 290d397..3906bcd 100644
36620 --- a/arch/x86/platform/efi/efi_64.c
36621 +++ b/arch/x86/platform/efi/efi_64.c
36622 @@ -99,6 +99,11 @@ void __init efi_call_phys_prelog(void)
36623 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
36624 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
36625 }
36626 +
36627 +#ifdef CONFIG_PAX_PER_CPU_PGD
36628 + load_cr3(swapper_pg_dir);
36629 +#endif
36630 +
36631 __flush_tlb_all();
36632 }
36633
36634 @@ -116,6 +121,11 @@ void __init efi_call_phys_epilog(void)
36635 for (pgd = 0; pgd < n_pgds; pgd++)
36636 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
36637 kfree(save_pgd);
36638 +
36639 +#ifdef CONFIG_PAX_PER_CPU_PGD
36640 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
36641 +#endif
36642 +
36643 __flush_tlb_all();
36644 local_irq_restore(efi_flags);
36645 early_code_mapping_set_exec(0);
36646 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
36647 index fbe66e6..eae5e38 100644
36648 --- a/arch/x86/platform/efi/efi_stub_32.S
36649 +++ b/arch/x86/platform/efi/efi_stub_32.S
36650 @@ -6,7 +6,9 @@
36651 */
36652
36653 #include <linux/linkage.h>
36654 +#include <linux/init.h>
36655 #include <asm/page_types.h>
36656 +#include <asm/segment.h>
36657
36658 /*
36659 * efi_call_phys(void *, ...) is a function with variable parameters.
36660 @@ -20,7 +22,7 @@
36661 * service functions will comply with gcc calling convention, too.
36662 */
36663
36664 -.text
36665 +__INIT
36666 ENTRY(efi_call_phys)
36667 /*
36668 * 0. The function can only be called in Linux kernel. So CS has been
36669 @@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
36670 * The mapping of lower virtual memory has been created in prelog and
36671 * epilog.
36672 */
36673 - movl $1f, %edx
36674 - subl $__PAGE_OFFSET, %edx
36675 - jmp *%edx
36676 +#ifdef CONFIG_PAX_KERNEXEC
36677 + movl $(__KERNEXEC_EFI_DS), %edx
36678 + mov %edx, %ds
36679 + mov %edx, %es
36680 + mov %edx, %ss
36681 + addl $2f,(1f)
36682 + ljmp *(1f)
36683 +
36684 +__INITDATA
36685 +1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
36686 +.previous
36687 +
36688 +2:
36689 + subl $2b,(1b)
36690 +#else
36691 + jmp 1f-__PAGE_OFFSET
36692 1:
36693 +#endif
36694
36695 /*
36696 * 2. Now on the top of stack is the return
36697 @@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
36698 * parameter 2, ..., param n. To make things easy, we save the return
36699 * address of efi_call_phys in a global variable.
36700 */
36701 - popl %edx
36702 - movl %edx, saved_return_addr
36703 - /* get the function pointer into ECX*/
36704 - popl %ecx
36705 - movl %ecx, efi_rt_function_ptr
36706 - movl $2f, %edx
36707 - subl $__PAGE_OFFSET, %edx
36708 - pushl %edx
36709 + popl (saved_return_addr)
36710 + popl (efi_rt_function_ptr)
36711
36712 /*
36713 * 3. Clear PG bit in %CR0.
36714 @@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
36715 /*
36716 * 5. Call the physical function.
36717 */
36718 - jmp *%ecx
36719 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
36720
36721 -2:
36722 /*
36723 * 6. After EFI runtime service returns, control will return to
36724 * following instruction. We'd better readjust stack pointer first.
36725 @@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
36726 movl %cr0, %edx
36727 orl $0x80000000, %edx
36728 movl %edx, %cr0
36729 - jmp 1f
36730 -1:
36731 +
36732 /*
36733 * 8. Now restore the virtual mode from flat mode by
36734 * adding EIP with PAGE_OFFSET.
36735 */
36736 - movl $1f, %edx
36737 - jmp *%edx
36738 +#ifdef CONFIG_PAX_KERNEXEC
36739 + movl $(__KERNEL_DS), %edx
36740 + mov %edx, %ds
36741 + mov %edx, %es
36742 + mov %edx, %ss
36743 + ljmp $(__KERNEL_CS),$1f
36744 +#else
36745 + jmp 1f+__PAGE_OFFSET
36746 +#endif
36747 1:
36748
36749 /*
36750 * 9. Balance the stack. And because EAX contain the return value,
36751 * we'd better not clobber it.
36752 */
36753 - leal efi_rt_function_ptr, %edx
36754 - movl (%edx), %ecx
36755 - pushl %ecx
36756 + pushl (efi_rt_function_ptr)
36757
36758 /*
36759 - * 10. Push the saved return address onto the stack and return.
36760 + * 10. Return to the saved return address.
36761 */
36762 - leal saved_return_addr, %edx
36763 - movl (%edx), %ecx
36764 - pushl %ecx
36765 - ret
36766 + jmpl *(saved_return_addr)
36767 ENDPROC(efi_call_phys)
36768 .previous
36769
36770 -.data
36771 +__INITDATA
36772 saved_return_addr:
36773 .long 0
36774 efi_rt_function_ptr:
36775 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
36776 index 5fcda72..b9d1d65 100644
36777 --- a/arch/x86/platform/efi/efi_stub_64.S
36778 +++ b/arch/x86/platform/efi/efi_stub_64.S
36779 @@ -11,6 +11,7 @@
36780 #include <asm/msr.h>
36781 #include <asm/processor-flags.h>
36782 #include <asm/page_types.h>
36783 +#include <asm/alternative-asm.h>
36784
36785 #define SAVE_XMM \
36786 mov %rsp, %rax; \
36787 @@ -88,6 +89,7 @@ ENTRY(efi_call)
36788 RESTORE_PGT
36789 addq $48, %rsp
36790 RESTORE_XMM
36791 + pax_force_retaddr 0, 1
36792 ret
36793 ENDPROC(efi_call)
36794
36795 diff --git a/arch/x86/platform/intel-mid/intel-mid.c b/arch/x86/platform/intel-mid/intel-mid.c
36796 index 1bbedc4..eb795b5 100644
36797 --- a/arch/x86/platform/intel-mid/intel-mid.c
36798 +++ b/arch/x86/platform/intel-mid/intel-mid.c
36799 @@ -71,9 +71,10 @@ static void intel_mid_power_off(void)
36800 {
36801 };
36802
36803 -static void intel_mid_reboot(void)
36804 +static void __noreturn intel_mid_reboot(void)
36805 {
36806 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
36807 + BUG();
36808 }
36809
36810 static unsigned long __init intel_mid_calibrate_tsc(void)
36811 diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
36812 index d6ee929..3637cb5 100644
36813 --- a/arch/x86/platform/olpc/olpc_dt.c
36814 +++ b/arch/x86/platform/olpc/olpc_dt.c
36815 @@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
36816 return res;
36817 }
36818
36819 -static struct of_pdt_ops prom_olpc_ops __initdata = {
36820 +static struct of_pdt_ops prom_olpc_ops __initconst = {
36821 .nextprop = olpc_dt_nextprop,
36822 .getproplen = olpc_dt_getproplen,
36823 .getproperty = olpc_dt_getproperty,
36824 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
36825 index 424f4c9..f2a2988 100644
36826 --- a/arch/x86/power/cpu.c
36827 +++ b/arch/x86/power/cpu.c
36828 @@ -137,11 +137,8 @@ static void do_fpu_end(void)
36829 static void fix_processor_context(void)
36830 {
36831 int cpu = smp_processor_id();
36832 - struct tss_struct *t = &per_cpu(init_tss, cpu);
36833 -#ifdef CONFIG_X86_64
36834 - struct desc_struct *desc = get_cpu_gdt_table(cpu);
36835 - tss_desc tss;
36836 -#endif
36837 + struct tss_struct *t = init_tss + cpu;
36838 +
36839 set_tss_desc(cpu, t); /*
36840 * This just modifies memory; should not be
36841 * necessary. But... This is necessary, because
36842 @@ -150,10 +147,6 @@ static void fix_processor_context(void)
36843 */
36844
36845 #ifdef CONFIG_X86_64
36846 - memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
36847 - tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
36848 - write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
36849 -
36850 syscall_init(); /* This sets MSR_*STAR and related */
36851 #endif
36852 load_TR_desc(); /* This does ltr */
36853 diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
36854 index bad628a..a102610 100644
36855 --- a/arch/x86/realmode/init.c
36856 +++ b/arch/x86/realmode/init.c
36857 @@ -68,7 +68,13 @@ void __init setup_real_mode(void)
36858 __va(real_mode_header->trampoline_header);
36859
36860 #ifdef CONFIG_X86_32
36861 - trampoline_header->start = __pa_symbol(startup_32_smp);
36862 + trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
36863 +
36864 +#ifdef CONFIG_PAX_KERNEXEC
36865 + trampoline_header->start -= LOAD_PHYSICAL_ADDR;
36866 +#endif
36867 +
36868 + trampoline_header->boot_cs = __BOOT_CS;
36869 trampoline_header->gdt_limit = __BOOT_DS + 7;
36870 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
36871 #else
36872 @@ -84,7 +90,7 @@ void __init setup_real_mode(void)
36873 *trampoline_cr4_features = read_cr4();
36874
36875 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
36876 - trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
36877 + trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
36878 trampoline_pgd[511] = init_level4_pgt[511].pgd;
36879 #endif
36880 }
36881 diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
36882 index 7c0d7be..d24dc88 100644
36883 --- a/arch/x86/realmode/rm/Makefile
36884 +++ b/arch/x86/realmode/rm/Makefile
36885 @@ -67,5 +67,8 @@ $(obj)/realmode.relocs: $(obj)/realmode.elf FORCE
36886
36887 KBUILD_CFLAGS := $(LINUXINCLUDE) $(REALMODE_CFLAGS) -D_SETUP -D_WAKEUP \
36888 -I$(srctree)/arch/x86/boot
36889 +ifdef CONSTIFY_PLUGIN
36890 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
36891 +endif
36892 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
36893 GCOV_PROFILE := n
36894 diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
36895 index a28221d..93c40f1 100644
36896 --- a/arch/x86/realmode/rm/header.S
36897 +++ b/arch/x86/realmode/rm/header.S
36898 @@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
36899 #endif
36900 /* APM/BIOS reboot */
36901 .long pa_machine_real_restart_asm
36902 -#ifdef CONFIG_X86_64
36903 +#ifdef CONFIG_X86_32
36904 + .long __KERNEL_CS
36905 +#else
36906 .long __KERNEL32_CS
36907 #endif
36908 END(real_mode_header)
36909 diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
36910 index 48ddd76..c26749f 100644
36911 --- a/arch/x86/realmode/rm/trampoline_32.S
36912 +++ b/arch/x86/realmode/rm/trampoline_32.S
36913 @@ -24,6 +24,12 @@
36914 #include <asm/page_types.h>
36915 #include "realmode.h"
36916
36917 +#ifdef CONFIG_PAX_KERNEXEC
36918 +#define ta(X) (X)
36919 +#else
36920 +#define ta(X) (pa_ ## X)
36921 +#endif
36922 +
36923 .text
36924 .code16
36925
36926 @@ -38,8 +44,6 @@ ENTRY(trampoline_start)
36927
36928 cli # We should be safe anyway
36929
36930 - movl tr_start, %eax # where we need to go
36931 -
36932 movl $0xA5A5A5A5, trampoline_status
36933 # write marker for master knows we're running
36934
36935 @@ -55,7 +59,7 @@ ENTRY(trampoline_start)
36936 movw $1, %dx # protected mode (PE) bit
36937 lmsw %dx # into protected mode
36938
36939 - ljmpl $__BOOT_CS, $pa_startup_32
36940 + ljmpl *(trampoline_header)
36941
36942 .section ".text32","ax"
36943 .code32
36944 @@ -66,7 +70,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
36945 .balign 8
36946 GLOBAL(trampoline_header)
36947 tr_start: .space 4
36948 - tr_gdt_pad: .space 2
36949 + tr_boot_cs: .space 2
36950 tr_gdt: .space 6
36951 END(trampoline_header)
36952
36953 diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
36954 index dac7b20..72dbaca 100644
36955 --- a/arch/x86/realmode/rm/trampoline_64.S
36956 +++ b/arch/x86/realmode/rm/trampoline_64.S
36957 @@ -93,6 +93,7 @@ ENTRY(startup_32)
36958 movl %edx, %gs
36959
36960 movl pa_tr_cr4, %eax
36961 + andl $~X86_CR4_PCIDE, %eax
36962 movl %eax, %cr4 # Enable PAE mode
36963
36964 # Setup trampoline 4 level pagetables
36965 @@ -106,7 +107,7 @@ ENTRY(startup_32)
36966 wrmsr
36967
36968 # Enable paging and in turn activate Long Mode
36969 - movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
36970 + movl $(X86_CR0_PG | X86_CR0_PE), %eax
36971 movl %eax, %cr0
36972
36973 /*
36974 diff --git a/arch/x86/realmode/rm/wakeup_asm.S b/arch/x86/realmode/rm/wakeup_asm.S
36975 index 9e7e147..25a4158 100644
36976 --- a/arch/x86/realmode/rm/wakeup_asm.S
36977 +++ b/arch/x86/realmode/rm/wakeup_asm.S
36978 @@ -126,11 +126,10 @@ ENTRY(wakeup_start)
36979 lgdtl pmode_gdt
36980
36981 /* This really couldn't... */
36982 - movl pmode_entry, %eax
36983 movl pmode_cr0, %ecx
36984 movl %ecx, %cr0
36985 - ljmpl $__KERNEL_CS, $pa_startup_32
36986 - /* -> jmp *%eax in trampoline_32.S */
36987 +
36988 + ljmpl *pmode_entry
36989 #else
36990 jmp trampoline_start
36991 #endif
36992 diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
36993 index 604a37e..e49702a 100644
36994 --- a/arch/x86/tools/Makefile
36995 +++ b/arch/x86/tools/Makefile
36996 @@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
36997
36998 $(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
36999
37000 -HOST_EXTRACFLAGS += -I$(srctree)/tools/include
37001 +HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
37002 hostprogs-y += relocs
37003 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
37004 PHONY += relocs
37005 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
37006 index bbb1d22..e505211 100644
37007 --- a/arch/x86/tools/relocs.c
37008 +++ b/arch/x86/tools/relocs.c
37009 @@ -1,5 +1,7 @@
37010 /* This is included from relocs_32/64.c */
37011
37012 +#include "../../../include/generated/autoconf.h"
37013 +
37014 #define ElfW(type) _ElfW(ELF_BITS, type)
37015 #define _ElfW(bits, type) __ElfW(bits, type)
37016 #define __ElfW(bits, type) Elf##bits##_##type
37017 @@ -11,6 +13,7 @@
37018 #define Elf_Sym ElfW(Sym)
37019
37020 static Elf_Ehdr ehdr;
37021 +static Elf_Phdr *phdr;
37022
37023 struct relocs {
37024 uint32_t *offset;
37025 @@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
37026 }
37027 }
37028
37029 +static void read_phdrs(FILE *fp)
37030 +{
37031 + unsigned int i;
37032 +
37033 + phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
37034 + if (!phdr) {
37035 + die("Unable to allocate %d program headers\n",
37036 + ehdr.e_phnum);
37037 + }
37038 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
37039 + die("Seek to %d failed: %s\n",
37040 + ehdr.e_phoff, strerror(errno));
37041 + }
37042 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
37043 + die("Cannot read ELF program headers: %s\n",
37044 + strerror(errno));
37045 + }
37046 + for(i = 0; i < ehdr.e_phnum; i++) {
37047 + phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
37048 + phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
37049 + phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
37050 + phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
37051 + phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
37052 + phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
37053 + phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
37054 + phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
37055 + }
37056 +
37057 +}
37058 +
37059 static void read_shdrs(FILE *fp)
37060 {
37061 - int i;
37062 + unsigned int i;
37063 Elf_Shdr shdr;
37064
37065 secs = calloc(ehdr.e_shnum, sizeof(struct section));
37066 @@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
37067
37068 static void read_strtabs(FILE *fp)
37069 {
37070 - int i;
37071 + unsigned int i;
37072 for (i = 0; i < ehdr.e_shnum; i++) {
37073 struct section *sec = &secs[i];
37074 if (sec->shdr.sh_type != SHT_STRTAB) {
37075 @@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
37076
37077 static void read_symtabs(FILE *fp)
37078 {
37079 - int i,j;
37080 + unsigned int i,j;
37081 for (i = 0; i < ehdr.e_shnum; i++) {
37082 struct section *sec = &secs[i];
37083 if (sec->shdr.sh_type != SHT_SYMTAB) {
37084 @@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
37085 }
37086
37087
37088 -static void read_relocs(FILE *fp)
37089 +static void read_relocs(FILE *fp, int use_real_mode)
37090 {
37091 - int i,j;
37092 + unsigned int i,j;
37093 + uint32_t base;
37094 +
37095 for (i = 0; i < ehdr.e_shnum; i++) {
37096 struct section *sec = &secs[i];
37097 if (sec->shdr.sh_type != SHT_REL_TYPE) {
37098 @@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
37099 die("Cannot read symbol table: %s\n",
37100 strerror(errno));
37101 }
37102 + base = 0;
37103 +
37104 +#ifdef CONFIG_X86_32
37105 + for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
37106 + if (phdr[j].p_type != PT_LOAD )
37107 + continue;
37108 + 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)
37109 + continue;
37110 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
37111 + break;
37112 + }
37113 +#endif
37114 +
37115 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
37116 Elf_Rel *rel = &sec->reltab[j];
37117 - rel->r_offset = elf_addr_to_cpu(rel->r_offset);
37118 + rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
37119 rel->r_info = elf_xword_to_cpu(rel->r_info);
37120 #if (SHT_REL_TYPE == SHT_RELA)
37121 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
37122 @@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
37123
37124 static void print_absolute_symbols(void)
37125 {
37126 - int i;
37127 + unsigned int i;
37128 const char *format;
37129
37130 if (ELF_BITS == 64)
37131 @@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
37132 for (i = 0; i < ehdr.e_shnum; i++) {
37133 struct section *sec = &secs[i];
37134 char *sym_strtab;
37135 - int j;
37136 + unsigned int j;
37137
37138 if (sec->shdr.sh_type != SHT_SYMTAB) {
37139 continue;
37140 @@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
37141
37142 static void print_absolute_relocs(void)
37143 {
37144 - int i, printed = 0;
37145 + unsigned int i, printed = 0;
37146 const char *format;
37147
37148 if (ELF_BITS == 64)
37149 @@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
37150 struct section *sec_applies, *sec_symtab;
37151 char *sym_strtab;
37152 Elf_Sym *sh_symtab;
37153 - int j;
37154 + unsigned int j;
37155 if (sec->shdr.sh_type != SHT_REL_TYPE) {
37156 continue;
37157 }
37158 @@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
37159 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
37160 Elf_Sym *sym, const char *symname))
37161 {
37162 - int i;
37163 + unsigned int i;
37164 /* Walk through the relocations */
37165 for (i = 0; i < ehdr.e_shnum; i++) {
37166 char *sym_strtab;
37167 Elf_Sym *sh_symtab;
37168 struct section *sec_applies, *sec_symtab;
37169 - int j;
37170 + unsigned int j;
37171 struct section *sec = &secs[i];
37172
37173 if (sec->shdr.sh_type != SHT_REL_TYPE) {
37174 @@ -822,6 +870,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
37175 {
37176 unsigned r_type = ELF32_R_TYPE(rel->r_info);
37177 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
37178 + char *sym_strtab = sec->link->link->strtab;
37179 +
37180 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
37181 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
37182 + return 0;
37183 +
37184 +#ifdef CONFIG_PAX_KERNEXEC
37185 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
37186 + if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
37187 + return 0;
37188 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
37189 + return 0;
37190 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
37191 + return 0;
37192 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
37193 + return 0;
37194 +#endif
37195
37196 switch (r_type) {
37197 case R_386_NONE:
37198 @@ -960,7 +1025,7 @@ static int write32_as_text(uint32_t v, FILE *f)
37199
37200 static void emit_relocs(int as_text, int use_real_mode)
37201 {
37202 - int i;
37203 + unsigned int i;
37204 int (*write_reloc)(uint32_t, FILE *) = write32;
37205 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
37206 const char *symname);
37207 @@ -1060,10 +1125,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
37208 {
37209 regex_init(use_real_mode);
37210 read_ehdr(fp);
37211 + read_phdrs(fp);
37212 read_shdrs(fp);
37213 read_strtabs(fp);
37214 read_symtabs(fp);
37215 - read_relocs(fp);
37216 + read_relocs(fp, use_real_mode);
37217 if (ELF_BITS == 64)
37218 percpu_init();
37219 if (show_absolute_syms) {
37220 diff --git a/arch/x86/um/mem_32.c b/arch/x86/um/mem_32.c
37221 index f40281e..92728c9 100644
37222 --- a/arch/x86/um/mem_32.c
37223 +++ b/arch/x86/um/mem_32.c
37224 @@ -21,7 +21,7 @@ static int __init gate_vma_init(void)
37225 gate_vma.vm_start = FIXADDR_USER_START;
37226 gate_vma.vm_end = FIXADDR_USER_END;
37227 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
37228 - gate_vma.vm_page_prot = __P101;
37229 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
37230
37231 return 0;
37232 }
37233 diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
37234 index 80ffa5b..a33bd15 100644
37235 --- a/arch/x86/um/tls_32.c
37236 +++ b/arch/x86/um/tls_32.c
37237 @@ -260,7 +260,7 @@ out:
37238 if (unlikely(task == current &&
37239 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
37240 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
37241 - "without flushed TLS.", current->pid);
37242 + "without flushed TLS.", task_pid_nr(current));
37243 }
37244
37245 return 0;
37246 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
37247 index 61b04fe..3134230 100644
37248 --- a/arch/x86/vdso/Makefile
37249 +++ b/arch/x86/vdso/Makefile
37250 @@ -170,7 +170,7 @@ quiet_cmd_vdso = VDSO $@
37251 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
37252 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
37253
37254 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv) \
37255 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv) \
37256 $(call cc-ldoption, -Wl$(comma)--build-id) -Wl,-Bsymbolic $(LTO_CFLAGS)
37257 GCOV_PROFILE := n
37258
37259 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
37260 index e4f7781..ab5ab26 100644
37261 --- a/arch/x86/vdso/vdso32-setup.c
37262 +++ b/arch/x86/vdso/vdso32-setup.c
37263 @@ -14,6 +14,7 @@
37264 #include <asm/cpufeature.h>
37265 #include <asm/processor.h>
37266 #include <asm/vdso.h>
37267 +#include <asm/mman.h>
37268
37269 #ifdef CONFIG_COMPAT_VDSO
37270 #define VDSO_DEFAULT 0
37271 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
37272 index 5a5176d..e570acd 100644
37273 --- a/arch/x86/vdso/vma.c
37274 +++ b/arch/x86/vdso/vma.c
37275 @@ -16,10 +16,9 @@
37276 #include <asm/vdso.h>
37277 #include <asm/page.h>
37278 #include <asm/hpet.h>
37279 +#include <asm/mman.h>
37280
37281 #if defined(CONFIG_X86_64)
37282 -unsigned int __read_mostly vdso64_enabled = 1;
37283 -
37284 extern unsigned short vdso_sync_cpuid;
37285 #endif
37286
37287 @@ -101,6 +100,11 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr)
37288 .pages = no_pages,
37289 };
37290
37291 +#ifdef CONFIG_PAX_RANDMMAP
37292 + if (mm->pax_flags & MF_PAX_RANDMMAP)
37293 + calculate_addr = false;
37294 +#endif
37295 +
37296 if (calculate_addr) {
37297 addr = vdso_addr(current->mm->start_stack,
37298 image->sym_end_mapping);
37299 @@ -110,13 +114,13 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr)
37300
37301 down_write(&mm->mmap_sem);
37302
37303 - addr = get_unmapped_area(NULL, addr, image->sym_end_mapping, 0, 0);
37304 + addr = get_unmapped_area(NULL, addr, image->sym_end_mapping, 0, MAP_EXECUTABLE);
37305 if (IS_ERR_VALUE(addr)) {
37306 ret = addr;
37307 goto up_fail;
37308 }
37309
37310 - current->mm->context.vdso = (void __user *)addr;
37311 + mm->context.vdso = addr;
37312
37313 /*
37314 * MAYWRITE to allow gdb to COW and set breakpoints
37315 @@ -161,15 +165,12 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr)
37316 hpet_address >> PAGE_SHIFT,
37317 PAGE_SIZE,
37318 pgprot_noncached(PAGE_READONLY));
37319 -
37320 - if (ret)
37321 - goto up_fail;
37322 }
37323 #endif
37324
37325 up_fail:
37326 if (ret)
37327 - current->mm->context.vdso = NULL;
37328 + current->mm->context.vdso = 0;
37329
37330 up_write(&mm->mmap_sem);
37331 return ret;
37332 @@ -189,8 +190,8 @@ static int load_vdso32(void)
37333
37334 if (selected_vdso32->sym_VDSO32_SYSENTER_RETURN)
37335 current_thread_info()->sysenter_return =
37336 - current->mm->context.vdso +
37337 - selected_vdso32->sym_VDSO32_SYSENTER_RETURN;
37338 + (void __force_user *)(current->mm->context.vdso +
37339 + selected_vdso32->sym_VDSO32_SYSENTER_RETURN);
37340
37341 return 0;
37342 }
37343 @@ -199,9 +200,6 @@ static int load_vdso32(void)
37344 #ifdef CONFIG_X86_64
37345 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
37346 {
37347 - if (!vdso64_enabled)
37348 - return 0;
37349 -
37350 return map_vdso(&vdso_image_64, true);
37351 }
37352
37353 @@ -210,12 +208,8 @@ int compat_arch_setup_additional_pages(struct linux_binprm *bprm,
37354 int uses_interp)
37355 {
37356 #ifdef CONFIG_X86_X32_ABI
37357 - if (test_thread_flag(TIF_X32)) {
37358 - if (!vdso64_enabled)
37359 - return 0;
37360 -
37361 + if (test_thread_flag(TIF_X32))
37362 return map_vdso(&vdso_image_x32, true);
37363 - }
37364 #endif
37365
37366 return load_vdso32();
37367 @@ -227,12 +221,3 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
37368 return load_vdso32();
37369 }
37370 #endif
37371 -
37372 -#ifdef CONFIG_X86_64
37373 -static __init int vdso_setup(char *s)
37374 -{
37375 - vdso64_enabled = simple_strtoul(s, NULL, 0);
37376 - return 0;
37377 -}
37378 -__setup("vdso=", vdso_setup);
37379 -#endif
37380 diff --git a/arch/x86/xen/Kconfig b/arch/x86/xen/Kconfig
37381 index e88fda8..76ce7ce 100644
37382 --- a/arch/x86/xen/Kconfig
37383 +++ b/arch/x86/xen/Kconfig
37384 @@ -9,6 +9,7 @@ config XEN
37385 select XEN_HAVE_PVMMU
37386 depends on X86_64 || (X86_32 && X86_PAE)
37387 depends on X86_TSC
37388 + depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_XEN
37389 help
37390 This is the Linux Xen port. Enabling this will allow the
37391 kernel to boot in a paravirtualized environment under the
37392 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
37393 index ffb101e..98c0ecf 100644
37394 --- a/arch/x86/xen/enlighten.c
37395 +++ b/arch/x86/xen/enlighten.c
37396 @@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
37397
37398 struct shared_info xen_dummy_shared_info;
37399
37400 -void *xen_initial_gdt;
37401 -
37402 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
37403 __read_mostly int xen_have_vector_callback;
37404 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
37405 @@ -542,8 +540,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
37406 {
37407 unsigned long va = dtr->address;
37408 unsigned int size = dtr->size + 1;
37409 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
37410 - unsigned long frames[pages];
37411 + unsigned long frames[65536 / PAGE_SIZE];
37412 int f;
37413
37414 /*
37415 @@ -591,8 +588,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
37416 {
37417 unsigned long va = dtr->address;
37418 unsigned int size = dtr->size + 1;
37419 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
37420 - unsigned long frames[pages];
37421 + unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
37422 int f;
37423
37424 /*
37425 @@ -600,7 +596,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
37426 * 8-byte entries, or 16 4k pages..
37427 */
37428
37429 - BUG_ON(size > 65536);
37430 + BUG_ON(size > GDT_SIZE);
37431 BUG_ON(va & ~PAGE_MASK);
37432
37433 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
37434 @@ -989,7 +985,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
37435 return 0;
37436 }
37437
37438 -static void set_xen_basic_apic_ops(void)
37439 +static void __init set_xen_basic_apic_ops(void)
37440 {
37441 apic->read = xen_apic_read;
37442 apic->write = xen_apic_write;
37443 @@ -1295,30 +1291,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
37444 #endif
37445 };
37446
37447 -static void xen_reboot(int reason)
37448 +static __noreturn void xen_reboot(int reason)
37449 {
37450 struct sched_shutdown r = { .reason = reason };
37451
37452 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
37453 - BUG();
37454 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
37455 + BUG();
37456 }
37457
37458 -static void xen_restart(char *msg)
37459 +static __noreturn void xen_restart(char *msg)
37460 {
37461 xen_reboot(SHUTDOWN_reboot);
37462 }
37463
37464 -static void xen_emergency_restart(void)
37465 +static __noreturn void xen_emergency_restart(void)
37466 {
37467 xen_reboot(SHUTDOWN_reboot);
37468 }
37469
37470 -static void xen_machine_halt(void)
37471 +static __noreturn void xen_machine_halt(void)
37472 {
37473 xen_reboot(SHUTDOWN_poweroff);
37474 }
37475
37476 -static void xen_machine_power_off(void)
37477 +static __noreturn void xen_machine_power_off(void)
37478 {
37479 if (pm_power_off)
37480 pm_power_off();
37481 @@ -1568,7 +1564,17 @@ asmlinkage __visible void __init xen_start_kernel(void)
37482 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
37483
37484 /* Work out if we support NX */
37485 - x86_configure_nx();
37486 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
37487 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
37488 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
37489 + unsigned l, h;
37490 +
37491 + __supported_pte_mask |= _PAGE_NX;
37492 + rdmsr(MSR_EFER, l, h);
37493 + l |= EFER_NX;
37494 + wrmsr(MSR_EFER, l, h);
37495 + }
37496 +#endif
37497
37498 /* Get mfn list */
37499 xen_build_dynamic_phys_to_machine();
37500 @@ -1596,13 +1602,6 @@ asmlinkage __visible void __init xen_start_kernel(void)
37501
37502 machine_ops = xen_machine_ops;
37503
37504 - /*
37505 - * The only reliable way to retain the initial address of the
37506 - * percpu gdt_page is to remember it here, so we can go and
37507 - * mark it RW later, when the initial percpu area is freed.
37508 - */
37509 - xen_initial_gdt = &per_cpu(gdt_page, 0);
37510 -
37511 xen_smp_init();
37512
37513 #ifdef CONFIG_ACPI_NUMA
37514 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
37515 index e8a1201..046c66c 100644
37516 --- a/arch/x86/xen/mmu.c
37517 +++ b/arch/x86/xen/mmu.c
37518 @@ -379,7 +379,7 @@ static pteval_t pte_mfn_to_pfn(pteval_t val)
37519 return val;
37520 }
37521
37522 -static pteval_t pte_pfn_to_mfn(pteval_t val)
37523 +static pteval_t __intentional_overflow(-1) pte_pfn_to_mfn(pteval_t val)
37524 {
37525 if (val & _PAGE_PRESENT) {
37526 unsigned long pfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT;
37527 @@ -1904,6 +1904,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
37528 /* L3_k[510] -> level2_kernel_pgt
37529 * L3_i[511] -> level2_fixmap_pgt */
37530 convert_pfn_mfn(level3_kernel_pgt);
37531 + convert_pfn_mfn(level3_vmalloc_start_pgt);
37532 + convert_pfn_mfn(level3_vmalloc_end_pgt);
37533 + convert_pfn_mfn(level3_vmemmap_pgt);
37534 }
37535 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
37536 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
37537 @@ -1933,8 +1936,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
37538 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
37539 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
37540 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
37541 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
37542 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
37543 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
37544 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
37545 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
37546 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
37547 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
37548 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
37549
37550 @@ -2120,6 +2127,7 @@ static void __init xen_post_allocator_init(void)
37551 pv_mmu_ops.set_pud = xen_set_pud;
37552 #if PAGETABLE_LEVELS == 4
37553 pv_mmu_ops.set_pgd = xen_set_pgd;
37554 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
37555 #endif
37556
37557 /* This will work as long as patching hasn't happened yet
37558 @@ -2198,6 +2206,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
37559 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
37560 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
37561 .set_pgd = xen_set_pgd_hyper,
37562 + .set_pgd_batched = xen_set_pgd_hyper,
37563
37564 .alloc_pud = xen_alloc_pmd_init,
37565 .release_pud = xen_release_pmd_init,
37566 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
37567 index 7005974..54fb05f 100644
37568 --- a/arch/x86/xen/smp.c
37569 +++ b/arch/x86/xen/smp.c
37570 @@ -283,17 +283,13 @@ static void __init xen_smp_prepare_boot_cpu(void)
37571
37572 if (xen_pv_domain()) {
37573 if (!xen_feature(XENFEAT_writable_page_tables))
37574 - /* We've switched to the "real" per-cpu gdt, so make
37575 - * sure the old memory can be recycled. */
37576 - make_lowmem_page_readwrite(xen_initial_gdt);
37577 -
37578 #ifdef CONFIG_X86_32
37579 /*
37580 * Xen starts us with XEN_FLAT_RING1_DS, but linux code
37581 * expects __USER_DS
37582 */
37583 - loadsegment(ds, __USER_DS);
37584 - loadsegment(es, __USER_DS);
37585 + loadsegment(ds, __KERNEL_DS);
37586 + loadsegment(es, __KERNEL_DS);
37587 #endif
37588
37589 xen_filter_cpu_maps();
37590 @@ -372,7 +368,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
37591 #ifdef CONFIG_X86_32
37592 /* Note: PVH is not yet supported on x86_32. */
37593 ctxt->user_regs.fs = __KERNEL_PERCPU;
37594 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
37595 + savesegment(gs, ctxt->user_regs.gs);
37596 #endif
37597 ctxt->user_regs.eip = (unsigned long)cpu_bringup_and_idle;
37598
37599 @@ -381,8 +377,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
37600 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
37601 ctxt->flags = VGCF_IN_KERNEL;
37602 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
37603 - ctxt->user_regs.ds = __USER_DS;
37604 - ctxt->user_regs.es = __USER_DS;
37605 + ctxt->user_regs.ds = __KERNEL_DS;
37606 + ctxt->user_regs.es = __KERNEL_DS;
37607 ctxt->user_regs.ss = __KERNEL_DS;
37608
37609 xen_copy_trap_info(ctxt->trap_ctxt);
37610 @@ -437,14 +433,13 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
37611 int rc;
37612
37613 per_cpu(current_task, cpu) = idle;
37614 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
37615 #ifdef CONFIG_X86_32
37616 irq_ctx_init(cpu);
37617 #else
37618 clear_tsk_thread_flag(idle, TIF_FORK);
37619 #endif
37620 - per_cpu(kernel_stack, cpu) =
37621 - (unsigned long)task_stack_page(idle) -
37622 - KERNEL_STACK_OFFSET + THREAD_SIZE;
37623 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
37624
37625 xen_setup_runstate_info(cpu);
37626 xen_setup_timer(cpu);
37627 @@ -720,7 +715,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
37628
37629 void __init xen_smp_init(void)
37630 {
37631 - smp_ops = xen_smp_ops;
37632 + memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
37633 xen_fill_possible_map();
37634 }
37635
37636 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
37637 index fd92a64..1f72641 100644
37638 --- a/arch/x86/xen/xen-asm_32.S
37639 +++ b/arch/x86/xen/xen-asm_32.S
37640 @@ -99,7 +99,7 @@ ENTRY(xen_iret)
37641 pushw %fs
37642 movl $(__KERNEL_PERCPU), %eax
37643 movl %eax, %fs
37644 - movl %fs:xen_vcpu, %eax
37645 + mov PER_CPU_VAR(xen_vcpu), %eax
37646 POP_FS
37647 #else
37648 movl %ss:xen_vcpu, %eax
37649 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
37650 index 485b695..fda3e7c 100644
37651 --- a/arch/x86/xen/xen-head.S
37652 +++ b/arch/x86/xen/xen-head.S
37653 @@ -39,6 +39,17 @@ ENTRY(startup_xen)
37654 #ifdef CONFIG_X86_32
37655 mov %esi,xen_start_info
37656 mov $init_thread_union+THREAD_SIZE,%esp
37657 +#ifdef CONFIG_SMP
37658 + movl $cpu_gdt_table,%edi
37659 + movl $__per_cpu_load,%eax
37660 + movw %ax,__KERNEL_PERCPU + 2(%edi)
37661 + rorl $16,%eax
37662 + movb %al,__KERNEL_PERCPU + 4(%edi)
37663 + movb %ah,__KERNEL_PERCPU + 7(%edi)
37664 + movl $__per_cpu_end - 1,%eax
37665 + subl $__per_cpu_start,%eax
37666 + movw %ax,__KERNEL_PERCPU + 0(%edi)
37667 +#endif
37668 #else
37669 mov %rsi,xen_start_info
37670 mov $init_thread_union+THREAD_SIZE,%rsp
37671 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
37672 index 97d8765..c4526ec 100644
37673 --- a/arch/x86/xen/xen-ops.h
37674 +++ b/arch/x86/xen/xen-ops.h
37675 @@ -10,8 +10,6 @@
37676 extern const char xen_hypervisor_callback[];
37677 extern const char xen_failsafe_callback[];
37678
37679 -extern void *xen_initial_gdt;
37680 -
37681 struct trap_info;
37682 void xen_copy_trap_info(struct trap_info *traps);
37683
37684 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
37685 index 525bd3d..ef888b1 100644
37686 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
37687 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
37688 @@ -119,9 +119,9 @@
37689 ----------------------------------------------------------------------*/
37690
37691 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
37692 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
37693 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
37694 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
37695 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
37696
37697 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
37698 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
37699 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
37700 index 2f33760..835e50a 100644
37701 --- a/arch/xtensa/variants/fsf/include/variant/core.h
37702 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
37703 @@ -11,6 +11,7 @@
37704 #ifndef _XTENSA_CORE_H
37705 #define _XTENSA_CORE_H
37706
37707 +#include <linux/const.h>
37708
37709 /****************************************************************************
37710 Parameters Useful for Any Code, USER or PRIVILEGED
37711 @@ -112,9 +113,9 @@
37712 ----------------------------------------------------------------------*/
37713
37714 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
37715 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
37716 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
37717 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
37718 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
37719
37720 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
37721 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
37722 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
37723 index af00795..2bb8105 100644
37724 --- a/arch/xtensa/variants/s6000/include/variant/core.h
37725 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
37726 @@ -11,6 +11,7 @@
37727 #ifndef _XTENSA_CORE_CONFIGURATION_H
37728 #define _XTENSA_CORE_CONFIGURATION_H
37729
37730 +#include <linux/const.h>
37731
37732 /****************************************************************************
37733 Parameters Useful for Any Code, USER or PRIVILEGED
37734 @@ -118,9 +119,9 @@
37735 ----------------------------------------------------------------------*/
37736
37737 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
37738 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
37739 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
37740 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
37741 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
37742
37743 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
37744 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
37745 diff --git a/block/bio.c b/block/bio.c
37746 index 0ec61c9..93b94060 100644
37747 --- a/block/bio.c
37748 +++ b/block/bio.c
37749 @@ -1159,7 +1159,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
37750 /*
37751 * Overflow, abort
37752 */
37753 - if (end < start)
37754 + if (end < start || end - start > INT_MAX - nr_pages)
37755 return ERR_PTR(-EINVAL);
37756
37757 nr_pages += end - start;
37758 @@ -1293,7 +1293,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
37759 /*
37760 * Overflow, abort
37761 */
37762 - if (end < start)
37763 + if (end < start || end - start > INT_MAX - nr_pages)
37764 return ERR_PTR(-EINVAL);
37765
37766 nr_pages += end - start;
37767 @@ -1555,7 +1555,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
37768 const int read = bio_data_dir(bio) == READ;
37769 struct bio_map_data *bmd = bio->bi_private;
37770 int i;
37771 - char *p = bmd->sgvecs[0].iov_base;
37772 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
37773
37774 bio_for_each_segment_all(bvec, bio, i) {
37775 char *addr = page_address(bvec->bv_page);
37776 diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
37777 index 28d227c..d4c0bad 100644
37778 --- a/block/blk-cgroup.c
37779 +++ b/block/blk-cgroup.c
37780 @@ -822,7 +822,7 @@ static void blkcg_css_free(struct cgroup_subsys_state *css)
37781 static struct cgroup_subsys_state *
37782 blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
37783 {
37784 - static atomic64_t id_seq = ATOMIC64_INIT(0);
37785 + static atomic64_unchecked_t id_seq = ATOMIC64_INIT(0);
37786 struct blkcg *blkcg;
37787
37788 if (!parent_css) {
37789 @@ -836,7 +836,7 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
37790
37791 blkcg->cfq_weight = CFQ_WEIGHT_DEFAULT;
37792 blkcg->cfq_leaf_weight = CFQ_WEIGHT_DEFAULT;
37793 - blkcg->id = atomic64_inc_return(&id_seq); /* root is 0, start from 1 */
37794 + blkcg->id = atomic64_inc_return_unchecked(&id_seq); /* root is 0, start from 1 */
37795 done:
37796 spin_lock_init(&blkcg->lock);
37797 INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_ATOMIC);
37798 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
37799 index 0736729..2ec3b48 100644
37800 --- a/block/blk-iopoll.c
37801 +++ b/block/blk-iopoll.c
37802 @@ -74,7 +74,7 @@ void blk_iopoll_complete(struct blk_iopoll *iop)
37803 }
37804 EXPORT_SYMBOL(blk_iopoll_complete);
37805
37806 -static void blk_iopoll_softirq(struct softirq_action *h)
37807 +static __latent_entropy void blk_iopoll_softirq(void)
37808 {
37809 struct list_head *list = this_cpu_ptr(&blk_cpu_iopoll);
37810 int rearm = 0, budget = blk_iopoll_budget;
37811 diff --git a/block/blk-map.c b/block/blk-map.c
37812 index f890d43..97b0482 100644
37813 --- a/block/blk-map.c
37814 +++ b/block/blk-map.c
37815 @@ -300,7 +300,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
37816 if (!len || !kbuf)
37817 return -EINVAL;
37818
37819 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
37820 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
37821 if (do_copy)
37822 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
37823 else
37824 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
37825 index 53b1737..08177d2e 100644
37826 --- a/block/blk-softirq.c
37827 +++ b/block/blk-softirq.c
37828 @@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
37829 * Softirq action handler - move entries to local list and loop over them
37830 * while passing them to the queue registered handler.
37831 */
37832 -static void blk_done_softirq(struct softirq_action *h)
37833 +static __latent_entropy void blk_done_softirq(void)
37834 {
37835 struct list_head *cpu_list, local_list;
37836
37837 diff --git a/block/bsg.c b/block/bsg.c
37838 index ff46add..c4ba8ee 100644
37839 --- a/block/bsg.c
37840 +++ b/block/bsg.c
37841 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
37842 struct sg_io_v4 *hdr, struct bsg_device *bd,
37843 fmode_t has_write_perm)
37844 {
37845 + unsigned char tmpcmd[sizeof(rq->__cmd)];
37846 + unsigned char *cmdptr;
37847 +
37848 if (hdr->request_len > BLK_MAX_CDB) {
37849 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
37850 if (!rq->cmd)
37851 return -ENOMEM;
37852 - }
37853 + cmdptr = rq->cmd;
37854 + } else
37855 + cmdptr = tmpcmd;
37856
37857 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
37858 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
37859 hdr->request_len))
37860 return -EFAULT;
37861
37862 + if (cmdptr != rq->cmd)
37863 + memcpy(rq->cmd, cmdptr, hdr->request_len);
37864 +
37865 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
37866 if (blk_verify_command(rq->cmd, has_write_perm))
37867 return -EPERM;
37868 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
37869 index a0926a6..b2b14b2 100644
37870 --- a/block/compat_ioctl.c
37871 +++ b/block/compat_ioctl.c
37872 @@ -156,7 +156,7 @@ static int compat_cdrom_generic_command(struct block_device *bdev, fmode_t mode,
37873 cgc = compat_alloc_user_space(sizeof(*cgc));
37874 cgc32 = compat_ptr(arg);
37875
37876 - if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) ||
37877 + if (copy_in_user(cgc->cmd, cgc32->cmd, sizeof(cgc->cmd)) ||
37878 get_user(data, &cgc32->buffer) ||
37879 put_user(compat_ptr(data), &cgc->buffer) ||
37880 copy_in_user(&cgc->buflen, &cgc32->buflen,
37881 @@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
37882 err |= __get_user(f->spec1, &uf->spec1);
37883 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
37884 err |= __get_user(name, &uf->name);
37885 - f->name = compat_ptr(name);
37886 + f->name = (void __force_kernel *)compat_ptr(name);
37887 if (err) {
37888 err = -EFAULT;
37889 goto out;
37890 diff --git a/block/genhd.c b/block/genhd.c
37891 index 791f419..89f21c4 100644
37892 --- a/block/genhd.c
37893 +++ b/block/genhd.c
37894 @@ -467,21 +467,24 @@ static char *bdevt_str(dev_t devt, char *buf)
37895
37896 /*
37897 * Register device numbers dev..(dev+range-1)
37898 - * range must be nonzero
37899 + * Noop if @range is zero.
37900 * The hash chain is sorted on range, so that subranges can override.
37901 */
37902 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
37903 struct kobject *(*probe)(dev_t, int *, void *),
37904 int (*lock)(dev_t, void *), void *data)
37905 {
37906 - kobj_map(bdev_map, devt, range, module, probe, lock, data);
37907 + if (range)
37908 + kobj_map(bdev_map, devt, range, module, probe, lock, data);
37909 }
37910
37911 EXPORT_SYMBOL(blk_register_region);
37912
37913 +/* undo blk_register_region(), noop if @range is zero */
37914 void blk_unregister_region(dev_t devt, unsigned long range)
37915 {
37916 - kobj_unmap(bdev_map, devt, range);
37917 + if (range)
37918 + kobj_unmap(bdev_map, devt, range);
37919 }
37920
37921 EXPORT_SYMBOL(blk_unregister_region);
37922 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
37923 index dc51f46..d5446a8 100644
37924 --- a/block/partitions/efi.c
37925 +++ b/block/partitions/efi.c
37926 @@ -293,14 +293,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
37927 if (!gpt)
37928 return NULL;
37929
37930 + if (!le32_to_cpu(gpt->num_partition_entries))
37931 + return NULL;
37932 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
37933 + if (!pte)
37934 + return NULL;
37935 +
37936 count = le32_to_cpu(gpt->num_partition_entries) *
37937 le32_to_cpu(gpt->sizeof_partition_entry);
37938 - if (!count)
37939 - return NULL;
37940 - pte = kmalloc(count, GFP_KERNEL);
37941 - if (!pte)
37942 - return NULL;
37943 -
37944 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
37945 (u8 *) pte, count) < count) {
37946 kfree(pte);
37947 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
37948 index 14695c6..27a4636 100644
37949 --- a/block/scsi_ioctl.c
37950 +++ b/block/scsi_ioctl.c
37951 @@ -67,7 +67,7 @@ static int scsi_get_bus(struct request_queue *q, int __user *p)
37952 return put_user(0, p);
37953 }
37954
37955 -static int sg_get_timeout(struct request_queue *q)
37956 +static int __intentional_overflow(-1) sg_get_timeout(struct request_queue *q)
37957 {
37958 return jiffies_to_clock_t(q->sg_timeout);
37959 }
37960 @@ -220,8 +220,20 @@ EXPORT_SYMBOL(blk_verify_command);
37961 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
37962 struct sg_io_hdr *hdr, fmode_t mode)
37963 {
37964 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
37965 + unsigned char tmpcmd[sizeof(rq->__cmd)];
37966 + unsigned char *cmdptr;
37967 +
37968 + if (rq->cmd != rq->__cmd)
37969 + cmdptr = rq->cmd;
37970 + else
37971 + cmdptr = tmpcmd;
37972 +
37973 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
37974 return -EFAULT;
37975 +
37976 + if (cmdptr != rq->cmd)
37977 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
37978 +
37979 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
37980 return -EPERM;
37981
37982 @@ -413,6 +425,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
37983 int err;
37984 unsigned int in_len, out_len, bytes, opcode, cmdlen;
37985 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
37986 + unsigned char tmpcmd[sizeof(rq->__cmd)];
37987 + unsigned char *cmdptr;
37988
37989 if (!sic)
37990 return -EINVAL;
37991 @@ -446,9 +460,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
37992 */
37993 err = -EFAULT;
37994 rq->cmd_len = cmdlen;
37995 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
37996 +
37997 + if (rq->cmd != rq->__cmd)
37998 + cmdptr = rq->cmd;
37999 + else
38000 + cmdptr = tmpcmd;
38001 +
38002 + if (copy_from_user(cmdptr, sic->data, cmdlen))
38003 goto error;
38004
38005 + if (rq->cmd != cmdptr)
38006 + memcpy(rq->cmd, cmdptr, cmdlen);
38007 +
38008 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
38009 goto error;
38010
38011 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
38012 index 7bdd61b..afec999 100644
38013 --- a/crypto/cryptd.c
38014 +++ b/crypto/cryptd.c
38015 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
38016
38017 struct cryptd_blkcipher_request_ctx {
38018 crypto_completion_t complete;
38019 -};
38020 +} __no_const;
38021
38022 struct cryptd_hash_ctx {
38023 struct crypto_shash *child;
38024 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
38025
38026 struct cryptd_aead_request_ctx {
38027 crypto_completion_t complete;
38028 -};
38029 +} __no_const;
38030
38031 static void cryptd_queue_worker(struct work_struct *work);
38032
38033 diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
38034 index 309d345..1632720 100644
38035 --- a/crypto/pcrypt.c
38036 +++ b/crypto/pcrypt.c
38037 @@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
38038 int ret;
38039
38040 pinst->kobj.kset = pcrypt_kset;
38041 - ret = kobject_add(&pinst->kobj, NULL, name);
38042 + ret = kobject_add(&pinst->kobj, NULL, "%s", name);
38043 if (!ret)
38044 kobject_uevent(&pinst->kobj, KOBJ_ADD);
38045
38046 diff --git a/drivers/acpi/acpica/hwxfsleep.c b/drivers/acpi/acpica/hwxfsleep.c
38047 index 6921c7f..78e1af7 100644
38048 --- a/drivers/acpi/acpica/hwxfsleep.c
38049 +++ b/drivers/acpi/acpica/hwxfsleep.c
38050 @@ -63,11 +63,12 @@ static acpi_status acpi_hw_sleep_dispatch(u8 sleep_state, u32 function_id);
38051 /* Legacy functions are optional, based upon ACPI_REDUCED_HARDWARE */
38052
38053 static struct acpi_sleep_functions acpi_sleep_dispatch[] = {
38054 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
38055 - acpi_hw_extended_sleep},
38056 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
38057 - acpi_hw_extended_wake_prep},
38058 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake), acpi_hw_extended_wake}
38059 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
38060 + .extended_function = acpi_hw_extended_sleep},
38061 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
38062 + .extended_function = acpi_hw_extended_wake_prep},
38063 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake),
38064 + .extended_function = acpi_hw_extended_wake}
38065 };
38066
38067 /*
38068 diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
38069 index e5bcd91..74f050d 100644
38070 --- a/drivers/acpi/apei/apei-internal.h
38071 +++ b/drivers/acpi/apei/apei-internal.h
38072 @@ -19,7 +19,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
38073 struct apei_exec_ins_type {
38074 u32 flags;
38075 apei_exec_ins_func_t run;
38076 -};
38077 +} __do_const;
38078
38079 struct apei_exec_context {
38080 u32 ip;
38081 diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
38082 index dab7cb7..f0d2994 100644
38083 --- a/drivers/acpi/apei/ghes.c
38084 +++ b/drivers/acpi/apei/ghes.c
38085 @@ -500,7 +500,7 @@ static void __ghes_print_estatus(const char *pfx,
38086 const struct acpi_hest_generic *generic,
38087 const struct acpi_generic_status *estatus)
38088 {
38089 - static atomic_t seqno;
38090 + static atomic_unchecked_t seqno;
38091 unsigned int curr_seqno;
38092 char pfx_seq[64];
38093
38094 @@ -511,7 +511,7 @@ static void __ghes_print_estatus(const char *pfx,
38095 else
38096 pfx = KERN_ERR;
38097 }
38098 - curr_seqno = atomic_inc_return(&seqno);
38099 + curr_seqno = atomic_inc_return_unchecked(&seqno);
38100 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
38101 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
38102 pfx_seq, generic->header.source_id);
38103 diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
38104 index a83e3c6..c3d617f 100644
38105 --- a/drivers/acpi/bgrt.c
38106 +++ b/drivers/acpi/bgrt.c
38107 @@ -86,8 +86,10 @@ static int __init bgrt_init(void)
38108 if (!bgrt_image)
38109 return -ENODEV;
38110
38111 - bin_attr_image.private = bgrt_image;
38112 - bin_attr_image.size = bgrt_image_size;
38113 + pax_open_kernel();
38114 + *(void **)&bin_attr_image.private = bgrt_image;
38115 + *(size_t *)&bin_attr_image.size = bgrt_image_size;
38116 + pax_close_kernel();
38117
38118 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
38119 if (!bgrt_kobj)
38120 diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
38121 index 3d8413d..95f638c 100644
38122 --- a/drivers/acpi/blacklist.c
38123 +++ b/drivers/acpi/blacklist.c
38124 @@ -51,7 +51,7 @@ struct acpi_blacklist_item {
38125 u32 is_critical_error;
38126 };
38127
38128 -static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
38129 +static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
38130
38131 /*
38132 * POLICY: If *anything* doesn't work, put it on the blacklist.
38133 @@ -163,7 +163,7 @@ static int __init dmi_disable_osi_win8(const struct dmi_system_id *d)
38134 return 0;
38135 }
38136
38137 -static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
38138 +static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
38139 {
38140 .callback = dmi_disable_osi_vista,
38141 .ident = "Fujitsu Siemens",
38142 diff --git a/drivers/acpi/custom_method.c b/drivers/acpi/custom_method.c
38143 index c68e724..e863008 100644
38144 --- a/drivers/acpi/custom_method.c
38145 +++ b/drivers/acpi/custom_method.c
38146 @@ -29,6 +29,10 @@ static ssize_t cm_write(struct file *file, const char __user * user_buf,
38147 struct acpi_table_header table;
38148 acpi_status status;
38149
38150 +#ifdef CONFIG_GRKERNSEC_KMEM
38151 + return -EPERM;
38152 +#endif
38153 +
38154 if (!(*ppos)) {
38155 /* parse the table header to get the table length */
38156 if (count <= sizeof(struct acpi_table_header))
38157 diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
38158 index 3dca36d..abaf070 100644
38159 --- a/drivers/acpi/processor_idle.c
38160 +++ b/drivers/acpi/processor_idle.c
38161 @@ -952,7 +952,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
38162 {
38163 int i, count = CPUIDLE_DRIVER_STATE_START;
38164 struct acpi_processor_cx *cx;
38165 - struct cpuidle_state *state;
38166 + cpuidle_state_no_const *state;
38167 struct cpuidle_driver *drv = &acpi_idle_driver;
38168
38169 if (!pr->flags.power_setup_done)
38170 diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
38171 index 38cb978..352c761 100644
38172 --- a/drivers/acpi/sysfs.c
38173 +++ b/drivers/acpi/sysfs.c
38174 @@ -423,11 +423,11 @@ static u32 num_counters;
38175 static struct attribute **all_attrs;
38176 static u32 acpi_gpe_count;
38177
38178 -static struct attribute_group interrupt_stats_attr_group = {
38179 +static attribute_group_no_const interrupt_stats_attr_group = {
38180 .name = "interrupts",
38181 };
38182
38183 -static struct kobj_attribute *counter_attrs;
38184 +static kobj_attribute_no_const *counter_attrs;
38185
38186 static void delete_gpe_attr_array(void)
38187 {
38188 diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
38189 index d72ce04..d6ab3c2 100644
38190 --- a/drivers/ata/libahci.c
38191 +++ b/drivers/ata/libahci.c
38192 @@ -1257,7 +1257,7 @@ int ahci_kick_engine(struct ata_port *ap)
38193 }
38194 EXPORT_SYMBOL_GPL(ahci_kick_engine);
38195
38196 -static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
38197 +static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
38198 struct ata_taskfile *tf, int is_cmd, u16 flags,
38199 unsigned long timeout_msec)
38200 {
38201 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
38202 index 677c0c1..354b89b 100644
38203 --- a/drivers/ata/libata-core.c
38204 +++ b/drivers/ata/libata-core.c
38205 @@ -98,7 +98,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
38206 static void ata_dev_xfermask(struct ata_device *dev);
38207 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
38208
38209 -atomic_t ata_print_id = ATOMIC_INIT(0);
38210 +atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
38211
38212 struct ata_force_param {
38213 const char *name;
38214 @@ -4863,7 +4863,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
38215 struct ata_port *ap;
38216 unsigned int tag;
38217
38218 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
38219 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
38220 ap = qc->ap;
38221
38222 qc->flags = 0;
38223 @@ -4879,7 +4879,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
38224 struct ata_port *ap;
38225 struct ata_link *link;
38226
38227 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
38228 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
38229 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
38230 ap = qc->ap;
38231 link = qc->dev->link;
38232 @@ -5983,6 +5983,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
38233 return;
38234
38235 spin_lock(&lock);
38236 + pax_open_kernel();
38237
38238 for (cur = ops->inherits; cur; cur = cur->inherits) {
38239 void **inherit = (void **)cur;
38240 @@ -5996,8 +5997,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
38241 if (IS_ERR(*pp))
38242 *pp = NULL;
38243
38244 - ops->inherits = NULL;
38245 + *(struct ata_port_operations **)&ops->inherits = NULL;
38246
38247 + pax_close_kernel();
38248 spin_unlock(&lock);
38249 }
38250
38251 @@ -6193,7 +6195,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
38252
38253 /* give ports names and add SCSI hosts */
38254 for (i = 0; i < host->n_ports; i++) {
38255 - host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
38256 + host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
38257 host->ports[i]->local_port_no = i + 1;
38258 }
38259
38260 diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
38261 index 72691fd..ad104c0 100644
38262 --- a/drivers/ata/libata-scsi.c
38263 +++ b/drivers/ata/libata-scsi.c
38264 @@ -4151,7 +4151,7 @@ int ata_sas_port_init(struct ata_port *ap)
38265
38266 if (rc)
38267 return rc;
38268 - ap->print_id = atomic_inc_return(&ata_print_id);
38269 + ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
38270 return 0;
38271 }
38272 EXPORT_SYMBOL_GPL(ata_sas_port_init);
38273 diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
38274 index 45b5ab3..98446b8 100644
38275 --- a/drivers/ata/libata.h
38276 +++ b/drivers/ata/libata.h
38277 @@ -53,7 +53,7 @@ enum {
38278 ATA_DNXFER_QUIET = (1 << 31),
38279 };
38280
38281 -extern atomic_t ata_print_id;
38282 +extern atomic_unchecked_t ata_print_id;
38283 extern int atapi_passthru16;
38284 extern int libata_fua;
38285 extern int libata_noacpi;
38286 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
38287 index 4edb1a8..84e1658 100644
38288 --- a/drivers/ata/pata_arasan_cf.c
38289 +++ b/drivers/ata/pata_arasan_cf.c
38290 @@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
38291 /* Handle platform specific quirks */
38292 if (quirk) {
38293 if (quirk & CF_BROKEN_PIO) {
38294 - ap->ops->set_piomode = NULL;
38295 + pax_open_kernel();
38296 + *(void **)&ap->ops->set_piomode = NULL;
38297 + pax_close_kernel();
38298 ap->pio_mask = 0;
38299 }
38300 if (quirk & CF_BROKEN_MWDMA)
38301 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
38302 index f9b983a..887b9d8 100644
38303 --- a/drivers/atm/adummy.c
38304 +++ b/drivers/atm/adummy.c
38305 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
38306 vcc->pop(vcc, skb);
38307 else
38308 dev_kfree_skb_any(skb);
38309 - atomic_inc(&vcc->stats->tx);
38310 + atomic_inc_unchecked(&vcc->stats->tx);
38311
38312 return 0;
38313 }
38314 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
38315 index f1a9198..f466a4a 100644
38316 --- a/drivers/atm/ambassador.c
38317 +++ b/drivers/atm/ambassador.c
38318 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
38319 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
38320
38321 // VC layer stats
38322 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
38323 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
38324
38325 // free the descriptor
38326 kfree (tx_descr);
38327 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
38328 dump_skb ("<<<", vc, skb);
38329
38330 // VC layer stats
38331 - atomic_inc(&atm_vcc->stats->rx);
38332 + atomic_inc_unchecked(&atm_vcc->stats->rx);
38333 __net_timestamp(skb);
38334 // end of our responsibility
38335 atm_vcc->push (atm_vcc, skb);
38336 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
38337 } else {
38338 PRINTK (KERN_INFO, "dropped over-size frame");
38339 // should we count this?
38340 - atomic_inc(&atm_vcc->stats->rx_drop);
38341 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
38342 }
38343
38344 } else {
38345 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
38346 }
38347
38348 if (check_area (skb->data, skb->len)) {
38349 - atomic_inc(&atm_vcc->stats->tx_err);
38350 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
38351 return -ENOMEM; // ?
38352 }
38353
38354 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
38355 index 0e3f8f9..765a7a5 100644
38356 --- a/drivers/atm/atmtcp.c
38357 +++ b/drivers/atm/atmtcp.c
38358 @@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
38359 if (vcc->pop) vcc->pop(vcc,skb);
38360 else dev_kfree_skb(skb);
38361 if (dev_data) return 0;
38362 - atomic_inc(&vcc->stats->tx_err);
38363 + atomic_inc_unchecked(&vcc->stats->tx_err);
38364 return -ENOLINK;
38365 }
38366 size = skb->len+sizeof(struct atmtcp_hdr);
38367 @@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
38368 if (!new_skb) {
38369 if (vcc->pop) vcc->pop(vcc,skb);
38370 else dev_kfree_skb(skb);
38371 - atomic_inc(&vcc->stats->tx_err);
38372 + atomic_inc_unchecked(&vcc->stats->tx_err);
38373 return -ENOBUFS;
38374 }
38375 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
38376 @@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
38377 if (vcc->pop) vcc->pop(vcc,skb);
38378 else dev_kfree_skb(skb);
38379 out_vcc->push(out_vcc,new_skb);
38380 - atomic_inc(&vcc->stats->tx);
38381 - atomic_inc(&out_vcc->stats->rx);
38382 + atomic_inc_unchecked(&vcc->stats->tx);
38383 + atomic_inc_unchecked(&out_vcc->stats->rx);
38384 return 0;
38385 }
38386
38387 @@ -299,7 +299,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
38388 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
38389 read_unlock(&vcc_sklist_lock);
38390 if (!out_vcc) {
38391 - atomic_inc(&vcc->stats->tx_err);
38392 + atomic_inc_unchecked(&vcc->stats->tx_err);
38393 goto done;
38394 }
38395 skb_pull(skb,sizeof(struct atmtcp_hdr));
38396 @@ -311,8 +311,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
38397 __net_timestamp(new_skb);
38398 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
38399 out_vcc->push(out_vcc,new_skb);
38400 - atomic_inc(&vcc->stats->tx);
38401 - atomic_inc(&out_vcc->stats->rx);
38402 + atomic_inc_unchecked(&vcc->stats->tx);
38403 + atomic_inc_unchecked(&out_vcc->stats->rx);
38404 done:
38405 if (vcc->pop) vcc->pop(vcc,skb);
38406 else dev_kfree_skb(skb);
38407 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
38408 index b1955ba..b179940 100644
38409 --- a/drivers/atm/eni.c
38410 +++ b/drivers/atm/eni.c
38411 @@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
38412 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
38413 vcc->dev->number);
38414 length = 0;
38415 - atomic_inc(&vcc->stats->rx_err);
38416 + atomic_inc_unchecked(&vcc->stats->rx_err);
38417 }
38418 else {
38419 length = ATM_CELL_SIZE-1; /* no HEC */
38420 @@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
38421 size);
38422 }
38423 eff = length = 0;
38424 - atomic_inc(&vcc->stats->rx_err);
38425 + atomic_inc_unchecked(&vcc->stats->rx_err);
38426 }
38427 else {
38428 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
38429 @@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
38430 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
38431 vcc->dev->number,vcc->vci,length,size << 2,descr);
38432 length = eff = 0;
38433 - atomic_inc(&vcc->stats->rx_err);
38434 + atomic_inc_unchecked(&vcc->stats->rx_err);
38435 }
38436 }
38437 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
38438 @@ -767,7 +767,7 @@ rx_dequeued++;
38439 vcc->push(vcc,skb);
38440 pushed++;
38441 }
38442 - atomic_inc(&vcc->stats->rx);
38443 + atomic_inc_unchecked(&vcc->stats->rx);
38444 }
38445 wake_up(&eni_dev->rx_wait);
38446 }
38447 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
38448 PCI_DMA_TODEVICE);
38449 if (vcc->pop) vcc->pop(vcc,skb);
38450 else dev_kfree_skb_irq(skb);
38451 - atomic_inc(&vcc->stats->tx);
38452 + atomic_inc_unchecked(&vcc->stats->tx);
38453 wake_up(&eni_dev->tx_wait);
38454 dma_complete++;
38455 }
38456 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
38457 index 82f2ae0..f205c02 100644
38458 --- a/drivers/atm/firestream.c
38459 +++ b/drivers/atm/firestream.c
38460 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
38461 }
38462 }
38463
38464 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
38465 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
38466
38467 fs_dprintk (FS_DEBUG_TXMEM, "i");
38468 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
38469 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
38470 #endif
38471 skb_put (skb, qe->p1 & 0xffff);
38472 ATM_SKB(skb)->vcc = atm_vcc;
38473 - atomic_inc(&atm_vcc->stats->rx);
38474 + atomic_inc_unchecked(&atm_vcc->stats->rx);
38475 __net_timestamp(skb);
38476 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
38477 atm_vcc->push (atm_vcc, skb);
38478 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
38479 kfree (pe);
38480 }
38481 if (atm_vcc)
38482 - atomic_inc(&atm_vcc->stats->rx_drop);
38483 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
38484 break;
38485 case 0x1f: /* Reassembly abort: no buffers. */
38486 /* Silently increment error counter. */
38487 if (atm_vcc)
38488 - atomic_inc(&atm_vcc->stats->rx_drop);
38489 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
38490 break;
38491 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
38492 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
38493 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
38494 index d4725fc..2d4ea65 100644
38495 --- a/drivers/atm/fore200e.c
38496 +++ b/drivers/atm/fore200e.c
38497 @@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
38498 #endif
38499 /* check error condition */
38500 if (*entry->status & STATUS_ERROR)
38501 - atomic_inc(&vcc->stats->tx_err);
38502 + atomic_inc_unchecked(&vcc->stats->tx_err);
38503 else
38504 - atomic_inc(&vcc->stats->tx);
38505 + atomic_inc_unchecked(&vcc->stats->tx);
38506 }
38507 }
38508
38509 @@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
38510 if (skb == NULL) {
38511 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
38512
38513 - atomic_inc(&vcc->stats->rx_drop);
38514 + atomic_inc_unchecked(&vcc->stats->rx_drop);
38515 return -ENOMEM;
38516 }
38517
38518 @@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
38519
38520 dev_kfree_skb_any(skb);
38521
38522 - atomic_inc(&vcc->stats->rx_drop);
38523 + atomic_inc_unchecked(&vcc->stats->rx_drop);
38524 return -ENOMEM;
38525 }
38526
38527 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
38528
38529 vcc->push(vcc, skb);
38530 - atomic_inc(&vcc->stats->rx);
38531 + atomic_inc_unchecked(&vcc->stats->rx);
38532
38533 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
38534
38535 @@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
38536 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
38537 fore200e->atm_dev->number,
38538 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
38539 - atomic_inc(&vcc->stats->rx_err);
38540 + atomic_inc_unchecked(&vcc->stats->rx_err);
38541 }
38542 }
38543
38544 @@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
38545 goto retry_here;
38546 }
38547
38548 - atomic_inc(&vcc->stats->tx_err);
38549 + atomic_inc_unchecked(&vcc->stats->tx_err);
38550
38551 fore200e->tx_sat++;
38552 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
38553 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
38554 index aa6be26..f70a785 100644
38555 --- a/drivers/atm/he.c
38556 +++ b/drivers/atm/he.c
38557 @@ -1690,7 +1690,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
38558
38559 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
38560 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
38561 - atomic_inc(&vcc->stats->rx_drop);
38562 + atomic_inc_unchecked(&vcc->stats->rx_drop);
38563 goto return_host_buffers;
38564 }
38565
38566 @@ -1717,7 +1717,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
38567 RBRQ_LEN_ERR(he_dev->rbrq_head)
38568 ? "LEN_ERR" : "",
38569 vcc->vpi, vcc->vci);
38570 - atomic_inc(&vcc->stats->rx_err);
38571 + atomic_inc_unchecked(&vcc->stats->rx_err);
38572 goto return_host_buffers;
38573 }
38574
38575 @@ -1769,7 +1769,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
38576 vcc->push(vcc, skb);
38577 spin_lock(&he_dev->global_lock);
38578
38579 - atomic_inc(&vcc->stats->rx);
38580 + atomic_inc_unchecked(&vcc->stats->rx);
38581
38582 return_host_buffers:
38583 ++pdus_assembled;
38584 @@ -2095,7 +2095,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
38585 tpd->vcc->pop(tpd->vcc, tpd->skb);
38586 else
38587 dev_kfree_skb_any(tpd->skb);
38588 - atomic_inc(&tpd->vcc->stats->tx_err);
38589 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
38590 }
38591 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
38592 return;
38593 @@ -2507,7 +2507,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
38594 vcc->pop(vcc, skb);
38595 else
38596 dev_kfree_skb_any(skb);
38597 - atomic_inc(&vcc->stats->tx_err);
38598 + atomic_inc_unchecked(&vcc->stats->tx_err);
38599 return -EINVAL;
38600 }
38601
38602 @@ -2518,7 +2518,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
38603 vcc->pop(vcc, skb);
38604 else
38605 dev_kfree_skb_any(skb);
38606 - atomic_inc(&vcc->stats->tx_err);
38607 + atomic_inc_unchecked(&vcc->stats->tx_err);
38608 return -EINVAL;
38609 }
38610 #endif
38611 @@ -2530,7 +2530,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
38612 vcc->pop(vcc, skb);
38613 else
38614 dev_kfree_skb_any(skb);
38615 - atomic_inc(&vcc->stats->tx_err);
38616 + atomic_inc_unchecked(&vcc->stats->tx_err);
38617 spin_unlock_irqrestore(&he_dev->global_lock, flags);
38618 return -ENOMEM;
38619 }
38620 @@ -2572,7 +2572,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
38621 vcc->pop(vcc, skb);
38622 else
38623 dev_kfree_skb_any(skb);
38624 - atomic_inc(&vcc->stats->tx_err);
38625 + atomic_inc_unchecked(&vcc->stats->tx_err);
38626 spin_unlock_irqrestore(&he_dev->global_lock, flags);
38627 return -ENOMEM;
38628 }
38629 @@ -2603,7 +2603,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
38630 __enqueue_tpd(he_dev, tpd, cid);
38631 spin_unlock_irqrestore(&he_dev->global_lock, flags);
38632
38633 - atomic_inc(&vcc->stats->tx);
38634 + atomic_inc_unchecked(&vcc->stats->tx);
38635
38636 return 0;
38637 }
38638 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
38639 index 1dc0519..1aadaf7 100644
38640 --- a/drivers/atm/horizon.c
38641 +++ b/drivers/atm/horizon.c
38642 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
38643 {
38644 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
38645 // VC layer stats
38646 - atomic_inc(&vcc->stats->rx);
38647 + atomic_inc_unchecked(&vcc->stats->rx);
38648 __net_timestamp(skb);
38649 // end of our responsibility
38650 vcc->push (vcc, skb);
38651 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
38652 dev->tx_iovec = NULL;
38653
38654 // VC layer stats
38655 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
38656 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
38657
38658 // free the skb
38659 hrz_kfree_skb (skb);
38660 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
38661 index b621f56..1e3a799 100644
38662 --- a/drivers/atm/idt77252.c
38663 +++ b/drivers/atm/idt77252.c
38664 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
38665 else
38666 dev_kfree_skb(skb);
38667
38668 - atomic_inc(&vcc->stats->tx);
38669 + atomic_inc_unchecked(&vcc->stats->tx);
38670 }
38671
38672 atomic_dec(&scq->used);
38673 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
38674 if ((sb = dev_alloc_skb(64)) == NULL) {
38675 printk("%s: Can't allocate buffers for aal0.\n",
38676 card->name);
38677 - atomic_add(i, &vcc->stats->rx_drop);
38678 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
38679 break;
38680 }
38681 if (!atm_charge(vcc, sb->truesize)) {
38682 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
38683 card->name);
38684 - atomic_add(i - 1, &vcc->stats->rx_drop);
38685 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
38686 dev_kfree_skb(sb);
38687 break;
38688 }
38689 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
38690 ATM_SKB(sb)->vcc = vcc;
38691 __net_timestamp(sb);
38692 vcc->push(vcc, sb);
38693 - atomic_inc(&vcc->stats->rx);
38694 + atomic_inc_unchecked(&vcc->stats->rx);
38695
38696 cell += ATM_CELL_PAYLOAD;
38697 }
38698 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
38699 "(CDC: %08x)\n",
38700 card->name, len, rpp->len, readl(SAR_REG_CDC));
38701 recycle_rx_pool_skb(card, rpp);
38702 - atomic_inc(&vcc->stats->rx_err);
38703 + atomic_inc_unchecked(&vcc->stats->rx_err);
38704 return;
38705 }
38706 if (stat & SAR_RSQE_CRC) {
38707 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
38708 recycle_rx_pool_skb(card, rpp);
38709 - atomic_inc(&vcc->stats->rx_err);
38710 + atomic_inc_unchecked(&vcc->stats->rx_err);
38711 return;
38712 }
38713 if (skb_queue_len(&rpp->queue) > 1) {
38714 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
38715 RXPRINTK("%s: Can't alloc RX skb.\n",
38716 card->name);
38717 recycle_rx_pool_skb(card, rpp);
38718 - atomic_inc(&vcc->stats->rx_err);
38719 + atomic_inc_unchecked(&vcc->stats->rx_err);
38720 return;
38721 }
38722 if (!atm_charge(vcc, skb->truesize)) {
38723 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
38724 __net_timestamp(skb);
38725
38726 vcc->push(vcc, skb);
38727 - atomic_inc(&vcc->stats->rx);
38728 + atomic_inc_unchecked(&vcc->stats->rx);
38729
38730 return;
38731 }
38732 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
38733 __net_timestamp(skb);
38734
38735 vcc->push(vcc, skb);
38736 - atomic_inc(&vcc->stats->rx);
38737 + atomic_inc_unchecked(&vcc->stats->rx);
38738
38739 if (skb->truesize > SAR_FB_SIZE_3)
38740 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
38741 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
38742 if (vcc->qos.aal != ATM_AAL0) {
38743 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
38744 card->name, vpi, vci);
38745 - atomic_inc(&vcc->stats->rx_drop);
38746 + atomic_inc_unchecked(&vcc->stats->rx_drop);
38747 goto drop;
38748 }
38749
38750 if ((sb = dev_alloc_skb(64)) == NULL) {
38751 printk("%s: Can't allocate buffers for AAL0.\n",
38752 card->name);
38753 - atomic_inc(&vcc->stats->rx_err);
38754 + atomic_inc_unchecked(&vcc->stats->rx_err);
38755 goto drop;
38756 }
38757
38758 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
38759 ATM_SKB(sb)->vcc = vcc;
38760 __net_timestamp(sb);
38761 vcc->push(vcc, sb);
38762 - atomic_inc(&vcc->stats->rx);
38763 + atomic_inc_unchecked(&vcc->stats->rx);
38764
38765 drop:
38766 skb_pull(queue, 64);
38767 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
38768
38769 if (vc == NULL) {
38770 printk("%s: NULL connection in send().\n", card->name);
38771 - atomic_inc(&vcc->stats->tx_err);
38772 + atomic_inc_unchecked(&vcc->stats->tx_err);
38773 dev_kfree_skb(skb);
38774 return -EINVAL;
38775 }
38776 if (!test_bit(VCF_TX, &vc->flags)) {
38777 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
38778 - atomic_inc(&vcc->stats->tx_err);
38779 + atomic_inc_unchecked(&vcc->stats->tx_err);
38780 dev_kfree_skb(skb);
38781 return -EINVAL;
38782 }
38783 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
38784 break;
38785 default:
38786 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
38787 - atomic_inc(&vcc->stats->tx_err);
38788 + atomic_inc_unchecked(&vcc->stats->tx_err);
38789 dev_kfree_skb(skb);
38790 return -EINVAL;
38791 }
38792
38793 if (skb_shinfo(skb)->nr_frags != 0) {
38794 printk("%s: No scatter-gather yet.\n", card->name);
38795 - atomic_inc(&vcc->stats->tx_err);
38796 + atomic_inc_unchecked(&vcc->stats->tx_err);
38797 dev_kfree_skb(skb);
38798 return -EINVAL;
38799 }
38800 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
38801
38802 err = queue_skb(card, vc, skb, oam);
38803 if (err) {
38804 - atomic_inc(&vcc->stats->tx_err);
38805 + atomic_inc_unchecked(&vcc->stats->tx_err);
38806 dev_kfree_skb(skb);
38807 return err;
38808 }
38809 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
38810 skb = dev_alloc_skb(64);
38811 if (!skb) {
38812 printk("%s: Out of memory in send_oam().\n", card->name);
38813 - atomic_inc(&vcc->stats->tx_err);
38814 + atomic_inc_unchecked(&vcc->stats->tx_err);
38815 return -ENOMEM;
38816 }
38817 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
38818 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
38819 index 4217f29..88f547a 100644
38820 --- a/drivers/atm/iphase.c
38821 +++ b/drivers/atm/iphase.c
38822 @@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
38823 status = (u_short) (buf_desc_ptr->desc_mode);
38824 if (status & (RX_CER | RX_PTE | RX_OFL))
38825 {
38826 - atomic_inc(&vcc->stats->rx_err);
38827 + atomic_inc_unchecked(&vcc->stats->rx_err);
38828 IF_ERR(printk("IA: bad packet, dropping it");)
38829 if (status & RX_CER) {
38830 IF_ERR(printk(" cause: packet CRC error\n");)
38831 @@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
38832 len = dma_addr - buf_addr;
38833 if (len > iadev->rx_buf_sz) {
38834 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
38835 - atomic_inc(&vcc->stats->rx_err);
38836 + atomic_inc_unchecked(&vcc->stats->rx_err);
38837 goto out_free_desc;
38838 }
38839
38840 @@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
38841 ia_vcc = INPH_IA_VCC(vcc);
38842 if (ia_vcc == NULL)
38843 {
38844 - atomic_inc(&vcc->stats->rx_err);
38845 + atomic_inc_unchecked(&vcc->stats->rx_err);
38846 atm_return(vcc, skb->truesize);
38847 dev_kfree_skb_any(skb);
38848 goto INCR_DLE;
38849 @@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
38850 if ((length > iadev->rx_buf_sz) || (length >
38851 (skb->len - sizeof(struct cpcs_trailer))))
38852 {
38853 - atomic_inc(&vcc->stats->rx_err);
38854 + atomic_inc_unchecked(&vcc->stats->rx_err);
38855 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
38856 length, skb->len);)
38857 atm_return(vcc, skb->truesize);
38858 @@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
38859
38860 IF_RX(printk("rx_dle_intr: skb push");)
38861 vcc->push(vcc,skb);
38862 - atomic_inc(&vcc->stats->rx);
38863 + atomic_inc_unchecked(&vcc->stats->rx);
38864 iadev->rx_pkt_cnt++;
38865 }
38866 INCR_DLE:
38867 @@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
38868 {
38869 struct k_sonet_stats *stats;
38870 stats = &PRIV(_ia_dev[board])->sonet_stats;
38871 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
38872 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
38873 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
38874 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
38875 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
38876 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
38877 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
38878 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
38879 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
38880 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
38881 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
38882 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
38883 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
38884 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
38885 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
38886 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
38887 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
38888 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
38889 }
38890 ia_cmds.status = 0;
38891 break;
38892 @@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
38893 if ((desc == 0) || (desc > iadev->num_tx_desc))
38894 {
38895 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
38896 - atomic_inc(&vcc->stats->tx);
38897 + atomic_inc_unchecked(&vcc->stats->tx);
38898 if (vcc->pop)
38899 vcc->pop(vcc, skb);
38900 else
38901 @@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
38902 ATM_DESC(skb) = vcc->vci;
38903 skb_queue_tail(&iadev->tx_dma_q, skb);
38904
38905 - atomic_inc(&vcc->stats->tx);
38906 + atomic_inc_unchecked(&vcc->stats->tx);
38907 iadev->tx_pkt_cnt++;
38908 /* Increment transaction counter */
38909 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
38910
38911 #if 0
38912 /* add flow control logic */
38913 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
38914 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
38915 if (iavcc->vc_desc_cnt > 10) {
38916 vcc->tx_quota = vcc->tx_quota * 3 / 4;
38917 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
38918 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
38919 index fa7d7019..1e404c7 100644
38920 --- a/drivers/atm/lanai.c
38921 +++ b/drivers/atm/lanai.c
38922 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
38923 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
38924 lanai_endtx(lanai, lvcc);
38925 lanai_free_skb(lvcc->tx.atmvcc, skb);
38926 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
38927 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
38928 }
38929
38930 /* Try to fill the buffer - don't call unless there is backlog */
38931 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
38932 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
38933 __net_timestamp(skb);
38934 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
38935 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
38936 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
38937 out:
38938 lvcc->rx.buf.ptr = end;
38939 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
38940 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
38941 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
38942 "vcc %d\n", lanai->number, (unsigned int) s, vci);
38943 lanai->stats.service_rxnotaal5++;
38944 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
38945 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
38946 return 0;
38947 }
38948 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
38949 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
38950 int bytes;
38951 read_unlock(&vcc_sklist_lock);
38952 DPRINTK("got trashed rx pdu on vci %d\n", vci);
38953 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
38954 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
38955 lvcc->stats.x.aal5.service_trash++;
38956 bytes = (SERVICE_GET_END(s) * 16) -
38957 (((unsigned long) lvcc->rx.buf.ptr) -
38958 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
38959 }
38960 if (s & SERVICE_STREAM) {
38961 read_unlock(&vcc_sklist_lock);
38962 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
38963 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
38964 lvcc->stats.x.aal5.service_stream++;
38965 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
38966 "PDU on VCI %d!\n", lanai->number, vci);
38967 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
38968 return 0;
38969 }
38970 DPRINTK("got rx crc error on vci %d\n", vci);
38971 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
38972 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
38973 lvcc->stats.x.aal5.service_rxcrc++;
38974 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
38975 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
38976 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
38977 index 9988ac9..7c52585 100644
38978 --- a/drivers/atm/nicstar.c
38979 +++ b/drivers/atm/nicstar.c
38980 @@ -1640,7 +1640,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
38981 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
38982 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
38983 card->index);
38984 - atomic_inc(&vcc->stats->tx_err);
38985 + atomic_inc_unchecked(&vcc->stats->tx_err);
38986 dev_kfree_skb_any(skb);
38987 return -EINVAL;
38988 }
38989 @@ -1648,7 +1648,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
38990 if (!vc->tx) {
38991 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
38992 card->index);
38993 - atomic_inc(&vcc->stats->tx_err);
38994 + atomic_inc_unchecked(&vcc->stats->tx_err);
38995 dev_kfree_skb_any(skb);
38996 return -EINVAL;
38997 }
38998 @@ -1656,14 +1656,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
38999 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
39000 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
39001 card->index);
39002 - atomic_inc(&vcc->stats->tx_err);
39003 + atomic_inc_unchecked(&vcc->stats->tx_err);
39004 dev_kfree_skb_any(skb);
39005 return -EINVAL;
39006 }
39007
39008 if (skb_shinfo(skb)->nr_frags != 0) {
39009 printk("nicstar%d: No scatter-gather yet.\n", card->index);
39010 - atomic_inc(&vcc->stats->tx_err);
39011 + atomic_inc_unchecked(&vcc->stats->tx_err);
39012 dev_kfree_skb_any(skb);
39013 return -EINVAL;
39014 }
39015 @@ -1711,11 +1711,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
39016 }
39017
39018 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
39019 - atomic_inc(&vcc->stats->tx_err);
39020 + atomic_inc_unchecked(&vcc->stats->tx_err);
39021 dev_kfree_skb_any(skb);
39022 return -EIO;
39023 }
39024 - atomic_inc(&vcc->stats->tx);
39025 + atomic_inc_unchecked(&vcc->stats->tx);
39026
39027 return 0;
39028 }
39029 @@ -2032,14 +2032,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
39030 printk
39031 ("nicstar%d: Can't allocate buffers for aal0.\n",
39032 card->index);
39033 - atomic_add(i, &vcc->stats->rx_drop);
39034 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
39035 break;
39036 }
39037 if (!atm_charge(vcc, sb->truesize)) {
39038 RXPRINTK
39039 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
39040 card->index);
39041 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
39042 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
39043 dev_kfree_skb_any(sb);
39044 break;
39045 }
39046 @@ -2054,7 +2054,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
39047 ATM_SKB(sb)->vcc = vcc;
39048 __net_timestamp(sb);
39049 vcc->push(vcc, sb);
39050 - atomic_inc(&vcc->stats->rx);
39051 + atomic_inc_unchecked(&vcc->stats->rx);
39052 cell += ATM_CELL_PAYLOAD;
39053 }
39054
39055 @@ -2071,7 +2071,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
39056 if (iovb == NULL) {
39057 printk("nicstar%d: Out of iovec buffers.\n",
39058 card->index);
39059 - atomic_inc(&vcc->stats->rx_drop);
39060 + atomic_inc_unchecked(&vcc->stats->rx_drop);
39061 recycle_rx_buf(card, skb);
39062 return;
39063 }
39064 @@ -2095,7 +2095,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
39065 small or large buffer itself. */
39066 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
39067 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
39068 - atomic_inc(&vcc->stats->rx_err);
39069 + atomic_inc_unchecked(&vcc->stats->rx_err);
39070 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
39071 NS_MAX_IOVECS);
39072 NS_PRV_IOVCNT(iovb) = 0;
39073 @@ -2115,7 +2115,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
39074 ("nicstar%d: Expected a small buffer, and this is not one.\n",
39075 card->index);
39076 which_list(card, skb);
39077 - atomic_inc(&vcc->stats->rx_err);
39078 + atomic_inc_unchecked(&vcc->stats->rx_err);
39079 recycle_rx_buf(card, skb);
39080 vc->rx_iov = NULL;
39081 recycle_iov_buf(card, iovb);
39082 @@ -2128,7 +2128,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
39083 ("nicstar%d: Expected a large buffer, and this is not one.\n",
39084 card->index);
39085 which_list(card, skb);
39086 - atomic_inc(&vcc->stats->rx_err);
39087 + atomic_inc_unchecked(&vcc->stats->rx_err);
39088 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
39089 NS_PRV_IOVCNT(iovb));
39090 vc->rx_iov = NULL;
39091 @@ -2151,7 +2151,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
39092 printk(" - PDU size mismatch.\n");
39093 else
39094 printk(".\n");
39095 - atomic_inc(&vcc->stats->rx_err);
39096 + atomic_inc_unchecked(&vcc->stats->rx_err);
39097 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
39098 NS_PRV_IOVCNT(iovb));
39099 vc->rx_iov = NULL;
39100 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
39101 /* skb points to a small buffer */
39102 if (!atm_charge(vcc, skb->truesize)) {
39103 push_rxbufs(card, skb);
39104 - atomic_inc(&vcc->stats->rx_drop);
39105 + atomic_inc_unchecked(&vcc->stats->rx_drop);
39106 } else {
39107 skb_put(skb, len);
39108 dequeue_sm_buf(card, skb);
39109 @@ -2175,7 +2175,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
39110 ATM_SKB(skb)->vcc = vcc;
39111 __net_timestamp(skb);
39112 vcc->push(vcc, skb);
39113 - atomic_inc(&vcc->stats->rx);
39114 + atomic_inc_unchecked(&vcc->stats->rx);
39115 }
39116 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
39117 struct sk_buff *sb;
39118 @@ -2186,7 +2186,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
39119 if (len <= NS_SMBUFSIZE) {
39120 if (!atm_charge(vcc, sb->truesize)) {
39121 push_rxbufs(card, sb);
39122 - atomic_inc(&vcc->stats->rx_drop);
39123 + atomic_inc_unchecked(&vcc->stats->rx_drop);
39124 } else {
39125 skb_put(sb, len);
39126 dequeue_sm_buf(card, sb);
39127 @@ -2196,7 +2196,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
39128 ATM_SKB(sb)->vcc = vcc;
39129 __net_timestamp(sb);
39130 vcc->push(vcc, sb);
39131 - atomic_inc(&vcc->stats->rx);
39132 + atomic_inc_unchecked(&vcc->stats->rx);
39133 }
39134
39135 push_rxbufs(card, skb);
39136 @@ -2205,7 +2205,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
39137
39138 if (!atm_charge(vcc, skb->truesize)) {
39139 push_rxbufs(card, skb);
39140 - atomic_inc(&vcc->stats->rx_drop);
39141 + atomic_inc_unchecked(&vcc->stats->rx_drop);
39142 } else {
39143 dequeue_lg_buf(card, skb);
39144 #ifdef NS_USE_DESTRUCTORS
39145 @@ -2218,7 +2218,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
39146 ATM_SKB(skb)->vcc = vcc;
39147 __net_timestamp(skb);
39148 vcc->push(vcc, skb);
39149 - atomic_inc(&vcc->stats->rx);
39150 + atomic_inc_unchecked(&vcc->stats->rx);
39151 }
39152
39153 push_rxbufs(card, sb);
39154 @@ -2239,7 +2239,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
39155 printk
39156 ("nicstar%d: Out of huge buffers.\n",
39157 card->index);
39158 - atomic_inc(&vcc->stats->rx_drop);
39159 + atomic_inc_unchecked(&vcc->stats->rx_drop);
39160 recycle_iovec_rx_bufs(card,
39161 (struct iovec *)
39162 iovb->data,
39163 @@ -2290,7 +2290,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
39164 card->hbpool.count++;
39165 } else
39166 dev_kfree_skb_any(hb);
39167 - atomic_inc(&vcc->stats->rx_drop);
39168 + atomic_inc_unchecked(&vcc->stats->rx_drop);
39169 } else {
39170 /* Copy the small buffer to the huge buffer */
39171 sb = (struct sk_buff *)iov->iov_base;
39172 @@ -2327,7 +2327,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
39173 #endif /* NS_USE_DESTRUCTORS */
39174 __net_timestamp(hb);
39175 vcc->push(vcc, hb);
39176 - atomic_inc(&vcc->stats->rx);
39177 + atomic_inc_unchecked(&vcc->stats->rx);
39178 }
39179 }
39180
39181 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
39182 index 943cf0d..37d15d5 100644
39183 --- a/drivers/atm/solos-pci.c
39184 +++ b/drivers/atm/solos-pci.c
39185 @@ -838,7 +838,7 @@ static void solos_bh(unsigned long card_arg)
39186 }
39187 atm_charge(vcc, skb->truesize);
39188 vcc->push(vcc, skb);
39189 - atomic_inc(&vcc->stats->rx);
39190 + atomic_inc_unchecked(&vcc->stats->rx);
39191 break;
39192
39193 case PKT_STATUS:
39194 @@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
39195 vcc = SKB_CB(oldskb)->vcc;
39196
39197 if (vcc) {
39198 - atomic_inc(&vcc->stats->tx);
39199 + atomic_inc_unchecked(&vcc->stats->tx);
39200 solos_pop(vcc, oldskb);
39201 } else {
39202 dev_kfree_skb_irq(oldskb);
39203 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
39204 index 0215934..ce9f5b1 100644
39205 --- a/drivers/atm/suni.c
39206 +++ b/drivers/atm/suni.c
39207 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
39208
39209
39210 #define ADD_LIMITED(s,v) \
39211 - atomic_add((v),&stats->s); \
39212 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
39213 + atomic_add_unchecked((v),&stats->s); \
39214 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
39215
39216
39217 static void suni_hz(unsigned long from_timer)
39218 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
39219 index 5120a96..e2572bd 100644
39220 --- a/drivers/atm/uPD98402.c
39221 +++ b/drivers/atm/uPD98402.c
39222 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
39223 struct sonet_stats tmp;
39224 int error = 0;
39225
39226 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
39227 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
39228 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
39229 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
39230 if (zero && !error) {
39231 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
39232
39233
39234 #define ADD_LIMITED(s,v) \
39235 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
39236 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
39237 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
39238 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
39239 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
39240 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
39241
39242
39243 static void stat_event(struct atm_dev *dev)
39244 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
39245 if (reason & uPD98402_INT_PFM) stat_event(dev);
39246 if (reason & uPD98402_INT_PCO) {
39247 (void) GET(PCOCR); /* clear interrupt cause */
39248 - atomic_add(GET(HECCT),
39249 + atomic_add_unchecked(GET(HECCT),
39250 &PRIV(dev)->sonet_stats.uncorr_hcs);
39251 }
39252 if ((reason & uPD98402_INT_RFO) &&
39253 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
39254 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
39255 uPD98402_INT_LOS),PIMR); /* enable them */
39256 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
39257 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
39258 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
39259 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
39260 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
39261 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
39262 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
39263 return 0;
39264 }
39265
39266 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
39267 index 969c3c2..9b72956 100644
39268 --- a/drivers/atm/zatm.c
39269 +++ b/drivers/atm/zatm.c
39270 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
39271 }
39272 if (!size) {
39273 dev_kfree_skb_irq(skb);
39274 - if (vcc) atomic_inc(&vcc->stats->rx_err);
39275 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
39276 continue;
39277 }
39278 if (!atm_charge(vcc,skb->truesize)) {
39279 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
39280 skb->len = size;
39281 ATM_SKB(skb)->vcc = vcc;
39282 vcc->push(vcc,skb);
39283 - atomic_inc(&vcc->stats->rx);
39284 + atomic_inc_unchecked(&vcc->stats->rx);
39285 }
39286 zout(pos & 0xffff,MTA(mbx));
39287 #if 0 /* probably a stupid idea */
39288 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
39289 skb_queue_head(&zatm_vcc->backlog,skb);
39290 break;
39291 }
39292 - atomic_inc(&vcc->stats->tx);
39293 + atomic_inc_unchecked(&vcc->stats->tx);
39294 wake_up(&zatm_vcc->tx_wait);
39295 }
39296
39297 diff --git a/drivers/base/bus.c b/drivers/base/bus.c
39298 index 83e910a..b224a73 100644
39299 --- a/drivers/base/bus.c
39300 +++ b/drivers/base/bus.c
39301 @@ -1124,7 +1124,7 @@ int subsys_interface_register(struct subsys_interface *sif)
39302 return -EINVAL;
39303
39304 mutex_lock(&subsys->p->mutex);
39305 - list_add_tail(&sif->node, &subsys->p->interfaces);
39306 + pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
39307 if (sif->add_dev) {
39308 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
39309 while ((dev = subsys_dev_iter_next(&iter)))
39310 @@ -1149,7 +1149,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
39311 subsys = sif->subsys;
39312
39313 mutex_lock(&subsys->p->mutex);
39314 - list_del_init(&sif->node);
39315 + pax_list_del_init((struct list_head *)&sif->node);
39316 if (sif->remove_dev) {
39317 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
39318 while ((dev = subsys_dev_iter_next(&iter)))
39319 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
39320 index 25798db..15f130e 100644
39321 --- a/drivers/base/devtmpfs.c
39322 +++ b/drivers/base/devtmpfs.c
39323 @@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
39324 if (!thread)
39325 return 0;
39326
39327 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
39328 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
39329 if (err)
39330 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
39331 else
39332 @@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
39333 *err = sys_unshare(CLONE_NEWNS);
39334 if (*err)
39335 goto out;
39336 - *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
39337 + *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
39338 if (*err)
39339 goto out;
39340 - sys_chdir("/.."); /* will traverse into overmounted root */
39341 - sys_chroot(".");
39342 + sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
39343 + sys_chroot((char __force_user *)".");
39344 complete(&setup_done);
39345 while (1) {
39346 spin_lock(&req_lock);
39347 diff --git a/drivers/base/node.c b/drivers/base/node.c
39348 index 8f7ed99..700dd0c 100644
39349 --- a/drivers/base/node.c
39350 +++ b/drivers/base/node.c
39351 @@ -624,7 +624,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
39352 struct node_attr {
39353 struct device_attribute attr;
39354 enum node_states state;
39355 -};
39356 +} __do_const;
39357
39358 static ssize_t show_node_state(struct device *dev,
39359 struct device_attribute *attr, char *buf)
39360 diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
39361 index eee55c1..b8c9393 100644
39362 --- a/drivers/base/power/domain.c
39363 +++ b/drivers/base/power/domain.c
39364 @@ -1821,9 +1821,9 @@ int __pm_genpd_remove_callbacks(struct device *dev, bool clear_td)
39365
39366 if (dev->power.subsys_data->domain_data) {
39367 gpd_data = to_gpd_data(dev->power.subsys_data->domain_data);
39368 - gpd_data->ops = (struct gpd_dev_ops){ NULL };
39369 + memset(&gpd_data->ops, 0, sizeof(gpd_data->ops));
39370 if (clear_td)
39371 - gpd_data->td = (struct gpd_timing_data){ 0 };
39372 + memset(&gpd_data->td, 0, sizeof(gpd_data->td));
39373
39374 if (--gpd_data->refcount == 0) {
39375 dev->power.subsys_data->domain_data = NULL;
39376 @@ -1862,7 +1862,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
39377 {
39378 struct cpuidle_driver *cpuidle_drv;
39379 struct gpd_cpu_data *cpu_data;
39380 - struct cpuidle_state *idle_state;
39381 + cpuidle_state_no_const *idle_state;
39382 int ret = 0;
39383
39384 if (IS_ERR_OR_NULL(genpd) || state < 0)
39385 @@ -1930,7 +1930,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
39386 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
39387 {
39388 struct gpd_cpu_data *cpu_data;
39389 - struct cpuidle_state *idle_state;
39390 + cpuidle_state_no_const *idle_state;
39391 int ret = 0;
39392
39393 if (IS_ERR_OR_NULL(genpd))
39394 diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
39395 index 95b181d1..c4f0e19 100644
39396 --- a/drivers/base/power/sysfs.c
39397 +++ b/drivers/base/power/sysfs.c
39398 @@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
39399 return -EIO;
39400 }
39401 }
39402 - return sprintf(buf, p);
39403 + return sprintf(buf, "%s", p);
39404 }
39405
39406 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
39407 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
39408 index eb1bd2e..2667d3a 100644
39409 --- a/drivers/base/power/wakeup.c
39410 +++ b/drivers/base/power/wakeup.c
39411 @@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
39412 * They need to be modified together atomically, so it's better to use one
39413 * atomic variable to hold them both.
39414 */
39415 -static atomic_t combined_event_count = ATOMIC_INIT(0);
39416 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
39417
39418 #define IN_PROGRESS_BITS (sizeof(int) * 4)
39419 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
39420
39421 static void split_counters(unsigned int *cnt, unsigned int *inpr)
39422 {
39423 - unsigned int comb = atomic_read(&combined_event_count);
39424 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
39425
39426 *cnt = (comb >> IN_PROGRESS_BITS);
39427 *inpr = comb & MAX_IN_PROGRESS;
39428 @@ -401,7 +401,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
39429 ws->start_prevent_time = ws->last_time;
39430
39431 /* Increment the counter of events in progress. */
39432 - cec = atomic_inc_return(&combined_event_count);
39433 + cec = atomic_inc_return_unchecked(&combined_event_count);
39434
39435 trace_wakeup_source_activate(ws->name, cec);
39436 }
39437 @@ -527,7 +527,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
39438 * Increment the counter of registered wakeup events and decrement the
39439 * couter of wakeup events in progress simultaneously.
39440 */
39441 - cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
39442 + cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
39443 trace_wakeup_source_deactivate(ws->name, cec);
39444
39445 split_counters(&cnt, &inpr);
39446 diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
39447 index dbb8350..4762f4c 100644
39448 --- a/drivers/base/syscore.c
39449 +++ b/drivers/base/syscore.c
39450 @@ -22,7 +22,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
39451 void register_syscore_ops(struct syscore_ops *ops)
39452 {
39453 mutex_lock(&syscore_ops_lock);
39454 - list_add_tail(&ops->node, &syscore_ops_list);
39455 + pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
39456 mutex_unlock(&syscore_ops_lock);
39457 }
39458 EXPORT_SYMBOL_GPL(register_syscore_ops);
39459 @@ -34,7 +34,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
39460 void unregister_syscore_ops(struct syscore_ops *ops)
39461 {
39462 mutex_lock(&syscore_ops_lock);
39463 - list_del(&ops->node);
39464 + pax_list_del((struct list_head *)&ops->node);
39465 mutex_unlock(&syscore_ops_lock);
39466 }
39467 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
39468 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
39469 index 4595c22..d4f6c54 100644
39470 --- a/drivers/block/cciss.c
39471 +++ b/drivers/block/cciss.c
39472 @@ -3011,7 +3011,7 @@ static void start_io(ctlr_info_t *h)
39473 while (!list_empty(&h->reqQ)) {
39474 c = list_entry(h->reqQ.next, CommandList_struct, list);
39475 /* can't do anything if fifo is full */
39476 - if ((h->access.fifo_full(h))) {
39477 + if ((h->access->fifo_full(h))) {
39478 dev_warn(&h->pdev->dev, "fifo full\n");
39479 break;
39480 }
39481 @@ -3021,7 +3021,7 @@ static void start_io(ctlr_info_t *h)
39482 h->Qdepth--;
39483
39484 /* Tell the controller execute command */
39485 - h->access.submit_command(h, c);
39486 + h->access->submit_command(h, c);
39487
39488 /* Put job onto the completed Q */
39489 addQ(&h->cmpQ, c);
39490 @@ -3447,17 +3447,17 @@ startio:
39491
39492 static inline unsigned long get_next_completion(ctlr_info_t *h)
39493 {
39494 - return h->access.command_completed(h);
39495 + return h->access->command_completed(h);
39496 }
39497
39498 static inline int interrupt_pending(ctlr_info_t *h)
39499 {
39500 - return h->access.intr_pending(h);
39501 + return h->access->intr_pending(h);
39502 }
39503
39504 static inline long interrupt_not_for_us(ctlr_info_t *h)
39505 {
39506 - return ((h->access.intr_pending(h) == 0) ||
39507 + return ((h->access->intr_pending(h) == 0) ||
39508 (h->interrupts_enabled == 0));
39509 }
39510
39511 @@ -3490,7 +3490,7 @@ static inline u32 next_command(ctlr_info_t *h)
39512 u32 a;
39513
39514 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
39515 - return h->access.command_completed(h);
39516 + return h->access->command_completed(h);
39517
39518 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
39519 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
39520 @@ -4047,7 +4047,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
39521 trans_support & CFGTBL_Trans_use_short_tags);
39522
39523 /* Change the access methods to the performant access methods */
39524 - h->access = SA5_performant_access;
39525 + h->access = &SA5_performant_access;
39526 h->transMethod = CFGTBL_Trans_Performant;
39527
39528 return;
39529 @@ -4321,7 +4321,7 @@ static int cciss_pci_init(ctlr_info_t *h)
39530 if (prod_index < 0)
39531 return -ENODEV;
39532 h->product_name = products[prod_index].product_name;
39533 - h->access = *(products[prod_index].access);
39534 + h->access = products[prod_index].access;
39535
39536 if (cciss_board_disabled(h)) {
39537 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
39538 @@ -5053,7 +5053,7 @@ reinit_after_soft_reset:
39539 }
39540
39541 /* make sure the board interrupts are off */
39542 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
39543 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
39544 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
39545 if (rc)
39546 goto clean2;
39547 @@ -5103,7 +5103,7 @@ reinit_after_soft_reset:
39548 * fake ones to scoop up any residual completions.
39549 */
39550 spin_lock_irqsave(&h->lock, flags);
39551 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
39552 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
39553 spin_unlock_irqrestore(&h->lock, flags);
39554 free_irq(h->intr[h->intr_mode], h);
39555 rc = cciss_request_irq(h, cciss_msix_discard_completions,
39556 @@ -5123,9 +5123,9 @@ reinit_after_soft_reset:
39557 dev_info(&h->pdev->dev, "Board READY.\n");
39558 dev_info(&h->pdev->dev,
39559 "Waiting for stale completions to drain.\n");
39560 - h->access.set_intr_mask(h, CCISS_INTR_ON);
39561 + h->access->set_intr_mask(h, CCISS_INTR_ON);
39562 msleep(10000);
39563 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
39564 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
39565
39566 rc = controller_reset_failed(h->cfgtable);
39567 if (rc)
39568 @@ -5148,7 +5148,7 @@ reinit_after_soft_reset:
39569 cciss_scsi_setup(h);
39570
39571 /* Turn the interrupts on so we can service requests */
39572 - h->access.set_intr_mask(h, CCISS_INTR_ON);
39573 + h->access->set_intr_mask(h, CCISS_INTR_ON);
39574
39575 /* Get the firmware version */
39576 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
39577 @@ -5220,7 +5220,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
39578 kfree(flush_buf);
39579 if (return_code != IO_OK)
39580 dev_warn(&h->pdev->dev, "Error flushing cache\n");
39581 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
39582 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
39583 free_irq(h->intr[h->intr_mode], h);
39584 }
39585
39586 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
39587 index 7fda30e..2f27946 100644
39588 --- a/drivers/block/cciss.h
39589 +++ b/drivers/block/cciss.h
39590 @@ -101,7 +101,7 @@ struct ctlr_info
39591 /* information about each logical volume */
39592 drive_info_struct *drv[CISS_MAX_LUN];
39593
39594 - struct access_method access;
39595 + struct access_method *access;
39596
39597 /* queue and queue Info */
39598 struct list_head reqQ;
39599 @@ -402,27 +402,27 @@ static bool SA5_performant_intr_pending(ctlr_info_t *h)
39600 }
39601
39602 static struct access_method SA5_access = {
39603 - SA5_submit_command,
39604 - SA5_intr_mask,
39605 - SA5_fifo_full,
39606 - SA5_intr_pending,
39607 - SA5_completed,
39608 + .submit_command = SA5_submit_command,
39609 + .set_intr_mask = SA5_intr_mask,
39610 + .fifo_full = SA5_fifo_full,
39611 + .intr_pending = SA5_intr_pending,
39612 + .command_completed = SA5_completed,
39613 };
39614
39615 static struct access_method SA5B_access = {
39616 - SA5_submit_command,
39617 - SA5B_intr_mask,
39618 - SA5_fifo_full,
39619 - SA5B_intr_pending,
39620 - SA5_completed,
39621 + .submit_command = SA5_submit_command,
39622 + .set_intr_mask = SA5B_intr_mask,
39623 + .fifo_full = SA5_fifo_full,
39624 + .intr_pending = SA5B_intr_pending,
39625 + .command_completed = SA5_completed,
39626 };
39627
39628 static struct access_method SA5_performant_access = {
39629 - SA5_submit_command,
39630 - SA5_performant_intr_mask,
39631 - SA5_fifo_full,
39632 - SA5_performant_intr_pending,
39633 - SA5_performant_completed,
39634 + .submit_command = SA5_submit_command,
39635 + .set_intr_mask = SA5_performant_intr_mask,
39636 + .fifo_full = SA5_fifo_full,
39637 + .intr_pending = SA5_performant_intr_pending,
39638 + .command_completed = SA5_performant_completed,
39639 };
39640
39641 struct board_type {
39642 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
39643 index 2b94403..fd6ad1f 100644
39644 --- a/drivers/block/cpqarray.c
39645 +++ b/drivers/block/cpqarray.c
39646 @@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
39647 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
39648 goto Enomem4;
39649 }
39650 - hba[i]->access.set_intr_mask(hba[i], 0);
39651 + hba[i]->access->set_intr_mask(hba[i], 0);
39652 if (request_irq(hba[i]->intr, do_ida_intr,
39653 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
39654 {
39655 @@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
39656 add_timer(&hba[i]->timer);
39657
39658 /* Enable IRQ now that spinlock and rate limit timer are set up */
39659 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
39660 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
39661
39662 for(j=0; j<NWD; j++) {
39663 struct gendisk *disk = ida_gendisk[i][j];
39664 @@ -694,7 +694,7 @@ DBGINFO(
39665 for(i=0; i<NR_PRODUCTS; i++) {
39666 if (board_id == products[i].board_id) {
39667 c->product_name = products[i].product_name;
39668 - c->access = *(products[i].access);
39669 + c->access = products[i].access;
39670 break;
39671 }
39672 }
39673 @@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
39674 hba[ctlr]->intr = intr;
39675 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
39676 hba[ctlr]->product_name = products[j].product_name;
39677 - hba[ctlr]->access = *(products[j].access);
39678 + hba[ctlr]->access = products[j].access;
39679 hba[ctlr]->ctlr = ctlr;
39680 hba[ctlr]->board_id = board_id;
39681 hba[ctlr]->pci_dev = NULL; /* not PCI */
39682 @@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
39683
39684 while((c = h->reqQ) != NULL) {
39685 /* Can't do anything if we're busy */
39686 - if (h->access.fifo_full(h) == 0)
39687 + if (h->access->fifo_full(h) == 0)
39688 return;
39689
39690 /* Get the first entry from the request Q */
39691 @@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
39692 h->Qdepth--;
39693
39694 /* Tell the controller to do our bidding */
39695 - h->access.submit_command(h, c);
39696 + h->access->submit_command(h, c);
39697
39698 /* Get onto the completion Q */
39699 addQ(&h->cmpQ, c);
39700 @@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
39701 unsigned long flags;
39702 __u32 a,a1;
39703
39704 - istat = h->access.intr_pending(h);
39705 + istat = h->access->intr_pending(h);
39706 /* Is this interrupt for us? */
39707 if (istat == 0)
39708 return IRQ_NONE;
39709 @@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
39710 */
39711 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
39712 if (istat & FIFO_NOT_EMPTY) {
39713 - while((a = h->access.command_completed(h))) {
39714 + while((a = h->access->command_completed(h))) {
39715 a1 = a; a &= ~3;
39716 if ((c = h->cmpQ) == NULL)
39717 {
39718 @@ -1448,11 +1448,11 @@ static int sendcmd(
39719 /*
39720 * Disable interrupt
39721 */
39722 - info_p->access.set_intr_mask(info_p, 0);
39723 + info_p->access->set_intr_mask(info_p, 0);
39724 /* Make sure there is room in the command FIFO */
39725 /* Actually it should be completely empty at this time. */
39726 for (i = 200000; i > 0; i--) {
39727 - temp = info_p->access.fifo_full(info_p);
39728 + temp = info_p->access->fifo_full(info_p);
39729 if (temp != 0) {
39730 break;
39731 }
39732 @@ -1465,7 +1465,7 @@ DBG(
39733 /*
39734 * Send the cmd
39735 */
39736 - info_p->access.submit_command(info_p, c);
39737 + info_p->access->submit_command(info_p, c);
39738 complete = pollcomplete(ctlr);
39739
39740 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
39741 @@ -1548,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
39742 * we check the new geometry. Then turn interrupts back on when
39743 * we're done.
39744 */
39745 - host->access.set_intr_mask(host, 0);
39746 + host->access->set_intr_mask(host, 0);
39747 getgeometry(ctlr);
39748 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
39749 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
39750
39751 for(i=0; i<NWD; i++) {
39752 struct gendisk *disk = ida_gendisk[ctlr][i];
39753 @@ -1590,7 +1590,7 @@ static int pollcomplete(int ctlr)
39754 /* Wait (up to 2 seconds) for a command to complete */
39755
39756 for (i = 200000; i > 0; i--) {
39757 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
39758 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
39759 if (done == 0) {
39760 udelay(10); /* a short fixed delay */
39761 } else
39762 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
39763 index be73e9d..7fbf140 100644
39764 --- a/drivers/block/cpqarray.h
39765 +++ b/drivers/block/cpqarray.h
39766 @@ -99,7 +99,7 @@ struct ctlr_info {
39767 drv_info_t drv[NWD];
39768 struct proc_dir_entry *proc;
39769
39770 - struct access_method access;
39771 + struct access_method *access;
39772
39773 cmdlist_t *reqQ;
39774 cmdlist_t *cmpQ;
39775 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
39776 index a76ceb3..3c1a9fd 100644
39777 --- a/drivers/block/drbd/drbd_int.h
39778 +++ b/drivers/block/drbd/drbd_int.h
39779 @@ -331,7 +331,7 @@ struct drbd_epoch {
39780 struct drbd_connection *connection;
39781 struct list_head list;
39782 unsigned int barrier_nr;
39783 - atomic_t epoch_size; /* increased on every request added. */
39784 + atomic_unchecked_t epoch_size; /* increased on every request added. */
39785 atomic_t active; /* increased on every req. added, and dec on every finished. */
39786 unsigned long flags;
39787 };
39788 @@ -797,7 +797,7 @@ struct drbd_device {
39789 unsigned int al_tr_number;
39790 int al_tr_cycle;
39791 wait_queue_head_t seq_wait;
39792 - atomic_t packet_seq;
39793 + atomic_unchecked_t packet_seq;
39794 unsigned int peer_seq;
39795 spinlock_t peer_seq_lock;
39796 unsigned int minor;
39797 @@ -1407,7 +1407,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
39798 char __user *uoptval;
39799 int err;
39800
39801 - uoptval = (char __user __force *)optval;
39802 + uoptval = (char __force_user *)optval;
39803
39804 set_fs(KERNEL_DS);
39805 if (level == SOL_SOCKET)
39806 diff --git a/drivers/block/drbd/drbd_interval.c b/drivers/block/drbd/drbd_interval.c
39807 index 89c497c..9c736ae 100644
39808 --- a/drivers/block/drbd/drbd_interval.c
39809 +++ b/drivers/block/drbd/drbd_interval.c
39810 @@ -67,9 +67,9 @@ static void augment_rotate(struct rb_node *rb_old, struct rb_node *rb_new)
39811 }
39812
39813 static const struct rb_augment_callbacks augment_callbacks = {
39814 - augment_propagate,
39815 - augment_copy,
39816 - augment_rotate,
39817 + .propagate = augment_propagate,
39818 + .copy = augment_copy,
39819 + .rotate = augment_rotate,
39820 };
39821
39822 /**
39823 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
39824 index 960645c..6c2724a 100644
39825 --- a/drivers/block/drbd/drbd_main.c
39826 +++ b/drivers/block/drbd/drbd_main.c
39827 @@ -1322,7 +1322,7 @@ static int _drbd_send_ack(struct drbd_peer_device *peer_device, enum drbd_packet
39828 p->sector = sector;
39829 p->block_id = block_id;
39830 p->blksize = blksize;
39831 - p->seq_num = cpu_to_be32(atomic_inc_return(&peer_device->device->packet_seq));
39832 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&peer_device->device->packet_seq));
39833 return drbd_send_command(peer_device, sock, cmd, sizeof(*p), NULL, 0);
39834 }
39835
39836 @@ -1628,7 +1628,7 @@ int drbd_send_dblock(struct drbd_peer_device *peer_device, struct drbd_request *
39837 return -EIO;
39838 p->sector = cpu_to_be64(req->i.sector);
39839 p->block_id = (unsigned long)req;
39840 - p->seq_num = cpu_to_be32(atomic_inc_return(&device->packet_seq));
39841 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&device->packet_seq));
39842 dp_flags = bio_flags_to_wire(peer_device->connection, req->master_bio->bi_rw);
39843 if (device->state.conn >= C_SYNC_SOURCE &&
39844 device->state.conn <= C_PAUSED_SYNC_T)
39845 @@ -2670,8 +2670,8 @@ void drbd_destroy_connection(struct kref *kref)
39846 struct drbd_connection *connection = container_of(kref, struct drbd_connection, kref);
39847 struct drbd_resource *resource = connection->resource;
39848
39849 - if (atomic_read(&connection->current_epoch->epoch_size) != 0)
39850 - drbd_err(connection, "epoch_size:%d\n", atomic_read(&connection->current_epoch->epoch_size));
39851 + if (atomic_read_unchecked(&connection->current_epoch->epoch_size) != 0)
39852 + drbd_err(connection, "epoch_size:%d\n", atomic_read_unchecked(&connection->current_epoch->epoch_size));
39853 kfree(connection->current_epoch);
39854
39855 idr_destroy(&connection->peer_devices);
39856 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
39857 index 3f2e167..d3170e4 100644
39858 --- a/drivers/block/drbd/drbd_nl.c
39859 +++ b/drivers/block/drbd/drbd_nl.c
39860 @@ -3616,7 +3616,7 @@ finish:
39861
39862 void drbd_bcast_event(struct drbd_device *device, const struct sib_info *sib)
39863 {
39864 - static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
39865 + static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
39866 struct sk_buff *msg;
39867 struct drbd_genlmsghdr *d_out;
39868 unsigned seq;
39869 @@ -3629,7 +3629,7 @@ void drbd_bcast_event(struct drbd_device *device, const struct sib_info *sib)
39870 return;
39871 }
39872
39873 - seq = atomic_inc_return(&drbd_genl_seq);
39874 + seq = atomic_inc_return_unchecked(&drbd_genl_seq);
39875 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
39876 if (!msg)
39877 goto failed;
39878 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
39879 index 5b17ec8..6c21e6b 100644
39880 --- a/drivers/block/drbd/drbd_receiver.c
39881 +++ b/drivers/block/drbd/drbd_receiver.c
39882 @@ -834,7 +834,7 @@ int drbd_connected(struct drbd_peer_device *peer_device)
39883 struct drbd_device *device = peer_device->device;
39884 int err;
39885
39886 - atomic_set(&device->packet_seq, 0);
39887 + atomic_set_unchecked(&device->packet_seq, 0);
39888 device->peer_seq = 0;
39889
39890 device->state_mutex = peer_device->connection->agreed_pro_version < 100 ?
39891 @@ -1199,7 +1199,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_connection *connectio
39892 do {
39893 next_epoch = NULL;
39894
39895 - epoch_size = atomic_read(&epoch->epoch_size);
39896 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
39897
39898 switch (ev & ~EV_CLEANUP) {
39899 case EV_PUT:
39900 @@ -1239,7 +1239,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_connection *connectio
39901 rv = FE_DESTROYED;
39902 } else {
39903 epoch->flags = 0;
39904 - atomic_set(&epoch->epoch_size, 0);
39905 + atomic_set_unchecked(&epoch->epoch_size, 0);
39906 /* atomic_set(&epoch->active, 0); is already zero */
39907 if (rv == FE_STILL_LIVE)
39908 rv = FE_RECYCLED;
39909 @@ -1490,7 +1490,7 @@ static int receive_Barrier(struct drbd_connection *connection, struct packet_inf
39910 conn_wait_active_ee_empty(connection);
39911 drbd_flush(connection);
39912
39913 - if (atomic_read(&connection->current_epoch->epoch_size)) {
39914 + if (atomic_read_unchecked(&connection->current_epoch->epoch_size)) {
39915 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
39916 if (epoch)
39917 break;
39918 @@ -1503,11 +1503,11 @@ static int receive_Barrier(struct drbd_connection *connection, struct packet_inf
39919 }
39920
39921 epoch->flags = 0;
39922 - atomic_set(&epoch->epoch_size, 0);
39923 + atomic_set_unchecked(&epoch->epoch_size, 0);
39924 atomic_set(&epoch->active, 0);
39925
39926 spin_lock(&connection->epoch_lock);
39927 - if (atomic_read(&connection->current_epoch->epoch_size)) {
39928 + if (atomic_read_unchecked(&connection->current_epoch->epoch_size)) {
39929 list_add(&epoch->list, &connection->current_epoch->list);
39930 connection->current_epoch = epoch;
39931 connection->epochs++;
39932 @@ -2224,7 +2224,7 @@ static int receive_Data(struct drbd_connection *connection, struct packet_info *
39933
39934 err = wait_for_and_update_peer_seq(peer_device, peer_seq);
39935 drbd_send_ack_dp(peer_device, P_NEG_ACK, p, pi->size);
39936 - atomic_inc(&connection->current_epoch->epoch_size);
39937 + atomic_inc_unchecked(&connection->current_epoch->epoch_size);
39938 err2 = drbd_drain_block(peer_device, pi->size);
39939 if (!err)
39940 err = err2;
39941 @@ -2266,7 +2266,7 @@ static int receive_Data(struct drbd_connection *connection, struct packet_info *
39942
39943 spin_lock(&connection->epoch_lock);
39944 peer_req->epoch = connection->current_epoch;
39945 - atomic_inc(&peer_req->epoch->epoch_size);
39946 + atomic_inc_unchecked(&peer_req->epoch->epoch_size);
39947 atomic_inc(&peer_req->epoch->active);
39948 spin_unlock(&connection->epoch_lock);
39949
39950 @@ -4461,7 +4461,7 @@ struct data_cmd {
39951 int expect_payload;
39952 size_t pkt_size;
39953 int (*fn)(struct drbd_connection *, struct packet_info *);
39954 -};
39955 +} __do_const;
39956
39957 static struct data_cmd drbd_cmd_handler[] = {
39958 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
39959 @@ -4572,7 +4572,7 @@ static void conn_disconnect(struct drbd_connection *connection)
39960 if (!list_empty(&connection->current_epoch->list))
39961 drbd_err(connection, "ASSERTION FAILED: connection->current_epoch->list not empty\n");
39962 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
39963 - atomic_set(&connection->current_epoch->epoch_size, 0);
39964 + atomic_set_unchecked(&connection->current_epoch->epoch_size, 0);
39965 connection->send.seen_any_write_yet = false;
39966
39967 drbd_info(connection, "Connection closed\n");
39968 @@ -5364,7 +5364,7 @@ static int connection_finish_peer_reqs(struct drbd_connection *connection)
39969 struct asender_cmd {
39970 size_t pkt_size;
39971 int (*fn)(struct drbd_connection *connection, struct packet_info *);
39972 -};
39973 +} __do_const;
39974
39975 static struct asender_cmd asender_tbl[] = {
39976 [P_PING] = { 0, got_Ping },
39977 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
39978 index 6cb1beb..bf490f7 100644
39979 --- a/drivers/block/loop.c
39980 +++ b/drivers/block/loop.c
39981 @@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
39982
39983 file_start_write(file);
39984 set_fs(get_ds());
39985 - bw = file->f_op->write(file, buf, len, &pos);
39986 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
39987 set_fs(old_fs);
39988 file_end_write(file);
39989 if (likely(bw == len))
39990 diff --git a/drivers/block/nvme-core.c b/drivers/block/nvme-core.c
39991 index 02351e2..a9ea617 100644
39992 --- a/drivers/block/nvme-core.c
39993 +++ b/drivers/block/nvme-core.c
39994 @@ -73,7 +73,6 @@ static LIST_HEAD(dev_list);
39995 static struct task_struct *nvme_thread;
39996 static struct workqueue_struct *nvme_workq;
39997 static wait_queue_head_t nvme_kthread_wait;
39998 -static struct notifier_block nvme_nb;
39999
40000 static void nvme_reset_failed_dev(struct work_struct *ws);
40001
40002 @@ -2925,6 +2924,10 @@ static struct pci_driver nvme_driver = {
40003 .err_handler = &nvme_err_handler,
40004 };
40005
40006 +static struct notifier_block nvme_nb = {
40007 + .notifier_call = &nvme_cpu_notify,
40008 +};
40009 +
40010 static int __init nvme_init(void)
40011 {
40012 int result;
40013 @@ -2941,7 +2944,6 @@ static int __init nvme_init(void)
40014 else if (result > 0)
40015 nvme_major = result;
40016
40017 - nvme_nb.notifier_call = &nvme_cpu_notify;
40018 result = register_hotcpu_notifier(&nvme_nb);
40019 if (result)
40020 goto unregister_blkdev;
40021 diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
40022 index 758ac44..58087fd 100644
40023 --- a/drivers/block/pktcdvd.c
40024 +++ b/drivers/block/pktcdvd.c
40025 @@ -108,7 +108,7 @@ static int pkt_seq_show(struct seq_file *m, void *p);
40026
40027 static sector_t get_zone(sector_t sector, struct pktcdvd_device *pd)
40028 {
40029 - return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1);
40030 + return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1UL);
40031 }
40032
40033 /*
40034 @@ -1888,7 +1888,7 @@ static noinline_for_stack int pkt_probe_settings(struct pktcdvd_device *pd)
40035 return -EROFS;
40036 }
40037 pd->settings.fp = ti.fp;
40038 - pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1);
40039 + pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1UL);
40040
40041 if (ti.nwa_v) {
40042 pd->nwa = be32_to_cpu(ti.next_writable);
40043 diff --git a/drivers/block/smart1,2.h b/drivers/block/smart1,2.h
40044 index e5565fb..71be10b4 100644
40045 --- a/drivers/block/smart1,2.h
40046 +++ b/drivers/block/smart1,2.h
40047 @@ -108,11 +108,11 @@ static unsigned long smart4_intr_pending(ctlr_info_t *h)
40048 }
40049
40050 static struct access_method smart4_access = {
40051 - smart4_submit_command,
40052 - smart4_intr_mask,
40053 - smart4_fifo_full,
40054 - smart4_intr_pending,
40055 - smart4_completed,
40056 + .submit_command = smart4_submit_command,
40057 + .set_intr_mask = smart4_intr_mask,
40058 + .fifo_full = smart4_fifo_full,
40059 + .intr_pending = smart4_intr_pending,
40060 + .command_completed = smart4_completed,
40061 };
40062
40063 /*
40064 @@ -144,11 +144,11 @@ static unsigned long smart2_intr_pending(ctlr_info_t *h)
40065 }
40066
40067 static struct access_method smart2_access = {
40068 - smart2_submit_command,
40069 - smart2_intr_mask,
40070 - smart2_fifo_full,
40071 - smart2_intr_pending,
40072 - smart2_completed,
40073 + .submit_command = smart2_submit_command,
40074 + .set_intr_mask = smart2_intr_mask,
40075 + .fifo_full = smart2_fifo_full,
40076 + .intr_pending = smart2_intr_pending,
40077 + .command_completed = smart2_completed,
40078 };
40079
40080 /*
40081 @@ -180,11 +180,11 @@ static unsigned long smart2e_intr_pending(ctlr_info_t *h)
40082 }
40083
40084 static struct access_method smart2e_access = {
40085 - smart2e_submit_command,
40086 - smart2e_intr_mask,
40087 - smart2e_fifo_full,
40088 - smart2e_intr_pending,
40089 - smart2e_completed,
40090 + .submit_command = smart2e_submit_command,
40091 + .set_intr_mask = smart2e_intr_mask,
40092 + .fifo_full = smart2e_fifo_full,
40093 + .intr_pending = smart2e_intr_pending,
40094 + .command_completed = smart2e_completed,
40095 };
40096
40097 /*
40098 @@ -270,9 +270,9 @@ static unsigned long smart1_intr_pending(ctlr_info_t *h)
40099 }
40100
40101 static struct access_method smart1_access = {
40102 - smart1_submit_command,
40103 - smart1_intr_mask,
40104 - smart1_fifo_full,
40105 - smart1_intr_pending,
40106 - smart1_completed,
40107 + .submit_command = smart1_submit_command,
40108 + .set_intr_mask = smart1_intr_mask,
40109 + .fifo_full = smart1_fifo_full,
40110 + .intr_pending = smart1_intr_pending,
40111 + .command_completed = smart1_completed,
40112 };
40113 diff --git a/drivers/bluetooth/btwilink.c b/drivers/bluetooth/btwilink.c
40114 index f038dba..bb74c08 100644
40115 --- a/drivers/bluetooth/btwilink.c
40116 +++ b/drivers/bluetooth/btwilink.c
40117 @@ -288,7 +288,7 @@ static int ti_st_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
40118
40119 static int bt_ti_probe(struct platform_device *pdev)
40120 {
40121 - static struct ti_st *hst;
40122 + struct ti_st *hst;
40123 struct hci_dev *hdev;
40124 int err;
40125
40126 diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
40127 index 898b84b..86f74b9 100644
40128 --- a/drivers/cdrom/cdrom.c
40129 +++ b/drivers/cdrom/cdrom.c
40130 @@ -610,7 +610,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
40131 ENSURE(reset, CDC_RESET);
40132 ENSURE(generic_packet, CDC_GENERIC_PACKET);
40133 cdi->mc_flags = 0;
40134 - cdo->n_minors = 0;
40135 cdi->options = CDO_USE_FFLAGS;
40136
40137 if (autoclose == 1 && CDROM_CAN(CDC_CLOSE_TRAY))
40138 @@ -630,8 +629,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
40139 else
40140 cdi->cdda_method = CDDA_OLD;
40141
40142 - if (!cdo->generic_packet)
40143 - cdo->generic_packet = cdrom_dummy_generic_packet;
40144 + if (!cdo->generic_packet) {
40145 + pax_open_kernel();
40146 + *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
40147 + pax_close_kernel();
40148 + }
40149
40150 cd_dbg(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
40151 mutex_lock(&cdrom_mutex);
40152 @@ -652,7 +654,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
40153 if (cdi->exit)
40154 cdi->exit(cdi);
40155
40156 - cdi->ops->n_minors--;
40157 cd_dbg(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
40158 }
40159
40160 @@ -2126,7 +2127,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
40161 */
40162 nr = nframes;
40163 do {
40164 - cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
40165 + cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
40166 if (cgc.buffer)
40167 break;
40168
40169 @@ -3434,7 +3435,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
40170 struct cdrom_device_info *cdi;
40171 int ret;
40172
40173 - ret = scnprintf(info + *pos, max_size - *pos, header);
40174 + ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
40175 if (!ret)
40176 return 1;
40177
40178 diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
40179 index 584bc31..e64a12c 100644
40180 --- a/drivers/cdrom/gdrom.c
40181 +++ b/drivers/cdrom/gdrom.c
40182 @@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
40183 .audio_ioctl = gdrom_audio_ioctl,
40184 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
40185 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
40186 - .n_minors = 1,
40187 };
40188
40189 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
40190 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
40191 index 6e9f74a..50c7cea 100644
40192 --- a/drivers/char/Kconfig
40193 +++ b/drivers/char/Kconfig
40194 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
40195
40196 config DEVKMEM
40197 bool "/dev/kmem virtual device support"
40198 - default y
40199 + default n
40200 + depends on !GRKERNSEC_KMEM
40201 help
40202 Say Y here if you want to support the /dev/kmem device. The
40203 /dev/kmem device is rarely used, but can be used for certain
40204 @@ -577,6 +578,7 @@ config DEVPORT
40205 bool
40206 depends on !M68K
40207 depends on ISA || PCI
40208 + depends on !GRKERNSEC_KMEM
40209 default y
40210
40211 source "drivers/s390/char/Kconfig"
40212 diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
40213 index a48e05b..6bac831 100644
40214 --- a/drivers/char/agp/compat_ioctl.c
40215 +++ b/drivers/char/agp/compat_ioctl.c
40216 @@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
40217 return -ENOMEM;
40218 }
40219
40220 - if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
40221 + if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
40222 sizeof(*usegment) * ureserve.seg_count)) {
40223 kfree(usegment);
40224 kfree(ksegment);
40225 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
40226 index b297033..fa217ca 100644
40227 --- a/drivers/char/agp/frontend.c
40228 +++ b/drivers/char/agp/frontend.c
40229 @@ -819,7 +819,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
40230 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
40231 return -EFAULT;
40232
40233 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
40234 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
40235 return -EFAULT;
40236
40237 client = agp_find_client_by_pid(reserve.pid);
40238 @@ -849,7 +849,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
40239 if (segment == NULL)
40240 return -ENOMEM;
40241
40242 - if (copy_from_user(segment, (void __user *) reserve.seg_list,
40243 + if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
40244 sizeof(struct agp_segment) * reserve.seg_count)) {
40245 kfree(segment);
40246 return -EFAULT;
40247 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
40248 index 4f94375..413694e 100644
40249 --- a/drivers/char/genrtc.c
40250 +++ b/drivers/char/genrtc.c
40251 @@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
40252 switch (cmd) {
40253
40254 case RTC_PLL_GET:
40255 + memset(&pll, 0, sizeof(pll));
40256 if (get_rtc_pll(&pll))
40257 return -EINVAL;
40258 else
40259 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
40260 index d5d4cd8..22d561d 100644
40261 --- a/drivers/char/hpet.c
40262 +++ b/drivers/char/hpet.c
40263 @@ -575,7 +575,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
40264 }
40265
40266 static int
40267 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
40268 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
40269 struct hpet_info *info)
40270 {
40271 struct hpet_timer __iomem *timer;
40272 diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
40273 index 86fe45c..c0ea948 100644
40274 --- a/drivers/char/hw_random/intel-rng.c
40275 +++ b/drivers/char/hw_random/intel-rng.c
40276 @@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
40277
40278 if (no_fwh_detect)
40279 return -ENODEV;
40280 - printk(warning);
40281 + printk("%s", warning);
40282 return -EBUSY;
40283 }
40284
40285 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
40286 index e6db938..835e3a2 100644
40287 --- a/drivers/char/ipmi/ipmi_msghandler.c
40288 +++ b/drivers/char/ipmi/ipmi_msghandler.c
40289 @@ -438,7 +438,7 @@ struct ipmi_smi {
40290 struct proc_dir_entry *proc_dir;
40291 char proc_dir_name[10];
40292
40293 - atomic_t stats[IPMI_NUM_STATS];
40294 + atomic_unchecked_t stats[IPMI_NUM_STATS];
40295
40296 /*
40297 * run_to_completion duplicate of smb_info, smi_info
40298 @@ -470,9 +470,9 @@ static LIST_HEAD(smi_watchers);
40299 static DEFINE_MUTEX(smi_watchers_mutex);
40300
40301 #define ipmi_inc_stat(intf, stat) \
40302 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
40303 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
40304 #define ipmi_get_stat(intf, stat) \
40305 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
40306 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
40307
40308 static int is_lan_addr(struct ipmi_addr *addr)
40309 {
40310 @@ -2926,7 +2926,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
40311 INIT_LIST_HEAD(&intf->cmd_rcvrs);
40312 init_waitqueue_head(&intf->waitq);
40313 for (i = 0; i < IPMI_NUM_STATS; i++)
40314 - atomic_set(&intf->stats[i], 0);
40315 + atomic_set_unchecked(&intf->stats[i], 0);
40316
40317 intf->proc_dir = NULL;
40318
40319 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
40320 index 5d66568..c9d93c3 100644
40321 --- a/drivers/char/ipmi/ipmi_si_intf.c
40322 +++ b/drivers/char/ipmi/ipmi_si_intf.c
40323 @@ -285,7 +285,7 @@ struct smi_info {
40324 unsigned char slave_addr;
40325
40326 /* Counters and things for the proc filesystem. */
40327 - atomic_t stats[SI_NUM_STATS];
40328 + atomic_unchecked_t stats[SI_NUM_STATS];
40329
40330 struct task_struct *thread;
40331
40332 @@ -294,9 +294,9 @@ struct smi_info {
40333 };
40334
40335 #define smi_inc_stat(smi, stat) \
40336 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
40337 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
40338 #define smi_get_stat(smi, stat) \
40339 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
40340 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
40341
40342 #define SI_MAX_PARMS 4
40343
40344 @@ -3374,7 +3374,7 @@ static int try_smi_init(struct smi_info *new_smi)
40345 atomic_set(&new_smi->req_events, 0);
40346 new_smi->run_to_completion = false;
40347 for (i = 0; i < SI_NUM_STATS; i++)
40348 - atomic_set(&new_smi->stats[i], 0);
40349 + atomic_set_unchecked(&new_smi->stats[i], 0);
40350
40351 new_smi->interrupt_disabled = true;
40352 atomic_set(&new_smi->stop_operation, 0);
40353 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
40354 index 917403f..dddd899 100644
40355 --- a/drivers/char/mem.c
40356 +++ b/drivers/char/mem.c
40357 @@ -18,6 +18,7 @@
40358 #include <linux/raw.h>
40359 #include <linux/tty.h>
40360 #include <linux/capability.h>
40361 +#include <linux/security.h>
40362 #include <linux/ptrace.h>
40363 #include <linux/device.h>
40364 #include <linux/highmem.h>
40365 @@ -36,6 +37,10 @@
40366
40367 #define DEVPORT_MINOR 4
40368
40369 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
40370 +extern const struct file_operations grsec_fops;
40371 +#endif
40372 +
40373 static inline unsigned long size_inside_page(unsigned long start,
40374 unsigned long size)
40375 {
40376 @@ -67,9 +72,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
40377
40378 while (cursor < to) {
40379 if (!devmem_is_allowed(pfn)) {
40380 +#ifdef CONFIG_GRKERNSEC_KMEM
40381 + gr_handle_mem_readwrite(from, to);
40382 +#else
40383 printk(KERN_INFO
40384 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
40385 current->comm, from, to);
40386 +#endif
40387 return 0;
40388 }
40389 cursor += PAGE_SIZE;
40390 @@ -77,6 +86,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
40391 }
40392 return 1;
40393 }
40394 +#elif defined(CONFIG_GRKERNSEC_KMEM)
40395 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
40396 +{
40397 + return 0;
40398 +}
40399 #else
40400 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
40401 {
40402 @@ -122,6 +136,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
40403
40404 while (count > 0) {
40405 unsigned long remaining;
40406 + char *temp;
40407
40408 sz = size_inside_page(p, count);
40409
40410 @@ -137,7 +152,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
40411 if (!ptr)
40412 return -EFAULT;
40413
40414 - remaining = copy_to_user(buf, ptr, sz);
40415 +#ifdef CONFIG_PAX_USERCOPY
40416 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
40417 + if (!temp) {
40418 + unxlate_dev_mem_ptr(p, ptr);
40419 + return -ENOMEM;
40420 + }
40421 + memcpy(temp, ptr, sz);
40422 +#else
40423 + temp = ptr;
40424 +#endif
40425 +
40426 + remaining = copy_to_user(buf, temp, sz);
40427 +
40428 +#ifdef CONFIG_PAX_USERCOPY
40429 + kfree(temp);
40430 +#endif
40431 +
40432 unxlate_dev_mem_ptr(p, ptr);
40433 if (remaining)
40434 return -EFAULT;
40435 @@ -369,9 +400,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
40436 size_t count, loff_t *ppos)
40437 {
40438 unsigned long p = *ppos;
40439 - ssize_t low_count, read, sz;
40440 + ssize_t low_count, read, sz, err = 0;
40441 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
40442 - int err = 0;
40443
40444 read = 0;
40445 if (p < (unsigned long) high_memory) {
40446 @@ -393,6 +423,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
40447 }
40448 #endif
40449 while (low_count > 0) {
40450 + char *temp;
40451 +
40452 sz = size_inside_page(p, low_count);
40453
40454 /*
40455 @@ -402,7 +434,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
40456 */
40457 kbuf = xlate_dev_kmem_ptr((char *)p);
40458
40459 - if (copy_to_user(buf, kbuf, sz))
40460 +#ifdef CONFIG_PAX_USERCOPY
40461 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
40462 + if (!temp)
40463 + return -ENOMEM;
40464 + memcpy(temp, kbuf, sz);
40465 +#else
40466 + temp = kbuf;
40467 +#endif
40468 +
40469 + err = copy_to_user(buf, temp, sz);
40470 +
40471 +#ifdef CONFIG_PAX_USERCOPY
40472 + kfree(temp);
40473 +#endif
40474 +
40475 + if (err)
40476 return -EFAULT;
40477 buf += sz;
40478 p += sz;
40479 @@ -827,6 +874,9 @@ static const struct memdev {
40480 #ifdef CONFIG_PRINTK
40481 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
40482 #endif
40483 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
40484 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
40485 +#endif
40486 };
40487
40488 static int memory_open(struct inode *inode, struct file *filp)
40489 @@ -898,7 +948,7 @@ static int __init chr_dev_init(void)
40490 continue;
40491
40492 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
40493 - NULL, devlist[minor].name);
40494 + NULL, "%s", devlist[minor].name);
40495 }
40496
40497 return tty_init();
40498 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
40499 index 9df78e2..01ba9ae 100644
40500 --- a/drivers/char/nvram.c
40501 +++ b/drivers/char/nvram.c
40502 @@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
40503
40504 spin_unlock_irq(&rtc_lock);
40505
40506 - if (copy_to_user(buf, contents, tmp - contents))
40507 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
40508 return -EFAULT;
40509
40510 *ppos = i;
40511 diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
40512 index 8320abd..ec48108 100644
40513 --- a/drivers/char/pcmcia/synclink_cs.c
40514 +++ b/drivers/char/pcmcia/synclink_cs.c
40515 @@ -2345,9 +2345,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
40516
40517 if (debug_level >= DEBUG_LEVEL_INFO)
40518 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
40519 - __FILE__, __LINE__, info->device_name, port->count);
40520 + __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
40521
40522 - WARN_ON(!port->count);
40523 + WARN_ON(!atomic_read(&port->count));
40524
40525 if (tty_port_close_start(port, tty, filp) == 0)
40526 goto cleanup;
40527 @@ -2365,7 +2365,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
40528 cleanup:
40529 if (debug_level >= DEBUG_LEVEL_INFO)
40530 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
40531 - tty->driver->name, port->count);
40532 + tty->driver->name, atomic_read(&port->count));
40533 }
40534
40535 /* Wait until the transmitter is empty.
40536 @@ -2507,7 +2507,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
40537
40538 if (debug_level >= DEBUG_LEVEL_INFO)
40539 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
40540 - __FILE__, __LINE__, tty->driver->name, port->count);
40541 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
40542
40543 /* If port is closing, signal caller to try again */
40544 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
40545 @@ -2527,11 +2527,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
40546 goto cleanup;
40547 }
40548 spin_lock(&port->lock);
40549 - port->count++;
40550 + atomic_inc(&port->count);
40551 spin_unlock(&port->lock);
40552 spin_unlock_irqrestore(&info->netlock, flags);
40553
40554 - if (port->count == 1) {
40555 + if (atomic_read(&port->count) == 1) {
40556 /* 1st open on this device, init hardware */
40557 retval = startup(info, tty);
40558 if (retval < 0)
40559 @@ -3920,7 +3920,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
40560 unsigned short new_crctype;
40561
40562 /* return error if TTY interface open */
40563 - if (info->port.count)
40564 + if (atomic_read(&info->port.count))
40565 return -EBUSY;
40566
40567 switch (encoding)
40568 @@ -4024,7 +4024,7 @@ static int hdlcdev_open(struct net_device *dev)
40569
40570 /* arbitrate between network and tty opens */
40571 spin_lock_irqsave(&info->netlock, flags);
40572 - if (info->port.count != 0 || info->netcount != 0) {
40573 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
40574 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
40575 spin_unlock_irqrestore(&info->netlock, flags);
40576 return -EBUSY;
40577 @@ -4114,7 +4114,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
40578 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
40579
40580 /* return error if TTY interface open */
40581 - if (info->port.count)
40582 + if (atomic_read(&info->port.count))
40583 return -EBUSY;
40584
40585 if (cmd != SIOCWANDEV)
40586 diff --git a/drivers/char/random.c b/drivers/char/random.c
40587 index 71529e1..822b036 100644
40588 --- a/drivers/char/random.c
40589 +++ b/drivers/char/random.c
40590 @@ -284,9 +284,6 @@
40591 /*
40592 * To allow fractional bits to be tracked, the entropy_count field is
40593 * denominated in units of 1/8th bits.
40594 - *
40595 - * 2*(ENTROPY_SHIFT + log2(poolbits)) must <= 31, or the multiply in
40596 - * credit_entropy_bits() needs to be 64 bits wide.
40597 */
40598 #define ENTROPY_SHIFT 3
40599 #define ENTROPY_BITS(r) ((r)->entropy_count >> ENTROPY_SHIFT)
40600 @@ -433,9 +430,9 @@ struct entropy_store {
40601 };
40602
40603 static void push_to_pool(struct work_struct *work);
40604 -static __u32 input_pool_data[INPUT_POOL_WORDS];
40605 -static __u32 blocking_pool_data[OUTPUT_POOL_WORDS];
40606 -static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS];
40607 +static __u32 input_pool_data[INPUT_POOL_WORDS] __latent_entropy;
40608 +static __u32 blocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
40609 +static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
40610
40611 static struct entropy_store input_pool = {
40612 .poolinfo = &poolinfo_table[0],
40613 @@ -524,8 +521,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
40614 input_rotate = (input_rotate + (i ? 7 : 14)) & 31;
40615 }
40616
40617 - ACCESS_ONCE(r->input_rotate) = input_rotate;
40618 - ACCESS_ONCE(r->add_ptr) = i;
40619 + ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
40620 + ACCESS_ONCE_RW(r->add_ptr) = i;
40621 smp_wmb();
40622
40623 if (out)
40624 @@ -632,7 +629,7 @@ retry:
40625 /* The +2 corresponds to the /4 in the denominator */
40626
40627 do {
40628 - unsigned int anfrac = min(pnfrac, pool_size/2);
40629 + u64 anfrac = min(pnfrac, pool_size/2);
40630 unsigned int add =
40631 ((pool_size - entropy_count)*anfrac*3) >> s;
40632
40633 @@ -1177,7 +1174,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
40634
40635 extract_buf(r, tmp);
40636 i = min_t(int, nbytes, EXTRACT_SIZE);
40637 - if (copy_to_user(buf, tmp, i)) {
40638 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
40639 ret = -EFAULT;
40640 break;
40641 }
40642 @@ -1567,7 +1564,7 @@ static char sysctl_bootid[16];
40643 static int proc_do_uuid(struct ctl_table *table, int write,
40644 void __user *buffer, size_t *lenp, loff_t *ppos)
40645 {
40646 - struct ctl_table fake_table;
40647 + ctl_table_no_const fake_table;
40648 unsigned char buf[64], tmp_uuid[16], *uuid;
40649
40650 uuid = table->data;
40651 @@ -1597,7 +1594,7 @@ static int proc_do_uuid(struct ctl_table *table, int write,
40652 static int proc_do_entropy(struct ctl_table *table, int write,
40653 void __user *buffer, size_t *lenp, loff_t *ppos)
40654 {
40655 - struct ctl_table fake_table;
40656 + ctl_table_no_const fake_table;
40657 int entropy_count;
40658
40659 entropy_count = *(int *)table->data >> ENTROPY_SHIFT;
40660 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
40661 index 7cc1fe22..b602d6b 100644
40662 --- a/drivers/char/sonypi.c
40663 +++ b/drivers/char/sonypi.c
40664 @@ -54,6 +54,7 @@
40665
40666 #include <asm/uaccess.h>
40667 #include <asm/io.h>
40668 +#include <asm/local.h>
40669
40670 #include <linux/sonypi.h>
40671
40672 @@ -490,7 +491,7 @@ static struct sonypi_device {
40673 spinlock_t fifo_lock;
40674 wait_queue_head_t fifo_proc_list;
40675 struct fasync_struct *fifo_async;
40676 - int open_count;
40677 + local_t open_count;
40678 int model;
40679 struct input_dev *input_jog_dev;
40680 struct input_dev *input_key_dev;
40681 @@ -892,7 +893,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
40682 static int sonypi_misc_release(struct inode *inode, struct file *file)
40683 {
40684 mutex_lock(&sonypi_device.lock);
40685 - sonypi_device.open_count--;
40686 + local_dec(&sonypi_device.open_count);
40687 mutex_unlock(&sonypi_device.lock);
40688 return 0;
40689 }
40690 @@ -901,9 +902,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
40691 {
40692 mutex_lock(&sonypi_device.lock);
40693 /* Flush input queue on first open */
40694 - if (!sonypi_device.open_count)
40695 + if (!local_read(&sonypi_device.open_count))
40696 kfifo_reset(&sonypi_device.fifo);
40697 - sonypi_device.open_count++;
40698 + local_inc(&sonypi_device.open_count);
40699 mutex_unlock(&sonypi_device.lock);
40700
40701 return 0;
40702 diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
40703 index 565a947..dcdc06e 100644
40704 --- a/drivers/char/tpm/tpm_acpi.c
40705 +++ b/drivers/char/tpm/tpm_acpi.c
40706 @@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
40707 virt = acpi_os_map_iomem(start, len);
40708 if (!virt) {
40709 kfree(log->bios_event_log);
40710 + log->bios_event_log = NULL;
40711 printk("%s: ERROR - Unable to map memory\n", __func__);
40712 return -EIO;
40713 }
40714
40715 - memcpy_fromio(log->bios_event_log, virt, len);
40716 + memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
40717
40718 acpi_os_unmap_iomem(virt, len);
40719 return 0;
40720 diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
40721 index 59f7cb2..bac8b6d 100644
40722 --- a/drivers/char/tpm/tpm_eventlog.c
40723 +++ b/drivers/char/tpm/tpm_eventlog.c
40724 @@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
40725 event = addr;
40726
40727 if ((event->event_type == 0 && event->event_size == 0) ||
40728 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
40729 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
40730 return NULL;
40731
40732 return addr;
40733 @@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
40734 return NULL;
40735
40736 if ((event->event_type == 0 && event->event_size == 0) ||
40737 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
40738 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
40739 return NULL;
40740
40741 (*pos)++;
40742 @@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
40743 int i;
40744
40745 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
40746 - seq_putc(m, data[i]);
40747 + if (!seq_putc(m, data[i]))
40748 + return -EFAULT;
40749
40750 return 0;
40751 }
40752 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
40753 index 60aafb8..10c08e0 100644
40754 --- a/drivers/char/virtio_console.c
40755 +++ b/drivers/char/virtio_console.c
40756 @@ -684,7 +684,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
40757 if (to_user) {
40758 ssize_t ret;
40759
40760 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
40761 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
40762 if (ret)
40763 return -EFAULT;
40764 } else {
40765 @@ -787,7 +787,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
40766 if (!port_has_data(port) && !port->host_connected)
40767 return 0;
40768
40769 - return fill_readbuf(port, ubuf, count, true);
40770 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
40771 }
40772
40773 static int wait_port_writable(struct port *port, bool nonblock)
40774 diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
40775 index 57a078e..c17cde8 100644
40776 --- a/drivers/clk/clk-composite.c
40777 +++ b/drivers/clk/clk-composite.c
40778 @@ -146,7 +146,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
40779 struct clk *clk;
40780 struct clk_init_data init;
40781 struct clk_composite *composite;
40782 - struct clk_ops *clk_composite_ops;
40783 + clk_ops_no_const *clk_composite_ops;
40784
40785 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
40786 if (!composite) {
40787 diff --git a/drivers/clk/socfpga/clk-gate.c b/drivers/clk/socfpga/clk-gate.c
40788 index dd3a78c..386d49c 100644
40789 --- a/drivers/clk/socfpga/clk-gate.c
40790 +++ b/drivers/clk/socfpga/clk-gate.c
40791 @@ -22,6 +22,7 @@
40792 #include <linux/mfd/syscon.h>
40793 #include <linux/of.h>
40794 #include <linux/regmap.h>
40795 +#include <asm/pgtable.h>
40796
40797 #include "clk.h"
40798
40799 @@ -174,7 +175,7 @@ static int socfpga_clk_prepare(struct clk_hw *hwclk)
40800 return 0;
40801 }
40802
40803 -static struct clk_ops gateclk_ops = {
40804 +static clk_ops_no_const gateclk_ops __read_only = {
40805 .prepare = socfpga_clk_prepare,
40806 .recalc_rate = socfpga_clk_recalc_rate,
40807 .get_parent = socfpga_clk_get_parent,
40808 @@ -208,8 +209,10 @@ static void __init __socfpga_gate_init(struct device_node *node,
40809 socfpga_clk->hw.reg = clk_mgr_base_addr + clk_gate[0];
40810 socfpga_clk->hw.bit_idx = clk_gate[1];
40811
40812 - gateclk_ops.enable = clk_gate_ops.enable;
40813 - gateclk_ops.disable = clk_gate_ops.disable;
40814 + pax_open_kernel();
40815 + *(void **)&gateclk_ops.enable = clk_gate_ops.enable;
40816 + *(void **)&gateclk_ops.disable = clk_gate_ops.disable;
40817 + pax_close_kernel();
40818 }
40819
40820 rc = of_property_read_u32(node, "fixed-divider", &fixed_div);
40821 diff --git a/drivers/clk/socfpga/clk-pll.c b/drivers/clk/socfpga/clk-pll.c
40822 index de6da95..c98278b 100644
40823 --- a/drivers/clk/socfpga/clk-pll.c
40824 +++ b/drivers/clk/socfpga/clk-pll.c
40825 @@ -21,6 +21,7 @@
40826 #include <linux/io.h>
40827 #include <linux/of.h>
40828 #include <linux/of_address.h>
40829 +#include <asm/pgtable.h>
40830
40831 #include "clk.h"
40832
40833 @@ -76,7 +77,7 @@ static u8 clk_pll_get_parent(struct clk_hw *hwclk)
40834 CLK_MGR_PLL_CLK_SRC_MASK;
40835 }
40836
40837 -static struct clk_ops clk_pll_ops = {
40838 +static clk_ops_no_const clk_pll_ops __read_only = {
40839 .recalc_rate = clk_pll_recalc_rate,
40840 .get_parent = clk_pll_get_parent,
40841 };
40842 @@ -120,8 +121,10 @@ static __init struct clk *__socfpga_pll_init(struct device_node *node,
40843 pll_clk->hw.hw.init = &init;
40844
40845 pll_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
40846 - clk_pll_ops.enable = clk_gate_ops.enable;
40847 - clk_pll_ops.disable = clk_gate_ops.disable;
40848 + pax_open_kernel();
40849 + *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
40850 + *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
40851 + pax_close_kernel();
40852
40853 clk = clk_register(NULL, &pll_clk->hw.hw);
40854 if (WARN_ON(IS_ERR(clk))) {
40855 diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
40856 index b0c18ed..1713a80 100644
40857 --- a/drivers/cpufreq/acpi-cpufreq.c
40858 +++ b/drivers/cpufreq/acpi-cpufreq.c
40859 @@ -675,8 +675,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
40860 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
40861 per_cpu(acfreq_data, cpu) = data;
40862
40863 - if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
40864 - acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
40865 + if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
40866 + pax_open_kernel();
40867 + *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
40868 + pax_close_kernel();
40869 + }
40870
40871 result = acpi_processor_register_performance(data->acpi_data, cpu);
40872 if (result)
40873 @@ -809,7 +812,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
40874 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
40875 break;
40876 case ACPI_ADR_SPACE_FIXED_HARDWARE:
40877 - acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
40878 + pax_open_kernel();
40879 + *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
40880 + pax_close_kernel();
40881 break;
40882 default:
40883 break;
40884 @@ -903,8 +908,10 @@ static void __init acpi_cpufreq_boost_init(void)
40885 if (!msrs)
40886 return;
40887
40888 - acpi_cpufreq_driver.boost_supported = true;
40889 - acpi_cpufreq_driver.boost_enabled = boost_state(0);
40890 + pax_open_kernel();
40891 + *(bool *)&acpi_cpufreq_driver.boost_supported = true;
40892 + *(bool *)&acpi_cpufreq_driver.boost_enabled = boost_state(0);
40893 + pax_close_kernel();
40894
40895 cpu_notifier_register_begin();
40896
40897 diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
40898 index 6f02485..13684ae 100644
40899 --- a/drivers/cpufreq/cpufreq.c
40900 +++ b/drivers/cpufreq/cpufreq.c
40901 @@ -2100,7 +2100,7 @@ void cpufreq_unregister_governor(struct cpufreq_governor *governor)
40902 }
40903
40904 mutex_lock(&cpufreq_governor_mutex);
40905 - list_del(&governor->governor_list);
40906 + pax_list_del(&governor->governor_list);
40907 mutex_unlock(&cpufreq_governor_mutex);
40908 return;
40909 }
40910 @@ -2316,7 +2316,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
40911 return NOTIFY_OK;
40912 }
40913
40914 -static struct notifier_block __refdata cpufreq_cpu_notifier = {
40915 +static struct notifier_block cpufreq_cpu_notifier = {
40916 .notifier_call = cpufreq_cpu_callback,
40917 };
40918
40919 @@ -2356,13 +2356,17 @@ int cpufreq_boost_trigger_state(int state)
40920 return 0;
40921
40922 write_lock_irqsave(&cpufreq_driver_lock, flags);
40923 - cpufreq_driver->boost_enabled = state;
40924 + pax_open_kernel();
40925 + *(bool *)&cpufreq_driver->boost_enabled = state;
40926 + pax_close_kernel();
40927 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
40928
40929 ret = cpufreq_driver->set_boost(state);
40930 if (ret) {
40931 write_lock_irqsave(&cpufreq_driver_lock, flags);
40932 - cpufreq_driver->boost_enabled = !state;
40933 + pax_open_kernel();
40934 + *(bool *)&cpufreq_driver->boost_enabled = !state;
40935 + pax_close_kernel();
40936 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
40937
40938 pr_err("%s: Cannot %s BOOST\n",
40939 @@ -2419,8 +2423,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
40940
40941 pr_debug("trying to register driver %s\n", driver_data->name);
40942
40943 - if (driver_data->setpolicy)
40944 - driver_data->flags |= CPUFREQ_CONST_LOOPS;
40945 + if (driver_data->setpolicy) {
40946 + pax_open_kernel();
40947 + *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
40948 + pax_close_kernel();
40949 + }
40950
40951 write_lock_irqsave(&cpufreq_driver_lock, flags);
40952 if (cpufreq_driver) {
40953 @@ -2435,8 +2442,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
40954 * Check if driver provides function to enable boost -
40955 * if not, use cpufreq_boost_set_sw as default
40956 */
40957 - if (!cpufreq_driver->set_boost)
40958 - cpufreq_driver->set_boost = cpufreq_boost_set_sw;
40959 + if (!cpufreq_driver->set_boost) {
40960 + pax_open_kernel();
40961 + *(void **)&cpufreq_driver->set_boost = cpufreq_boost_set_sw;
40962 + pax_close_kernel();
40963 + }
40964
40965 ret = cpufreq_sysfs_create_file(&boost.attr);
40966 if (ret) {
40967 diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
40968 index 1b44496..b80ff5e 100644
40969 --- a/drivers/cpufreq/cpufreq_governor.c
40970 +++ b/drivers/cpufreq/cpufreq_governor.c
40971 @@ -245,7 +245,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
40972 struct dbs_data *dbs_data;
40973 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
40974 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
40975 - struct od_ops *od_ops = NULL;
40976 + const struct od_ops *od_ops = NULL;
40977 struct od_dbs_tuners *od_tuners = NULL;
40978 struct cs_dbs_tuners *cs_tuners = NULL;
40979 struct cpu_dbs_common_info *cpu_cdbs;
40980 @@ -311,7 +311,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
40981
40982 if ((cdata->governor == GOV_CONSERVATIVE) &&
40983 (!policy->governor->initialized)) {
40984 - struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
40985 + const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
40986
40987 cpufreq_register_notifier(cs_ops->notifier_block,
40988 CPUFREQ_TRANSITION_NOTIFIER);
40989 @@ -331,7 +331,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
40990
40991 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
40992 (policy->governor->initialized == 1)) {
40993 - struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
40994 + const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
40995
40996 cpufreq_unregister_notifier(cs_ops->notifier_block,
40997 CPUFREQ_TRANSITION_NOTIFIER);
40998 diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
40999 index cc401d1..8197340 100644
41000 --- a/drivers/cpufreq/cpufreq_governor.h
41001 +++ b/drivers/cpufreq/cpufreq_governor.h
41002 @@ -212,7 +212,7 @@ struct common_dbs_data {
41003 void (*exit)(struct dbs_data *dbs_data);
41004
41005 /* Governor specific ops, see below */
41006 - void *gov_ops;
41007 + const void *gov_ops;
41008 };
41009
41010 /* Governor Per policy data */
41011 @@ -232,7 +232,7 @@ struct od_ops {
41012 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
41013 unsigned int freq_next, unsigned int relation);
41014 void (*freq_increase)(struct cpufreq_policy *policy, unsigned int freq);
41015 -};
41016 +} __no_const;
41017
41018 struct cs_ops {
41019 struct notifier_block *notifier_block;
41020 diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
41021 index 18d4091..434be15 100644
41022 --- a/drivers/cpufreq/cpufreq_ondemand.c
41023 +++ b/drivers/cpufreq/cpufreq_ondemand.c
41024 @@ -521,7 +521,7 @@ static void od_exit(struct dbs_data *dbs_data)
41025
41026 define_get_cpu_dbs_routines(od_cpu_dbs_info);
41027
41028 -static struct od_ops od_ops = {
41029 +static struct od_ops od_ops __read_only = {
41030 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
41031 .powersave_bias_target = generic_powersave_bias_target,
41032 .freq_increase = dbs_freq_increase,
41033 @@ -576,14 +576,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
41034 (struct cpufreq_policy *, unsigned int, unsigned int),
41035 unsigned int powersave_bias)
41036 {
41037 - od_ops.powersave_bias_target = f;
41038 + pax_open_kernel();
41039 + *(void **)&od_ops.powersave_bias_target = f;
41040 + pax_close_kernel();
41041 od_set_powersave_bias(powersave_bias);
41042 }
41043 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
41044
41045 void od_unregister_powersave_bias_handler(void)
41046 {
41047 - od_ops.powersave_bias_target = generic_powersave_bias_target;
41048 + pax_open_kernel();
41049 + *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
41050 + pax_close_kernel();
41051 od_set_powersave_bias(0);
41052 }
41053 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
41054 diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
41055 index 86631cb..c34ec78 100644
41056 --- a/drivers/cpufreq/intel_pstate.c
41057 +++ b/drivers/cpufreq/intel_pstate.c
41058 @@ -121,10 +121,10 @@ struct pstate_funcs {
41059 struct cpu_defaults {
41060 struct pstate_adjust_policy pid_policy;
41061 struct pstate_funcs funcs;
41062 -};
41063 +} __do_const;
41064
41065 static struct pstate_adjust_policy pid_params;
41066 -static struct pstate_funcs pstate_funcs;
41067 +static struct pstate_funcs *pstate_funcs;
41068
41069 struct perf_limits {
41070 int no_turbo;
41071 @@ -526,7 +526,7 @@ static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
41072
41073 cpu->pstate.current_pstate = pstate;
41074
41075 - pstate_funcs.set(cpu, pstate);
41076 + pstate_funcs->set(cpu, pstate);
41077 }
41078
41079 static inline void intel_pstate_pstate_increase(struct cpudata *cpu, int steps)
41080 @@ -546,12 +546,12 @@ static inline void intel_pstate_pstate_decrease(struct cpudata *cpu, int steps)
41081
41082 static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
41083 {
41084 - cpu->pstate.min_pstate = pstate_funcs.get_min();
41085 - cpu->pstate.max_pstate = pstate_funcs.get_max();
41086 - cpu->pstate.turbo_pstate = pstate_funcs.get_turbo();
41087 + cpu->pstate.min_pstate = pstate_funcs->get_min();
41088 + cpu->pstate.max_pstate = pstate_funcs->get_max();
41089 + cpu->pstate.turbo_pstate = pstate_funcs->get_turbo();
41090
41091 - if (pstate_funcs.get_vid)
41092 - pstate_funcs.get_vid(cpu);
41093 + if (pstate_funcs->get_vid)
41094 + pstate_funcs->get_vid(cpu);
41095 intel_pstate_set_pstate(cpu, cpu->pstate.min_pstate);
41096 }
41097
41098 @@ -838,9 +838,9 @@ static int intel_pstate_msrs_not_valid(void)
41099 rdmsrl(MSR_IA32_APERF, aperf);
41100 rdmsrl(MSR_IA32_MPERF, mperf);
41101
41102 - if (!pstate_funcs.get_max() ||
41103 - !pstate_funcs.get_min() ||
41104 - !pstate_funcs.get_turbo())
41105 + if (!pstate_funcs->get_max() ||
41106 + !pstate_funcs->get_min() ||
41107 + !pstate_funcs->get_turbo())
41108 return -ENODEV;
41109
41110 rdmsrl(MSR_IA32_APERF, tmp);
41111 @@ -854,7 +854,7 @@ static int intel_pstate_msrs_not_valid(void)
41112 return 0;
41113 }
41114
41115 -static void copy_pid_params(struct pstate_adjust_policy *policy)
41116 +static void copy_pid_params(const struct pstate_adjust_policy *policy)
41117 {
41118 pid_params.sample_rate_ms = policy->sample_rate_ms;
41119 pid_params.p_gain_pct = policy->p_gain_pct;
41120 @@ -866,11 +866,7 @@ static void copy_pid_params(struct pstate_adjust_policy *policy)
41121
41122 static void copy_cpu_funcs(struct pstate_funcs *funcs)
41123 {
41124 - pstate_funcs.get_max = funcs->get_max;
41125 - pstate_funcs.get_min = funcs->get_min;
41126 - pstate_funcs.get_turbo = funcs->get_turbo;
41127 - pstate_funcs.set = funcs->set;
41128 - pstate_funcs.get_vid = funcs->get_vid;
41129 + pstate_funcs = funcs;
41130 }
41131
41132 #if IS_ENABLED(CONFIG_ACPI)
41133 diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
41134 index 529cfd9..0e28fff 100644
41135 --- a/drivers/cpufreq/p4-clockmod.c
41136 +++ b/drivers/cpufreq/p4-clockmod.c
41137 @@ -134,10 +134,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
41138 case 0x0F: /* Core Duo */
41139 case 0x16: /* Celeron Core */
41140 case 0x1C: /* Atom */
41141 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
41142 + pax_open_kernel();
41143 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
41144 + pax_close_kernel();
41145 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
41146 case 0x0D: /* Pentium M (Dothan) */
41147 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
41148 + pax_open_kernel();
41149 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
41150 + pax_close_kernel();
41151 /* fall through */
41152 case 0x09: /* Pentium M (Banias) */
41153 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
41154 @@ -149,7 +153,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
41155
41156 /* on P-4s, the TSC runs with constant frequency independent whether
41157 * throttling is active or not. */
41158 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
41159 + pax_open_kernel();
41160 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
41161 + pax_close_kernel();
41162
41163 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
41164 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
41165 diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
41166 index 9bb42ba..b01b4a2 100644
41167 --- a/drivers/cpufreq/sparc-us3-cpufreq.c
41168 +++ b/drivers/cpufreq/sparc-us3-cpufreq.c
41169 @@ -18,14 +18,12 @@
41170 #include <asm/head.h>
41171 #include <asm/timer.h>
41172
41173 -static struct cpufreq_driver *cpufreq_us3_driver;
41174 -
41175 struct us3_freq_percpu_info {
41176 struct cpufreq_frequency_table table[4];
41177 };
41178
41179 /* Indexed by cpu number. */
41180 -static struct us3_freq_percpu_info *us3_freq_table;
41181 +static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
41182
41183 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
41184 * in the Safari config register.
41185 @@ -156,16 +154,27 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
41186
41187 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
41188 {
41189 - if (cpufreq_us3_driver)
41190 - us3_freq_target(policy, 0);
41191 + us3_freq_target(policy, 0);
41192
41193 return 0;
41194 }
41195
41196 +static int __init us3_freq_init(void);
41197 +static void __exit us3_freq_exit(void);
41198 +
41199 +static struct cpufreq_driver cpufreq_us3_driver = {
41200 + .init = us3_freq_cpu_init,
41201 + .verify = cpufreq_generic_frequency_table_verify,
41202 + .target_index = us3_freq_target,
41203 + .get = us3_freq_get,
41204 + .exit = us3_freq_cpu_exit,
41205 + .name = "UltraSPARC-III",
41206 +
41207 +};
41208 +
41209 static int __init us3_freq_init(void)
41210 {
41211 unsigned long manuf, impl, ver;
41212 - int ret;
41213
41214 if (tlb_type != cheetah && tlb_type != cheetah_plus)
41215 return -ENODEV;
41216 @@ -178,55 +187,15 @@ static int __init us3_freq_init(void)
41217 (impl == CHEETAH_IMPL ||
41218 impl == CHEETAH_PLUS_IMPL ||
41219 impl == JAGUAR_IMPL ||
41220 - impl == PANTHER_IMPL)) {
41221 - struct cpufreq_driver *driver;
41222 -
41223 - ret = -ENOMEM;
41224 - driver = kzalloc(sizeof(*driver), GFP_KERNEL);
41225 - if (!driver)
41226 - goto err_out;
41227 -
41228 - us3_freq_table = kzalloc((NR_CPUS * sizeof(*us3_freq_table)),
41229 - GFP_KERNEL);
41230 - if (!us3_freq_table)
41231 - goto err_out;
41232 -
41233 - driver->init = us3_freq_cpu_init;
41234 - driver->verify = cpufreq_generic_frequency_table_verify;
41235 - driver->target_index = us3_freq_target;
41236 - driver->get = us3_freq_get;
41237 - driver->exit = us3_freq_cpu_exit;
41238 - strcpy(driver->name, "UltraSPARC-III");
41239 -
41240 - cpufreq_us3_driver = driver;
41241 - ret = cpufreq_register_driver(driver);
41242 - if (ret)
41243 - goto err_out;
41244 -
41245 - return 0;
41246 -
41247 -err_out:
41248 - if (driver) {
41249 - kfree(driver);
41250 - cpufreq_us3_driver = NULL;
41251 - }
41252 - kfree(us3_freq_table);
41253 - us3_freq_table = NULL;
41254 - return ret;
41255 - }
41256 + impl == PANTHER_IMPL))
41257 + return cpufreq_register_driver(&cpufreq_us3_driver);
41258
41259 return -ENODEV;
41260 }
41261
41262 static void __exit us3_freq_exit(void)
41263 {
41264 - if (cpufreq_us3_driver) {
41265 - cpufreq_unregister_driver(cpufreq_us3_driver);
41266 - kfree(cpufreq_us3_driver);
41267 - cpufreq_us3_driver = NULL;
41268 - kfree(us3_freq_table);
41269 - us3_freq_table = NULL;
41270 - }
41271 + cpufreq_unregister_driver(&cpufreq_us3_driver);
41272 }
41273
41274 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
41275 diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
41276 index 7d4a315..21bb886 100644
41277 --- a/drivers/cpufreq/speedstep-centrino.c
41278 +++ b/drivers/cpufreq/speedstep-centrino.c
41279 @@ -351,8 +351,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
41280 !cpu_has(cpu, X86_FEATURE_EST))
41281 return -ENODEV;
41282
41283 - if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
41284 - centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
41285 + if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
41286 + pax_open_kernel();
41287 + *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
41288 + pax_close_kernel();
41289 + }
41290
41291 if (policy->cpu != 0)
41292 return -ENODEV;
41293 diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
41294 index 9634f20..e1499c7 100644
41295 --- a/drivers/cpuidle/driver.c
41296 +++ b/drivers/cpuidle/driver.c
41297 @@ -205,7 +205,7 @@ static int poll_idle(struct cpuidle_device *dev,
41298
41299 static void poll_idle_init(struct cpuidle_driver *drv)
41300 {
41301 - struct cpuidle_state *state = &drv->states[0];
41302 + cpuidle_state_no_const *state = &drv->states[0];
41303
41304 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
41305 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
41306 diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
41307 index ca89412..a7b9c49 100644
41308 --- a/drivers/cpuidle/governor.c
41309 +++ b/drivers/cpuidle/governor.c
41310 @@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
41311 mutex_lock(&cpuidle_lock);
41312 if (__cpuidle_find_governor(gov->name) == NULL) {
41313 ret = 0;
41314 - list_add_tail(&gov->governor_list, &cpuidle_governors);
41315 + pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
41316 if (!cpuidle_curr_governor ||
41317 cpuidle_curr_governor->rating < gov->rating)
41318 cpuidle_switch_governor(gov);
41319 diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
41320 index efe2f17..b8124f9 100644
41321 --- a/drivers/cpuidle/sysfs.c
41322 +++ b/drivers/cpuidle/sysfs.c
41323 @@ -135,7 +135,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
41324 NULL
41325 };
41326
41327 -static struct attribute_group cpuidle_attr_group = {
41328 +static attribute_group_no_const cpuidle_attr_group = {
41329 .attrs = cpuidle_default_attrs,
41330 .name = "cpuidle",
41331 };
41332 diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
41333 index 12fea3e..1e28f47 100644
41334 --- a/drivers/crypto/hifn_795x.c
41335 +++ b/drivers/crypto/hifn_795x.c
41336 @@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
41337 MODULE_PARM_DESC(hifn_pll_ref,
41338 "PLL reference clock (pci[freq] or ext[freq], default ext)");
41339
41340 -static atomic_t hifn_dev_number;
41341 +static atomic_unchecked_t hifn_dev_number;
41342
41343 #define ACRYPTO_OP_DECRYPT 0
41344 #define ACRYPTO_OP_ENCRYPT 1
41345 @@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
41346 goto err_out_disable_pci_device;
41347
41348 snprintf(name, sizeof(name), "hifn%d",
41349 - atomic_inc_return(&hifn_dev_number)-1);
41350 + atomic_inc_return_unchecked(&hifn_dev_number)-1);
41351
41352 err = pci_request_regions(pdev, name);
41353 if (err)
41354 diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
41355 index 9f90369..bfcacdb 100644
41356 --- a/drivers/devfreq/devfreq.c
41357 +++ b/drivers/devfreq/devfreq.c
41358 @@ -673,7 +673,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
41359 goto err_out;
41360 }
41361
41362 - list_add(&governor->node, &devfreq_governor_list);
41363 + pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
41364
41365 list_for_each_entry(devfreq, &devfreq_list, node) {
41366 int ret = 0;
41367 @@ -761,7 +761,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
41368 }
41369 }
41370
41371 - list_del(&governor->node);
41372 + pax_list_del((struct list_head *)&governor->node);
41373 err_out:
41374 mutex_unlock(&devfreq_list_lock);
41375
41376 diff --git a/drivers/dma/sh/shdma-base.c b/drivers/dma/sh/shdma-base.c
41377 index b35007e..55ad549 100644
41378 --- a/drivers/dma/sh/shdma-base.c
41379 +++ b/drivers/dma/sh/shdma-base.c
41380 @@ -267,8 +267,8 @@ static int shdma_alloc_chan_resources(struct dma_chan *chan)
41381 schan->slave_id = -EINVAL;
41382 }
41383
41384 - schan->desc = kcalloc(NR_DESCS_PER_CHANNEL,
41385 - sdev->desc_size, GFP_KERNEL);
41386 + schan->desc = kcalloc(sdev->desc_size,
41387 + NR_DESCS_PER_CHANNEL, GFP_KERNEL);
41388 if (!schan->desc) {
41389 ret = -ENOMEM;
41390 goto edescalloc;
41391 diff --git a/drivers/dma/sh/shdmac.c b/drivers/dma/sh/shdmac.c
41392 index 146d5df..3c14970 100644
41393 --- a/drivers/dma/sh/shdmac.c
41394 +++ b/drivers/dma/sh/shdmac.c
41395 @@ -514,7 +514,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
41396 return ret;
41397 }
41398
41399 -static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
41400 +static struct notifier_block sh_dmae_nmi_notifier = {
41401 .notifier_call = sh_dmae_nmi_handler,
41402
41403 /* Run before NMI debug handler and KGDB */
41404 diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
41405 index 592af5f..bb1d583 100644
41406 --- a/drivers/edac/edac_device.c
41407 +++ b/drivers/edac/edac_device.c
41408 @@ -477,9 +477,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
41409 */
41410 int edac_device_alloc_index(void)
41411 {
41412 - static atomic_t device_indexes = ATOMIC_INIT(0);
41413 + static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
41414
41415 - return atomic_inc_return(&device_indexes) - 1;
41416 + return atomic_inc_return_unchecked(&device_indexes) - 1;
41417 }
41418 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
41419
41420 diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
41421 index 01fae82..1dd8289 100644
41422 --- a/drivers/edac/edac_mc_sysfs.c
41423 +++ b/drivers/edac/edac_mc_sysfs.c
41424 @@ -152,7 +152,7 @@ static const char * const edac_caps[] = {
41425 struct dev_ch_attribute {
41426 struct device_attribute attr;
41427 int channel;
41428 -};
41429 +} __do_const;
41430
41431 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
41432 struct dev_ch_attribute dev_attr_legacy_##_name = \
41433 @@ -1009,14 +1009,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
41434 }
41435
41436 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
41437 + pax_open_kernel();
41438 if (mci->get_sdram_scrub_rate) {
41439 - dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
41440 - dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
41441 + *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
41442 + *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
41443 }
41444 if (mci->set_sdram_scrub_rate) {
41445 - dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
41446 - dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
41447 + *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
41448 + *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
41449 }
41450 + pax_close_kernel();
41451 err = device_create_file(&mci->dev,
41452 &dev_attr_sdram_scrub_rate);
41453 if (err) {
41454 diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
41455 index 2cf44b4d..6dd2dc7 100644
41456 --- a/drivers/edac/edac_pci.c
41457 +++ b/drivers/edac/edac_pci.c
41458 @@ -29,7 +29,7 @@
41459
41460 static DEFINE_MUTEX(edac_pci_ctls_mutex);
41461 static LIST_HEAD(edac_pci_list);
41462 -static atomic_t pci_indexes = ATOMIC_INIT(0);
41463 +static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
41464
41465 /*
41466 * edac_pci_alloc_ctl_info
41467 @@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
41468 */
41469 int edac_pci_alloc_index(void)
41470 {
41471 - return atomic_inc_return(&pci_indexes) - 1;
41472 + return atomic_inc_return_unchecked(&pci_indexes) - 1;
41473 }
41474 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
41475
41476 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
41477 index e8658e4..22746d6 100644
41478 --- a/drivers/edac/edac_pci_sysfs.c
41479 +++ b/drivers/edac/edac_pci_sysfs.c
41480 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
41481 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
41482 static int edac_pci_poll_msec = 1000; /* one second workq period */
41483
41484 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
41485 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
41486 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
41487 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
41488
41489 static struct kobject *edac_pci_top_main_kobj;
41490 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
41491 @@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
41492 void *value;
41493 ssize_t(*show) (void *, char *);
41494 ssize_t(*store) (void *, const char *, size_t);
41495 -};
41496 +} __do_const;
41497
41498 /* Set of show/store abstract level functions for PCI Parity object */
41499 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
41500 @@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
41501 edac_printk(KERN_CRIT, EDAC_PCI,
41502 "Signaled System Error on %s\n",
41503 pci_name(dev));
41504 - atomic_inc(&pci_nonparity_count);
41505 + atomic_inc_unchecked(&pci_nonparity_count);
41506 }
41507
41508 if (status & (PCI_STATUS_PARITY)) {
41509 @@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
41510 "Master Data Parity Error on %s\n",
41511 pci_name(dev));
41512
41513 - atomic_inc(&pci_parity_count);
41514 + atomic_inc_unchecked(&pci_parity_count);
41515 }
41516
41517 if (status & (PCI_STATUS_DETECTED_PARITY)) {
41518 @@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
41519 "Detected Parity Error on %s\n",
41520 pci_name(dev));
41521
41522 - atomic_inc(&pci_parity_count);
41523 + atomic_inc_unchecked(&pci_parity_count);
41524 }
41525 }
41526
41527 @@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
41528 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
41529 "Signaled System Error on %s\n",
41530 pci_name(dev));
41531 - atomic_inc(&pci_nonparity_count);
41532 + atomic_inc_unchecked(&pci_nonparity_count);
41533 }
41534
41535 if (status & (PCI_STATUS_PARITY)) {
41536 @@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
41537 "Master Data Parity Error on "
41538 "%s\n", pci_name(dev));
41539
41540 - atomic_inc(&pci_parity_count);
41541 + atomic_inc_unchecked(&pci_parity_count);
41542 }
41543
41544 if (status & (PCI_STATUS_DETECTED_PARITY)) {
41545 @@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
41546 "Detected Parity Error on %s\n",
41547 pci_name(dev));
41548
41549 - atomic_inc(&pci_parity_count);
41550 + atomic_inc_unchecked(&pci_parity_count);
41551 }
41552 }
41553 }
41554 @@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
41555 if (!check_pci_errors)
41556 return;
41557
41558 - before_count = atomic_read(&pci_parity_count);
41559 + before_count = atomic_read_unchecked(&pci_parity_count);
41560
41561 /* scan all PCI devices looking for a Parity Error on devices and
41562 * bridges.
41563 @@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
41564 /* Only if operator has selected panic on PCI Error */
41565 if (edac_pci_get_panic_on_pe()) {
41566 /* If the count is different 'after' from 'before' */
41567 - if (before_count != atomic_read(&pci_parity_count))
41568 + if (before_count != atomic_read_unchecked(&pci_parity_count))
41569 panic("EDAC: PCI Parity Error");
41570 }
41571 }
41572 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
41573 index 51b7e3a..aa8a3e8 100644
41574 --- a/drivers/edac/mce_amd.h
41575 +++ b/drivers/edac/mce_amd.h
41576 @@ -77,7 +77,7 @@ struct amd_decoder_ops {
41577 bool (*mc0_mce)(u16, u8);
41578 bool (*mc1_mce)(u16, u8);
41579 bool (*mc2_mce)(u16, u8);
41580 -};
41581 +} __no_const;
41582
41583 void amd_report_gart_errors(bool);
41584 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
41585 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
41586 index 57ea7f4..af06b76 100644
41587 --- a/drivers/firewire/core-card.c
41588 +++ b/drivers/firewire/core-card.c
41589 @@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
41590 const struct fw_card_driver *driver,
41591 struct device *device)
41592 {
41593 - static atomic_t index = ATOMIC_INIT(-1);
41594 + static atomic_unchecked_t index = ATOMIC_INIT(-1);
41595
41596 - card->index = atomic_inc_return(&index);
41597 + card->index = atomic_inc_return_unchecked(&index);
41598 card->driver = driver;
41599 card->device = device;
41600 card->current_tlabel = 0;
41601 @@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
41602
41603 void fw_core_remove_card(struct fw_card *card)
41604 {
41605 - struct fw_card_driver dummy_driver = dummy_driver_template;
41606 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
41607
41608 card->driver->update_phy_reg(card, 4,
41609 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
41610 diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
41611 index 2c6d5e1..a2cca6b 100644
41612 --- a/drivers/firewire/core-device.c
41613 +++ b/drivers/firewire/core-device.c
41614 @@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
41615 struct config_rom_attribute {
41616 struct device_attribute attr;
41617 u32 key;
41618 -};
41619 +} __do_const;
41620
41621 static ssize_t show_immediate(struct device *dev,
41622 struct device_attribute *dattr, char *buf)
41623 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
41624 index eb6935c..3cc2bfa 100644
41625 --- a/drivers/firewire/core-transaction.c
41626 +++ b/drivers/firewire/core-transaction.c
41627 @@ -38,6 +38,7 @@
41628 #include <linux/timer.h>
41629 #include <linux/types.h>
41630 #include <linux/workqueue.h>
41631 +#include <linux/sched.h>
41632
41633 #include <asm/byteorder.h>
41634
41635 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
41636 index e1480ff6..1a429bd 100644
41637 --- a/drivers/firewire/core.h
41638 +++ b/drivers/firewire/core.h
41639 @@ -111,6 +111,7 @@ struct fw_card_driver {
41640
41641 int (*stop_iso)(struct fw_iso_context *ctx);
41642 };
41643 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
41644
41645 void fw_card_initialize(struct fw_card *card,
41646 const struct fw_card_driver *driver, struct device *device);
41647 diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c
41648 index a66a321..f6caf20 100644
41649 --- a/drivers/firewire/ohci.c
41650 +++ b/drivers/firewire/ohci.c
41651 @@ -2056,10 +2056,12 @@ static void bus_reset_work(struct work_struct *work)
41652 be32_to_cpu(ohci->next_header));
41653 }
41654
41655 +#ifndef CONFIG_GRKERNSEC
41656 if (param_remote_dma) {
41657 reg_write(ohci, OHCI1394_PhyReqFilterHiSet, ~0);
41658 reg_write(ohci, OHCI1394_PhyReqFilterLoSet, ~0);
41659 }
41660 +#endif
41661
41662 spin_unlock_irq(&ohci->lock);
41663
41664 @@ -2591,8 +2593,10 @@ static int ohci_enable_phys_dma(struct fw_card *card,
41665 unsigned long flags;
41666 int n, ret = 0;
41667
41668 +#ifndef CONFIG_GRKERNSEC
41669 if (param_remote_dma)
41670 return 0;
41671 +#endif
41672
41673 /*
41674 * FIXME: Make sure this bitmask is cleared when we clear the busReset
41675 diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
41676 index 94a58a0..f5eba42 100644
41677 --- a/drivers/firmware/dmi-id.c
41678 +++ b/drivers/firmware/dmi-id.c
41679 @@ -16,7 +16,7 @@
41680 struct dmi_device_attribute{
41681 struct device_attribute dev_attr;
41682 int field;
41683 -};
41684 +} __do_const;
41685 #define to_dmi_dev_attr(_dev_attr) \
41686 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
41687
41688 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
41689 index 17afc51..0ef90cd 100644
41690 --- a/drivers/firmware/dmi_scan.c
41691 +++ b/drivers/firmware/dmi_scan.c
41692 @@ -835,7 +835,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
41693 if (buf == NULL)
41694 return -1;
41695
41696 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
41697 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
41698
41699 dmi_unmap(buf);
41700 return 0;
41701 diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c
41702 index 1491dd4..aa910db 100644
41703 --- a/drivers/firmware/efi/cper.c
41704 +++ b/drivers/firmware/efi/cper.c
41705 @@ -41,12 +41,12 @@
41706 */
41707 u64 cper_next_record_id(void)
41708 {
41709 - static atomic64_t seq;
41710 + static atomic64_unchecked_t seq;
41711
41712 - if (!atomic64_read(&seq))
41713 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
41714 + if (!atomic64_read_unchecked(&seq))
41715 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
41716
41717 - return atomic64_inc_return(&seq);
41718 + return atomic64_inc_return_unchecked(&seq);
41719 }
41720 EXPORT_SYMBOL_GPL(cper_next_record_id);
41721
41722 diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
41723 index dc79346..b39bd69 100644
41724 --- a/drivers/firmware/efi/efi.c
41725 +++ b/drivers/firmware/efi/efi.c
41726 @@ -122,14 +122,16 @@ static struct attribute_group efi_subsys_attr_group = {
41727 };
41728
41729 static struct efivars generic_efivars;
41730 -static struct efivar_operations generic_ops;
41731 +static efivar_operations_no_const generic_ops __read_only;
41732
41733 static int generic_ops_register(void)
41734 {
41735 - generic_ops.get_variable = efi.get_variable;
41736 - generic_ops.set_variable = efi.set_variable;
41737 - generic_ops.get_next_variable = efi.get_next_variable;
41738 - generic_ops.query_variable_store = efi_query_variable_store;
41739 + pax_open_kernel();
41740 + *(void **)&generic_ops.get_variable = efi.get_variable;
41741 + *(void **)&generic_ops.set_variable = efi.set_variable;
41742 + *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
41743 + *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
41744 + pax_close_kernel();
41745
41746 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
41747 }
41748 diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
41749 index 463c565..02a5640 100644
41750 --- a/drivers/firmware/efi/efivars.c
41751 +++ b/drivers/firmware/efi/efivars.c
41752 @@ -588,7 +588,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
41753 static int
41754 create_efivars_bin_attributes(void)
41755 {
41756 - struct bin_attribute *attr;
41757 + bin_attribute_no_const *attr;
41758 int error;
41759
41760 /* new_var */
41761 diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
41762 index 2f569aa..c95f4fb 100644
41763 --- a/drivers/firmware/google/memconsole.c
41764 +++ b/drivers/firmware/google/memconsole.c
41765 @@ -155,7 +155,10 @@ static int __init memconsole_init(void)
41766 if (!found_memconsole())
41767 return -ENODEV;
41768
41769 - memconsole_bin_attr.size = memconsole_length;
41770 + pax_open_kernel();
41771 + *(size_t *)&memconsole_bin_attr.size = memconsole_length;
41772 + pax_close_kernel();
41773 +
41774 return sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
41775 }
41776
41777 diff --git a/drivers/gpio/gpio-em.c b/drivers/gpio/gpio-em.c
41778 index cde3605..8b69df7 100644
41779 --- a/drivers/gpio/gpio-em.c
41780 +++ b/drivers/gpio/gpio-em.c
41781 @@ -278,7 +278,7 @@ static int em_gio_probe(struct platform_device *pdev)
41782 struct em_gio_priv *p;
41783 struct resource *io[2], *irq[2];
41784 struct gpio_chip *gpio_chip;
41785 - struct irq_chip *irq_chip;
41786 + irq_chip_no_const *irq_chip;
41787 const char *name = dev_name(&pdev->dev);
41788 int ret;
41789
41790 diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
41791 index 7030422..42a3fe9 100644
41792 --- a/drivers/gpio/gpio-ich.c
41793 +++ b/drivers/gpio/gpio-ich.c
41794 @@ -94,7 +94,7 @@ struct ichx_desc {
41795 * this option allows driver caching written output values
41796 */
41797 bool use_outlvl_cache;
41798 -};
41799 +} __do_const;
41800
41801 static struct {
41802 spinlock_t lock;
41803 diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c
41804 index b6ae89e..ac7349c 100644
41805 --- a/drivers/gpio/gpio-rcar.c
41806 +++ b/drivers/gpio/gpio-rcar.c
41807 @@ -357,7 +357,7 @@ static int gpio_rcar_probe(struct platform_device *pdev)
41808 struct gpio_rcar_priv *p;
41809 struct resource *io, *irq;
41810 struct gpio_chip *gpio_chip;
41811 - struct irq_chip *irq_chip;
41812 + irq_chip_no_const *irq_chip;
41813 struct device *dev = &pdev->dev;
41814 const char *name = dev_name(dev);
41815 int ret;
41816 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
41817 index 66cbcc1..0c5e622 100644
41818 --- a/drivers/gpio/gpio-vr41xx.c
41819 +++ b/drivers/gpio/gpio-vr41xx.c
41820 @@ -224,7 +224,7 @@ static int giu_get_irq(unsigned int irq)
41821 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
41822 maskl, pendl, maskh, pendh);
41823
41824 - atomic_inc(&irq_err_count);
41825 + atomic_inc_unchecked(&irq_err_count);
41826
41827 return -EINVAL;
41828 }
41829 diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
41830 index 2ebc907..01bdd6e 100644
41831 --- a/drivers/gpio/gpiolib.c
41832 +++ b/drivers/gpio/gpiolib.c
41833 @@ -1482,8 +1482,10 @@ static void gpiochip_irqchip_remove(struct gpio_chip *gpiochip)
41834 }
41835
41836 if (gpiochip->irqchip) {
41837 - gpiochip->irqchip->irq_request_resources = NULL;
41838 - gpiochip->irqchip->irq_release_resources = NULL;
41839 + pax_open_kernel();
41840 + *(void **)&gpiochip->irqchip->irq_request_resources = NULL;
41841 + *(void **)&gpiochip->irqchip->irq_release_resources = NULL;
41842 + pax_close_kernel();
41843 gpiochip->irqchip = NULL;
41844 }
41845 }
41846 @@ -1549,8 +1551,11 @@ int gpiochip_irqchip_add(struct gpio_chip *gpiochip,
41847 gpiochip->irqchip = NULL;
41848 return -EINVAL;
41849 }
41850 - irqchip->irq_request_resources = gpiochip_irq_reqres;
41851 - irqchip->irq_release_resources = gpiochip_irq_relres;
41852 +
41853 + pax_open_kernel();
41854 + *(void **)&irqchip->irq_request_resources = gpiochip_irq_reqres;
41855 + *(void **)&irqchip->irq_release_resources = gpiochip_irq_relres;
41856 + pax_close_kernel();
41857
41858 /*
41859 * Prepare the mapping since the irqchip shall be orthogonal to
41860 diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
41861 index fe94cc1..5e697b3 100644
41862 --- a/drivers/gpu/drm/drm_crtc.c
41863 +++ b/drivers/gpu/drm/drm_crtc.c
41864 @@ -3584,7 +3584,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
41865 goto done;
41866 }
41867
41868 - if (copy_to_user(&enum_ptr[copied].name,
41869 + if (copy_to_user(enum_ptr[copied].name,
41870 &prop_enum->name, DRM_PROP_NAME_LEN)) {
41871 ret = -EFAULT;
41872 goto done;
41873 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
41874 index 8218078..9960928a 100644
41875 --- a/drivers/gpu/drm/drm_drv.c
41876 +++ b/drivers/gpu/drm/drm_drv.c
41877 @@ -233,7 +233,7 @@ module_exit(drm_core_exit);
41878 /**
41879 * Copy and IOCTL return string to user space
41880 */
41881 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
41882 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
41883 {
41884 int len;
41885
41886 @@ -342,7 +342,7 @@ long drm_ioctl(struct file *filp,
41887 struct drm_file *file_priv = filp->private_data;
41888 struct drm_device *dev;
41889 const struct drm_ioctl_desc *ioctl = NULL;
41890 - drm_ioctl_t *func;
41891 + drm_ioctl_no_const_t func;
41892 unsigned int nr = DRM_IOCTL_NR(cmd);
41893 int retcode = -EINVAL;
41894 char stack_kdata[128];
41895 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
41896 index 021fe5d..abc9ce6 100644
41897 --- a/drivers/gpu/drm/drm_fops.c
41898 +++ b/drivers/gpu/drm/drm_fops.c
41899 @@ -88,7 +88,7 @@ int drm_open(struct inode *inode, struct file *filp)
41900 return PTR_ERR(minor);
41901
41902 dev = minor->dev;
41903 - if (!dev->open_count++)
41904 + if (local_inc_return(&dev->open_count) == 1)
41905 need_setup = 1;
41906
41907 /* share address_space across all char-devs of a single device */
41908 @@ -105,7 +105,7 @@ int drm_open(struct inode *inode, struct file *filp)
41909 return 0;
41910
41911 err_undo:
41912 - dev->open_count--;
41913 + local_dec(&dev->open_count);
41914 drm_minor_release(minor);
41915 return retcode;
41916 }
41917 @@ -427,7 +427,7 @@ int drm_release(struct inode *inode, struct file *filp)
41918
41919 mutex_lock(&drm_global_mutex);
41920
41921 - DRM_DEBUG("open_count = %d\n", dev->open_count);
41922 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
41923
41924 if (dev->driver->preclose)
41925 dev->driver->preclose(dev, file_priv);
41926 @@ -436,10 +436,10 @@ int drm_release(struct inode *inode, struct file *filp)
41927 * Begin inline drm_release
41928 */
41929
41930 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
41931 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
41932 task_pid_nr(current),
41933 (long)old_encode_dev(file_priv->minor->kdev->devt),
41934 - dev->open_count);
41935 + local_read(&dev->open_count));
41936
41937 /* Release any auth tokens that might point to this file_priv,
41938 (do that under the drm_global_mutex) */
41939 @@ -540,7 +540,7 @@ int drm_release(struct inode *inode, struct file *filp)
41940 * End inline drm_release
41941 */
41942
41943 - if (!--dev->open_count) {
41944 + if (local_dec_and_test(&dev->open_count)) {
41945 retcode = drm_lastclose(dev);
41946 if (drm_device_is_unplugged(dev))
41947 drm_put_dev(dev);
41948 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
41949 index 3d2e91c..d31c4c9 100644
41950 --- a/drivers/gpu/drm/drm_global.c
41951 +++ b/drivers/gpu/drm/drm_global.c
41952 @@ -36,7 +36,7 @@
41953 struct drm_global_item {
41954 struct mutex mutex;
41955 void *object;
41956 - int refcount;
41957 + atomic_t refcount;
41958 };
41959
41960 static struct drm_global_item glob[DRM_GLOBAL_NUM];
41961 @@ -49,7 +49,7 @@ void drm_global_init(void)
41962 struct drm_global_item *item = &glob[i];
41963 mutex_init(&item->mutex);
41964 item->object = NULL;
41965 - item->refcount = 0;
41966 + atomic_set(&item->refcount, 0);
41967 }
41968 }
41969
41970 @@ -59,7 +59,7 @@ void drm_global_release(void)
41971 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
41972 struct drm_global_item *item = &glob[i];
41973 BUG_ON(item->object != NULL);
41974 - BUG_ON(item->refcount != 0);
41975 + BUG_ON(atomic_read(&item->refcount) != 0);
41976 }
41977 }
41978
41979 @@ -69,7 +69,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
41980 struct drm_global_item *item = &glob[ref->global_type];
41981
41982 mutex_lock(&item->mutex);
41983 - if (item->refcount == 0) {
41984 + if (atomic_read(&item->refcount) == 0) {
41985 item->object = kzalloc(ref->size, GFP_KERNEL);
41986 if (unlikely(item->object == NULL)) {
41987 ret = -ENOMEM;
41988 @@ -82,7 +82,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
41989 goto out_err;
41990
41991 }
41992 - ++item->refcount;
41993 + atomic_inc(&item->refcount);
41994 ref->object = item->object;
41995 mutex_unlock(&item->mutex);
41996 return 0;
41997 @@ -98,9 +98,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
41998 struct drm_global_item *item = &glob[ref->global_type];
41999
42000 mutex_lock(&item->mutex);
42001 - BUG_ON(item->refcount == 0);
42002 + BUG_ON(atomic_read(&item->refcount) == 0);
42003 BUG_ON(ref->object != item->object);
42004 - if (--item->refcount == 0) {
42005 + if (atomic_dec_and_test(&item->refcount)) {
42006 ref->release(ref);
42007 item->object = NULL;
42008 }
42009 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
42010 index 86feedd..cba70f5 100644
42011 --- a/drivers/gpu/drm/drm_info.c
42012 +++ b/drivers/gpu/drm/drm_info.c
42013 @@ -73,10 +73,13 @@ int drm_vm_info(struct seq_file *m, void *data)
42014 struct drm_local_map *map;
42015 struct drm_map_list *r_list;
42016
42017 - /* Hardcoded from _DRM_FRAME_BUFFER,
42018 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
42019 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
42020 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
42021 + static const char * const types[] = {
42022 + [_DRM_FRAME_BUFFER] = "FB",
42023 + [_DRM_REGISTERS] = "REG",
42024 + [_DRM_SHM] = "SHM",
42025 + [_DRM_AGP] = "AGP",
42026 + [_DRM_SCATTER_GATHER] = "SG",
42027 + [_DRM_CONSISTENT] = "PCI"};
42028 const char *type;
42029 int i;
42030
42031 @@ -87,7 +90,7 @@ int drm_vm_info(struct seq_file *m, void *data)
42032 map = r_list->map;
42033 if (!map)
42034 continue;
42035 - if (map->type < 0 || map->type > 5)
42036 + if (map->type >= ARRAY_SIZE(types))
42037 type = "??";
42038 else
42039 type = types[map->type];
42040 @@ -259,7 +262,11 @@ int drm_vma_info(struct seq_file *m, void *data)
42041 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
42042 vma->vm_flags & VM_LOCKED ? 'l' : '-',
42043 vma->vm_flags & VM_IO ? 'i' : '-',
42044 +#ifdef CONFIG_GRKERNSEC_HIDESYM
42045 + 0);
42046 +#else
42047 vma->vm_pgoff);
42048 +#endif
42049
42050 #if defined(__i386__)
42051 pgprot = pgprot_val(vma->vm_page_prot);
42052 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
42053 index 2f4c4343..dd12cd2 100644
42054 --- a/drivers/gpu/drm/drm_ioc32.c
42055 +++ b/drivers/gpu/drm/drm_ioc32.c
42056 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
42057 request = compat_alloc_user_space(nbytes);
42058 if (!access_ok(VERIFY_WRITE, request, nbytes))
42059 return -EFAULT;
42060 - list = (struct drm_buf_desc *) (request + 1);
42061 + list = (struct drm_buf_desc __user *) (request + 1);
42062
42063 if (__put_user(count, &request->count)
42064 || __put_user(list, &request->list))
42065 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
42066 request = compat_alloc_user_space(nbytes);
42067 if (!access_ok(VERIFY_WRITE, request, nbytes))
42068 return -EFAULT;
42069 - list = (struct drm_buf_pub *) (request + 1);
42070 + list = (struct drm_buf_pub __user *) (request + 1);
42071
42072 if (__put_user(count, &request->count)
42073 || __put_user(list, &request->list))
42074 @@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
42075 return 0;
42076 }
42077
42078 -drm_ioctl_compat_t *drm_compat_ioctls[] = {
42079 +drm_ioctl_compat_t drm_compat_ioctls[] = {
42080 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
42081 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
42082 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
42083 @@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
42084 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
42085 {
42086 unsigned int nr = DRM_IOCTL_NR(cmd);
42087 - drm_ioctl_compat_t *fn;
42088 int ret;
42089
42090 /* Assume that ioctls without an explicit compat routine will just
42091 @@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
42092 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
42093 return drm_ioctl(filp, cmd, arg);
42094
42095 - fn = drm_compat_ioctls[nr];
42096 -
42097 - if (fn != NULL)
42098 - ret = (*fn) (filp, cmd, arg);
42099 + if (drm_compat_ioctls[nr] != NULL)
42100 + ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
42101 else
42102 ret = drm_ioctl(filp, cmd, arg);
42103
42104 diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
42105 index 14d1646..99f9d49 100644
42106 --- a/drivers/gpu/drm/drm_stub.c
42107 +++ b/drivers/gpu/drm/drm_stub.c
42108 @@ -455,7 +455,7 @@ void drm_unplug_dev(struct drm_device *dev)
42109
42110 drm_device_set_unplugged(dev);
42111
42112 - if (dev->open_count == 0) {
42113 + if (local_read(&dev->open_count) == 0) {
42114 drm_put_dev(dev);
42115 }
42116 mutex_unlock(&drm_global_mutex);
42117 diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
42118 index 369b262..09ea3ab 100644
42119 --- a/drivers/gpu/drm/drm_sysfs.c
42120 +++ b/drivers/gpu/drm/drm_sysfs.c
42121 @@ -505,7 +505,7 @@ static void drm_sysfs_release(struct device *dev)
42122 */
42123 int drm_sysfs_device_add(struct drm_minor *minor)
42124 {
42125 - char *minor_str;
42126 + const char *minor_str;
42127 int r;
42128
42129 if (minor->type == DRM_MINOR_CONTROL)
42130 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
42131 index d4d16ed..8fb0b51 100644
42132 --- a/drivers/gpu/drm/i810/i810_drv.h
42133 +++ b/drivers/gpu/drm/i810/i810_drv.h
42134 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
42135 int page_flipping;
42136
42137 wait_queue_head_t irq_queue;
42138 - atomic_t irq_received;
42139 - atomic_t irq_emitted;
42140 + atomic_unchecked_t irq_received;
42141 + atomic_unchecked_t irq_emitted;
42142
42143 int front_offset;
42144 } drm_i810_private_t;
42145 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
42146 index d443441..ab091dd 100644
42147 --- a/drivers/gpu/drm/i915/i915_dma.c
42148 +++ b/drivers/gpu/drm/i915/i915_dma.c
42149 @@ -1290,7 +1290,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
42150 * locking inversion with the driver load path. And the access here is
42151 * completely racy anyway. So don't bother with locking for now.
42152 */
42153 - return dev->open_count == 0;
42154 + return local_read(&dev->open_count) == 0;
42155 }
42156
42157 static const struct vga_switcheroo_client_ops i915_switcheroo_ops = {
42158 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
42159 index 3a30133..ef4a743 100644
42160 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
42161 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
42162 @@ -891,9 +891,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
42163
42164 static int
42165 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
42166 - int count)
42167 + unsigned int count)
42168 {
42169 - int i;
42170 + unsigned int i;
42171 unsigned relocs_total = 0;
42172 unsigned relocs_max = UINT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
42173
42174 diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
42175 index 2e0613e..a8b94d9 100644
42176 --- a/drivers/gpu/drm/i915/i915_ioc32.c
42177 +++ b/drivers/gpu/drm/i915/i915_ioc32.c
42178 @@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
42179 (unsigned long)request);
42180 }
42181
42182 -static drm_ioctl_compat_t *i915_compat_ioctls[] = {
42183 +static drm_ioctl_compat_t i915_compat_ioctls[] = {
42184 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
42185 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
42186 [DRM_I915_GETPARAM] = compat_i915_getparam,
42187 @@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
42188 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
42189 {
42190 unsigned int nr = DRM_IOCTL_NR(cmd);
42191 - drm_ioctl_compat_t *fn = NULL;
42192 int ret;
42193
42194 if (nr < DRM_COMMAND_BASE)
42195 return drm_compat_ioctl(filp, cmd, arg);
42196
42197 - if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(i915_compat_ioctls))
42198 - fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
42199 -
42200 - if (fn != NULL)
42201 + if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(i915_compat_ioctls)) {
42202 + drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
42203 ret = (*fn) (filp, cmd, arg);
42204 - else
42205 + } else
42206 ret = drm_ioctl(filp, cmd, arg);
42207
42208 return ret;
42209 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
42210 index f0be855..94e82d9 100644
42211 --- a/drivers/gpu/drm/i915/intel_display.c
42212 +++ b/drivers/gpu/drm/i915/intel_display.c
42213 @@ -11604,13 +11604,13 @@ struct intel_quirk {
42214 int subsystem_vendor;
42215 int subsystem_device;
42216 void (*hook)(struct drm_device *dev);
42217 -};
42218 +} __do_const;
42219
42220 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
42221 struct intel_dmi_quirk {
42222 void (*hook)(struct drm_device *dev);
42223 const struct dmi_system_id (*dmi_id_list)[];
42224 -};
42225 +} __do_const;
42226
42227 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
42228 {
42229 @@ -11618,18 +11618,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
42230 return 1;
42231 }
42232
42233 -static const struct intel_dmi_quirk intel_dmi_quirks[] = {
42234 +static const struct dmi_system_id intel_dmi_quirks_table[] = {
42235 {
42236 - .dmi_id_list = &(const struct dmi_system_id[]) {
42237 - {
42238 - .callback = intel_dmi_reverse_brightness,
42239 - .ident = "NCR Corporation",
42240 - .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
42241 - DMI_MATCH(DMI_PRODUCT_NAME, ""),
42242 - },
42243 - },
42244 - { } /* terminating entry */
42245 + .callback = intel_dmi_reverse_brightness,
42246 + .ident = "NCR Corporation",
42247 + .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
42248 + DMI_MATCH(DMI_PRODUCT_NAME, ""),
42249 },
42250 + },
42251 + { } /* terminating entry */
42252 +};
42253 +
42254 +static const struct intel_dmi_quirk intel_dmi_quirks[] = {
42255 + {
42256 + .dmi_id_list = &intel_dmi_quirks_table,
42257 .hook = quirk_invert_brightness,
42258 },
42259 };
42260 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
42261 index fe45321..836fdca 100644
42262 --- a/drivers/gpu/drm/mga/mga_drv.h
42263 +++ b/drivers/gpu/drm/mga/mga_drv.h
42264 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
42265 u32 clear_cmd;
42266 u32 maccess;
42267
42268 - atomic_t vbl_received; /**< Number of vblanks received. */
42269 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
42270 wait_queue_head_t fence_queue;
42271 - atomic_t last_fence_retired;
42272 + atomic_unchecked_t last_fence_retired;
42273 u32 next_fence_to_post;
42274
42275 unsigned int fb_cpp;
42276 diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
42277 index 729bfd5..ead8823 100644
42278 --- a/drivers/gpu/drm/mga/mga_ioc32.c
42279 +++ b/drivers/gpu/drm/mga/mga_ioc32.c
42280 @@ -190,7 +190,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
42281 return 0;
42282 }
42283
42284 -drm_ioctl_compat_t *mga_compat_ioctls[] = {
42285 +drm_ioctl_compat_t mga_compat_ioctls[] = {
42286 [DRM_MGA_INIT] = compat_mga_init,
42287 [DRM_MGA_GETPARAM] = compat_mga_getparam,
42288 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
42289 @@ -208,18 +208,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
42290 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
42291 {
42292 unsigned int nr = DRM_IOCTL_NR(cmd);
42293 - drm_ioctl_compat_t *fn = NULL;
42294 int ret;
42295
42296 if (nr < DRM_COMMAND_BASE)
42297 return drm_compat_ioctl(filp, cmd, arg);
42298
42299 - if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(mga_compat_ioctls))
42300 - fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
42301 -
42302 - if (fn != NULL)
42303 + if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(mga_compat_ioctls)) {
42304 + drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
42305 ret = (*fn) (filp, cmd, arg);
42306 - else
42307 + } else
42308 ret = drm_ioctl(filp, cmd, arg);
42309
42310 return ret;
42311 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
42312 index 1b071b8..de8601a 100644
42313 --- a/drivers/gpu/drm/mga/mga_irq.c
42314 +++ b/drivers/gpu/drm/mga/mga_irq.c
42315 @@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
42316 if (crtc != 0)
42317 return 0;
42318
42319 - return atomic_read(&dev_priv->vbl_received);
42320 + return atomic_read_unchecked(&dev_priv->vbl_received);
42321 }
42322
42323
42324 @@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
42325 /* VBLANK interrupt */
42326 if (status & MGA_VLINEPEN) {
42327 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
42328 - atomic_inc(&dev_priv->vbl_received);
42329 + atomic_inc_unchecked(&dev_priv->vbl_received);
42330 drm_handle_vblank(dev, 0);
42331 handled = 1;
42332 }
42333 @@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
42334 if ((prim_start & ~0x03) != (prim_end & ~0x03))
42335 MGA_WRITE(MGA_PRIMEND, prim_end);
42336
42337 - atomic_inc(&dev_priv->last_fence_retired);
42338 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
42339 wake_up(&dev_priv->fence_queue);
42340 handled = 1;
42341 }
42342 @@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
42343 * using fences.
42344 */
42345 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * HZ,
42346 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
42347 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
42348 - *sequence) <= (1 << 23)));
42349
42350 *sequence = cur_fence;
42351 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
42352 index 8268a4c..5105708 100644
42353 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
42354 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
42355 @@ -965,7 +965,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
42356 struct bit_table {
42357 const char id;
42358 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
42359 -};
42360 +} __no_const;
42361
42362 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
42363
42364 diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
42365 index 7efbafa..19f8087 100644
42366 --- a/drivers/gpu/drm/nouveau/nouveau_drm.h
42367 +++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
42368 @@ -97,7 +97,6 @@ struct nouveau_drm {
42369 struct drm_global_reference mem_global_ref;
42370 struct ttm_bo_global_ref bo_global_ref;
42371 struct ttm_bo_device bdev;
42372 - atomic_t validate_sequence;
42373 int (*move)(struct nouveau_channel *,
42374 struct ttm_buffer_object *,
42375 struct ttm_mem_reg *, struct ttm_mem_reg *);
42376 diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
42377 index 462679a..88e32a7 100644
42378 --- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
42379 +++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
42380 @@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
42381 unsigned long arg)
42382 {
42383 unsigned int nr = DRM_IOCTL_NR(cmd);
42384 - drm_ioctl_compat_t *fn = NULL;
42385 + drm_ioctl_compat_t fn = NULL;
42386 int ret;
42387
42388 if (nr < DRM_COMMAND_BASE)
42389 diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
42390 index ab0228f..20b756b 100644
42391 --- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
42392 +++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
42393 @@ -130,11 +130,11 @@ nouveau_vram_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
42394 }
42395
42396 const struct ttm_mem_type_manager_func nouveau_vram_manager = {
42397 - nouveau_vram_manager_init,
42398 - nouveau_vram_manager_fini,
42399 - nouveau_vram_manager_new,
42400 - nouveau_vram_manager_del,
42401 - nouveau_vram_manager_debug
42402 + .init = nouveau_vram_manager_init,
42403 + .takedown = nouveau_vram_manager_fini,
42404 + .get_node = nouveau_vram_manager_new,
42405 + .put_node = nouveau_vram_manager_del,
42406 + .debug = nouveau_vram_manager_debug
42407 };
42408
42409 static int
42410 @@ -199,11 +199,11 @@ nouveau_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
42411 }
42412
42413 const struct ttm_mem_type_manager_func nouveau_gart_manager = {
42414 - nouveau_gart_manager_init,
42415 - nouveau_gart_manager_fini,
42416 - nouveau_gart_manager_new,
42417 - nouveau_gart_manager_del,
42418 - nouveau_gart_manager_debug
42419 + .init = nouveau_gart_manager_init,
42420 + .takedown = nouveau_gart_manager_fini,
42421 + .get_node = nouveau_gart_manager_new,
42422 + .put_node = nouveau_gart_manager_del,
42423 + .debug = nouveau_gart_manager_debug
42424 };
42425
42426 #include <core/subdev/vm/nv04.h>
42427 @@ -271,11 +271,11 @@ nv04_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
42428 }
42429
42430 const struct ttm_mem_type_manager_func nv04_gart_manager = {
42431 - nv04_gart_manager_init,
42432 - nv04_gart_manager_fini,
42433 - nv04_gart_manager_new,
42434 - nv04_gart_manager_del,
42435 - nv04_gart_manager_debug
42436 + .init = nv04_gart_manager_init,
42437 + .takedown = nv04_gart_manager_fini,
42438 + .get_node = nv04_gart_manager_new,
42439 + .put_node = nv04_gart_manager_del,
42440 + .debug = nv04_gart_manager_debug
42441 };
42442
42443 int
42444 diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
42445 index 4f4c3fe..2cce716 100644
42446 --- a/drivers/gpu/drm/nouveau/nouveau_vga.c
42447 +++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
42448 @@ -70,7 +70,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
42449 * locking inversion with the driver load path. And the access here is
42450 * completely racy anyway. So don't bother with locking for now.
42451 */
42452 - return dev->open_count == 0;
42453 + return local_read(&dev->open_count) == 0;
42454 }
42455
42456 static const struct vga_switcheroo_client_ops
42457 diff --git a/drivers/gpu/drm/qxl/qxl_cmd.c b/drivers/gpu/drm/qxl/qxl_cmd.c
42458 index eb89653..613cf71 100644
42459 --- a/drivers/gpu/drm/qxl/qxl_cmd.c
42460 +++ b/drivers/gpu/drm/qxl/qxl_cmd.c
42461 @@ -285,27 +285,27 @@ static int wait_for_io_cmd_user(struct qxl_device *qdev, uint8_t val, long port,
42462 int ret;
42463
42464 mutex_lock(&qdev->async_io_mutex);
42465 - irq_num = atomic_read(&qdev->irq_received_io_cmd);
42466 + irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
42467 if (qdev->last_sent_io_cmd > irq_num) {
42468 if (intr)
42469 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
42470 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
42471 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
42472 else
42473 ret = wait_event_timeout(qdev->io_cmd_event,
42474 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
42475 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
42476 /* 0 is timeout, just bail the "hw" has gone away */
42477 if (ret <= 0)
42478 goto out;
42479 - irq_num = atomic_read(&qdev->irq_received_io_cmd);
42480 + irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
42481 }
42482 outb(val, addr);
42483 qdev->last_sent_io_cmd = irq_num + 1;
42484 if (intr)
42485 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
42486 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
42487 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
42488 else
42489 ret = wait_event_timeout(qdev->io_cmd_event,
42490 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
42491 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
42492 out:
42493 if (ret > 0)
42494 ret = 0;
42495 diff --git a/drivers/gpu/drm/qxl/qxl_debugfs.c b/drivers/gpu/drm/qxl/qxl_debugfs.c
42496 index c3c2bbd..bc3c0fb 100644
42497 --- a/drivers/gpu/drm/qxl/qxl_debugfs.c
42498 +++ b/drivers/gpu/drm/qxl/qxl_debugfs.c
42499 @@ -42,10 +42,10 @@ qxl_debugfs_irq_received(struct seq_file *m, void *data)
42500 struct drm_info_node *node = (struct drm_info_node *) m->private;
42501 struct qxl_device *qdev = node->minor->dev->dev_private;
42502
42503 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received));
42504 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_display));
42505 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_cursor));
42506 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_io_cmd));
42507 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received));
42508 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_display));
42509 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_cursor));
42510 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_io_cmd));
42511 seq_printf(m, "%d\n", qdev->irq_received_error);
42512 return 0;
42513 }
42514 diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h
42515 index 36ed40b..0397633 100644
42516 --- a/drivers/gpu/drm/qxl/qxl_drv.h
42517 +++ b/drivers/gpu/drm/qxl/qxl_drv.h
42518 @@ -290,10 +290,10 @@ struct qxl_device {
42519 unsigned int last_sent_io_cmd;
42520
42521 /* interrupt handling */
42522 - atomic_t irq_received;
42523 - atomic_t irq_received_display;
42524 - atomic_t irq_received_cursor;
42525 - atomic_t irq_received_io_cmd;
42526 + atomic_unchecked_t irq_received;
42527 + atomic_unchecked_t irq_received_display;
42528 + atomic_unchecked_t irq_received_cursor;
42529 + atomic_unchecked_t irq_received_io_cmd;
42530 unsigned irq_received_error;
42531 wait_queue_head_t display_event;
42532 wait_queue_head_t cursor_event;
42533 diff --git a/drivers/gpu/drm/qxl/qxl_ioctl.c b/drivers/gpu/drm/qxl/qxl_ioctl.c
42534 index b110883..dd06418 100644
42535 --- a/drivers/gpu/drm/qxl/qxl_ioctl.c
42536 +++ b/drivers/gpu/drm/qxl/qxl_ioctl.c
42537 @@ -181,7 +181,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
42538
42539 /* TODO copy slow path code from i915 */
42540 fb_cmd = qxl_bo_kmap_atomic_page(qdev, cmd_bo, (release->release_offset & PAGE_SIZE));
42541 - 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);
42542 + 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);
42543
42544 {
42545 struct qxl_drawable *draw = fb_cmd;
42546 @@ -201,7 +201,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
42547 struct drm_qxl_reloc reloc;
42548
42549 if (copy_from_user(&reloc,
42550 - &((struct drm_qxl_reloc *)(uintptr_t)cmd->relocs)[i],
42551 + &((struct drm_qxl_reloc __force_user *)(uintptr_t)cmd->relocs)[i],
42552 sizeof(reloc))) {
42553 ret = -EFAULT;
42554 goto out_free_bos;
42555 @@ -294,10 +294,10 @@ static int qxl_execbuffer_ioctl(struct drm_device *dev, void *data,
42556
42557 for (cmd_num = 0; cmd_num < execbuffer->commands_num; ++cmd_num) {
42558
42559 - struct drm_qxl_command *commands =
42560 - (struct drm_qxl_command *)(uintptr_t)execbuffer->commands;
42561 + struct drm_qxl_command __user *commands =
42562 + (struct drm_qxl_command __user *)(uintptr_t)execbuffer->commands;
42563
42564 - if (copy_from_user(&user_cmd, &commands[cmd_num],
42565 + if (copy_from_user(&user_cmd, (struct drm_qxl_command __force_user *)&commands[cmd_num],
42566 sizeof(user_cmd)))
42567 return -EFAULT;
42568
42569 diff --git a/drivers/gpu/drm/qxl/qxl_irq.c b/drivers/gpu/drm/qxl/qxl_irq.c
42570 index 0bf1e20..42a7310 100644
42571 --- a/drivers/gpu/drm/qxl/qxl_irq.c
42572 +++ b/drivers/gpu/drm/qxl/qxl_irq.c
42573 @@ -36,19 +36,19 @@ irqreturn_t qxl_irq_handler(int irq, void *arg)
42574 if (!pending)
42575 return IRQ_NONE;
42576
42577 - atomic_inc(&qdev->irq_received);
42578 + atomic_inc_unchecked(&qdev->irq_received);
42579
42580 if (pending & QXL_INTERRUPT_DISPLAY) {
42581 - atomic_inc(&qdev->irq_received_display);
42582 + atomic_inc_unchecked(&qdev->irq_received_display);
42583 wake_up_all(&qdev->display_event);
42584 qxl_queue_garbage_collect(qdev, false);
42585 }
42586 if (pending & QXL_INTERRUPT_CURSOR) {
42587 - atomic_inc(&qdev->irq_received_cursor);
42588 + atomic_inc_unchecked(&qdev->irq_received_cursor);
42589 wake_up_all(&qdev->cursor_event);
42590 }
42591 if (pending & QXL_INTERRUPT_IO_CMD) {
42592 - atomic_inc(&qdev->irq_received_io_cmd);
42593 + atomic_inc_unchecked(&qdev->irq_received_io_cmd);
42594 wake_up_all(&qdev->io_cmd_event);
42595 }
42596 if (pending & QXL_INTERRUPT_ERROR) {
42597 @@ -85,10 +85,10 @@ int qxl_irq_init(struct qxl_device *qdev)
42598 init_waitqueue_head(&qdev->io_cmd_event);
42599 INIT_WORK(&qdev->client_monitors_config_work,
42600 qxl_client_monitors_config_work_func);
42601 - atomic_set(&qdev->irq_received, 0);
42602 - atomic_set(&qdev->irq_received_display, 0);
42603 - atomic_set(&qdev->irq_received_cursor, 0);
42604 - atomic_set(&qdev->irq_received_io_cmd, 0);
42605 + atomic_set_unchecked(&qdev->irq_received, 0);
42606 + atomic_set_unchecked(&qdev->irq_received_display, 0);
42607 + atomic_set_unchecked(&qdev->irq_received_cursor, 0);
42608 + atomic_set_unchecked(&qdev->irq_received_io_cmd, 0);
42609 qdev->irq_received_error = 0;
42610 ret = drm_irq_install(qdev->ddev, qdev->ddev->pdev->irq);
42611 qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
42612 diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
42613 index 71a1bae..cb1f103 100644
42614 --- a/drivers/gpu/drm/qxl/qxl_ttm.c
42615 +++ b/drivers/gpu/drm/qxl/qxl_ttm.c
42616 @@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
42617 }
42618 }
42619
42620 -static struct vm_operations_struct qxl_ttm_vm_ops;
42621 +static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
42622 static const struct vm_operations_struct *ttm_vm_ops;
42623
42624 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
42625 @@ -145,8 +145,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
42626 return r;
42627 if (unlikely(ttm_vm_ops == NULL)) {
42628 ttm_vm_ops = vma->vm_ops;
42629 + pax_open_kernel();
42630 qxl_ttm_vm_ops = *ttm_vm_ops;
42631 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
42632 + pax_close_kernel();
42633 }
42634 vma->vm_ops = &qxl_ttm_vm_ops;
42635 return 0;
42636 @@ -555,25 +557,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
42637 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
42638 {
42639 #if defined(CONFIG_DEBUG_FS)
42640 - static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
42641 - static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
42642 - unsigned i;
42643 + static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
42644 + {
42645 + .name = "qxl_mem_mm",
42646 + .show = &qxl_mm_dump_table,
42647 + },
42648 + {
42649 + .name = "qxl_surf_mm",
42650 + .show = &qxl_mm_dump_table,
42651 + }
42652 + };
42653
42654 - for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
42655 - if (i == 0)
42656 - sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
42657 - else
42658 - sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
42659 - qxl_mem_types_list[i].name = qxl_mem_types_names[i];
42660 - qxl_mem_types_list[i].show = &qxl_mm_dump_table;
42661 - qxl_mem_types_list[i].driver_features = 0;
42662 - if (i == 0)
42663 - qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
42664 - else
42665 - qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
42666 + pax_open_kernel();
42667 + *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
42668 + *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
42669 + pax_close_kernel();
42670
42671 - }
42672 - return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
42673 + return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
42674 #else
42675 return 0;
42676 #endif
42677 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
42678 index 59459fe..be26b31 100644
42679 --- a/drivers/gpu/drm/r128/r128_cce.c
42680 +++ b/drivers/gpu/drm/r128/r128_cce.c
42681 @@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
42682
42683 /* GH: Simple idle check.
42684 */
42685 - atomic_set(&dev_priv->idle_count, 0);
42686 + atomic_set_unchecked(&dev_priv->idle_count, 0);
42687
42688 /* We don't support anything other than bus-mastering ring mode,
42689 * but the ring can be in either AGP or PCI space for the ring
42690 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
42691 index 5bf3f5f..7000661 100644
42692 --- a/drivers/gpu/drm/r128/r128_drv.h
42693 +++ b/drivers/gpu/drm/r128/r128_drv.h
42694 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
42695 int is_pci;
42696 unsigned long cce_buffers_offset;
42697
42698 - atomic_t idle_count;
42699 + atomic_unchecked_t idle_count;
42700
42701 int page_flipping;
42702 int current_page;
42703 u32 crtc_offset;
42704 u32 crtc_offset_cntl;
42705
42706 - atomic_t vbl_received;
42707 + atomic_unchecked_t vbl_received;
42708
42709 u32 color_fmt;
42710 unsigned int front_offset;
42711 diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
42712 index 663f38c..c689495 100644
42713 --- a/drivers/gpu/drm/r128/r128_ioc32.c
42714 +++ b/drivers/gpu/drm/r128/r128_ioc32.c
42715 @@ -178,7 +178,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
42716 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
42717 }
42718
42719 -drm_ioctl_compat_t *r128_compat_ioctls[] = {
42720 +drm_ioctl_compat_t r128_compat_ioctls[] = {
42721 [DRM_R128_INIT] = compat_r128_init,
42722 [DRM_R128_DEPTH] = compat_r128_depth,
42723 [DRM_R128_STIPPLE] = compat_r128_stipple,
42724 @@ -197,18 +197,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
42725 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
42726 {
42727 unsigned int nr = DRM_IOCTL_NR(cmd);
42728 - drm_ioctl_compat_t *fn = NULL;
42729 int ret;
42730
42731 if (nr < DRM_COMMAND_BASE)
42732 return drm_compat_ioctl(filp, cmd, arg);
42733
42734 - if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(r128_compat_ioctls))
42735 - fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
42736 -
42737 - if (fn != NULL)
42738 + if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(r128_compat_ioctls)) {
42739 + drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
42740 ret = (*fn) (filp, cmd, arg);
42741 - else
42742 + } else
42743 ret = drm_ioctl(filp, cmd, arg);
42744
42745 return ret;
42746 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
42747 index c2ae496..30b5993 100644
42748 --- a/drivers/gpu/drm/r128/r128_irq.c
42749 +++ b/drivers/gpu/drm/r128/r128_irq.c
42750 @@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
42751 if (crtc != 0)
42752 return 0;
42753
42754 - return atomic_read(&dev_priv->vbl_received);
42755 + return atomic_read_unchecked(&dev_priv->vbl_received);
42756 }
42757
42758 irqreturn_t r128_driver_irq_handler(int irq, void *arg)
42759 @@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(int irq, void *arg)
42760 /* VBLANK interrupt */
42761 if (status & R128_CRTC_VBLANK_INT) {
42762 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
42763 - atomic_inc(&dev_priv->vbl_received);
42764 + atomic_inc_unchecked(&dev_priv->vbl_received);
42765 drm_handle_vblank(dev, 0);
42766 return IRQ_HANDLED;
42767 }
42768 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
42769 index 575e986..66e62ca 100644
42770 --- a/drivers/gpu/drm/r128/r128_state.c
42771 +++ b/drivers/gpu/drm/r128/r128_state.c
42772 @@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
42773
42774 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
42775 {
42776 - if (atomic_read(&dev_priv->idle_count) == 0)
42777 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
42778 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
42779 else
42780 - atomic_set(&dev_priv->idle_count, 0);
42781 + atomic_set_unchecked(&dev_priv->idle_count, 0);
42782 }
42783
42784 #endif
42785 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
42786 index 4a85bb6..aaea819 100644
42787 --- a/drivers/gpu/drm/radeon/mkregtable.c
42788 +++ b/drivers/gpu/drm/radeon/mkregtable.c
42789 @@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
42790 regex_t mask_rex;
42791 regmatch_t match[4];
42792 char buf[1024];
42793 - size_t end;
42794 + long end;
42795 int len;
42796 int done = 0;
42797 int r;
42798 unsigned o;
42799 struct offset *offset;
42800 char last_reg_s[10];
42801 - int last_reg;
42802 + unsigned long last_reg;
42803
42804 if (regcomp
42805 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
42806 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
42807 index 697add2..9860f5b 100644
42808 --- a/drivers/gpu/drm/radeon/radeon_device.c
42809 +++ b/drivers/gpu/drm/radeon/radeon_device.c
42810 @@ -1169,7 +1169,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
42811 * locking inversion with the driver load path. And the access here is
42812 * completely racy anyway. So don't bother with locking for now.
42813 */
42814 - return dev->open_count == 0;
42815 + return local_read(&dev->open_count) == 0;
42816 }
42817
42818 static const struct vga_switcheroo_client_ops radeon_switcheroo_ops = {
42819 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
42820 index dafd812..1bf20c7 100644
42821 --- a/drivers/gpu/drm/radeon/radeon_drv.h
42822 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
42823 @@ -262,7 +262,7 @@ typedef struct drm_radeon_private {
42824
42825 /* SW interrupt */
42826 wait_queue_head_t swi_queue;
42827 - atomic_t swi_emitted;
42828 + atomic_unchecked_t swi_emitted;
42829 int vblank_crtc;
42830 uint32_t irq_enable_reg;
42831 uint32_t r500_disp_irq_reg;
42832 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
42833 index 0b98ea1..0881827 100644
42834 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
42835 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
42836 @@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
42837 request = compat_alloc_user_space(sizeof(*request));
42838 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
42839 || __put_user(req32.param, &request->param)
42840 - || __put_user((void __user *)(unsigned long)req32.value,
42841 + || __put_user((unsigned long)req32.value,
42842 &request->value))
42843 return -EFAULT;
42844
42845 @@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
42846 #define compat_radeon_cp_setparam NULL
42847 #endif /* X86_64 || IA64 */
42848
42849 -static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
42850 +static drm_ioctl_compat_t radeon_compat_ioctls[] = {
42851 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
42852 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
42853 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
42854 @@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
42855 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
42856 {
42857 unsigned int nr = DRM_IOCTL_NR(cmd);
42858 - drm_ioctl_compat_t *fn = NULL;
42859 int ret;
42860
42861 if (nr < DRM_COMMAND_BASE)
42862 return drm_compat_ioctl(filp, cmd, arg);
42863
42864 - if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(radeon_compat_ioctls))
42865 - fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
42866 -
42867 - if (fn != NULL)
42868 + if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(radeon_compat_ioctls)) {
42869 + drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
42870 ret = (*fn) (filp, cmd, arg);
42871 - else
42872 + } else
42873 ret = drm_ioctl(filp, cmd, arg);
42874
42875 return ret;
42876 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
42877 index 244b19b..c19226d 100644
42878 --- a/drivers/gpu/drm/radeon/radeon_irq.c
42879 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
42880 @@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
42881 unsigned int ret;
42882 RING_LOCALS;
42883
42884 - atomic_inc(&dev_priv->swi_emitted);
42885 - ret = atomic_read(&dev_priv->swi_emitted);
42886 + atomic_inc_unchecked(&dev_priv->swi_emitted);
42887 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
42888
42889 BEGIN_RING(4);
42890 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
42891 @@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
42892 drm_radeon_private_t *dev_priv =
42893 (drm_radeon_private_t *) dev->dev_private;
42894
42895 - atomic_set(&dev_priv->swi_emitted, 0);
42896 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
42897 init_waitqueue_head(&dev_priv->swi_queue);
42898
42899 dev->max_vblank_count = 0x001fffff;
42900 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
42901 index 23bb64f..69d7234 100644
42902 --- a/drivers/gpu/drm/radeon/radeon_state.c
42903 +++ b/drivers/gpu/drm/radeon/radeon_state.c
42904 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
42905 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
42906 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
42907
42908 - if (copy_from_user(&depth_boxes, clear->depth_boxes,
42909 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || copy_from_user(&depth_boxes, clear->depth_boxes,
42910 sarea_priv->nbox * sizeof(depth_boxes[0])))
42911 return -EFAULT;
42912
42913 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
42914 {
42915 drm_radeon_private_t *dev_priv = dev->dev_private;
42916 drm_radeon_getparam_t *param = data;
42917 - int value;
42918 + int value = 0;
42919
42920 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
42921
42922 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
42923 index c8a8a51..219dacc 100644
42924 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
42925 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
42926 @@ -797,7 +797,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
42927 man->size = size >> PAGE_SHIFT;
42928 }
42929
42930 -static struct vm_operations_struct radeon_ttm_vm_ops;
42931 +static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
42932 static const struct vm_operations_struct *ttm_vm_ops = NULL;
42933
42934 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
42935 @@ -838,8 +838,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
42936 }
42937 if (unlikely(ttm_vm_ops == NULL)) {
42938 ttm_vm_ops = vma->vm_ops;
42939 + pax_open_kernel();
42940 radeon_ttm_vm_ops = *ttm_vm_ops;
42941 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
42942 + pax_close_kernel();
42943 }
42944 vma->vm_ops = &radeon_ttm_vm_ops;
42945 return 0;
42946 diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
42947 index ef40381..347463e 100644
42948 --- a/drivers/gpu/drm/tegra/dc.c
42949 +++ b/drivers/gpu/drm/tegra/dc.c
42950 @@ -1173,7 +1173,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
42951 }
42952
42953 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
42954 - dc->debugfs_files[i].data = dc;
42955 + *(void **)&dc->debugfs_files[i].data = dc;
42956
42957 err = drm_debugfs_create_files(dc->debugfs_files,
42958 ARRAY_SIZE(debugfs_files),
42959 diff --git a/drivers/gpu/drm/tegra/dsi.c b/drivers/gpu/drm/tegra/dsi.c
42960 index bd56f2a..255af4b 100644
42961 --- a/drivers/gpu/drm/tegra/dsi.c
42962 +++ b/drivers/gpu/drm/tegra/dsi.c
42963 @@ -41,7 +41,7 @@ struct tegra_dsi {
42964 struct clk *clk_lp;
42965 struct clk *clk;
42966
42967 - struct drm_info_list *debugfs_files;
42968 + drm_info_list_no_const *debugfs_files;
42969 struct drm_minor *minor;
42970 struct dentry *debugfs;
42971
42972 diff --git a/drivers/gpu/drm/tegra/hdmi.c b/drivers/gpu/drm/tegra/hdmi.c
42973 index ba067bb..23afbbd 100644
42974 --- a/drivers/gpu/drm/tegra/hdmi.c
42975 +++ b/drivers/gpu/drm/tegra/hdmi.c
42976 @@ -60,7 +60,7 @@ struct tegra_hdmi {
42977 bool stereo;
42978 bool dvi;
42979
42980 - struct drm_info_list *debugfs_files;
42981 + drm_info_list_no_const *debugfs_files;
42982 struct drm_minor *minor;
42983 struct dentry *debugfs;
42984 };
42985 diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
42986 index bd850c9..d9f3573 100644
42987 --- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
42988 +++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
42989 @@ -146,10 +146,10 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
42990 }
42991
42992 const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
42993 - ttm_bo_man_init,
42994 - ttm_bo_man_takedown,
42995 - ttm_bo_man_get_node,
42996 - ttm_bo_man_put_node,
42997 - ttm_bo_man_debug
42998 + .init = ttm_bo_man_init,
42999 + .takedown = ttm_bo_man_takedown,
43000 + .get_node = ttm_bo_man_get_node,
43001 + .put_node = ttm_bo_man_put_node,
43002 + .debug = ttm_bo_man_debug
43003 };
43004 EXPORT_SYMBOL(ttm_bo_manager_func);
43005 diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
43006 index dbc2def..0a9f710 100644
43007 --- a/drivers/gpu/drm/ttm/ttm_memory.c
43008 +++ b/drivers/gpu/drm/ttm/ttm_memory.c
43009 @@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
43010 zone->glob = glob;
43011 glob->zone_kernel = zone;
43012 ret = kobject_init_and_add(
43013 - &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
43014 + &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
43015 if (unlikely(ret != 0)) {
43016 kobject_put(&zone->kobj);
43017 return ret;
43018 @@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
43019 zone->glob = glob;
43020 glob->zone_dma32 = zone;
43021 ret = kobject_init_and_add(
43022 - &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
43023 + &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
43024 if (unlikely(ret != 0)) {
43025 kobject_put(&zone->kobj);
43026 return ret;
43027 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
43028 index 863bef9..cba15cf 100644
43029 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
43030 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
43031 @@ -391,9 +391,9 @@ out:
43032 static unsigned long
43033 ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
43034 {
43035 - static atomic_t start_pool = ATOMIC_INIT(0);
43036 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
43037 unsigned i;
43038 - unsigned pool_offset = atomic_add_return(1, &start_pool);
43039 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
43040 struct ttm_page_pool *pool;
43041 int shrink_pages = sc->nr_to_scan;
43042 unsigned long freed = 0;
43043 diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
43044 index 3771763..883f206 100644
43045 --- a/drivers/gpu/drm/udl/udl_fb.c
43046 +++ b/drivers/gpu/drm/udl/udl_fb.c
43047 @@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
43048 fb_deferred_io_cleanup(info);
43049 kfree(info->fbdefio);
43050 info->fbdefio = NULL;
43051 - info->fbops->fb_mmap = udl_fb_mmap;
43052 }
43053
43054 pr_warn("released /dev/fb%d user=%d count=%d\n",
43055 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
43056 index ad02732..144f5ed 100644
43057 --- a/drivers/gpu/drm/via/via_drv.h
43058 +++ b/drivers/gpu/drm/via/via_drv.h
43059 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
43060 typedef uint32_t maskarray_t[5];
43061
43062 typedef struct drm_via_irq {
43063 - atomic_t irq_received;
43064 + atomic_unchecked_t irq_received;
43065 uint32_t pending_mask;
43066 uint32_t enable_mask;
43067 wait_queue_head_t irq_queue;
43068 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
43069 struct timeval last_vblank;
43070 int last_vblank_valid;
43071 unsigned usec_per_vblank;
43072 - atomic_t vbl_received;
43073 + atomic_unchecked_t vbl_received;
43074 drm_via_state_t hc_state;
43075 char pci_buf[VIA_PCI_BUF_SIZE];
43076 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
43077 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
43078 index 1319433..a993b0c 100644
43079 --- a/drivers/gpu/drm/via/via_irq.c
43080 +++ b/drivers/gpu/drm/via/via_irq.c
43081 @@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
43082 if (crtc != 0)
43083 return 0;
43084
43085 - return atomic_read(&dev_priv->vbl_received);
43086 + return atomic_read_unchecked(&dev_priv->vbl_received);
43087 }
43088
43089 irqreturn_t via_driver_irq_handler(int irq, void *arg)
43090 @@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
43091
43092 status = VIA_READ(VIA_REG_INTERRUPT);
43093 if (status & VIA_IRQ_VBLANK_PENDING) {
43094 - atomic_inc(&dev_priv->vbl_received);
43095 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
43096 + atomic_inc_unchecked(&dev_priv->vbl_received);
43097 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
43098 do_gettimeofday(&cur_vblank);
43099 if (dev_priv->last_vblank_valid) {
43100 dev_priv->usec_per_vblank =
43101 @@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
43102 dev_priv->last_vblank = cur_vblank;
43103 dev_priv->last_vblank_valid = 1;
43104 }
43105 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
43106 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
43107 DRM_DEBUG("US per vblank is: %u\n",
43108 dev_priv->usec_per_vblank);
43109 }
43110 @@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
43111
43112 for (i = 0; i < dev_priv->num_irqs; ++i) {
43113 if (status & cur_irq->pending_mask) {
43114 - atomic_inc(&cur_irq->irq_received);
43115 + atomic_inc_unchecked(&cur_irq->irq_received);
43116 wake_up(&cur_irq->irq_queue);
43117 handled = 1;
43118 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
43119 @@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
43120 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
43121 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
43122 masks[irq][4]));
43123 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
43124 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
43125 } else {
43126 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
43127 (((cur_irq_sequence =
43128 - atomic_read(&cur_irq->irq_received)) -
43129 + atomic_read_unchecked(&cur_irq->irq_received)) -
43130 *sequence) <= (1 << 23)));
43131 }
43132 *sequence = cur_irq_sequence;
43133 @@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
43134 }
43135
43136 for (i = 0; i < dev_priv->num_irqs; ++i) {
43137 - atomic_set(&cur_irq->irq_received, 0);
43138 + atomic_set_unchecked(&cur_irq->irq_received, 0);
43139 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
43140 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
43141 init_waitqueue_head(&cur_irq->irq_queue);
43142 @@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
43143 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
43144 case VIA_IRQ_RELATIVE:
43145 irqwait->request.sequence +=
43146 - atomic_read(&cur_irq->irq_received);
43147 + atomic_read_unchecked(&cur_irq->irq_received);
43148 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
43149 case VIA_IRQ_ABSOLUTE:
43150 break;
43151 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
43152 index 6b252a8..5975dfe 100644
43153 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
43154 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
43155 @@ -437,7 +437,7 @@ struct vmw_private {
43156 * Fencing and IRQs.
43157 */
43158
43159 - atomic_t marker_seq;
43160 + atomic_unchecked_t marker_seq;
43161 wait_queue_head_t fence_queue;
43162 wait_queue_head_t fifo_queue;
43163 int fence_queue_waiters; /* Protected by hw_mutex */
43164 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
43165 index 6ccd993..618d592 100644
43166 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
43167 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
43168 @@ -154,7 +154,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
43169 (unsigned int) min,
43170 (unsigned int) fifo->capabilities);
43171
43172 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
43173 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
43174 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
43175 vmw_marker_queue_init(&fifo->marker_queue);
43176 return vmw_fifo_send_fence(dev_priv, &dummy);
43177 @@ -372,7 +372,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
43178 if (reserveable)
43179 iowrite32(bytes, fifo_mem +
43180 SVGA_FIFO_RESERVED);
43181 - return fifo_mem + (next_cmd >> 2);
43182 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
43183 } else {
43184 need_bounce = true;
43185 }
43186 @@ -492,7 +492,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
43187
43188 fm = vmw_fifo_reserve(dev_priv, bytes);
43189 if (unlikely(fm == NULL)) {
43190 - *seqno = atomic_read(&dev_priv->marker_seq);
43191 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
43192 ret = -ENOMEM;
43193 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
43194 false, 3*HZ);
43195 @@ -500,7 +500,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
43196 }
43197
43198 do {
43199 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
43200 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
43201 } while (*seqno == 0);
43202
43203 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
43204 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
43205 index b1273e8..9c274fd 100644
43206 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
43207 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
43208 @@ -164,9 +164,9 @@ static void vmw_gmrid_man_debug(struct ttm_mem_type_manager *man,
43209 }
43210
43211 const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
43212 - vmw_gmrid_man_init,
43213 - vmw_gmrid_man_takedown,
43214 - vmw_gmrid_man_get_node,
43215 - vmw_gmrid_man_put_node,
43216 - vmw_gmrid_man_debug
43217 + .init = vmw_gmrid_man_init,
43218 + .takedown = vmw_gmrid_man_takedown,
43219 + .get_node = vmw_gmrid_man_get_node,
43220 + .put_node = vmw_gmrid_man_put_node,
43221 + .debug = vmw_gmrid_man_debug
43222 };
43223 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
43224 index 37881ec..319065d 100644
43225 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
43226 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
43227 @@ -235,7 +235,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
43228 int ret;
43229
43230 num_clips = arg->num_clips;
43231 - clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
43232 + clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
43233
43234 if (unlikely(num_clips == 0))
43235 return 0;
43236 @@ -318,7 +318,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
43237 int ret;
43238
43239 num_clips = arg->num_clips;
43240 - clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
43241 + clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
43242
43243 if (unlikely(num_clips == 0))
43244 return 0;
43245 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
43246 index 0c42376..6febe77 100644
43247 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
43248 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
43249 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
43250 * emitted. Then the fence is stale and signaled.
43251 */
43252
43253 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
43254 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
43255 > VMW_FENCE_WRAP);
43256
43257 return ret;
43258 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
43259
43260 if (fifo_idle)
43261 down_read(&fifo_state->rwsem);
43262 - signal_seq = atomic_read(&dev_priv->marker_seq);
43263 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
43264 ret = 0;
43265
43266 for (;;) {
43267 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
43268 index 8a8725c2..afed796 100644
43269 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
43270 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
43271 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
43272 while (!vmw_lag_lt(queue, us)) {
43273 spin_lock(&queue->lock);
43274 if (list_empty(&queue->head))
43275 - seqno = atomic_read(&dev_priv->marker_seq);
43276 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
43277 else {
43278 marker = list_first_entry(&queue->head,
43279 struct vmw_marker, head);
43280 diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
43281 index 6866448..2ad2b34 100644
43282 --- a/drivers/gpu/vga/vga_switcheroo.c
43283 +++ b/drivers/gpu/vga/vga_switcheroo.c
43284 @@ -644,7 +644,7 @@ static int vga_switcheroo_runtime_resume(struct device *dev)
43285
43286 /* this version is for the case where the power switch is separate
43287 to the device being powered down. */
43288 -int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain)
43289 +int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain)
43290 {
43291 /* copy over all the bus versions */
43292 if (dev->bus && dev->bus->pm) {
43293 @@ -689,7 +689,7 @@ static int vga_switcheroo_runtime_resume_hdmi_audio(struct device *dev)
43294 return ret;
43295 }
43296
43297 -int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain)
43298 +int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain)
43299 {
43300 /* copy over all the bus versions */
43301 if (dev->bus && dev->bus->pm) {
43302 diff --git a/drivers/hid/hid-cherry.c b/drivers/hid/hid-cherry.c
43303 index 1bdcccc..f745d2c 100644
43304 --- a/drivers/hid/hid-cherry.c
43305 +++ b/drivers/hid/hid-cherry.c
43306 @@ -28,7 +28,7 @@
43307 static __u8 *ch_report_fixup(struct hid_device *hdev, __u8 *rdesc,
43308 unsigned int *rsize)
43309 {
43310 - if (*rsize >= 17 && rdesc[11] == 0x3c && rdesc[12] == 0x02) {
43311 + if (*rsize >= 18 && rdesc[11] == 0x3c && rdesc[12] == 0x02) {
43312 hid_info(hdev, "fixing up Cherry Cymotion report descriptor\n");
43313 rdesc[11] = rdesc[16] = 0xff;
43314 rdesc[12] = rdesc[17] = 0x03;
43315 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
43316 index 8ed66fd..38ff772 100644
43317 --- a/drivers/hid/hid-core.c
43318 +++ b/drivers/hid/hid-core.c
43319 @@ -2488,7 +2488,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
43320
43321 int hid_add_device(struct hid_device *hdev)
43322 {
43323 - static atomic_t id = ATOMIC_INIT(0);
43324 + static atomic_unchecked_t id = ATOMIC_INIT(0);
43325 int ret;
43326
43327 if (WARN_ON(hdev->status & HID_STAT_ADDED))
43328 @@ -2530,7 +2530,7 @@ int hid_add_device(struct hid_device *hdev)
43329 /* XXX hack, any other cleaner solution after the driver core
43330 * is converted to allow more than 20 bytes as the device name? */
43331 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
43332 - hdev->vendor, hdev->product, atomic_inc_return(&id));
43333 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
43334
43335 hid_debug_register(hdev, dev_name(&hdev->dev));
43336 ret = device_add(&hdev->dev);
43337 diff --git a/drivers/hid/hid-kye.c b/drivers/hid/hid-kye.c
43338 index e776963..b92bf01 100644
43339 --- a/drivers/hid/hid-kye.c
43340 +++ b/drivers/hid/hid-kye.c
43341 @@ -300,7 +300,7 @@ static __u8 *kye_report_fixup(struct hid_device *hdev, __u8 *rdesc,
43342 * - change the button usage range to 4-7 for the extra
43343 * buttons
43344 */
43345 - if (*rsize >= 74 &&
43346 + if (*rsize >= 75 &&
43347 rdesc[61] == 0x05 && rdesc[62] == 0x08 &&
43348 rdesc[63] == 0x19 && rdesc[64] == 0x08 &&
43349 rdesc[65] == 0x29 && rdesc[66] == 0x0f &&
43350 diff --git a/drivers/hid/hid-lg.c b/drivers/hid/hid-lg.c
43351 index a976f48..f91ff14 100644
43352 --- a/drivers/hid/hid-lg.c
43353 +++ b/drivers/hid/hid-lg.c
43354 @@ -345,14 +345,14 @@ static __u8 *lg_report_fixup(struct hid_device *hdev, __u8 *rdesc,
43355 struct usb_device_descriptor *udesc;
43356 __u16 bcdDevice, rev_maj, rev_min;
43357
43358 - if ((drv_data->quirks & LG_RDESC) && *rsize >= 90 && rdesc[83] == 0x26 &&
43359 + if ((drv_data->quirks & LG_RDESC) && *rsize >= 91 && rdesc[83] == 0x26 &&
43360 rdesc[84] == 0x8c && rdesc[85] == 0x02) {
43361 hid_info(hdev,
43362 "fixing up Logitech keyboard report descriptor\n");
43363 rdesc[84] = rdesc[89] = 0x4d;
43364 rdesc[85] = rdesc[90] = 0x10;
43365 }
43366 - if ((drv_data->quirks & LG_RDESC_REL_ABS) && *rsize >= 50 &&
43367 + if ((drv_data->quirks & LG_RDESC_REL_ABS) && *rsize >= 51 &&
43368 rdesc[32] == 0x81 && rdesc[33] == 0x06 &&
43369 rdesc[49] == 0x81 && rdesc[50] == 0x06) {
43370 hid_info(hdev,
43371 diff --git a/drivers/hid/hid-logitech-dj.c b/drivers/hid/hid-logitech-dj.c
43372 index 486dbde..b7ba829 100644
43373 --- a/drivers/hid/hid-logitech-dj.c
43374 +++ b/drivers/hid/hid-logitech-dj.c
43375 @@ -238,13 +238,6 @@ static void logi_dj_recv_add_djhid_device(struct dj_receiver_dev *djrcv_dev,
43376 return;
43377 }
43378
43379 - if ((dj_report->device_index < DJ_DEVICE_INDEX_MIN) ||
43380 - (dj_report->device_index > DJ_DEVICE_INDEX_MAX)) {
43381 - dev_err(&djrcv_hdev->dev, "%s: invalid device index:%d\n",
43382 - __func__, dj_report->device_index);
43383 - return;
43384 - }
43385 -
43386 if (djrcv_dev->paired_dj_devices[dj_report->device_index]) {
43387 /* The device is already known. No need to reallocate it. */
43388 dbg_hid("%s: device is already known\n", __func__);
43389 @@ -557,7 +550,7 @@ static int logi_dj_ll_raw_request(struct hid_device *hid,
43390 if (!out_buf)
43391 return -ENOMEM;
43392
43393 - if (count < DJREPORT_SHORT_LENGTH - 2)
43394 + if (count > DJREPORT_SHORT_LENGTH - 2)
43395 count = DJREPORT_SHORT_LENGTH - 2;
43396
43397 out_buf[0] = REPORT_ID_DJ_SHORT;
43398 @@ -690,6 +683,12 @@ static int logi_dj_raw_event(struct hid_device *hdev,
43399 * device (via hid_input_report() ) and return 1 so hid-core does not do
43400 * anything else with it.
43401 */
43402 + if ((dj_report->device_index < DJ_DEVICE_INDEX_MIN) ||
43403 + (dj_report->device_index > DJ_DEVICE_INDEX_MAX)) {
43404 + dev_err(&hdev->dev, "%s: invalid device index:%d\n",
43405 + __func__, dj_report->device_index);
43406 + return false;
43407 + }
43408
43409 spin_lock_irqsave(&djrcv_dev->lock, flags);
43410 if (dj_report->report_id == REPORT_ID_DJ_SHORT) {
43411 diff --git a/drivers/hid/hid-magicmouse.c b/drivers/hid/hid-magicmouse.c
43412 index ecc2cbf..29a74c1 100644
43413 --- a/drivers/hid/hid-magicmouse.c
43414 +++ b/drivers/hid/hid-magicmouse.c
43415 @@ -290,6 +290,11 @@ static int magicmouse_raw_event(struct hid_device *hdev,
43416 if (size < 4 || ((size - 4) % 9) != 0)
43417 return 0;
43418 npoints = (size - 4) / 9;
43419 + if (npoints > 15) {
43420 + hid_warn(hdev, "invalid size value (%d) for TRACKPAD_REPORT_ID\n",
43421 + size);
43422 + return 0;
43423 + }
43424 msc->ntouches = 0;
43425 for (ii = 0; ii < npoints; ii++)
43426 magicmouse_emit_touch(msc, ii, data + ii * 9 + 4);
43427 @@ -307,6 +312,11 @@ static int magicmouse_raw_event(struct hid_device *hdev,
43428 if (size < 6 || ((size - 6) % 8) != 0)
43429 return 0;
43430 npoints = (size - 6) / 8;
43431 + if (npoints > 15) {
43432 + hid_warn(hdev, "invalid size value (%d) for MOUSE_REPORT_ID\n",
43433 + size);
43434 + return 0;
43435 + }
43436 msc->ntouches = 0;
43437 for (ii = 0; ii < npoints; ii++)
43438 magicmouse_emit_touch(msc, ii, data + ii * 8 + 6);
43439 diff --git a/drivers/hid/hid-monterey.c b/drivers/hid/hid-monterey.c
43440 index 9e14c00..25daf28 100644
43441 --- a/drivers/hid/hid-monterey.c
43442 +++ b/drivers/hid/hid-monterey.c
43443 @@ -24,7 +24,7 @@
43444 static __u8 *mr_report_fixup(struct hid_device *hdev, __u8 *rdesc,
43445 unsigned int *rsize)
43446 {
43447 - if (*rsize >= 30 && rdesc[29] == 0x05 && rdesc[30] == 0x09) {
43448 + if (*rsize >= 31 && rdesc[29] == 0x05 && rdesc[30] == 0x09) {
43449 hid_info(hdev, "fixing up button/consumer in HID report descriptor\n");
43450 rdesc[30] = 0x0c;
43451 }
43452 diff --git a/drivers/hid/hid-petalynx.c b/drivers/hid/hid-petalynx.c
43453 index 736b250..6aca4f2 100644
43454 --- a/drivers/hid/hid-petalynx.c
43455 +++ b/drivers/hid/hid-petalynx.c
43456 @@ -25,7 +25,7 @@
43457 static __u8 *pl_report_fixup(struct hid_device *hdev, __u8 *rdesc,
43458 unsigned int *rsize)
43459 {
43460 - if (*rsize >= 60 && rdesc[39] == 0x2a && rdesc[40] == 0xf5 &&
43461 + if (*rsize >= 62 && rdesc[39] == 0x2a && rdesc[40] == 0xf5 &&
43462 rdesc[41] == 0x00 && rdesc[59] == 0x26 &&
43463 rdesc[60] == 0xf9 && rdesc[61] == 0x00) {
43464 hid_info(hdev, "fixing up Petalynx Maxter Remote report descriptor\n");
43465 diff --git a/drivers/hid/hid-picolcd_core.c b/drivers/hid/hid-picolcd_core.c
43466 index acbb0210..020df3c 100644
43467 --- a/drivers/hid/hid-picolcd_core.c
43468 +++ b/drivers/hid/hid-picolcd_core.c
43469 @@ -350,6 +350,12 @@ static int picolcd_raw_event(struct hid_device *hdev,
43470 if (!data)
43471 return 1;
43472
43473 + if (size > 64) {
43474 + hid_warn(hdev, "invalid size value (%d) for picolcd raw event\n",
43475 + size);
43476 + return 0;
43477 + }
43478 +
43479 if (report->id == REPORT_KEY_STATE) {
43480 if (data->input_keys)
43481 ret = picolcd_raw_keypad(data, report, raw_data+1, size-1);
43482 diff --git a/drivers/hid/hid-sunplus.c b/drivers/hid/hid-sunplus.c
43483 index 87fc91e..91072fa 100644
43484 --- a/drivers/hid/hid-sunplus.c
43485 +++ b/drivers/hid/hid-sunplus.c
43486 @@ -24,7 +24,7 @@
43487 static __u8 *sp_report_fixup(struct hid_device *hdev, __u8 *rdesc,
43488 unsigned int *rsize)
43489 {
43490 - if (*rsize >= 107 && rdesc[104] == 0x26 && rdesc[105] == 0x80 &&
43491 + if (*rsize >= 112 && rdesc[104] == 0x26 && rdesc[105] == 0x80 &&
43492 rdesc[106] == 0x03) {
43493 hid_info(hdev, "fixing up Sunplus Wireless Desktop report descriptor\n");
43494 rdesc[105] = rdesc[110] = 0x03;
43495 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
43496 index c13fb5b..55a3802 100644
43497 --- a/drivers/hid/hid-wiimote-debug.c
43498 +++ b/drivers/hid/hid-wiimote-debug.c
43499 @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
43500 else if (size == 0)
43501 return -EIO;
43502
43503 - if (copy_to_user(u, buf, size))
43504 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
43505 return -EFAULT;
43506
43507 *off += size;
43508 diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
43509 index 0cb92e3..c7d453d 100644
43510 --- a/drivers/hid/uhid.c
43511 +++ b/drivers/hid/uhid.c
43512 @@ -47,7 +47,7 @@ struct uhid_device {
43513 struct mutex report_lock;
43514 wait_queue_head_t report_wait;
43515 atomic_t report_done;
43516 - atomic_t report_id;
43517 + atomic_unchecked_t report_id;
43518 struct uhid_event report_buf;
43519 };
43520
43521 @@ -163,7 +163,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum,
43522
43523 spin_lock_irqsave(&uhid->qlock, flags);
43524 ev->type = UHID_FEATURE;
43525 - ev->u.feature.id = atomic_inc_return(&uhid->report_id);
43526 + ev->u.feature.id = atomic_inc_return_unchecked(&uhid->report_id);
43527 ev->u.feature.rnum = rnum;
43528 ev->u.feature.rtype = report_type;
43529
43530 @@ -538,7 +538,7 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid,
43531 spin_lock_irqsave(&uhid->qlock, flags);
43532
43533 /* id for old report; drop it silently */
43534 - if (atomic_read(&uhid->report_id) != ev->u.feature_answer.id)
43535 + if (atomic_read_unchecked(&uhid->report_id) != ev->u.feature_answer.id)
43536 goto unlock;
43537 if (atomic_read(&uhid->report_done))
43538 goto unlock;
43539 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
43540 index 284cf66..084c627 100644
43541 --- a/drivers/hv/channel.c
43542 +++ b/drivers/hv/channel.c
43543 @@ -365,8 +365,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
43544 int ret = 0;
43545 int t;
43546
43547 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
43548 - atomic_inc(&vmbus_connection.next_gpadl_handle);
43549 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
43550 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
43551
43552 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
43553 if (ret)
43554 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
43555 index edfc848..d83e195 100644
43556 --- a/drivers/hv/hv.c
43557 +++ b/drivers/hv/hv.c
43558 @@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
43559 u64 output_address = (output) ? virt_to_phys(output) : 0;
43560 u32 output_address_hi = output_address >> 32;
43561 u32 output_address_lo = output_address & 0xFFFFFFFF;
43562 - void *hypercall_page = hv_context.hypercall_page;
43563 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
43564
43565 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
43566 "=a"(hv_status_lo) : "d" (control_hi),
43567 @@ -154,7 +154,7 @@ int hv_init(void)
43568 /* See if the hypercall page is already set */
43569 rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
43570
43571 - virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_EXEC);
43572 + virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_RX);
43573
43574 if (!virtaddr)
43575 goto cleanup;
43576 diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
43577 index 5e90c5d..d8fcefb 100644
43578 --- a/drivers/hv/hv_balloon.c
43579 +++ b/drivers/hv/hv_balloon.c
43580 @@ -470,7 +470,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
43581
43582 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
43583 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
43584 -static atomic_t trans_id = ATOMIC_INIT(0);
43585 +static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
43586
43587 static int dm_ring_size = (5 * PAGE_SIZE);
43588
43589 @@ -893,7 +893,7 @@ static void hot_add_req(struct work_struct *dummy)
43590 pr_info("Memory hot add failed\n");
43591
43592 dm->state = DM_INITIALIZED;
43593 - resp.hdr.trans_id = atomic_inc_return(&trans_id);
43594 + resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
43595 vmbus_sendpacket(dm->dev->channel, &resp,
43596 sizeof(struct dm_hot_add_response),
43597 (unsigned long)NULL,
43598 @@ -973,7 +973,7 @@ static void post_status(struct hv_dynmem_device *dm)
43599 memset(&status, 0, sizeof(struct dm_status));
43600 status.hdr.type = DM_STATUS_REPORT;
43601 status.hdr.size = sizeof(struct dm_status);
43602 - status.hdr.trans_id = atomic_inc_return(&trans_id);
43603 + status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
43604
43605 /*
43606 * The host expects the guest to report free memory.
43607 @@ -993,7 +993,7 @@ static void post_status(struct hv_dynmem_device *dm)
43608 * send the status. This can happen if we were interrupted
43609 * after we picked our transaction ID.
43610 */
43611 - if (status.hdr.trans_id != atomic_read(&trans_id))
43612 + if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
43613 return;
43614
43615 /*
43616 @@ -1129,7 +1129,7 @@ static void balloon_up(struct work_struct *dummy)
43617 */
43618
43619 do {
43620 - bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
43621 + bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
43622 ret = vmbus_sendpacket(dm_device.dev->channel,
43623 bl_resp,
43624 bl_resp->hdr.size,
43625 @@ -1175,7 +1175,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
43626
43627 memset(&resp, 0, sizeof(struct dm_unballoon_response));
43628 resp.hdr.type = DM_UNBALLOON_RESPONSE;
43629 - resp.hdr.trans_id = atomic_inc_return(&trans_id);
43630 + resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
43631 resp.hdr.size = sizeof(struct dm_unballoon_response);
43632
43633 vmbus_sendpacket(dm_device.dev->channel, &resp,
43634 @@ -1239,7 +1239,7 @@ static void version_resp(struct hv_dynmem_device *dm,
43635 memset(&version_req, 0, sizeof(struct dm_version_request));
43636 version_req.hdr.type = DM_VERSION_REQUEST;
43637 version_req.hdr.size = sizeof(struct dm_version_request);
43638 - version_req.hdr.trans_id = atomic_inc_return(&trans_id);
43639 + version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
43640 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
43641 version_req.is_last_attempt = 1;
43642
43643 @@ -1409,7 +1409,7 @@ static int balloon_probe(struct hv_device *dev,
43644 memset(&version_req, 0, sizeof(struct dm_version_request));
43645 version_req.hdr.type = DM_VERSION_REQUEST;
43646 version_req.hdr.size = sizeof(struct dm_version_request);
43647 - version_req.hdr.trans_id = atomic_inc_return(&trans_id);
43648 + version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
43649 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
43650 version_req.is_last_attempt = 0;
43651
43652 @@ -1440,7 +1440,7 @@ static int balloon_probe(struct hv_device *dev,
43653 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
43654 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
43655 cap_msg.hdr.size = sizeof(struct dm_capabilities);
43656 - cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
43657 + cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
43658
43659 cap_msg.caps.cap_bits.balloon = 1;
43660 cap_msg.caps.cap_bits.hot_add = 1;
43661 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
43662 index 22b7507..fc2fc47 100644
43663 --- a/drivers/hv/hyperv_vmbus.h
43664 +++ b/drivers/hv/hyperv_vmbus.h
43665 @@ -607,7 +607,7 @@ enum vmbus_connect_state {
43666 struct vmbus_connection {
43667 enum vmbus_connect_state conn_state;
43668
43669 - atomic_t next_gpadl_handle;
43670 + atomic_unchecked_t next_gpadl_handle;
43671
43672 /*
43673 * Represents channel interrupts. Each bit position represents a
43674 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
43675 index 4d6b269..2e23b86 100644
43676 --- a/drivers/hv/vmbus_drv.c
43677 +++ b/drivers/hv/vmbus_drv.c
43678 @@ -807,10 +807,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
43679 {
43680 int ret = 0;
43681
43682 - static atomic_t device_num = ATOMIC_INIT(0);
43683 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
43684
43685 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
43686 - atomic_inc_return(&device_num));
43687 + atomic_inc_return_unchecked(&device_num));
43688
43689 child_device_obj->device.bus = &hv_bus;
43690 child_device_obj->device.parent = &hv_acpi_dev->dev;
43691 diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
43692 index 579bdf9..75118b5 100644
43693 --- a/drivers/hwmon/acpi_power_meter.c
43694 +++ b/drivers/hwmon/acpi_power_meter.c
43695 @@ -116,7 +116,7 @@ struct sensor_template {
43696 struct device_attribute *devattr,
43697 const char *buf, size_t count);
43698 int index;
43699 -};
43700 +} __do_const;
43701
43702 /* Averaging interval */
43703 static int update_avg_interval(struct acpi_power_meter_resource *resource)
43704 @@ -631,7 +631,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
43705 struct sensor_template *attrs)
43706 {
43707 struct device *dev = &resource->acpi_dev->dev;
43708 - struct sensor_device_attribute *sensors =
43709 + sensor_device_attribute_no_const *sensors =
43710 &resource->sensors[resource->num_sensors];
43711 int res = 0;
43712
43713 diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
43714 index 3288f13..71cfb4e 100644
43715 --- a/drivers/hwmon/applesmc.c
43716 +++ b/drivers/hwmon/applesmc.c
43717 @@ -1106,7 +1106,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
43718 {
43719 struct applesmc_node_group *grp;
43720 struct applesmc_dev_attr *node;
43721 - struct attribute *attr;
43722 + attribute_no_const *attr;
43723 int ret, i;
43724
43725 for (grp = groups; grp->format; grp++) {
43726 diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
43727 index ae208f6..48b6c5b 100644
43728 --- a/drivers/hwmon/asus_atk0110.c
43729 +++ b/drivers/hwmon/asus_atk0110.c
43730 @@ -147,10 +147,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
43731 struct atk_sensor_data {
43732 struct list_head list;
43733 struct atk_data *data;
43734 - struct device_attribute label_attr;
43735 - struct device_attribute input_attr;
43736 - struct device_attribute limit1_attr;
43737 - struct device_attribute limit2_attr;
43738 + device_attribute_no_const label_attr;
43739 + device_attribute_no_const input_attr;
43740 + device_attribute_no_const limit1_attr;
43741 + device_attribute_no_const limit2_attr;
43742 char label_attr_name[ATTR_NAME_SIZE];
43743 char input_attr_name[ATTR_NAME_SIZE];
43744 char limit1_attr_name[ATTR_NAME_SIZE];
43745 @@ -270,7 +270,7 @@ static ssize_t atk_name_show(struct device *dev,
43746 static struct device_attribute atk_name_attr =
43747 __ATTR(name, 0444, atk_name_show, NULL);
43748
43749 -static void atk_init_attribute(struct device_attribute *attr, char *name,
43750 +static void atk_init_attribute(device_attribute_no_const *attr, char *name,
43751 sysfs_show_func show)
43752 {
43753 sysfs_attr_init(&attr->attr);
43754 diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
43755 index d76f0b7..55ae976 100644
43756 --- a/drivers/hwmon/coretemp.c
43757 +++ b/drivers/hwmon/coretemp.c
43758 @@ -784,7 +784,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
43759 return NOTIFY_OK;
43760 }
43761
43762 -static struct notifier_block coretemp_cpu_notifier __refdata = {
43763 +static struct notifier_block coretemp_cpu_notifier = {
43764 .notifier_call = coretemp_cpu_callback,
43765 };
43766
43767 diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
43768 index 632f1dc..57e6a58 100644
43769 --- a/drivers/hwmon/ibmaem.c
43770 +++ b/drivers/hwmon/ibmaem.c
43771 @@ -926,7 +926,7 @@ static int aem_register_sensors(struct aem_data *data,
43772 struct aem_rw_sensor_template *rw)
43773 {
43774 struct device *dev = &data->pdev->dev;
43775 - struct sensor_device_attribute *sensors = data->sensors;
43776 + sensor_device_attribute_no_const *sensors = data->sensors;
43777 int err;
43778
43779 /* Set up read-only sensors */
43780 diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
43781 index 14c82da..09b25d7 100644
43782 --- a/drivers/hwmon/iio_hwmon.c
43783 +++ b/drivers/hwmon/iio_hwmon.c
43784 @@ -61,7 +61,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
43785 {
43786 struct device *dev = &pdev->dev;
43787 struct iio_hwmon_state *st;
43788 - struct sensor_device_attribute *a;
43789 + sensor_device_attribute_no_const *a;
43790 int ret, i;
43791 int in_i = 1, temp_i = 1, curr_i = 1;
43792 enum iio_chan_type type;
43793 diff --git a/drivers/hwmon/nct6683.c b/drivers/hwmon/nct6683.c
43794 index 7710f46..427a28d 100644
43795 --- a/drivers/hwmon/nct6683.c
43796 +++ b/drivers/hwmon/nct6683.c
43797 @@ -397,11 +397,11 @@ static struct attribute_group *
43798 nct6683_create_attr_group(struct device *dev, struct sensor_template_group *tg,
43799 int repeat)
43800 {
43801 - struct sensor_device_attribute_2 *a2;
43802 - struct sensor_device_attribute *a;
43803 + sensor_device_attribute_2_no_const *a2;
43804 + sensor_device_attribute_no_const *a;
43805 struct sensor_device_template **t;
43806 struct sensor_device_attr_u *su;
43807 - struct attribute_group *group;
43808 + attribute_group_no_const *group;
43809 struct attribute **attrs;
43810 int i, j, count;
43811
43812 diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
43813 index 59d9a3f..2298fa4 100644
43814 --- a/drivers/hwmon/nct6775.c
43815 +++ b/drivers/hwmon/nct6775.c
43816 @@ -944,10 +944,10 @@ static struct attribute_group *
43817 nct6775_create_attr_group(struct device *dev, struct sensor_template_group *tg,
43818 int repeat)
43819 {
43820 - struct attribute_group *group;
43821 + attribute_group_no_const *group;
43822 struct sensor_device_attr_u *su;
43823 - struct sensor_device_attribute *a;
43824 - struct sensor_device_attribute_2 *a2;
43825 + sensor_device_attribute_no_const *a;
43826 + sensor_device_attribute_2_no_const *a2;
43827 struct attribute **attrs;
43828 struct sensor_device_template **t;
43829 int i, count;
43830 diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
43831 index 291d11f..3f0dbbd 100644
43832 --- a/drivers/hwmon/pmbus/pmbus_core.c
43833 +++ b/drivers/hwmon/pmbus/pmbus_core.c
43834 @@ -783,7 +783,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
43835 return 0;
43836 }
43837
43838 -static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
43839 +static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
43840 const char *name,
43841 umode_t mode,
43842 ssize_t (*show)(struct device *dev,
43843 @@ -800,7 +800,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
43844 dev_attr->store = store;
43845 }
43846
43847 -static void pmbus_attr_init(struct sensor_device_attribute *a,
43848 +static void pmbus_attr_init(sensor_device_attribute_no_const *a,
43849 const char *name,
43850 umode_t mode,
43851 ssize_t (*show)(struct device *dev,
43852 @@ -822,7 +822,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
43853 u16 reg, u8 mask)
43854 {
43855 struct pmbus_boolean *boolean;
43856 - struct sensor_device_attribute *a;
43857 + sensor_device_attribute_no_const *a;
43858
43859 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
43860 if (!boolean)
43861 @@ -847,7 +847,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
43862 bool update, bool readonly)
43863 {
43864 struct pmbus_sensor *sensor;
43865 - struct device_attribute *a;
43866 + device_attribute_no_const *a;
43867
43868 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
43869 if (!sensor)
43870 @@ -878,7 +878,7 @@ static int pmbus_add_label(struct pmbus_data *data,
43871 const char *lstring, int index)
43872 {
43873 struct pmbus_label *label;
43874 - struct device_attribute *a;
43875 + device_attribute_no_const *a;
43876
43877 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
43878 if (!label)
43879 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
43880 index 97cd45a..ac54d8b 100644
43881 --- a/drivers/hwmon/sht15.c
43882 +++ b/drivers/hwmon/sht15.c
43883 @@ -169,7 +169,7 @@ struct sht15_data {
43884 int supply_uv;
43885 bool supply_uv_valid;
43886 struct work_struct update_supply_work;
43887 - atomic_t interrupt_handled;
43888 + atomic_unchecked_t interrupt_handled;
43889 };
43890
43891 /**
43892 @@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
43893 ret = gpio_direction_input(data->pdata->gpio_data);
43894 if (ret)
43895 return ret;
43896 - atomic_set(&data->interrupt_handled, 0);
43897 + atomic_set_unchecked(&data->interrupt_handled, 0);
43898
43899 enable_irq(gpio_to_irq(data->pdata->gpio_data));
43900 if (gpio_get_value(data->pdata->gpio_data) == 0) {
43901 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
43902 /* Only relevant if the interrupt hasn't occurred. */
43903 - if (!atomic_read(&data->interrupt_handled))
43904 + if (!atomic_read_unchecked(&data->interrupt_handled))
43905 schedule_work(&data->read_work);
43906 }
43907 ret = wait_event_timeout(data->wait_queue,
43908 @@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
43909
43910 /* First disable the interrupt */
43911 disable_irq_nosync(irq);
43912 - atomic_inc(&data->interrupt_handled);
43913 + atomic_inc_unchecked(&data->interrupt_handled);
43914 /* Then schedule a reading work struct */
43915 if (data->state != SHT15_READING_NOTHING)
43916 schedule_work(&data->read_work);
43917 @@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
43918 * If not, then start the interrupt again - care here as could
43919 * have gone low in meantime so verify it hasn't!
43920 */
43921 - atomic_set(&data->interrupt_handled, 0);
43922 + atomic_set_unchecked(&data->interrupt_handled, 0);
43923 enable_irq(gpio_to_irq(data->pdata->gpio_data));
43924 /* If still not occurred or another handler was scheduled */
43925 if (gpio_get_value(data->pdata->gpio_data)
43926 - || atomic_read(&data->interrupt_handled))
43927 + || atomic_read_unchecked(&data->interrupt_handled))
43928 return;
43929 }
43930
43931 diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
43932 index 8df43c5..b07b91d 100644
43933 --- a/drivers/hwmon/via-cputemp.c
43934 +++ b/drivers/hwmon/via-cputemp.c
43935 @@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
43936 return NOTIFY_OK;
43937 }
43938
43939 -static struct notifier_block via_cputemp_cpu_notifier __refdata = {
43940 +static struct notifier_block via_cputemp_cpu_notifier = {
43941 .notifier_call = via_cputemp_cpu_callback,
43942 };
43943
43944 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
43945 index 41fc683..a39cfea 100644
43946 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
43947 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
43948 @@ -43,7 +43,7 @@
43949 extern struct i2c_adapter amd756_smbus;
43950
43951 static struct i2c_adapter *s4882_adapter;
43952 -static struct i2c_algorithm *s4882_algo;
43953 +static i2c_algorithm_no_const *s4882_algo;
43954
43955 /* Wrapper access functions for multiplexed SMBus */
43956 static DEFINE_MUTEX(amd756_lock);
43957 diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
43958 index b19a310..d6eece0 100644
43959 --- a/drivers/i2c/busses/i2c-diolan-u2c.c
43960 +++ b/drivers/i2c/busses/i2c-diolan-u2c.c
43961 @@ -98,7 +98,7 @@ MODULE_PARM_DESC(frequency, "I2C clock frequency in hertz");
43962 /* usb layer */
43963
43964 /* Send command to device, and get response. */
43965 -static int diolan_usb_transfer(struct i2c_diolan_u2c *dev)
43966 +static int __intentional_overflow(-1) diolan_usb_transfer(struct i2c_diolan_u2c *dev)
43967 {
43968 int ret = 0;
43969 int actual;
43970 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
43971 index b170bdf..3c76427 100644
43972 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
43973 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
43974 @@ -41,7 +41,7 @@
43975 extern struct i2c_adapter *nforce2_smbus;
43976
43977 static struct i2c_adapter *s4985_adapter;
43978 -static struct i2c_algorithm *s4985_algo;
43979 +static i2c_algorithm_no_const *s4985_algo;
43980
43981 /* Wrapper access functions for multiplexed SMBus */
43982 static DEFINE_MUTEX(nforce2_lock);
43983 diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
43984 index 80b47e8..1a6040d9 100644
43985 --- a/drivers/i2c/i2c-dev.c
43986 +++ b/drivers/i2c/i2c-dev.c
43987 @@ -277,7 +277,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
43988 break;
43989 }
43990
43991 - data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
43992 + data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
43993 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
43994 if (IS_ERR(rdwr_pa[i].buf)) {
43995 res = PTR_ERR(rdwr_pa[i].buf);
43996 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
43997 index 0b510ba..4fbb5085 100644
43998 --- a/drivers/ide/ide-cd.c
43999 +++ b/drivers/ide/ide-cd.c
44000 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
44001 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
44002 if ((unsigned long)buf & alignment
44003 || blk_rq_bytes(rq) & q->dma_pad_mask
44004 - || object_is_on_stack(buf))
44005 + || object_starts_on_stack(buf))
44006 drive->dma = 0;
44007 }
44008 }
44009 diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
44010 index 4b1f375..770b95f 100644
44011 --- a/drivers/iio/industrialio-core.c
44012 +++ b/drivers/iio/industrialio-core.c
44013 @@ -551,7 +551,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
44014 }
44015
44016 static
44017 -int __iio_device_attr_init(struct device_attribute *dev_attr,
44018 +int __iio_device_attr_init(device_attribute_no_const *dev_attr,
44019 const char *postfix,
44020 struct iio_chan_spec const *chan,
44021 ssize_t (*readfunc)(struct device *dev,
44022 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
44023 index c323917..6ddea8b 100644
44024 --- a/drivers/infiniband/core/cm.c
44025 +++ b/drivers/infiniband/core/cm.c
44026 @@ -115,7 +115,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
44027
44028 struct cm_counter_group {
44029 struct kobject obj;
44030 - atomic_long_t counter[CM_ATTR_COUNT];
44031 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
44032 };
44033
44034 struct cm_counter_attribute {
44035 @@ -1398,7 +1398,7 @@ static void cm_dup_req_handler(struct cm_work *work,
44036 struct ib_mad_send_buf *msg = NULL;
44037 int ret;
44038
44039 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
44040 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
44041 counter[CM_REQ_COUNTER]);
44042
44043 /* Quick state check to discard duplicate REQs. */
44044 @@ -1785,7 +1785,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
44045 if (!cm_id_priv)
44046 return;
44047
44048 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
44049 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
44050 counter[CM_REP_COUNTER]);
44051 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
44052 if (ret)
44053 @@ -1952,7 +1952,7 @@ static int cm_rtu_handler(struct cm_work *work)
44054 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
44055 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
44056 spin_unlock_irq(&cm_id_priv->lock);
44057 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
44058 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
44059 counter[CM_RTU_COUNTER]);
44060 goto out;
44061 }
44062 @@ -2135,7 +2135,7 @@ static int cm_dreq_handler(struct cm_work *work)
44063 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
44064 dreq_msg->local_comm_id);
44065 if (!cm_id_priv) {
44066 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
44067 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
44068 counter[CM_DREQ_COUNTER]);
44069 cm_issue_drep(work->port, work->mad_recv_wc);
44070 return -EINVAL;
44071 @@ -2160,7 +2160,7 @@ static int cm_dreq_handler(struct cm_work *work)
44072 case IB_CM_MRA_REP_RCVD:
44073 break;
44074 case IB_CM_TIMEWAIT:
44075 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
44076 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
44077 counter[CM_DREQ_COUNTER]);
44078 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
44079 goto unlock;
44080 @@ -2174,7 +2174,7 @@ static int cm_dreq_handler(struct cm_work *work)
44081 cm_free_msg(msg);
44082 goto deref;
44083 case IB_CM_DREQ_RCVD:
44084 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
44085 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
44086 counter[CM_DREQ_COUNTER]);
44087 goto unlock;
44088 default:
44089 @@ -2541,7 +2541,7 @@ static int cm_mra_handler(struct cm_work *work)
44090 ib_modify_mad(cm_id_priv->av.port->mad_agent,
44091 cm_id_priv->msg, timeout)) {
44092 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
44093 - atomic_long_inc(&work->port->
44094 + atomic_long_inc_unchecked(&work->port->
44095 counter_group[CM_RECV_DUPLICATES].
44096 counter[CM_MRA_COUNTER]);
44097 goto out;
44098 @@ -2550,7 +2550,7 @@ static int cm_mra_handler(struct cm_work *work)
44099 break;
44100 case IB_CM_MRA_REQ_RCVD:
44101 case IB_CM_MRA_REP_RCVD:
44102 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
44103 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
44104 counter[CM_MRA_COUNTER]);
44105 /* fall through */
44106 default:
44107 @@ -2712,7 +2712,7 @@ static int cm_lap_handler(struct cm_work *work)
44108 case IB_CM_LAP_IDLE:
44109 break;
44110 case IB_CM_MRA_LAP_SENT:
44111 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
44112 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
44113 counter[CM_LAP_COUNTER]);
44114 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
44115 goto unlock;
44116 @@ -2728,7 +2728,7 @@ static int cm_lap_handler(struct cm_work *work)
44117 cm_free_msg(msg);
44118 goto deref;
44119 case IB_CM_LAP_RCVD:
44120 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
44121 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
44122 counter[CM_LAP_COUNTER]);
44123 goto unlock;
44124 default:
44125 @@ -3012,7 +3012,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
44126 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
44127 if (cur_cm_id_priv) {
44128 spin_unlock_irq(&cm.lock);
44129 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
44130 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
44131 counter[CM_SIDR_REQ_COUNTER]);
44132 goto out; /* Duplicate message. */
44133 }
44134 @@ -3224,10 +3224,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
44135 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
44136 msg->retries = 1;
44137
44138 - atomic_long_add(1 + msg->retries,
44139 + atomic_long_add_unchecked(1 + msg->retries,
44140 &port->counter_group[CM_XMIT].counter[attr_index]);
44141 if (msg->retries)
44142 - atomic_long_add(msg->retries,
44143 + atomic_long_add_unchecked(msg->retries,
44144 &port->counter_group[CM_XMIT_RETRIES].
44145 counter[attr_index]);
44146
44147 @@ -3437,7 +3437,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
44148 }
44149
44150 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
44151 - atomic_long_inc(&port->counter_group[CM_RECV].
44152 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
44153 counter[attr_id - CM_ATTR_ID_OFFSET]);
44154
44155 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
44156 @@ -3668,7 +3668,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
44157 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
44158
44159 return sprintf(buf, "%ld\n",
44160 - atomic_long_read(&group->counter[cm_attr->index]));
44161 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
44162 }
44163
44164 static const struct sysfs_ops cm_counter_ops = {
44165 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
44166 index 9f5ad7c..588cd84 100644
44167 --- a/drivers/infiniband/core/fmr_pool.c
44168 +++ b/drivers/infiniband/core/fmr_pool.c
44169 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
44170
44171 struct task_struct *thread;
44172
44173 - atomic_t req_ser;
44174 - atomic_t flush_ser;
44175 + atomic_unchecked_t req_ser;
44176 + atomic_unchecked_t flush_ser;
44177
44178 wait_queue_head_t force_wait;
44179 };
44180 @@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
44181 struct ib_fmr_pool *pool = pool_ptr;
44182
44183 do {
44184 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
44185 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
44186 ib_fmr_batch_release(pool);
44187
44188 - atomic_inc(&pool->flush_ser);
44189 + atomic_inc_unchecked(&pool->flush_ser);
44190 wake_up_interruptible(&pool->force_wait);
44191
44192 if (pool->flush_function)
44193 @@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
44194 }
44195
44196 set_current_state(TASK_INTERRUPTIBLE);
44197 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
44198 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
44199 !kthread_should_stop())
44200 schedule();
44201 __set_current_state(TASK_RUNNING);
44202 @@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
44203 pool->dirty_watermark = params->dirty_watermark;
44204 pool->dirty_len = 0;
44205 spin_lock_init(&pool->pool_lock);
44206 - atomic_set(&pool->req_ser, 0);
44207 - atomic_set(&pool->flush_ser, 0);
44208 + atomic_set_unchecked(&pool->req_ser, 0);
44209 + atomic_set_unchecked(&pool->flush_ser, 0);
44210 init_waitqueue_head(&pool->force_wait);
44211
44212 pool->thread = kthread_run(ib_fmr_cleanup_thread,
44213 @@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
44214 }
44215 spin_unlock_irq(&pool->pool_lock);
44216
44217 - serial = atomic_inc_return(&pool->req_ser);
44218 + serial = atomic_inc_return_unchecked(&pool->req_ser);
44219 wake_up_process(pool->thread);
44220
44221 if (wait_event_interruptible(pool->force_wait,
44222 - atomic_read(&pool->flush_ser) - serial >= 0))
44223 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
44224 return -EINTR;
44225
44226 return 0;
44227 @@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
44228 } else {
44229 list_add_tail(&fmr->list, &pool->dirty_list);
44230 if (++pool->dirty_len >= pool->dirty_watermark) {
44231 - atomic_inc(&pool->req_ser);
44232 + atomic_inc_unchecked(&pool->req_ser);
44233 wake_up_process(pool->thread);
44234 }
44235 }
44236 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
44237 index ec7a298..8742e59 100644
44238 --- a/drivers/infiniband/hw/cxgb4/mem.c
44239 +++ b/drivers/infiniband/hw/cxgb4/mem.c
44240 @@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
44241 int err;
44242 struct fw_ri_tpte tpt;
44243 u32 stag_idx;
44244 - static atomic_t key;
44245 + static atomic_unchecked_t key;
44246
44247 if (c4iw_fatal_error(rdev))
44248 return -EIO;
44249 @@ -270,7 +270,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
44250 if (rdev->stats.stag.cur > rdev->stats.stag.max)
44251 rdev->stats.stag.max = rdev->stats.stag.cur;
44252 mutex_unlock(&rdev->stats.lock);
44253 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
44254 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
44255 }
44256 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
44257 __func__, stag_state, type, pdid, stag_idx);
44258 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
44259 index 79b3dbc..96e5fcc 100644
44260 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
44261 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
44262 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
44263 struct ib_atomic_eth *ateth;
44264 struct ipath_ack_entry *e;
44265 u64 vaddr;
44266 - atomic64_t *maddr;
44267 + atomic64_unchecked_t *maddr;
44268 u64 sdata;
44269 u32 rkey;
44270 u8 next;
44271 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
44272 IB_ACCESS_REMOTE_ATOMIC)))
44273 goto nack_acc_unlck;
44274 /* Perform atomic OP and save result. */
44275 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
44276 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
44277 sdata = be64_to_cpu(ateth->swap_data);
44278 e = &qp->s_ack_queue[qp->r_head_ack_queue];
44279 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
44280 - (u64) atomic64_add_return(sdata, maddr) - sdata :
44281 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
44282 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
44283 be64_to_cpu(ateth->compare_data),
44284 sdata);
44285 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
44286 index 1f95bba..9530f87 100644
44287 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
44288 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
44289 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
44290 unsigned long flags;
44291 struct ib_wc wc;
44292 u64 sdata;
44293 - atomic64_t *maddr;
44294 + atomic64_unchecked_t *maddr;
44295 enum ib_wc_status send_status;
44296
44297 /*
44298 @@ -382,11 +382,11 @@ again:
44299 IB_ACCESS_REMOTE_ATOMIC)))
44300 goto acc_err;
44301 /* Perform atomic OP and save result. */
44302 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
44303 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
44304 sdata = wqe->wr.wr.atomic.compare_add;
44305 *(u64 *) sqp->s_sge.sge.vaddr =
44306 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
44307 - (u64) atomic64_add_return(sdata, maddr) - sdata :
44308 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
44309 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
44310 sdata, wqe->wr.wr.atomic.swap);
44311 goto send_comp;
44312 diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
44313 index 287ad05..5ae7b44d 100644
44314 --- a/drivers/infiniband/hw/mlx4/mad.c
44315 +++ b/drivers/infiniband/hw/mlx4/mad.c
44316 @@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
44317
44318 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
44319 {
44320 - return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
44321 + return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
44322 cpu_to_be64(0xff00000000000000LL);
44323 }
44324
44325 diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
44326 index ed327e6..ca1739e0 100644
44327 --- a/drivers/infiniband/hw/mlx4/mcg.c
44328 +++ b/drivers/infiniband/hw/mlx4/mcg.c
44329 @@ -1041,7 +1041,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
44330 {
44331 char name[20];
44332
44333 - atomic_set(&ctx->tid, 0);
44334 + atomic_set_unchecked(&ctx->tid, 0);
44335 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
44336 ctx->mcg_wq = create_singlethread_workqueue(name);
44337 if (!ctx->mcg_wq)
44338 diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
44339 index 369da3c..223e6e9 100644
44340 --- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
44341 +++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
44342 @@ -426,7 +426,7 @@ struct mlx4_ib_demux_ctx {
44343 struct list_head mcg_mgid0_list;
44344 struct workqueue_struct *mcg_wq;
44345 struct mlx4_ib_demux_pv_ctx **tun;
44346 - atomic_t tid;
44347 + atomic_unchecked_t tid;
44348 int flushing; /* flushing the work queue */
44349 };
44350
44351 diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
44352 index 9d3e5c1..6f166df 100644
44353 --- a/drivers/infiniband/hw/mthca/mthca_cmd.c
44354 +++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
44355 @@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
44356 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
44357 }
44358
44359 -int mthca_QUERY_FW(struct mthca_dev *dev)
44360 +int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
44361 {
44362 struct mthca_mailbox *mailbox;
44363 u32 *outbox;
44364 @@ -1612,7 +1612,7 @@ int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
44365 CMD_TIME_CLASS_B);
44366 }
44367
44368 -int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
44369 +int __intentional_overflow(-1) mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
44370 int num_mtt)
44371 {
44372 return mthca_cmd(dev, mailbox->dma, num_mtt, 0, CMD_WRITE_MTT,
44373 @@ -1634,7 +1634,7 @@ int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
44374 0, CMD_MAP_EQ, CMD_TIME_CLASS_B);
44375 }
44376
44377 -int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
44378 +int __intentional_overflow(-1) mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
44379 int eq_num)
44380 {
44381 return mthca_cmd(dev, mailbox->dma, eq_num, 0, CMD_SW2HW_EQ,
44382 @@ -1857,7 +1857,7 @@ int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn)
44383 CMD_TIME_CLASS_B);
44384 }
44385
44386 -int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
44387 +int __intentional_overflow(-1) mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
44388 int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
44389 void *in_mad, void *response_mad)
44390 {
44391 diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
44392 index ded76c1..0cf0a08 100644
44393 --- a/drivers/infiniband/hw/mthca/mthca_main.c
44394 +++ b/drivers/infiniband/hw/mthca/mthca_main.c
44395 @@ -692,7 +692,7 @@ err_close:
44396 return err;
44397 }
44398
44399 -static int mthca_setup_hca(struct mthca_dev *dev)
44400 +static int __intentional_overflow(-1) mthca_setup_hca(struct mthca_dev *dev)
44401 {
44402 int err;
44403
44404 diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
44405 index ed9a989..6aa5dc2 100644
44406 --- a/drivers/infiniband/hw/mthca/mthca_mr.c
44407 +++ b/drivers/infiniband/hw/mthca/mthca_mr.c
44408 @@ -81,7 +81,7 @@ struct mthca_mpt_entry {
44409 * through the bitmaps)
44410 */
44411
44412 -static u32 mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
44413 +static u32 __intentional_overflow(-1) mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
44414 {
44415 int o;
44416 int m;
44417 @@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
44418 return key;
44419 }
44420
44421 -int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
44422 +int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
44423 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
44424 {
44425 struct mthca_mailbox *mailbox;
44426 @@ -516,7 +516,7 @@ int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
44427 return mthca_mr_alloc(dev, pd, 12, 0, ~0ULL, access, mr);
44428 }
44429
44430 -int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
44431 +int __intentional_overflow(-1) mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
44432 u64 *buffer_list, int buffer_size_shift,
44433 int list_len, u64 iova, u64 total_size,
44434 u32 access, struct mthca_mr *mr)
44435 diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
44436 index 415f8e1..e34214e 100644
44437 --- a/drivers/infiniband/hw/mthca/mthca_provider.c
44438 +++ b/drivers/infiniband/hw/mthca/mthca_provider.c
44439 @@ -764,7 +764,7 @@ unlock:
44440 return 0;
44441 }
44442
44443 -static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
44444 +static int __intentional_overflow(-1) mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
44445 {
44446 struct mthca_dev *dev = to_mdev(ibcq->device);
44447 struct mthca_cq *cq = to_mcq(ibcq);
44448 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
44449 index 3b2a6dc..bce26ff 100644
44450 --- a/drivers/infiniband/hw/nes/nes.c
44451 +++ b/drivers/infiniband/hw/nes/nes.c
44452 @@ -97,7 +97,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
44453 LIST_HEAD(nes_adapter_list);
44454 static LIST_HEAD(nes_dev_list);
44455
44456 -atomic_t qps_destroyed;
44457 +atomic_unchecked_t qps_destroyed;
44458
44459 static unsigned int ee_flsh_adapter;
44460 static unsigned int sysfs_nonidx_addr;
44461 @@ -278,7 +278,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
44462 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
44463 struct nes_adapter *nesadapter = nesdev->nesadapter;
44464
44465 - atomic_inc(&qps_destroyed);
44466 + atomic_inc_unchecked(&qps_destroyed);
44467
44468 /* Free the control structures */
44469
44470 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
44471 index bd9d132..70d84f4 100644
44472 --- a/drivers/infiniband/hw/nes/nes.h
44473 +++ b/drivers/infiniband/hw/nes/nes.h
44474 @@ -180,17 +180,17 @@ extern unsigned int nes_debug_level;
44475 extern unsigned int wqm_quanta;
44476 extern struct list_head nes_adapter_list;
44477
44478 -extern atomic_t cm_connects;
44479 -extern atomic_t cm_accepts;
44480 -extern atomic_t cm_disconnects;
44481 -extern atomic_t cm_closes;
44482 -extern atomic_t cm_connecteds;
44483 -extern atomic_t cm_connect_reqs;
44484 -extern atomic_t cm_rejects;
44485 -extern atomic_t mod_qp_timouts;
44486 -extern atomic_t qps_created;
44487 -extern atomic_t qps_destroyed;
44488 -extern atomic_t sw_qps_destroyed;
44489 +extern atomic_unchecked_t cm_connects;
44490 +extern atomic_unchecked_t cm_accepts;
44491 +extern atomic_unchecked_t cm_disconnects;
44492 +extern atomic_unchecked_t cm_closes;
44493 +extern atomic_unchecked_t cm_connecteds;
44494 +extern atomic_unchecked_t cm_connect_reqs;
44495 +extern atomic_unchecked_t cm_rejects;
44496 +extern atomic_unchecked_t mod_qp_timouts;
44497 +extern atomic_unchecked_t qps_created;
44498 +extern atomic_unchecked_t qps_destroyed;
44499 +extern atomic_unchecked_t sw_qps_destroyed;
44500 extern u32 mh_detected;
44501 extern u32 mh_pauses_sent;
44502 extern u32 cm_packets_sent;
44503 @@ -199,16 +199,16 @@ extern u32 cm_packets_created;
44504 extern u32 cm_packets_received;
44505 extern u32 cm_packets_dropped;
44506 extern u32 cm_packets_retrans;
44507 -extern atomic_t cm_listens_created;
44508 -extern atomic_t cm_listens_destroyed;
44509 +extern atomic_unchecked_t cm_listens_created;
44510 +extern atomic_unchecked_t cm_listens_destroyed;
44511 extern u32 cm_backlog_drops;
44512 -extern atomic_t cm_loopbacks;
44513 -extern atomic_t cm_nodes_created;
44514 -extern atomic_t cm_nodes_destroyed;
44515 -extern atomic_t cm_accel_dropped_pkts;
44516 -extern atomic_t cm_resets_recvd;
44517 -extern atomic_t pau_qps_created;
44518 -extern atomic_t pau_qps_destroyed;
44519 +extern atomic_unchecked_t cm_loopbacks;
44520 +extern atomic_unchecked_t cm_nodes_created;
44521 +extern atomic_unchecked_t cm_nodes_destroyed;
44522 +extern atomic_unchecked_t cm_accel_dropped_pkts;
44523 +extern atomic_unchecked_t cm_resets_recvd;
44524 +extern atomic_unchecked_t pau_qps_created;
44525 +extern atomic_unchecked_t pau_qps_destroyed;
44526
44527 extern u32 int_mod_timer_init;
44528 extern u32 int_mod_cq_depth_256;
44529 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
44530 index 6f09a72..cf4399d 100644
44531 --- a/drivers/infiniband/hw/nes/nes_cm.c
44532 +++ b/drivers/infiniband/hw/nes/nes_cm.c
44533 @@ -69,14 +69,14 @@ u32 cm_packets_dropped;
44534 u32 cm_packets_retrans;
44535 u32 cm_packets_created;
44536 u32 cm_packets_received;
44537 -atomic_t cm_listens_created;
44538 -atomic_t cm_listens_destroyed;
44539 +atomic_unchecked_t cm_listens_created;
44540 +atomic_unchecked_t cm_listens_destroyed;
44541 u32 cm_backlog_drops;
44542 -atomic_t cm_loopbacks;
44543 -atomic_t cm_nodes_created;
44544 -atomic_t cm_nodes_destroyed;
44545 -atomic_t cm_accel_dropped_pkts;
44546 -atomic_t cm_resets_recvd;
44547 +atomic_unchecked_t cm_loopbacks;
44548 +atomic_unchecked_t cm_nodes_created;
44549 +atomic_unchecked_t cm_nodes_destroyed;
44550 +atomic_unchecked_t cm_accel_dropped_pkts;
44551 +atomic_unchecked_t cm_resets_recvd;
44552
44553 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
44554 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
44555 @@ -135,28 +135,28 @@ static void record_ird_ord(struct nes_cm_node *, u16, u16);
44556 /* instance of function pointers for client API */
44557 /* set address of this instance to cm_core->cm_ops at cm_core alloc */
44558 static struct nes_cm_ops nes_cm_api = {
44559 - mini_cm_accelerated,
44560 - mini_cm_listen,
44561 - mini_cm_del_listen,
44562 - mini_cm_connect,
44563 - mini_cm_close,
44564 - mini_cm_accept,
44565 - mini_cm_reject,
44566 - mini_cm_recv_pkt,
44567 - mini_cm_dealloc_core,
44568 - mini_cm_get,
44569 - mini_cm_set
44570 + .accelerated = mini_cm_accelerated,
44571 + .listen = mini_cm_listen,
44572 + .stop_listener = mini_cm_del_listen,
44573 + .connect = mini_cm_connect,
44574 + .close = mini_cm_close,
44575 + .accept = mini_cm_accept,
44576 + .reject = mini_cm_reject,
44577 + .recv_pkt = mini_cm_recv_pkt,
44578 + .destroy_cm_core = mini_cm_dealloc_core,
44579 + .get = mini_cm_get,
44580 + .set = mini_cm_set
44581 };
44582
44583 static struct nes_cm_core *g_cm_core;
44584
44585 -atomic_t cm_connects;
44586 -atomic_t cm_accepts;
44587 -atomic_t cm_disconnects;
44588 -atomic_t cm_closes;
44589 -atomic_t cm_connecteds;
44590 -atomic_t cm_connect_reqs;
44591 -atomic_t cm_rejects;
44592 +atomic_unchecked_t cm_connects;
44593 +atomic_unchecked_t cm_accepts;
44594 +atomic_unchecked_t cm_disconnects;
44595 +atomic_unchecked_t cm_closes;
44596 +atomic_unchecked_t cm_connecteds;
44597 +atomic_unchecked_t cm_connect_reqs;
44598 +atomic_unchecked_t cm_rejects;
44599
44600 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
44601 {
44602 @@ -1436,7 +1436,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
44603 kfree(listener);
44604 listener = NULL;
44605 ret = 0;
44606 - atomic_inc(&cm_listens_destroyed);
44607 + atomic_inc_unchecked(&cm_listens_destroyed);
44608 } else {
44609 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
44610 }
44611 @@ -1637,7 +1637,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
44612 cm_node->rem_mac);
44613
44614 add_hte_node(cm_core, cm_node);
44615 - atomic_inc(&cm_nodes_created);
44616 + atomic_inc_unchecked(&cm_nodes_created);
44617
44618 return cm_node;
44619 }
44620 @@ -1698,7 +1698,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
44621 }
44622
44623 atomic_dec(&cm_core->node_cnt);
44624 - atomic_inc(&cm_nodes_destroyed);
44625 + atomic_inc_unchecked(&cm_nodes_destroyed);
44626 nesqp = cm_node->nesqp;
44627 if (nesqp) {
44628 nesqp->cm_node = NULL;
44629 @@ -1762,7 +1762,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
44630
44631 static void drop_packet(struct sk_buff *skb)
44632 {
44633 - atomic_inc(&cm_accel_dropped_pkts);
44634 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
44635 dev_kfree_skb_any(skb);
44636 }
44637
44638 @@ -1825,7 +1825,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
44639 {
44640
44641 int reset = 0; /* whether to send reset in case of err.. */
44642 - atomic_inc(&cm_resets_recvd);
44643 + atomic_inc_unchecked(&cm_resets_recvd);
44644 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
44645 " refcnt=%d\n", cm_node, cm_node->state,
44646 atomic_read(&cm_node->ref_count));
44647 @@ -2492,7 +2492,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
44648 rem_ref_cm_node(cm_node->cm_core, cm_node);
44649 return NULL;
44650 }
44651 - atomic_inc(&cm_loopbacks);
44652 + atomic_inc_unchecked(&cm_loopbacks);
44653 loopbackremotenode->loopbackpartner = cm_node;
44654 loopbackremotenode->tcp_cntxt.rcv_wscale =
44655 NES_CM_DEFAULT_RCV_WND_SCALE;
44656 @@ -2773,7 +2773,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
44657 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
44658 else {
44659 rem_ref_cm_node(cm_core, cm_node);
44660 - atomic_inc(&cm_accel_dropped_pkts);
44661 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
44662 dev_kfree_skb_any(skb);
44663 }
44664 break;
44665 @@ -3081,7 +3081,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
44666
44667 if ((cm_id) && (cm_id->event_handler)) {
44668 if (issue_disconn) {
44669 - atomic_inc(&cm_disconnects);
44670 + atomic_inc_unchecked(&cm_disconnects);
44671 cm_event.event = IW_CM_EVENT_DISCONNECT;
44672 cm_event.status = disconn_status;
44673 cm_event.local_addr = cm_id->local_addr;
44674 @@ -3103,7 +3103,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
44675 }
44676
44677 if (issue_close) {
44678 - atomic_inc(&cm_closes);
44679 + atomic_inc_unchecked(&cm_closes);
44680 nes_disconnect(nesqp, 1);
44681
44682 cm_id->provider_data = nesqp;
44683 @@ -3241,7 +3241,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
44684
44685 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
44686 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
44687 - atomic_inc(&cm_accepts);
44688 + atomic_inc_unchecked(&cm_accepts);
44689
44690 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
44691 netdev_refcnt_read(nesvnic->netdev));
44692 @@ -3439,7 +3439,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
44693 struct nes_cm_core *cm_core;
44694 u8 *start_buff;
44695
44696 - atomic_inc(&cm_rejects);
44697 + atomic_inc_unchecked(&cm_rejects);
44698 cm_node = (struct nes_cm_node *)cm_id->provider_data;
44699 loopback = cm_node->loopbackpartner;
44700 cm_core = cm_node->cm_core;
44701 @@ -3504,7 +3504,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
44702 ntohs(raddr->sin_port), ntohl(laddr->sin_addr.s_addr),
44703 ntohs(laddr->sin_port));
44704
44705 - atomic_inc(&cm_connects);
44706 + atomic_inc_unchecked(&cm_connects);
44707 nesqp->active_conn = 1;
44708
44709 /* cache the cm_id in the qp */
44710 @@ -3649,7 +3649,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
44711 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
44712 return err;
44713 }
44714 - atomic_inc(&cm_listens_created);
44715 + atomic_inc_unchecked(&cm_listens_created);
44716 }
44717
44718 cm_id->add_ref(cm_id);
44719 @@ -3756,7 +3756,7 @@ static void cm_event_connected(struct nes_cm_event *event)
44720
44721 if (nesqp->destroyed)
44722 return;
44723 - atomic_inc(&cm_connecteds);
44724 + atomic_inc_unchecked(&cm_connecteds);
44725 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
44726 " local port 0x%04X. jiffies = %lu.\n",
44727 nesqp->hwqp.qp_id, ntohl(raddr->sin_addr.s_addr),
44728 @@ -3941,7 +3941,7 @@ static void cm_event_reset(struct nes_cm_event *event)
44729
44730 cm_id->add_ref(cm_id);
44731 ret = cm_id->event_handler(cm_id, &cm_event);
44732 - atomic_inc(&cm_closes);
44733 + atomic_inc_unchecked(&cm_closes);
44734 cm_event.event = IW_CM_EVENT_CLOSE;
44735 cm_event.status = 0;
44736 cm_event.provider_data = cm_id->provider_data;
44737 @@ -3981,7 +3981,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
44738 return;
44739 cm_id = cm_node->cm_id;
44740
44741 - atomic_inc(&cm_connect_reqs);
44742 + atomic_inc_unchecked(&cm_connect_reqs);
44743 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
44744 cm_node, cm_id, jiffies);
44745
44746 @@ -4030,7 +4030,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
44747 return;
44748 cm_id = cm_node->cm_id;
44749
44750 - atomic_inc(&cm_connect_reqs);
44751 + atomic_inc_unchecked(&cm_connect_reqs);
44752 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
44753 cm_node, cm_id, jiffies);
44754
44755 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
44756 index 4166452..fc952c3 100644
44757 --- a/drivers/infiniband/hw/nes/nes_mgt.c
44758 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
44759 @@ -40,8 +40,8 @@
44760 #include "nes.h"
44761 #include "nes_mgt.h"
44762
44763 -atomic_t pau_qps_created;
44764 -atomic_t pau_qps_destroyed;
44765 +atomic_unchecked_t pau_qps_created;
44766 +atomic_unchecked_t pau_qps_destroyed;
44767
44768 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
44769 {
44770 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
44771 {
44772 struct sk_buff *skb;
44773 unsigned long flags;
44774 - atomic_inc(&pau_qps_destroyed);
44775 + atomic_inc_unchecked(&pau_qps_destroyed);
44776
44777 /* Free packets that have not yet been forwarded */
44778 /* Lock is acquired by skb_dequeue when removing the skb */
44779 @@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
44780 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
44781 skb_queue_head_init(&nesqp->pau_list);
44782 spin_lock_init(&nesqp->pau_lock);
44783 - atomic_inc(&pau_qps_created);
44784 + atomic_inc_unchecked(&pau_qps_created);
44785 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
44786 }
44787
44788 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
44789 index 49eb511..a774366 100644
44790 --- a/drivers/infiniband/hw/nes/nes_nic.c
44791 +++ b/drivers/infiniband/hw/nes/nes_nic.c
44792 @@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
44793 target_stat_values[++index] = mh_detected;
44794 target_stat_values[++index] = mh_pauses_sent;
44795 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
44796 - target_stat_values[++index] = atomic_read(&cm_connects);
44797 - target_stat_values[++index] = atomic_read(&cm_accepts);
44798 - target_stat_values[++index] = atomic_read(&cm_disconnects);
44799 - target_stat_values[++index] = atomic_read(&cm_connecteds);
44800 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
44801 - target_stat_values[++index] = atomic_read(&cm_rejects);
44802 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
44803 - target_stat_values[++index] = atomic_read(&qps_created);
44804 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
44805 - target_stat_values[++index] = atomic_read(&qps_destroyed);
44806 - target_stat_values[++index] = atomic_read(&cm_closes);
44807 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
44808 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
44809 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
44810 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
44811 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
44812 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
44813 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
44814 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
44815 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
44816 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
44817 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
44818 target_stat_values[++index] = cm_packets_sent;
44819 target_stat_values[++index] = cm_packets_bounced;
44820 target_stat_values[++index] = cm_packets_created;
44821 target_stat_values[++index] = cm_packets_received;
44822 target_stat_values[++index] = cm_packets_dropped;
44823 target_stat_values[++index] = cm_packets_retrans;
44824 - target_stat_values[++index] = atomic_read(&cm_listens_created);
44825 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
44826 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
44827 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
44828 target_stat_values[++index] = cm_backlog_drops;
44829 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
44830 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
44831 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
44832 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
44833 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
44834 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
44835 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
44836 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
44837 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
44838 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
44839 target_stat_values[++index] = nesadapter->free_4kpbl;
44840 target_stat_values[++index] = nesadapter->free_256pbl;
44841 target_stat_values[++index] = int_mod_timer_init;
44842 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
44843 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
44844 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
44845 - target_stat_values[++index] = atomic_read(&pau_qps_created);
44846 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
44847 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
44848 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
44849 }
44850
44851 /**
44852 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
44853 index 218dd35..97ce31d 100644
44854 --- a/drivers/infiniband/hw/nes/nes_verbs.c
44855 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
44856 @@ -46,9 +46,9 @@
44857
44858 #include <rdma/ib_umem.h>
44859
44860 -atomic_t mod_qp_timouts;
44861 -atomic_t qps_created;
44862 -atomic_t sw_qps_destroyed;
44863 +atomic_unchecked_t mod_qp_timouts;
44864 +atomic_unchecked_t qps_created;
44865 +atomic_unchecked_t sw_qps_destroyed;
44866
44867 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
44868
44869 @@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
44870 if (init_attr->create_flags)
44871 return ERR_PTR(-EINVAL);
44872
44873 - atomic_inc(&qps_created);
44874 + atomic_inc_unchecked(&qps_created);
44875 switch (init_attr->qp_type) {
44876 case IB_QPT_RC:
44877 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
44878 @@ -1468,7 +1468,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
44879 struct iw_cm_event cm_event;
44880 int ret = 0;
44881
44882 - atomic_inc(&sw_qps_destroyed);
44883 + atomic_inc_unchecked(&sw_qps_destroyed);
44884 nesqp->destroyed = 1;
44885
44886 /* Blow away the connection if it exists. */
44887 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
44888 index c00ae09..04e91be 100644
44889 --- a/drivers/infiniband/hw/qib/qib.h
44890 +++ b/drivers/infiniband/hw/qib/qib.h
44891 @@ -52,6 +52,7 @@
44892 #include <linux/kref.h>
44893 #include <linux/sched.h>
44894 #include <linux/kthread.h>
44895 +#include <linux/slab.h>
44896
44897 #include "qib_common.h"
44898 #include "qib_verbs.h"
44899 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
44900 index 24c41ba..102d71f 100644
44901 --- a/drivers/input/gameport/gameport.c
44902 +++ b/drivers/input/gameport/gameport.c
44903 @@ -490,14 +490,14 @@ EXPORT_SYMBOL(gameport_set_phys);
44904 */
44905 static void gameport_init_port(struct gameport *gameport)
44906 {
44907 - static atomic_t gameport_no = ATOMIC_INIT(0);
44908 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
44909
44910 __module_get(THIS_MODULE);
44911
44912 mutex_init(&gameport->drv_mutex);
44913 device_initialize(&gameport->dev);
44914 dev_set_name(&gameport->dev, "gameport%lu",
44915 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
44916 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
44917 gameport->dev.bus = &gameport_bus;
44918 gameport->dev.release = gameport_release_port;
44919 if (gameport->parent)
44920 diff --git a/drivers/input/input.c b/drivers/input/input.c
44921 index 29ca0bb..f4bc2e3 100644
44922 --- a/drivers/input/input.c
44923 +++ b/drivers/input/input.c
44924 @@ -1774,7 +1774,7 @@ EXPORT_SYMBOL_GPL(input_class);
44925 */
44926 struct input_dev *input_allocate_device(void)
44927 {
44928 - static atomic_t input_no = ATOMIC_INIT(0);
44929 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
44930 struct input_dev *dev;
44931
44932 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
44933 @@ -1789,7 +1789,7 @@ struct input_dev *input_allocate_device(void)
44934 INIT_LIST_HEAD(&dev->node);
44935
44936 dev_set_name(&dev->dev, "input%ld",
44937 - (unsigned long) atomic_inc_return(&input_no) - 1);
44938 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
44939
44940 __module_get(THIS_MODULE);
44941 }
44942 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
44943 index 4a95b22..874c182 100644
44944 --- a/drivers/input/joystick/sidewinder.c
44945 +++ b/drivers/input/joystick/sidewinder.c
44946 @@ -30,6 +30,7 @@
44947 #include <linux/kernel.h>
44948 #include <linux/module.h>
44949 #include <linux/slab.h>
44950 +#include <linux/sched.h>
44951 #include <linux/input.h>
44952 #include <linux/gameport.h>
44953 #include <linux/jiffies.h>
44954 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
44955 index 603fe0d..f63decc 100644
44956 --- a/drivers/input/joystick/xpad.c
44957 +++ b/drivers/input/joystick/xpad.c
44958 @@ -737,7 +737,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
44959
44960 static int xpad_led_probe(struct usb_xpad *xpad)
44961 {
44962 - static atomic_t led_seq = ATOMIC_INIT(0);
44963 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
44964 long led_no;
44965 struct xpad_led *led;
44966 struct led_classdev *led_cdev;
44967 @@ -750,7 +750,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
44968 if (!led)
44969 return -ENOMEM;
44970
44971 - led_no = (long)atomic_inc_return(&led_seq) - 1;
44972 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
44973
44974 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
44975 led->xpad = xpad;
44976 diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
44977 index 719410f..1896169 100644
44978 --- a/drivers/input/misc/ims-pcu.c
44979 +++ b/drivers/input/misc/ims-pcu.c
44980 @@ -1851,7 +1851,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
44981
44982 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
44983 {
44984 - static atomic_t device_no = ATOMIC_INIT(0);
44985 + static atomic_unchecked_t device_no = ATOMIC_INIT(0);
44986
44987 const struct ims_pcu_device_info *info;
44988 int error;
44989 @@ -1882,7 +1882,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
44990 }
44991
44992 /* Device appears to be operable, complete initialization */
44993 - pcu->device_no = atomic_inc_return(&device_no) - 1;
44994 + pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
44995
44996 /*
44997 * PCU-B devices, both GEN_1 and GEN_2 do not have OFN sensor
44998 diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
44999 index 2f0b39d..7370f13 100644
45000 --- a/drivers/input/mouse/psmouse.h
45001 +++ b/drivers/input/mouse/psmouse.h
45002 @@ -116,7 +116,7 @@ struct psmouse_attribute {
45003 ssize_t (*set)(struct psmouse *psmouse, void *data,
45004 const char *buf, size_t count);
45005 bool protect;
45006 -};
45007 +} __do_const;
45008 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
45009
45010 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
45011 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
45012 index b604564..3f14ae4 100644
45013 --- a/drivers/input/mousedev.c
45014 +++ b/drivers/input/mousedev.c
45015 @@ -744,7 +744,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
45016
45017 spin_unlock_irq(&client->packet_lock);
45018
45019 - if (copy_to_user(buffer, data, count))
45020 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
45021 return -EFAULT;
45022
45023 return count;
45024 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
45025 index b29134d..394deb0 100644
45026 --- a/drivers/input/serio/serio.c
45027 +++ b/drivers/input/serio/serio.c
45028 @@ -514,7 +514,7 @@ static void serio_release_port(struct device *dev)
45029 */
45030 static void serio_init_port(struct serio *serio)
45031 {
45032 - static atomic_t serio_no = ATOMIC_INIT(0);
45033 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
45034
45035 __module_get(THIS_MODULE);
45036
45037 @@ -525,7 +525,7 @@ static void serio_init_port(struct serio *serio)
45038 mutex_init(&serio->drv_mutex);
45039 device_initialize(&serio->dev);
45040 dev_set_name(&serio->dev, "serio%ld",
45041 - (long)atomic_inc_return(&serio_no) - 1);
45042 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
45043 serio->dev.bus = &serio_bus;
45044 serio->dev.release = serio_release_port;
45045 serio->dev.groups = serio_device_attr_groups;
45046 diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
45047 index c9a02fe..0debc75 100644
45048 --- a/drivers/input/serio/serio_raw.c
45049 +++ b/drivers/input/serio/serio_raw.c
45050 @@ -292,7 +292,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
45051
45052 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
45053 {
45054 - static atomic_t serio_raw_no = ATOMIC_INIT(0);
45055 + static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
45056 struct serio_raw *serio_raw;
45057 int err;
45058
45059 @@ -303,7 +303,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
45060 }
45061
45062 snprintf(serio_raw->name, sizeof(serio_raw->name),
45063 - "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
45064 + "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
45065 kref_init(&serio_raw->kref);
45066 INIT_LIST_HEAD(&serio_raw->client_list);
45067 init_waitqueue_head(&serio_raw->wait);
45068 diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
45069 index e5555fc..937986d 100644
45070 --- a/drivers/iommu/iommu.c
45071 +++ b/drivers/iommu/iommu.c
45072 @@ -588,7 +588,7 @@ static struct notifier_block iommu_bus_nb = {
45073 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
45074 {
45075 bus_register_notifier(bus, &iommu_bus_nb);
45076 - bus_for_each_dev(bus, NULL, ops, add_iommu_group);
45077 + bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
45078 }
45079
45080 /**
45081 diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
45082 index 33c4395..e06447e 100644
45083 --- a/drivers/iommu/irq_remapping.c
45084 +++ b/drivers/iommu/irq_remapping.c
45085 @@ -354,7 +354,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
45086 void panic_if_irq_remap(const char *msg)
45087 {
45088 if (irq_remapping_enabled)
45089 - panic(msg);
45090 + panic("%s", msg);
45091 }
45092
45093 static void ir_ack_apic_edge(struct irq_data *data)
45094 @@ -375,10 +375,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
45095
45096 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
45097 {
45098 - chip->irq_print_chip = ir_print_prefix;
45099 - chip->irq_ack = ir_ack_apic_edge;
45100 - chip->irq_eoi = ir_ack_apic_level;
45101 - chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
45102 + pax_open_kernel();
45103 + *(void **)&chip->irq_print_chip = ir_print_prefix;
45104 + *(void **)&chip->irq_ack = ir_ack_apic_edge;
45105 + *(void **)&chip->irq_eoi = ir_ack_apic_level;
45106 + *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
45107 + pax_close_kernel();
45108 }
45109
45110 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
45111 diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
45112 index 7c131cf..035129b 100644
45113 --- a/drivers/irqchip/irq-gic.c
45114 +++ b/drivers/irqchip/irq-gic.c
45115 @@ -85,7 +85,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
45116 * Supported arch specific GIC irq extension.
45117 * Default make them NULL.
45118 */
45119 -struct irq_chip gic_arch_extn = {
45120 +irq_chip_no_const gic_arch_extn = {
45121 .irq_eoi = NULL,
45122 .irq_mask = NULL,
45123 .irq_unmask = NULL,
45124 @@ -337,7 +337,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
45125 chained_irq_exit(chip, desc);
45126 }
45127
45128 -static struct irq_chip gic_chip = {
45129 +static irq_chip_no_const gic_chip __read_only = {
45130 .name = "GIC",
45131 .irq_mask = gic_mask_irq,
45132 .irq_unmask = gic_unmask_irq,
45133 diff --git a/drivers/irqchip/irq-renesas-irqc.c b/drivers/irqchip/irq-renesas-irqc.c
45134 index 8777065..a4a9967 100644
45135 --- a/drivers/irqchip/irq-renesas-irqc.c
45136 +++ b/drivers/irqchip/irq-renesas-irqc.c
45137 @@ -151,7 +151,7 @@ static int irqc_probe(struct platform_device *pdev)
45138 struct irqc_priv *p;
45139 struct resource *io;
45140 struct resource *irq;
45141 - struct irq_chip *irq_chip;
45142 + irq_chip_no_const *irq_chip;
45143 const char *name = dev_name(&pdev->dev);
45144 int ret;
45145 int k;
45146 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
45147 index f9a87ed..3fdd854 100644
45148 --- a/drivers/isdn/capi/capi.c
45149 +++ b/drivers/isdn/capi/capi.c
45150 @@ -81,8 +81,8 @@ struct capiminor {
45151
45152 struct capi20_appl *ap;
45153 u32 ncci;
45154 - atomic_t datahandle;
45155 - atomic_t msgid;
45156 + atomic_unchecked_t datahandle;
45157 + atomic_unchecked_t msgid;
45158
45159 struct tty_port port;
45160 int ttyinstop;
45161 @@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
45162 capimsg_setu16(s, 2, mp->ap->applid);
45163 capimsg_setu8 (s, 4, CAPI_DATA_B3);
45164 capimsg_setu8 (s, 5, CAPI_RESP);
45165 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
45166 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
45167 capimsg_setu32(s, 8, mp->ncci);
45168 capimsg_setu16(s, 12, datahandle);
45169 }
45170 @@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
45171 mp->outbytes -= len;
45172 spin_unlock_bh(&mp->outlock);
45173
45174 - datahandle = atomic_inc_return(&mp->datahandle);
45175 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
45176 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
45177 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
45178 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
45179 capimsg_setu16(skb->data, 2, mp->ap->applid);
45180 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
45181 capimsg_setu8 (skb->data, 5, CAPI_REQ);
45182 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
45183 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
45184 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
45185 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
45186 capimsg_setu16(skb->data, 16, len); /* Data length */
45187 diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
45188 index b7ae0a0..04590fa 100644
45189 --- a/drivers/isdn/gigaset/bas-gigaset.c
45190 +++ b/drivers/isdn/gigaset/bas-gigaset.c
45191 @@ -2565,22 +2565,22 @@ static int gigaset_post_reset(struct usb_interface *intf)
45192
45193
45194 static const struct gigaset_ops gigops = {
45195 - gigaset_write_cmd,
45196 - gigaset_write_room,
45197 - gigaset_chars_in_buffer,
45198 - gigaset_brkchars,
45199 - gigaset_init_bchannel,
45200 - gigaset_close_bchannel,
45201 - gigaset_initbcshw,
45202 - gigaset_freebcshw,
45203 - gigaset_reinitbcshw,
45204 - gigaset_initcshw,
45205 - gigaset_freecshw,
45206 - gigaset_set_modem_ctrl,
45207 - gigaset_baud_rate,
45208 - gigaset_set_line_ctrl,
45209 - gigaset_isoc_send_skb,
45210 - gigaset_isoc_input,
45211 + .write_cmd = gigaset_write_cmd,
45212 + .write_room = gigaset_write_room,
45213 + .chars_in_buffer = gigaset_chars_in_buffer,
45214 + .brkchars = gigaset_brkchars,
45215 + .init_bchannel = gigaset_init_bchannel,
45216 + .close_bchannel = gigaset_close_bchannel,
45217 + .initbcshw = gigaset_initbcshw,
45218 + .freebcshw = gigaset_freebcshw,
45219 + .reinitbcshw = gigaset_reinitbcshw,
45220 + .initcshw = gigaset_initcshw,
45221 + .freecshw = gigaset_freecshw,
45222 + .set_modem_ctrl = gigaset_set_modem_ctrl,
45223 + .baud_rate = gigaset_baud_rate,
45224 + .set_line_ctrl = gigaset_set_line_ctrl,
45225 + .send_skb = gigaset_isoc_send_skb,
45226 + .handle_input = gigaset_isoc_input,
45227 };
45228
45229 /* bas_gigaset_init
45230 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
45231 index 600c79b..3752bab 100644
45232 --- a/drivers/isdn/gigaset/interface.c
45233 +++ b/drivers/isdn/gigaset/interface.c
45234 @@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
45235 }
45236 tty->driver_data = cs;
45237
45238 - ++cs->port.count;
45239 + atomic_inc(&cs->port.count);
45240
45241 - if (cs->port.count == 1) {
45242 + if (atomic_read(&cs->port.count) == 1) {
45243 tty_port_tty_set(&cs->port, tty);
45244 cs->port.low_latency = 1;
45245 }
45246 @@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
45247
45248 if (!cs->connected)
45249 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
45250 - else if (!cs->port.count)
45251 + else if (!atomic_read(&cs->port.count))
45252 dev_warn(cs->dev, "%s: device not opened\n", __func__);
45253 - else if (!--cs->port.count)
45254 + else if (!atomic_dec_return(&cs->port.count))
45255 tty_port_tty_set(&cs->port, NULL);
45256
45257 mutex_unlock(&cs->mutex);
45258 diff --git a/drivers/isdn/gigaset/ser-gigaset.c b/drivers/isdn/gigaset/ser-gigaset.c
45259 index 8c91fd5..14f13ce 100644
45260 --- a/drivers/isdn/gigaset/ser-gigaset.c
45261 +++ b/drivers/isdn/gigaset/ser-gigaset.c
45262 @@ -453,22 +453,22 @@ static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
45263 }
45264
45265 static const struct gigaset_ops ops = {
45266 - gigaset_write_cmd,
45267 - gigaset_write_room,
45268 - gigaset_chars_in_buffer,
45269 - gigaset_brkchars,
45270 - gigaset_init_bchannel,
45271 - gigaset_close_bchannel,
45272 - gigaset_initbcshw,
45273 - gigaset_freebcshw,
45274 - gigaset_reinitbcshw,
45275 - gigaset_initcshw,
45276 - gigaset_freecshw,
45277 - gigaset_set_modem_ctrl,
45278 - gigaset_baud_rate,
45279 - gigaset_set_line_ctrl,
45280 - gigaset_m10x_send_skb, /* asyncdata.c */
45281 - gigaset_m10x_input, /* asyncdata.c */
45282 + .write_cmd = gigaset_write_cmd,
45283 + .write_room = gigaset_write_room,
45284 + .chars_in_buffer = gigaset_chars_in_buffer,
45285 + .brkchars = gigaset_brkchars,
45286 + .init_bchannel = gigaset_init_bchannel,
45287 + .close_bchannel = gigaset_close_bchannel,
45288 + .initbcshw = gigaset_initbcshw,
45289 + .freebcshw = gigaset_freebcshw,
45290 + .reinitbcshw = gigaset_reinitbcshw,
45291 + .initcshw = gigaset_initcshw,
45292 + .freecshw = gigaset_freecshw,
45293 + .set_modem_ctrl = gigaset_set_modem_ctrl,
45294 + .baud_rate = gigaset_baud_rate,
45295 + .set_line_ctrl = gigaset_set_line_ctrl,
45296 + .send_skb = gigaset_m10x_send_skb, /* asyncdata.c */
45297 + .handle_input = gigaset_m10x_input, /* asyncdata.c */
45298 };
45299
45300
45301 diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
45302 index d0a41cb..b953e50 100644
45303 --- a/drivers/isdn/gigaset/usb-gigaset.c
45304 +++ b/drivers/isdn/gigaset/usb-gigaset.c
45305 @@ -547,7 +547,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
45306 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
45307 memcpy(cs->hw.usb->bchars, buf, 6);
45308 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
45309 - 0, 0, &buf, 6, 2000);
45310 + 0, 0, buf, 6, 2000);
45311 }
45312
45313 static void gigaset_freebcshw(struct bc_state *bcs)
45314 @@ -869,22 +869,22 @@ static int gigaset_pre_reset(struct usb_interface *intf)
45315 }
45316
45317 static const struct gigaset_ops ops = {
45318 - gigaset_write_cmd,
45319 - gigaset_write_room,
45320 - gigaset_chars_in_buffer,
45321 - gigaset_brkchars,
45322 - gigaset_init_bchannel,
45323 - gigaset_close_bchannel,
45324 - gigaset_initbcshw,
45325 - gigaset_freebcshw,
45326 - gigaset_reinitbcshw,
45327 - gigaset_initcshw,
45328 - gigaset_freecshw,
45329 - gigaset_set_modem_ctrl,
45330 - gigaset_baud_rate,
45331 - gigaset_set_line_ctrl,
45332 - gigaset_m10x_send_skb,
45333 - gigaset_m10x_input,
45334 + .write_cmd = gigaset_write_cmd,
45335 + .write_room = gigaset_write_room,
45336 + .chars_in_buffer = gigaset_chars_in_buffer,
45337 + .brkchars = gigaset_brkchars,
45338 + .init_bchannel = gigaset_init_bchannel,
45339 + .close_bchannel = gigaset_close_bchannel,
45340 + .initbcshw = gigaset_initbcshw,
45341 + .freebcshw = gigaset_freebcshw,
45342 + .reinitbcshw = gigaset_reinitbcshw,
45343 + .initcshw = gigaset_initcshw,
45344 + .freecshw = gigaset_freecshw,
45345 + .set_modem_ctrl = gigaset_set_modem_ctrl,
45346 + .baud_rate = gigaset_baud_rate,
45347 + .set_line_ctrl = gigaset_set_line_ctrl,
45348 + .send_skb = gigaset_m10x_send_skb,
45349 + .handle_input = gigaset_m10x_input,
45350 };
45351
45352 /*
45353 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
45354 index 4d9b195..455075c 100644
45355 --- a/drivers/isdn/hardware/avm/b1.c
45356 +++ b/drivers/isdn/hardware/avm/b1.c
45357 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
45358 }
45359 if (left) {
45360 if (t4file->user) {
45361 - if (copy_from_user(buf, dp, left))
45362 + if (left > sizeof buf || copy_from_user(buf, dp, left))
45363 return -EFAULT;
45364 } else {
45365 memcpy(buf, dp, left);
45366 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
45367 }
45368 if (left) {
45369 if (config->user) {
45370 - if (copy_from_user(buf, dp, left))
45371 + if (left > sizeof buf || copy_from_user(buf, dp, left))
45372 return -EFAULT;
45373 } else {
45374 memcpy(buf, dp, left);
45375 diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
45376 index 9b856e1..fa03c92 100644
45377 --- a/drivers/isdn/i4l/isdn_common.c
45378 +++ b/drivers/isdn/i4l/isdn_common.c
45379 @@ -1654,6 +1654,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
45380 } else
45381 return -EINVAL;
45382 case IIOCDBGVAR:
45383 + if (!capable(CAP_SYS_RAWIO))
45384 + return -EPERM;
45385 if (arg) {
45386 if (copy_to_user(argp, &dev, sizeof(ulong)))
45387 return -EFAULT;
45388 diff --git a/drivers/isdn/i4l/isdn_concap.c b/drivers/isdn/i4l/isdn_concap.c
45389 index 91d5730..336523e 100644
45390 --- a/drivers/isdn/i4l/isdn_concap.c
45391 +++ b/drivers/isdn/i4l/isdn_concap.c
45392 @@ -80,9 +80,9 @@ static int isdn_concap_dl_disconn_req(struct concap_proto *concap)
45393 }
45394
45395 struct concap_device_ops isdn_concap_reliable_dl_dops = {
45396 - &isdn_concap_dl_data_req,
45397 - &isdn_concap_dl_connect_req,
45398 - &isdn_concap_dl_disconn_req
45399 + .data_req = &isdn_concap_dl_data_req,
45400 + .connect_req = &isdn_concap_dl_connect_req,
45401 + .disconn_req = &isdn_concap_dl_disconn_req
45402 };
45403
45404 /* The following should better go into a dedicated source file such that
45405 diff --git a/drivers/isdn/i4l/isdn_ppp.c b/drivers/isdn/i4l/isdn_ppp.c
45406 index 62f0688..38ceac5 100644
45407 --- a/drivers/isdn/i4l/isdn_ppp.c
45408 +++ b/drivers/isdn/i4l/isdn_ppp.c
45409 @@ -378,15 +378,10 @@ isdn_ppp_release(int min, struct file *file)
45410 is->slcomp = NULL;
45411 #endif
45412 #ifdef CONFIG_IPPP_FILTER
45413 - if (is->pass_filter) {
45414 - sk_unattached_filter_destroy(is->pass_filter);
45415 - is->pass_filter = NULL;
45416 - }
45417 -
45418 - if (is->active_filter) {
45419 - sk_unattached_filter_destroy(is->active_filter);
45420 - is->active_filter = NULL;
45421 - }
45422 + kfree(is->pass_filter);
45423 + is->pass_filter = NULL;
45424 + kfree(is->active_filter);
45425 + is->active_filter = NULL;
45426 #endif
45427
45428 /* TODO: if this was the previous master: link the stuff to the new master */
45429 @@ -442,7 +437,7 @@ static int get_filter(void __user *arg, struct sock_filter **p)
45430 {
45431 struct sock_fprog uprog;
45432 struct sock_filter *code = NULL;
45433 - int len;
45434 + int len, err;
45435
45436 if (copy_from_user(&uprog, arg, sizeof(uprog)))
45437 return -EFAULT;
45438 @@ -458,6 +453,12 @@ static int get_filter(void __user *arg, struct sock_filter **p)
45439 if (IS_ERR(code))
45440 return PTR_ERR(code);
45441
45442 + err = sk_chk_filter(code, uprog.len);
45443 + if (err) {
45444 + kfree(code);
45445 + return err;
45446 + }
45447 +
45448 *p = code;
45449 return uprog.len;
45450 }
45451 @@ -628,53 +629,25 @@ isdn_ppp_ioctl(int min, struct file *file, unsigned int cmd, unsigned long arg)
45452 #ifdef CONFIG_IPPP_FILTER
45453 case PPPIOCSPASS:
45454 {
45455 - struct sock_fprog_kern fprog;
45456 struct sock_filter *code;
45457 - int err, len = get_filter(argp, &code);
45458 -
45459 + int len = get_filter(argp, &code);
45460 if (len < 0)
45461 return len;
45462 -
45463 - fprog.len = len;
45464 - fprog.filter = code;
45465 -
45466 - if (is->pass_filter) {
45467 - sk_unattached_filter_destroy(is->pass_filter);
45468 - is->pass_filter = NULL;
45469 - }
45470 - if (fprog.filter != NULL)
45471 - err = sk_unattached_filter_create(&is->pass_filter,
45472 - &fprog);
45473 - else
45474 - err = 0;
45475 - kfree(code);
45476 -
45477 - return err;
45478 + kfree(is->pass_filter);
45479 + is->pass_filter = code;
45480 + is->pass_len = len;
45481 + break;
45482 }
45483 case PPPIOCSACTIVE:
45484 {
45485 - struct sock_fprog_kern fprog;
45486 struct sock_filter *code;
45487 - int err, len = get_filter(argp, &code);
45488 -
45489 + int len = get_filter(argp, &code);
45490 if (len < 0)
45491 return len;
45492 -
45493 - fprog.len = len;
45494 - fprog.filter = code;
45495 -
45496 - if (is->active_filter) {
45497 - sk_unattached_filter_destroy(is->active_filter);
45498 - is->active_filter = NULL;
45499 - }
45500 - if (fprog.filter != NULL)
45501 - err = sk_unattached_filter_create(&is->active_filter,
45502 - &fprog);
45503 - else
45504 - err = 0;
45505 - kfree(code);
45506 -
45507 - return err;
45508 + kfree(is->active_filter);
45509 + is->active_filter = code;
45510 + is->active_len = len;
45511 + break;
45512 }
45513 #endif /* CONFIG_IPPP_FILTER */
45514 default:
45515 @@ -1174,14 +1147,14 @@ isdn_ppp_push_higher(isdn_net_dev *net_dev, isdn_net_local *lp, struct sk_buff *
45516 }
45517
45518 if (is->pass_filter
45519 - && SK_RUN_FILTER(is->pass_filter, skb) == 0) {
45520 + && sk_run_filter(skb, is->pass_filter) == 0) {
45521 if (is->debug & 0x2)
45522 printk(KERN_DEBUG "IPPP: inbound frame filtered.\n");
45523 kfree_skb(skb);
45524 return;
45525 }
45526 if (!(is->active_filter
45527 - && SK_RUN_FILTER(is->active_filter, skb) == 0)) {
45528 + && sk_run_filter(skb, is->active_filter) == 0)) {
45529 if (is->debug & 0x2)
45530 printk(KERN_DEBUG "IPPP: link-active filter: resetting huptimer.\n");
45531 lp->huptimer = 0;
45532 @@ -1320,14 +1293,14 @@ isdn_ppp_xmit(struct sk_buff *skb, struct net_device *netdev)
45533 }
45534
45535 if (ipt->pass_filter
45536 - && SK_RUN_FILTER(ipt->pass_filter, skb) == 0) {
45537 + && sk_run_filter(skb, ipt->pass_filter) == 0) {
45538 if (ipt->debug & 0x4)
45539 printk(KERN_DEBUG "IPPP: outbound frame filtered.\n");
45540 kfree_skb(skb);
45541 goto unlock;
45542 }
45543 if (!(ipt->active_filter
45544 - && SK_RUN_FILTER(ipt->active_filter, skb) == 0)) {
45545 + && sk_run_filter(skb, ipt->active_filter) == 0)) {
45546 if (ipt->debug & 0x4)
45547 printk(KERN_DEBUG "IPPP: link-active filter: resetting huptimer.\n");
45548 lp->huptimer = 0;
45549 @@ -1517,9 +1490,9 @@ int isdn_ppp_autodial_filter(struct sk_buff *skb, isdn_net_local *lp)
45550 }
45551
45552 drop |= is->pass_filter
45553 - && SK_RUN_FILTER(is->pass_filter, skb) == 0;
45554 + && sk_run_filter(skb, is->pass_filter) == 0;
45555 drop |= is->active_filter
45556 - && SK_RUN_FILTER(is->active_filter, skb) == 0;
45557 + && sk_run_filter(skb, is->active_filter) == 0;
45558
45559 skb_push(skb, IPPP_MAX_HEADER - 4);
45560 return drop;
45561 diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
45562 index 3c5f249..5fac4d0 100644
45563 --- a/drivers/isdn/i4l/isdn_tty.c
45564 +++ b/drivers/isdn/i4l/isdn_tty.c
45565 @@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
45566
45567 #ifdef ISDN_DEBUG_MODEM_OPEN
45568 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
45569 - port->count);
45570 + atomic_read(&port->count));
45571 #endif
45572 - port->count++;
45573 + atomic_inc(&port->count);
45574 port->tty = tty;
45575 /*
45576 * Start up serial port
45577 @@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
45578 #endif
45579 return;
45580 }
45581 - if ((tty->count == 1) && (port->count != 1)) {
45582 + if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
45583 /*
45584 * Uh, oh. tty->count is 1, which means that the tty
45585 * structure will be freed. Info->count should always
45586 @@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
45587 * serial port won't be shutdown.
45588 */
45589 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
45590 - "info->count is %d\n", port->count);
45591 - port->count = 1;
45592 + "info->count is %d\n", atomic_read(&port->count));
45593 + atomic_set(&port->count, 1);
45594 }
45595 - if (--port->count < 0) {
45596 + if (atomic_dec_return(&port->count) < 0) {
45597 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
45598 - info->line, port->count);
45599 - port->count = 0;
45600 + info->line, atomic_read(&port->count));
45601 + atomic_set(&port->count, 0);
45602 }
45603 - if (port->count) {
45604 + if (atomic_read(&port->count)) {
45605 #ifdef ISDN_DEBUG_MODEM_OPEN
45606 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
45607 #endif
45608 @@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
45609 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
45610 return;
45611 isdn_tty_shutdown(info);
45612 - port->count = 0;
45613 + atomic_set(&port->count, 0);
45614 port->flags &= ~ASYNC_NORMAL_ACTIVE;
45615 port->tty = NULL;
45616 wake_up_interruptible(&port->open_wait);
45617 @@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
45618 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
45619 modem_info *info = &dev->mdm.info[i];
45620
45621 - if (info->port.count == 0)
45622 + if (atomic_read(&info->port.count) == 0)
45623 continue;
45624 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
45625 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
45626 diff --git a/drivers/isdn/i4l/isdn_x25iface.c b/drivers/isdn/i4l/isdn_x25iface.c
45627 index e2d4e58..40cd045 100644
45628 --- a/drivers/isdn/i4l/isdn_x25iface.c
45629 +++ b/drivers/isdn/i4l/isdn_x25iface.c
45630 @@ -53,14 +53,14 @@ static int isdn_x25iface_disconn_ind(struct concap_proto *);
45631
45632
45633 static struct concap_proto_ops ix25_pops = {
45634 - &isdn_x25iface_proto_new,
45635 - &isdn_x25iface_proto_del,
45636 - &isdn_x25iface_proto_restart,
45637 - &isdn_x25iface_proto_close,
45638 - &isdn_x25iface_xmit,
45639 - &isdn_x25iface_receive,
45640 - &isdn_x25iface_connect_ind,
45641 - &isdn_x25iface_disconn_ind
45642 + .proto_new = &isdn_x25iface_proto_new,
45643 + .proto_del = &isdn_x25iface_proto_del,
45644 + .restart = &isdn_x25iface_proto_restart,
45645 + .close = &isdn_x25iface_proto_close,
45646 + .encap_and_xmit = &isdn_x25iface_xmit,
45647 + .data_ind = &isdn_x25iface_receive,
45648 + .connect_ind = &isdn_x25iface_connect_ind,
45649 + .disconn_ind = &isdn_x25iface_disconn_ind
45650 };
45651
45652 /* error message helper function */
45653 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
45654 index 6a7447c..cae33fe 100644
45655 --- a/drivers/isdn/icn/icn.c
45656 +++ b/drivers/isdn/icn/icn.c
45657 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
45658 if (count > len)
45659 count = len;
45660 if (user) {
45661 - if (copy_from_user(msg, buf, count))
45662 + if (count > sizeof msg || copy_from_user(msg, buf, count))
45663 return -EFAULT;
45664 } else
45665 memcpy(msg, buf, count);
45666 diff --git a/drivers/isdn/mISDN/dsp_cmx.c b/drivers/isdn/mISDN/dsp_cmx.c
45667 index a4f05c5..1433bc5 100644
45668 --- a/drivers/isdn/mISDN/dsp_cmx.c
45669 +++ b/drivers/isdn/mISDN/dsp_cmx.c
45670 @@ -1628,7 +1628,7 @@ unsigned long dsp_spl_jiffies; /* calculate the next time to fire */
45671 static u16 dsp_count; /* last sample count */
45672 static int dsp_count_valid; /* if we have last sample count */
45673
45674 -void
45675 +void __intentional_overflow(-1)
45676 dsp_cmx_send(void *arg)
45677 {
45678 struct dsp_conf *conf;
45679 diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
45680 index f58a354..fbae176 100644
45681 --- a/drivers/leds/leds-clevo-mail.c
45682 +++ b/drivers/leds/leds-clevo-mail.c
45683 @@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
45684 * detected as working, but in reality it is not) as low as
45685 * possible.
45686 */
45687 -static struct dmi_system_id clevo_mail_led_dmi_table[] __initdata = {
45688 +static struct dmi_system_id clevo_mail_led_dmi_table[] __initconst = {
45689 {
45690 .callback = clevo_mail_led_dmi_callback,
45691 .ident = "Clevo D410J",
45692 diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
45693 index 2eb3ef6..295891f 100644
45694 --- a/drivers/leds/leds-ss4200.c
45695 +++ b/drivers/leds/leds-ss4200.c
45696 @@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
45697 * detected as working, but in reality it is not) as low as
45698 * possible.
45699 */
45700 -static struct dmi_system_id nas_led_whitelist[] __initdata = {
45701 +static struct dmi_system_id nas_led_whitelist[] __initconst = {
45702 {
45703 .callback = ss4200_led_dmi_callback,
45704 .ident = "Intel SS4200-E",
45705 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
45706 index 0bf1e4e..b4bf44e 100644
45707 --- a/drivers/lguest/core.c
45708 +++ b/drivers/lguest/core.c
45709 @@ -97,9 +97,17 @@ static __init int map_switcher(void)
45710 * The end address needs +1 because __get_vm_area allocates an
45711 * extra guard page, so we need space for that.
45712 */
45713 +
45714 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
45715 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
45716 + VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
45717 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
45718 +#else
45719 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
45720 VM_ALLOC, switcher_addr, switcher_addr
45721 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
45722 +#endif
45723 +
45724 if (!switcher_vma) {
45725 err = -ENOMEM;
45726 printk("lguest: could not map switcher pages high\n");
45727 @@ -124,7 +132,7 @@ static __init int map_switcher(void)
45728 * Now the Switcher is mapped at the right address, we can't fail!
45729 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
45730 */
45731 - memcpy(switcher_vma->addr, start_switcher_text,
45732 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
45733 end_switcher_text - start_switcher_text);
45734
45735 printk(KERN_INFO "lguest: mapped switcher at %p\n",
45736 diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
45737 index e8b55c3..3514c37 100644
45738 --- a/drivers/lguest/page_tables.c
45739 +++ b/drivers/lguest/page_tables.c
45740 @@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
45741 /*:*/
45742
45743 #ifdef CONFIG_X86_PAE
45744 -static void release_pmd(pmd_t *spmd)
45745 +static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
45746 {
45747 /* If the entry's not present, there's nothing to release. */
45748 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
45749 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
45750 index 922a1ac..9dd0c2a 100644
45751 --- a/drivers/lguest/x86/core.c
45752 +++ b/drivers/lguest/x86/core.c
45753 @@ -59,7 +59,7 @@ static struct {
45754 /* Offset from where switcher.S was compiled to where we've copied it */
45755 static unsigned long switcher_offset(void)
45756 {
45757 - return switcher_addr - (unsigned long)start_switcher_text;
45758 + return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
45759 }
45760
45761 /* This cpu's struct lguest_pages (after the Switcher text page) */
45762 @@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
45763 * These copies are pretty cheap, so we do them unconditionally: */
45764 /* Save the current Host top-level page directory.
45765 */
45766 +
45767 +#ifdef CONFIG_PAX_PER_CPU_PGD
45768 + pages->state.host_cr3 = read_cr3();
45769 +#else
45770 pages->state.host_cr3 = __pa(current->mm->pgd);
45771 +#endif
45772 +
45773 /*
45774 * Set up the Guest's page tables to see this CPU's pages (and no
45775 * other CPU's pages).
45776 @@ -477,7 +483,7 @@ void __init lguest_arch_host_init(void)
45777 * compiled-in switcher code and the high-mapped copy we just made.
45778 */
45779 for (i = 0; i < IDT_ENTRIES; i++)
45780 - default_idt_entries[i] += switcher_offset();
45781 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
45782
45783 /*
45784 * Set up the Switcher's per-cpu areas.
45785 @@ -560,7 +566,7 @@ void __init lguest_arch_host_init(void)
45786 * it will be undisturbed when we switch. To change %cs and jump we
45787 * need this structure to feed to Intel's "lcall" instruction.
45788 */
45789 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
45790 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
45791 lguest_entry.segment = LGUEST_CS;
45792
45793 /*
45794 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
45795 index 40634b0..4f5855e 100644
45796 --- a/drivers/lguest/x86/switcher_32.S
45797 +++ b/drivers/lguest/x86/switcher_32.S
45798 @@ -87,6 +87,7 @@
45799 #include <asm/page.h>
45800 #include <asm/segment.h>
45801 #include <asm/lguest.h>
45802 +#include <asm/processor-flags.h>
45803
45804 // We mark the start of the code to copy
45805 // It's placed in .text tho it's never run here
45806 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
45807 // Changes type when we load it: damn Intel!
45808 // For after we switch over our page tables
45809 // That entry will be read-only: we'd crash.
45810 +
45811 +#ifdef CONFIG_PAX_KERNEXEC
45812 + mov %cr0, %edx
45813 + xor $X86_CR0_WP, %edx
45814 + mov %edx, %cr0
45815 +#endif
45816 +
45817 movl $(GDT_ENTRY_TSS*8), %edx
45818 ltr %dx
45819
45820 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
45821 // Let's clear it again for our return.
45822 // The GDT descriptor of the Host
45823 // Points to the table after two "size" bytes
45824 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
45825 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
45826 // Clear "used" from type field (byte 5, bit 2)
45827 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
45828 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
45829 +
45830 +#ifdef CONFIG_PAX_KERNEXEC
45831 + mov %cr0, %eax
45832 + xor $X86_CR0_WP, %eax
45833 + mov %eax, %cr0
45834 +#endif
45835
45836 // Once our page table's switched, the Guest is live!
45837 // The Host fades as we run this final step.
45838 @@ -295,13 +309,12 @@ deliver_to_host:
45839 // I consulted gcc, and it gave
45840 // These instructions, which I gladly credit:
45841 leal (%edx,%ebx,8), %eax
45842 - movzwl (%eax),%edx
45843 - movl 4(%eax), %eax
45844 - xorw %ax, %ax
45845 - orl %eax, %edx
45846 + movl 4(%eax), %edx
45847 + movw (%eax), %dx
45848 // Now the address of the handler's in %edx
45849 // We call it now: its "iret" drops us home.
45850 - jmp *%edx
45851 + ljmp $__KERNEL_CS, $1f
45852 +1: jmp *%edx
45853
45854 // Every interrupt can come to us here
45855 // But we must truly tell each apart.
45856 diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
45857 index a08e3ee..df8ade2 100644
45858 --- a/drivers/md/bcache/closure.h
45859 +++ b/drivers/md/bcache/closure.h
45860 @@ -238,7 +238,7 @@ static inline void closure_set_stopped(struct closure *cl)
45861 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
45862 struct workqueue_struct *wq)
45863 {
45864 - BUG_ON(object_is_on_stack(cl));
45865 + BUG_ON(object_starts_on_stack(cl));
45866 closure_set_ip(cl);
45867 cl->fn = fn;
45868 cl->wq = wq;
45869 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
45870 index 67f8b31..9418f2b 100644
45871 --- a/drivers/md/bitmap.c
45872 +++ b/drivers/md/bitmap.c
45873 @@ -1775,7 +1775,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
45874 chunk_kb ? "KB" : "B");
45875 if (bitmap->storage.file) {
45876 seq_printf(seq, ", file: ");
45877 - seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
45878 + seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
45879 }
45880
45881 seq_printf(seq, "\n");
45882 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
45883 index 5152142..623d141 100644
45884 --- a/drivers/md/dm-ioctl.c
45885 +++ b/drivers/md/dm-ioctl.c
45886 @@ -1769,7 +1769,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
45887 cmd == DM_LIST_VERSIONS_CMD)
45888 return 0;
45889
45890 - if ((cmd == DM_DEV_CREATE_CMD)) {
45891 + if (cmd == DM_DEV_CREATE_CMD) {
45892 if (!*param->name) {
45893 DMWARN("name not supplied when creating device");
45894 return -EINVAL;
45895 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
45896 index 7dfdb5c..4caada6 100644
45897 --- a/drivers/md/dm-raid1.c
45898 +++ b/drivers/md/dm-raid1.c
45899 @@ -40,7 +40,7 @@ enum dm_raid1_error {
45900
45901 struct mirror {
45902 struct mirror_set *ms;
45903 - atomic_t error_count;
45904 + atomic_unchecked_t error_count;
45905 unsigned long error_type;
45906 struct dm_dev *dev;
45907 sector_t offset;
45908 @@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
45909 struct mirror *m;
45910
45911 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
45912 - if (!atomic_read(&m->error_count))
45913 + if (!atomic_read_unchecked(&m->error_count))
45914 return m;
45915
45916 return NULL;
45917 @@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
45918 * simple way to tell if a device has encountered
45919 * errors.
45920 */
45921 - atomic_inc(&m->error_count);
45922 + atomic_inc_unchecked(&m->error_count);
45923
45924 if (test_and_set_bit(error_type, &m->error_type))
45925 return;
45926 @@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
45927 struct mirror *m = get_default_mirror(ms);
45928
45929 do {
45930 - if (likely(!atomic_read(&m->error_count)))
45931 + if (likely(!atomic_read_unchecked(&m->error_count)))
45932 return m;
45933
45934 if (m-- == ms->mirror)
45935 @@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
45936 {
45937 struct mirror *default_mirror = get_default_mirror(m->ms);
45938
45939 - return !atomic_read(&default_mirror->error_count);
45940 + return !atomic_read_unchecked(&default_mirror->error_count);
45941 }
45942
45943 static int mirror_available(struct mirror_set *ms, struct bio *bio)
45944 @@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
45945 */
45946 if (likely(region_in_sync(ms, region, 1)))
45947 m = choose_mirror(ms, bio->bi_iter.bi_sector);
45948 - else if (m && atomic_read(&m->error_count))
45949 + else if (m && atomic_read_unchecked(&m->error_count))
45950 m = NULL;
45951
45952 if (likely(m))
45953 @@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
45954 }
45955
45956 ms->mirror[mirror].ms = ms;
45957 - atomic_set(&(ms->mirror[mirror].error_count), 0);
45958 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
45959 ms->mirror[mirror].error_type = 0;
45960 ms->mirror[mirror].offset = offset;
45961
45962 @@ -1342,7 +1342,7 @@ static void mirror_resume(struct dm_target *ti)
45963 */
45964 static char device_status_char(struct mirror *m)
45965 {
45966 - if (!atomic_read(&(m->error_count)))
45967 + if (!atomic_read_unchecked(&(m->error_count)))
45968 return 'A';
45969
45970 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
45971 diff --git a/drivers/md/dm-stats.c b/drivers/md/dm-stats.c
45972 index 28a9012..9c0f6a5 100644
45973 --- a/drivers/md/dm-stats.c
45974 +++ b/drivers/md/dm-stats.c
45975 @@ -382,7 +382,7 @@ do_sync_free:
45976 synchronize_rcu_expedited();
45977 dm_stat_free(&s->rcu_head);
45978 } else {
45979 - ACCESS_ONCE(dm_stat_need_rcu_barrier) = 1;
45980 + ACCESS_ONCE_RW(dm_stat_need_rcu_barrier) = 1;
45981 call_rcu(&s->rcu_head, dm_stat_free);
45982 }
45983 return 0;
45984 @@ -554,8 +554,8 @@ void dm_stats_account_io(struct dm_stats *stats, unsigned long bi_rw,
45985 ((bi_rw & (REQ_WRITE | REQ_DISCARD)) ==
45986 (ACCESS_ONCE(last->last_rw) & (REQ_WRITE | REQ_DISCARD)))
45987 ));
45988 - ACCESS_ONCE(last->last_sector) = end_sector;
45989 - ACCESS_ONCE(last->last_rw) = bi_rw;
45990 + ACCESS_ONCE_RW(last->last_sector) = end_sector;
45991 + ACCESS_ONCE_RW(last->last_rw) = bi_rw;
45992 }
45993
45994 rcu_read_lock();
45995 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
45996 index d1600d2..4c3af3a 100644
45997 --- a/drivers/md/dm-stripe.c
45998 +++ b/drivers/md/dm-stripe.c
45999 @@ -21,7 +21,7 @@ struct stripe {
46000 struct dm_dev *dev;
46001 sector_t physical_start;
46002
46003 - atomic_t error_count;
46004 + atomic_unchecked_t error_count;
46005 };
46006
46007 struct stripe_c {
46008 @@ -186,7 +186,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
46009 kfree(sc);
46010 return r;
46011 }
46012 - atomic_set(&(sc->stripe[i].error_count), 0);
46013 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
46014 }
46015
46016 ti->private = sc;
46017 @@ -330,7 +330,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
46018 DMEMIT("%d ", sc->stripes);
46019 for (i = 0; i < sc->stripes; i++) {
46020 DMEMIT("%s ", sc->stripe[i].dev->name);
46021 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
46022 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
46023 'D' : 'A';
46024 }
46025 buffer[i] = '\0';
46026 @@ -375,8 +375,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
46027 */
46028 for (i = 0; i < sc->stripes; i++)
46029 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
46030 - atomic_inc(&(sc->stripe[i].error_count));
46031 - if (atomic_read(&(sc->stripe[i].error_count)) <
46032 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
46033 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
46034 DM_IO_ERROR_THRESHOLD)
46035 schedule_work(&sc->trigger_event);
46036 }
46037 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
46038 index 5f59f1e..01bd02e 100644
46039 --- a/drivers/md/dm-table.c
46040 +++ b/drivers/md/dm-table.c
46041 @@ -274,7 +274,7 @@ static struct dm_dev_internal *find_device(struct list_head *l, dev_t dev)
46042 static int open_dev(struct dm_dev_internal *d, dev_t dev,
46043 struct mapped_device *md)
46044 {
46045 - static char *_claim_ptr = "I belong to device-mapper";
46046 + static char _claim_ptr[] = "I belong to device-mapper";
46047 struct block_device *bdev;
46048
46049 int r;
46050 @@ -342,7 +342,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
46051 if (!dev_size)
46052 return 0;
46053
46054 - if ((start >= dev_size) || (start + len > dev_size)) {
46055 + if ((start >= dev_size) || (len > dev_size - start)) {
46056 DMWARN("%s: %s too small for target: "
46057 "start=%llu, len=%llu, dev_size=%llu",
46058 dm_device_name(ti->table->md), bdevname(bdev, b),
46059 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
46060 index e9d33ad..dae9880d 100644
46061 --- a/drivers/md/dm-thin-metadata.c
46062 +++ b/drivers/md/dm-thin-metadata.c
46063 @@ -404,7 +404,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
46064 {
46065 pmd->info.tm = pmd->tm;
46066 pmd->info.levels = 2;
46067 - pmd->info.value_type.context = pmd->data_sm;
46068 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
46069 pmd->info.value_type.size = sizeof(__le64);
46070 pmd->info.value_type.inc = data_block_inc;
46071 pmd->info.value_type.dec = data_block_dec;
46072 @@ -423,7 +423,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
46073
46074 pmd->bl_info.tm = pmd->tm;
46075 pmd->bl_info.levels = 1;
46076 - pmd->bl_info.value_type.context = pmd->data_sm;
46077 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
46078 pmd->bl_info.value_type.size = sizeof(__le64);
46079 pmd->bl_info.value_type.inc = data_block_inc;
46080 pmd->bl_info.value_type.dec = data_block_dec;
46081 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
46082 index 32b958d..34011e8 100644
46083 --- a/drivers/md/dm.c
46084 +++ b/drivers/md/dm.c
46085 @@ -180,9 +180,9 @@ struct mapped_device {
46086 /*
46087 * Event handling.
46088 */
46089 - atomic_t event_nr;
46090 + atomic_unchecked_t event_nr;
46091 wait_queue_head_t eventq;
46092 - atomic_t uevent_seq;
46093 + atomic_unchecked_t uevent_seq;
46094 struct list_head uevent_list;
46095 spinlock_t uevent_lock; /* Protect access to uevent_list */
46096
46097 @@ -1952,8 +1952,8 @@ static struct mapped_device *alloc_dev(int minor)
46098 spin_lock_init(&md->deferred_lock);
46099 atomic_set(&md->holders, 1);
46100 atomic_set(&md->open_count, 0);
46101 - atomic_set(&md->event_nr, 0);
46102 - atomic_set(&md->uevent_seq, 0);
46103 + atomic_set_unchecked(&md->event_nr, 0);
46104 + atomic_set_unchecked(&md->uevent_seq, 0);
46105 INIT_LIST_HEAD(&md->uevent_list);
46106 spin_lock_init(&md->uevent_lock);
46107
46108 @@ -2107,7 +2107,7 @@ static void event_callback(void *context)
46109
46110 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
46111
46112 - atomic_inc(&md->event_nr);
46113 + atomic_inc_unchecked(&md->event_nr);
46114 wake_up(&md->eventq);
46115 }
46116
46117 @@ -2800,18 +2800,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
46118
46119 uint32_t dm_next_uevent_seq(struct mapped_device *md)
46120 {
46121 - return atomic_add_return(1, &md->uevent_seq);
46122 + return atomic_add_return_unchecked(1, &md->uevent_seq);
46123 }
46124
46125 uint32_t dm_get_event_nr(struct mapped_device *md)
46126 {
46127 - return atomic_read(&md->event_nr);
46128 + return atomic_read_unchecked(&md->event_nr);
46129 }
46130
46131 int dm_wait_event(struct mapped_device *md, int event_nr)
46132 {
46133 return wait_event_interruptible(md->eventq,
46134 - (event_nr != atomic_read(&md->event_nr)));
46135 + (event_nr != atomic_read_unchecked(&md->event_nr)));
46136 }
46137
46138 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
46139 diff --git a/drivers/md/md.c b/drivers/md/md.c
46140 index 32fc19c..cb6eba3 100644
46141 --- a/drivers/md/md.c
46142 +++ b/drivers/md/md.c
46143 @@ -194,10 +194,10 @@ EXPORT_SYMBOL_GPL(bio_clone_mddev);
46144 * start build, activate spare
46145 */
46146 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
46147 -static atomic_t md_event_count;
46148 +static atomic_unchecked_t md_event_count;
46149 void md_new_event(struct mddev *mddev)
46150 {
46151 - atomic_inc(&md_event_count);
46152 + atomic_inc_unchecked(&md_event_count);
46153 wake_up(&md_event_waiters);
46154 }
46155 EXPORT_SYMBOL_GPL(md_new_event);
46156 @@ -207,7 +207,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
46157 */
46158 static void md_new_event_inintr(struct mddev *mddev)
46159 {
46160 - atomic_inc(&md_event_count);
46161 + atomic_inc_unchecked(&md_event_count);
46162 wake_up(&md_event_waiters);
46163 }
46164
46165 @@ -1462,7 +1462,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
46166 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
46167 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
46168 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
46169 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
46170 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
46171
46172 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
46173 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
46174 @@ -1713,7 +1713,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
46175 else
46176 sb->resync_offset = cpu_to_le64(0);
46177
46178 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
46179 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
46180
46181 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
46182 sb->size = cpu_to_le64(mddev->dev_sectors);
46183 @@ -2725,7 +2725,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
46184 static ssize_t
46185 errors_show(struct md_rdev *rdev, char *page)
46186 {
46187 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
46188 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
46189 }
46190
46191 static ssize_t
46192 @@ -2734,7 +2734,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
46193 char *e;
46194 unsigned long n = simple_strtoul(buf, &e, 10);
46195 if (*buf && (*e == 0 || *e == '\n')) {
46196 - atomic_set(&rdev->corrected_errors, n);
46197 + atomic_set_unchecked(&rdev->corrected_errors, n);
46198 return len;
46199 }
46200 return -EINVAL;
46201 @@ -3183,8 +3183,8 @@ int md_rdev_init(struct md_rdev *rdev)
46202 rdev->sb_loaded = 0;
46203 rdev->bb_page = NULL;
46204 atomic_set(&rdev->nr_pending, 0);
46205 - atomic_set(&rdev->read_errors, 0);
46206 - atomic_set(&rdev->corrected_errors, 0);
46207 + atomic_set_unchecked(&rdev->read_errors, 0);
46208 + atomic_set_unchecked(&rdev->corrected_errors, 0);
46209
46210 INIT_LIST_HEAD(&rdev->same_set);
46211 init_waitqueue_head(&rdev->blocked_wait);
46212 @@ -7068,7 +7068,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
46213
46214 spin_unlock(&pers_lock);
46215 seq_printf(seq, "\n");
46216 - seq->poll_event = atomic_read(&md_event_count);
46217 + seq->poll_event = atomic_read_unchecked(&md_event_count);
46218 return 0;
46219 }
46220 if (v == (void*)2) {
46221 @@ -7171,7 +7171,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
46222 return error;
46223
46224 seq = file->private_data;
46225 - seq->poll_event = atomic_read(&md_event_count);
46226 + seq->poll_event = atomic_read_unchecked(&md_event_count);
46227 return error;
46228 }
46229
46230 @@ -7188,7 +7188,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
46231 /* always allow read */
46232 mask = POLLIN | POLLRDNORM;
46233
46234 - if (seq->poll_event != atomic_read(&md_event_count))
46235 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
46236 mask |= POLLERR | POLLPRI;
46237 return mask;
46238 }
46239 @@ -7232,7 +7232,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
46240 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
46241 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
46242 (int)part_stat_read(&disk->part0, sectors[1]) -
46243 - atomic_read(&disk->sync_io);
46244 + atomic_read_unchecked(&disk->sync_io);
46245 /* sync IO will cause sync_io to increase before the disk_stats
46246 * as sync_io is counted when a request starts, and
46247 * disk_stats is counted when it completes.
46248 diff --git a/drivers/md/md.h b/drivers/md/md.h
46249 index a49d991..3582bb7 100644
46250 --- a/drivers/md/md.h
46251 +++ b/drivers/md/md.h
46252 @@ -94,13 +94,13 @@ struct md_rdev {
46253 * only maintained for arrays that
46254 * support hot removal
46255 */
46256 - atomic_t read_errors; /* number of consecutive read errors that
46257 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
46258 * we have tried to ignore.
46259 */
46260 struct timespec last_read_error; /* monotonic time since our
46261 * last read error
46262 */
46263 - atomic_t corrected_errors; /* number of corrected read errors,
46264 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
46265 * for reporting to userspace and storing
46266 * in superblock.
46267 */
46268 @@ -449,7 +449,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
46269
46270 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
46271 {
46272 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
46273 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
46274 }
46275
46276 struct md_personality
46277 diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
46278 index 786b689..ea8c956 100644
46279 --- a/drivers/md/persistent-data/dm-space-map-metadata.c
46280 +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
46281 @@ -679,7 +679,7 @@ static int sm_metadata_extend(struct dm_space_map *sm, dm_block_t extra_blocks)
46282 * Flick into a mode where all blocks get allocated in the new area.
46283 */
46284 smm->begin = old_len;
46285 - memcpy(sm, &bootstrap_ops, sizeof(*sm));
46286 + memcpy((void *)sm, &bootstrap_ops, sizeof(*sm));
46287
46288 /*
46289 * Extend.
46290 @@ -710,7 +710,7 @@ out:
46291 /*
46292 * Switch back to normal behaviour.
46293 */
46294 - memcpy(sm, &ops, sizeof(*sm));
46295 + memcpy((void *)sm, &ops, sizeof(*sm));
46296 return r;
46297 }
46298
46299 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
46300 index 3e6d115..ffecdeb 100644
46301 --- a/drivers/md/persistent-data/dm-space-map.h
46302 +++ b/drivers/md/persistent-data/dm-space-map.h
46303 @@ -71,6 +71,7 @@ struct dm_space_map {
46304 dm_sm_threshold_fn fn,
46305 void *context);
46306 };
46307 +typedef struct dm_space_map __no_const dm_space_map_no_const;
46308
46309 /*----------------------------------------------------------------*/
46310
46311 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
46312 index 56e24c0..e1c8e1f 100644
46313 --- a/drivers/md/raid1.c
46314 +++ b/drivers/md/raid1.c
46315 @@ -1931,7 +1931,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
46316 if (r1_sync_page_io(rdev, sect, s,
46317 bio->bi_io_vec[idx].bv_page,
46318 READ) != 0)
46319 - atomic_add(s, &rdev->corrected_errors);
46320 + atomic_add_unchecked(s, &rdev->corrected_errors);
46321 }
46322 sectors -= s;
46323 sect += s;
46324 @@ -2165,7 +2165,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
46325 test_bit(In_sync, &rdev->flags)) {
46326 if (r1_sync_page_io(rdev, sect, s,
46327 conf->tmppage, READ)) {
46328 - atomic_add(s, &rdev->corrected_errors);
46329 + atomic_add_unchecked(s, &rdev->corrected_errors);
46330 printk(KERN_INFO
46331 "md/raid1:%s: read error corrected "
46332 "(%d sectors at %llu on %s)\n",
46333 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
46334 index cb882aa..cb8aeca 100644
46335 --- a/drivers/md/raid10.c
46336 +++ b/drivers/md/raid10.c
46337 @@ -1949,7 +1949,7 @@ static void end_sync_read(struct bio *bio, int error)
46338 /* The write handler will notice the lack of
46339 * R10BIO_Uptodate and record any errors etc
46340 */
46341 - atomic_add(r10_bio->sectors,
46342 + atomic_add_unchecked(r10_bio->sectors,
46343 &conf->mirrors[d].rdev->corrected_errors);
46344
46345 /* for reconstruct, we always reschedule after a read.
46346 @@ -2307,7 +2307,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
46347 {
46348 struct timespec cur_time_mon;
46349 unsigned long hours_since_last;
46350 - unsigned int read_errors = atomic_read(&rdev->read_errors);
46351 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
46352
46353 ktime_get_ts(&cur_time_mon);
46354
46355 @@ -2329,9 +2329,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
46356 * overflowing the shift of read_errors by hours_since_last.
46357 */
46358 if (hours_since_last >= 8 * sizeof(read_errors))
46359 - atomic_set(&rdev->read_errors, 0);
46360 + atomic_set_unchecked(&rdev->read_errors, 0);
46361 else
46362 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
46363 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
46364 }
46365
46366 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
46367 @@ -2385,8 +2385,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
46368 return;
46369
46370 check_decay_read_errors(mddev, rdev);
46371 - atomic_inc(&rdev->read_errors);
46372 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
46373 + atomic_inc_unchecked(&rdev->read_errors);
46374 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
46375 char b[BDEVNAME_SIZE];
46376 bdevname(rdev->bdev, b);
46377
46378 @@ -2394,7 +2394,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
46379 "md/raid10:%s: %s: Raid device exceeded "
46380 "read_error threshold [cur %d:max %d]\n",
46381 mdname(mddev), b,
46382 - atomic_read(&rdev->read_errors), max_read_errors);
46383 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
46384 printk(KERN_NOTICE
46385 "md/raid10:%s: %s: Failing raid device\n",
46386 mdname(mddev), b);
46387 @@ -2549,7 +2549,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
46388 sect +
46389 choose_data_offset(r10_bio, rdev)),
46390 bdevname(rdev->bdev, b));
46391 - atomic_add(s, &rdev->corrected_errors);
46392 + atomic_add_unchecked(s, &rdev->corrected_errors);
46393 }
46394
46395 rdev_dec_pending(rdev, mddev);
46396 @@ -2954,6 +2954,7 @@ static sector_t sync_request(struct mddev *mddev, sector_t sector_nr,
46397 */
46398 if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery)) {
46399 end_reshape(conf);
46400 + close_sync(conf);
46401 return 0;
46402 }
46403
46404 @@ -4411,7 +4412,7 @@ read_more:
46405 read_bio->bi_private = r10_bio;
46406 read_bio->bi_end_io = end_sync_read;
46407 read_bio->bi_rw = READ;
46408 - read_bio->bi_flags &= ~(BIO_POOL_MASK - 1);
46409 + read_bio->bi_flags &= (~0UL << BIO_RESET_BITS);
46410 read_bio->bi_flags |= 1 << BIO_UPTODATE;
46411 read_bio->bi_vcnt = 0;
46412 read_bio->bi_iter.bi_size = 0;
46413 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
46414 index 6234b2e..4990801 100644
46415 --- a/drivers/md/raid5.c
46416 +++ b/drivers/md/raid5.c
46417 @@ -1731,6 +1731,10 @@ static int grow_one_stripe(struct r5conf *conf, int hash)
46418 return 1;
46419 }
46420
46421 +#ifdef CONFIG_GRKERNSEC_HIDESYM
46422 +static atomic_unchecked_t raid5_cache_id = ATOMIC_INIT(0);
46423 +#endif
46424 +
46425 static int grow_stripes(struct r5conf *conf, int num)
46426 {
46427 struct kmem_cache *sc;
46428 @@ -1742,7 +1746,11 @@ static int grow_stripes(struct r5conf *conf, int num)
46429 "raid%d-%s", conf->level, mdname(conf->mddev));
46430 else
46431 sprintf(conf->cache_name[0],
46432 +#ifdef CONFIG_GRKERNSEC_HIDESYM
46433 + "raid%d-%08lx", conf->level, atomic_inc_return_unchecked(&raid5_cache_id));
46434 +#else
46435 "raid%d-%p", conf->level, conf->mddev);
46436 +#endif
46437 sprintf(conf->cache_name[1], "%s-alt", conf->cache_name[0]);
46438
46439 conf->active_name = 0;
46440 @@ -2018,21 +2026,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
46441 mdname(conf->mddev), STRIPE_SECTORS,
46442 (unsigned long long)s,
46443 bdevname(rdev->bdev, b));
46444 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
46445 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
46446 clear_bit(R5_ReadError, &sh->dev[i].flags);
46447 clear_bit(R5_ReWrite, &sh->dev[i].flags);
46448 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
46449 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
46450
46451 - if (atomic_read(&rdev->read_errors))
46452 - atomic_set(&rdev->read_errors, 0);
46453 + if (atomic_read_unchecked(&rdev->read_errors))
46454 + atomic_set_unchecked(&rdev->read_errors, 0);
46455 } else {
46456 const char *bdn = bdevname(rdev->bdev, b);
46457 int retry = 0;
46458 int set_bad = 0;
46459
46460 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
46461 - atomic_inc(&rdev->read_errors);
46462 + atomic_inc_unchecked(&rdev->read_errors);
46463 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
46464 printk_ratelimited(
46465 KERN_WARNING
46466 @@ -2060,7 +2068,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
46467 mdname(conf->mddev),
46468 (unsigned long long)s,
46469 bdn);
46470 - } else if (atomic_read(&rdev->read_errors)
46471 + } else if (atomic_read_unchecked(&rdev->read_errors)
46472 > conf->max_nr_stripes)
46473 printk(KERN_WARNING
46474 "md/raid:%s: Too many read errors, failing device %s.\n",
46475 @@ -3817,6 +3825,8 @@ static void handle_stripe(struct stripe_head *sh)
46476 set_bit(R5_Wantwrite, &dev->flags);
46477 if (prexor)
46478 continue;
46479 + if (s.failed > 1)
46480 + continue;
46481 if (!test_bit(R5_Insync, &dev->flags) ||
46482 ((i == sh->pd_idx || i == sh->qd_idx) &&
46483 s.failed == 0))
46484 diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
46485 index 983db75..ef9248c 100644
46486 --- a/drivers/media/dvb-core/dvbdev.c
46487 +++ b/drivers/media/dvb-core/dvbdev.c
46488 @@ -185,7 +185,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
46489 const struct dvb_device *template, void *priv, int type)
46490 {
46491 struct dvb_device *dvbdev;
46492 - struct file_operations *dvbdevfops;
46493 + file_operations_no_const *dvbdevfops;
46494 struct device *clsdev;
46495 int minor;
46496 int id;
46497 diff --git a/drivers/media/dvb-frontends/af9033.h b/drivers/media/dvb-frontends/af9033.h
46498 index 539f4db..cdd403b 100644
46499 --- a/drivers/media/dvb-frontends/af9033.h
46500 +++ b/drivers/media/dvb-frontends/af9033.h
46501 @@ -82,7 +82,7 @@ struct af9033_ops {
46502 int (*pid_filter_ctrl)(struct dvb_frontend *fe, int onoff);
46503 int (*pid_filter)(struct dvb_frontend *fe, int index, u16 pid,
46504 int onoff);
46505 -};
46506 +} __no_const;
46507
46508
46509 #if IS_ENABLED(CONFIG_DVB_AF9033)
46510 diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
46511 index 9b6c3bb..baeb5c7 100644
46512 --- a/drivers/media/dvb-frontends/dib3000.h
46513 +++ b/drivers/media/dvb-frontends/dib3000.h
46514 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
46515 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
46516 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
46517 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
46518 -};
46519 +} __no_const;
46520
46521 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
46522 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
46523 diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
46524 index ed8cb90..5ef7f79 100644
46525 --- a/drivers/media/pci/cx88/cx88-video.c
46526 +++ b/drivers/media/pci/cx88/cx88-video.c
46527 @@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
46528
46529 /* ------------------------------------------------------------------ */
46530
46531 -static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
46532 -static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
46533 -static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
46534 +static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
46535 +static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
46536 +static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
46537
46538 module_param_array(video_nr, int, NULL, 0444);
46539 module_param_array(vbi_nr, int, NULL, 0444);
46540 diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
46541 index 802642d..5534900 100644
46542 --- a/drivers/media/pci/ivtv/ivtv-driver.c
46543 +++ b/drivers/media/pci/ivtv/ivtv-driver.c
46544 @@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
46545 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
46546
46547 /* ivtv instance counter */
46548 -static atomic_t ivtv_instance = ATOMIC_INIT(0);
46549 +static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
46550
46551 /* Parameter declarations */
46552 static int cardtype[IVTV_MAX_CARDS];
46553 diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
46554 index 9a726ea..f5e9b52 100644
46555 --- a/drivers/media/platform/omap/omap_vout.c
46556 +++ b/drivers/media/platform/omap/omap_vout.c
46557 @@ -63,7 +63,6 @@ enum omap_vout_channels {
46558 OMAP_VIDEO2,
46559 };
46560
46561 -static struct videobuf_queue_ops video_vbq_ops;
46562 /* Variables configurable through module params*/
46563 static u32 video1_numbuffers = 3;
46564 static u32 video2_numbuffers = 3;
46565 @@ -1015,6 +1014,12 @@ static int omap_vout_open(struct file *file)
46566 {
46567 struct videobuf_queue *q;
46568 struct omap_vout_device *vout = NULL;
46569 + static struct videobuf_queue_ops video_vbq_ops = {
46570 + .buf_setup = omap_vout_buffer_setup,
46571 + .buf_prepare = omap_vout_buffer_prepare,
46572 + .buf_release = omap_vout_buffer_release,
46573 + .buf_queue = omap_vout_buffer_queue,
46574 + };
46575
46576 vout = video_drvdata(file);
46577 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
46578 @@ -1032,10 +1037,6 @@ static int omap_vout_open(struct file *file)
46579 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
46580
46581 q = &vout->vbq;
46582 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
46583 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
46584 - video_vbq_ops.buf_release = omap_vout_buffer_release;
46585 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
46586 spin_lock_init(&vout->vbq_lock);
46587
46588 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
46589 diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
46590 index fb2acc5..a2fcbdc4 100644
46591 --- a/drivers/media/platform/s5p-tv/mixer.h
46592 +++ b/drivers/media/platform/s5p-tv/mixer.h
46593 @@ -156,7 +156,7 @@ struct mxr_layer {
46594 /** layer index (unique identifier) */
46595 int idx;
46596 /** callbacks for layer methods */
46597 - struct mxr_layer_ops ops;
46598 + struct mxr_layer_ops *ops;
46599 /** format array */
46600 const struct mxr_format **fmt_array;
46601 /** size of format array */
46602 diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
46603 index 74344c7..a39e70e 100644
46604 --- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
46605 +++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
46606 @@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
46607 {
46608 struct mxr_layer *layer;
46609 int ret;
46610 - struct mxr_layer_ops ops = {
46611 + static struct mxr_layer_ops ops = {
46612 .release = mxr_graph_layer_release,
46613 .buffer_set = mxr_graph_buffer_set,
46614 .stream_set = mxr_graph_stream_set,
46615 diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
46616 index b713403..53cb5ad 100644
46617 --- a/drivers/media/platform/s5p-tv/mixer_reg.c
46618 +++ b/drivers/media/platform/s5p-tv/mixer_reg.c
46619 @@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
46620 layer->update_buf = next;
46621 }
46622
46623 - layer->ops.buffer_set(layer, layer->update_buf);
46624 + layer->ops->buffer_set(layer, layer->update_buf);
46625
46626 if (done && done != layer->shadow_buf)
46627 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
46628 diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
46629 index 8a8dbc8..b74c62d 100644
46630 --- a/drivers/media/platform/s5p-tv/mixer_video.c
46631 +++ b/drivers/media/platform/s5p-tv/mixer_video.c
46632 @@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
46633 layer->geo.src.height = layer->geo.src.full_height;
46634
46635 mxr_geometry_dump(mdev, &layer->geo);
46636 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
46637 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
46638 mxr_geometry_dump(mdev, &layer->geo);
46639 }
46640
46641 @@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
46642 layer->geo.dst.full_width = mbus_fmt.width;
46643 layer->geo.dst.full_height = mbus_fmt.height;
46644 layer->geo.dst.field = mbus_fmt.field;
46645 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
46646 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
46647
46648 mxr_geometry_dump(mdev, &layer->geo);
46649 }
46650 @@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
46651 /* set source size to highest accepted value */
46652 geo->src.full_width = max(geo->dst.full_width, pix->width);
46653 geo->src.full_height = max(geo->dst.full_height, pix->height);
46654 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
46655 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
46656 mxr_geometry_dump(mdev, &layer->geo);
46657 /* set cropping to total visible screen */
46658 geo->src.width = pix->width;
46659 @@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
46660 geo->src.x_offset = 0;
46661 geo->src.y_offset = 0;
46662 /* assure consistency of geometry */
46663 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
46664 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
46665 mxr_geometry_dump(mdev, &layer->geo);
46666 /* set full size to lowest possible value */
46667 geo->src.full_width = 0;
46668 geo->src.full_height = 0;
46669 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
46670 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
46671 mxr_geometry_dump(mdev, &layer->geo);
46672
46673 /* returning results */
46674 @@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
46675 target->width = s->r.width;
46676 target->height = s->r.height;
46677
46678 - layer->ops.fix_geometry(layer, stage, s->flags);
46679 + layer->ops->fix_geometry(layer, stage, s->flags);
46680
46681 /* retrieve update selection rectangle */
46682 res.left = target->x_offset;
46683 @@ -954,13 +954,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
46684 mxr_output_get(mdev);
46685
46686 mxr_layer_update_output(layer);
46687 - layer->ops.format_set(layer);
46688 + layer->ops->format_set(layer);
46689 /* enabling layer in hardware */
46690 spin_lock_irqsave(&layer->enq_slock, flags);
46691 layer->state = MXR_LAYER_STREAMING;
46692 spin_unlock_irqrestore(&layer->enq_slock, flags);
46693
46694 - layer->ops.stream_set(layer, MXR_ENABLE);
46695 + layer->ops->stream_set(layer, MXR_ENABLE);
46696 mxr_streamer_get(mdev);
46697
46698 return 0;
46699 @@ -1030,7 +1030,7 @@ static void stop_streaming(struct vb2_queue *vq)
46700 spin_unlock_irqrestore(&layer->enq_slock, flags);
46701
46702 /* disabling layer in hardware */
46703 - layer->ops.stream_set(layer, MXR_DISABLE);
46704 + layer->ops->stream_set(layer, MXR_DISABLE);
46705 /* remove one streamer */
46706 mxr_streamer_put(mdev);
46707 /* allow changes in output configuration */
46708 @@ -1068,8 +1068,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
46709
46710 void mxr_layer_release(struct mxr_layer *layer)
46711 {
46712 - if (layer->ops.release)
46713 - layer->ops.release(layer);
46714 + if (layer->ops->release)
46715 + layer->ops->release(layer);
46716 }
46717
46718 void mxr_base_layer_release(struct mxr_layer *layer)
46719 @@ -1095,7 +1095,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
46720
46721 layer->mdev = mdev;
46722 layer->idx = idx;
46723 - layer->ops = *ops;
46724 + layer->ops = ops;
46725
46726 spin_lock_init(&layer->enq_slock);
46727 INIT_LIST_HEAD(&layer->enq_list);
46728 diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
46729 index c9388c4..ce71ece 100644
46730 --- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
46731 +++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
46732 @@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
46733 {
46734 struct mxr_layer *layer;
46735 int ret;
46736 - struct mxr_layer_ops ops = {
46737 + static struct mxr_layer_ops ops = {
46738 .release = mxr_vp_layer_release,
46739 .buffer_set = mxr_vp_buffer_set,
46740 .stream_set = mxr_vp_stream_set,
46741 diff --git a/drivers/media/platform/vivi.c b/drivers/media/platform/vivi.c
46742 index d00bf3d..1301a0c 100644
46743 --- a/drivers/media/platform/vivi.c
46744 +++ b/drivers/media/platform/vivi.c
46745 @@ -58,8 +58,8 @@ MODULE_AUTHOR("Mauro Carvalho Chehab, Ted Walther and John Sokol");
46746 MODULE_LICENSE("Dual BSD/GPL");
46747 MODULE_VERSION(VIVI_VERSION);
46748
46749 -static unsigned video_nr = -1;
46750 -module_param(video_nr, uint, 0644);
46751 +static int video_nr = -1;
46752 +module_param(video_nr, int, 0644);
46753 MODULE_PARM_DESC(video_nr, "videoX start number, -1 is autodetect");
46754
46755 static unsigned n_devs = 1;
46756 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
46757 index d719e59..63f3470 100644
46758 --- a/drivers/media/radio/radio-cadet.c
46759 +++ b/drivers/media/radio/radio-cadet.c
46760 @@ -333,6 +333,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
46761 unsigned char readbuf[RDS_BUFFER];
46762 int i = 0;
46763
46764 + if (count > RDS_BUFFER)
46765 + return -EFAULT;
46766 mutex_lock(&dev->lock);
46767 if (dev->rdsstat == 0)
46768 cadet_start_rds(dev);
46769 @@ -349,8 +351,9 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
46770 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
46771 mutex_unlock(&dev->lock);
46772
46773 - if (i && copy_to_user(data, readbuf, i))
46774 - return -EFAULT;
46775 + if (i > sizeof(readbuf) || (i && copy_to_user(data, readbuf, i)))
46776 + i = -EFAULT;
46777 +
46778 return i;
46779 }
46780
46781 diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
46782 index 5236035..c622c74 100644
46783 --- a/drivers/media/radio/radio-maxiradio.c
46784 +++ b/drivers/media/radio/radio-maxiradio.c
46785 @@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
46786 /* TEA5757 pin mappings */
46787 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
46788
46789 -static atomic_t maxiradio_instance = ATOMIC_INIT(0);
46790 +static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
46791
46792 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
46793 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
46794 diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
46795 index 050b3bb..79f62b9 100644
46796 --- a/drivers/media/radio/radio-shark.c
46797 +++ b/drivers/media/radio/radio-shark.c
46798 @@ -79,7 +79,7 @@ struct shark_device {
46799 u32 last_val;
46800 };
46801
46802 -static atomic_t shark_instance = ATOMIC_INIT(0);
46803 +static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
46804
46805 static void shark_write_val(struct snd_tea575x *tea, u32 val)
46806 {
46807 diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
46808 index 8654e0d..0608a64 100644
46809 --- a/drivers/media/radio/radio-shark2.c
46810 +++ b/drivers/media/radio/radio-shark2.c
46811 @@ -74,7 +74,7 @@ struct shark_device {
46812 u8 *transfer_buffer;
46813 };
46814
46815 -static atomic_t shark_instance = ATOMIC_INIT(0);
46816 +static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
46817
46818 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
46819 {
46820 diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
46821 index 2fd9009..278cc1e 100644
46822 --- a/drivers/media/radio/radio-si476x.c
46823 +++ b/drivers/media/radio/radio-si476x.c
46824 @@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
46825 struct si476x_radio *radio;
46826 struct v4l2_ctrl *ctrl;
46827
46828 - static atomic_t instance = ATOMIC_INIT(0);
46829 + static atomic_unchecked_t instance = ATOMIC_INIT(0);
46830
46831 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
46832 if (!radio)
46833 diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
46834 index a1c641e..3007da9 100644
46835 --- a/drivers/media/usb/dvb-usb/cxusb.c
46836 +++ b/drivers/media/usb/dvb-usb/cxusb.c
46837 @@ -1112,7 +1112,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
46838
46839 struct dib0700_adapter_state {
46840 int (*set_param_save) (struct dvb_frontend *);
46841 -};
46842 +} __no_const;
46843
46844 static int dib7070_set_param_override(struct dvb_frontend *fe)
46845 {
46846 diff --git a/drivers/media/usb/dvb-usb/dvb-usb-firmware.c b/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
46847 index 733a7ff..f8b52e3 100644
46848 --- a/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
46849 +++ b/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
46850 @@ -35,42 +35,57 @@ static int usb_cypress_writemem(struct usb_device *udev,u16 addr,u8 *data, u8 le
46851
46852 int usb_cypress_load_firmware(struct usb_device *udev, const struct firmware *fw, int type)
46853 {
46854 - struct hexline hx;
46855 - u8 reset;
46856 + struct hexline *hx;
46857 + u8 *reset;
46858 int ret,pos=0;
46859
46860 + reset = kmalloc(1, GFP_KERNEL);
46861 + if (reset == NULL)
46862 + return -ENOMEM;
46863 +
46864 + hx = kmalloc(sizeof(struct hexline), GFP_KERNEL);
46865 + if (hx == NULL) {
46866 + kfree(reset);
46867 + return -ENOMEM;
46868 + }
46869 +
46870 /* stop the CPU */
46871 - reset = 1;
46872 - if ((ret = usb_cypress_writemem(udev,cypress[type].cpu_cs_register,&reset,1)) != 1)
46873 + reset[0] = 1;
46874 + if ((ret = usb_cypress_writemem(udev,cypress[type].cpu_cs_register,reset,1)) != 1)
46875 err("could not stop the USB controller CPU.");
46876
46877 - while ((ret = dvb_usb_get_hexline(fw,&hx,&pos)) > 0) {
46878 - deb_fw("writing to address 0x%04x (buffer: 0x%02x %02x)\n",hx.addr,hx.len,hx.chk);
46879 - ret = usb_cypress_writemem(udev,hx.addr,hx.data,hx.len);
46880 + while ((ret = dvb_usb_get_hexline(fw,hx,&pos)) > 0) {
46881 + deb_fw("writing to address 0x%04x (buffer: 0x%02x %02x)\n",hx->addr,hx->len,hx->chk);
46882 + ret = usb_cypress_writemem(udev,hx->addr,hx->data,hx->len);
46883
46884 - if (ret != hx.len) {
46885 + if (ret != hx->len) {
46886 err("error while transferring firmware "
46887 "(transferred size: %d, block size: %d)",
46888 - ret,hx.len);
46889 + ret,hx->len);
46890 ret = -EINVAL;
46891 break;
46892 }
46893 }
46894 if (ret < 0) {
46895 err("firmware download failed at %d with %d",pos,ret);
46896 + kfree(reset);
46897 + kfree(hx);
46898 return ret;
46899 }
46900
46901 if (ret == 0) {
46902 /* restart the CPU */
46903 - reset = 0;
46904 - if (ret || usb_cypress_writemem(udev,cypress[type].cpu_cs_register,&reset,1) != 1) {
46905 + reset[0] = 0;
46906 + if (ret || usb_cypress_writemem(udev,cypress[type].cpu_cs_register,reset,1) != 1) {
46907 err("could not restart the USB controller CPU.");
46908 ret = -EINVAL;
46909 }
46910 } else
46911 ret = -EIO;
46912
46913 + kfree(reset);
46914 + kfree(hx);
46915 +
46916 return ret;
46917 }
46918 EXPORT_SYMBOL(usb_cypress_load_firmware);
46919 diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
46920 index ae0f56a..ec71784 100644
46921 --- a/drivers/media/usb/dvb-usb/dw2102.c
46922 +++ b/drivers/media/usb/dvb-usb/dw2102.c
46923 @@ -118,7 +118,7 @@ struct su3000_state {
46924
46925 struct s6x0_state {
46926 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
46927 -};
46928 +} __no_const;
46929
46930 /* debug */
46931 static int dvb_usb_dw2102_debug;
46932 diff --git a/drivers/media/usb/dvb-usb/technisat-usb2.c b/drivers/media/usb/dvb-usb/technisat-usb2.c
46933 index d947e03..87fef42 100644
46934 --- a/drivers/media/usb/dvb-usb/technisat-usb2.c
46935 +++ b/drivers/media/usb/dvb-usb/technisat-usb2.c
46936 @@ -87,8 +87,11 @@ struct technisat_usb2_state {
46937 static int technisat_usb2_i2c_access(struct usb_device *udev,
46938 u8 device_addr, u8 *tx, u8 txlen, u8 *rx, u8 rxlen)
46939 {
46940 - u8 b[64];
46941 - int ret, actual_length;
46942 + u8 *b = kmalloc(64, GFP_KERNEL);
46943 + int ret, actual_length, error = 0;
46944 +
46945 + if (b == NULL)
46946 + return -ENOMEM;
46947
46948 deb_i2c("i2c-access: %02x, tx: ", device_addr);
46949 debug_dump(tx, txlen, deb_i2c);
46950 @@ -121,7 +124,8 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
46951
46952 if (ret < 0) {
46953 err("i2c-error: out failed %02x = %d", device_addr, ret);
46954 - return -ENODEV;
46955 + error = -ENODEV;
46956 + goto out;
46957 }
46958
46959 ret = usb_bulk_msg(udev,
46960 @@ -129,7 +133,8 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
46961 b, 64, &actual_length, 1000);
46962 if (ret < 0) {
46963 err("i2c-error: in failed %02x = %d", device_addr, ret);
46964 - return -ENODEV;
46965 + error = -ENODEV;
46966 + goto out;
46967 }
46968
46969 if (b[0] != I2C_STATUS_OK) {
46970 @@ -137,8 +142,10 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
46971 /* handle tuner-i2c-nak */
46972 if (!(b[0] == I2C_STATUS_NAK &&
46973 device_addr == 0x60
46974 - /* && device_is_technisat_usb2 */))
46975 - return -ENODEV;
46976 + /* && device_is_technisat_usb2 */)) {
46977 + error = -ENODEV;
46978 + goto out;
46979 + }
46980 }
46981
46982 deb_i2c("status: %d, ", b[0]);
46983 @@ -152,7 +159,9 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
46984
46985 deb_i2c("\n");
46986
46987 - return 0;
46988 +out:
46989 + kfree(b);
46990 + return error;
46991 }
46992
46993 static int technisat_usb2_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msg,
46994 @@ -224,14 +233,16 @@ static int technisat_usb2_set_led(struct dvb_usb_device *d, int red, enum techni
46995 {
46996 int ret;
46997
46998 - u8 led[8] = {
46999 - red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST,
47000 - 0
47001 - };
47002 + u8 *led = kzalloc(8, GFP_KERNEL);
47003 +
47004 + if (led == NULL)
47005 + return -ENOMEM;
47006
47007 if (disable_led_control && state != TECH_LED_OFF)
47008 return 0;
47009
47010 + led[0] = red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST;
47011 +
47012 switch (state) {
47013 case TECH_LED_ON:
47014 led[1] = 0x82;
47015 @@ -263,16 +274,22 @@ static int technisat_usb2_set_led(struct dvb_usb_device *d, int red, enum techni
47016 red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST,
47017 USB_TYPE_VENDOR | USB_DIR_OUT,
47018 0, 0,
47019 - led, sizeof(led), 500);
47020 + led, 8, 500);
47021
47022 mutex_unlock(&d->i2c_mutex);
47023 +
47024 + kfree(led);
47025 +
47026 return ret;
47027 }
47028
47029 static int technisat_usb2_set_led_timer(struct dvb_usb_device *d, u8 red, u8 green)
47030 {
47031 int ret;
47032 - u8 b = 0;
47033 + u8 *b = kzalloc(1, GFP_KERNEL);
47034 +
47035 + if (b == NULL)
47036 + return -ENOMEM;
47037
47038 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
47039 return -EAGAIN;
47040 @@ -281,10 +298,12 @@ static int technisat_usb2_set_led_timer(struct dvb_usb_device *d, u8 red, u8 gre
47041 SET_LED_TIMER_DIVIDER_VENDOR_REQUEST,
47042 USB_TYPE_VENDOR | USB_DIR_OUT,
47043 (red << 8) | green, 0,
47044 - &b, 1, 500);
47045 + b, 1, 500);
47046
47047 mutex_unlock(&d->i2c_mutex);
47048
47049 + kfree(b);
47050 +
47051 return ret;
47052 }
47053
47054 @@ -328,7 +347,7 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
47055 struct dvb_usb_device_description **desc, int *cold)
47056 {
47057 int ret;
47058 - u8 version[3];
47059 + u8 *version = kmalloc(3, GFP_KERNEL);
47060
47061 /* first select the interface */
47062 if (usb_set_interface(udev, 0, 1) != 0)
47063 @@ -338,11 +357,14 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
47064
47065 *cold = 0; /* by default do not download a firmware - just in case something is wrong */
47066
47067 + if (version == NULL)
47068 + return 0;
47069 +
47070 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
47071 GET_VERSION_INFO_VENDOR_REQUEST,
47072 USB_TYPE_VENDOR | USB_DIR_IN,
47073 0, 0,
47074 - version, sizeof(version), 500);
47075 + version, 3, 500);
47076
47077 if (ret < 0)
47078 *cold = 1;
47079 @@ -351,6 +373,8 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
47080 *cold = 0;
47081 }
47082
47083 + kfree(version);
47084 +
47085 return 0;
47086 }
47087
47088 @@ -591,10 +615,15 @@ static int technisat_usb2_frontend_attach(struct dvb_usb_adapter *a)
47089
47090 static int technisat_usb2_get_ir(struct dvb_usb_device *d)
47091 {
47092 - u8 buf[62], *b;
47093 + u8 *buf, *b;
47094 int ret;
47095 struct ir_raw_event ev;
47096
47097 + buf = kmalloc(62, GFP_KERNEL);
47098 +
47099 + if (buf == NULL)
47100 + return -ENOMEM;
47101 +
47102 buf[0] = GET_IR_DATA_VENDOR_REQUEST;
47103 buf[1] = 0x08;
47104 buf[2] = 0x8f;
47105 @@ -617,16 +646,20 @@ static int technisat_usb2_get_ir(struct dvb_usb_device *d)
47106 GET_IR_DATA_VENDOR_REQUEST,
47107 USB_TYPE_VENDOR | USB_DIR_IN,
47108 0x8080, 0,
47109 - buf, sizeof(buf), 500);
47110 + buf, 62, 500);
47111
47112 unlock:
47113 mutex_unlock(&d->i2c_mutex);
47114
47115 - if (ret < 0)
47116 + if (ret < 0) {
47117 + kfree(buf);
47118 return ret;
47119 + }
47120
47121 - if (ret == 1)
47122 + if (ret == 1) {
47123 + kfree(buf);
47124 return 0; /* no key pressed */
47125 + }
47126
47127 /* decoding */
47128 b = buf+1;
47129 @@ -653,6 +686,8 @@ unlock:
47130
47131 ir_raw_event_handle(d->rc_dev);
47132
47133 + kfree(buf);
47134 +
47135 return 1;
47136 }
47137
47138 diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
47139 index 7e2411c..cef73ca 100644
47140 --- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
47141 +++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
47142 @@ -328,7 +328,7 @@ struct v4l2_buffer32 {
47143 __u32 reserved;
47144 };
47145
47146 -static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
47147 +static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
47148 enum v4l2_memory memory)
47149 {
47150 void __user *up_pln;
47151 @@ -357,7 +357,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
47152 return 0;
47153 }
47154
47155 -static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
47156 +static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
47157 enum v4l2_memory memory)
47158 {
47159 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
47160 @@ -427,7 +427,7 @@ static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
47161 * by passing a very big num_planes value */
47162 uplane = compat_alloc_user_space(num_planes *
47163 sizeof(struct v4l2_plane));
47164 - kp->m.planes = uplane;
47165 + kp->m.planes = (struct v4l2_plane __force_kernel *)uplane;
47166
47167 while (--num_planes >= 0) {
47168 ret = get_v4l2_plane32(uplane, uplane32, kp->memory);
47169 @@ -498,7 +498,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
47170 if (num_planes == 0)
47171 return 0;
47172
47173 - uplane = kp->m.planes;
47174 + uplane = (struct v4l2_plane __force_user *)kp->m.planes;
47175 if (get_user(p, &up->m.planes))
47176 return -EFAULT;
47177 uplane32 = compat_ptr(p);
47178 @@ -552,7 +552,7 @@ static int get_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_frame
47179 get_user(kp->capability, &up->capability) ||
47180 get_user(kp->flags, &up->flags))
47181 return -EFAULT;
47182 - kp->base = compat_ptr(tmp);
47183 + kp->base = (void __force_kernel *)compat_ptr(tmp);
47184 get_v4l2_pix_format(&kp->fmt, &up->fmt);
47185 return 0;
47186 }
47187 @@ -658,7 +658,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
47188 n * sizeof(struct v4l2_ext_control32)))
47189 return -EFAULT;
47190 kcontrols = compat_alloc_user_space(n * sizeof(struct v4l2_ext_control));
47191 - kp->controls = kcontrols;
47192 + kp->controls = (struct v4l2_ext_control __force_kernel *)kcontrols;
47193 while (--n >= 0) {
47194 if (copy_in_user(kcontrols, ucontrols, sizeof(*ucontrols)))
47195 return -EFAULT;
47196 @@ -680,7 +680,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
47197 static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext_controls32 __user *up)
47198 {
47199 struct v4l2_ext_control32 __user *ucontrols;
47200 - struct v4l2_ext_control __user *kcontrols = kp->controls;
47201 + struct v4l2_ext_control __user *kcontrols = (struct v4l2_ext_control __force_user *)kp->controls;
47202 int n = kp->count;
47203 compat_caddr_t p;
47204
47205 @@ -774,7 +774,7 @@ static int put_v4l2_edid32(struct v4l2_edid *kp, struct v4l2_edid32 __user *up)
47206 put_user(kp->start_block, &up->start_block) ||
47207 put_user(kp->blocks, &up->blocks) ||
47208 put_user(tmp, &up->edid) ||
47209 - copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
47210 + copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
47211 return -EFAULT;
47212 return 0;
47213 }
47214 diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c
47215 index 55c6832..a91c7a6 100644
47216 --- a/drivers/media/v4l2-core/v4l2-ctrls.c
47217 +++ b/drivers/media/v4l2-core/v4l2-ctrls.c
47218 @@ -1431,8 +1431,8 @@ static int validate_new(const struct v4l2_ctrl *ctrl,
47219 return 0;
47220
47221 case V4L2_CTRL_TYPE_STRING:
47222 - len = strlen(c->string);
47223 - if (len < ctrl->minimum)
47224 + len = strlen_user(c->string);
47225 + if (!len || len < ctrl->minimum)
47226 return -ERANGE;
47227 if ((len - ctrl->minimum) % ctrl->step)
47228 return -ERANGE;
47229 diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
47230 index 015f92a..59e311e 100644
47231 --- a/drivers/media/v4l2-core/v4l2-device.c
47232 +++ b/drivers/media/v4l2-core/v4l2-device.c
47233 @@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
47234 EXPORT_SYMBOL_GPL(v4l2_device_put);
47235
47236 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
47237 - atomic_t *instance)
47238 + atomic_unchecked_t *instance)
47239 {
47240 - int num = atomic_inc_return(instance) - 1;
47241 + int num = atomic_inc_return_unchecked(instance) - 1;
47242 int len = strlen(basename);
47243
47244 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
47245 diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
47246 index 16bffd8..3ab516a 100644
47247 --- a/drivers/media/v4l2-core/v4l2-ioctl.c
47248 +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
47249 @@ -2003,7 +2003,8 @@ struct v4l2_ioctl_info {
47250 struct file *file, void *fh, void *p);
47251 } u;
47252 void (*debug)(const void *arg, bool write_only);
47253 -};
47254 +} __do_const;
47255 +typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
47256
47257 /* This control needs a priority check */
47258 #define INFO_FL_PRIO (1 << 0)
47259 @@ -2186,7 +2187,7 @@ static long __video_do_ioctl(struct file *file,
47260 struct video_device *vfd = video_devdata(file);
47261 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
47262 bool write_only = false;
47263 - struct v4l2_ioctl_info default_info;
47264 + v4l2_ioctl_info_no_const default_info;
47265 const struct v4l2_ioctl_info *info;
47266 void *fh = file->private_data;
47267 struct v4l2_fh *vfh = NULL;
47268 @@ -2276,7 +2277,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
47269 ret = -EINVAL;
47270 break;
47271 }
47272 - *user_ptr = (void __user *)buf->m.planes;
47273 + *user_ptr = (void __force_user *)buf->m.planes;
47274 *kernel_ptr = (void **)&buf->m.planes;
47275 *array_size = sizeof(struct v4l2_plane) * buf->length;
47276 ret = 1;
47277 @@ -2293,7 +2294,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
47278 ret = -EINVAL;
47279 break;
47280 }
47281 - *user_ptr = (void __user *)edid->edid;
47282 + *user_ptr = (void __force_user *)edid->edid;
47283 *kernel_ptr = (void **)&edid->edid;
47284 *array_size = edid->blocks * 128;
47285 ret = 1;
47286 @@ -2311,7 +2312,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
47287 ret = -EINVAL;
47288 break;
47289 }
47290 - *user_ptr = (void __user *)ctrls->controls;
47291 + *user_ptr = (void __force_user *)ctrls->controls;
47292 *kernel_ptr = (void **)&ctrls->controls;
47293 *array_size = sizeof(struct v4l2_ext_control)
47294 * ctrls->count;
47295 @@ -2412,7 +2413,7 @@ video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
47296 }
47297
47298 if (has_array_args) {
47299 - *kernel_ptr = (void __force *)user_ptr;
47300 + *kernel_ptr = (void __force_kernel *)user_ptr;
47301 if (copy_to_user(user_ptr, mbuf, array_size))
47302 err = -EFAULT;
47303 goto out_array_args;
47304 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
47305 index ebc0af7..baed058 100644
47306 --- a/drivers/message/fusion/mptbase.c
47307 +++ b/drivers/message/fusion/mptbase.c
47308 @@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
47309 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
47310 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
47311
47312 +#ifdef CONFIG_GRKERNSEC_HIDESYM
47313 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
47314 +#else
47315 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
47316 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
47317 +#endif
47318 +
47319 /*
47320 * Rounding UP to nearest 4-kB boundary here...
47321 */
47322 @@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
47323 ioc->facts.GlobalCredits);
47324
47325 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
47326 +#ifdef CONFIG_GRKERNSEC_HIDESYM
47327 + NULL, NULL);
47328 +#else
47329 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
47330 +#endif
47331 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
47332 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
47333 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
47334 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
47335 index 711fcb5..5da1fb0 100644
47336 --- a/drivers/message/fusion/mptsas.c
47337 +++ b/drivers/message/fusion/mptsas.c
47338 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
47339 return 0;
47340 }
47341
47342 +static inline void
47343 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
47344 +{
47345 + if (phy_info->port_details) {
47346 + phy_info->port_details->rphy = rphy;
47347 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
47348 + ioc->name, rphy));
47349 + }
47350 +
47351 + if (rphy) {
47352 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
47353 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
47354 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
47355 + ioc->name, rphy, rphy->dev.release));
47356 + }
47357 +}
47358 +
47359 /* no mutex */
47360 static void
47361 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
47362 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
47363 return NULL;
47364 }
47365
47366 -static inline void
47367 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
47368 -{
47369 - if (phy_info->port_details) {
47370 - phy_info->port_details->rphy = rphy;
47371 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
47372 - ioc->name, rphy));
47373 - }
47374 -
47375 - if (rphy) {
47376 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
47377 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
47378 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
47379 - ioc->name, rphy, rphy->dev.release));
47380 - }
47381 -}
47382 -
47383 static inline struct sas_port *
47384 mptsas_get_port(struct mptsas_phyinfo *phy_info)
47385 {
47386 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
47387 index 2a1c6f2..a04c6a2 100644
47388 --- a/drivers/message/fusion/mptscsih.c
47389 +++ b/drivers/message/fusion/mptscsih.c
47390 @@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
47391
47392 h = shost_priv(SChost);
47393
47394 - if (h) {
47395 - if (h->info_kbuf == NULL)
47396 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
47397 - return h->info_kbuf;
47398 - h->info_kbuf[0] = '\0';
47399 + if (!h)
47400 + return NULL;
47401
47402 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
47403 - h->info_kbuf[size-1] = '\0';
47404 - }
47405 + if (h->info_kbuf == NULL)
47406 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
47407 + return h->info_kbuf;
47408 + h->info_kbuf[0] = '\0';
47409 +
47410 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
47411 + h->info_kbuf[size-1] = '\0';
47412
47413 return h->info_kbuf;
47414 }
47415 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
47416 index b7d87cd..3fb36da 100644
47417 --- a/drivers/message/i2o/i2o_proc.c
47418 +++ b/drivers/message/i2o/i2o_proc.c
47419 @@ -255,12 +255,6 @@ static char *scsi_devices[] = {
47420 "Array Controller Device"
47421 };
47422
47423 -static char *chtostr(char *tmp, u8 *chars, int n)
47424 -{
47425 - tmp[0] = 0;
47426 - return strncat(tmp, (char *)chars, n);
47427 -}
47428 -
47429 static int i2o_report_query_status(struct seq_file *seq, int block_status,
47430 char *group)
47431 {
47432 @@ -707,9 +701,9 @@ static int i2o_seq_show_status(struct seq_file *seq, void *v)
47433 static int i2o_seq_show_hw(struct seq_file *seq, void *v)
47434 {
47435 struct i2o_controller *c = (struct i2o_controller *)seq->private;
47436 - static u32 work32[5];
47437 - static u8 *work8 = (u8 *) work32;
47438 - static u16 *work16 = (u16 *) work32;
47439 + u32 work32[5];
47440 + u8 *work8 = (u8 *) work32;
47441 + u16 *work16 = (u16 *) work32;
47442 int token;
47443 u32 hwcap;
47444
47445 @@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
47446 } *result;
47447
47448 i2o_exec_execute_ddm_table ddm_table;
47449 - char tmp[28 + 1];
47450
47451 result = kmalloc(sizeof(*result), GFP_KERNEL);
47452 if (!result)
47453 @@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
47454
47455 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
47456 seq_printf(seq, "%-#8x", ddm_table.module_id);
47457 - seq_printf(seq, "%-29s",
47458 - chtostr(tmp, ddm_table.module_name_version, 28));
47459 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
47460 seq_printf(seq, "%9d ", ddm_table.data_size);
47461 seq_printf(seq, "%8d", ddm_table.code_size);
47462
47463 @@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
47464
47465 i2o_driver_result_table *result;
47466 i2o_driver_store_table *dst;
47467 - char tmp[28 + 1];
47468
47469 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
47470 if (result == NULL)
47471 @@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
47472
47473 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
47474 seq_printf(seq, "%-#8x", dst->module_id);
47475 - seq_printf(seq, "%-29s",
47476 - chtostr(tmp, dst->module_name_version, 28));
47477 - seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
47478 + seq_printf(seq, "%-.28s", dst->module_name_version);
47479 + seq_printf(seq, "%-.8s", dst->date);
47480 seq_printf(seq, "%8d ", dst->module_size);
47481 seq_printf(seq, "%8d ", dst->mpb_size);
47482 seq_printf(seq, "0x%04x", dst->module_flags);
47483 @@ -1246,11 +1236,10 @@ static int i2o_seq_show_authorized_users(struct seq_file *seq, void *v)
47484 static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
47485 {
47486 struct i2o_device *d = (struct i2o_device *)seq->private;
47487 - static u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
47488 + u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
47489 // == (allow) 512d bytes (max)
47490 - static u16 *work16 = (u16 *) work32;
47491 + u16 *work16 = (u16 *) work32;
47492 int token;
47493 - char tmp[16 + 1];
47494
47495 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
47496
47497 @@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
47498 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
47499 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
47500 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
47501 - seq_printf(seq, "Vendor info : %s\n",
47502 - chtostr(tmp, (u8 *) (work32 + 2), 16));
47503 - seq_printf(seq, "Product info : %s\n",
47504 - chtostr(tmp, (u8 *) (work32 + 6), 16));
47505 - seq_printf(seq, "Description : %s\n",
47506 - chtostr(tmp, (u8 *) (work32 + 10), 16));
47507 - seq_printf(seq, "Product rev. : %s\n",
47508 - chtostr(tmp, (u8 *) (work32 + 14), 8));
47509 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
47510 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
47511 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
47512 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
47513
47514 seq_printf(seq, "Serial number : ");
47515 print_serial_number(seq, (u8 *) (work32 + 16),
47516 @@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
47517 u8 pad[256]; // allow up to 256 byte (max) serial number
47518 } result;
47519
47520 - char tmp[24 + 1];
47521 -
47522 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
47523
47524 if (token < 0) {
47525 @@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
47526 }
47527
47528 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
47529 - seq_printf(seq, "Module name : %s\n",
47530 - chtostr(tmp, result.module_name, 24));
47531 - seq_printf(seq, "Module revision : %s\n",
47532 - chtostr(tmp, result.module_rev, 8));
47533 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
47534 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
47535
47536 seq_printf(seq, "Serial number : ");
47537 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
47538 @@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
47539 u8 instance_number[4];
47540 } result;
47541
47542 - char tmp[64 + 1];
47543 -
47544 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
47545
47546 if (token < 0) {
47547 @@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
47548 return 0;
47549 }
47550
47551 - seq_printf(seq, "Device name : %s\n",
47552 - chtostr(tmp, result.device_name, 64));
47553 - seq_printf(seq, "Service name : %s\n",
47554 - chtostr(tmp, result.service_name, 64));
47555 - seq_printf(seq, "Physical name : %s\n",
47556 - chtostr(tmp, result.physical_location, 64));
47557 - seq_printf(seq, "Instance number : %s\n",
47558 - chtostr(tmp, result.instance_number, 4));
47559 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
47560 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
47561 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
47562 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
47563
47564 return 0;
47565 }
47566 @@ -1368,9 +1343,9 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
47567 static int i2o_seq_show_sgl_limits(struct seq_file *seq, void *v)
47568 {
47569 struct i2o_device *d = (struct i2o_device *)seq->private;
47570 - static u32 work32[12];
47571 - static u16 *work16 = (u16 *) work32;
47572 - static u8 *work8 = (u8 *) work32;
47573 + u32 work32[12];
47574 + u16 *work16 = (u16 *) work32;
47575 + u8 *work8 = (u8 *) work32;
47576 int token;
47577
47578 token = i2o_parm_field_get(d, 0xF103, -1, &work32, sizeof(work32));
47579 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
47580 index 92752fb..a7494f6 100644
47581 --- a/drivers/message/i2o/iop.c
47582 +++ b/drivers/message/i2o/iop.c
47583 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
47584
47585 spin_lock_irqsave(&c->context_list_lock, flags);
47586
47587 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
47588 - atomic_inc(&c->context_list_counter);
47589 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
47590 + atomic_inc_unchecked(&c->context_list_counter);
47591
47592 - entry->context = atomic_read(&c->context_list_counter);
47593 + entry->context = atomic_read_unchecked(&c->context_list_counter);
47594
47595 list_add(&entry->list, &c->context_list);
47596
47597 @@ -1076,7 +1076,7 @@ struct i2o_controller *i2o_iop_alloc(void)
47598
47599 #if BITS_PER_LONG == 64
47600 spin_lock_init(&c->context_list_lock);
47601 - atomic_set(&c->context_list_counter, 0);
47602 + atomic_set_unchecked(&c->context_list_counter, 0);
47603 INIT_LIST_HEAD(&c->context_list);
47604 #endif
47605
47606 diff --git a/drivers/mfd/ab8500-debugfs.c b/drivers/mfd/ab8500-debugfs.c
47607 index d1a22aa..d0f7bf7 100644
47608 --- a/drivers/mfd/ab8500-debugfs.c
47609 +++ b/drivers/mfd/ab8500-debugfs.c
47610 @@ -100,7 +100,7 @@ static int irq_last;
47611 static u32 *irq_count;
47612 static int num_irqs;
47613
47614 -static struct device_attribute **dev_attr;
47615 +static device_attribute_no_const **dev_attr;
47616 static char **event_name;
47617
47618 static u8 avg_sample = SAMPLE_16;
47619 diff --git a/drivers/mfd/max8925-i2c.c b/drivers/mfd/max8925-i2c.c
47620 index a83eed5..62a58a9 100644
47621 --- a/drivers/mfd/max8925-i2c.c
47622 +++ b/drivers/mfd/max8925-i2c.c
47623 @@ -152,7 +152,7 @@ static int max8925_probe(struct i2c_client *client,
47624 const struct i2c_device_id *id)
47625 {
47626 struct max8925_platform_data *pdata = dev_get_platdata(&client->dev);
47627 - static struct max8925_chip *chip;
47628 + struct max8925_chip *chip;
47629 struct device_node *node = client->dev.of_node;
47630
47631 if (node && !pdata) {
47632 diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
47633 index f9e42ea..614d240 100644
47634 --- a/drivers/mfd/tps65910.c
47635 +++ b/drivers/mfd/tps65910.c
47636 @@ -230,7 +230,7 @@ static int tps65910_irq_init(struct tps65910 *tps65910, int irq,
47637 struct tps65910_platform_data *pdata)
47638 {
47639 int ret = 0;
47640 - static struct regmap_irq_chip *tps6591x_irqs_chip;
47641 + struct regmap_irq_chip *tps6591x_irqs_chip;
47642
47643 if (!irq) {
47644 dev_warn(tps65910->dev, "No interrupt support, no core IRQ\n");
47645 diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
47646 index 596b1f6..5b6ab74 100644
47647 --- a/drivers/mfd/twl4030-irq.c
47648 +++ b/drivers/mfd/twl4030-irq.c
47649 @@ -34,6 +34,7 @@
47650 #include <linux/of.h>
47651 #include <linux/irqdomain.h>
47652 #include <linux/i2c/twl.h>
47653 +#include <asm/pgtable.h>
47654
47655 #include "twl-core.h"
47656
47657 @@ -725,10 +726,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
47658 * Install an irq handler for each of the SIH modules;
47659 * clone dummy irq_chip since PIH can't *do* anything
47660 */
47661 - twl4030_irq_chip = dummy_irq_chip;
47662 - twl4030_irq_chip.name = "twl4030";
47663 + pax_open_kernel();
47664 + memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
47665 + *(const char **)&twl4030_irq_chip.name = "twl4030";
47666
47667 - twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
47668 + *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
47669 + pax_close_kernel();
47670
47671 for (i = irq_base; i < irq_end; i++) {
47672 irq_set_chip_and_handler(i, &twl4030_irq_chip,
47673 diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
47674 index 464419b..64bae8d 100644
47675 --- a/drivers/misc/c2port/core.c
47676 +++ b/drivers/misc/c2port/core.c
47677 @@ -922,7 +922,9 @@ struct c2port_device *c2port_device_register(char *name,
47678 goto error_idr_alloc;
47679 c2dev->id = ret;
47680
47681 - bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
47682 + pax_open_kernel();
47683 + *(size_t *)&bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
47684 + pax_close_kernel();
47685
47686 c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
47687 "c2port%d", c2dev->id);
47688 diff --git a/drivers/misc/eeprom/sunxi_sid.c b/drivers/misc/eeprom/sunxi_sid.c
47689 index 3f2b625..945e179 100644
47690 --- a/drivers/misc/eeprom/sunxi_sid.c
47691 +++ b/drivers/misc/eeprom/sunxi_sid.c
47692 @@ -126,7 +126,9 @@ static int sunxi_sid_probe(struct platform_device *pdev)
47693
47694 platform_set_drvdata(pdev, sid_data);
47695
47696 - sid_bin_attr.size = sid_data->keysize;
47697 + pax_open_kernel();
47698 + *(size_t *)&sid_bin_attr.size = sid_data->keysize;
47699 + pax_close_kernel();
47700 if (device_create_bin_file(&pdev->dev, &sid_bin_attr))
47701 return -ENODEV;
47702
47703 diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
47704 index 36f5d52..32311c3 100644
47705 --- a/drivers/misc/kgdbts.c
47706 +++ b/drivers/misc/kgdbts.c
47707 @@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
47708 char before[BREAK_INSTR_SIZE];
47709 char after[BREAK_INSTR_SIZE];
47710
47711 - probe_kernel_read(before, (char *)kgdbts_break_test,
47712 + probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
47713 BREAK_INSTR_SIZE);
47714 init_simple_test();
47715 ts.tst = plant_and_detach_test;
47716 @@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
47717 /* Activate test with initial breakpoint */
47718 if (!is_early)
47719 kgdb_breakpoint();
47720 - probe_kernel_read(after, (char *)kgdbts_break_test,
47721 + probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
47722 BREAK_INSTR_SIZE);
47723 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
47724 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
47725 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
47726 index 3ef4627..8d00486 100644
47727 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
47728 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
47729 @@ -497,7 +497,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
47730 * the lid is closed. This leads to interrupts as soon as a little move
47731 * is done.
47732 */
47733 - atomic_inc(&lis3->count);
47734 + atomic_inc_unchecked(&lis3->count);
47735
47736 wake_up_interruptible(&lis3->misc_wait);
47737 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
47738 @@ -583,7 +583,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
47739 if (lis3->pm_dev)
47740 pm_runtime_get_sync(lis3->pm_dev);
47741
47742 - atomic_set(&lis3->count, 0);
47743 + atomic_set_unchecked(&lis3->count, 0);
47744 return 0;
47745 }
47746
47747 @@ -615,7 +615,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
47748 add_wait_queue(&lis3->misc_wait, &wait);
47749 while (true) {
47750 set_current_state(TASK_INTERRUPTIBLE);
47751 - data = atomic_xchg(&lis3->count, 0);
47752 + data = atomic_xchg_unchecked(&lis3->count, 0);
47753 if (data)
47754 break;
47755
47756 @@ -656,7 +656,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
47757 struct lis3lv02d, miscdev);
47758
47759 poll_wait(file, &lis3->misc_wait, wait);
47760 - if (atomic_read(&lis3->count))
47761 + if (atomic_read_unchecked(&lis3->count))
47762 return POLLIN | POLLRDNORM;
47763 return 0;
47764 }
47765 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
47766 index c439c82..1f20f57 100644
47767 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
47768 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
47769 @@ -297,7 +297,7 @@ struct lis3lv02d {
47770 struct input_polled_dev *idev; /* input device */
47771 struct platform_device *pdev; /* platform device */
47772 struct regulator_bulk_data regulators[2];
47773 - atomic_t count; /* interrupt count after last read */
47774 + atomic_unchecked_t count; /* interrupt count after last read */
47775 union axis_conversion ac; /* hw -> logical axis */
47776 int mapped_btns[3];
47777
47778 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
47779 index 2f30bad..c4c13d0 100644
47780 --- a/drivers/misc/sgi-gru/gruhandles.c
47781 +++ b/drivers/misc/sgi-gru/gruhandles.c
47782 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
47783 unsigned long nsec;
47784
47785 nsec = CLKS2NSEC(clks);
47786 - atomic_long_inc(&mcs_op_statistics[op].count);
47787 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
47788 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
47789 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
47790 if (mcs_op_statistics[op].max < nsec)
47791 mcs_op_statistics[op].max = nsec;
47792 }
47793 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
47794 index 4f76359..cdfcb2e 100644
47795 --- a/drivers/misc/sgi-gru/gruprocfs.c
47796 +++ b/drivers/misc/sgi-gru/gruprocfs.c
47797 @@ -32,9 +32,9 @@
47798
47799 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
47800
47801 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
47802 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
47803 {
47804 - unsigned long val = atomic_long_read(v);
47805 + unsigned long val = atomic_long_read_unchecked(v);
47806
47807 seq_printf(s, "%16lu %s\n", val, id);
47808 }
47809 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
47810
47811 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
47812 for (op = 0; op < mcsop_last; op++) {
47813 - count = atomic_long_read(&mcs_op_statistics[op].count);
47814 - total = atomic_long_read(&mcs_op_statistics[op].total);
47815 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
47816 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
47817 max = mcs_op_statistics[op].max;
47818 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
47819 count ? total / count : 0, max);
47820 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
47821 index 5c3ce24..4915ccb 100644
47822 --- a/drivers/misc/sgi-gru/grutables.h
47823 +++ b/drivers/misc/sgi-gru/grutables.h
47824 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
47825 * GRU statistics.
47826 */
47827 struct gru_stats_s {
47828 - atomic_long_t vdata_alloc;
47829 - atomic_long_t vdata_free;
47830 - atomic_long_t gts_alloc;
47831 - atomic_long_t gts_free;
47832 - atomic_long_t gms_alloc;
47833 - atomic_long_t gms_free;
47834 - atomic_long_t gts_double_allocate;
47835 - atomic_long_t assign_context;
47836 - atomic_long_t assign_context_failed;
47837 - atomic_long_t free_context;
47838 - atomic_long_t load_user_context;
47839 - atomic_long_t load_kernel_context;
47840 - atomic_long_t lock_kernel_context;
47841 - atomic_long_t unlock_kernel_context;
47842 - atomic_long_t steal_user_context;
47843 - atomic_long_t steal_kernel_context;
47844 - atomic_long_t steal_context_failed;
47845 - atomic_long_t nopfn;
47846 - atomic_long_t asid_new;
47847 - atomic_long_t asid_next;
47848 - atomic_long_t asid_wrap;
47849 - atomic_long_t asid_reuse;
47850 - atomic_long_t intr;
47851 - atomic_long_t intr_cbr;
47852 - atomic_long_t intr_tfh;
47853 - atomic_long_t intr_spurious;
47854 - atomic_long_t intr_mm_lock_failed;
47855 - atomic_long_t call_os;
47856 - atomic_long_t call_os_wait_queue;
47857 - atomic_long_t user_flush_tlb;
47858 - atomic_long_t user_unload_context;
47859 - atomic_long_t user_exception;
47860 - atomic_long_t set_context_option;
47861 - atomic_long_t check_context_retarget_intr;
47862 - atomic_long_t check_context_unload;
47863 - atomic_long_t tlb_dropin;
47864 - atomic_long_t tlb_preload_page;
47865 - atomic_long_t tlb_dropin_fail_no_asid;
47866 - atomic_long_t tlb_dropin_fail_upm;
47867 - atomic_long_t tlb_dropin_fail_invalid;
47868 - atomic_long_t tlb_dropin_fail_range_active;
47869 - atomic_long_t tlb_dropin_fail_idle;
47870 - atomic_long_t tlb_dropin_fail_fmm;
47871 - atomic_long_t tlb_dropin_fail_no_exception;
47872 - atomic_long_t tfh_stale_on_fault;
47873 - atomic_long_t mmu_invalidate_range;
47874 - atomic_long_t mmu_invalidate_page;
47875 - atomic_long_t flush_tlb;
47876 - atomic_long_t flush_tlb_gru;
47877 - atomic_long_t flush_tlb_gru_tgh;
47878 - atomic_long_t flush_tlb_gru_zero_asid;
47879 + atomic_long_unchecked_t vdata_alloc;
47880 + atomic_long_unchecked_t vdata_free;
47881 + atomic_long_unchecked_t gts_alloc;
47882 + atomic_long_unchecked_t gts_free;
47883 + atomic_long_unchecked_t gms_alloc;
47884 + atomic_long_unchecked_t gms_free;
47885 + atomic_long_unchecked_t gts_double_allocate;
47886 + atomic_long_unchecked_t assign_context;
47887 + atomic_long_unchecked_t assign_context_failed;
47888 + atomic_long_unchecked_t free_context;
47889 + atomic_long_unchecked_t load_user_context;
47890 + atomic_long_unchecked_t load_kernel_context;
47891 + atomic_long_unchecked_t lock_kernel_context;
47892 + atomic_long_unchecked_t unlock_kernel_context;
47893 + atomic_long_unchecked_t steal_user_context;
47894 + atomic_long_unchecked_t steal_kernel_context;
47895 + atomic_long_unchecked_t steal_context_failed;
47896 + atomic_long_unchecked_t nopfn;
47897 + atomic_long_unchecked_t asid_new;
47898 + atomic_long_unchecked_t asid_next;
47899 + atomic_long_unchecked_t asid_wrap;
47900 + atomic_long_unchecked_t asid_reuse;
47901 + atomic_long_unchecked_t intr;
47902 + atomic_long_unchecked_t intr_cbr;
47903 + atomic_long_unchecked_t intr_tfh;
47904 + atomic_long_unchecked_t intr_spurious;
47905 + atomic_long_unchecked_t intr_mm_lock_failed;
47906 + atomic_long_unchecked_t call_os;
47907 + atomic_long_unchecked_t call_os_wait_queue;
47908 + atomic_long_unchecked_t user_flush_tlb;
47909 + atomic_long_unchecked_t user_unload_context;
47910 + atomic_long_unchecked_t user_exception;
47911 + atomic_long_unchecked_t set_context_option;
47912 + atomic_long_unchecked_t check_context_retarget_intr;
47913 + atomic_long_unchecked_t check_context_unload;
47914 + atomic_long_unchecked_t tlb_dropin;
47915 + atomic_long_unchecked_t tlb_preload_page;
47916 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
47917 + atomic_long_unchecked_t tlb_dropin_fail_upm;
47918 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
47919 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
47920 + atomic_long_unchecked_t tlb_dropin_fail_idle;
47921 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
47922 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
47923 + atomic_long_unchecked_t tfh_stale_on_fault;
47924 + atomic_long_unchecked_t mmu_invalidate_range;
47925 + atomic_long_unchecked_t mmu_invalidate_page;
47926 + atomic_long_unchecked_t flush_tlb;
47927 + atomic_long_unchecked_t flush_tlb_gru;
47928 + atomic_long_unchecked_t flush_tlb_gru_tgh;
47929 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
47930
47931 - atomic_long_t copy_gpa;
47932 - atomic_long_t read_gpa;
47933 + atomic_long_unchecked_t copy_gpa;
47934 + atomic_long_unchecked_t read_gpa;
47935
47936 - atomic_long_t mesq_receive;
47937 - atomic_long_t mesq_receive_none;
47938 - atomic_long_t mesq_send;
47939 - atomic_long_t mesq_send_failed;
47940 - atomic_long_t mesq_noop;
47941 - atomic_long_t mesq_send_unexpected_error;
47942 - atomic_long_t mesq_send_lb_overflow;
47943 - atomic_long_t mesq_send_qlimit_reached;
47944 - atomic_long_t mesq_send_amo_nacked;
47945 - atomic_long_t mesq_send_put_nacked;
47946 - atomic_long_t mesq_page_overflow;
47947 - atomic_long_t mesq_qf_locked;
47948 - atomic_long_t mesq_qf_noop_not_full;
47949 - atomic_long_t mesq_qf_switch_head_failed;
47950 - atomic_long_t mesq_qf_unexpected_error;
47951 - atomic_long_t mesq_noop_unexpected_error;
47952 - atomic_long_t mesq_noop_lb_overflow;
47953 - atomic_long_t mesq_noop_qlimit_reached;
47954 - atomic_long_t mesq_noop_amo_nacked;
47955 - atomic_long_t mesq_noop_put_nacked;
47956 - atomic_long_t mesq_noop_page_overflow;
47957 + atomic_long_unchecked_t mesq_receive;
47958 + atomic_long_unchecked_t mesq_receive_none;
47959 + atomic_long_unchecked_t mesq_send;
47960 + atomic_long_unchecked_t mesq_send_failed;
47961 + atomic_long_unchecked_t mesq_noop;
47962 + atomic_long_unchecked_t mesq_send_unexpected_error;
47963 + atomic_long_unchecked_t mesq_send_lb_overflow;
47964 + atomic_long_unchecked_t mesq_send_qlimit_reached;
47965 + atomic_long_unchecked_t mesq_send_amo_nacked;
47966 + atomic_long_unchecked_t mesq_send_put_nacked;
47967 + atomic_long_unchecked_t mesq_page_overflow;
47968 + atomic_long_unchecked_t mesq_qf_locked;
47969 + atomic_long_unchecked_t mesq_qf_noop_not_full;
47970 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
47971 + atomic_long_unchecked_t mesq_qf_unexpected_error;
47972 + atomic_long_unchecked_t mesq_noop_unexpected_error;
47973 + atomic_long_unchecked_t mesq_noop_lb_overflow;
47974 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
47975 + atomic_long_unchecked_t mesq_noop_amo_nacked;
47976 + atomic_long_unchecked_t mesq_noop_put_nacked;
47977 + atomic_long_unchecked_t mesq_noop_page_overflow;
47978
47979 };
47980
47981 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
47982 tghop_invalidate, mcsop_last};
47983
47984 struct mcs_op_statistic {
47985 - atomic_long_t count;
47986 - atomic_long_t total;
47987 + atomic_long_unchecked_t count;
47988 + atomic_long_unchecked_t total;
47989 unsigned long max;
47990 };
47991
47992 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
47993
47994 #define STAT(id) do { \
47995 if (gru_options & OPT_STATS) \
47996 - atomic_long_inc(&gru_stats.id); \
47997 + atomic_long_inc_unchecked(&gru_stats.id); \
47998 } while (0)
47999
48000 #ifdef CONFIG_SGI_GRU_DEBUG
48001 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
48002 index c862cd4..0d176fe 100644
48003 --- a/drivers/misc/sgi-xp/xp.h
48004 +++ b/drivers/misc/sgi-xp/xp.h
48005 @@ -288,7 +288,7 @@ struct xpc_interface {
48006 xpc_notify_func, void *);
48007 void (*received) (short, int, void *);
48008 enum xp_retval (*partid_to_nasids) (short, void *);
48009 -};
48010 +} __no_const;
48011
48012 extern struct xpc_interface xpc_interface;
48013
48014 diff --git a/drivers/misc/sgi-xp/xp_main.c b/drivers/misc/sgi-xp/xp_main.c
48015 index 01be66d..e3a0c7e 100644
48016 --- a/drivers/misc/sgi-xp/xp_main.c
48017 +++ b/drivers/misc/sgi-xp/xp_main.c
48018 @@ -78,13 +78,13 @@ xpc_notloaded(void)
48019 }
48020
48021 struct xpc_interface xpc_interface = {
48022 - (void (*)(int))xpc_notloaded,
48023 - (void (*)(int))xpc_notloaded,
48024 - (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
48025 - (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
48026 + .connect = (void (*)(int))xpc_notloaded,
48027 + .disconnect = (void (*)(int))xpc_notloaded,
48028 + .send = (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
48029 + .send_notify = (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
48030 void *))xpc_notloaded,
48031 - (void (*)(short, int, void *))xpc_notloaded,
48032 - (enum xp_retval(*)(short, void *))xpc_notloaded
48033 + .received = (void (*)(short, int, void *))xpc_notloaded,
48034 + .partid_to_nasids = (enum xp_retval(*)(short, void *))xpc_notloaded
48035 };
48036 EXPORT_SYMBOL_GPL(xpc_interface);
48037
48038 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
48039 index b94d5f7..7f494c5 100644
48040 --- a/drivers/misc/sgi-xp/xpc.h
48041 +++ b/drivers/misc/sgi-xp/xpc.h
48042 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
48043 void (*received_payload) (struct xpc_channel *, void *);
48044 void (*notify_senders_of_disconnect) (struct xpc_channel *);
48045 };
48046 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
48047
48048 /* struct xpc_partition act_state values (for XPC HB) */
48049
48050 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
48051 /* found in xpc_main.c */
48052 extern struct device *xpc_part;
48053 extern struct device *xpc_chan;
48054 -extern struct xpc_arch_operations xpc_arch_ops;
48055 +extern xpc_arch_operations_no_const xpc_arch_ops;
48056 extern int xpc_disengage_timelimit;
48057 extern int xpc_disengage_timedout;
48058 extern int xpc_activate_IRQ_rcvd;
48059 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
48060 index 82dc574..8539ab2 100644
48061 --- a/drivers/misc/sgi-xp/xpc_main.c
48062 +++ b/drivers/misc/sgi-xp/xpc_main.c
48063 @@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
48064 .notifier_call = xpc_system_die,
48065 };
48066
48067 -struct xpc_arch_operations xpc_arch_ops;
48068 +xpc_arch_operations_no_const xpc_arch_ops;
48069
48070 /*
48071 * Timer function to enforce the timelimit on the partition disengage.
48072 @@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
48073
48074 if (((die_args->trapnr == X86_TRAP_MF) ||
48075 (die_args->trapnr == X86_TRAP_XF)) &&
48076 - !user_mode_vm(die_args->regs))
48077 + !user_mode(die_args->regs))
48078 xpc_die_deactivate();
48079
48080 break;
48081 diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
48082 index 452782b..0c10e40 100644
48083 --- a/drivers/mmc/card/block.c
48084 +++ b/drivers/mmc/card/block.c
48085 @@ -574,7 +574,7 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
48086 if (idata->ic.postsleep_min_us)
48087 usleep_range(idata->ic.postsleep_min_us, idata->ic.postsleep_max_us);
48088
48089 - if (copy_to_user(&(ic_ptr->response), cmd.resp, sizeof(cmd.resp))) {
48090 + if (copy_to_user(ic_ptr->response, cmd.resp, sizeof(cmd.resp))) {
48091 err = -EFAULT;
48092 goto cmd_rel_host;
48093 }
48094 diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
48095 index f51b5ba..86614a7 100644
48096 --- a/drivers/mmc/core/mmc_ops.c
48097 +++ b/drivers/mmc/core/mmc_ops.c
48098 @@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
48099 void *data_buf;
48100 int is_on_stack;
48101
48102 - is_on_stack = object_is_on_stack(buf);
48103 + is_on_stack = object_starts_on_stack(buf);
48104 if (is_on_stack) {
48105 /*
48106 * dma onto stack is unsafe/nonportable, but callers to this
48107 diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
48108 index 738fa24..1568451 100644
48109 --- a/drivers/mmc/host/dw_mmc.h
48110 +++ b/drivers/mmc/host/dw_mmc.h
48111 @@ -257,5 +257,5 @@ struct dw_mci_drv_data {
48112 int (*parse_dt)(struct dw_mci *host);
48113 int (*execute_tuning)(struct dw_mci_slot *slot, u32 opcode,
48114 struct dw_mci_tuning_data *tuning_data);
48115 -};
48116 +} __do_const;
48117 #endif /* _DW_MMC_H_ */
48118 diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
48119 index 7ad463e..2aa0079 100644
48120 --- a/drivers/mmc/host/mmci.c
48121 +++ b/drivers/mmc/host/mmci.c
48122 @@ -1506,7 +1506,9 @@ static int mmci_probe(struct amba_device *dev,
48123 mmc->caps |= MMC_CAP_CMD23;
48124
48125 if (variant->busy_detect) {
48126 - mmci_ops.card_busy = mmci_card_busy;
48127 + pax_open_kernel();
48128 + *(void **)&mmci_ops.card_busy = mmci_card_busy;
48129 + pax_close_kernel();
48130 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
48131 mmc->caps |= MMC_CAP_WAIT_WHILE_BUSY;
48132 mmc->max_busy_timeout = 0;
48133 diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
48134 index ccec0e3..199f9ce 100644
48135 --- a/drivers/mmc/host/sdhci-esdhc-imx.c
48136 +++ b/drivers/mmc/host/sdhci-esdhc-imx.c
48137 @@ -1034,9 +1034,12 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
48138 host->mmc->caps |= MMC_CAP_1_8V_DDR;
48139 }
48140
48141 - if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING)
48142 - sdhci_esdhc_ops.platform_execute_tuning =
48143 + if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING) {
48144 + pax_open_kernel();
48145 + *(void **)&sdhci_esdhc_ops.platform_execute_tuning =
48146 esdhc_executing_tuning;
48147 + pax_close_kernel();
48148 + }
48149
48150 if (imx_data->socdata->flags & ESDHC_FLAG_STD_TUNING)
48151 writel(readl(host->ioaddr + ESDHC_TUNING_CTRL) |
48152 diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
48153 index fa5954a..56840e5 100644
48154 --- a/drivers/mmc/host/sdhci-s3c.c
48155 +++ b/drivers/mmc/host/sdhci-s3c.c
48156 @@ -584,9 +584,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
48157 * we can use overriding functions instead of default.
48158 */
48159 if (sc->no_divider) {
48160 - sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
48161 - sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
48162 - sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
48163 + pax_open_kernel();
48164 + *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
48165 + *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
48166 + *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
48167 + pax_close_kernel();
48168 }
48169
48170 /* It supports additional host capabilities if needed */
48171 diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
48172 index 423666b..81ff5eb 100644
48173 --- a/drivers/mtd/chips/cfi_cmdset_0020.c
48174 +++ b/drivers/mtd/chips/cfi_cmdset_0020.c
48175 @@ -666,7 +666,7 @@ cfi_staa_writev(struct mtd_info *mtd, const struct kvec *vecs,
48176 size_t totlen = 0, thislen;
48177 int ret = 0;
48178 size_t buflen = 0;
48179 - static char *buffer;
48180 + char *buffer;
48181
48182 if (!ECCBUF_SIZE) {
48183 /* We should fall back to a general writev implementation.
48184 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
48185 index 9f2012a..a81c720 100644
48186 --- a/drivers/mtd/nand/denali.c
48187 +++ b/drivers/mtd/nand/denali.c
48188 @@ -24,6 +24,7 @@
48189 #include <linux/slab.h>
48190 #include <linux/mtd/mtd.h>
48191 #include <linux/module.h>
48192 +#include <linux/slab.h>
48193
48194 #include "denali.h"
48195
48196 diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
48197 index f638cd8..2cbf586 100644
48198 --- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
48199 +++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
48200 @@ -387,7 +387,7 @@ void prepare_data_dma(struct gpmi_nand_data *this, enum dma_data_direction dr)
48201
48202 /* first try to map the upper buffer directly */
48203 if (virt_addr_valid(this->upper_buf) &&
48204 - !object_is_on_stack(this->upper_buf)) {
48205 + !object_starts_on_stack(this->upper_buf)) {
48206 sg_init_one(sgl, this->upper_buf, this->upper_len);
48207 ret = dma_map_sg(this->dev, sgl, 1, dr);
48208 if (ret == 0)
48209 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
48210 index 51b9d6a..52af9a7 100644
48211 --- a/drivers/mtd/nftlmount.c
48212 +++ b/drivers/mtd/nftlmount.c
48213 @@ -24,6 +24,7 @@
48214 #include <asm/errno.h>
48215 #include <linux/delay.h>
48216 #include <linux/slab.h>
48217 +#include <linux/sched.h>
48218 #include <linux/mtd/mtd.h>
48219 #include <linux/mtd/nand.h>
48220 #include <linux/mtd/nftl.h>
48221 diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
48222 index cf49c22..971b133 100644
48223 --- a/drivers/mtd/sm_ftl.c
48224 +++ b/drivers/mtd/sm_ftl.c
48225 @@ -56,7 +56,7 @@ static ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
48226 #define SM_CIS_VENDOR_OFFSET 0x59
48227 static struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
48228 {
48229 - struct attribute_group *attr_group;
48230 + attribute_group_no_const *attr_group;
48231 struct attribute **attributes;
48232 struct sm_sysfs_attribute *vendor_attribute;
48233 char *vendor;
48234 diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
48235 index 5ab3c18..5c3a836 100644
48236 --- a/drivers/net/bonding/bond_netlink.c
48237 +++ b/drivers/net/bonding/bond_netlink.c
48238 @@ -542,7 +542,7 @@ nla_put_failure:
48239 return -EMSGSIZE;
48240 }
48241
48242 -struct rtnl_link_ops bond_link_ops __read_mostly = {
48243 +struct rtnl_link_ops bond_link_ops = {
48244 .kind = "bond",
48245 .priv_size = sizeof(struct bonding),
48246 .setup = bond_setup,
48247 diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
48248 index 4168822..f38eeddf 100644
48249 --- a/drivers/net/can/Kconfig
48250 +++ b/drivers/net/can/Kconfig
48251 @@ -98,7 +98,7 @@ config CAN_JANZ_ICAN3
48252
48253 config CAN_FLEXCAN
48254 tristate "Support for Freescale FLEXCAN based chips"
48255 - depends on ARM || PPC
48256 + depends on (ARM && CPU_LITTLE_ENDIAN) || PPC
48257 ---help---
48258 Say Y here if you want to support for Freescale FlexCAN.
48259
48260 diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
48261 index 1d162cc..b546a75 100644
48262 --- a/drivers/net/ethernet/8390/ax88796.c
48263 +++ b/drivers/net/ethernet/8390/ax88796.c
48264 @@ -889,9 +889,11 @@ static int ax_probe(struct platform_device *pdev)
48265 if (ax->plat->reg_offsets)
48266 ei_local->reg_offset = ax->plat->reg_offsets;
48267 else {
48268 + resource_size_t _mem_size = mem_size;
48269 + do_div(_mem_size, 0x18);
48270 ei_local->reg_offset = ax->reg_offsets;
48271 for (ret = 0; ret < 0x18; ret++)
48272 - ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
48273 + ax->reg_offsets[ret] = _mem_size * ret;
48274 }
48275
48276 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
48277 diff --git a/drivers/net/ethernet/altera/altera_tse_main.c b/drivers/net/ethernet/altera/altera_tse_main.c
48278 index 7330681..7e9e463 100644
48279 --- a/drivers/net/ethernet/altera/altera_tse_main.c
48280 +++ b/drivers/net/ethernet/altera/altera_tse_main.c
48281 @@ -1182,7 +1182,7 @@ static int tse_shutdown(struct net_device *dev)
48282 return 0;
48283 }
48284
48285 -static struct net_device_ops altera_tse_netdev_ops = {
48286 +static net_device_ops_no_const altera_tse_netdev_ops __read_only = {
48287 .ndo_open = tse_open,
48288 .ndo_stop = tse_shutdown,
48289 .ndo_start_xmit = tse_start_xmit,
48290 @@ -1439,11 +1439,13 @@ static int altera_tse_probe(struct platform_device *pdev)
48291 ndev->netdev_ops = &altera_tse_netdev_ops;
48292 altera_tse_set_ethtool_ops(ndev);
48293
48294 + pax_open_kernel();
48295 altera_tse_netdev_ops.ndo_set_rx_mode = tse_set_rx_mode;
48296
48297 if (priv->hash_filter)
48298 altera_tse_netdev_ops.ndo_set_rx_mode =
48299 tse_set_rx_mode_hashfilter;
48300 + pax_close_kernel();
48301
48302 /* Scatter/gather IO is not supported,
48303 * so it is turned off
48304 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-common.h b/drivers/net/ethernet/amd/xgbe/xgbe-common.h
48305 index bf462ee8..18b8375 100644
48306 --- a/drivers/net/ethernet/amd/xgbe/xgbe-common.h
48307 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-common.h
48308 @@ -986,14 +986,14 @@ do { \
48309 * operations, everything works on mask values.
48310 */
48311 #define XMDIO_READ(_pdata, _mmd, _reg) \
48312 - ((_pdata)->hw_if.read_mmd_regs((_pdata), 0, \
48313 + ((_pdata)->hw_if->read_mmd_regs((_pdata), 0, \
48314 MII_ADDR_C45 | (_mmd << 16) | ((_reg) & 0xffff)))
48315
48316 #define XMDIO_READ_BITS(_pdata, _mmd, _reg, _mask) \
48317 (XMDIO_READ((_pdata), _mmd, _reg) & _mask)
48318
48319 #define XMDIO_WRITE(_pdata, _mmd, _reg, _val) \
48320 - ((_pdata)->hw_if.write_mmd_regs((_pdata), 0, \
48321 + ((_pdata)->hw_if->write_mmd_regs((_pdata), 0, \
48322 MII_ADDR_C45 | (_mmd << 16) | ((_reg) & 0xffff), (_val)))
48323
48324 #define XMDIO_WRITE_BITS(_pdata, _mmd, _reg, _mask, _val) \
48325 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-debugfs.c b/drivers/net/ethernet/amd/xgbe/xgbe-debugfs.c
48326 index 6bb76d5..ded47a8 100644
48327 --- a/drivers/net/ethernet/amd/xgbe/xgbe-debugfs.c
48328 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-debugfs.c
48329 @@ -273,7 +273,7 @@ static ssize_t xpcs_reg_value_read(struct file *filp, char __user *buffer,
48330 struct xgbe_prv_data *pdata = filp->private_data;
48331 unsigned int value;
48332
48333 - value = pdata->hw_if.read_mmd_regs(pdata, pdata->debugfs_xpcs_mmd,
48334 + value = pdata->hw_if->read_mmd_regs(pdata, pdata->debugfs_xpcs_mmd,
48335 pdata->debugfs_xpcs_reg);
48336
48337 return xgbe_common_read(buffer, count, ppos, value);
48338 @@ -291,7 +291,7 @@ static ssize_t xpcs_reg_value_write(struct file *filp,
48339 if (len < 0)
48340 return len;
48341
48342 - pdata->hw_if.write_mmd_regs(pdata, pdata->debugfs_xpcs_mmd,
48343 + pdata->hw_if->write_mmd_regs(pdata, pdata->debugfs_xpcs_mmd,
48344 pdata->debugfs_xpcs_reg, value);
48345
48346 return len;
48347 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-desc.c b/drivers/net/ethernet/amd/xgbe/xgbe-desc.c
48348 index 6f1c859..e96ac1a 100644
48349 --- a/drivers/net/ethernet/amd/xgbe/xgbe-desc.c
48350 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-desc.c
48351 @@ -236,7 +236,7 @@ err_ring:
48352
48353 static void xgbe_wrapper_tx_descriptor_init(struct xgbe_prv_data *pdata)
48354 {
48355 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48356 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48357 struct xgbe_channel *channel;
48358 struct xgbe_ring *ring;
48359 struct xgbe_ring_data *rdata;
48360 @@ -277,7 +277,7 @@ static void xgbe_wrapper_tx_descriptor_init(struct xgbe_prv_data *pdata)
48361
48362 static void xgbe_wrapper_rx_descriptor_init(struct xgbe_prv_data *pdata)
48363 {
48364 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48365 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48366 struct xgbe_channel *channel;
48367 struct xgbe_ring *ring;
48368 struct xgbe_ring_desc *rdesc;
48369 @@ -496,7 +496,7 @@ err_out:
48370 static void xgbe_realloc_skb(struct xgbe_channel *channel)
48371 {
48372 struct xgbe_prv_data *pdata = channel->pdata;
48373 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48374 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48375 struct xgbe_ring *ring = channel->rx_ring;
48376 struct xgbe_ring_data *rdata;
48377 struct sk_buff *skb = NULL;
48378 @@ -540,17 +540,12 @@ static void xgbe_realloc_skb(struct xgbe_channel *channel)
48379 DBGPR("<--xgbe_realloc_skb\n");
48380 }
48381
48382 -void xgbe_init_function_ptrs_desc(struct xgbe_desc_if *desc_if)
48383 -{
48384 - DBGPR("-->xgbe_init_function_ptrs_desc\n");
48385 -
48386 - desc_if->alloc_ring_resources = xgbe_alloc_ring_resources;
48387 - desc_if->free_ring_resources = xgbe_free_ring_resources;
48388 - desc_if->map_tx_skb = xgbe_map_tx_skb;
48389 - desc_if->realloc_skb = xgbe_realloc_skb;
48390 - desc_if->unmap_skb = xgbe_unmap_skb;
48391 - desc_if->wrapper_tx_desc_init = xgbe_wrapper_tx_descriptor_init;
48392 - desc_if->wrapper_rx_desc_init = xgbe_wrapper_rx_descriptor_init;
48393 -
48394 - DBGPR("<--xgbe_init_function_ptrs_desc\n");
48395 -}
48396 +const struct xgbe_desc_if default_xgbe_desc_if = {
48397 + .alloc_ring_resources = xgbe_alloc_ring_resources,
48398 + .free_ring_resources = xgbe_free_ring_resources,
48399 + .map_tx_skb = xgbe_map_tx_skb,
48400 + .realloc_skb = xgbe_realloc_skb,
48401 + .unmap_skb = xgbe_unmap_skb,
48402 + .wrapper_tx_desc_init = xgbe_wrapper_tx_descriptor_init,
48403 + .wrapper_rx_desc_init = xgbe_wrapper_rx_descriptor_init,
48404 +};
48405 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-dev.c b/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
48406 index 002293b..5ced1dd 100644
48407 --- a/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
48408 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
48409 @@ -2030,7 +2030,7 @@ static void xgbe_powerdown_rx(struct xgbe_prv_data *pdata)
48410
48411 static int xgbe_init(struct xgbe_prv_data *pdata)
48412 {
48413 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
48414 + struct xgbe_desc_if *desc_if = pdata->desc_if;
48415 int ret;
48416
48417 DBGPR("-->xgbe_init\n");
48418 @@ -2096,87 +2096,82 @@ static int xgbe_init(struct xgbe_prv_data *pdata)
48419 return 0;
48420 }
48421
48422 -void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *hw_if)
48423 -{
48424 - DBGPR("-->xgbe_init_function_ptrs\n");
48425 -
48426 - hw_if->tx_complete = xgbe_tx_complete;
48427 -
48428 - hw_if->set_promiscuous_mode = xgbe_set_promiscuous_mode;
48429 - hw_if->set_all_multicast_mode = xgbe_set_all_multicast_mode;
48430 - hw_if->set_addn_mac_addrs = xgbe_set_addn_mac_addrs;
48431 - hw_if->set_mac_address = xgbe_set_mac_address;
48432 -
48433 - hw_if->enable_rx_csum = xgbe_enable_rx_csum;
48434 - hw_if->disable_rx_csum = xgbe_disable_rx_csum;
48435 -
48436 - hw_if->enable_rx_vlan_stripping = xgbe_enable_rx_vlan_stripping;
48437 - hw_if->disable_rx_vlan_stripping = xgbe_disable_rx_vlan_stripping;
48438 -
48439 - hw_if->read_mmd_regs = xgbe_read_mmd_regs;
48440 - hw_if->write_mmd_regs = xgbe_write_mmd_regs;
48441 -
48442 - hw_if->set_gmii_speed = xgbe_set_gmii_speed;
48443 - hw_if->set_gmii_2500_speed = xgbe_set_gmii_2500_speed;
48444 - hw_if->set_xgmii_speed = xgbe_set_xgmii_speed;
48445 -
48446 - hw_if->enable_tx = xgbe_enable_tx;
48447 - hw_if->disable_tx = xgbe_disable_tx;
48448 - hw_if->enable_rx = xgbe_enable_rx;
48449 - hw_if->disable_rx = xgbe_disable_rx;
48450 -
48451 - hw_if->powerup_tx = xgbe_powerup_tx;
48452 - hw_if->powerdown_tx = xgbe_powerdown_tx;
48453 - hw_if->powerup_rx = xgbe_powerup_rx;
48454 - hw_if->powerdown_rx = xgbe_powerdown_rx;
48455 -
48456 - hw_if->pre_xmit = xgbe_pre_xmit;
48457 - hw_if->dev_read = xgbe_dev_read;
48458 - hw_if->enable_int = xgbe_enable_int;
48459 - hw_if->disable_int = xgbe_disable_int;
48460 - hw_if->init = xgbe_init;
48461 - hw_if->exit = xgbe_exit;
48462 +const struct xgbe_hw_if default_xgbe_hw_if = {
48463 + .tx_complete = xgbe_tx_complete,
48464 +
48465 + .set_promiscuous_mode = xgbe_set_promiscuous_mode,
48466 + .set_all_multicast_mode = xgbe_set_all_multicast_mode,
48467 + .set_addn_mac_addrs = xgbe_set_addn_mac_addrs,
48468 + .set_mac_address = xgbe_set_mac_address,
48469 +
48470 + .enable_rx_csum = xgbe_enable_rx_csum,
48471 + .disable_rx_csum = xgbe_disable_rx_csum,
48472 +
48473 + .enable_rx_vlan_stripping = xgbe_enable_rx_vlan_stripping,
48474 + .disable_rx_vlan_stripping = xgbe_disable_rx_vlan_stripping,
48475 +
48476 + .read_mmd_regs = xgbe_read_mmd_regs,
48477 + .write_mmd_regs = xgbe_write_mmd_regs,
48478 +
48479 + .set_gmii_speed = xgbe_set_gmii_speed,
48480 + .set_gmii_2500_speed = xgbe_set_gmii_2500_speed,
48481 + .set_xgmii_speed = xgbe_set_xgmii_speed,
48482 +
48483 + .enable_tx = xgbe_enable_tx,
48484 + .disable_tx = xgbe_disable_tx,
48485 + .enable_rx = xgbe_enable_rx,
48486 + .disable_rx = xgbe_disable_rx,
48487 +
48488 + .powerup_tx = xgbe_powerup_tx,
48489 + .powerdown_tx = xgbe_powerdown_tx,
48490 + .powerup_rx = xgbe_powerup_rx,
48491 + .powerdown_rx = xgbe_powerdown_rx,
48492 +
48493 + .pre_xmit = xgbe_pre_xmit,
48494 + .dev_read = xgbe_dev_read,
48495 + .enable_int = xgbe_enable_int,
48496 + .disable_int = xgbe_disable_int,
48497 + .init = xgbe_init,
48498 + .exit = xgbe_exit,
48499
48500 /* Descriptor related Sequences have to be initialized here */
48501 - hw_if->tx_desc_init = xgbe_tx_desc_init;
48502 - hw_if->rx_desc_init = xgbe_rx_desc_init;
48503 - hw_if->tx_desc_reset = xgbe_tx_desc_reset;
48504 - hw_if->rx_desc_reset = xgbe_rx_desc_reset;
48505 - hw_if->is_last_desc = xgbe_is_last_desc;
48506 - hw_if->is_context_desc = xgbe_is_context_desc;
48507 + .tx_desc_init = xgbe_tx_desc_init,
48508 + .rx_desc_init = xgbe_rx_desc_init,
48509 + .tx_desc_reset = xgbe_tx_desc_reset,
48510 + .rx_desc_reset = xgbe_rx_desc_reset,
48511 + .is_last_desc = xgbe_is_last_desc,
48512 + .is_context_desc = xgbe_is_context_desc,
48513
48514 /* For FLOW ctrl */
48515 - hw_if->config_tx_flow_control = xgbe_config_tx_flow_control;
48516 - hw_if->config_rx_flow_control = xgbe_config_rx_flow_control;
48517 + .config_tx_flow_control = xgbe_config_tx_flow_control,
48518 + .config_rx_flow_control = xgbe_config_rx_flow_control,
48519
48520 /* For RX coalescing */
48521 - hw_if->config_rx_coalesce = xgbe_config_rx_coalesce;
48522 - hw_if->config_tx_coalesce = xgbe_config_tx_coalesce;
48523 - hw_if->usec_to_riwt = xgbe_usec_to_riwt;
48524 - hw_if->riwt_to_usec = xgbe_riwt_to_usec;
48525 + .config_rx_coalesce = xgbe_config_rx_coalesce,
48526 + .config_tx_coalesce = xgbe_config_tx_coalesce,
48527 + .usec_to_riwt = xgbe_usec_to_riwt,
48528 + .riwt_to_usec = xgbe_riwt_to_usec,
48529
48530 /* For RX and TX threshold config */
48531 - hw_if->config_rx_threshold = xgbe_config_rx_threshold;
48532 - hw_if->config_tx_threshold = xgbe_config_tx_threshold;
48533 + .config_rx_threshold = xgbe_config_rx_threshold,
48534 + .config_tx_threshold = xgbe_config_tx_threshold,
48535
48536 /* For RX and TX Store and Forward Mode config */
48537 - hw_if->config_rsf_mode = xgbe_config_rsf_mode;
48538 - hw_if->config_tsf_mode = xgbe_config_tsf_mode;
48539 + .config_rsf_mode = xgbe_config_rsf_mode,
48540 + .config_tsf_mode = xgbe_config_tsf_mode,
48541
48542 /* For TX DMA Operating on Second Frame config */
48543 - hw_if->config_osp_mode = xgbe_config_osp_mode;
48544 + .config_osp_mode = xgbe_config_osp_mode,
48545
48546 /* For RX and TX PBL config */
48547 - hw_if->config_rx_pbl_val = xgbe_config_rx_pbl_val;
48548 - hw_if->get_rx_pbl_val = xgbe_get_rx_pbl_val;
48549 - hw_if->config_tx_pbl_val = xgbe_config_tx_pbl_val;
48550 - hw_if->get_tx_pbl_val = xgbe_get_tx_pbl_val;
48551 - hw_if->config_pblx8 = xgbe_config_pblx8;
48552 + .config_rx_pbl_val = xgbe_config_rx_pbl_val,
48553 + .get_rx_pbl_val = xgbe_get_rx_pbl_val,
48554 + .config_tx_pbl_val = xgbe_config_tx_pbl_val,
48555 + .get_tx_pbl_val = xgbe_get_tx_pbl_val,
48556 + .config_pblx8 = xgbe_config_pblx8,
48557
48558 /* For MMC statistics support */
48559 - hw_if->tx_mmc_int = xgbe_tx_mmc_int;
48560 - hw_if->rx_mmc_int = xgbe_rx_mmc_int;
48561 - hw_if->read_mmc_stats = xgbe_read_mmc_stats;
48562 -
48563 - DBGPR("<--xgbe_init_function_ptrs\n");
48564 -}
48565 + .tx_mmc_int = xgbe_tx_mmc_int,
48566 + .rx_mmc_int = xgbe_rx_mmc_int,
48567 + .read_mmc_stats = xgbe_read_mmc_stats,
48568 +};
48569 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-drv.c b/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
48570 index cfe3d93..07a78ae 100644
48571 --- a/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
48572 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
48573 @@ -153,7 +153,7 @@ static int xgbe_calc_rx_buf_size(struct net_device *netdev, unsigned int mtu)
48574
48575 static void xgbe_enable_rx_tx_ints(struct xgbe_prv_data *pdata)
48576 {
48577 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48578 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48579 struct xgbe_channel *channel;
48580 unsigned int i;
48581
48582 @@ -170,7 +170,7 @@ static void xgbe_enable_rx_tx_ints(struct xgbe_prv_data *pdata)
48583
48584 static void xgbe_disable_rx_tx_ints(struct xgbe_prv_data *pdata)
48585 {
48586 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48587 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48588 struct xgbe_channel *channel;
48589 unsigned int i;
48590
48591 @@ -188,7 +188,7 @@ static void xgbe_disable_rx_tx_ints(struct xgbe_prv_data *pdata)
48592 static irqreturn_t xgbe_isr(int irq, void *data)
48593 {
48594 struct xgbe_prv_data *pdata = data;
48595 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48596 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48597 struct xgbe_channel *channel;
48598 unsigned int dma_isr, dma_ch_isr;
48599 unsigned int mac_isr;
48600 @@ -403,7 +403,7 @@ static void xgbe_napi_disable(struct xgbe_prv_data *pdata)
48601
48602 void xgbe_init_tx_coalesce(struct xgbe_prv_data *pdata)
48603 {
48604 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48605 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48606
48607 DBGPR("-->xgbe_init_tx_coalesce\n");
48608
48609 @@ -417,7 +417,7 @@ void xgbe_init_tx_coalesce(struct xgbe_prv_data *pdata)
48610
48611 void xgbe_init_rx_coalesce(struct xgbe_prv_data *pdata)
48612 {
48613 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48614 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48615
48616 DBGPR("-->xgbe_init_rx_coalesce\n");
48617
48618 @@ -431,7 +431,7 @@ void xgbe_init_rx_coalesce(struct xgbe_prv_data *pdata)
48619
48620 static void xgbe_free_tx_skbuff(struct xgbe_prv_data *pdata)
48621 {
48622 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
48623 + struct xgbe_desc_if *desc_if = pdata->desc_if;
48624 struct xgbe_channel *channel;
48625 struct xgbe_ring *ring;
48626 struct xgbe_ring_data *rdata;
48627 @@ -456,7 +456,7 @@ static void xgbe_free_tx_skbuff(struct xgbe_prv_data *pdata)
48628
48629 static void xgbe_free_rx_skbuff(struct xgbe_prv_data *pdata)
48630 {
48631 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
48632 + struct xgbe_desc_if *desc_if = pdata->desc_if;
48633 struct xgbe_channel *channel;
48634 struct xgbe_ring *ring;
48635 struct xgbe_ring_data *rdata;
48636 @@ -482,7 +482,7 @@ static void xgbe_free_rx_skbuff(struct xgbe_prv_data *pdata)
48637 int xgbe_powerdown(struct net_device *netdev, unsigned int caller)
48638 {
48639 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48640 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48641 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48642 unsigned long flags;
48643
48644 DBGPR("-->xgbe_powerdown\n");
48645 @@ -520,7 +520,7 @@ int xgbe_powerdown(struct net_device *netdev, unsigned int caller)
48646 int xgbe_powerup(struct net_device *netdev, unsigned int caller)
48647 {
48648 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48649 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48650 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48651 unsigned long flags;
48652
48653 DBGPR("-->xgbe_powerup\n");
48654 @@ -557,7 +557,7 @@ int xgbe_powerup(struct net_device *netdev, unsigned int caller)
48655
48656 static int xgbe_start(struct xgbe_prv_data *pdata)
48657 {
48658 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48659 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48660 struct net_device *netdev = pdata->netdev;
48661
48662 DBGPR("-->xgbe_start\n");
48663 @@ -583,7 +583,7 @@ static int xgbe_start(struct xgbe_prv_data *pdata)
48664
48665 static void xgbe_stop(struct xgbe_prv_data *pdata)
48666 {
48667 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48668 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48669 struct net_device *netdev = pdata->netdev;
48670
48671 DBGPR("-->xgbe_stop\n");
48672 @@ -603,7 +603,7 @@ static void xgbe_stop(struct xgbe_prv_data *pdata)
48673
48674 static void xgbe_restart_dev(struct xgbe_prv_data *pdata, unsigned int reset)
48675 {
48676 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48677 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48678
48679 DBGPR("-->xgbe_restart_dev\n");
48680
48681 @@ -741,8 +741,8 @@ static void xgbe_packet_info(struct xgbe_ring *ring, struct sk_buff *skb,
48682 static int xgbe_open(struct net_device *netdev)
48683 {
48684 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48685 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48686 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
48687 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48688 + struct xgbe_desc_if *desc_if = pdata->desc_if;
48689 int ret;
48690
48691 DBGPR("-->xgbe_open\n");
48692 @@ -804,8 +804,8 @@ err_clk:
48693 static int xgbe_close(struct net_device *netdev)
48694 {
48695 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48696 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48697 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
48698 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48699 + struct xgbe_desc_if *desc_if = pdata->desc_if;
48700
48701 DBGPR("-->xgbe_close\n");
48702
48703 @@ -835,8 +835,8 @@ static int xgbe_close(struct net_device *netdev)
48704 static int xgbe_xmit(struct sk_buff *skb, struct net_device *netdev)
48705 {
48706 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48707 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48708 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
48709 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48710 + struct xgbe_desc_if *desc_if = pdata->desc_if;
48711 struct xgbe_channel *channel;
48712 struct xgbe_ring *ring;
48713 struct xgbe_packet_data *packet;
48714 @@ -903,7 +903,7 @@ tx_netdev_return:
48715 static void xgbe_set_rx_mode(struct net_device *netdev)
48716 {
48717 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48718 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48719 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48720 unsigned int pr_mode, am_mode;
48721
48722 DBGPR("-->xgbe_set_rx_mode\n");
48723 @@ -930,7 +930,7 @@ static void xgbe_set_rx_mode(struct net_device *netdev)
48724 static int xgbe_set_mac_address(struct net_device *netdev, void *addr)
48725 {
48726 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48727 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48728 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48729 struct sockaddr *saddr = addr;
48730
48731 DBGPR("-->xgbe_set_mac_address\n");
48732 @@ -976,7 +976,7 @@ static struct rtnl_link_stats64 *xgbe_get_stats64(struct net_device *netdev,
48733
48734 DBGPR("-->%s\n", __func__);
48735
48736 - pdata->hw_if.read_mmc_stats(pdata);
48737 + pdata->hw_if->read_mmc_stats(pdata);
48738
48739 s->rx_packets = pstats->rxframecount_gb;
48740 s->rx_bytes = pstats->rxoctetcount_gb;
48741 @@ -1020,7 +1020,7 @@ static int xgbe_set_features(struct net_device *netdev,
48742 netdev_features_t features)
48743 {
48744 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48745 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48746 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48747 unsigned int rxcsum_enabled, rxvlan_enabled;
48748
48749 rxcsum_enabled = !!(pdata->netdev_features & NETIF_F_RXCSUM);
48750 @@ -1072,8 +1072,8 @@ struct net_device_ops *xgbe_get_netdev_ops(void)
48751 static int xgbe_tx_poll(struct xgbe_channel *channel)
48752 {
48753 struct xgbe_prv_data *pdata = channel->pdata;
48754 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48755 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
48756 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48757 + struct xgbe_desc_if *desc_if = pdata->desc_if;
48758 struct xgbe_ring *ring = channel->tx_ring;
48759 struct xgbe_ring_data *rdata;
48760 struct xgbe_ring_desc *rdesc;
48761 @@ -1124,8 +1124,8 @@ static int xgbe_tx_poll(struct xgbe_channel *channel)
48762 static int xgbe_rx_poll(struct xgbe_channel *channel, int budget)
48763 {
48764 struct xgbe_prv_data *pdata = channel->pdata;
48765 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48766 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
48767 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48768 + struct xgbe_desc_if *desc_if = pdata->desc_if;
48769 struct xgbe_ring *ring = channel->rx_ring;
48770 struct xgbe_ring_data *rdata;
48771 struct xgbe_packet_data *packet;
48772 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c b/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
48773 index 8909f2b..719e767 100644
48774 --- a/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
48775 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
48776 @@ -202,7 +202,7 @@ static void xgbe_get_ethtool_stats(struct net_device *netdev,
48777
48778 DBGPR("-->%s\n", __func__);
48779
48780 - pdata->hw_if.read_mmc_stats(pdata);
48781 + pdata->hw_if->read_mmc_stats(pdata);
48782 for (i = 0; i < XGBE_STATS_COUNT; i++) {
48783 stat = (u8 *)pdata + xgbe_gstring_stats[i].stat_offset;
48784 *data++ = *(u64 *)stat;
48785 @@ -387,7 +387,7 @@ static int xgbe_get_coalesce(struct net_device *netdev,
48786 struct ethtool_coalesce *ec)
48787 {
48788 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48789 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48790 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48791 unsigned int riwt;
48792
48793 DBGPR("-->xgbe_get_coalesce\n");
48794 @@ -410,7 +410,7 @@ static int xgbe_set_coalesce(struct net_device *netdev,
48795 struct ethtool_coalesce *ec)
48796 {
48797 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48798 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48799 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48800 unsigned int rx_frames, rx_riwt, rx_usecs;
48801 unsigned int tx_frames, tx_usecs;
48802
48803 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-main.c b/drivers/net/ethernet/amd/xgbe/xgbe-main.c
48804 index 5a1891f..1b7888e 100644
48805 --- a/drivers/net/ethernet/amd/xgbe/xgbe-main.c
48806 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-main.c
48807 @@ -210,12 +210,6 @@ static void xgbe_default_config(struct xgbe_prv_data *pdata)
48808 DBGPR("<--xgbe_default_config\n");
48809 }
48810
48811 -static void xgbe_init_all_fptrs(struct xgbe_prv_data *pdata)
48812 -{
48813 - xgbe_init_function_ptrs_dev(&pdata->hw_if);
48814 - xgbe_init_function_ptrs_desc(&pdata->desc_if);
48815 -}
48816 -
48817 static int xgbe_probe(struct platform_device *pdev)
48818 {
48819 struct xgbe_prv_data *pdata;
48820 @@ -306,9 +300,8 @@ static int xgbe_probe(struct platform_device *pdev)
48821 netdev->base_addr = (unsigned long)pdata->xgmac_regs;
48822
48823 /* Set all the function pointers */
48824 - xgbe_init_all_fptrs(pdata);
48825 - hw_if = &pdata->hw_if;
48826 - desc_if = &pdata->desc_if;
48827 + hw_if = pdata->hw_if = &default_xgbe_hw_if;
48828 + desc_if = pdata->desc_if = &default_xgbe_desc_if;
48829
48830 /* Issue software reset to device */
48831 hw_if->exit(pdata);
48832 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c b/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
48833 index ea7a5d6..d10a742 100644
48834 --- a/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
48835 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
48836 @@ -128,7 +128,7 @@
48837 static int xgbe_mdio_read(struct mii_bus *mii, int prtad, int mmd_reg)
48838 {
48839 struct xgbe_prv_data *pdata = mii->priv;
48840 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48841 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48842 int mmd_data;
48843
48844 DBGPR_MDIO("-->xgbe_mdio_read: prtad=%#x mmd_reg=%#x\n",
48845 @@ -145,7 +145,7 @@ static int xgbe_mdio_write(struct mii_bus *mii, int prtad, int mmd_reg,
48846 u16 mmd_val)
48847 {
48848 struct xgbe_prv_data *pdata = mii->priv;
48849 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48850 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48851 int mmd_data = mmd_val;
48852
48853 DBGPR_MDIO("-->xgbe_mdio_write: prtad=%#x mmd_reg=%#x mmd_data=%#x\n",
48854 @@ -161,7 +161,7 @@ static int xgbe_mdio_write(struct mii_bus *mii, int prtad, int mmd_reg,
48855 static void xgbe_adjust_link(struct net_device *netdev)
48856 {
48857 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48858 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48859 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48860 struct phy_device *phydev = pdata->phydev;
48861 unsigned long flags;
48862 int new_state = 0;
48863 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe.h b/drivers/net/ethernet/amd/xgbe/xgbe.h
48864 index ab06271..a560fa7 100644
48865 --- a/drivers/net/ethernet/amd/xgbe/xgbe.h
48866 +++ b/drivers/net/ethernet/amd/xgbe/xgbe.h
48867 @@ -527,8 +527,8 @@ struct xgbe_prv_data {
48868
48869 int irq_number;
48870
48871 - struct xgbe_hw_if hw_if;
48872 - struct xgbe_desc_if desc_if;
48873 + const struct xgbe_hw_if *hw_if;
48874 + const struct xgbe_desc_if *desc_if;
48875
48876 /* Rings for Tx/Rx on a DMA channel */
48877 struct xgbe_channel *channel;
48878 @@ -611,6 +611,9 @@ struct xgbe_prv_data {
48879 #endif
48880 };
48881
48882 +extern const struct xgbe_hw_if default_xgbe_hw_if;
48883 +extern const struct xgbe_desc_if default_xgbe_desc_if;
48884 +
48885 /* Function prototypes*/
48886
48887 void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *);
48888 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
48889 index 571427c..e9fe9e7 100644
48890 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
48891 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
48892 @@ -1058,7 +1058,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
48893 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
48894 {
48895 /* RX_MODE controlling object */
48896 - bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
48897 + bnx2x_init_rx_mode_obj(bp);
48898
48899 /* multicast configuration controlling object */
48900 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
48901 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
48902 index b193604..8873bfd 100644
48903 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
48904 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
48905 @@ -2329,15 +2329,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
48906 return rc;
48907 }
48908
48909 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
48910 - struct bnx2x_rx_mode_obj *o)
48911 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
48912 {
48913 if (CHIP_IS_E1x(bp)) {
48914 - o->wait_comp = bnx2x_empty_rx_mode_wait;
48915 - o->config_rx_mode = bnx2x_set_rx_mode_e1x;
48916 + bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
48917 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
48918 } else {
48919 - o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
48920 - o->config_rx_mode = bnx2x_set_rx_mode_e2;
48921 + bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
48922 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
48923 }
48924 }
48925
48926 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
48927 index 718ecd2..2183b2f 100644
48928 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
48929 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
48930 @@ -1340,8 +1340,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
48931
48932 /********************* RX MODE ****************/
48933
48934 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
48935 - struct bnx2x_rx_mode_obj *o);
48936 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
48937
48938 /**
48939 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
48940 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
48941 index 461acca..2b546ba 100644
48942 --- a/drivers/net/ethernet/broadcom/tg3.h
48943 +++ b/drivers/net/ethernet/broadcom/tg3.h
48944 @@ -150,6 +150,7 @@
48945 #define CHIPREV_ID_5750_A0 0x4000
48946 #define CHIPREV_ID_5750_A1 0x4001
48947 #define CHIPREV_ID_5750_A3 0x4003
48948 +#define CHIPREV_ID_5750_C1 0x4201
48949 #define CHIPREV_ID_5750_C2 0x4202
48950 #define CHIPREV_ID_5752_A0_HW 0x5000
48951 #define CHIPREV_ID_5752_A0 0x6000
48952 diff --git a/drivers/net/ethernet/brocade/bna/bna_enet.c b/drivers/net/ethernet/brocade/bna/bna_enet.c
48953 index 13f9636..228040f 100644
48954 --- a/drivers/net/ethernet/brocade/bna/bna_enet.c
48955 +++ b/drivers/net/ethernet/brocade/bna/bna_enet.c
48956 @@ -1690,10 +1690,10 @@ bna_cb_ioceth_reset(void *arg)
48957 }
48958
48959 static struct bfa_ioc_cbfn bna_ioceth_cbfn = {
48960 - bna_cb_ioceth_enable,
48961 - bna_cb_ioceth_disable,
48962 - bna_cb_ioceth_hbfail,
48963 - bna_cb_ioceth_reset
48964 + .enable_cbfn = bna_cb_ioceth_enable,
48965 + .disable_cbfn = bna_cb_ioceth_disable,
48966 + .hbfail_cbfn = bna_cb_ioceth_hbfail,
48967 + .reset_cbfn = bna_cb_ioceth_reset
48968 };
48969
48970 static void bna_attr_init(struct bna_ioceth *ioceth)
48971 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
48972 index 8cffcdf..aadf043 100644
48973 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
48974 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
48975 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
48976 */
48977 struct l2t_skb_cb {
48978 arp_failure_handler_func arp_failure_handler;
48979 -};
48980 +} __no_const;
48981
48982 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
48983
48984 diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
48985 index a83271c..cf00874 100644
48986 --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
48987 +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
48988 @@ -2174,7 +2174,7 @@ static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
48989
48990 int i;
48991 struct adapter *ap = netdev2adap(dev);
48992 - static const unsigned int *reg_ranges;
48993 + const unsigned int *reg_ranges;
48994 int arr_size = 0, buf_size = 0;
48995
48996 if (is_t4(ap->params.chip)) {
48997 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
48998 index c05b66d..ed69872 100644
48999 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
49000 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
49001 @@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
49002 for (i=0; i<ETH_ALEN; i++) {
49003 tmp.addr[i] = dev->dev_addr[i];
49004 }
49005 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
49006 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
49007 break;
49008
49009 case DE4X5_SET_HWADDR: /* Set the hardware address */
49010 @@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
49011 spin_lock_irqsave(&lp->lock, flags);
49012 memcpy(&statbuf, &lp->pktStats, ioc->len);
49013 spin_unlock_irqrestore(&lp->lock, flags);
49014 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
49015 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
49016 return -EFAULT;
49017 break;
49018 }
49019 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
49020 index 1e187fb..d024547 100644
49021 --- a/drivers/net/ethernet/emulex/benet/be_main.c
49022 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
49023 @@ -533,7 +533,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
49024
49025 if (wrapped)
49026 newacc += 65536;
49027 - ACCESS_ONCE(*acc) = newacc;
49028 + ACCESS_ONCE_RW(*acc) = newacc;
49029 }
49030
49031 static void populate_erx_stats(struct be_adapter *adapter,
49032 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
49033 index c77fa4a..7fd42fc 100644
49034 --- a/drivers/net/ethernet/faraday/ftgmac100.c
49035 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
49036 @@ -30,6 +30,8 @@
49037 #include <linux/netdevice.h>
49038 #include <linux/phy.h>
49039 #include <linux/platform_device.h>
49040 +#include <linux/interrupt.h>
49041 +#include <linux/irqreturn.h>
49042 #include <net/ip.h>
49043
49044 #include "ftgmac100.h"
49045 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
49046 index 4ff1adc..0ea6bf4 100644
49047 --- a/drivers/net/ethernet/faraday/ftmac100.c
49048 +++ b/drivers/net/ethernet/faraday/ftmac100.c
49049 @@ -31,6 +31,8 @@
49050 #include <linux/module.h>
49051 #include <linux/netdevice.h>
49052 #include <linux/platform_device.h>
49053 +#include <linux/interrupt.h>
49054 +#include <linux/irqreturn.h>
49055
49056 #include "ftmac100.h"
49057
49058 diff --git a/drivers/net/ethernet/intel/i40e/i40e_ptp.c b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
49059 index 101f439..59e7ec6 100644
49060 --- a/drivers/net/ethernet/intel/i40e/i40e_ptp.c
49061 +++ b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
49062 @@ -401,7 +401,7 @@ void i40e_ptp_set_increment(struct i40e_pf *pf)
49063 wr32(hw, I40E_PRTTSYN_INC_H, incval >> 32);
49064
49065 /* Update the base adjustement value. */
49066 - ACCESS_ONCE(pf->ptp_base_adj) = incval;
49067 + ACCESS_ONCE_RW(pf->ptp_base_adj) = incval;
49068 smp_mb(); /* Force the above update. */
49069 }
49070
49071 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
49072 index 68f87ec..241dbe3 100644
49073 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
49074 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
49075 @@ -792,7 +792,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
49076 }
49077
49078 /* update the base incval used to calculate frequency adjustment */
49079 - ACCESS_ONCE(adapter->base_incval) = incval;
49080 + ACCESS_ONCE_RW(adapter->base_incval) = incval;
49081 smp_mb();
49082
49083 /* need lock to prevent incorrect read while modifying cyclecounter */
49084 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
49085 index 2bbd01f..e8baa64 100644
49086 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
49087 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
49088 @@ -3457,7 +3457,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
49089 struct __vxge_hw_fifo *fifo;
49090 struct vxge_hw_fifo_config *config;
49091 u32 txdl_size, txdl_per_memblock;
49092 - struct vxge_hw_mempool_cbs fifo_mp_callback;
49093 + static struct vxge_hw_mempool_cbs fifo_mp_callback = {
49094 + .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
49095 + };
49096 +
49097 struct __vxge_hw_virtualpath *vpath;
49098
49099 if ((vp == NULL) || (attr == NULL)) {
49100 @@ -3540,8 +3543,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
49101 goto exit;
49102 }
49103
49104 - fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
49105 -
49106 fifo->mempool =
49107 __vxge_hw_mempool_create(vpath->hldev,
49108 fifo->config->memblock_size,
49109 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
49110 index 73e6683..464e910 100644
49111 --- a/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c
49112 +++ b/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c
49113 @@ -120,6 +120,10 @@ static void pch_gbe_mdio_write(struct net_device *netdev, int addr, int reg,
49114 int data);
49115 static void pch_gbe_set_multi(struct net_device *netdev);
49116
49117 +static struct sock_filter ptp_filter[] = {
49118 + PTP_FILTER
49119 +};
49120 +
49121 static int pch_ptp_match(struct sk_buff *skb, u16 uid_hi, u32 uid_lo, u16 seqid)
49122 {
49123 u8 *data = skb->data;
49124 @@ -127,7 +131,7 @@ static int pch_ptp_match(struct sk_buff *skb, u16 uid_hi, u32 uid_lo, u16 seqid)
49125 u16 *hi, *id;
49126 u32 lo;
49127
49128 - if (ptp_classify_raw(skb) == PTP_CLASS_NONE)
49129 + if (sk_run_filter(skb, ptp_filter) == PTP_CLASS_NONE)
49130 return 0;
49131
49132 offset = ETH_HLEN + IPV4_HLEN(data) + UDP_HLEN;
49133 @@ -2631,6 +2635,11 @@ static int pch_gbe_probe(struct pci_dev *pdev,
49134
49135 adapter->ptp_pdev = pci_get_bus_and_slot(adapter->pdev->bus->number,
49136 PCI_DEVFN(12, 4));
49137 + if (ptp_filter_init(ptp_filter, ARRAY_SIZE(ptp_filter))) {
49138 + dev_err(&pdev->dev, "Bad ptp filter\n");
49139 + ret = -EINVAL;
49140 + goto err_free_netdev;
49141 + }
49142
49143 netdev->netdev_ops = &pch_gbe_netdev_ops;
49144 netdev->watchdog_timeo = PCH_GBE_WATCHDOG_PERIOD;
49145 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
49146 index f33559b..c7f50ac 100644
49147 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
49148 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
49149 @@ -2176,7 +2176,9 @@ int qlcnic_83xx_configure_opmode(struct qlcnic_adapter *adapter)
49150 max_tx_rings = QLCNIC_MAX_VNIC_TX_RINGS;
49151 } else if (ret == QLC_83XX_DEFAULT_OPMODE) {
49152 ahw->nic_mode = QLCNIC_DEFAULT_MODE;
49153 - adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
49154 + pax_open_kernel();
49155 + *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
49156 + pax_close_kernel();
49157 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
49158 max_sds_rings = QLCNIC_MAX_SDS_RINGS;
49159 max_tx_rings = QLCNIC_MAX_TX_RINGS;
49160 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
49161 index be7d7a6..a8983f8 100644
49162 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
49163 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
49164 @@ -207,17 +207,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
49165 case QLCNIC_NON_PRIV_FUNC:
49166 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
49167 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
49168 - nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
49169 + pax_open_kernel();
49170 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
49171 + pax_close_kernel();
49172 break;
49173 case QLCNIC_PRIV_FUNC:
49174 ahw->op_mode = QLCNIC_PRIV_FUNC;
49175 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
49176 - nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
49177 + pax_open_kernel();
49178 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
49179 + pax_close_kernel();
49180 break;
49181 case QLCNIC_MGMT_FUNC:
49182 ahw->op_mode = QLCNIC_MGMT_FUNC;
49183 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
49184 - nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
49185 + pax_open_kernel();
49186 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
49187 + pax_close_kernel();
49188 break;
49189 default:
49190 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
49191 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
49192 index e46fc39..abe135b 100644
49193 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
49194 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
49195 @@ -1228,7 +1228,7 @@ flash_temp:
49196 int qlcnic_dump_fw(struct qlcnic_adapter *adapter)
49197 {
49198 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
49199 - static const struct qlcnic_dump_operations *fw_dump_ops;
49200 + const struct qlcnic_dump_operations *fw_dump_ops;
49201 struct qlcnic_83xx_dump_template_hdr *hdr_83xx;
49202 u32 entry_offset, dump, no_entries, buf_offset = 0;
49203 int i, k, ops_cnt, ops_index, dump_size = 0;
49204 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
49205 index 61623e9..ac97c27 100644
49206 --- a/drivers/net/ethernet/realtek/r8169.c
49207 +++ b/drivers/net/ethernet/realtek/r8169.c
49208 @@ -759,22 +759,22 @@ struct rtl8169_private {
49209 struct mdio_ops {
49210 void (*write)(struct rtl8169_private *, int, int);
49211 int (*read)(struct rtl8169_private *, int);
49212 - } mdio_ops;
49213 + } __no_const mdio_ops;
49214
49215 struct pll_power_ops {
49216 void (*down)(struct rtl8169_private *);
49217 void (*up)(struct rtl8169_private *);
49218 - } pll_power_ops;
49219 + } __no_const pll_power_ops;
49220
49221 struct jumbo_ops {
49222 void (*enable)(struct rtl8169_private *);
49223 void (*disable)(struct rtl8169_private *);
49224 - } jumbo_ops;
49225 + } __no_const jumbo_ops;
49226
49227 struct csi_ops {
49228 void (*write)(struct rtl8169_private *, int, int);
49229 u32 (*read)(struct rtl8169_private *, int);
49230 - } csi_ops;
49231 + } __no_const csi_ops;
49232
49233 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
49234 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
49235 diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
49236 index 6b861e3..204ac86 100644
49237 --- a/drivers/net/ethernet/sfc/ptp.c
49238 +++ b/drivers/net/ethernet/sfc/ptp.c
49239 @@ -822,7 +822,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
49240 ptp->start.dma_addr);
49241
49242 /* Clear flag that signals MC ready */
49243 - ACCESS_ONCE(*start) = 0;
49244 + ACCESS_ONCE_RW(*start) = 0;
49245 rc = efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
49246 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
49247 EFX_BUG_ON_PARANOID(rc);
49248 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
49249 index 50617c5..b13724c 100644
49250 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
49251 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
49252 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
49253
49254 writel(value, ioaddr + MMC_CNTRL);
49255
49256 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
49257 - MMC_CNTRL, value);
49258 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
49259 +// MMC_CNTRL, value);
49260 }
49261
49262 /* To mask all all interrupts.*/
49263 diff --git a/drivers/net/ethernet/ti/cpts.c b/drivers/net/ethernet/ti/cpts.c
49264 index 6b56f85..50e285f 100644
49265 --- a/drivers/net/ethernet/ti/cpts.c
49266 +++ b/drivers/net/ethernet/ti/cpts.c
49267 @@ -33,6 +33,10 @@
49268
49269 #ifdef CONFIG_TI_CPTS
49270
49271 +static struct sock_filter ptp_filter[] = {
49272 + PTP_FILTER
49273 +};
49274 +
49275 #define cpts_read32(c, r) __raw_readl(&c->reg->r)
49276 #define cpts_write32(c, v, r) __raw_writel(v, &c->reg->r)
49277
49278 @@ -296,7 +300,7 @@ static u64 cpts_find_ts(struct cpts *cpts, struct sk_buff *skb, int ev_type)
49279 u64 ns = 0;
49280 struct cpts_event *event;
49281 struct list_head *this, *next;
49282 - unsigned int class = ptp_classify_raw(skb);
49283 + unsigned int class = sk_run_filter(skb, ptp_filter);
49284 unsigned long flags;
49285 u16 seqid;
49286 u8 mtype;
49287 @@ -367,6 +371,10 @@ int cpts_register(struct device *dev, struct cpts *cpts,
49288 int err, i;
49289 unsigned long flags;
49290
49291 + if (ptp_filter_init(ptp_filter, ARRAY_SIZE(ptp_filter))) {
49292 + pr_err("cpts: bad ptp filter\n");
49293 + return -EINVAL;
49294 + }
49295 cpts->info = cpts_info;
49296 cpts->clock = ptp_clock_register(&cpts->info, dev);
49297 if (IS_ERR(cpts->clock)) {
49298 diff --git a/drivers/net/ethernet/xscale/Kconfig b/drivers/net/ethernet/xscale/Kconfig
49299 index b81bc9f..3f43101 100644
49300 --- a/drivers/net/ethernet/xscale/Kconfig
49301 +++ b/drivers/net/ethernet/xscale/Kconfig
49302 @@ -23,7 +23,6 @@ config IXP4XX_ETH
49303 tristate "Intel IXP4xx Ethernet support"
49304 depends on ARM && ARCH_IXP4XX && IXP4XX_NPE && IXP4XX_QMGR
49305 select PHYLIB
49306 - select NET_PTP_CLASSIFY
49307 ---help---
49308 Say Y here if you want to use built-in Ethernet ports
49309 on IXP4xx processor.
49310 diff --git a/drivers/net/ethernet/xscale/ixp4xx_eth.c b/drivers/net/ethernet/xscale/ixp4xx_eth.c
49311 index f7e0f0f..25283f1 100644
49312 --- a/drivers/net/ethernet/xscale/ixp4xx_eth.c
49313 +++ b/drivers/net/ethernet/xscale/ixp4xx_eth.c
49314 @@ -256,6 +256,10 @@ static int ports_open;
49315 static struct port *npe_port_tab[MAX_NPES];
49316 static struct dma_pool *dma_pool;
49317
49318 +static struct sock_filter ptp_filter[] = {
49319 + PTP_FILTER
49320 +};
49321 +
49322 static int ixp_ptp_match(struct sk_buff *skb, u16 uid_hi, u32 uid_lo, u16 seqid)
49323 {
49324 u8 *data = skb->data;
49325 @@ -263,7 +267,7 @@ static int ixp_ptp_match(struct sk_buff *skb, u16 uid_hi, u32 uid_lo, u16 seqid)
49326 u16 *hi, *id;
49327 u32 lo;
49328
49329 - if (ptp_classify_raw(skb) != PTP_CLASS_V1_IPV4)
49330 + if (sk_run_filter(skb, ptp_filter) != PTP_CLASS_V1_IPV4)
49331 return 0;
49332
49333 offset = ETH_HLEN + IPV4_HLEN(data) + UDP_HLEN;
49334 @@ -1409,6 +1413,11 @@ static int eth_init_one(struct platform_device *pdev)
49335 char phy_id[MII_BUS_ID_SIZE + 3];
49336 int err;
49337
49338 + if (ptp_filter_init(ptp_filter, ARRAY_SIZE(ptp_filter))) {
49339 + pr_err("ixp4xx_eth: bad ptp filter\n");
49340 + return -EINVAL;
49341 + }
49342 +
49343 if (!(dev = alloc_etherdev(sizeof(struct port))))
49344 return -ENOMEM;
49345
49346 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
49347 index 6cc37c1..fdd9d77 100644
49348 --- a/drivers/net/hyperv/hyperv_net.h
49349 +++ b/drivers/net/hyperv/hyperv_net.h
49350 @@ -170,7 +170,7 @@ struct rndis_device {
49351
49352 enum rndis_device_state state;
49353 bool link_state;
49354 - atomic_t new_req_id;
49355 + atomic_unchecked_t new_req_id;
49356
49357 spinlock_t request_lock;
49358 struct list_head req_list;
49359 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
49360 index 99c527a..6a2ce38 100644
49361 --- a/drivers/net/hyperv/rndis_filter.c
49362 +++ b/drivers/net/hyperv/rndis_filter.c
49363 @@ -102,7 +102,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
49364 * template
49365 */
49366 set = &rndis_msg->msg.set_req;
49367 - set->req_id = atomic_inc_return(&dev->new_req_id);
49368 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
49369
49370 /* Add to the request list */
49371 spin_lock_irqsave(&dev->request_lock, flags);
49372 @@ -930,7 +930,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
49373
49374 /* Setup the rndis set */
49375 halt = &request->request_msg.msg.halt_req;
49376 - halt->req_id = atomic_inc_return(&dev->new_req_id);
49377 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
49378
49379 /* Ignore return since this msg is optional. */
49380 rndis_filter_send_request(dev, request);
49381 diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
49382 index 78f18be..1d19c62 100644
49383 --- a/drivers/net/ieee802154/fakehard.c
49384 +++ b/drivers/net/ieee802154/fakehard.c
49385 @@ -364,7 +364,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
49386 phy->transmit_power = 0xbf;
49387
49388 dev->netdev_ops = &fake_ops;
49389 - dev->ml_priv = &fake_mlme;
49390 + dev->ml_priv = (void *)&fake_mlme;
49391
49392 priv = netdev_priv(dev);
49393 priv->phy = phy;
49394 diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
49395 index ef8a5c2..76877d6 100644
49396 --- a/drivers/net/macvlan.c
49397 +++ b/drivers/net/macvlan.c
49398 @@ -264,7 +264,7 @@ static void macvlan_broadcast_enqueue(struct macvlan_port *port,
49399 free_nskb:
49400 kfree_skb(nskb);
49401 err:
49402 - atomic_long_inc(&skb->dev->rx_dropped);
49403 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
49404 }
49405
49406 /* called under rcu_read_lock() from netif_receive_skb */
49407 @@ -1134,13 +1134,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
49408 int macvlan_link_register(struct rtnl_link_ops *ops)
49409 {
49410 /* common fields */
49411 - ops->priv_size = sizeof(struct macvlan_dev);
49412 - ops->validate = macvlan_validate;
49413 - ops->maxtype = IFLA_MACVLAN_MAX;
49414 - ops->policy = macvlan_policy;
49415 - ops->changelink = macvlan_changelink;
49416 - ops->get_size = macvlan_get_size;
49417 - ops->fill_info = macvlan_fill_info;
49418 + pax_open_kernel();
49419 + *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
49420 + *(void **)&ops->validate = macvlan_validate;
49421 + *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
49422 + *(const void **)&ops->policy = macvlan_policy;
49423 + *(void **)&ops->changelink = macvlan_changelink;
49424 + *(void **)&ops->get_size = macvlan_get_size;
49425 + *(void **)&ops->fill_info = macvlan_fill_info;
49426 + pax_close_kernel();
49427
49428 return rtnl_link_register(ops);
49429 };
49430 @@ -1220,7 +1222,7 @@ static int macvlan_device_event(struct notifier_block *unused,
49431 return NOTIFY_DONE;
49432 }
49433
49434 -static struct notifier_block macvlan_notifier_block __read_mostly = {
49435 +static struct notifier_block macvlan_notifier_block = {
49436 .notifier_call = macvlan_device_event,
49437 };
49438
49439 diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
49440 index 3381c4f..dea5fd5 100644
49441 --- a/drivers/net/macvtap.c
49442 +++ b/drivers/net/macvtap.c
49443 @@ -1020,7 +1020,7 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd,
49444 }
49445
49446 ret = 0;
49447 - if (copy_to_user(&ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
49448 + if (copy_to_user(ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
49449 put_user(q->flags, &ifr->ifr_flags))
49450 ret = -EFAULT;
49451 macvtap_put_vlan(vlan);
49452 @@ -1190,7 +1190,7 @@ static int macvtap_device_event(struct notifier_block *unused,
49453 return NOTIFY_DONE;
49454 }
49455
49456 -static struct notifier_block macvtap_notifier_block __read_mostly = {
49457 +static struct notifier_block macvtap_notifier_block = {
49458 .notifier_call = macvtap_device_event,
49459 };
49460
49461 diff --git a/drivers/net/phy/dp83640.c b/drivers/net/phy/dp83640.c
49462 index 9408157..d53b924 100644
49463 --- a/drivers/net/phy/dp83640.c
49464 +++ b/drivers/net/phy/dp83640.c
49465 @@ -27,7 +27,6 @@
49466 #include <linux/module.h>
49467 #include <linux/net_tstamp.h>
49468 #include <linux/netdevice.h>
49469 -#include <linux/if_vlan.h>
49470 #include <linux/phy.h>
49471 #include <linux/ptp_classify.h>
49472 #include <linux/ptp_clock_kernel.h>
49473 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
49474 index d5b77ef..72ff14b 100644
49475 --- a/drivers/net/ppp/ppp_generic.c
49476 +++ b/drivers/net/ppp/ppp_generic.c
49477 @@ -143,8 +143,9 @@ struct ppp {
49478 struct sk_buff_head mrq; /* MP: receive reconstruction queue */
49479 #endif /* CONFIG_PPP_MULTILINK */
49480 #ifdef CONFIG_PPP_FILTER
49481 - struct sk_filter *pass_filter; /* filter for packets to pass */
49482 - struct sk_filter *active_filter;/* filter for pkts to reset idle */
49483 + struct sock_filter *pass_filter; /* filter for packets to pass */
49484 + struct sock_filter *active_filter;/* filter for pkts to reset idle */
49485 + unsigned pass_len, active_len;
49486 #endif /* CONFIG_PPP_FILTER */
49487 struct net *ppp_net; /* the net we belong to */
49488 struct ppp_link_stats stats64; /* 64 bit network stats */
49489 @@ -539,7 +540,7 @@ static int get_filter(void __user *arg, struct sock_filter **p)
49490 {
49491 struct sock_fprog uprog;
49492 struct sock_filter *code = NULL;
49493 - int len;
49494 + int len, err;
49495
49496 if (copy_from_user(&uprog, arg, sizeof(uprog)))
49497 return -EFAULT;
49498 @@ -554,6 +555,12 @@ static int get_filter(void __user *arg, struct sock_filter **p)
49499 if (IS_ERR(code))
49500 return PTR_ERR(code);
49501
49502 + err = sk_chk_filter(code, uprog.len);
49503 + if (err) {
49504 + kfree(code);
49505 + return err;
49506 + }
49507 +
49508 *p = code;
49509 return uprog.len;
49510 }
49511 @@ -748,52 +755,28 @@ static long ppp_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
49512 case PPPIOCSPASS:
49513 {
49514 struct sock_filter *code;
49515 -
49516 err = get_filter(argp, &code);
49517 if (err >= 0) {
49518 - struct sock_fprog_kern fprog = {
49519 - .len = err,
49520 - .filter = code,
49521 - };
49522 -
49523 ppp_lock(ppp);
49524 - if (ppp->pass_filter) {
49525 - sk_unattached_filter_destroy(ppp->pass_filter);
49526 - ppp->pass_filter = NULL;
49527 - }
49528 - if (fprog.filter != NULL)
49529 - err = sk_unattached_filter_create(&ppp->pass_filter,
49530 - &fprog);
49531 - else
49532 - err = 0;
49533 - kfree(code);
49534 + kfree(ppp->pass_filter);
49535 + ppp->pass_filter = code;
49536 + ppp->pass_len = err;
49537 ppp_unlock(ppp);
49538 + err = 0;
49539 }
49540 break;
49541 }
49542 case PPPIOCSACTIVE:
49543 {
49544 struct sock_filter *code;
49545 -
49546 err = get_filter(argp, &code);
49547 if (err >= 0) {
49548 - struct sock_fprog_kern fprog = {
49549 - .len = err,
49550 - .filter = code,
49551 - };
49552 -
49553 ppp_lock(ppp);
49554 - if (ppp->active_filter) {
49555 - sk_unattached_filter_destroy(ppp->active_filter);
49556 - ppp->active_filter = NULL;
49557 - }
49558 - if (fprog.filter != NULL)
49559 - err = sk_unattached_filter_create(&ppp->active_filter,
49560 - &fprog);
49561 - else
49562 - err = 0;
49563 - kfree(code);
49564 + kfree(ppp->active_filter);
49565 + ppp->active_filter = code;
49566 + ppp->active_len = err;
49567 ppp_unlock(ppp);
49568 + err = 0;
49569 }
49570 break;
49571 }
49572 @@ -1201,7 +1184,7 @@ ppp_send_frame(struct ppp *ppp, struct sk_buff *skb)
49573 a four-byte PPP header on each packet */
49574 *skb_push(skb, 2) = 1;
49575 if (ppp->pass_filter &&
49576 - SK_RUN_FILTER(ppp->pass_filter, skb) == 0) {
49577 + sk_run_filter(skb, ppp->pass_filter) == 0) {
49578 if (ppp->debug & 1)
49579 netdev_printk(KERN_DEBUG, ppp->dev,
49580 "PPP: outbound frame "
49581 @@ -1211,7 +1194,7 @@ ppp_send_frame(struct ppp *ppp, struct sk_buff *skb)
49582 }
49583 /* if this packet passes the active filter, record the time */
49584 if (!(ppp->active_filter &&
49585 - SK_RUN_FILTER(ppp->active_filter, skb) == 0))
49586 + sk_run_filter(skb, ppp->active_filter) == 0))
49587 ppp->last_xmit = jiffies;
49588 skb_pull(skb, 2);
49589 #else
49590 @@ -1835,7 +1818,7 @@ ppp_receive_nonmp_frame(struct ppp *ppp, struct sk_buff *skb)
49591
49592 *skb_push(skb, 2) = 0;
49593 if (ppp->pass_filter &&
49594 - SK_RUN_FILTER(ppp->pass_filter, skb) == 0) {
49595 + sk_run_filter(skb, ppp->pass_filter) == 0) {
49596 if (ppp->debug & 1)
49597 netdev_printk(KERN_DEBUG, ppp->dev,
49598 "PPP: inbound frame "
49599 @@ -1844,7 +1827,7 @@ ppp_receive_nonmp_frame(struct ppp *ppp, struct sk_buff *skb)
49600 return;
49601 }
49602 if (!(ppp->active_filter &&
49603 - SK_RUN_FILTER(ppp->active_filter, skb) == 0))
49604 + sk_run_filter(skb, ppp->active_filter) == 0))
49605 ppp->last_recv = jiffies;
49606 __skb_pull(skb, 2);
49607 } else
49608 @@ -2689,10 +2672,6 @@ ppp_create_interface(struct net *net, int unit, int *retp)
49609 ppp->minseq = -1;
49610 skb_queue_head_init(&ppp->mrq);
49611 #endif /* CONFIG_PPP_MULTILINK */
49612 -#ifdef CONFIG_PPP_FILTER
49613 - ppp->pass_filter = NULL;
49614 - ppp->active_filter = NULL;
49615 -#endif /* CONFIG_PPP_FILTER */
49616
49617 /*
49618 * drum roll: don't forget to set
49619 @@ -2823,15 +2802,10 @@ static void ppp_destroy_interface(struct ppp *ppp)
49620 skb_queue_purge(&ppp->mrq);
49621 #endif /* CONFIG_PPP_MULTILINK */
49622 #ifdef CONFIG_PPP_FILTER
49623 - if (ppp->pass_filter) {
49624 - sk_unattached_filter_destroy(ppp->pass_filter);
49625 - ppp->pass_filter = NULL;
49626 - }
49627 -
49628 - if (ppp->active_filter) {
49629 - sk_unattached_filter_destroy(ppp->active_filter);
49630 - ppp->active_filter = NULL;
49631 - }
49632 + kfree(ppp->pass_filter);
49633 + ppp->pass_filter = NULL;
49634 + kfree(ppp->active_filter);
49635 + ppp->active_filter = NULL;
49636 #endif /* CONFIG_PPP_FILTER */
49637
49638 kfree_skb(ppp->xmit_pending);
49639 diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
49640 index 1252d9c..80e660b 100644
49641 --- a/drivers/net/slip/slhc.c
49642 +++ b/drivers/net/slip/slhc.c
49643 @@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
49644 register struct tcphdr *thp;
49645 register struct iphdr *ip;
49646 register struct cstate *cs;
49647 - int len, hdrlen;
49648 + long len, hdrlen;
49649 unsigned char *cp = icp;
49650
49651 /* We've got a compressed packet; read the change byte */
49652 diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
49653 index b4958c7..277cb96 100644
49654 --- a/drivers/net/team/team.c
49655 +++ b/drivers/net/team/team.c
49656 @@ -2868,7 +2868,7 @@ static int team_device_event(struct notifier_block *unused,
49657 return NOTIFY_DONE;
49658 }
49659
49660 -static struct notifier_block team_notifier_block __read_mostly = {
49661 +static struct notifier_block team_notifier_block = {
49662 .notifier_call = team_device_event,
49663 };
49664
49665 diff --git a/drivers/net/team/team_mode_loadbalance.c b/drivers/net/team/team_mode_loadbalance.c
49666 index a58dfeb..dbde341 100644
49667 --- a/drivers/net/team/team_mode_loadbalance.c
49668 +++ b/drivers/net/team/team_mode_loadbalance.c
49669 @@ -49,7 +49,7 @@ struct lb_port_mapping {
49670 struct lb_priv_ex {
49671 struct team *team;
49672 struct lb_port_mapping tx_hash_to_port_mapping[LB_TX_HASHTABLE_SIZE];
49673 - struct sock_fprog_kern *orig_fprog;
49674 + struct sock_fprog *orig_fprog;
49675 struct {
49676 unsigned int refresh_interval; /* in tenths of second */
49677 struct delayed_work refresh_dw;
49678 @@ -241,15 +241,15 @@ static int lb_bpf_func_get(struct team *team, struct team_gsetter_ctx *ctx)
49679 return 0;
49680 }
49681
49682 -static int __fprog_create(struct sock_fprog_kern **pfprog, u32 data_len,
49683 +static int __fprog_create(struct sock_fprog **pfprog, u32 data_len,
49684 const void *data)
49685 {
49686 - struct sock_fprog_kern *fprog;
49687 + struct sock_fprog *fprog;
49688 struct sock_filter *filter = (struct sock_filter *) data;
49689
49690 if (data_len % sizeof(struct sock_filter))
49691 return -EINVAL;
49692 - fprog = kmalloc(sizeof(*fprog), GFP_KERNEL);
49693 + fprog = kmalloc(sizeof(struct sock_fprog), GFP_KERNEL);
49694 if (!fprog)
49695 return -ENOMEM;
49696 fprog->filter = kmemdup(filter, data_len, GFP_KERNEL);
49697 @@ -262,7 +262,7 @@ static int __fprog_create(struct sock_fprog_kern **pfprog, u32 data_len,
49698 return 0;
49699 }
49700
49701 -static void __fprog_destroy(struct sock_fprog_kern *fprog)
49702 +static void __fprog_destroy(struct sock_fprog *fprog)
49703 {
49704 kfree(fprog->filter);
49705 kfree(fprog);
49706 @@ -273,7 +273,7 @@ static int lb_bpf_func_set(struct team *team, struct team_gsetter_ctx *ctx)
49707 struct lb_priv *lb_priv = get_lb_priv(team);
49708 struct sk_filter *fp = NULL;
49709 struct sk_filter *orig_fp;
49710 - struct sock_fprog_kern *fprog = NULL;
49711 + struct sock_fprog *fprog = NULL;
49712 int err;
49713
49714 if (ctx->data.bin_val.len) {
49715 diff --git a/drivers/net/tun.c b/drivers/net/tun.c
49716 index 98bad1f..f197d7a 100644
49717 --- a/drivers/net/tun.c
49718 +++ b/drivers/net/tun.c
49719 @@ -1854,7 +1854,7 @@ unlock:
49720 }
49721
49722 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
49723 - unsigned long arg, int ifreq_len)
49724 + unsigned long arg, size_t ifreq_len)
49725 {
49726 struct tun_file *tfile = file->private_data;
49727 struct tun_struct *tun;
49728 @@ -1867,6 +1867,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
49729 unsigned int ifindex;
49730 int ret;
49731
49732 + if (ifreq_len > sizeof ifr)
49733 + return -EFAULT;
49734 +
49735 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
49736 if (copy_from_user(&ifr, argp, ifreq_len))
49737 return -EFAULT;
49738 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
49739 index a4272ed..cdd69ff 100644
49740 --- a/drivers/net/usb/hso.c
49741 +++ b/drivers/net/usb/hso.c
49742 @@ -71,7 +71,7 @@
49743 #include <asm/byteorder.h>
49744 #include <linux/serial_core.h>
49745 #include <linux/serial.h>
49746 -
49747 +#include <asm/local.h>
49748
49749 #define MOD_AUTHOR "Option Wireless"
49750 #define MOD_DESCRIPTION "USB High Speed Option driver"
49751 @@ -1177,7 +1177,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
49752 struct urb *urb;
49753
49754 urb = serial->rx_urb[0];
49755 - if (serial->port.count > 0) {
49756 + if (atomic_read(&serial->port.count) > 0) {
49757 count = put_rxbuf_data(urb, serial);
49758 if (count == -1)
49759 return;
49760 @@ -1215,7 +1215,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
49761 DUMP1(urb->transfer_buffer, urb->actual_length);
49762
49763 /* Anyone listening? */
49764 - if (serial->port.count == 0)
49765 + if (atomic_read(&serial->port.count) == 0)
49766 return;
49767
49768 if (serial->parent->port_spec & HSO_INFO_CRC_BUG)
49769 @@ -1277,8 +1277,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
49770 tty_port_tty_set(&serial->port, tty);
49771
49772 /* check for port already opened, if not set the termios */
49773 - serial->port.count++;
49774 - if (serial->port.count == 1) {
49775 + if (atomic_inc_return(&serial->port.count) == 1) {
49776 serial->rx_state = RX_IDLE;
49777 /* Force default termio settings */
49778 _hso_serial_set_termios(tty, NULL);
49779 @@ -1288,7 +1287,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
49780 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
49781 if (result) {
49782 hso_stop_serial_device(serial->parent);
49783 - serial->port.count--;
49784 + atomic_dec(&serial->port.count);
49785 kref_put(&serial->parent->ref, hso_serial_ref_free);
49786 }
49787 } else {
49788 @@ -1325,10 +1324,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
49789
49790 /* reset the rts and dtr */
49791 /* do the actual close */
49792 - serial->port.count--;
49793 + atomic_dec(&serial->port.count);
49794
49795 - if (serial->port.count <= 0) {
49796 - serial->port.count = 0;
49797 + if (atomic_read(&serial->port.count) <= 0) {
49798 + atomic_set(&serial->port.count, 0);
49799 tty_port_tty_set(&serial->port, NULL);
49800 if (!usb_gone)
49801 hso_stop_serial_device(serial->parent);
49802 @@ -1403,7 +1402,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
49803
49804 /* the actual setup */
49805 spin_lock_irqsave(&serial->serial_lock, flags);
49806 - if (serial->port.count)
49807 + if (atomic_read(&serial->port.count))
49808 _hso_serial_set_termios(tty, old);
49809 else
49810 tty->termios = *old;
49811 @@ -1872,7 +1871,7 @@ static void intr_callback(struct urb *urb)
49812 D1("Pending read interrupt on port %d\n", i);
49813 spin_lock(&serial->serial_lock);
49814 if (serial->rx_state == RX_IDLE &&
49815 - serial->port.count > 0) {
49816 + atomic_read(&serial->port.count) > 0) {
49817 /* Setup and send a ctrl req read on
49818 * port i */
49819 if (!serial->rx_urb_filled[0]) {
49820 @@ -3045,7 +3044,7 @@ static int hso_resume(struct usb_interface *iface)
49821 /* Start all serial ports */
49822 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
49823 if (serial_table[i] && (serial_table[i]->interface == iface)) {
49824 - if (dev2ser(serial_table[i])->port.count) {
49825 + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
49826 result =
49827 hso_start_serial_device(serial_table[i], GFP_NOIO);
49828 hso_kick_transmit(dev2ser(serial_table[i]));
49829 diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
49830 index 3eab74c..fb6097c 100644
49831 --- a/drivers/net/usb/r8152.c
49832 +++ b/drivers/net/usb/r8152.c
49833 @@ -567,7 +567,7 @@ struct r8152 {
49834 void (*up)(struct r8152 *);
49835 void (*down)(struct r8152 *);
49836 void (*unload)(struct r8152 *);
49837 - } rtl_ops;
49838 + } __no_const rtl_ops;
49839
49840 int intr_interval;
49841 u32 saved_wolopts;
49842 diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
49843 index a2515887..6d13233 100644
49844 --- a/drivers/net/usb/sierra_net.c
49845 +++ b/drivers/net/usb/sierra_net.c
49846 @@ -51,7 +51,7 @@ static const char driver_name[] = "sierra_net";
49847 /* atomic counter partially included in MAC address to make sure 2 devices
49848 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
49849 */
49850 -static atomic_t iface_counter = ATOMIC_INIT(0);
49851 +static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
49852
49853 /*
49854 * SYNC Timer Delay definition used to set the expiry time
49855 @@ -697,7 +697,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
49856 dev->net->netdev_ops = &sierra_net_device_ops;
49857
49858 /* change MAC addr to include, ifacenum, and to be unique */
49859 - dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
49860 + dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
49861 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
49862
49863 /* we will have to manufacture ethernet headers, prepare template */
49864 diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
49865 index 7d9f84a..7f690da 100644
49866 --- a/drivers/net/virtio_net.c
49867 +++ b/drivers/net/virtio_net.c
49868 @@ -47,7 +47,7 @@ module_param(gso, bool, 0444);
49869 #define RECEIVE_AVG_WEIGHT 64
49870
49871 /* Minimum alignment for mergeable packet buffers. */
49872 -#define MERGEABLE_BUFFER_ALIGN max(L1_CACHE_BYTES, 256)
49873 +#define MERGEABLE_BUFFER_ALIGN max(L1_CACHE_BYTES, 256UL)
49874
49875 #define VIRTNET_DRIVER_VERSION "1.0.0"
49876
49877 diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
49878 index 9f79192..838cf95 100644
49879 --- a/drivers/net/vxlan.c
49880 +++ b/drivers/net/vxlan.c
49881 @@ -2838,7 +2838,7 @@ nla_put_failure:
49882 return -EMSGSIZE;
49883 }
49884
49885 -static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
49886 +static struct rtnl_link_ops vxlan_link_ops = {
49887 .kind = "vxlan",
49888 .maxtype = IFLA_VXLAN_MAX,
49889 .policy = vxlan_policy,
49890 @@ -2885,7 +2885,7 @@ static int vxlan_lowerdev_event(struct notifier_block *unused,
49891 return NOTIFY_DONE;
49892 }
49893
49894 -static struct notifier_block vxlan_notifier_block __read_mostly = {
49895 +static struct notifier_block vxlan_notifier_block = {
49896 .notifier_call = vxlan_lowerdev_event,
49897 };
49898
49899 diff --git a/drivers/net/wan/lmc/lmc_media.c b/drivers/net/wan/lmc/lmc_media.c
49900 index 5920c99..ff2e4a5 100644
49901 --- a/drivers/net/wan/lmc/lmc_media.c
49902 +++ b/drivers/net/wan/lmc/lmc_media.c
49903 @@ -95,62 +95,63 @@ static inline void write_av9110_bit (lmc_softc_t *, int);
49904 static void write_av9110(lmc_softc_t *, u32, u32, u32, u32, u32);
49905
49906 lmc_media_t lmc_ds3_media = {
49907 - lmc_ds3_init, /* special media init stuff */
49908 - lmc_ds3_default, /* reset to default state */
49909 - lmc_ds3_set_status, /* reset status to state provided */
49910 - lmc_dummy_set_1, /* set clock source */
49911 - lmc_dummy_set2_1, /* set line speed */
49912 - lmc_ds3_set_100ft, /* set cable length */
49913 - lmc_ds3_set_scram, /* set scrambler */
49914 - lmc_ds3_get_link_status, /* get link status */
49915 - lmc_dummy_set_1, /* set link status */
49916 - lmc_ds3_set_crc_length, /* set CRC length */
49917 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
49918 - lmc_ds3_watchdog
49919 + .init = lmc_ds3_init, /* special media init stuff */
49920 + .defaults = lmc_ds3_default, /* reset to default state */
49921 + .set_status = lmc_ds3_set_status, /* reset status to state provided */
49922 + .set_clock_source = lmc_dummy_set_1, /* set clock source */
49923 + .set_speed = lmc_dummy_set2_1, /* set line speed */
49924 + .set_cable_length = lmc_ds3_set_100ft, /* set cable length */
49925 + .set_scrambler = lmc_ds3_set_scram, /* set scrambler */
49926 + .get_link_status = lmc_ds3_get_link_status, /* get link status */
49927 + .set_link_status = lmc_dummy_set_1, /* set link status */
49928 + .set_crc_length = lmc_ds3_set_crc_length, /* set CRC length */
49929 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
49930 + .watchdog = lmc_ds3_watchdog
49931 };
49932
49933 lmc_media_t lmc_hssi_media = {
49934 - lmc_hssi_init, /* special media init stuff */
49935 - lmc_hssi_default, /* reset to default state */
49936 - lmc_hssi_set_status, /* reset status to state provided */
49937 - lmc_hssi_set_clock, /* set clock source */
49938 - lmc_dummy_set2_1, /* set line speed */
49939 - lmc_dummy_set_1, /* set cable length */
49940 - lmc_dummy_set_1, /* set scrambler */
49941 - lmc_hssi_get_link_status, /* get link status */
49942 - lmc_hssi_set_link_status, /* set link status */
49943 - lmc_hssi_set_crc_length, /* set CRC length */
49944 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
49945 - lmc_hssi_watchdog
49946 + .init = lmc_hssi_init, /* special media init stuff */
49947 + .defaults = lmc_hssi_default, /* reset to default state */
49948 + .set_status = lmc_hssi_set_status, /* reset status to state provided */
49949 + .set_clock_source = lmc_hssi_set_clock, /* set clock source */
49950 + .set_speed = lmc_dummy_set2_1, /* set line speed */
49951 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
49952 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
49953 + .get_link_status = lmc_hssi_get_link_status, /* get link status */
49954 + .set_link_status = lmc_hssi_set_link_status, /* set link status */
49955 + .set_crc_length = lmc_hssi_set_crc_length, /* set CRC length */
49956 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
49957 + .watchdog = lmc_hssi_watchdog
49958 };
49959
49960 -lmc_media_t lmc_ssi_media = { lmc_ssi_init, /* special media init stuff */
49961 - lmc_ssi_default, /* reset to default state */
49962 - lmc_ssi_set_status, /* reset status to state provided */
49963 - lmc_ssi_set_clock, /* set clock source */
49964 - lmc_ssi_set_speed, /* set line speed */
49965 - lmc_dummy_set_1, /* set cable length */
49966 - lmc_dummy_set_1, /* set scrambler */
49967 - lmc_ssi_get_link_status, /* get link status */
49968 - lmc_ssi_set_link_status, /* set link status */
49969 - lmc_ssi_set_crc_length, /* set CRC length */
49970 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
49971 - lmc_ssi_watchdog
49972 +lmc_media_t lmc_ssi_media = {
49973 + .init = lmc_ssi_init, /* special media init stuff */
49974 + .defaults = lmc_ssi_default, /* reset to default state */
49975 + .set_status = lmc_ssi_set_status, /* reset status to state provided */
49976 + .set_clock_source = lmc_ssi_set_clock, /* set clock source */
49977 + .set_speed = lmc_ssi_set_speed, /* set line speed */
49978 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
49979 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
49980 + .get_link_status = lmc_ssi_get_link_status, /* get link status */
49981 + .set_link_status = lmc_ssi_set_link_status, /* set link status */
49982 + .set_crc_length = lmc_ssi_set_crc_length, /* set CRC length */
49983 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
49984 + .watchdog = lmc_ssi_watchdog
49985 };
49986
49987 lmc_media_t lmc_t1_media = {
49988 - lmc_t1_init, /* special media init stuff */
49989 - lmc_t1_default, /* reset to default state */
49990 - lmc_t1_set_status, /* reset status to state provided */
49991 - lmc_t1_set_clock, /* set clock source */
49992 - lmc_dummy_set2_1, /* set line speed */
49993 - lmc_dummy_set_1, /* set cable length */
49994 - lmc_dummy_set_1, /* set scrambler */
49995 - lmc_t1_get_link_status, /* get link status */
49996 - lmc_dummy_set_1, /* set link status */
49997 - lmc_t1_set_crc_length, /* set CRC length */
49998 - lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
49999 - lmc_t1_watchdog
50000 + .init = lmc_t1_init, /* special media init stuff */
50001 + .defaults = lmc_t1_default, /* reset to default state */
50002 + .set_status = lmc_t1_set_status, /* reset status to state provided */
50003 + .set_clock_source = lmc_t1_set_clock, /* set clock source */
50004 + .set_speed = lmc_dummy_set2_1, /* set line speed */
50005 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
50006 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
50007 + .get_link_status = lmc_t1_get_link_status, /* get link status */
50008 + .set_link_status = lmc_dummy_set_1, /* set link status */
50009 + .set_crc_length = lmc_t1_set_crc_length, /* set CRC length */
50010 + .set_circuit_type = lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
50011 + .watchdog = lmc_t1_watchdog
50012 };
50013
50014 static void
50015 diff --git a/drivers/net/wan/z85230.c b/drivers/net/wan/z85230.c
50016 index feacc3b..5bac0de 100644
50017 --- a/drivers/net/wan/z85230.c
50018 +++ b/drivers/net/wan/z85230.c
50019 @@ -485,9 +485,9 @@ static void z8530_status(struct z8530_channel *chan)
50020
50021 struct z8530_irqhandler z8530_sync =
50022 {
50023 - z8530_rx,
50024 - z8530_tx,
50025 - z8530_status
50026 + .rx = z8530_rx,
50027 + .tx = z8530_tx,
50028 + .status = z8530_status
50029 };
50030
50031 EXPORT_SYMBOL(z8530_sync);
50032 @@ -605,15 +605,15 @@ static void z8530_dma_status(struct z8530_channel *chan)
50033 }
50034
50035 static struct z8530_irqhandler z8530_dma_sync = {
50036 - z8530_dma_rx,
50037 - z8530_dma_tx,
50038 - z8530_dma_status
50039 + .rx = z8530_dma_rx,
50040 + .tx = z8530_dma_tx,
50041 + .status = z8530_dma_status
50042 };
50043
50044 static struct z8530_irqhandler z8530_txdma_sync = {
50045 - z8530_rx,
50046 - z8530_dma_tx,
50047 - z8530_dma_status
50048 + .rx = z8530_rx,
50049 + .tx = z8530_dma_tx,
50050 + .status = z8530_dma_status
50051 };
50052
50053 /**
50054 @@ -680,9 +680,9 @@ static void z8530_status_clear(struct z8530_channel *chan)
50055
50056 struct z8530_irqhandler z8530_nop=
50057 {
50058 - z8530_rx_clear,
50059 - z8530_tx_clear,
50060 - z8530_status_clear
50061 + .rx = z8530_rx_clear,
50062 + .tx = z8530_tx_clear,
50063 + .status = z8530_status_clear
50064 };
50065
50066
50067 diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
50068 index 0b60295..b8bfa5b 100644
50069 --- a/drivers/net/wimax/i2400m/rx.c
50070 +++ b/drivers/net/wimax/i2400m/rx.c
50071 @@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
50072 if (i2400m->rx_roq == NULL)
50073 goto error_roq_alloc;
50074
50075 - rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
50076 + rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
50077 GFP_KERNEL);
50078 if (rd == NULL) {
50079 result = -ENOMEM;
50080 diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
50081 index 64747d4..17c4cf3 100644
50082 --- a/drivers/net/wireless/airo.c
50083 +++ b/drivers/net/wireless/airo.c
50084 @@ -7846,7 +7846,7 @@ static int writerids(struct net_device *dev, aironet_ioctl *comp) {
50085 struct airo_info *ai = dev->ml_priv;
50086 int ridcode;
50087 int enabled;
50088 - static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
50089 + int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
50090 unsigned char *iobuf;
50091
50092 /* Only super-user can write RIDs */
50093 diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
50094 index d48776e..373d049 100644
50095 --- a/drivers/net/wireless/at76c50x-usb.c
50096 +++ b/drivers/net/wireless/at76c50x-usb.c
50097 @@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
50098 }
50099
50100 /* Convert timeout from the DFU status to jiffies */
50101 -static inline unsigned long at76_get_timeout(struct dfu_status *s)
50102 +static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
50103 {
50104 return msecs_to_jiffies((s->poll_timeout[2] << 16)
50105 | (s->poll_timeout[1] << 8)
50106 diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
50107 index e493db4..2c1853a 100644
50108 --- a/drivers/net/wireless/ath/ath10k/htc.c
50109 +++ b/drivers/net/wireless/ath/ath10k/htc.c
50110 @@ -840,7 +840,10 @@ void ath10k_htc_stop(struct ath10k_htc *htc)
50111 /* registered target arrival callback from the HIF layer */
50112 int ath10k_htc_init(struct ath10k *ar)
50113 {
50114 - struct ath10k_hif_cb htc_callbacks;
50115 + static struct ath10k_hif_cb htc_callbacks = {
50116 + .rx_completion = ath10k_htc_rx_completion_handler,
50117 + .tx_completion = ath10k_htc_tx_completion_handler,
50118 + };
50119 struct ath10k_htc_ep *ep = NULL;
50120 struct ath10k_htc *htc = &ar->htc;
50121
50122 @@ -850,8 +853,6 @@ int ath10k_htc_init(struct ath10k *ar)
50123 ath10k_htc_reset_endpoint_states(htc);
50124
50125 /* setup HIF layer callbacks */
50126 - htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
50127 - htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
50128 htc->ar = ar;
50129
50130 /* Get HIF default pipe for HTC message exchange */
50131 diff --git a/drivers/net/wireless/ath/ath10k/htc.h b/drivers/net/wireless/ath/ath10k/htc.h
50132 index 4716d33..a688310 100644
50133 --- a/drivers/net/wireless/ath/ath10k/htc.h
50134 +++ b/drivers/net/wireless/ath/ath10k/htc.h
50135 @@ -271,13 +271,13 @@ enum ath10k_htc_ep_id {
50136
50137 struct ath10k_htc_ops {
50138 void (*target_send_suspend_complete)(struct ath10k *ar);
50139 -};
50140 +} __no_const;
50141
50142 struct ath10k_htc_ep_ops {
50143 void (*ep_tx_complete)(struct ath10k *, struct sk_buff *);
50144 void (*ep_rx_complete)(struct ath10k *, struct sk_buff *);
50145 void (*ep_tx_credits)(struct ath10k *);
50146 -};
50147 +} __no_const;
50148
50149 /* service connection information */
50150 struct ath10k_htc_svc_conn_req {
50151 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
50152 index 741b38d..b7ae41b 100644
50153 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
50154 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
50155 @@ -220,8 +220,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
50156 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
50157 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
50158
50159 - ACCESS_ONCE(ads->ds_link) = i->link;
50160 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
50161 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
50162 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
50163
50164 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
50165 ctl6 = SM(i->keytype, AR_EncrType);
50166 @@ -235,26 +235,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
50167
50168 if ((i->is_first || i->is_last) &&
50169 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
50170 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
50171 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
50172 | set11nTries(i->rates, 1)
50173 | set11nTries(i->rates, 2)
50174 | set11nTries(i->rates, 3)
50175 | (i->dur_update ? AR_DurUpdateEna : 0)
50176 | SM(0, AR_BurstDur);
50177
50178 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
50179 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
50180 | set11nRate(i->rates, 1)
50181 | set11nRate(i->rates, 2)
50182 | set11nRate(i->rates, 3);
50183 } else {
50184 - ACCESS_ONCE(ads->ds_ctl2) = 0;
50185 - ACCESS_ONCE(ads->ds_ctl3) = 0;
50186 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
50187 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
50188 }
50189
50190 if (!i->is_first) {
50191 - ACCESS_ONCE(ads->ds_ctl0) = 0;
50192 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
50193 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
50194 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
50195 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
50196 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
50197 return;
50198 }
50199
50200 @@ -279,7 +279,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
50201 break;
50202 }
50203
50204 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
50205 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
50206 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
50207 | SM(i->txpower, AR_XmitPower)
50208 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
50209 @@ -289,19 +289,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
50210 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
50211 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
50212
50213 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
50214 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
50215 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
50216 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
50217
50218 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
50219 return;
50220
50221 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
50222 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
50223 | set11nPktDurRTSCTS(i->rates, 1);
50224
50225 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
50226 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
50227 | set11nPktDurRTSCTS(i->rates, 3);
50228
50229 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
50230 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
50231 | set11nRateFlags(i->rates, 1)
50232 | set11nRateFlags(i->rates, 2)
50233 | set11nRateFlags(i->rates, 3)
50234 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
50235 index 729ffbf..49f50e3 100644
50236 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
50237 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
50238 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
50239 (i->qcu << AR_TxQcuNum_S) | desc_len;
50240
50241 checksum += val;
50242 - ACCESS_ONCE(ads->info) = val;
50243 + ACCESS_ONCE_RW(ads->info) = val;
50244
50245 checksum += i->link;
50246 - ACCESS_ONCE(ads->link) = i->link;
50247 + ACCESS_ONCE_RW(ads->link) = i->link;
50248
50249 checksum += i->buf_addr[0];
50250 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
50251 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
50252 checksum += i->buf_addr[1];
50253 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
50254 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
50255 checksum += i->buf_addr[2];
50256 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
50257 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
50258 checksum += i->buf_addr[3];
50259 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
50260 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
50261
50262 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
50263 - ACCESS_ONCE(ads->ctl3) = val;
50264 + ACCESS_ONCE_RW(ads->ctl3) = val;
50265 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
50266 - ACCESS_ONCE(ads->ctl5) = val;
50267 + ACCESS_ONCE_RW(ads->ctl5) = val;
50268 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
50269 - ACCESS_ONCE(ads->ctl7) = val;
50270 + ACCESS_ONCE_RW(ads->ctl7) = val;
50271 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
50272 - ACCESS_ONCE(ads->ctl9) = val;
50273 + ACCESS_ONCE_RW(ads->ctl9) = val;
50274
50275 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
50276 - ACCESS_ONCE(ads->ctl10) = checksum;
50277 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
50278
50279 if (i->is_first || i->is_last) {
50280 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
50281 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
50282 | set11nTries(i->rates, 1)
50283 | set11nTries(i->rates, 2)
50284 | set11nTries(i->rates, 3)
50285 | (i->dur_update ? AR_DurUpdateEna : 0)
50286 | SM(0, AR_BurstDur);
50287
50288 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
50289 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
50290 | set11nRate(i->rates, 1)
50291 | set11nRate(i->rates, 2)
50292 | set11nRate(i->rates, 3);
50293 } else {
50294 - ACCESS_ONCE(ads->ctl13) = 0;
50295 - ACCESS_ONCE(ads->ctl14) = 0;
50296 + ACCESS_ONCE_RW(ads->ctl13) = 0;
50297 + ACCESS_ONCE_RW(ads->ctl14) = 0;
50298 }
50299
50300 ads->ctl20 = 0;
50301 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
50302
50303 ctl17 = SM(i->keytype, AR_EncrType);
50304 if (!i->is_first) {
50305 - ACCESS_ONCE(ads->ctl11) = 0;
50306 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
50307 - ACCESS_ONCE(ads->ctl15) = 0;
50308 - ACCESS_ONCE(ads->ctl16) = 0;
50309 - ACCESS_ONCE(ads->ctl17) = ctl17;
50310 - ACCESS_ONCE(ads->ctl18) = 0;
50311 - ACCESS_ONCE(ads->ctl19) = 0;
50312 + ACCESS_ONCE_RW(ads->ctl11) = 0;
50313 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
50314 + ACCESS_ONCE_RW(ads->ctl15) = 0;
50315 + ACCESS_ONCE_RW(ads->ctl16) = 0;
50316 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
50317 + ACCESS_ONCE_RW(ads->ctl18) = 0;
50318 + ACCESS_ONCE_RW(ads->ctl19) = 0;
50319 return;
50320 }
50321
50322 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
50323 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
50324 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
50325 | SM(i->txpower, AR_XmitPower)
50326 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
50327 @@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
50328 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
50329 ctl12 |= SM(val, AR_PAPRDChainMask);
50330
50331 - ACCESS_ONCE(ads->ctl12) = ctl12;
50332 - ACCESS_ONCE(ads->ctl17) = ctl17;
50333 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
50334 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
50335
50336 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
50337 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
50338 | set11nPktDurRTSCTS(i->rates, 1);
50339
50340 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
50341 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
50342 | set11nPktDurRTSCTS(i->rates, 3);
50343
50344 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
50345 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
50346 | set11nRateFlags(i->rates, 1)
50347 | set11nRateFlags(i->rates, 2)
50348 | set11nRateFlags(i->rates, 3)
50349 | SM(i->rtscts_rate, AR_RTSCTSRate);
50350
50351 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
50352 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
50353 }
50354
50355 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
50356 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
50357 index 0acd4b5..0591c91 100644
50358 --- a/drivers/net/wireless/ath/ath9k/hw.h
50359 +++ b/drivers/net/wireless/ath/ath9k/hw.h
50360 @@ -629,7 +629,7 @@ struct ath_hw_private_ops {
50361
50362 /* ANI */
50363 void (*ani_cache_ini_regs)(struct ath_hw *ah);
50364 -};
50365 +} __no_const;
50366
50367 /**
50368 * struct ath_spec_scan - parameters for Atheros spectral scan
50369 @@ -706,7 +706,7 @@ struct ath_hw_ops {
50370 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
50371 void (*set_bt_ant_diversity)(struct ath_hw *hw, bool enable);
50372 #endif
50373 -};
50374 +} __no_const;
50375
50376 struct ath_nf_limits {
50377 s16 max;
50378 diff --git a/drivers/net/wireless/b43/phy_lp.c b/drivers/net/wireless/b43/phy_lp.c
50379 index 92190da..f3a4c4c 100644
50380 --- a/drivers/net/wireless/b43/phy_lp.c
50381 +++ b/drivers/net/wireless/b43/phy_lp.c
50382 @@ -2514,7 +2514,7 @@ static int lpphy_b2063_tune(struct b43_wldev *dev,
50383 {
50384 struct ssb_bus *bus = dev->dev->sdev->bus;
50385
50386 - static const struct b206x_channel *chandata = NULL;
50387 + const struct b206x_channel *chandata = NULL;
50388 u32 crystal_freq = bus->chipco.pmu.crystalfreq * 1000;
50389 u32 freqref, vco_freq, val1, val2, val3, timeout, timeoutref, count;
50390 u16 old_comm15, scale;
50391 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
50392 index dc1d20c..f7a4f06 100644
50393 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
50394 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
50395 @@ -3633,7 +3633,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
50396 */
50397 if (il3945_mod_params.disable_hw_scan) {
50398 D_INFO("Disabling hw_scan\n");
50399 - il3945_mac_ops.hw_scan = NULL;
50400 + pax_open_kernel();
50401 + *(void **)&il3945_mac_ops.hw_scan = NULL;
50402 + pax_close_kernel();
50403 }
50404
50405 D_INFO("*** LOAD DRIVER ***\n");
50406 diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
50407 index 0ffb6ff..c0b7f0e 100644
50408 --- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
50409 +++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
50410 @@ -188,7 +188,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
50411 {
50412 struct iwl_priv *priv = file->private_data;
50413 char buf[64];
50414 - int buf_size;
50415 + size_t buf_size;
50416 u32 offset, len;
50417
50418 memset(buf, 0, sizeof(buf));
50419 @@ -458,7 +458,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
50420 struct iwl_priv *priv = file->private_data;
50421
50422 char buf[8];
50423 - int buf_size;
50424 + size_t buf_size;
50425 u32 reset_flag;
50426
50427 memset(buf, 0, sizeof(buf));
50428 @@ -539,7 +539,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
50429 {
50430 struct iwl_priv *priv = file->private_data;
50431 char buf[8];
50432 - int buf_size;
50433 + size_t buf_size;
50434 int ht40;
50435
50436 memset(buf, 0, sizeof(buf));
50437 @@ -591,7 +591,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
50438 {
50439 struct iwl_priv *priv = file->private_data;
50440 char buf[8];
50441 - int buf_size;
50442 + size_t buf_size;
50443 int value;
50444
50445 memset(buf, 0, sizeof(buf));
50446 @@ -683,10 +683,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
50447 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
50448 DEBUGFS_READ_FILE_OPS(current_sleep_command);
50449
50450 -static const char *fmt_value = " %-30s %10u\n";
50451 -static const char *fmt_hex = " %-30s 0x%02X\n";
50452 -static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
50453 -static const char *fmt_header =
50454 +static const char fmt_value[] = " %-30s %10u\n";
50455 +static const char fmt_hex[] = " %-30s 0x%02X\n";
50456 +static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
50457 +static const char fmt_header[] =
50458 "%-32s current cumulative delta max\n";
50459
50460 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
50461 @@ -1856,7 +1856,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
50462 {
50463 struct iwl_priv *priv = file->private_data;
50464 char buf[8];
50465 - int buf_size;
50466 + size_t buf_size;
50467 int clear;
50468
50469 memset(buf, 0, sizeof(buf));
50470 @@ -1901,7 +1901,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
50471 {
50472 struct iwl_priv *priv = file->private_data;
50473 char buf[8];
50474 - int buf_size;
50475 + size_t buf_size;
50476 int trace;
50477
50478 memset(buf, 0, sizeof(buf));
50479 @@ -1972,7 +1972,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
50480 {
50481 struct iwl_priv *priv = file->private_data;
50482 char buf[8];
50483 - int buf_size;
50484 + size_t buf_size;
50485 int missed;
50486
50487 memset(buf, 0, sizeof(buf));
50488 @@ -2013,7 +2013,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
50489
50490 struct iwl_priv *priv = file->private_data;
50491 char buf[8];
50492 - int buf_size;
50493 + size_t buf_size;
50494 int plcp;
50495
50496 memset(buf, 0, sizeof(buf));
50497 @@ -2073,7 +2073,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
50498
50499 struct iwl_priv *priv = file->private_data;
50500 char buf[8];
50501 - int buf_size;
50502 + size_t buf_size;
50503 int flush;
50504
50505 memset(buf, 0, sizeof(buf));
50506 @@ -2163,7 +2163,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
50507
50508 struct iwl_priv *priv = file->private_data;
50509 char buf[8];
50510 - int buf_size;
50511 + size_t buf_size;
50512 int rts;
50513
50514 if (!priv->cfg->ht_params)
50515 @@ -2204,7 +2204,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
50516 {
50517 struct iwl_priv *priv = file->private_data;
50518 char buf[8];
50519 - int buf_size;
50520 + size_t buf_size;
50521
50522 memset(buf, 0, sizeof(buf));
50523 buf_size = min(count, sizeof(buf) - 1);
50524 @@ -2238,7 +2238,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
50525 struct iwl_priv *priv = file->private_data;
50526 u32 event_log_flag;
50527 char buf[8];
50528 - int buf_size;
50529 + size_t buf_size;
50530
50531 /* check that the interface is up */
50532 if (!iwl_is_ready(priv))
50533 @@ -2292,7 +2292,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
50534 struct iwl_priv *priv = file->private_data;
50535 char buf[8];
50536 u32 calib_disabled;
50537 - int buf_size;
50538 + size_t buf_size;
50539
50540 memset(buf, 0, sizeof(buf));
50541 buf_size = min(count, sizeof(buf) - 1);
50542 diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
50543 index 788085b..0bc852a 100644
50544 --- a/drivers/net/wireless/iwlwifi/pcie/trans.c
50545 +++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
50546 @@ -1598,7 +1598,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
50547 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
50548
50549 char buf[8];
50550 - int buf_size;
50551 + size_t buf_size;
50552 u32 reset_flag;
50553
50554 memset(buf, 0, sizeof(buf));
50555 @@ -1619,7 +1619,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
50556 {
50557 struct iwl_trans *trans = file->private_data;
50558 char buf[8];
50559 - int buf_size;
50560 + size_t buf_size;
50561 int csr;
50562
50563 memset(buf, 0, sizeof(buf));
50564 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
50565 index a312c65..162b13a 100644
50566 --- a/drivers/net/wireless/mac80211_hwsim.c
50567 +++ b/drivers/net/wireless/mac80211_hwsim.c
50568 @@ -2573,20 +2573,20 @@ static int __init init_mac80211_hwsim(void)
50569 if (channels < 1)
50570 return -EINVAL;
50571
50572 - mac80211_hwsim_mchan_ops = mac80211_hwsim_ops;
50573 - mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
50574 - mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
50575 - mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
50576 - mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
50577 - mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
50578 - mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
50579 - mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
50580 - mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
50581 - mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
50582 - mac80211_hwsim_mchan_ops.assign_vif_chanctx =
50583 - mac80211_hwsim_assign_vif_chanctx;
50584 - mac80211_hwsim_mchan_ops.unassign_vif_chanctx =
50585 - mac80211_hwsim_unassign_vif_chanctx;
50586 + pax_open_kernel();
50587 + memcpy((void *)&mac80211_hwsim_mchan_ops, &mac80211_hwsim_ops, sizeof mac80211_hwsim_mchan_ops);
50588 + *(void **)&mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
50589 + *(void **)&mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
50590 + *(void **)&mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
50591 + *(void **)&mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
50592 + *(void **)&mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
50593 + *(void **)&mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
50594 + *(void **)&mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
50595 + *(void **)&mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
50596 + *(void **)&mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
50597 + *(void **)&mac80211_hwsim_mchan_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
50598 + *(void **)&mac80211_hwsim_mchan_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
50599 + pax_close_kernel();
50600
50601 spin_lock_init(&hwsim_radio_lock);
50602 INIT_LIST_HEAD(&hwsim_radios);
50603 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
50604 index d2a9a08..0cb175d 100644
50605 --- a/drivers/net/wireless/rndis_wlan.c
50606 +++ b/drivers/net/wireless/rndis_wlan.c
50607 @@ -1236,7 +1236,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
50608
50609 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
50610
50611 - if (rts_threshold < 0 || rts_threshold > 2347)
50612 + if (rts_threshold > 2347)
50613 rts_threshold = 2347;
50614
50615 tmp = cpu_to_le32(rts_threshold);
50616 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
50617 index d13f25c..2573994 100644
50618 --- a/drivers/net/wireless/rt2x00/rt2x00.h
50619 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
50620 @@ -375,7 +375,7 @@ struct rt2x00_intf {
50621 * for hardware which doesn't support hardware
50622 * sequence counting.
50623 */
50624 - atomic_t seqno;
50625 + atomic_unchecked_t seqno;
50626 };
50627
50628 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
50629 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
50630 index 5642ccc..01f03eb 100644
50631 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
50632 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
50633 @@ -250,9 +250,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
50634 * sequence counter given by mac80211.
50635 */
50636 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
50637 - seqno = atomic_add_return(0x10, &intf->seqno);
50638 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
50639 else
50640 - seqno = atomic_read(&intf->seqno);
50641 + seqno = atomic_read_unchecked(&intf->seqno);
50642
50643 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
50644 hdr->seq_ctrl |= cpu_to_le16(seqno);
50645 diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
50646 index b661f896..ddf7d2b 100644
50647 --- a/drivers/net/wireless/ti/wl1251/sdio.c
50648 +++ b/drivers/net/wireless/ti/wl1251/sdio.c
50649 @@ -282,13 +282,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
50650
50651 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
50652
50653 - wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
50654 - wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
50655 + pax_open_kernel();
50656 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
50657 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
50658 + pax_close_kernel();
50659
50660 wl1251_info("using dedicated interrupt line");
50661 } else {
50662 - wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
50663 - wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
50664 + pax_open_kernel();
50665 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
50666 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
50667 + pax_close_kernel();
50668
50669 wl1251_info("using SDIO interrupt");
50670 }
50671 diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
50672 index d50dfac..0a6f5be3 100644
50673 --- a/drivers/net/wireless/ti/wl12xx/main.c
50674 +++ b/drivers/net/wireless/ti/wl12xx/main.c
50675 @@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
50676 sizeof(wl->conf.mem));
50677
50678 /* read data preparation is only needed by wl127x */
50679 - wl->ops->prepare_read = wl127x_prepare_read;
50680 + pax_open_kernel();
50681 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
50682 + pax_close_kernel();
50683
50684 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
50685 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
50686 @@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
50687 sizeof(wl->conf.mem));
50688
50689 /* read data preparation is only needed by wl127x */
50690 - wl->ops->prepare_read = wl127x_prepare_read;
50691 + pax_open_kernel();
50692 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
50693 + pax_close_kernel();
50694
50695 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
50696 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
50697 diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
50698 index de5b4fa..7996ec6 100644
50699 --- a/drivers/net/wireless/ti/wl18xx/main.c
50700 +++ b/drivers/net/wireless/ti/wl18xx/main.c
50701 @@ -1900,8 +1900,10 @@ static int wl18xx_setup(struct wl1271 *wl)
50702 }
50703
50704 if (!checksum_param) {
50705 - wl18xx_ops.set_rx_csum = NULL;
50706 - wl18xx_ops.init_vif = NULL;
50707 + pax_open_kernel();
50708 + *(void **)&wl18xx_ops.set_rx_csum = NULL;
50709 + *(void **)&wl18xx_ops.init_vif = NULL;
50710 + pax_close_kernel();
50711 }
50712
50713 /* Enable 11a Band only if we have 5G antennas */
50714 diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
50715 index a912dc0..a8225ba 100644
50716 --- a/drivers/net/wireless/zd1211rw/zd_usb.c
50717 +++ b/drivers/net/wireless/zd1211rw/zd_usb.c
50718 @@ -385,7 +385,7 @@ static inline void handle_regs_int(struct urb *urb)
50719 {
50720 struct zd_usb *usb = urb->context;
50721 struct zd_usb_interrupt *intr = &usb->intr;
50722 - int len;
50723 + unsigned int len;
50724 u16 int_num;
50725
50726 ZD_ASSERT(in_interrupt());
50727 diff --git a/drivers/nfc/nfcwilink.c b/drivers/nfc/nfcwilink.c
50728 index 683671a..4519fc2 100644
50729 --- a/drivers/nfc/nfcwilink.c
50730 +++ b/drivers/nfc/nfcwilink.c
50731 @@ -497,7 +497,7 @@ static struct nci_ops nfcwilink_ops = {
50732
50733 static int nfcwilink_probe(struct platform_device *pdev)
50734 {
50735 - static struct nfcwilink *drv;
50736 + struct nfcwilink *drv;
50737 int rc;
50738 __u32 protocols;
50739
50740 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
50741 index d93b2b6..ae50401 100644
50742 --- a/drivers/oprofile/buffer_sync.c
50743 +++ b/drivers/oprofile/buffer_sync.c
50744 @@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
50745 if (cookie == NO_COOKIE)
50746 offset = pc;
50747 if (cookie == INVALID_COOKIE) {
50748 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
50749 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
50750 offset = pc;
50751 }
50752 if (cookie != last_cookie) {
50753 @@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
50754 /* add userspace sample */
50755
50756 if (!mm) {
50757 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
50758 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
50759 return 0;
50760 }
50761
50762 cookie = lookup_dcookie(mm, s->eip, &offset);
50763
50764 if (cookie == INVALID_COOKIE) {
50765 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
50766 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
50767 return 0;
50768 }
50769
50770 @@ -552,7 +552,7 @@ void sync_buffer(int cpu)
50771 /* ignore backtraces if failed to add a sample */
50772 if (state == sb_bt_start) {
50773 state = sb_bt_ignore;
50774 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
50775 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
50776 }
50777 }
50778 release_mm(mm);
50779 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
50780 index c0cc4e7..44d4e54 100644
50781 --- a/drivers/oprofile/event_buffer.c
50782 +++ b/drivers/oprofile/event_buffer.c
50783 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
50784 }
50785
50786 if (buffer_pos == buffer_size) {
50787 - atomic_inc(&oprofile_stats.event_lost_overflow);
50788 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
50789 return;
50790 }
50791
50792 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
50793 index ed2c3ec..deda85a 100644
50794 --- a/drivers/oprofile/oprof.c
50795 +++ b/drivers/oprofile/oprof.c
50796 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
50797 if (oprofile_ops.switch_events())
50798 return;
50799
50800 - atomic_inc(&oprofile_stats.multiplex_counter);
50801 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
50802 start_switch_worker();
50803 }
50804
50805 diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
50806 index ee2cfce..7f8f699 100644
50807 --- a/drivers/oprofile/oprofile_files.c
50808 +++ b/drivers/oprofile/oprofile_files.c
50809 @@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
50810
50811 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
50812
50813 -static ssize_t timeout_read(struct file *file, char __user *buf,
50814 +static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
50815 size_t count, loff_t *offset)
50816 {
50817 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
50818 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
50819 index 59659ce..6c860a0 100644
50820 --- a/drivers/oprofile/oprofile_stats.c
50821 +++ b/drivers/oprofile/oprofile_stats.c
50822 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
50823 cpu_buf->sample_invalid_eip = 0;
50824 }
50825
50826 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
50827 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
50828 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
50829 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
50830 - atomic_set(&oprofile_stats.multiplex_counter, 0);
50831 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
50832 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
50833 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
50834 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
50835 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
50836 }
50837
50838
50839 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
50840 index 1fc622b..8c48fc3 100644
50841 --- a/drivers/oprofile/oprofile_stats.h
50842 +++ b/drivers/oprofile/oprofile_stats.h
50843 @@ -13,11 +13,11 @@
50844 #include <linux/atomic.h>
50845
50846 struct oprofile_stat_struct {
50847 - atomic_t sample_lost_no_mm;
50848 - atomic_t sample_lost_no_mapping;
50849 - atomic_t bt_lost_no_mapping;
50850 - atomic_t event_lost_overflow;
50851 - atomic_t multiplex_counter;
50852 + atomic_unchecked_t sample_lost_no_mm;
50853 + atomic_unchecked_t sample_lost_no_mapping;
50854 + atomic_unchecked_t bt_lost_no_mapping;
50855 + atomic_unchecked_t event_lost_overflow;
50856 + atomic_unchecked_t multiplex_counter;
50857 };
50858
50859 extern struct oprofile_stat_struct oprofile_stats;
50860 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
50861 index 3f49345..c750d0b 100644
50862 --- a/drivers/oprofile/oprofilefs.c
50863 +++ b/drivers/oprofile/oprofilefs.c
50864 @@ -176,8 +176,8 @@ int oprofilefs_create_ro_ulong(struct dentry *root,
50865
50866 static ssize_t atomic_read_file(struct file *file, char __user *buf, size_t count, loff_t *offset)
50867 {
50868 - atomic_t *val = file->private_data;
50869 - return oprofilefs_ulong_to_user(atomic_read(val), buf, count, offset);
50870 + atomic_unchecked_t *val = file->private_data;
50871 + return oprofilefs_ulong_to_user(atomic_read_unchecked(val), buf, count, offset);
50872 }
50873
50874
50875 @@ -189,7 +189,7 @@ static const struct file_operations atomic_ro_fops = {
50876
50877
50878 int oprofilefs_create_ro_atomic(struct dentry *root,
50879 - char const *name, atomic_t *val)
50880 + char const *name, atomic_unchecked_t *val)
50881 {
50882 return __oprofilefs_create_file(root, name,
50883 &atomic_ro_fops, 0444, val);
50884 diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
50885 index 61be1d9..dec05d7 100644
50886 --- a/drivers/oprofile/timer_int.c
50887 +++ b/drivers/oprofile/timer_int.c
50888 @@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
50889 return NOTIFY_OK;
50890 }
50891
50892 -static struct notifier_block __refdata oprofile_cpu_notifier = {
50893 +static struct notifier_block oprofile_cpu_notifier = {
50894 .notifier_call = oprofile_cpu_notify,
50895 };
50896
50897 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
50898 index 3b47080..6cd05dd 100644
50899 --- a/drivers/parport/procfs.c
50900 +++ b/drivers/parport/procfs.c
50901 @@ -64,7 +64,7 @@ static int do_active_device(struct ctl_table *table, int write,
50902
50903 *ppos += len;
50904
50905 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
50906 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
50907 }
50908
50909 #ifdef CONFIG_PARPORT_1284
50910 @@ -106,7 +106,7 @@ static int do_autoprobe(struct ctl_table *table, int write,
50911
50912 *ppos += len;
50913
50914 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
50915 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
50916 }
50917 #endif /* IEEE1284.3 support. */
50918
50919 diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
50920 index 8dcccff..35d701d 100644
50921 --- a/drivers/pci/hotplug/acpiphp_ibm.c
50922 +++ b/drivers/pci/hotplug/acpiphp_ibm.c
50923 @@ -452,7 +452,9 @@ static int __init ibm_acpiphp_init(void)
50924 goto init_cleanup;
50925 }
50926
50927 - ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
50928 + pax_open_kernel();
50929 + *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
50930 + pax_close_kernel();
50931 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
50932
50933 return retval;
50934 diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
50935 index 04fcd78..39e83f1 100644
50936 --- a/drivers/pci/hotplug/cpcihp_generic.c
50937 +++ b/drivers/pci/hotplug/cpcihp_generic.c
50938 @@ -73,7 +73,6 @@ static u16 port;
50939 static unsigned int enum_bit;
50940 static u8 enum_mask;
50941
50942 -static struct cpci_hp_controller_ops generic_hpc_ops;
50943 static struct cpci_hp_controller generic_hpc;
50944
50945 static int __init validate_parameters(void)
50946 @@ -139,6 +138,10 @@ static int query_enum(void)
50947 return ((value & enum_mask) == enum_mask);
50948 }
50949
50950 +static struct cpci_hp_controller_ops generic_hpc_ops = {
50951 + .query_enum = query_enum,
50952 +};
50953 +
50954 static int __init cpcihp_generic_init(void)
50955 {
50956 int status;
50957 @@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
50958 pci_dev_put(dev);
50959
50960 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
50961 - generic_hpc_ops.query_enum = query_enum;
50962 generic_hpc.ops = &generic_hpc_ops;
50963
50964 status = cpci_hp_register_controller(&generic_hpc);
50965 diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
50966 index 6757b3e..d3bad62 100644
50967 --- a/drivers/pci/hotplug/cpcihp_zt5550.c
50968 +++ b/drivers/pci/hotplug/cpcihp_zt5550.c
50969 @@ -59,7 +59,6 @@
50970 /* local variables */
50971 static bool debug;
50972 static bool poll;
50973 -static struct cpci_hp_controller_ops zt5550_hpc_ops;
50974 static struct cpci_hp_controller zt5550_hpc;
50975
50976 /* Primary cPCI bus bridge device */
50977 @@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
50978 return 0;
50979 }
50980
50981 +static struct cpci_hp_controller_ops zt5550_hpc_ops = {
50982 + .query_enum = zt5550_hc_query_enum,
50983 +};
50984 +
50985 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
50986 {
50987 int status;
50988 @@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
50989 dbg("returned from zt5550_hc_config");
50990
50991 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
50992 - zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
50993 zt5550_hpc.ops = &zt5550_hpc_ops;
50994 if(!poll) {
50995 zt5550_hpc.irq = hc_dev->irq;
50996 zt5550_hpc.irq_flags = IRQF_SHARED;
50997 zt5550_hpc.dev_id = hc_dev;
50998
50999 - zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
51000 - zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
51001 - zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
51002 + pax_open_kernel();
51003 + *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
51004 + *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
51005 + *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
51006 + pax_open_kernel();
51007 } else {
51008 info("using ENUM# polling mode");
51009 }
51010 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
51011 index 0968a9b..5a00edf 100644
51012 --- a/drivers/pci/hotplug/cpqphp_nvram.c
51013 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
51014 @@ -427,9 +427,13 @@ static u32 store_HRT (void __iomem *rom_start)
51015
51016 void compaq_nvram_init (void __iomem *rom_start)
51017 {
51018 +
51019 +#ifndef CONFIG_PAX_KERNEXEC
51020 if (rom_start) {
51021 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
51022 }
51023 +#endif
51024 +
51025 dbg("int15 entry = %p\n", compaq_int15_entry_point);
51026
51027 /* initialize our int15 lock */
51028 diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
51029 index 56d8486..f26113f 100644
51030 --- a/drivers/pci/hotplug/pci_hotplug_core.c
51031 +++ b/drivers/pci/hotplug/pci_hotplug_core.c
51032 @@ -436,8 +436,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
51033 return -EINVAL;
51034 }
51035
51036 - slot->ops->owner = owner;
51037 - slot->ops->mod_name = mod_name;
51038 + pax_open_kernel();
51039 + *(struct module **)&slot->ops->owner = owner;
51040 + *(const char **)&slot->ops->mod_name = mod_name;
51041 + pax_close_kernel();
51042
51043 mutex_lock(&pci_hp_mutex);
51044 /*
51045 diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
51046 index a2297db..7c7d161 100644
51047 --- a/drivers/pci/hotplug/pciehp_core.c
51048 +++ b/drivers/pci/hotplug/pciehp_core.c
51049 @@ -92,7 +92,7 @@ static int init_slot(struct controller *ctrl)
51050 struct slot *slot = ctrl->slot;
51051 struct hotplug_slot *hotplug = NULL;
51052 struct hotplug_slot_info *info = NULL;
51053 - struct hotplug_slot_ops *ops = NULL;
51054 + hotplug_slot_ops_no_const *ops = NULL;
51055 char name[SLOT_NAME_SIZE];
51056 int retval = -ENOMEM;
51057
51058 diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
51059 index 13f3d30..363cb44 100644
51060 --- a/drivers/pci/msi.c
51061 +++ b/drivers/pci/msi.c
51062 @@ -523,8 +523,8 @@ static int populate_msi_sysfs(struct pci_dev *pdev)
51063 {
51064 struct attribute **msi_attrs;
51065 struct attribute *msi_attr;
51066 - struct device_attribute *msi_dev_attr;
51067 - struct attribute_group *msi_irq_group;
51068 + device_attribute_no_const *msi_dev_attr;
51069 + attribute_group_no_const *msi_irq_group;
51070 const struct attribute_group **msi_irq_groups;
51071 struct msi_desc *entry;
51072 int ret = -ENOMEM;
51073 @@ -584,7 +584,7 @@ error_attrs:
51074 count = 0;
51075 msi_attr = msi_attrs[count];
51076 while (msi_attr) {
51077 - msi_dev_attr = container_of(msi_attr, struct device_attribute, attr);
51078 + msi_dev_attr = container_of(msi_attr, device_attribute_no_const, attr);
51079 kfree(msi_attr->name);
51080 kfree(msi_dev_attr);
51081 ++count;
51082 diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
51083 index 9ff0a90..e819dda 100644
51084 --- a/drivers/pci/pci-sysfs.c
51085 +++ b/drivers/pci/pci-sysfs.c
51086 @@ -1134,7 +1134,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
51087 {
51088 /* allocate attribute structure, piggyback attribute name */
51089 int name_len = write_combine ? 13 : 10;
51090 - struct bin_attribute *res_attr;
51091 + bin_attribute_no_const *res_attr;
51092 int retval;
51093
51094 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
51095 @@ -1311,7 +1311,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
51096 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
51097 {
51098 int retval;
51099 - struct bin_attribute *attr;
51100 + bin_attribute_no_const *attr;
51101
51102 /* If the device has VPD, try to expose it in sysfs. */
51103 if (dev->vpd) {
51104 @@ -1358,7 +1358,7 @@ int __must_check pci_create_sysfs_dev_files(struct pci_dev *pdev)
51105 {
51106 int retval;
51107 int rom_size = 0;
51108 - struct bin_attribute *attr;
51109 + bin_attribute_no_const *attr;
51110
51111 if (!sysfs_initialized)
51112 return -EACCES;
51113 diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
51114 index 0601890..dc15007 100644
51115 --- a/drivers/pci/pci.h
51116 +++ b/drivers/pci/pci.h
51117 @@ -91,7 +91,7 @@ struct pci_vpd_ops {
51118 struct pci_vpd {
51119 unsigned int len;
51120 const struct pci_vpd_ops *ops;
51121 - struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
51122 + bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
51123 };
51124
51125 int pci_vpd_pci22_init(struct pci_dev *dev);
51126 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
51127 index e1e7026..d28dd33 100644
51128 --- a/drivers/pci/pcie/aspm.c
51129 +++ b/drivers/pci/pcie/aspm.c
51130 @@ -27,9 +27,9 @@
51131 #define MODULE_PARAM_PREFIX "pcie_aspm."
51132
51133 /* Note: those are not register definitions */
51134 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
51135 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
51136 -#define ASPM_STATE_L1 (4) /* L1 state */
51137 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
51138 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
51139 +#define ASPM_STATE_L1 (4U) /* L1 state */
51140 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
51141 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
51142
51143 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
51144 index e3cf8a2..be1baf0 100644
51145 --- a/drivers/pci/probe.c
51146 +++ b/drivers/pci/probe.c
51147 @@ -176,7 +176,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
51148 struct pci_bus_region region, inverted_region;
51149 bool bar_too_big = false, bar_too_high = false, bar_invalid = false;
51150
51151 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
51152 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
51153
51154 /* No printks while decoding is disabled! */
51155 if (!dev->mmio_always_on) {
51156 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
51157 index 3f155e7..0f4b1f0 100644
51158 --- a/drivers/pci/proc.c
51159 +++ b/drivers/pci/proc.c
51160 @@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
51161 static int __init pci_proc_init(void)
51162 {
51163 struct pci_dev *dev = NULL;
51164 +
51165 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
51166 +#ifdef CONFIG_GRKERNSEC_PROC_USER
51167 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
51168 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51169 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
51170 +#endif
51171 +#else
51172 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
51173 +#endif
51174 proc_create("devices", 0, proc_bus_pci_dir,
51175 &proc_bus_pci_dev_operations);
51176 proc_initialized = 1;
51177 diff --git a/drivers/platform/chrome/chromeos_laptop.c b/drivers/platform/chrome/chromeos_laptop.c
51178 index 7f1a2e2..bc4b405 100644
51179 --- a/drivers/platform/chrome/chromeos_laptop.c
51180 +++ b/drivers/platform/chrome/chromeos_laptop.c
51181 @@ -395,7 +395,7 @@ static struct chromeos_laptop cr48 = {
51182 .callback = chromeos_laptop_dmi_matched, \
51183 .driver_data = (void *)&board_
51184
51185 -static struct dmi_system_id chromeos_laptop_dmi_table[] __initdata = {
51186 +static struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = {
51187 {
51188 .ident = "Samsung Series 5 550",
51189 .matches = {
51190 diff --git a/drivers/platform/x86/alienware-wmi.c b/drivers/platform/x86/alienware-wmi.c
51191 index 297b664..ab91e39 100644
51192 --- a/drivers/platform/x86/alienware-wmi.c
51193 +++ b/drivers/platform/x86/alienware-wmi.c
51194 @@ -133,7 +133,7 @@ struct wmax_led_args {
51195 } __packed;
51196
51197 static struct platform_device *platform_device;
51198 -static struct device_attribute *zone_dev_attrs;
51199 +static device_attribute_no_const *zone_dev_attrs;
51200 static struct attribute **zone_attrs;
51201 static struct platform_zone *zone_data;
51202
51203 @@ -144,7 +144,7 @@ static struct platform_driver platform_driver = {
51204 }
51205 };
51206
51207 -static struct attribute_group zone_attribute_group = {
51208 +static attribute_group_no_const zone_attribute_group = {
51209 .name = "rgb_zones",
51210 };
51211
51212 diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
51213 index 3c6cced..12e0771 100644
51214 --- a/drivers/platform/x86/asus-wmi.c
51215 +++ b/drivers/platform/x86/asus-wmi.c
51216 @@ -1592,6 +1592,10 @@ static int show_dsts(struct seq_file *m, void *data)
51217 int err;
51218 u32 retval = -1;
51219
51220 +#ifdef CONFIG_GRKERNSEC_KMEM
51221 + return -EPERM;
51222 +#endif
51223 +
51224 err = asus_wmi_get_devstate(asus, asus->debug.dev_id, &retval);
51225
51226 if (err < 0)
51227 @@ -1608,6 +1612,10 @@ static int show_devs(struct seq_file *m, void *data)
51228 int err;
51229 u32 retval = -1;
51230
51231 +#ifdef CONFIG_GRKERNSEC_KMEM
51232 + return -EPERM;
51233 +#endif
51234 +
51235 err = asus_wmi_set_devstate(asus->debug.dev_id, asus->debug.ctrl_param,
51236 &retval);
51237
51238 @@ -1632,6 +1640,10 @@ static int show_call(struct seq_file *m, void *data)
51239 union acpi_object *obj;
51240 acpi_status status;
51241
51242 +#ifdef CONFIG_GRKERNSEC_KMEM
51243 + return -EPERM;
51244 +#endif
51245 +
51246 status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID,
51247 1, asus->debug.method_id,
51248 &input, &output);
51249 diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
51250 index 62f8030..c7f2a45 100644
51251 --- a/drivers/platform/x86/msi-laptop.c
51252 +++ b/drivers/platform/x86/msi-laptop.c
51253 @@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
51254
51255 if (!quirks->ec_read_only) {
51256 /* allow userland write sysfs file */
51257 - dev_attr_bluetooth.store = store_bluetooth;
51258 - dev_attr_wlan.store = store_wlan;
51259 - dev_attr_threeg.store = store_threeg;
51260 - dev_attr_bluetooth.attr.mode |= S_IWUSR;
51261 - dev_attr_wlan.attr.mode |= S_IWUSR;
51262 - dev_attr_threeg.attr.mode |= S_IWUSR;
51263 + pax_open_kernel();
51264 + *(void **)&dev_attr_bluetooth.store = store_bluetooth;
51265 + *(void **)&dev_attr_wlan.store = store_wlan;
51266 + *(void **)&dev_attr_threeg.store = store_threeg;
51267 + *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
51268 + *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
51269 + *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
51270 + pax_close_kernel();
51271 }
51272
51273 /* disable hardware control by fn key */
51274 diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c
51275 index 70222f2..8c8ce66 100644
51276 --- a/drivers/platform/x86/msi-wmi.c
51277 +++ b/drivers/platform/x86/msi-wmi.c
51278 @@ -183,7 +183,7 @@ static const struct backlight_ops msi_backlight_ops = {
51279 static void msi_wmi_notify(u32 value, void *context)
51280 {
51281 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
51282 - static struct key_entry *key;
51283 + struct key_entry *key;
51284 union acpi_object *obj;
51285 acpi_status status;
51286
51287 diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
51288 index 9c5a074..06c976a 100644
51289 --- a/drivers/platform/x86/sony-laptop.c
51290 +++ b/drivers/platform/x86/sony-laptop.c
51291 @@ -2527,7 +2527,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
51292 }
51293
51294 /* High speed charging function */
51295 -static struct device_attribute *hsc_handle;
51296 +static device_attribute_no_const *hsc_handle;
51297
51298 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
51299 struct device_attribute *attr,
51300 @@ -2601,7 +2601,7 @@ static void sony_nc_highspeed_charging_cleanup(struct platform_device *pd)
51301 }
51302
51303 /* low battery function */
51304 -static struct device_attribute *lowbatt_handle;
51305 +static device_attribute_no_const *lowbatt_handle;
51306
51307 static ssize_t sony_nc_lowbatt_store(struct device *dev,
51308 struct device_attribute *attr,
51309 @@ -2667,7 +2667,7 @@ static void sony_nc_lowbatt_cleanup(struct platform_device *pd)
51310 }
51311
51312 /* fan speed function */
51313 -static struct device_attribute *fan_handle, *hsf_handle;
51314 +static device_attribute_no_const *fan_handle, *hsf_handle;
51315
51316 static ssize_t sony_nc_hsfan_store(struct device *dev,
51317 struct device_attribute *attr,
51318 @@ -2774,7 +2774,7 @@ static void sony_nc_fanspeed_cleanup(struct platform_device *pd)
51319 }
51320
51321 /* USB charge function */
51322 -static struct device_attribute *uc_handle;
51323 +static device_attribute_no_const *uc_handle;
51324
51325 static ssize_t sony_nc_usb_charge_store(struct device *dev,
51326 struct device_attribute *attr,
51327 @@ -2848,7 +2848,7 @@ static void sony_nc_usb_charge_cleanup(struct platform_device *pd)
51328 }
51329
51330 /* Panel ID function */
51331 -static struct device_attribute *panel_handle;
51332 +static device_attribute_no_const *panel_handle;
51333
51334 static ssize_t sony_nc_panelid_show(struct device *dev,
51335 struct device_attribute *attr, char *buffer)
51336 @@ -2895,7 +2895,7 @@ static void sony_nc_panelid_cleanup(struct platform_device *pd)
51337 }
51338
51339 /* smart connect function */
51340 -static struct device_attribute *sc_handle;
51341 +static device_attribute_no_const *sc_handle;
51342
51343 static ssize_t sony_nc_smart_conn_store(struct device *dev,
51344 struct device_attribute *attr,
51345 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
51346 index d82f196..5458f34 100644
51347 --- a/drivers/platform/x86/thinkpad_acpi.c
51348 +++ b/drivers/platform/x86/thinkpad_acpi.c
51349 @@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
51350 return 0;
51351 }
51352
51353 -void static hotkey_mask_warn_incomplete_mask(void)
51354 +static void hotkey_mask_warn_incomplete_mask(void)
51355 {
51356 /* log only what the user can fix... */
51357 const u32 wantedmask = hotkey_driver_mask &
51358 @@ -2438,10 +2438,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
51359 && !tp_features.bright_unkfw)
51360 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
51361 }
51362 +}
51363
51364 #undef TPACPI_COMPARE_KEY
51365 #undef TPACPI_MAY_SEND_KEY
51366 -}
51367
51368 /*
51369 * Polling driver
51370 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
51371 index 438d4c7..ca8a2fb 100644
51372 --- a/drivers/pnp/pnpbios/bioscalls.c
51373 +++ b/drivers/pnp/pnpbios/bioscalls.c
51374 @@ -59,7 +59,7 @@ do { \
51375 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
51376 } while(0)
51377
51378 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
51379 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
51380 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
51381
51382 /*
51383 @@ -96,7 +96,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
51384
51385 cpu = get_cpu();
51386 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
51387 +
51388 + pax_open_kernel();
51389 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
51390 + pax_close_kernel();
51391
51392 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
51393 spin_lock_irqsave(&pnp_bios_lock, flags);
51394 @@ -134,7 +137,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
51395 :"memory");
51396 spin_unlock_irqrestore(&pnp_bios_lock, flags);
51397
51398 + pax_open_kernel();
51399 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
51400 + pax_close_kernel();
51401 +
51402 put_cpu();
51403
51404 /* If we get here and this is set then the PnP BIOS faulted on us. */
51405 @@ -468,7 +474,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
51406 return status;
51407 }
51408
51409 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
51410 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
51411 {
51412 int i;
51413
51414 @@ -476,6 +482,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
51415 pnp_bios_callpoint.offset = header->fields.pm16offset;
51416 pnp_bios_callpoint.segment = PNP_CS16;
51417
51418 + pax_open_kernel();
51419 +
51420 for_each_possible_cpu(i) {
51421 struct desc_struct *gdt = get_cpu_gdt_table(i);
51422 if (!gdt)
51423 @@ -487,4 +495,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
51424 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
51425 (unsigned long)__va(header->fields.pm16dseg));
51426 }
51427 +
51428 + pax_close_kernel();
51429 }
51430 diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
51431 index 0c52e2a..3421ab7 100644
51432 --- a/drivers/power/pda_power.c
51433 +++ b/drivers/power/pda_power.c
51434 @@ -37,7 +37,11 @@ static int polling;
51435
51436 #if IS_ENABLED(CONFIG_USB_PHY)
51437 static struct usb_phy *transceiver;
51438 -static struct notifier_block otg_nb;
51439 +static int otg_handle_notification(struct notifier_block *nb,
51440 + unsigned long event, void *unused);
51441 +static struct notifier_block otg_nb = {
51442 + .notifier_call = otg_handle_notification
51443 +};
51444 #endif
51445
51446 static struct regulator *ac_draw;
51447 @@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
51448
51449 #if IS_ENABLED(CONFIG_USB_PHY)
51450 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
51451 - otg_nb.notifier_call = otg_handle_notification;
51452 ret = usb_register_notifier(transceiver, &otg_nb);
51453 if (ret) {
51454 dev_err(dev, "failure to register otg notifier\n");
51455 diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
51456 index cc439fd..8fa30df 100644
51457 --- a/drivers/power/power_supply.h
51458 +++ b/drivers/power/power_supply.h
51459 @@ -16,12 +16,12 @@ struct power_supply;
51460
51461 #ifdef CONFIG_SYSFS
51462
51463 -extern void power_supply_init_attrs(struct device_type *dev_type);
51464 +extern void power_supply_init_attrs(void);
51465 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
51466
51467 #else
51468
51469 -static inline void power_supply_init_attrs(struct device_type *dev_type) {}
51470 +static inline void power_supply_init_attrs(void) {}
51471 #define power_supply_uevent NULL
51472
51473 #endif /* CONFIG_SYSFS */
51474 diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
51475 index 5a5a24e..f7a3754 100644
51476 --- a/drivers/power/power_supply_core.c
51477 +++ b/drivers/power/power_supply_core.c
51478 @@ -28,7 +28,10 @@ EXPORT_SYMBOL_GPL(power_supply_class);
51479 ATOMIC_NOTIFIER_HEAD(power_supply_notifier);
51480 EXPORT_SYMBOL_GPL(power_supply_notifier);
51481
51482 -static struct device_type power_supply_dev_type;
51483 +extern const struct attribute_group *power_supply_attr_groups[];
51484 +static struct device_type power_supply_dev_type = {
51485 + .groups = power_supply_attr_groups,
51486 +};
51487
51488 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
51489 struct power_supply *supply)
51490 @@ -639,7 +642,7 @@ static int __init power_supply_class_init(void)
51491 return PTR_ERR(power_supply_class);
51492
51493 power_supply_class->dev_uevent = power_supply_uevent;
51494 - power_supply_init_attrs(&power_supply_dev_type);
51495 + power_supply_init_attrs();
51496
51497 return 0;
51498 }
51499 diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
51500 index 44420d1..967126e 100644
51501 --- a/drivers/power/power_supply_sysfs.c
51502 +++ b/drivers/power/power_supply_sysfs.c
51503 @@ -230,17 +230,15 @@ static struct attribute_group power_supply_attr_group = {
51504 .is_visible = power_supply_attr_is_visible,
51505 };
51506
51507 -static const struct attribute_group *power_supply_attr_groups[] = {
51508 +const struct attribute_group *power_supply_attr_groups[] = {
51509 &power_supply_attr_group,
51510 NULL,
51511 };
51512
51513 -void power_supply_init_attrs(struct device_type *dev_type)
51514 +void power_supply_init_attrs(void)
51515 {
51516 int i;
51517
51518 - dev_type->groups = power_supply_attr_groups;
51519 -
51520 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
51521 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
51522 }
51523 diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c
51524 index 84419af..268ede8 100644
51525 --- a/drivers/powercap/powercap_sys.c
51526 +++ b/drivers/powercap/powercap_sys.c
51527 @@ -154,8 +154,77 @@ struct powercap_constraint_attr {
51528 struct device_attribute name_attr;
51529 };
51530
51531 +static ssize_t show_constraint_name(struct device *dev,
51532 + struct device_attribute *dev_attr,
51533 + char *buf);
51534 +
51535 static struct powercap_constraint_attr
51536 - constraint_attrs[MAX_CONSTRAINTS_PER_ZONE];
51537 + constraint_attrs[MAX_CONSTRAINTS_PER_ZONE] = {
51538 + [0 ... MAX_CONSTRAINTS_PER_ZONE - 1] = {
51539 + .power_limit_attr = {
51540 + .attr = {
51541 + .name = NULL,
51542 + .mode = S_IWUSR | S_IRUGO
51543 + },
51544 + .show = show_constraint_power_limit_uw,
51545 + .store = store_constraint_power_limit_uw
51546 + },
51547 +
51548 + .time_window_attr = {
51549 + .attr = {
51550 + .name = NULL,
51551 + .mode = S_IWUSR | S_IRUGO
51552 + },
51553 + .show = show_constraint_time_window_us,
51554 + .store = store_constraint_time_window_us
51555 + },
51556 +
51557 + .max_power_attr = {
51558 + .attr = {
51559 + .name = NULL,
51560 + .mode = S_IRUGO
51561 + },
51562 + .show = show_constraint_max_power_uw,
51563 + .store = NULL
51564 + },
51565 +
51566 + .min_power_attr = {
51567 + .attr = {
51568 + .name = NULL,
51569 + .mode = S_IRUGO
51570 + },
51571 + .show = show_constraint_min_power_uw,
51572 + .store = NULL
51573 + },
51574 +
51575 + .max_time_window_attr = {
51576 + .attr = {
51577 + .name = NULL,
51578 + .mode = S_IRUGO
51579 + },
51580 + .show = show_constraint_max_time_window_us,
51581 + .store = NULL
51582 + },
51583 +
51584 + .min_time_window_attr = {
51585 + .attr = {
51586 + .name = NULL,
51587 + .mode = S_IRUGO
51588 + },
51589 + .show = show_constraint_min_time_window_us,
51590 + .store = NULL
51591 + },
51592 +
51593 + .name_attr = {
51594 + .attr = {
51595 + .name = NULL,
51596 + .mode = S_IRUGO
51597 + },
51598 + .show = show_constraint_name,
51599 + .store = NULL
51600 + }
51601 + }
51602 +};
51603
51604 /* A list of powercap control_types */
51605 static LIST_HEAD(powercap_cntrl_list);
51606 @@ -193,23 +262,16 @@ static ssize_t show_constraint_name(struct device *dev,
51607 }
51608
51609 static int create_constraint_attribute(int id, const char *name,
51610 - int mode,
51611 - struct device_attribute *dev_attr,
51612 - ssize_t (*show)(struct device *,
51613 - struct device_attribute *, char *),
51614 - ssize_t (*store)(struct device *,
51615 - struct device_attribute *,
51616 - const char *, size_t)
51617 - )
51618 + struct device_attribute *dev_attr)
51619 {
51620 + name = kasprintf(GFP_KERNEL, "constraint_%d_%s", id, name);
51621
51622 - dev_attr->attr.name = kasprintf(GFP_KERNEL, "constraint_%d_%s",
51623 - id, name);
51624 - if (!dev_attr->attr.name)
51625 + if (!name)
51626 return -ENOMEM;
51627 - dev_attr->attr.mode = mode;
51628 - dev_attr->show = show;
51629 - dev_attr->store = store;
51630 +
51631 + pax_open_kernel();
51632 + *(const char **)&dev_attr->attr.name = name;
51633 + pax_close_kernel();
51634
51635 return 0;
51636 }
51637 @@ -236,49 +298,31 @@ static int seed_constraint_attributes(void)
51638
51639 for (i = 0; i < MAX_CONSTRAINTS_PER_ZONE; ++i) {
51640 ret = create_constraint_attribute(i, "power_limit_uw",
51641 - S_IWUSR | S_IRUGO,
51642 - &constraint_attrs[i].power_limit_attr,
51643 - show_constraint_power_limit_uw,
51644 - store_constraint_power_limit_uw);
51645 + &constraint_attrs[i].power_limit_attr);
51646 if (ret)
51647 goto err_alloc;
51648 ret = create_constraint_attribute(i, "time_window_us",
51649 - S_IWUSR | S_IRUGO,
51650 - &constraint_attrs[i].time_window_attr,
51651 - show_constraint_time_window_us,
51652 - store_constraint_time_window_us);
51653 + &constraint_attrs[i].time_window_attr);
51654 if (ret)
51655 goto err_alloc;
51656 - ret = create_constraint_attribute(i, "name", S_IRUGO,
51657 - &constraint_attrs[i].name_attr,
51658 - show_constraint_name,
51659 - NULL);
51660 + ret = create_constraint_attribute(i, "name",
51661 + &constraint_attrs[i].name_attr);
51662 if (ret)
51663 goto err_alloc;
51664 - ret = create_constraint_attribute(i, "max_power_uw", S_IRUGO,
51665 - &constraint_attrs[i].max_power_attr,
51666 - show_constraint_max_power_uw,
51667 - NULL);
51668 + ret = create_constraint_attribute(i, "max_power_uw",
51669 + &constraint_attrs[i].max_power_attr);
51670 if (ret)
51671 goto err_alloc;
51672 - ret = create_constraint_attribute(i, "min_power_uw", S_IRUGO,
51673 - &constraint_attrs[i].min_power_attr,
51674 - show_constraint_min_power_uw,
51675 - NULL);
51676 + ret = create_constraint_attribute(i, "min_power_uw",
51677 + &constraint_attrs[i].min_power_attr);
51678 if (ret)
51679 goto err_alloc;
51680 ret = create_constraint_attribute(i, "max_time_window_us",
51681 - S_IRUGO,
51682 - &constraint_attrs[i].max_time_window_attr,
51683 - show_constraint_max_time_window_us,
51684 - NULL);
51685 + &constraint_attrs[i].max_time_window_attr);
51686 if (ret)
51687 goto err_alloc;
51688 ret = create_constraint_attribute(i, "min_time_window_us",
51689 - S_IRUGO,
51690 - &constraint_attrs[i].min_time_window_attr,
51691 - show_constraint_min_time_window_us,
51692 - NULL);
51693 + &constraint_attrs[i].min_time_window_attr);
51694 if (ret)
51695 goto err_alloc;
51696
51697 @@ -378,10 +422,12 @@ static void create_power_zone_common_attributes(
51698 power_zone->zone_dev_attrs[count++] =
51699 &dev_attr_max_energy_range_uj.attr;
51700 if (power_zone->ops->get_energy_uj) {
51701 + pax_open_kernel();
51702 if (power_zone->ops->reset_energy_uj)
51703 - dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
51704 + *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
51705 else
51706 - dev_attr_energy_uj.attr.mode = S_IRUGO;
51707 + *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IRUGO;
51708 + pax_close_kernel();
51709 power_zone->zone_dev_attrs[count++] =
51710 &dev_attr_energy_uj.attr;
51711 }
51712 diff --git a/drivers/ptp/Kconfig b/drivers/ptp/Kconfig
51713 index ee3de34..bec7285 100644
51714 --- a/drivers/ptp/Kconfig
51715 +++ b/drivers/ptp/Kconfig
51716 @@ -8,7 +8,6 @@ config PTP_1588_CLOCK
51717 tristate "PTP clock support"
51718 depends on NET
51719 select PPS
51720 - select NET_PTP_CLASSIFY
51721 help
51722 The IEEE 1588 standard defines a method to precisely
51723 synchronize distributed clocks over Ethernet networks. The
51724 diff --git a/drivers/ptp/ptp_private.h b/drivers/ptp/ptp_private.h
51725 index 9c5d414..c7900ce 100644
51726 --- a/drivers/ptp/ptp_private.h
51727 +++ b/drivers/ptp/ptp_private.h
51728 @@ -51,7 +51,7 @@ struct ptp_clock {
51729 struct mutex pincfg_mux; /* protect concurrent info->pin_config access */
51730 wait_queue_head_t tsev_wq;
51731 int defunct; /* tells readers to go away when clock is being removed */
51732 - struct device_attribute *pin_dev_attr;
51733 + device_attribute_no_const *pin_dev_attr;
51734 struct attribute **pin_attr;
51735 struct attribute_group pin_attr_group;
51736 };
51737 diff --git a/drivers/ptp/ptp_sysfs.c b/drivers/ptp/ptp_sysfs.c
51738 index 302e626..12579af 100644
51739 --- a/drivers/ptp/ptp_sysfs.c
51740 +++ b/drivers/ptp/ptp_sysfs.c
51741 @@ -280,7 +280,7 @@ static int ptp_populate_pins(struct ptp_clock *ptp)
51742 goto no_pin_attr;
51743
51744 for (i = 0; i < n_pins; i++) {
51745 - struct device_attribute *da = &ptp->pin_dev_attr[i];
51746 + device_attribute_no_const *da = &ptp->pin_dev_attr[i];
51747 sysfs_attr_init(&da->attr);
51748 da->attr.name = info->pin_config[i].name;
51749 da->attr.mode = 0644;
51750 diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
51751 index 4c1f999..11078c9 100644
51752 --- a/drivers/regulator/core.c
51753 +++ b/drivers/regulator/core.c
51754 @@ -3391,7 +3391,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
51755 {
51756 const struct regulation_constraints *constraints = NULL;
51757 const struct regulator_init_data *init_data;
51758 - static atomic_t regulator_no = ATOMIC_INIT(0);
51759 + static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
51760 struct regulator_dev *rdev;
51761 struct device *dev;
51762 int ret, i;
51763 @@ -3461,7 +3461,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
51764 rdev->dev.of_node = of_node_get(config->of_node);
51765 rdev->dev.parent = dev;
51766 dev_set_name(&rdev->dev, "regulator.%d",
51767 - atomic_inc_return(&regulator_no) - 1);
51768 + atomic_inc_return_unchecked(&regulator_no) - 1);
51769 ret = device_register(&rdev->dev);
51770 if (ret != 0) {
51771 put_device(&rdev->dev);
51772 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
51773 index 2fc4111..6aa88ca 100644
51774 --- a/drivers/regulator/max8660.c
51775 +++ b/drivers/regulator/max8660.c
51776 @@ -424,8 +424,10 @@ static int max8660_probe(struct i2c_client *client,
51777 max8660->shadow_regs[MAX8660_OVER1] = 5;
51778 } else {
51779 /* Otherwise devices can be toggled via software */
51780 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
51781 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
51782 + pax_open_kernel();
51783 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
51784 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
51785 + pax_close_kernel();
51786 }
51787
51788 /*
51789 diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
51790 index dbedf17..18ff6b7 100644
51791 --- a/drivers/regulator/max8973-regulator.c
51792 +++ b/drivers/regulator/max8973-regulator.c
51793 @@ -403,9 +403,11 @@ static int max8973_probe(struct i2c_client *client,
51794 if (!pdata || !pdata->enable_ext_control) {
51795 max->desc.enable_reg = MAX8973_VOUT;
51796 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
51797 - max->ops.enable = regulator_enable_regmap;
51798 - max->ops.disable = regulator_disable_regmap;
51799 - max->ops.is_enabled = regulator_is_enabled_regmap;
51800 + pax_open_kernel();
51801 + *(void **)&max->ops.enable = regulator_enable_regmap;
51802 + *(void **)&max->ops.disable = regulator_disable_regmap;
51803 + *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
51804 + pax_close_kernel();
51805 }
51806
51807 if (pdata) {
51808 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
51809 index f374fa5..26f0683 100644
51810 --- a/drivers/regulator/mc13892-regulator.c
51811 +++ b/drivers/regulator/mc13892-regulator.c
51812 @@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
51813 }
51814 mc13xxx_unlock(mc13892);
51815
51816 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
51817 + pax_open_kernel();
51818 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
51819 = mc13892_vcam_set_mode;
51820 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
51821 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
51822 = mc13892_vcam_get_mode;
51823 + pax_close_kernel();
51824
51825 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
51826 ARRAY_SIZE(mc13892_regulators));
51827 diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
51828 index b0e4a3e..e5dc11e 100644
51829 --- a/drivers/rtc/rtc-cmos.c
51830 +++ b/drivers/rtc/rtc-cmos.c
51831 @@ -789,7 +789,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
51832 hpet_rtc_timer_init();
51833
51834 /* export at least the first block of NVRAM */
51835 - nvram.size = address_space - NVRAM_OFFSET;
51836 + pax_open_kernel();
51837 + *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
51838 + pax_close_kernel();
51839 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
51840 if (retval < 0) {
51841 dev_dbg(dev, "can't create nvram file? %d\n", retval);
51842 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
51843 index d049393..bb20be0 100644
51844 --- a/drivers/rtc/rtc-dev.c
51845 +++ b/drivers/rtc/rtc-dev.c
51846 @@ -16,6 +16,7 @@
51847 #include <linux/module.h>
51848 #include <linux/rtc.h>
51849 #include <linux/sched.h>
51850 +#include <linux/grsecurity.h>
51851 #include "rtc-core.h"
51852
51853 static dev_t rtc_devt;
51854 @@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
51855 if (copy_from_user(&tm, uarg, sizeof(tm)))
51856 return -EFAULT;
51857
51858 + gr_log_timechange();
51859 +
51860 return rtc_set_time(rtc, &tm);
51861
51862 case RTC_PIE_ON:
51863 diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
51864 index f03d5ba..8325bf6 100644
51865 --- a/drivers/rtc/rtc-ds1307.c
51866 +++ b/drivers/rtc/rtc-ds1307.c
51867 @@ -107,7 +107,7 @@ struct ds1307 {
51868 u8 offset; /* register's offset */
51869 u8 regs[11];
51870 u16 nvram_offset;
51871 - struct bin_attribute *nvram;
51872 + bin_attribute_no_const *nvram;
51873 enum ds_type type;
51874 unsigned long flags;
51875 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
51876 diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
51877 index 11880c1..b823aa4 100644
51878 --- a/drivers/rtc/rtc-m48t59.c
51879 +++ b/drivers/rtc/rtc-m48t59.c
51880 @@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
51881 if (IS_ERR(m48t59->rtc))
51882 return PTR_ERR(m48t59->rtc);
51883
51884 - m48t59_nvram_attr.size = pdata->offset;
51885 + pax_open_kernel();
51886 + *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
51887 + pax_close_kernel();
51888
51889 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
51890 if (ret)
51891 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
51892 index e693af6..2e525b6 100644
51893 --- a/drivers/scsi/bfa/bfa_fcpim.h
51894 +++ b/drivers/scsi/bfa/bfa_fcpim.h
51895 @@ -36,7 +36,7 @@ struct bfa_iotag_s {
51896
51897 struct bfa_itn_s {
51898 bfa_isr_func_t isr;
51899 -};
51900 +} __no_const;
51901
51902 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
51903 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
51904 diff --git a/drivers/scsi/bfa/bfa_fcs.c b/drivers/scsi/bfa/bfa_fcs.c
51905 index a3ab5cc..8143622 100644
51906 --- a/drivers/scsi/bfa/bfa_fcs.c
51907 +++ b/drivers/scsi/bfa/bfa_fcs.c
51908 @@ -38,10 +38,21 @@ struct bfa_fcs_mod_s {
51909 #define BFA_FCS_MODULE(_mod) { _mod ## _modinit, _mod ## _modexit }
51910
51911 static struct bfa_fcs_mod_s fcs_modules[] = {
51912 - { bfa_fcs_port_attach, NULL, NULL },
51913 - { bfa_fcs_uf_attach, NULL, NULL },
51914 - { bfa_fcs_fabric_attach, bfa_fcs_fabric_modinit,
51915 - bfa_fcs_fabric_modexit },
51916 + {
51917 + .attach = bfa_fcs_port_attach,
51918 + .modinit = NULL,
51919 + .modexit = NULL
51920 + },
51921 + {
51922 + .attach = bfa_fcs_uf_attach,
51923 + .modinit = NULL,
51924 + .modexit = NULL
51925 + },
51926 + {
51927 + .attach = bfa_fcs_fabric_attach,
51928 + .modinit = bfa_fcs_fabric_modinit,
51929 + .modexit = bfa_fcs_fabric_modexit
51930 + },
51931 };
51932
51933 /*
51934 diff --git a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
51935 index ff75ef8..2dfe00a 100644
51936 --- a/drivers/scsi/bfa/bfa_fcs_lport.c
51937 +++ b/drivers/scsi/bfa/bfa_fcs_lport.c
51938 @@ -89,15 +89,26 @@ static struct {
51939 void (*offline) (struct bfa_fcs_lport_s *port);
51940 } __port_action[] = {
51941 {
51942 - bfa_fcs_lport_unknown_init, bfa_fcs_lport_unknown_online,
51943 - bfa_fcs_lport_unknown_offline}, {
51944 - bfa_fcs_lport_fab_init, bfa_fcs_lport_fab_online,
51945 - bfa_fcs_lport_fab_offline}, {
51946 - bfa_fcs_lport_n2n_init, bfa_fcs_lport_n2n_online,
51947 - bfa_fcs_lport_n2n_offline}, {
51948 - bfa_fcs_lport_loop_init, bfa_fcs_lport_loop_online,
51949 - bfa_fcs_lport_loop_offline},
51950 - };
51951 + .init = bfa_fcs_lport_unknown_init,
51952 + .online = bfa_fcs_lport_unknown_online,
51953 + .offline = bfa_fcs_lport_unknown_offline
51954 + },
51955 + {
51956 + .init = bfa_fcs_lport_fab_init,
51957 + .online = bfa_fcs_lport_fab_online,
51958 + .offline = bfa_fcs_lport_fab_offline
51959 + },
51960 + {
51961 + .init = bfa_fcs_lport_n2n_init,
51962 + .online = bfa_fcs_lport_n2n_online,
51963 + .offline = bfa_fcs_lport_n2n_offline
51964 + },
51965 + {
51966 + .init = bfa_fcs_lport_loop_init,
51967 + .online = bfa_fcs_lport_loop_online,
51968 + .offline = bfa_fcs_lport_loop_offline
51969 + },
51970 +};
51971
51972 /*
51973 * fcs_port_sm FCS logical port state machine
51974 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
51975 index 2e28392..9d865b6 100644
51976 --- a/drivers/scsi/bfa/bfa_ioc.h
51977 +++ b/drivers/scsi/bfa/bfa_ioc.h
51978 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
51979 bfa_ioc_disable_cbfn_t disable_cbfn;
51980 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
51981 bfa_ioc_reset_cbfn_t reset_cbfn;
51982 -};
51983 +} __no_const;
51984
51985 /*
51986 * IOC event notification mechanism.
51987 @@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
51988 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
51989 enum bfi_ioc_state fwstate);
51990 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
51991 -};
51992 +} __no_const;
51993
51994 /*
51995 * Queue element to wait for room in request queue. FIFO order is
51996 diff --git a/drivers/scsi/bfa/bfa_modules.h b/drivers/scsi/bfa/bfa_modules.h
51997 index a14c784..6de6790 100644
51998 --- a/drivers/scsi/bfa/bfa_modules.h
51999 +++ b/drivers/scsi/bfa/bfa_modules.h
52000 @@ -78,12 +78,12 @@ enum {
52001 \
52002 extern struct bfa_module_s hal_mod_ ## __mod; \
52003 struct bfa_module_s hal_mod_ ## __mod = { \
52004 - bfa_ ## __mod ## _meminfo, \
52005 - bfa_ ## __mod ## _attach, \
52006 - bfa_ ## __mod ## _detach, \
52007 - bfa_ ## __mod ## _start, \
52008 - bfa_ ## __mod ## _stop, \
52009 - bfa_ ## __mod ## _iocdisable, \
52010 + .meminfo = bfa_ ## __mod ## _meminfo, \
52011 + .attach = bfa_ ## __mod ## _attach, \
52012 + .detach = bfa_ ## __mod ## _detach, \
52013 + .start = bfa_ ## __mod ## _start, \
52014 + .stop = bfa_ ## __mod ## _stop, \
52015 + .iocdisable = bfa_ ## __mod ## _iocdisable, \
52016 }
52017
52018 #define BFA_CACHELINE_SZ (256)
52019 diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
52020 index 045c4e1..13de803 100644
52021 --- a/drivers/scsi/fcoe/fcoe_sysfs.c
52022 +++ b/drivers/scsi/fcoe/fcoe_sysfs.c
52023 @@ -33,8 +33,8 @@
52024 */
52025 #include "libfcoe.h"
52026
52027 -static atomic_t ctlr_num;
52028 -static atomic_t fcf_num;
52029 +static atomic_unchecked_t ctlr_num;
52030 +static atomic_unchecked_t fcf_num;
52031
52032 /*
52033 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
52034 @@ -685,7 +685,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
52035 if (!ctlr)
52036 goto out;
52037
52038 - ctlr->id = atomic_inc_return(&ctlr_num) - 1;
52039 + ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
52040 ctlr->f = f;
52041 ctlr->mode = FIP_CONN_TYPE_FABRIC;
52042 INIT_LIST_HEAD(&ctlr->fcfs);
52043 @@ -902,7 +902,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
52044 fcf->dev.parent = &ctlr->dev;
52045 fcf->dev.bus = &fcoe_bus_type;
52046 fcf->dev.type = &fcoe_fcf_device_type;
52047 - fcf->id = atomic_inc_return(&fcf_num) - 1;
52048 + fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
52049 fcf->state = FCOE_FCF_STATE_UNKNOWN;
52050
52051 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
52052 @@ -938,8 +938,8 @@ int __init fcoe_sysfs_setup(void)
52053 {
52054 int error;
52055
52056 - atomic_set(&ctlr_num, 0);
52057 - atomic_set(&fcf_num, 0);
52058 + atomic_set_unchecked(&ctlr_num, 0);
52059 + atomic_set_unchecked(&fcf_num, 0);
52060
52061 error = bus_register(&fcoe_bus_type);
52062 if (error)
52063 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
52064 index 3cbb57a..95e47a3 100644
52065 --- a/drivers/scsi/hosts.c
52066 +++ b/drivers/scsi/hosts.c
52067 @@ -42,7 +42,7 @@
52068 #include "scsi_logging.h"
52069
52070
52071 -static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
52072 +static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
52073
52074
52075 static void scsi_host_cls_release(struct device *dev)
52076 @@ -369,7 +369,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
52077 * subtract one because we increment first then return, but we need to
52078 * know what the next host number was before increment
52079 */
52080 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
52081 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
52082 shost->dma_channel = 0xff;
52083
52084 /* These three are default values which can be overridden */
52085 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
52086 index 31184b3..cc44bbf 100644
52087 --- a/drivers/scsi/hpsa.c
52088 +++ b/drivers/scsi/hpsa.c
52089 @@ -701,10 +701,10 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
52090 unsigned long flags;
52091
52092 if (h->transMethod & CFGTBL_Trans_io_accel1)
52093 - return h->access.command_completed(h, q);
52094 + return h->access->command_completed(h, q);
52095
52096 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
52097 - return h->access.command_completed(h, q);
52098 + return h->access->command_completed(h, q);
52099
52100 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
52101 a = rq->head[rq->current_entry];
52102 @@ -5455,7 +5455,7 @@ static void start_io(struct ctlr_info *h, unsigned long *flags)
52103 while (!list_empty(&h->reqQ)) {
52104 c = list_entry(h->reqQ.next, struct CommandList, list);
52105 /* can't do anything if fifo is full */
52106 - if ((h->access.fifo_full(h))) {
52107 + if ((h->access->fifo_full(h))) {
52108 h->fifo_recently_full = 1;
52109 dev_warn(&h->pdev->dev, "fifo full\n");
52110 break;
52111 @@ -5477,7 +5477,7 @@ static void start_io(struct ctlr_info *h, unsigned long *flags)
52112
52113 /* Tell the controller execute command */
52114 spin_unlock_irqrestore(&h->lock, *flags);
52115 - h->access.submit_command(h, c);
52116 + h->access->submit_command(h, c);
52117 spin_lock_irqsave(&h->lock, *flags);
52118 }
52119 }
52120 @@ -5493,17 +5493,17 @@ static void lock_and_start_io(struct ctlr_info *h)
52121
52122 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
52123 {
52124 - return h->access.command_completed(h, q);
52125 + return h->access->command_completed(h, q);
52126 }
52127
52128 static inline bool interrupt_pending(struct ctlr_info *h)
52129 {
52130 - return h->access.intr_pending(h);
52131 + return h->access->intr_pending(h);
52132 }
52133
52134 static inline long interrupt_not_for_us(struct ctlr_info *h)
52135 {
52136 - return (h->access.intr_pending(h) == 0) ||
52137 + return (h->access->intr_pending(h) == 0) ||
52138 (h->interrupts_enabled == 0);
52139 }
52140
52141 @@ -6459,7 +6459,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
52142 if (prod_index < 0)
52143 return -ENODEV;
52144 h->product_name = products[prod_index].product_name;
52145 - h->access = *(products[prod_index].access);
52146 + h->access = products[prod_index].access;
52147
52148 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
52149 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
52150 @@ -6781,7 +6781,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
52151 unsigned long flags;
52152 u32 lockup_detected;
52153
52154 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
52155 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
52156 spin_lock_irqsave(&h->lock, flags);
52157 lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
52158 if (!lockup_detected) {
52159 @@ -7022,7 +7022,7 @@ reinit_after_soft_reset:
52160 }
52161
52162 /* make sure the board interrupts are off */
52163 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
52164 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
52165
52166 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
52167 goto clean2;
52168 @@ -7057,7 +7057,7 @@ reinit_after_soft_reset:
52169 * fake ones to scoop up any residual completions.
52170 */
52171 spin_lock_irqsave(&h->lock, flags);
52172 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
52173 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
52174 spin_unlock_irqrestore(&h->lock, flags);
52175 free_irqs(h);
52176 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
52177 @@ -7076,9 +7076,9 @@ reinit_after_soft_reset:
52178 dev_info(&h->pdev->dev, "Board READY.\n");
52179 dev_info(&h->pdev->dev,
52180 "Waiting for stale completions to drain.\n");
52181 - h->access.set_intr_mask(h, HPSA_INTR_ON);
52182 + h->access->set_intr_mask(h, HPSA_INTR_ON);
52183 msleep(10000);
52184 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
52185 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
52186
52187 rc = controller_reset_failed(h->cfgtable);
52188 if (rc)
52189 @@ -7104,7 +7104,7 @@ reinit_after_soft_reset:
52190 h->drv_req_rescan = 0;
52191
52192 /* Turn the interrupts on so we can service requests */
52193 - h->access.set_intr_mask(h, HPSA_INTR_ON);
52194 + h->access->set_intr_mask(h, HPSA_INTR_ON);
52195
52196 hpsa_hba_inquiry(h);
52197 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
52198 @@ -7169,7 +7169,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
52199 * To write all data in the battery backed cache to disks
52200 */
52201 hpsa_flush_cache(h);
52202 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
52203 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
52204 hpsa_free_irqs_and_disable_msix(h);
52205 }
52206
52207 @@ -7287,7 +7287,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
52208 CFGTBL_Trans_enable_directed_msix |
52209 (trans_support & (CFGTBL_Trans_io_accel1 |
52210 CFGTBL_Trans_io_accel2));
52211 - struct access_method access = SA5_performant_access;
52212 + struct access_method *access = &SA5_performant_access;
52213
52214 /* This is a bit complicated. There are 8 registers on
52215 * the controller which we write to to tell it 8 different
52216 @@ -7329,7 +7329,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
52217 * perform the superfluous readl() after each command submission.
52218 */
52219 if (trans_support & (CFGTBL_Trans_io_accel1 | CFGTBL_Trans_io_accel2))
52220 - access = SA5_performant_access_no_read;
52221 + access = &SA5_performant_access_no_read;
52222
52223 /* Controller spec: zero out this buffer. */
52224 for (i = 0; i < h->nreply_queues; i++)
52225 @@ -7359,12 +7359,12 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
52226 * enable outbound interrupt coalescing in accelerator mode;
52227 */
52228 if (trans_support & CFGTBL_Trans_io_accel1) {
52229 - access = SA5_ioaccel_mode1_access;
52230 + access = &SA5_ioaccel_mode1_access;
52231 writel(10, &h->cfgtable->HostWrite.CoalIntDelay);
52232 writel(4, &h->cfgtable->HostWrite.CoalIntCount);
52233 } else {
52234 if (trans_support & CFGTBL_Trans_io_accel2) {
52235 - access = SA5_ioaccel_mode2_access;
52236 + access = &SA5_ioaccel_mode2_access;
52237 writel(10, &h->cfgtable->HostWrite.CoalIntDelay);
52238 writel(4, &h->cfgtable->HostWrite.CoalIntCount);
52239 }
52240 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
52241 index 24472ce..8782caf 100644
52242 --- a/drivers/scsi/hpsa.h
52243 +++ b/drivers/scsi/hpsa.h
52244 @@ -127,7 +127,7 @@ struct ctlr_info {
52245 unsigned int msix_vector;
52246 unsigned int msi_vector;
52247 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
52248 - struct access_method access;
52249 + struct access_method *access;
52250 char hba_mode_enabled;
52251
52252 /* queue and queue Info */
52253 @@ -536,43 +536,43 @@ static unsigned long SA5_ioaccel_mode1_completed(struct ctlr_info *h, u8 q)
52254 }
52255
52256 static struct access_method SA5_access = {
52257 - SA5_submit_command,
52258 - SA5_intr_mask,
52259 - SA5_fifo_full,
52260 - SA5_intr_pending,
52261 - SA5_completed,
52262 + .submit_command = SA5_submit_command,
52263 + .set_intr_mask = SA5_intr_mask,
52264 + .fifo_full = SA5_fifo_full,
52265 + .intr_pending = SA5_intr_pending,
52266 + .command_completed = SA5_completed,
52267 };
52268
52269 static struct access_method SA5_ioaccel_mode1_access = {
52270 - SA5_submit_command,
52271 - SA5_performant_intr_mask,
52272 - SA5_fifo_full,
52273 - SA5_ioaccel_mode1_intr_pending,
52274 - SA5_ioaccel_mode1_completed,
52275 + .submit_command = SA5_submit_command,
52276 + .set_intr_mask = SA5_performant_intr_mask,
52277 + .fifo_full = SA5_fifo_full,
52278 + .intr_pending = SA5_ioaccel_mode1_intr_pending,
52279 + .command_completed = SA5_ioaccel_mode1_completed,
52280 };
52281
52282 static struct access_method SA5_ioaccel_mode2_access = {
52283 - SA5_submit_command_ioaccel2,
52284 - SA5_performant_intr_mask,
52285 - SA5_fifo_full,
52286 - SA5_performant_intr_pending,
52287 - SA5_performant_completed,
52288 + .submit_command = SA5_submit_command_ioaccel2,
52289 + .set_intr_mask = SA5_performant_intr_mask,
52290 + .fifo_full = SA5_fifo_full,
52291 + .intr_pending = SA5_performant_intr_pending,
52292 + .command_completed = SA5_performant_completed,
52293 };
52294
52295 static struct access_method SA5_performant_access = {
52296 - SA5_submit_command,
52297 - SA5_performant_intr_mask,
52298 - SA5_fifo_full,
52299 - SA5_performant_intr_pending,
52300 - SA5_performant_completed,
52301 + .submit_command = SA5_submit_command,
52302 + .set_intr_mask = SA5_performant_intr_mask,
52303 + .fifo_full = SA5_fifo_full,
52304 + .intr_pending = SA5_performant_intr_pending,
52305 + .command_completed = SA5_performant_completed,
52306 };
52307
52308 static struct access_method SA5_performant_access_no_read = {
52309 - SA5_submit_command_no_read,
52310 - SA5_performant_intr_mask,
52311 - SA5_fifo_full,
52312 - SA5_performant_intr_pending,
52313 - SA5_performant_completed,
52314 + .submit_command = SA5_submit_command_no_read,
52315 + .set_intr_mask = SA5_performant_intr_mask,
52316 + .fifo_full = SA5_fifo_full,
52317 + .intr_pending = SA5_performant_intr_pending,
52318 + .command_completed = SA5_performant_completed,
52319 };
52320
52321 struct board_type {
52322 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
52323 index 1b3a094..068e683 100644
52324 --- a/drivers/scsi/libfc/fc_exch.c
52325 +++ b/drivers/scsi/libfc/fc_exch.c
52326 @@ -101,12 +101,12 @@ struct fc_exch_mgr {
52327 u16 pool_max_index;
52328
52329 struct {
52330 - atomic_t no_free_exch;
52331 - atomic_t no_free_exch_xid;
52332 - atomic_t xid_not_found;
52333 - atomic_t xid_busy;
52334 - atomic_t seq_not_found;
52335 - atomic_t non_bls_resp;
52336 + atomic_unchecked_t no_free_exch;
52337 + atomic_unchecked_t no_free_exch_xid;
52338 + atomic_unchecked_t xid_not_found;
52339 + atomic_unchecked_t xid_busy;
52340 + atomic_unchecked_t seq_not_found;
52341 + atomic_unchecked_t non_bls_resp;
52342 } stats;
52343 };
52344
52345 @@ -811,7 +811,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
52346 /* allocate memory for exchange */
52347 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
52348 if (!ep) {
52349 - atomic_inc(&mp->stats.no_free_exch);
52350 + atomic_inc_unchecked(&mp->stats.no_free_exch);
52351 goto out;
52352 }
52353 memset(ep, 0, sizeof(*ep));
52354 @@ -874,7 +874,7 @@ out:
52355 return ep;
52356 err:
52357 spin_unlock_bh(&pool->lock);
52358 - atomic_inc(&mp->stats.no_free_exch_xid);
52359 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
52360 mempool_free(ep, mp->ep_pool);
52361 return NULL;
52362 }
52363 @@ -1023,7 +1023,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
52364 xid = ntohs(fh->fh_ox_id); /* we originated exch */
52365 ep = fc_exch_find(mp, xid);
52366 if (!ep) {
52367 - atomic_inc(&mp->stats.xid_not_found);
52368 + atomic_inc_unchecked(&mp->stats.xid_not_found);
52369 reject = FC_RJT_OX_ID;
52370 goto out;
52371 }
52372 @@ -1053,7 +1053,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
52373 ep = fc_exch_find(mp, xid);
52374 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
52375 if (ep) {
52376 - atomic_inc(&mp->stats.xid_busy);
52377 + atomic_inc_unchecked(&mp->stats.xid_busy);
52378 reject = FC_RJT_RX_ID;
52379 goto rel;
52380 }
52381 @@ -1064,7 +1064,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
52382 }
52383 xid = ep->xid; /* get our XID */
52384 } else if (!ep) {
52385 - atomic_inc(&mp->stats.xid_not_found);
52386 + atomic_inc_unchecked(&mp->stats.xid_not_found);
52387 reject = FC_RJT_RX_ID; /* XID not found */
52388 goto out;
52389 }
52390 @@ -1082,7 +1082,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
52391 } else {
52392 sp = &ep->seq;
52393 if (sp->id != fh->fh_seq_id) {
52394 - atomic_inc(&mp->stats.seq_not_found);
52395 + atomic_inc_unchecked(&mp->stats.seq_not_found);
52396 if (f_ctl & FC_FC_END_SEQ) {
52397 /*
52398 * Update sequence_id based on incoming last
52399 @@ -1533,22 +1533,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
52400
52401 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
52402 if (!ep) {
52403 - atomic_inc(&mp->stats.xid_not_found);
52404 + atomic_inc_unchecked(&mp->stats.xid_not_found);
52405 goto out;
52406 }
52407 if (ep->esb_stat & ESB_ST_COMPLETE) {
52408 - atomic_inc(&mp->stats.xid_not_found);
52409 + atomic_inc_unchecked(&mp->stats.xid_not_found);
52410 goto rel;
52411 }
52412 if (ep->rxid == FC_XID_UNKNOWN)
52413 ep->rxid = ntohs(fh->fh_rx_id);
52414 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
52415 - atomic_inc(&mp->stats.xid_not_found);
52416 + atomic_inc_unchecked(&mp->stats.xid_not_found);
52417 goto rel;
52418 }
52419 if (ep->did != ntoh24(fh->fh_s_id) &&
52420 ep->did != FC_FID_FLOGI) {
52421 - atomic_inc(&mp->stats.xid_not_found);
52422 + atomic_inc_unchecked(&mp->stats.xid_not_found);
52423 goto rel;
52424 }
52425 sof = fr_sof(fp);
52426 @@ -1557,7 +1557,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
52427 sp->ssb_stat |= SSB_ST_RESP;
52428 sp->id = fh->fh_seq_id;
52429 } else if (sp->id != fh->fh_seq_id) {
52430 - atomic_inc(&mp->stats.seq_not_found);
52431 + atomic_inc_unchecked(&mp->stats.seq_not_found);
52432 goto rel;
52433 }
52434
52435 @@ -1619,9 +1619,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
52436 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
52437
52438 if (!sp)
52439 - atomic_inc(&mp->stats.xid_not_found);
52440 + atomic_inc_unchecked(&mp->stats.xid_not_found);
52441 else
52442 - atomic_inc(&mp->stats.non_bls_resp);
52443 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
52444
52445 fc_frame_free(fp);
52446 }
52447 @@ -2261,13 +2261,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
52448
52449 list_for_each_entry(ema, &lport->ema_list, ema_list) {
52450 mp = ema->mp;
52451 - st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
52452 + st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
52453 st->fc_no_free_exch_xid +=
52454 - atomic_read(&mp->stats.no_free_exch_xid);
52455 - st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
52456 - st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
52457 - st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
52458 - st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
52459 + atomic_read_unchecked(&mp->stats.no_free_exch_xid);
52460 + st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
52461 + st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
52462 + st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
52463 + st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
52464 }
52465 }
52466 EXPORT_SYMBOL(fc_exch_update_stats);
52467 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
52468 index 766098a..1c6c971 100644
52469 --- a/drivers/scsi/libsas/sas_ata.c
52470 +++ b/drivers/scsi/libsas/sas_ata.c
52471 @@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
52472 .postreset = ata_std_postreset,
52473 .error_handler = ata_std_error_handler,
52474 .post_internal_cmd = sas_ata_post_internal,
52475 - .qc_defer = ata_std_qc_defer,
52476 + .qc_defer = ata_std_qc_defer,
52477 .qc_prep = ata_noop_qc_prep,
52478 .qc_issue = sas_ata_qc_issue,
52479 .qc_fill_rtf = sas_ata_qc_fill_rtf,
52480 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
52481 index 434e903..5a4a79b 100644
52482 --- a/drivers/scsi/lpfc/lpfc.h
52483 +++ b/drivers/scsi/lpfc/lpfc.h
52484 @@ -430,7 +430,7 @@ struct lpfc_vport {
52485 struct dentry *debug_nodelist;
52486 struct dentry *vport_debugfs_root;
52487 struct lpfc_debugfs_trc *disc_trc;
52488 - atomic_t disc_trc_cnt;
52489 + atomic_unchecked_t disc_trc_cnt;
52490 #endif
52491 uint8_t stat_data_enabled;
52492 uint8_t stat_data_blocked;
52493 @@ -880,8 +880,8 @@ struct lpfc_hba {
52494 struct timer_list fabric_block_timer;
52495 unsigned long bit_flags;
52496 #define FABRIC_COMANDS_BLOCKED 0
52497 - atomic_t num_rsrc_err;
52498 - atomic_t num_cmd_success;
52499 + atomic_unchecked_t num_rsrc_err;
52500 + atomic_unchecked_t num_cmd_success;
52501 unsigned long last_rsrc_error_time;
52502 unsigned long last_ramp_down_time;
52503 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
52504 @@ -916,7 +916,7 @@ struct lpfc_hba {
52505
52506 struct dentry *debug_slow_ring_trc;
52507 struct lpfc_debugfs_trc *slow_ring_trc;
52508 - atomic_t slow_ring_trc_cnt;
52509 + atomic_unchecked_t slow_ring_trc_cnt;
52510 /* iDiag debugfs sub-directory */
52511 struct dentry *idiag_root;
52512 struct dentry *idiag_pci_cfg;
52513 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
52514 index b0aedce..89c6ca6 100644
52515 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
52516 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
52517 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
52518
52519 #include <linux/debugfs.h>
52520
52521 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
52522 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
52523 static unsigned long lpfc_debugfs_start_time = 0L;
52524
52525 /* iDiag */
52526 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
52527 lpfc_debugfs_enable = 0;
52528
52529 len = 0;
52530 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
52531 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
52532 (lpfc_debugfs_max_disc_trc - 1);
52533 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
52534 dtp = vport->disc_trc + i;
52535 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
52536 lpfc_debugfs_enable = 0;
52537
52538 len = 0;
52539 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
52540 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
52541 (lpfc_debugfs_max_slow_ring_trc - 1);
52542 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
52543 dtp = phba->slow_ring_trc + i;
52544 @@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
52545 !vport || !vport->disc_trc)
52546 return;
52547
52548 - index = atomic_inc_return(&vport->disc_trc_cnt) &
52549 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
52550 (lpfc_debugfs_max_disc_trc - 1);
52551 dtp = vport->disc_trc + index;
52552 dtp->fmt = fmt;
52553 dtp->data1 = data1;
52554 dtp->data2 = data2;
52555 dtp->data3 = data3;
52556 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
52557 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
52558 dtp->jif = jiffies;
52559 #endif
52560 return;
52561 @@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
52562 !phba || !phba->slow_ring_trc)
52563 return;
52564
52565 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
52566 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
52567 (lpfc_debugfs_max_slow_ring_trc - 1);
52568 dtp = phba->slow_ring_trc + index;
52569 dtp->fmt = fmt;
52570 dtp->data1 = data1;
52571 dtp->data2 = data2;
52572 dtp->data3 = data3;
52573 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
52574 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
52575 dtp->jif = jiffies;
52576 #endif
52577 return;
52578 @@ -4268,7 +4268,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
52579 "slow_ring buffer\n");
52580 goto debug_failed;
52581 }
52582 - atomic_set(&phba->slow_ring_trc_cnt, 0);
52583 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
52584 memset(phba->slow_ring_trc, 0,
52585 (sizeof(struct lpfc_debugfs_trc) *
52586 lpfc_debugfs_max_slow_ring_trc));
52587 @@ -4314,7 +4314,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
52588 "buffer\n");
52589 goto debug_failed;
52590 }
52591 - atomic_set(&vport->disc_trc_cnt, 0);
52592 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
52593
52594 snprintf(name, sizeof(name), "discovery_trace");
52595 vport->debug_disc_trc =
52596 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
52597 index 06f9a5b..82812092 100644
52598 --- a/drivers/scsi/lpfc/lpfc_init.c
52599 +++ b/drivers/scsi/lpfc/lpfc_init.c
52600 @@ -11296,8 +11296,10 @@ lpfc_init(void)
52601 "misc_register returned with status %d", error);
52602
52603 if (lpfc_enable_npiv) {
52604 - lpfc_transport_functions.vport_create = lpfc_vport_create;
52605 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
52606 + pax_open_kernel();
52607 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
52608 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
52609 + pax_close_kernel();
52610 }
52611 lpfc_transport_template =
52612 fc_attach_transport(&lpfc_transport_functions);
52613 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
52614 index 2df11da..e660a2c 100644
52615 --- a/drivers/scsi/lpfc/lpfc_scsi.c
52616 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
52617 @@ -382,7 +382,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
52618 uint32_t evt_posted;
52619
52620 spin_lock_irqsave(&phba->hbalock, flags);
52621 - atomic_inc(&phba->num_rsrc_err);
52622 + atomic_inc_unchecked(&phba->num_rsrc_err);
52623 phba->last_rsrc_error_time = jiffies;
52624
52625 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
52626 @@ -423,8 +423,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
52627 unsigned long num_rsrc_err, num_cmd_success;
52628 int i;
52629
52630 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
52631 - num_cmd_success = atomic_read(&phba->num_cmd_success);
52632 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
52633 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
52634
52635 /*
52636 * The error and success command counters are global per
52637 @@ -452,8 +452,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
52638 }
52639 }
52640 lpfc_destroy_vport_work_array(phba, vports);
52641 - atomic_set(&phba->num_rsrc_err, 0);
52642 - atomic_set(&phba->num_cmd_success, 0);
52643 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
52644 + atomic_set_unchecked(&phba->num_cmd_success, 0);
52645 }
52646
52647 /**
52648 diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
52649 index 5055f92..376cd98 100644
52650 --- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
52651 +++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
52652 @@ -1557,7 +1557,7 @@ _scsih_get_resync(struct device *dev)
52653 {
52654 struct scsi_device *sdev = to_scsi_device(dev);
52655 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
52656 - static struct _raid_device *raid_device;
52657 + struct _raid_device *raid_device;
52658 unsigned long flags;
52659 Mpi2RaidVolPage0_t vol_pg0;
52660 Mpi2ConfigReply_t mpi_reply;
52661 @@ -1609,7 +1609,7 @@ _scsih_get_state(struct device *dev)
52662 {
52663 struct scsi_device *sdev = to_scsi_device(dev);
52664 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
52665 - static struct _raid_device *raid_device;
52666 + struct _raid_device *raid_device;
52667 unsigned long flags;
52668 Mpi2RaidVolPage0_t vol_pg0;
52669 Mpi2ConfigReply_t mpi_reply;
52670 @@ -6631,7 +6631,7 @@ _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
52671 struct fw_event_work *fw_event)
52672 {
52673 Mpi2EventDataIrOperationStatus_t *event_data = fw_event->event_data;
52674 - static struct _raid_device *raid_device;
52675 + struct _raid_device *raid_device;
52676 unsigned long flags;
52677 u16 handle;
52678
52679 @@ -7102,7 +7102,7 @@ _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
52680 u64 sas_address;
52681 struct _sas_device *sas_device;
52682 struct _sas_node *expander_device;
52683 - static struct _raid_device *raid_device;
52684 + struct _raid_device *raid_device;
52685 u8 retry_count;
52686 unsigned long flags;
52687
52688 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
52689 index be8ce54..94ed33a 100644
52690 --- a/drivers/scsi/pmcraid.c
52691 +++ b/drivers/scsi/pmcraid.c
52692 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
52693 res->scsi_dev = scsi_dev;
52694 scsi_dev->hostdata = res;
52695 res->change_detected = 0;
52696 - atomic_set(&res->read_failures, 0);
52697 - atomic_set(&res->write_failures, 0);
52698 + atomic_set_unchecked(&res->read_failures, 0);
52699 + atomic_set_unchecked(&res->write_failures, 0);
52700 rc = 0;
52701 }
52702 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
52703 @@ -2687,9 +2687,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
52704
52705 /* If this was a SCSI read/write command keep count of errors */
52706 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
52707 - atomic_inc(&res->read_failures);
52708 + atomic_inc_unchecked(&res->read_failures);
52709 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
52710 - atomic_inc(&res->write_failures);
52711 + atomic_inc_unchecked(&res->write_failures);
52712
52713 if (!RES_IS_GSCSI(res->cfg_entry) &&
52714 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
52715 @@ -3545,7 +3545,7 @@ static int pmcraid_queuecommand_lck(
52716 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
52717 * hrrq_id assigned here in queuecommand
52718 */
52719 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
52720 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
52721 pinstance->num_hrrq;
52722 cmd->cmd_done = pmcraid_io_done;
52723
52724 @@ -3857,7 +3857,7 @@ static long pmcraid_ioctl_passthrough(
52725 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
52726 * hrrq_id assigned here in queuecommand
52727 */
52728 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
52729 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
52730 pinstance->num_hrrq;
52731
52732 if (request_size) {
52733 @@ -4495,7 +4495,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
52734
52735 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
52736 /* add resources only after host is added into system */
52737 - if (!atomic_read(&pinstance->expose_resources))
52738 + if (!atomic_read_unchecked(&pinstance->expose_resources))
52739 return;
52740
52741 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
52742 @@ -5322,8 +5322,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
52743 init_waitqueue_head(&pinstance->reset_wait_q);
52744
52745 atomic_set(&pinstance->outstanding_cmds, 0);
52746 - atomic_set(&pinstance->last_message_id, 0);
52747 - atomic_set(&pinstance->expose_resources, 0);
52748 + atomic_set_unchecked(&pinstance->last_message_id, 0);
52749 + atomic_set_unchecked(&pinstance->expose_resources, 0);
52750
52751 INIT_LIST_HEAD(&pinstance->free_res_q);
52752 INIT_LIST_HEAD(&pinstance->used_res_q);
52753 @@ -6036,7 +6036,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
52754 /* Schedule worker thread to handle CCN and take care of adding and
52755 * removing devices to OS
52756 */
52757 - atomic_set(&pinstance->expose_resources, 1);
52758 + atomic_set_unchecked(&pinstance->expose_resources, 1);
52759 schedule_work(&pinstance->worker_q);
52760 return rc;
52761
52762 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
52763 index e1d150f..6c6df44 100644
52764 --- a/drivers/scsi/pmcraid.h
52765 +++ b/drivers/scsi/pmcraid.h
52766 @@ -748,7 +748,7 @@ struct pmcraid_instance {
52767 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
52768
52769 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
52770 - atomic_t last_message_id;
52771 + atomic_unchecked_t last_message_id;
52772
52773 /* configuration table */
52774 struct pmcraid_config_table *cfg_table;
52775 @@ -777,7 +777,7 @@ struct pmcraid_instance {
52776 atomic_t outstanding_cmds;
52777
52778 /* should add/delete resources to mid-layer now ?*/
52779 - atomic_t expose_resources;
52780 + atomic_unchecked_t expose_resources;
52781
52782
52783
52784 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
52785 struct pmcraid_config_table_entry_ext cfg_entry_ext;
52786 };
52787 struct scsi_device *scsi_dev; /* Link scsi_device structure */
52788 - atomic_t read_failures; /* count of failed READ commands */
52789 - atomic_t write_failures; /* count of failed WRITE commands */
52790 + atomic_unchecked_t read_failures; /* count of failed READ commands */
52791 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
52792
52793 /* To indicate add/delete/modify during CCN */
52794 u8 change_detected;
52795 diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
52796 index 16fe519..3b1ec82 100644
52797 --- a/drivers/scsi/qla2xxx/qla_attr.c
52798 +++ b/drivers/scsi/qla2xxx/qla_attr.c
52799 @@ -2188,7 +2188,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
52800 return 0;
52801 }
52802
52803 -struct fc_function_template qla2xxx_transport_functions = {
52804 +fc_function_template_no_const qla2xxx_transport_functions = {
52805
52806 .show_host_node_name = 1,
52807 .show_host_port_name = 1,
52808 @@ -2236,7 +2236,7 @@ struct fc_function_template qla2xxx_transport_functions = {
52809 .bsg_timeout = qla24xx_bsg_timeout,
52810 };
52811
52812 -struct fc_function_template qla2xxx_transport_vport_functions = {
52813 +fc_function_template_no_const qla2xxx_transport_vport_functions = {
52814
52815 .show_host_node_name = 1,
52816 .show_host_port_name = 1,
52817 diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
52818 index d48dea8..0845f78 100644
52819 --- a/drivers/scsi/qla2xxx/qla_gbl.h
52820 +++ b/drivers/scsi/qla2xxx/qla_gbl.h
52821 @@ -569,8 +569,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
52822 struct device_attribute;
52823 extern struct device_attribute *qla2x00_host_attrs[];
52824 struct fc_function_template;
52825 -extern struct fc_function_template qla2xxx_transport_functions;
52826 -extern struct fc_function_template qla2xxx_transport_vport_functions;
52827 +extern fc_function_template_no_const qla2xxx_transport_functions;
52828 +extern fc_function_template_no_const qla2xxx_transport_vport_functions;
52829 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
52830 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *, bool);
52831 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
52832 diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
52833 index d96bfb5..d7afe90 100644
52834 --- a/drivers/scsi/qla2xxx/qla_os.c
52835 +++ b/drivers/scsi/qla2xxx/qla_os.c
52836 @@ -1490,8 +1490,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
52837 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
52838 /* Ok, a 64bit DMA mask is applicable. */
52839 ha->flags.enable_64bit_addressing = 1;
52840 - ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
52841 - ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
52842 + pax_open_kernel();
52843 + *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
52844 + *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
52845 + pax_close_kernel();
52846 return;
52847 }
52848 }
52849 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
52850 index 8f6d0fb..1b21097 100644
52851 --- a/drivers/scsi/qla4xxx/ql4_def.h
52852 +++ b/drivers/scsi/qla4xxx/ql4_def.h
52853 @@ -305,7 +305,7 @@ struct ddb_entry {
52854 * (4000 only) */
52855 atomic_t relogin_timer; /* Max Time to wait for
52856 * relogin to complete */
52857 - atomic_t relogin_retry_count; /* Num of times relogin has been
52858 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
52859 * retried */
52860 uint32_t default_time2wait; /* Default Min time between
52861 * relogins (+aens) */
52862 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
52863 index 3202063..f9f0ff6 100644
52864 --- a/drivers/scsi/qla4xxx/ql4_os.c
52865 +++ b/drivers/scsi/qla4xxx/ql4_os.c
52866 @@ -4494,12 +4494,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
52867 */
52868 if (!iscsi_is_session_online(cls_sess)) {
52869 /* Reset retry relogin timer */
52870 - atomic_inc(&ddb_entry->relogin_retry_count);
52871 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
52872 DEBUG2(ql4_printk(KERN_INFO, ha,
52873 "%s: index[%d] relogin timed out-retrying"
52874 " relogin (%d), retry (%d)\n", __func__,
52875 ddb_entry->fw_ddb_index,
52876 - atomic_read(&ddb_entry->relogin_retry_count),
52877 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
52878 ddb_entry->default_time2wait + 4));
52879 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
52880 atomic_set(&ddb_entry->retry_relogin_timer,
52881 @@ -6607,7 +6607,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
52882
52883 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
52884 atomic_set(&ddb_entry->relogin_timer, 0);
52885 - atomic_set(&ddb_entry->relogin_retry_count, 0);
52886 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
52887 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
52888 ddb_entry->default_relogin_timeout =
52889 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
52890 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
52891 index 88d46fe..7351be5 100644
52892 --- a/drivers/scsi/scsi.c
52893 +++ b/drivers/scsi/scsi.c
52894 @@ -640,7 +640,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
52895 struct Scsi_Host *host = cmd->device->host;
52896 int rtn = 0;
52897
52898 - atomic_inc(&cmd->device->iorequest_cnt);
52899 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
52900
52901 /* check if the device is still usable */
52902 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
52903 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
52904 index 3f50dfc..86af487 100644
52905 --- a/drivers/scsi/scsi_lib.c
52906 +++ b/drivers/scsi/scsi_lib.c
52907 @@ -1423,7 +1423,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
52908 shost = sdev->host;
52909 scsi_init_cmd_errh(cmd);
52910 cmd->result = DID_NO_CONNECT << 16;
52911 - atomic_inc(&cmd->device->iorequest_cnt);
52912 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
52913
52914 /*
52915 * SCSI request completion path will do scsi_device_unbusy(),
52916 @@ -1449,9 +1449,9 @@ static void scsi_softirq_done(struct request *rq)
52917
52918 INIT_LIST_HEAD(&cmd->eh_entry);
52919
52920 - atomic_inc(&cmd->device->iodone_cnt);
52921 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
52922 if (cmd->result)
52923 - atomic_inc(&cmd->device->ioerr_cnt);
52924 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
52925
52926 disposition = scsi_decide_disposition(cmd);
52927 if (disposition != SUCCESS &&
52928 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
52929 index 074e8cc..f612e5c 100644
52930 --- a/drivers/scsi/scsi_sysfs.c
52931 +++ b/drivers/scsi/scsi_sysfs.c
52932 @@ -780,7 +780,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
52933 char *buf) \
52934 { \
52935 struct scsi_device *sdev = to_scsi_device(dev); \
52936 - unsigned long long count = atomic_read(&sdev->field); \
52937 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
52938 return snprintf(buf, 20, "0x%llx\n", count); \
52939 } \
52940 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
52941 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
52942 index e51add0..1e06a96 100644
52943 --- a/drivers/scsi/scsi_tgt_lib.c
52944 +++ b/drivers/scsi/scsi_tgt_lib.c
52945 @@ -363,7 +363,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
52946 int err;
52947
52948 dprintk("%lx %u\n", uaddr, len);
52949 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
52950 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
52951 if (err) {
52952 /*
52953 * TODO: need to fixup sg_tablesize, max_segment_size,
52954 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
52955 index 521f583..6b15966 100644
52956 --- a/drivers/scsi/scsi_transport_fc.c
52957 +++ b/drivers/scsi/scsi_transport_fc.c
52958 @@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
52959 * Netlink Infrastructure
52960 */
52961
52962 -static atomic_t fc_event_seq;
52963 +static atomic_unchecked_t fc_event_seq;
52964
52965 /**
52966 * fc_get_event_number - Obtain the next sequential FC event number
52967 @@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
52968 u32
52969 fc_get_event_number(void)
52970 {
52971 - return atomic_add_return(1, &fc_event_seq);
52972 + return atomic_add_return_unchecked(1, &fc_event_seq);
52973 }
52974 EXPORT_SYMBOL(fc_get_event_number);
52975
52976 @@ -655,7 +655,7 @@ static __init int fc_transport_init(void)
52977 {
52978 int error;
52979
52980 - atomic_set(&fc_event_seq, 0);
52981 + atomic_set_unchecked(&fc_event_seq, 0);
52982
52983 error = transport_class_register(&fc_host_class);
52984 if (error)
52985 @@ -845,7 +845,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
52986 char *cp;
52987
52988 *val = simple_strtoul(buf, &cp, 0);
52989 - if ((*cp && (*cp != '\n')) || (*val < 0))
52990 + if (*cp && (*cp != '\n'))
52991 return -EINVAL;
52992 /*
52993 * Check for overflow; dev_loss_tmo is u32
52994 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
52995 index 0102a2d..cc3f8e9 100644
52996 --- a/drivers/scsi/scsi_transport_iscsi.c
52997 +++ b/drivers/scsi/scsi_transport_iscsi.c
52998 @@ -79,7 +79,7 @@ struct iscsi_internal {
52999 struct transport_container session_cont;
53000 };
53001
53002 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
53003 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
53004 static struct workqueue_struct *iscsi_eh_timer_workq;
53005
53006 static DEFINE_IDA(iscsi_sess_ida);
53007 @@ -2071,7 +2071,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
53008 int err;
53009
53010 ihost = shost->shost_data;
53011 - session->sid = atomic_add_return(1, &iscsi_session_nr);
53012 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
53013
53014 if (target_id == ISCSI_MAX_TARGET) {
53015 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
53016 @@ -4511,7 +4511,7 @@ static __init int iscsi_transport_init(void)
53017 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
53018 ISCSI_TRANSPORT_VERSION);
53019
53020 - atomic_set(&iscsi_session_nr, 0);
53021 + atomic_set_unchecked(&iscsi_session_nr, 0);
53022
53023 err = class_register(&iscsi_transport_class);
53024 if (err)
53025 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
53026 index 13e8983..d306a68 100644
53027 --- a/drivers/scsi/scsi_transport_srp.c
53028 +++ b/drivers/scsi/scsi_transport_srp.c
53029 @@ -36,7 +36,7 @@
53030 #include "scsi_transport_srp_internal.h"
53031
53032 struct srp_host_attrs {
53033 - atomic_t next_port_id;
53034 + atomic_unchecked_t next_port_id;
53035 };
53036 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
53037
53038 @@ -101,7 +101,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
53039 struct Scsi_Host *shost = dev_to_shost(dev);
53040 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
53041
53042 - atomic_set(&srp_host->next_port_id, 0);
53043 + atomic_set_unchecked(&srp_host->next_port_id, 0);
53044 return 0;
53045 }
53046
53047 @@ -734,7 +734,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
53048 rport_fast_io_fail_timedout);
53049 INIT_DELAYED_WORK(&rport->dev_loss_work, rport_dev_loss_timedout);
53050
53051 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
53052 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
53053 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
53054
53055 transport_setup_device(&rport->dev);
53056 diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
53057 index 6825eda..be470c4 100644
53058 --- a/drivers/scsi/sd.c
53059 +++ b/drivers/scsi/sd.c
53060 @@ -2954,7 +2954,7 @@ static int sd_probe(struct device *dev)
53061 sdkp->disk = gd;
53062 sdkp->index = index;
53063 atomic_set(&sdkp->openers, 0);
53064 - atomic_set(&sdkp->device->ioerr_cnt, 0);
53065 + atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
53066
53067 if (!sdp->request_queue->rq_timeout) {
53068 if (sdp->type != TYPE_MOD)
53069 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
53070 index 53268aab..17c2764 100644
53071 --- a/drivers/scsi/sg.c
53072 +++ b/drivers/scsi/sg.c
53073 @@ -1102,7 +1102,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
53074 sdp->disk->disk_name,
53075 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
53076 NULL,
53077 - (char *)arg);
53078 + (char __user *)arg);
53079 case BLKTRACESTART:
53080 return blk_trace_startstop(sdp->device->request_queue, 1);
53081 case BLKTRACESTOP:
53082 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
53083 index d4f9670..d37b662 100644
53084 --- a/drivers/spi/spi.c
53085 +++ b/drivers/spi/spi.c
53086 @@ -2204,7 +2204,7 @@ int spi_bus_unlock(struct spi_master *master)
53087 EXPORT_SYMBOL_GPL(spi_bus_unlock);
53088
53089 /* portable code must never pass more than 32 bytes */
53090 -#define SPI_BUFSIZ max(32, SMP_CACHE_BYTES)
53091 +#define SPI_BUFSIZ max(32UL, SMP_CACHE_BYTES)
53092
53093 static u8 *buf;
53094
53095 diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
53096 index c341ac1..bf9799f 100644
53097 --- a/drivers/staging/android/timed_output.c
53098 +++ b/drivers/staging/android/timed_output.c
53099 @@ -25,7 +25,7 @@
53100 #include "timed_output.h"
53101
53102 static struct class *timed_output_class;
53103 -static atomic_t device_count;
53104 +static atomic_unchecked_t device_count;
53105
53106 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
53107 char *buf)
53108 @@ -63,7 +63,7 @@ static int create_timed_output_class(void)
53109 timed_output_class = class_create(THIS_MODULE, "timed_output");
53110 if (IS_ERR(timed_output_class))
53111 return PTR_ERR(timed_output_class);
53112 - atomic_set(&device_count, 0);
53113 + atomic_set_unchecked(&device_count, 0);
53114 timed_output_class->dev_groups = timed_output_groups;
53115 }
53116
53117 @@ -81,7 +81,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
53118 if (ret < 0)
53119 return ret;
53120
53121 - tdev->index = atomic_inc_return(&device_count);
53122 + tdev->index = atomic_inc_return_unchecked(&device_count);
53123 tdev->dev = device_create(timed_output_class, NULL,
53124 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
53125 if (IS_ERR(tdev->dev))
53126 diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
53127 index fe47cd3..19a1bd1 100644
53128 --- a/drivers/staging/gdm724x/gdm_tty.c
53129 +++ b/drivers/staging/gdm724x/gdm_tty.c
53130 @@ -44,7 +44,7 @@
53131 #define gdm_tty_send_control(n, r, v, d, l) (\
53132 n->tty_dev->send_control(n->tty_dev->priv_dev, r, v, d, l))
53133
53134 -#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
53135 +#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && atomic_read(&gdm->port.count))
53136
53137 static struct tty_driver *gdm_driver[TTY_MAX_COUNT];
53138 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
53139 diff --git a/drivers/staging/imx-drm/imx-drm-core.c b/drivers/staging/imx-drm/imx-drm-core.c
53140 index def8280..e3fd96a 100644
53141 --- a/drivers/staging/imx-drm/imx-drm-core.c
53142 +++ b/drivers/staging/imx-drm/imx-drm-core.c
53143 @@ -355,7 +355,7 @@ int imx_drm_add_crtc(struct drm_device *drm, struct drm_crtc *crtc,
53144 if (imxdrm->pipes >= MAX_CRTC)
53145 return -EINVAL;
53146
53147 - if (imxdrm->drm->open_count)
53148 + if (local_read(&imxdrm->drm->open_count))
53149 return -EBUSY;
53150
53151 imx_drm_crtc = kzalloc(sizeof(*imx_drm_crtc), GFP_KERNEL);
53152 diff --git a/drivers/staging/lustre/lnet/selftest/brw_test.c b/drivers/staging/lustre/lnet/selftest/brw_test.c
53153 index 3f8020c..649fded 100644
53154 --- a/drivers/staging/lustre/lnet/selftest/brw_test.c
53155 +++ b/drivers/staging/lustre/lnet/selftest/brw_test.c
53156 @@ -488,13 +488,11 @@ brw_server_handle(struct srpc_server_rpc *rpc)
53157 return 0;
53158 }
53159
53160 -sfw_test_client_ops_t brw_test_client;
53161 -void brw_init_test_client(void)
53162 -{
53163 - brw_test_client.tso_init = brw_client_init;
53164 - brw_test_client.tso_fini = brw_client_fini;
53165 - brw_test_client.tso_prep_rpc = brw_client_prep_rpc;
53166 - brw_test_client.tso_done_rpc = brw_client_done_rpc;
53167 +sfw_test_client_ops_t brw_test_client = {
53168 + .tso_init = brw_client_init,
53169 + .tso_fini = brw_client_fini,
53170 + .tso_prep_rpc = brw_client_prep_rpc,
53171 + .tso_done_rpc = brw_client_done_rpc,
53172 };
53173
53174 srpc_service_t brw_test_service;
53175 diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
53176 index 050723a..fa6fdf1 100644
53177 --- a/drivers/staging/lustre/lnet/selftest/framework.c
53178 +++ b/drivers/staging/lustre/lnet/selftest/framework.c
53179 @@ -1635,12 +1635,10 @@ static srpc_service_t sfw_services[] =
53180
53181 extern sfw_test_client_ops_t ping_test_client;
53182 extern srpc_service_t ping_test_service;
53183 -extern void ping_init_test_client(void);
53184 extern void ping_init_test_service(void);
53185
53186 extern sfw_test_client_ops_t brw_test_client;
53187 extern srpc_service_t brw_test_service;
53188 -extern void brw_init_test_client(void);
53189 extern void brw_init_test_service(void);
53190
53191
53192 @@ -1684,12 +1682,10 @@ sfw_startup (void)
53193 INIT_LIST_HEAD(&sfw_data.fw_zombie_rpcs);
53194 INIT_LIST_HEAD(&sfw_data.fw_zombie_sessions);
53195
53196 - brw_init_test_client();
53197 brw_init_test_service();
53198 rc = sfw_register_test(&brw_test_service, &brw_test_client);
53199 LASSERT (rc == 0);
53200
53201 - ping_init_test_client();
53202 ping_init_test_service();
53203 rc = sfw_register_test(&ping_test_service, &ping_test_client);
53204 LASSERT (rc == 0);
53205 diff --git a/drivers/staging/lustre/lnet/selftest/ping_test.c b/drivers/staging/lustre/lnet/selftest/ping_test.c
53206 index 750cac4..e4d751f 100644
53207 --- a/drivers/staging/lustre/lnet/selftest/ping_test.c
53208 +++ b/drivers/staging/lustre/lnet/selftest/ping_test.c
53209 @@ -211,14 +211,12 @@ ping_server_handle(struct srpc_server_rpc *rpc)
53210 return 0;
53211 }
53212
53213 -sfw_test_client_ops_t ping_test_client;
53214 -void ping_init_test_client(void)
53215 -{
53216 - ping_test_client.tso_init = ping_client_init;
53217 - ping_test_client.tso_fini = ping_client_fini;
53218 - ping_test_client.tso_prep_rpc = ping_client_prep_rpc;
53219 - ping_test_client.tso_done_rpc = ping_client_done_rpc;
53220 -}
53221 +sfw_test_client_ops_t ping_test_client = {
53222 + .tso_init = ping_client_init,
53223 + .tso_fini = ping_client_fini,
53224 + .tso_prep_rpc = ping_client_prep_rpc,
53225 + .tso_done_rpc = ping_client_done_rpc,
53226 +};
53227
53228 srpc_service_t ping_test_service;
53229 void ping_init_test_service(void)
53230 diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h
53231 index 0c6b784..c64235c 100644
53232 --- a/drivers/staging/lustre/lustre/include/lustre_dlm.h
53233 +++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h
53234 @@ -1141,7 +1141,7 @@ struct ldlm_callback_suite {
53235 ldlm_completion_callback lcs_completion;
53236 ldlm_blocking_callback lcs_blocking;
53237 ldlm_glimpse_callback lcs_glimpse;
53238 -};
53239 +} __no_const;
53240
53241 /* ldlm_lockd.c */
53242 int ldlm_del_waiting_lock(struct ldlm_lock *lock);
53243 diff --git a/drivers/staging/lustre/lustre/include/obd.h b/drivers/staging/lustre/lustre/include/obd.h
53244 index d5c4613..a341678 100644
53245 --- a/drivers/staging/lustre/lustre/include/obd.h
53246 +++ b/drivers/staging/lustre/lustre/include/obd.h
53247 @@ -1439,7 +1439,7 @@ struct md_ops {
53248 * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
53249 * wrapper function in include/linux/obd_class.h.
53250 */
53251 -};
53252 +} __no_const;
53253
53254 struct lsm_operations {
53255 void (*lsm_free)(struct lov_stripe_md *);
53256 diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
53257 index 986bf38..eab2558f 100644
53258 --- a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
53259 +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
53260 @@ -259,7 +259,7 @@ ldlm_process_flock_lock(struct ldlm_lock *req, __u64 *flags, int first_enq,
53261 int added = (mode == LCK_NL);
53262 int overlaps = 0;
53263 int splitted = 0;
53264 - const struct ldlm_callback_suite null_cbs = { NULL };
53265 + const struct ldlm_callback_suite null_cbs = { };
53266
53267 CDEBUG(D_DLMTRACE, "flags %#llx owner "LPU64" pid %u mode %u start "
53268 LPU64" end "LPU64"\n", *flags,
53269 diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
53270 index e947b91..f408990 100644
53271 --- a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
53272 +++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
53273 @@ -217,7 +217,7 @@ DECLARE_PROC_HANDLER(proc_debug_mb)
53274 int LL_PROC_PROTO(proc_console_max_delay_cs)
53275 {
53276 int rc, max_delay_cs;
53277 - ctl_table_t dummy = *table;
53278 + ctl_table_no_const dummy = *table;
53279 cfs_duration_t d;
53280
53281 dummy.data = &max_delay_cs;
53282 @@ -248,7 +248,7 @@ int LL_PROC_PROTO(proc_console_max_delay_cs)
53283 int LL_PROC_PROTO(proc_console_min_delay_cs)
53284 {
53285 int rc, min_delay_cs;
53286 - ctl_table_t dummy = *table;
53287 + ctl_table_no_const dummy = *table;
53288 cfs_duration_t d;
53289
53290 dummy.data = &min_delay_cs;
53291 @@ -279,7 +279,7 @@ int LL_PROC_PROTO(proc_console_min_delay_cs)
53292 int LL_PROC_PROTO(proc_console_backoff)
53293 {
53294 int rc, backoff;
53295 - ctl_table_t dummy = *table;
53296 + ctl_table_no_const dummy = *table;
53297
53298 dummy.data = &backoff;
53299 dummy.proc_handler = &proc_dointvec;
53300 diff --git a/drivers/staging/lustre/lustre/libcfs/module.c b/drivers/staging/lustre/lustre/libcfs/module.c
53301 index b16ee08..a3db5c6 100644
53302 --- a/drivers/staging/lustre/lustre/libcfs/module.c
53303 +++ b/drivers/staging/lustre/lustre/libcfs/module.c
53304 @@ -314,11 +314,11 @@ out:
53305
53306
53307 struct cfs_psdev_ops libcfs_psdev_ops = {
53308 - libcfs_psdev_open,
53309 - libcfs_psdev_release,
53310 - NULL,
53311 - NULL,
53312 - libcfs_ioctl
53313 + .p_open = libcfs_psdev_open,
53314 + .p_close = libcfs_psdev_release,
53315 + .p_read = NULL,
53316 + .p_write = NULL,
53317 + .p_ioctl = libcfs_ioctl
53318 };
53319
53320 extern int insert_proc(void);
53321 diff --git a/drivers/staging/lustre/lustre/llite/dir.c b/drivers/staging/lustre/lustre/llite/dir.c
53322 index ae6f61a..03c3d5d 100644
53323 --- a/drivers/staging/lustre/lustre/llite/dir.c
53324 +++ b/drivers/staging/lustre/lustre/llite/dir.c
53325 @@ -660,7 +660,7 @@ int ll_dir_setdirstripe(struct inode *dir, struct lmv_user_md *lump,
53326 int mode;
53327 int err;
53328
53329 - mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
53330 + mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current_umask()) | S_IFDIR;
53331 op_data = ll_prep_md_op_data(NULL, dir, NULL, filename,
53332 strlen(filename), mode, LUSTRE_OPC_MKDIR,
53333 lump);
53334 diff --git a/drivers/staging/media/solo6x10/solo6x10-core.c b/drivers/staging/media/solo6x10/solo6x10-core.c
53335 index f670469..03b7438 100644
53336 --- a/drivers/staging/media/solo6x10/solo6x10-core.c
53337 +++ b/drivers/staging/media/solo6x10/solo6x10-core.c
53338 @@ -434,7 +434,7 @@ static void solo_device_release(struct device *dev)
53339
53340 static int solo_sysfs_init(struct solo_dev *solo_dev)
53341 {
53342 - struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
53343 + bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
53344 struct device *dev = &solo_dev->dev;
53345 const char *driver;
53346 int i;
53347 diff --git a/drivers/staging/media/solo6x10/solo6x10-g723.c b/drivers/staging/media/solo6x10/solo6x10-g723.c
53348 index 74f037b..5b5bb76 100644
53349 --- a/drivers/staging/media/solo6x10/solo6x10-g723.c
53350 +++ b/drivers/staging/media/solo6x10/solo6x10-g723.c
53351 @@ -355,7 +355,7 @@ static int solo_snd_pcm_init(struct solo_dev *solo_dev)
53352
53353 int solo_g723_init(struct solo_dev *solo_dev)
53354 {
53355 - static struct snd_device_ops ops = { NULL };
53356 + static struct snd_device_ops ops = { };
53357 struct snd_card *card;
53358 struct snd_kcontrol_new kctl;
53359 char name[32];
53360 diff --git a/drivers/staging/media/solo6x10/solo6x10-p2m.c b/drivers/staging/media/solo6x10/solo6x10-p2m.c
53361 index 7f2f247..d999137 100644
53362 --- a/drivers/staging/media/solo6x10/solo6x10-p2m.c
53363 +++ b/drivers/staging/media/solo6x10/solo6x10-p2m.c
53364 @@ -77,7 +77,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
53365
53366 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
53367 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
53368 - p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
53369 + p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
53370 if (p2m_id < 0)
53371 p2m_id = -p2m_id;
53372 }
53373 diff --git a/drivers/staging/media/solo6x10/solo6x10.h b/drivers/staging/media/solo6x10/solo6x10.h
53374 index 8964f8b..36eb087 100644
53375 --- a/drivers/staging/media/solo6x10/solo6x10.h
53376 +++ b/drivers/staging/media/solo6x10/solo6x10.h
53377 @@ -237,7 +237,7 @@ struct solo_dev {
53378
53379 /* P2M DMA Engine */
53380 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
53381 - atomic_t p2m_count;
53382 + atomic_unchecked_t p2m_count;
53383 int p2m_jiffies;
53384 unsigned int p2m_timeouts;
53385
53386 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
53387 index a0f4868..139f1fb 100644
53388 --- a/drivers/staging/octeon/ethernet-rx.c
53389 +++ b/drivers/staging/octeon/ethernet-rx.c
53390 @@ -417,11 +417,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
53391 /* Increment RX stats for virtual ports */
53392 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
53393 #ifdef CONFIG_64BIT
53394 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
53395 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
53396 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
53397 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
53398 #else
53399 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
53400 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
53401 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
53402 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
53403 #endif
53404 }
53405 netif_receive_skb(skb);
53406 @@ -432,9 +432,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
53407 dev->name);
53408 */
53409 #ifdef CONFIG_64BIT
53410 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
53411 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
53412 #else
53413 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
53414 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
53415 #endif
53416 dev_kfree_skb_irq(skb);
53417 }
53418 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
53419 index da9dd6b..8e3e0f5 100644
53420 --- a/drivers/staging/octeon/ethernet.c
53421 +++ b/drivers/staging/octeon/ethernet.c
53422 @@ -247,11 +247,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
53423 * since the RX tasklet also increments it.
53424 */
53425 #ifdef CONFIG_64BIT
53426 - atomic64_add(rx_status.dropped_packets,
53427 - (atomic64_t *)&priv->stats.rx_dropped);
53428 + atomic64_add_unchecked(rx_status.dropped_packets,
53429 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
53430 #else
53431 - atomic_add(rx_status.dropped_packets,
53432 - (atomic_t *)&priv->stats.rx_dropped);
53433 + atomic_add_unchecked(rx_status.dropped_packets,
53434 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
53435 #endif
53436 }
53437
53438 diff --git a/drivers/staging/rtl8188eu/include/hal_intf.h b/drivers/staging/rtl8188eu/include/hal_intf.h
53439 index c59fccd..79f8fc2 100644
53440 --- a/drivers/staging/rtl8188eu/include/hal_intf.h
53441 +++ b/drivers/staging/rtl8188eu/include/hal_intf.h
53442 @@ -267,7 +267,7 @@ struct hal_ops {
53443 s32 (*c2h_handler)(struct adapter *padapter,
53444 struct c2h_evt_hdr *c2h_evt);
53445 c2h_id_filter c2h_id_filter_ccx;
53446 -};
53447 +} __no_const;
53448
53449 enum rt_eeprom_type {
53450 EEPROM_93C46,
53451 diff --git a/drivers/staging/rtl8188eu/include/rtw_io.h b/drivers/staging/rtl8188eu/include/rtw_io.h
53452 index e8790f8..b4a5980 100644
53453 --- a/drivers/staging/rtl8188eu/include/rtw_io.h
53454 +++ b/drivers/staging/rtl8188eu/include/rtw_io.h
53455 @@ -124,7 +124,7 @@ struct _io_ops {
53456 u32 (*_write_scsi)(struct intf_hdl *pintfhdl, u32 cnt, u8 *pmem);
53457 void (*_read_port_cancel)(struct intf_hdl *pintfhdl);
53458 void (*_write_port_cancel)(struct intf_hdl *pintfhdl);
53459 -};
53460 +} __no_const;
53461
53462 struct io_req {
53463 struct list_head list;
53464 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
53465 index dc23395..cf7e9b1 100644
53466 --- a/drivers/staging/rtl8712/rtl871x_io.h
53467 +++ b/drivers/staging/rtl8712/rtl871x_io.h
53468 @@ -108,7 +108,7 @@ struct _io_ops {
53469 u8 *pmem);
53470 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
53471 u8 *pmem);
53472 -};
53473 +} __no_const;
53474
53475 struct io_req {
53476 struct list_head list;
53477 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
53478 index a863a98..d272795 100644
53479 --- a/drivers/staging/usbip/vhci.h
53480 +++ b/drivers/staging/usbip/vhci.h
53481 @@ -83,7 +83,7 @@ struct vhci_hcd {
53482 unsigned resuming:1;
53483 unsigned long re_timeout;
53484
53485 - atomic_t seqnum;
53486 + atomic_unchecked_t seqnum;
53487
53488 /*
53489 * NOTE:
53490 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
53491 index 0007d30..c06a693 100644
53492 --- a/drivers/staging/usbip/vhci_hcd.c
53493 +++ b/drivers/staging/usbip/vhci_hcd.c
53494 @@ -439,7 +439,7 @@ static void vhci_tx_urb(struct urb *urb)
53495
53496 spin_lock(&vdev->priv_lock);
53497
53498 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
53499 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
53500 if (priv->seqnum == 0xffff)
53501 dev_info(&urb->dev->dev, "seqnum max\n");
53502
53503 @@ -686,7 +686,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
53504 return -ENOMEM;
53505 }
53506
53507 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
53508 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
53509 if (unlink->seqnum == 0xffff)
53510 pr_info("seqnum max\n");
53511
53512 @@ -891,7 +891,7 @@ static int vhci_start(struct usb_hcd *hcd)
53513 vdev->rhport = rhport;
53514 }
53515
53516 - atomic_set(&vhci->seqnum, 0);
53517 + atomic_set_unchecked(&vhci->seqnum, 0);
53518 spin_lock_init(&vhci->lock);
53519
53520 hcd->power_budget = 0; /* no limit */
53521 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
53522 index d07fcb5..358e1e1 100644
53523 --- a/drivers/staging/usbip/vhci_rx.c
53524 +++ b/drivers/staging/usbip/vhci_rx.c
53525 @@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
53526 if (!urb) {
53527 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
53528 pr_info("max seqnum %d\n",
53529 - atomic_read(&the_controller->seqnum));
53530 + atomic_read_unchecked(&the_controller->seqnum));
53531 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
53532 return;
53533 }
53534 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
53535 index 317c2a8..ffeb4ef 100644
53536 --- a/drivers/staging/vt6655/hostap.c
53537 +++ b/drivers/staging/vt6655/hostap.c
53538 @@ -68,14 +68,13 @@ static int msglevel = MSG_LEVEL_INFO;
53539 *
53540 */
53541
53542 +static net_device_ops_no_const apdev_netdev_ops;
53543 +
53544 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
53545 {
53546 PSDevice apdev_priv;
53547 struct net_device *dev = pDevice->dev;
53548 int ret;
53549 - const struct net_device_ops apdev_netdev_ops = {
53550 - .ndo_start_xmit = pDevice->tx_80211,
53551 - };
53552
53553 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
53554
53555 @@ -87,6 +86,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
53556 *apdev_priv = *pDevice;
53557 eth_hw_addr_inherit(pDevice->apdev, dev);
53558
53559 + /* only half broken now */
53560 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
53561 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
53562
53563 pDevice->apdev->type = ARPHRD_IEEE80211;
53564 diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
53565 index e7e9372..161f530 100644
53566 --- a/drivers/target/sbp/sbp_target.c
53567 +++ b/drivers/target/sbp/sbp_target.c
53568 @@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
53569
53570 #define SESSION_MAINTENANCE_INTERVAL HZ
53571
53572 -static atomic_t login_id = ATOMIC_INIT(0);
53573 +static atomic_unchecked_t login_id = ATOMIC_INIT(0);
53574
53575 static void session_maintenance_work(struct work_struct *);
53576 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
53577 @@ -444,7 +444,7 @@ static void sbp_management_request_login(
53578 login->lun = se_lun;
53579 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
53580 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
53581 - login->login_id = atomic_inc_return(&login_id);
53582 + login->login_id = atomic_inc_return_unchecked(&login_id);
53583
53584 login->tgt_agt = sbp_target_agent_register(login);
53585 if (IS_ERR(login->tgt_agt)) {
53586 diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
53587 index 98da901..bb443e8 100644
53588 --- a/drivers/target/target_core_device.c
53589 +++ b/drivers/target/target_core_device.c
53590 @@ -1525,7 +1525,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
53591 spin_lock_init(&dev->se_tmr_lock);
53592 spin_lock_init(&dev->qf_cmd_lock);
53593 sema_init(&dev->caw_sem, 1);
53594 - atomic_set(&dev->dev_ordered_id, 0);
53595 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
53596 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
53597 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
53598 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
53599 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
53600 index 7fa62fc..abdd041 100644
53601 --- a/drivers/target/target_core_transport.c
53602 +++ b/drivers/target/target_core_transport.c
53603 @@ -1165,7 +1165,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
53604 * Used to determine when ORDERED commands should go from
53605 * Dormant to Active status.
53606 */
53607 - cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
53608 + cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
53609 smp_mb__after_atomic();
53610 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
53611 cmd->se_ordered_id, cmd->sam_task_attr,
53612 diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c
53613 index 4b2b999..cad9fa5 100644
53614 --- a/drivers/thermal/of-thermal.c
53615 +++ b/drivers/thermal/of-thermal.c
53616 @@ -30,6 +30,7 @@
53617 #include <linux/err.h>
53618 #include <linux/export.h>
53619 #include <linux/string.h>
53620 +#include <linux/mm.h>
53621
53622 #include "thermal_core.h"
53623
53624 @@ -341,8 +342,10 @@ thermal_zone_of_add_sensor(struct device_node *zone,
53625 tz->get_trend = get_trend;
53626 tz->sensor_data = data;
53627
53628 - tzd->ops->get_temp = of_thermal_get_temp;
53629 - tzd->ops->get_trend = of_thermal_get_trend;
53630 + pax_open_kernel();
53631 + *(void **)&tzd->ops->get_temp = of_thermal_get_temp;
53632 + *(void **)&tzd->ops->get_trend = of_thermal_get_trend;
53633 + pax_close_kernel();
53634 mutex_unlock(&tzd->lock);
53635
53636 return tzd;
53637 @@ -461,8 +464,10 @@ void thermal_zone_of_sensor_unregister(struct device *dev,
53638 return;
53639
53640 mutex_lock(&tzd->lock);
53641 - tzd->ops->get_temp = NULL;
53642 - tzd->ops->get_trend = NULL;
53643 + pax_open_kernel();
53644 + *(void **)&tzd->ops->get_temp = NULL;
53645 + *(void **)&tzd->ops->get_trend = NULL;
53646 + pax_close_kernel();
53647
53648 tz->get_temp = NULL;
53649 tz->get_trend = NULL;
53650 diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
53651 index a57bb5a..1f727d33 100644
53652 --- a/drivers/tty/cyclades.c
53653 +++ b/drivers/tty/cyclades.c
53654 @@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
53655 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
53656 info->port.count);
53657 #endif
53658 - info->port.count++;
53659 + atomic_inc(&info->port.count);
53660 #ifdef CY_DEBUG_COUNT
53661 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
53662 - current->pid, info->port.count);
53663 + current->pid, atomic_read(&info->port.count));
53664 #endif
53665
53666 /*
53667 @@ -3974,7 +3974,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
53668 for (j = 0; j < cy_card[i].nports; j++) {
53669 info = &cy_card[i].ports[j];
53670
53671 - if (info->port.count) {
53672 + if (atomic_read(&info->port.count)) {
53673 /* XXX is the ldisc num worth this? */
53674 struct tty_struct *tty;
53675 struct tty_ldisc *ld;
53676 diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
53677 index 4fcec1d..5a036f7 100644
53678 --- a/drivers/tty/hvc/hvc_console.c
53679 +++ b/drivers/tty/hvc/hvc_console.c
53680 @@ -342,7 +342,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
53681
53682 spin_lock_irqsave(&hp->port.lock, flags);
53683 /* Check and then increment for fast path open. */
53684 - if (hp->port.count++ > 0) {
53685 + if (atomic_inc_return(&hp->port.count) > 1) {
53686 spin_unlock_irqrestore(&hp->port.lock, flags);
53687 hvc_kick();
53688 return 0;
53689 @@ -397,7 +397,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
53690
53691 spin_lock_irqsave(&hp->port.lock, flags);
53692
53693 - if (--hp->port.count == 0) {
53694 + if (atomic_dec_return(&hp->port.count) == 0) {
53695 spin_unlock_irqrestore(&hp->port.lock, flags);
53696 /* We are done with the tty pointer now. */
53697 tty_port_tty_set(&hp->port, NULL);
53698 @@ -419,9 +419,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
53699 */
53700 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
53701 } else {
53702 - if (hp->port.count < 0)
53703 + if (atomic_read(&hp->port.count) < 0)
53704 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
53705 - hp->vtermno, hp->port.count);
53706 + hp->vtermno, atomic_read(&hp->port.count));
53707 spin_unlock_irqrestore(&hp->port.lock, flags);
53708 }
53709 }
53710 @@ -451,12 +451,12 @@ static void hvc_hangup(struct tty_struct *tty)
53711 * open->hangup case this can be called after the final close so prevent
53712 * that from happening for now.
53713 */
53714 - if (hp->port.count <= 0) {
53715 + if (atomic_read(&hp->port.count) <= 0) {
53716 spin_unlock_irqrestore(&hp->port.lock, flags);
53717 return;
53718 }
53719
53720 - hp->port.count = 0;
53721 + atomic_set(&hp->port.count, 0);
53722 spin_unlock_irqrestore(&hp->port.lock, flags);
53723 tty_port_tty_set(&hp->port, NULL);
53724
53725 @@ -504,7 +504,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
53726 return -EPIPE;
53727
53728 /* FIXME what's this (unprotected) check for? */
53729 - if (hp->port.count <= 0)
53730 + if (atomic_read(&hp->port.count) <= 0)
53731 return -EIO;
53732
53733 spin_lock_irqsave(&hp->lock, flags);
53734 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
53735 index 81e939e..95ead10 100644
53736 --- a/drivers/tty/hvc/hvcs.c
53737 +++ b/drivers/tty/hvc/hvcs.c
53738 @@ -83,6 +83,7 @@
53739 #include <asm/hvcserver.h>
53740 #include <asm/uaccess.h>
53741 #include <asm/vio.h>
53742 +#include <asm/local.h>
53743
53744 /*
53745 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
53746 @@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
53747
53748 spin_lock_irqsave(&hvcsd->lock, flags);
53749
53750 - if (hvcsd->port.count > 0) {
53751 + if (atomic_read(&hvcsd->port.count) > 0) {
53752 spin_unlock_irqrestore(&hvcsd->lock, flags);
53753 printk(KERN_INFO "HVCS: vterm state unchanged. "
53754 "The hvcs device node is still in use.\n");
53755 @@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
53756 }
53757 }
53758
53759 - hvcsd->port.count = 0;
53760 + atomic_set(&hvcsd->port.count, 0);
53761 hvcsd->port.tty = tty;
53762 tty->driver_data = hvcsd;
53763
53764 @@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
53765 unsigned long flags;
53766
53767 spin_lock_irqsave(&hvcsd->lock, flags);
53768 - hvcsd->port.count++;
53769 + atomic_inc(&hvcsd->port.count);
53770 hvcsd->todo_mask |= HVCS_SCHED_READ;
53771 spin_unlock_irqrestore(&hvcsd->lock, flags);
53772
53773 @@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
53774 hvcsd = tty->driver_data;
53775
53776 spin_lock_irqsave(&hvcsd->lock, flags);
53777 - if (--hvcsd->port.count == 0) {
53778 + if (atomic_dec_and_test(&hvcsd->port.count)) {
53779
53780 vio_disable_interrupts(hvcsd->vdev);
53781
53782 @@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
53783
53784 free_irq(irq, hvcsd);
53785 return;
53786 - } else if (hvcsd->port.count < 0) {
53787 + } else if (atomic_read(&hvcsd->port.count) < 0) {
53788 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
53789 " is missmanaged.\n",
53790 - hvcsd->vdev->unit_address, hvcsd->port.count);
53791 + hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
53792 }
53793
53794 spin_unlock_irqrestore(&hvcsd->lock, flags);
53795 @@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
53796
53797 spin_lock_irqsave(&hvcsd->lock, flags);
53798 /* Preserve this so that we know how many kref refs to put */
53799 - temp_open_count = hvcsd->port.count;
53800 + temp_open_count = atomic_read(&hvcsd->port.count);
53801
53802 /*
53803 * Don't kref put inside the spinlock because the destruction
53804 @@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
53805 tty->driver_data = NULL;
53806 hvcsd->port.tty = NULL;
53807
53808 - hvcsd->port.count = 0;
53809 + atomic_set(&hvcsd->port.count, 0);
53810
53811 /* This will drop any buffered data on the floor which is OK in a hangup
53812 * scenario. */
53813 @@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
53814 * the middle of a write operation? This is a crummy place to do this
53815 * but we want to keep it all in the spinlock.
53816 */
53817 - if (hvcsd->port.count <= 0) {
53818 + if (atomic_read(&hvcsd->port.count) <= 0) {
53819 spin_unlock_irqrestore(&hvcsd->lock, flags);
53820 return -ENODEV;
53821 }
53822 @@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
53823 {
53824 struct hvcs_struct *hvcsd = tty->driver_data;
53825
53826 - if (!hvcsd || hvcsd->port.count <= 0)
53827 + if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
53828 return 0;
53829
53830 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
53831 diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
53832 index 4190199..06d5bfa 100644
53833 --- a/drivers/tty/hvc/hvsi.c
53834 +++ b/drivers/tty/hvc/hvsi.c
53835 @@ -85,7 +85,7 @@ struct hvsi_struct {
53836 int n_outbuf;
53837 uint32_t vtermno;
53838 uint32_t virq;
53839 - atomic_t seqno; /* HVSI packet sequence number */
53840 + atomic_unchecked_t seqno; /* HVSI packet sequence number */
53841 uint16_t mctrl;
53842 uint8_t state; /* HVSI protocol state */
53843 uint8_t flags;
53844 @@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
53845
53846 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
53847 packet.hdr.len = sizeof(struct hvsi_query_response);
53848 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
53849 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
53850 packet.verb = VSV_SEND_VERSION_NUMBER;
53851 packet.u.version = HVSI_VERSION;
53852 packet.query_seqno = query_seqno+1;
53853 @@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
53854
53855 packet.hdr.type = VS_QUERY_PACKET_HEADER;
53856 packet.hdr.len = sizeof(struct hvsi_query);
53857 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
53858 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
53859 packet.verb = verb;
53860
53861 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
53862 @@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
53863 int wrote;
53864
53865 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
53866 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
53867 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
53868 packet.hdr.len = sizeof(struct hvsi_control);
53869 packet.verb = VSV_SET_MODEM_CTL;
53870 packet.mask = HVSI_TSDTR;
53871 @@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
53872 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
53873
53874 packet.hdr.type = VS_DATA_PACKET_HEADER;
53875 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
53876 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
53877 packet.hdr.len = count + sizeof(struct hvsi_header);
53878 memcpy(&packet.data, buf, count);
53879
53880 @@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
53881 struct hvsi_control packet __ALIGNED__;
53882
53883 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
53884 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
53885 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
53886 packet.hdr.len = 6;
53887 packet.verb = VSV_CLOSE_PROTOCOL;
53888
53889 @@ -725,7 +725,7 @@ static int hvsi_open(struct tty_struct *tty, struct file *filp)
53890
53891 tty_port_tty_set(&hp->port, tty);
53892 spin_lock_irqsave(&hp->lock, flags);
53893 - hp->port.count++;
53894 + atomic_inc(&hp->port.count);
53895 atomic_set(&hp->seqno, 0);
53896 h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE);
53897 spin_unlock_irqrestore(&hp->lock, flags);
53898 @@ -782,7 +782,7 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
53899
53900 spin_lock_irqsave(&hp->lock, flags);
53901
53902 - if (--hp->port.count == 0) {
53903 + if (atomic_dec_return(&hp->port.count) == 0) {
53904 tty_port_tty_set(&hp->port, NULL);
53905 hp->inbuf_end = hp->inbuf; /* discard remaining partial packets */
53906
53907 @@ -815,9 +815,9 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
53908
53909 spin_lock_irqsave(&hp->lock, flags);
53910 }
53911 - } else if (hp->port.count < 0)
53912 + } else if (atomic_read(&hp->port.count) < 0)
53913 printk(KERN_ERR "hvsi_close %lu: oops, count is %d\n",
53914 - hp - hvsi_ports, hp->port.count);
53915 + hp - hvsi_ports, atomic_read(&hp->port.count));
53916
53917 spin_unlock_irqrestore(&hp->lock, flags);
53918 }
53919 @@ -832,7 +832,7 @@ static void hvsi_hangup(struct tty_struct *tty)
53920 tty_port_tty_set(&hp->port, NULL);
53921
53922 spin_lock_irqsave(&hp->lock, flags);
53923 - hp->port.count = 0;
53924 + atomic_set(&hp->port.count, 0);
53925 hp->n_outbuf = 0;
53926 spin_unlock_irqrestore(&hp->lock, flags);
53927 }
53928 diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
53929 index 7ae6c29..05c6dba 100644
53930 --- a/drivers/tty/hvc/hvsi_lib.c
53931 +++ b/drivers/tty/hvc/hvsi_lib.c
53932 @@ -8,7 +8,7 @@
53933
53934 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
53935 {
53936 - packet->seqno = cpu_to_be16(atomic_inc_return(&pv->seqno));
53937 + packet->seqno = cpu_to_be16(atomic_inc_return_unchecked(&pv->seqno));
53938
53939 /* Assumes that always succeeds, works in practice */
53940 return pv->put_chars(pv->termno, (char *)packet, packet->len);
53941 @@ -20,7 +20,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
53942
53943 /* Reset state */
53944 pv->established = 0;
53945 - atomic_set(&pv->seqno, 0);
53946 + atomic_set_unchecked(&pv->seqno, 0);
53947
53948 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
53949
53950 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
53951 index 17ee3bf..8d2520d 100644
53952 --- a/drivers/tty/ipwireless/tty.c
53953 +++ b/drivers/tty/ipwireless/tty.c
53954 @@ -28,6 +28,7 @@
53955 #include <linux/tty_driver.h>
53956 #include <linux/tty_flip.h>
53957 #include <linux/uaccess.h>
53958 +#include <asm/local.h>
53959
53960 #include "tty.h"
53961 #include "network.h"
53962 @@ -98,10 +99,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
53963 mutex_unlock(&tty->ipw_tty_mutex);
53964 return -ENODEV;
53965 }
53966 - if (tty->port.count == 0)
53967 + if (atomic_read(&tty->port.count) == 0)
53968 tty->tx_bytes_queued = 0;
53969
53970 - tty->port.count++;
53971 + atomic_inc(&tty->port.count);
53972
53973 tty->port.tty = linux_tty;
53974 linux_tty->driver_data = tty;
53975 @@ -117,9 +118,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
53976
53977 static void do_ipw_close(struct ipw_tty *tty)
53978 {
53979 - tty->port.count--;
53980 -
53981 - if (tty->port.count == 0) {
53982 + if (atomic_dec_return(&tty->port.count) == 0) {
53983 struct tty_struct *linux_tty = tty->port.tty;
53984
53985 if (linux_tty != NULL) {
53986 @@ -140,7 +139,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
53987 return;
53988
53989 mutex_lock(&tty->ipw_tty_mutex);
53990 - if (tty->port.count == 0) {
53991 + if (atomic_read(&tty->port.count) == 0) {
53992 mutex_unlock(&tty->ipw_tty_mutex);
53993 return;
53994 }
53995 @@ -163,7 +162,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
53996
53997 mutex_lock(&tty->ipw_tty_mutex);
53998
53999 - if (!tty->port.count) {
54000 + if (!atomic_read(&tty->port.count)) {
54001 mutex_unlock(&tty->ipw_tty_mutex);
54002 return;
54003 }
54004 @@ -202,7 +201,7 @@ static int ipw_write(struct tty_struct *linux_tty,
54005 return -ENODEV;
54006
54007 mutex_lock(&tty->ipw_tty_mutex);
54008 - if (!tty->port.count) {
54009 + if (!atomic_read(&tty->port.count)) {
54010 mutex_unlock(&tty->ipw_tty_mutex);
54011 return -EINVAL;
54012 }
54013 @@ -242,7 +241,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
54014 if (!tty)
54015 return -ENODEV;
54016
54017 - if (!tty->port.count)
54018 + if (!atomic_read(&tty->port.count))
54019 return -EINVAL;
54020
54021 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
54022 @@ -284,7 +283,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
54023 if (!tty)
54024 return 0;
54025
54026 - if (!tty->port.count)
54027 + if (!atomic_read(&tty->port.count))
54028 return 0;
54029
54030 return tty->tx_bytes_queued;
54031 @@ -365,7 +364,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
54032 if (!tty)
54033 return -ENODEV;
54034
54035 - if (!tty->port.count)
54036 + if (!atomic_read(&tty->port.count))
54037 return -EINVAL;
54038
54039 return get_control_lines(tty);
54040 @@ -381,7 +380,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
54041 if (!tty)
54042 return -ENODEV;
54043
54044 - if (!tty->port.count)
54045 + if (!atomic_read(&tty->port.count))
54046 return -EINVAL;
54047
54048 return set_control_lines(tty, set, clear);
54049 @@ -395,7 +394,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
54050 if (!tty)
54051 return -ENODEV;
54052
54053 - if (!tty->port.count)
54054 + if (!atomic_read(&tty->port.count))
54055 return -EINVAL;
54056
54057 /* FIXME: Exactly how is the tty object locked here .. */
54058 @@ -551,7 +550,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
54059 * are gone */
54060 mutex_lock(&ttyj->ipw_tty_mutex);
54061 }
54062 - while (ttyj->port.count)
54063 + while (atomic_read(&ttyj->port.count))
54064 do_ipw_close(ttyj);
54065 ipwireless_disassociate_network_ttys(network,
54066 ttyj->channel_idx);
54067 diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
54068 index 1deaca4..c8582d4 100644
54069 --- a/drivers/tty/moxa.c
54070 +++ b/drivers/tty/moxa.c
54071 @@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
54072 }
54073
54074 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
54075 - ch->port.count++;
54076 + atomic_inc(&ch->port.count);
54077 tty->driver_data = ch;
54078 tty_port_tty_set(&ch->port, tty);
54079 mutex_lock(&ch->port.mutex);
54080 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
54081 index 2ebe47b..3205833 100644
54082 --- a/drivers/tty/n_gsm.c
54083 +++ b/drivers/tty/n_gsm.c
54084 @@ -1644,7 +1644,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
54085 spin_lock_init(&dlci->lock);
54086 mutex_init(&dlci->mutex);
54087 dlci->fifo = &dlci->_fifo;
54088 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
54089 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
54090 kfree(dlci);
54091 return NULL;
54092 }
54093 @@ -2954,7 +2954,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
54094 struct gsm_dlci *dlci = tty->driver_data;
54095 struct tty_port *port = &dlci->port;
54096
54097 - port->count++;
54098 + atomic_inc(&port->count);
54099 tty_port_tty_set(port, tty);
54100
54101 dlci->modem_rx = 0;
54102 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
54103 index f44f1ba..a8d5915 100644
54104 --- a/drivers/tty/n_tty.c
54105 +++ b/drivers/tty/n_tty.c
54106 @@ -115,7 +115,7 @@ struct n_tty_data {
54107 int minimum_to_wake;
54108
54109 /* consumer-published */
54110 - size_t read_tail;
54111 + size_t read_tail __intentional_overflow(-1);
54112 size_t line_start;
54113
54114 /* protected by output lock */
54115 @@ -2517,6 +2517,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
54116 {
54117 *ops = tty_ldisc_N_TTY;
54118 ops->owner = NULL;
54119 - ops->refcount = ops->flags = 0;
54120 + atomic_set(&ops->refcount, 0);
54121 + ops->flags = 0;
54122 }
54123 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
54124 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
54125 index 25c9bc7..24077b7 100644
54126 --- a/drivers/tty/pty.c
54127 +++ b/drivers/tty/pty.c
54128 @@ -790,8 +790,10 @@ static void __init unix98_pty_init(void)
54129 panic("Couldn't register Unix98 pts driver");
54130
54131 /* Now create the /dev/ptmx special device */
54132 + pax_open_kernel();
54133 tty_default_fops(&ptmx_fops);
54134 - ptmx_fops.open = ptmx_open;
54135 + *(void **)&ptmx_fops.open = ptmx_open;
54136 + pax_close_kernel();
54137
54138 cdev_init(&ptmx_cdev, &ptmx_fops);
54139 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
54140 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
54141 index 383c4c7..d408e21 100644
54142 --- a/drivers/tty/rocket.c
54143 +++ b/drivers/tty/rocket.c
54144 @@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
54145 tty->driver_data = info;
54146 tty_port_tty_set(port, tty);
54147
54148 - if (port->count++ == 0) {
54149 + if (atomic_inc_return(&port->count) == 1) {
54150 atomic_inc(&rp_num_ports_open);
54151
54152 #ifdef ROCKET_DEBUG_OPEN
54153 @@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
54154 #endif
54155 }
54156 #ifdef ROCKET_DEBUG_OPEN
54157 - printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
54158 + printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
54159 #endif
54160
54161 /*
54162 @@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
54163 spin_unlock_irqrestore(&info->port.lock, flags);
54164 return;
54165 }
54166 - if (info->port.count)
54167 + if (atomic_read(&info->port.count))
54168 atomic_dec(&rp_num_ports_open);
54169 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
54170 spin_unlock_irqrestore(&info->port.lock, flags);
54171 diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
54172 index 1274499..f541382 100644
54173 --- a/drivers/tty/serial/ioc4_serial.c
54174 +++ b/drivers/tty/serial/ioc4_serial.c
54175 @@ -437,7 +437,7 @@ struct ioc4_soft {
54176 } is_intr_info[MAX_IOC4_INTR_ENTS];
54177
54178 /* Number of entries active in the above array */
54179 - atomic_t is_num_intrs;
54180 + atomic_unchecked_t is_num_intrs;
54181 } is_intr_type[IOC4_NUM_INTR_TYPES];
54182
54183 /* is_ir_lock must be held while
54184 @@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
54185 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
54186 || (type == IOC4_OTHER_INTR_TYPE)));
54187
54188 - i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
54189 + i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
54190 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
54191
54192 /* Save off the lower level interrupt handler */
54193 @@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
54194
54195 soft = arg;
54196 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
54197 - num_intrs = (int)atomic_read(
54198 + num_intrs = (int)atomic_read_unchecked(
54199 &soft->is_intr_type[intr_type].is_num_intrs);
54200
54201 this_mir = this_ir = pending_intrs(soft, intr_type);
54202 diff --git a/drivers/tty/serial/kgdb_nmi.c b/drivers/tty/serial/kgdb_nmi.c
54203 index cfadf29..8cf4595 100644
54204 --- a/drivers/tty/serial/kgdb_nmi.c
54205 +++ b/drivers/tty/serial/kgdb_nmi.c
54206 @@ -51,7 +51,9 @@ static int kgdb_nmi_console_setup(struct console *co, char *options)
54207 * I/O utilities that messages sent to the console will automatically
54208 * be displayed on the dbg_io.
54209 */
54210 - dbg_io_ops->is_console = true;
54211 + pax_open_kernel();
54212 + *(int *)&dbg_io_ops->is_console = true;
54213 + pax_close_kernel();
54214
54215 return 0;
54216 }
54217 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
54218 index a260cde..6b2b5ce 100644
54219 --- a/drivers/tty/serial/kgdboc.c
54220 +++ b/drivers/tty/serial/kgdboc.c
54221 @@ -24,8 +24,9 @@
54222 #define MAX_CONFIG_LEN 40
54223
54224 static struct kgdb_io kgdboc_io_ops;
54225 +static struct kgdb_io kgdboc_io_ops_console;
54226
54227 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
54228 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
54229 static int configured = -1;
54230
54231 static char config[MAX_CONFIG_LEN];
54232 @@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
54233 kgdboc_unregister_kbd();
54234 if (configured == 1)
54235 kgdb_unregister_io_module(&kgdboc_io_ops);
54236 + else if (configured == 2)
54237 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
54238 }
54239
54240 static int configure_kgdboc(void)
54241 @@ -160,13 +163,13 @@ static int configure_kgdboc(void)
54242 int err;
54243 char *cptr = config;
54244 struct console *cons;
54245 + int is_console = 0;
54246
54247 err = kgdboc_option_setup(config);
54248 if (err || !strlen(config) || isspace(config[0]))
54249 goto noconfig;
54250
54251 err = -ENODEV;
54252 - kgdboc_io_ops.is_console = 0;
54253 kgdb_tty_driver = NULL;
54254
54255 kgdboc_use_kms = 0;
54256 @@ -187,7 +190,7 @@ static int configure_kgdboc(void)
54257 int idx;
54258 if (cons->device && cons->device(cons, &idx) == p &&
54259 idx == tty_line) {
54260 - kgdboc_io_ops.is_console = 1;
54261 + is_console = 1;
54262 break;
54263 }
54264 cons = cons->next;
54265 @@ -197,7 +200,13 @@ static int configure_kgdboc(void)
54266 kgdb_tty_line = tty_line;
54267
54268 do_register:
54269 - err = kgdb_register_io_module(&kgdboc_io_ops);
54270 + if (is_console) {
54271 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
54272 + configured = 2;
54273 + } else {
54274 + err = kgdb_register_io_module(&kgdboc_io_ops);
54275 + configured = 1;
54276 + }
54277 if (err)
54278 goto noconfig;
54279
54280 @@ -205,8 +214,6 @@ do_register:
54281 if (err)
54282 goto nmi_con_failed;
54283
54284 - configured = 1;
54285 -
54286 return 0;
54287
54288 nmi_con_failed:
54289 @@ -223,7 +230,7 @@ noconfig:
54290 static int __init init_kgdboc(void)
54291 {
54292 /* Already configured? */
54293 - if (configured == 1)
54294 + if (configured >= 1)
54295 return 0;
54296
54297 return configure_kgdboc();
54298 @@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
54299 if (config[len - 1] == '\n')
54300 config[len - 1] = '\0';
54301
54302 - if (configured == 1)
54303 + if (configured >= 1)
54304 cleanup_kgdboc();
54305
54306 /* Go and configure with the new params. */
54307 @@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
54308 .post_exception = kgdboc_post_exp_handler,
54309 };
54310
54311 +static struct kgdb_io kgdboc_io_ops_console = {
54312 + .name = "kgdboc",
54313 + .read_char = kgdboc_get_char,
54314 + .write_char = kgdboc_put_char,
54315 + .pre_exception = kgdboc_pre_exp_handler,
54316 + .post_exception = kgdboc_post_exp_handler,
54317 + .is_console = 1
54318 +};
54319 +
54320 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
54321 /* This is only available if kgdboc is a built in for early debugging */
54322 static int __init kgdboc_early_init(char *opt)
54323 diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
54324 index 72000a6..a190bc4 100644
54325 --- a/drivers/tty/serial/msm_serial.c
54326 +++ b/drivers/tty/serial/msm_serial.c
54327 @@ -981,7 +981,7 @@ static struct uart_driver msm_uart_driver = {
54328 .cons = MSM_CONSOLE,
54329 };
54330
54331 -static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
54332 +static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
54333
54334 static const struct of_device_id msm_uartdm_table[] = {
54335 { .compatible = "qcom,msm-uartdm-v1.1", .data = (void *)UARTDM_1P1 },
54336 @@ -1000,7 +1000,7 @@ static int msm_serial_probe(struct platform_device *pdev)
54337 int irq;
54338
54339 if (pdev->id == -1)
54340 - pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
54341 + pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
54342
54343 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
54344 return -ENXIO;
54345 diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
54346 index c1d3ebd..f618a93 100644
54347 --- a/drivers/tty/serial/samsung.c
54348 +++ b/drivers/tty/serial/samsung.c
54349 @@ -486,11 +486,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
54350 }
54351 }
54352
54353 +static int s3c64xx_serial_startup(struct uart_port *port);
54354 static int s3c24xx_serial_startup(struct uart_port *port)
54355 {
54356 struct s3c24xx_uart_port *ourport = to_ourport(port);
54357 int ret;
54358
54359 + /* Startup sequence is different for s3c64xx and higher SoC's */
54360 + if (s3c24xx_serial_has_interrupt_mask(port))
54361 + return s3c64xx_serial_startup(port);
54362 +
54363 dbg("s3c24xx_serial_startup: port=%p (%08llx,%p)\n",
54364 port, (unsigned long long)port->mapbase, port->membase);
54365
54366 @@ -1164,10 +1169,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
54367 /* setup info for port */
54368 port->dev = &platdev->dev;
54369
54370 - /* Startup sequence is different for s3c64xx and higher SoC's */
54371 - if (s3c24xx_serial_has_interrupt_mask(port))
54372 - s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
54373 -
54374 port->uartclk = 1;
54375
54376 if (cfg->uart_flags & UPF_CONS_FLOW) {
54377 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
54378 index fbf6c5a..3939d92 100644
54379 --- a/drivers/tty/serial/serial_core.c
54380 +++ b/drivers/tty/serial/serial_core.c
54381 @@ -1333,7 +1333,7 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
54382
54383 pr_debug("uart_close(%d) called\n", uport ? uport->line : -1);
54384
54385 - if (!port->count || tty_port_close_start(port, tty, filp) == 0)
54386 + if (!atomic_read(&port->count) || tty_port_close_start(port, tty, filp) == 0)
54387 return;
54388
54389 /*
54390 @@ -1460,7 +1460,7 @@ static void uart_hangup(struct tty_struct *tty)
54391 uart_flush_buffer(tty);
54392 uart_shutdown(tty, state);
54393 spin_lock_irqsave(&port->lock, flags);
54394 - port->count = 0;
54395 + atomic_set(&port->count, 0);
54396 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
54397 spin_unlock_irqrestore(&port->lock, flags);
54398 tty_port_tty_set(port, NULL);
54399 @@ -1558,7 +1558,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
54400 goto end;
54401 }
54402
54403 - port->count++;
54404 + atomic_inc(&port->count);
54405 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
54406 retval = -ENXIO;
54407 goto err_dec_count;
54408 @@ -1598,7 +1598,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
54409 end:
54410 return retval;
54411 err_dec_count:
54412 - port->count--;
54413 + atomic_inc(&port->count);
54414 mutex_unlock(&port->mutex);
54415 goto end;
54416 }
54417 diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
54418 index d48e040..0f52764 100644
54419 --- a/drivers/tty/synclink.c
54420 +++ b/drivers/tty/synclink.c
54421 @@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
54422
54423 if (debug_level >= DEBUG_LEVEL_INFO)
54424 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
54425 - __FILE__,__LINE__, info->device_name, info->port.count);
54426 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
54427
54428 if (tty_port_close_start(&info->port, tty, filp) == 0)
54429 goto cleanup;
54430 @@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
54431 cleanup:
54432 if (debug_level >= DEBUG_LEVEL_INFO)
54433 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
54434 - tty->driver->name, info->port.count);
54435 + tty->driver->name, atomic_read(&info->port.count));
54436
54437 } /* end of mgsl_close() */
54438
54439 @@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
54440
54441 mgsl_flush_buffer(tty);
54442 shutdown(info);
54443 -
54444 - info->port.count = 0;
54445 +
54446 + atomic_set(&info->port.count, 0);
54447 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
54448 info->port.tty = NULL;
54449
54450 @@ -3297,12 +3297,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
54451
54452 if (debug_level >= DEBUG_LEVEL_INFO)
54453 printk("%s(%d):block_til_ready before block on %s count=%d\n",
54454 - __FILE__,__LINE__, tty->driver->name, port->count );
54455 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
54456
54457 spin_lock_irqsave(&info->irq_spinlock, flags);
54458 if (!tty_hung_up_p(filp)) {
54459 extra_count = true;
54460 - port->count--;
54461 + atomic_dec(&port->count);
54462 }
54463 spin_unlock_irqrestore(&info->irq_spinlock, flags);
54464 port->blocked_open++;
54465 @@ -3331,7 +3331,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
54466
54467 if (debug_level >= DEBUG_LEVEL_INFO)
54468 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
54469 - __FILE__,__LINE__, tty->driver->name, port->count );
54470 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
54471
54472 tty_unlock(tty);
54473 schedule();
54474 @@ -3343,12 +3343,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
54475
54476 /* FIXME: Racy on hangup during close wait */
54477 if (extra_count)
54478 - port->count++;
54479 + atomic_inc(&port->count);
54480 port->blocked_open--;
54481
54482 if (debug_level >= DEBUG_LEVEL_INFO)
54483 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
54484 - __FILE__,__LINE__, tty->driver->name, port->count );
54485 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
54486
54487 if (!retval)
54488 port->flags |= ASYNC_NORMAL_ACTIVE;
54489 @@ -3400,7 +3400,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
54490
54491 if (debug_level >= DEBUG_LEVEL_INFO)
54492 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
54493 - __FILE__,__LINE__,tty->driver->name, info->port.count);
54494 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
54495
54496 /* If port is closing, signal caller to try again */
54497 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
54498 @@ -3419,10 +3419,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
54499 spin_unlock_irqrestore(&info->netlock, flags);
54500 goto cleanup;
54501 }
54502 - info->port.count++;
54503 + atomic_inc(&info->port.count);
54504 spin_unlock_irqrestore(&info->netlock, flags);
54505
54506 - if (info->port.count == 1) {
54507 + if (atomic_read(&info->port.count) == 1) {
54508 /* 1st open on this device, init hardware */
54509 retval = startup(info);
54510 if (retval < 0)
54511 @@ -3446,8 +3446,8 @@ cleanup:
54512 if (retval) {
54513 if (tty->count == 1)
54514 info->port.tty = NULL; /* tty layer will release tty struct */
54515 - if(info->port.count)
54516 - info->port.count--;
54517 + if (atomic_read(&info->port.count))
54518 + atomic_dec(&info->port.count);
54519 }
54520
54521 return retval;
54522 @@ -7665,7 +7665,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
54523 unsigned short new_crctype;
54524
54525 /* return error if TTY interface open */
54526 - if (info->port.count)
54527 + if (atomic_read(&info->port.count))
54528 return -EBUSY;
54529
54530 switch (encoding)
54531 @@ -7760,7 +7760,7 @@ static int hdlcdev_open(struct net_device *dev)
54532
54533 /* arbitrate between network and tty opens */
54534 spin_lock_irqsave(&info->netlock, flags);
54535 - if (info->port.count != 0 || info->netcount != 0) {
54536 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
54537 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
54538 spin_unlock_irqrestore(&info->netlock, flags);
54539 return -EBUSY;
54540 @@ -7846,7 +7846,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
54541 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
54542
54543 /* return error if TTY interface open */
54544 - if (info->port.count)
54545 + if (atomic_read(&info->port.count))
54546 return -EBUSY;
54547
54548 if (cmd != SIOCWANDEV)
54549 diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
54550 index c359a91..959fc26 100644
54551 --- a/drivers/tty/synclink_gt.c
54552 +++ b/drivers/tty/synclink_gt.c
54553 @@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
54554 tty->driver_data = info;
54555 info->port.tty = tty;
54556
54557 - DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
54558 + DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
54559
54560 /* If port is closing, signal caller to try again */
54561 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
54562 @@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
54563 mutex_unlock(&info->port.mutex);
54564 goto cleanup;
54565 }
54566 - info->port.count++;
54567 + atomic_inc(&info->port.count);
54568 spin_unlock_irqrestore(&info->netlock, flags);
54569
54570 - if (info->port.count == 1) {
54571 + if (atomic_read(&info->port.count) == 1) {
54572 /* 1st open on this device, init hardware */
54573 retval = startup(info);
54574 if (retval < 0) {
54575 @@ -715,8 +715,8 @@ cleanup:
54576 if (retval) {
54577 if (tty->count == 1)
54578 info->port.tty = NULL; /* tty layer will release tty struct */
54579 - if(info->port.count)
54580 - info->port.count--;
54581 + if(atomic_read(&info->port.count))
54582 + atomic_dec(&info->port.count);
54583 }
54584
54585 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
54586 @@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
54587
54588 if (sanity_check(info, tty->name, "close"))
54589 return;
54590 - DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
54591 + DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
54592
54593 if (tty_port_close_start(&info->port, tty, filp) == 0)
54594 goto cleanup;
54595 @@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
54596 tty_port_close_end(&info->port, tty);
54597 info->port.tty = NULL;
54598 cleanup:
54599 - DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
54600 + DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
54601 }
54602
54603 static void hangup(struct tty_struct *tty)
54604 @@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
54605 shutdown(info);
54606
54607 spin_lock_irqsave(&info->port.lock, flags);
54608 - info->port.count = 0;
54609 + atomic_set(&info->port.count, 0);
54610 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
54611 info->port.tty = NULL;
54612 spin_unlock_irqrestore(&info->port.lock, flags);
54613 @@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
54614 unsigned short new_crctype;
54615
54616 /* return error if TTY interface open */
54617 - if (info->port.count)
54618 + if (atomic_read(&info->port.count))
54619 return -EBUSY;
54620
54621 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
54622 @@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
54623
54624 /* arbitrate between network and tty opens */
54625 spin_lock_irqsave(&info->netlock, flags);
54626 - if (info->port.count != 0 || info->netcount != 0) {
54627 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
54628 DBGINFO(("%s hdlc_open busy\n", dev->name));
54629 spin_unlock_irqrestore(&info->netlock, flags);
54630 return -EBUSY;
54631 @@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
54632 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
54633
54634 /* return error if TTY interface open */
54635 - if (info->port.count)
54636 + if (atomic_read(&info->port.count))
54637 return -EBUSY;
54638
54639 if (cmd != SIOCWANDEV)
54640 @@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
54641 if (port == NULL)
54642 continue;
54643 spin_lock(&port->lock);
54644 - if ((port->port.count || port->netcount) &&
54645 + if ((atomic_read(&port->port.count) || port->netcount) &&
54646 port->pending_bh && !port->bh_running &&
54647 !port->bh_requested) {
54648 DBGISR(("%s bh queued\n", port->device_name));
54649 @@ -3302,7 +3302,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
54650 spin_lock_irqsave(&info->lock, flags);
54651 if (!tty_hung_up_p(filp)) {
54652 extra_count = true;
54653 - port->count--;
54654 + atomic_dec(&port->count);
54655 }
54656 spin_unlock_irqrestore(&info->lock, flags);
54657 port->blocked_open++;
54658 @@ -3339,7 +3339,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
54659 remove_wait_queue(&port->open_wait, &wait);
54660
54661 if (extra_count)
54662 - port->count++;
54663 + atomic_inc(&port->count);
54664 port->blocked_open--;
54665
54666 if (!retval)
54667 diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
54668 index 53ba853..3c30f6d 100644
54669 --- a/drivers/tty/synclinkmp.c
54670 +++ b/drivers/tty/synclinkmp.c
54671 @@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
54672
54673 if (debug_level >= DEBUG_LEVEL_INFO)
54674 printk("%s(%d):%s open(), old ref count = %d\n",
54675 - __FILE__,__LINE__,tty->driver->name, info->port.count);
54676 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
54677
54678 /* If port is closing, signal caller to try again */
54679 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
54680 @@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
54681 spin_unlock_irqrestore(&info->netlock, flags);
54682 goto cleanup;
54683 }
54684 - info->port.count++;
54685 + atomic_inc(&info->port.count);
54686 spin_unlock_irqrestore(&info->netlock, flags);
54687
54688 - if (info->port.count == 1) {
54689 + if (atomic_read(&info->port.count) == 1) {
54690 /* 1st open on this device, init hardware */
54691 retval = startup(info);
54692 if (retval < 0)
54693 @@ -796,8 +796,8 @@ cleanup:
54694 if (retval) {
54695 if (tty->count == 1)
54696 info->port.tty = NULL; /* tty layer will release tty struct */
54697 - if(info->port.count)
54698 - info->port.count--;
54699 + if(atomic_read(&info->port.count))
54700 + atomic_dec(&info->port.count);
54701 }
54702
54703 return retval;
54704 @@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
54705
54706 if (debug_level >= DEBUG_LEVEL_INFO)
54707 printk("%s(%d):%s close() entry, count=%d\n",
54708 - __FILE__,__LINE__, info->device_name, info->port.count);
54709 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
54710
54711 if (tty_port_close_start(&info->port, tty, filp) == 0)
54712 goto cleanup;
54713 @@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
54714 cleanup:
54715 if (debug_level >= DEBUG_LEVEL_INFO)
54716 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
54717 - tty->driver->name, info->port.count);
54718 + tty->driver->name, atomic_read(&info->port.count));
54719 }
54720
54721 /* Called by tty_hangup() when a hangup is signaled.
54722 @@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
54723 shutdown(info);
54724
54725 spin_lock_irqsave(&info->port.lock, flags);
54726 - info->port.count = 0;
54727 + atomic_set(&info->port.count, 0);
54728 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
54729 info->port.tty = NULL;
54730 spin_unlock_irqrestore(&info->port.lock, flags);
54731 @@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
54732 unsigned short new_crctype;
54733
54734 /* return error if TTY interface open */
54735 - if (info->port.count)
54736 + if (atomic_read(&info->port.count))
54737 return -EBUSY;
54738
54739 switch (encoding)
54740 @@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
54741
54742 /* arbitrate between network and tty opens */
54743 spin_lock_irqsave(&info->netlock, flags);
54744 - if (info->port.count != 0 || info->netcount != 0) {
54745 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
54746 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
54747 spin_unlock_irqrestore(&info->netlock, flags);
54748 return -EBUSY;
54749 @@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
54750 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
54751
54752 /* return error if TTY interface open */
54753 - if (info->port.count)
54754 + if (atomic_read(&info->port.count))
54755 return -EBUSY;
54756
54757 if (cmd != SIOCWANDEV)
54758 @@ -2621,7 +2621,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
54759 * do not request bottom half processing if the
54760 * device is not open in a normal mode.
54761 */
54762 - if ( port && (port->port.count || port->netcount) &&
54763 + if ( port && (atomic_read(&port->port.count) || port->netcount) &&
54764 port->pending_bh && !port->bh_running &&
54765 !port->bh_requested ) {
54766 if ( debug_level >= DEBUG_LEVEL_ISR )
54767 @@ -3319,12 +3319,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
54768
54769 if (debug_level >= DEBUG_LEVEL_INFO)
54770 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
54771 - __FILE__,__LINE__, tty->driver->name, port->count );
54772 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
54773
54774 spin_lock_irqsave(&info->lock, flags);
54775 if (!tty_hung_up_p(filp)) {
54776 extra_count = true;
54777 - port->count--;
54778 + atomic_dec(&port->count);
54779 }
54780 spin_unlock_irqrestore(&info->lock, flags);
54781 port->blocked_open++;
54782 @@ -3353,7 +3353,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
54783
54784 if (debug_level >= DEBUG_LEVEL_INFO)
54785 printk("%s(%d):%s block_til_ready() count=%d\n",
54786 - __FILE__,__LINE__, tty->driver->name, port->count );
54787 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
54788
54789 tty_unlock(tty);
54790 schedule();
54791 @@ -3364,12 +3364,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
54792 remove_wait_queue(&port->open_wait, &wait);
54793
54794 if (extra_count)
54795 - port->count++;
54796 + atomic_inc(&port->count);
54797 port->blocked_open--;
54798
54799 if (debug_level >= DEBUG_LEVEL_INFO)
54800 printk("%s(%d):%s block_til_ready() after, count=%d\n",
54801 - __FILE__,__LINE__, tty->driver->name, port->count );
54802 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
54803
54804 if (!retval)
54805 port->flags |= ASYNC_NORMAL_ACTIVE;
54806 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
54807 index 454b658..57b1430 100644
54808 --- a/drivers/tty/sysrq.c
54809 +++ b/drivers/tty/sysrq.c
54810 @@ -1084,7 +1084,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
54811 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
54812 size_t count, loff_t *ppos)
54813 {
54814 - if (count) {
54815 + if (count && capable(CAP_SYS_ADMIN)) {
54816 char c;
54817
54818 if (get_user(c, buf))
54819 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
54820 index 3411071..86f2cf2 100644
54821 --- a/drivers/tty/tty_io.c
54822 +++ b/drivers/tty/tty_io.c
54823 @@ -3475,7 +3475,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
54824
54825 void tty_default_fops(struct file_operations *fops)
54826 {
54827 - *fops = tty_fops;
54828 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
54829 }
54830
54831 /*
54832 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
54833 index 2d822aa..a566234 100644
54834 --- a/drivers/tty/tty_ldisc.c
54835 +++ b/drivers/tty/tty_ldisc.c
54836 @@ -71,7 +71,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
54837 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
54838 tty_ldiscs[disc] = new_ldisc;
54839 new_ldisc->num = disc;
54840 - new_ldisc->refcount = 0;
54841 + atomic_set(&new_ldisc->refcount, 0);
54842 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
54843
54844 return ret;
54845 @@ -99,7 +99,7 @@ int tty_unregister_ldisc(int disc)
54846 return -EINVAL;
54847
54848 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
54849 - if (tty_ldiscs[disc]->refcount)
54850 + if (atomic_read(&tty_ldiscs[disc]->refcount))
54851 ret = -EBUSY;
54852 else
54853 tty_ldiscs[disc] = NULL;
54854 @@ -120,7 +120,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
54855 if (ldops) {
54856 ret = ERR_PTR(-EAGAIN);
54857 if (try_module_get(ldops->owner)) {
54858 - ldops->refcount++;
54859 + atomic_inc(&ldops->refcount);
54860 ret = ldops;
54861 }
54862 }
54863 @@ -133,7 +133,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
54864 unsigned long flags;
54865
54866 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
54867 - ldops->refcount--;
54868 + atomic_dec(&ldops->refcount);
54869 module_put(ldops->owner);
54870 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
54871 }
54872 diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
54873 index 3f746c8..2f2fcaa 100644
54874 --- a/drivers/tty/tty_port.c
54875 +++ b/drivers/tty/tty_port.c
54876 @@ -235,7 +235,7 @@ void tty_port_hangup(struct tty_port *port)
54877 unsigned long flags;
54878
54879 spin_lock_irqsave(&port->lock, flags);
54880 - port->count = 0;
54881 + atomic_set(&port->count, 0);
54882 port->flags &= ~ASYNC_NORMAL_ACTIVE;
54883 tty = port->tty;
54884 if (tty)
54885 @@ -393,7 +393,7 @@ int tty_port_block_til_ready(struct tty_port *port,
54886 /* The port lock protects the port counts */
54887 spin_lock_irqsave(&port->lock, flags);
54888 if (!tty_hung_up_p(filp))
54889 - port->count--;
54890 + atomic_dec(&port->count);
54891 port->blocked_open++;
54892 spin_unlock_irqrestore(&port->lock, flags);
54893
54894 @@ -435,7 +435,7 @@ int tty_port_block_til_ready(struct tty_port *port,
54895 we must not mess that up further */
54896 spin_lock_irqsave(&port->lock, flags);
54897 if (!tty_hung_up_p(filp))
54898 - port->count++;
54899 + atomic_inc(&port->count);
54900 port->blocked_open--;
54901 if (retval == 0)
54902 port->flags |= ASYNC_NORMAL_ACTIVE;
54903 @@ -469,19 +469,19 @@ int tty_port_close_start(struct tty_port *port,
54904 return 0;
54905 }
54906
54907 - if (tty->count == 1 && port->count != 1) {
54908 + if (tty->count == 1 && atomic_read(&port->count) != 1) {
54909 printk(KERN_WARNING
54910 "tty_port_close_start: tty->count = 1 port count = %d.\n",
54911 - port->count);
54912 - port->count = 1;
54913 + atomic_read(&port->count));
54914 + atomic_set(&port->count, 1);
54915 }
54916 - if (--port->count < 0) {
54917 + if (atomic_dec_return(&port->count) < 0) {
54918 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
54919 - port->count);
54920 - port->count = 0;
54921 + atomic_read(&port->count));
54922 + atomic_set(&port->count, 0);
54923 }
54924
54925 - if (port->count) {
54926 + if (atomic_read(&port->count)) {
54927 spin_unlock_irqrestore(&port->lock, flags);
54928 return 0;
54929 }
54930 @@ -563,7 +563,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
54931 {
54932 spin_lock_irq(&port->lock);
54933 if (!tty_hung_up_p(filp))
54934 - ++port->count;
54935 + atomic_inc(&port->count);
54936 spin_unlock_irq(&port->lock);
54937 tty_port_tty_set(port, tty);
54938
54939 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
54940 index d0e3a44..5f8b754 100644
54941 --- a/drivers/tty/vt/keyboard.c
54942 +++ b/drivers/tty/vt/keyboard.c
54943 @@ -641,6 +641,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
54944 kbd->kbdmode == VC_OFF) &&
54945 value != KVAL(K_SAK))
54946 return; /* SAK is allowed even in raw mode */
54947 +
54948 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
54949 + {
54950 + void *func = fn_handler[value];
54951 + if (func == fn_show_state || func == fn_show_ptregs ||
54952 + func == fn_show_mem)
54953 + return;
54954 + }
54955 +#endif
54956 +
54957 fn_handler[value](vc);
54958 }
54959
54960 @@ -1776,9 +1786,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
54961 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
54962 return -EFAULT;
54963
54964 - if (!capable(CAP_SYS_TTY_CONFIG))
54965 - perm = 0;
54966 -
54967 switch (cmd) {
54968 case KDGKBENT:
54969 /* Ensure another thread doesn't free it under us */
54970 @@ -1793,6 +1800,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
54971 spin_unlock_irqrestore(&kbd_event_lock, flags);
54972 return put_user(val, &user_kbe->kb_value);
54973 case KDSKBENT:
54974 + if (!capable(CAP_SYS_TTY_CONFIG))
54975 + perm = 0;
54976 +
54977 if (!perm)
54978 return -EPERM;
54979 if (!i && v == K_NOSUCHMAP) {
54980 @@ -1883,9 +1893,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
54981 int i, j, k;
54982 int ret;
54983
54984 - if (!capable(CAP_SYS_TTY_CONFIG))
54985 - perm = 0;
54986 -
54987 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
54988 if (!kbs) {
54989 ret = -ENOMEM;
54990 @@ -1919,6 +1926,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
54991 kfree(kbs);
54992 return ((p && *p) ? -EOVERFLOW : 0);
54993 case KDSKBSENT:
54994 + if (!capable(CAP_SYS_TTY_CONFIG))
54995 + perm = 0;
54996 +
54997 if (!perm) {
54998 ret = -EPERM;
54999 goto reterr;
55000 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
55001 index a673e5b..36e5d32 100644
55002 --- a/drivers/uio/uio.c
55003 +++ b/drivers/uio/uio.c
55004 @@ -25,6 +25,7 @@
55005 #include <linux/kobject.h>
55006 #include <linux/cdev.h>
55007 #include <linux/uio_driver.h>
55008 +#include <asm/local.h>
55009
55010 #define UIO_MAX_DEVICES (1U << MINORBITS)
55011
55012 @@ -32,7 +33,7 @@ struct uio_device {
55013 struct module *owner;
55014 struct device *dev;
55015 int minor;
55016 - atomic_t event;
55017 + atomic_unchecked_t event;
55018 struct fasync_struct *async_queue;
55019 wait_queue_head_t wait;
55020 struct uio_info *info;
55021 @@ -243,7 +244,7 @@ static ssize_t event_show(struct device *dev,
55022 struct device_attribute *attr, char *buf)
55023 {
55024 struct uio_device *idev = dev_get_drvdata(dev);
55025 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
55026 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
55027 }
55028 static DEVICE_ATTR_RO(event);
55029
55030 @@ -405,7 +406,7 @@ void uio_event_notify(struct uio_info *info)
55031 {
55032 struct uio_device *idev = info->uio_dev;
55033
55034 - atomic_inc(&idev->event);
55035 + atomic_inc_unchecked(&idev->event);
55036 wake_up_interruptible(&idev->wait);
55037 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
55038 }
55039 @@ -458,7 +459,7 @@ static int uio_open(struct inode *inode, struct file *filep)
55040 }
55041
55042 listener->dev = idev;
55043 - listener->event_count = atomic_read(&idev->event);
55044 + listener->event_count = atomic_read_unchecked(&idev->event);
55045 filep->private_data = listener;
55046
55047 if (idev->info->open) {
55048 @@ -509,7 +510,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
55049 return -EIO;
55050
55051 poll_wait(filep, &idev->wait, wait);
55052 - if (listener->event_count != atomic_read(&idev->event))
55053 + if (listener->event_count != atomic_read_unchecked(&idev->event))
55054 return POLLIN | POLLRDNORM;
55055 return 0;
55056 }
55057 @@ -534,7 +535,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
55058 do {
55059 set_current_state(TASK_INTERRUPTIBLE);
55060
55061 - event_count = atomic_read(&idev->event);
55062 + event_count = atomic_read_unchecked(&idev->event);
55063 if (event_count != listener->event_count) {
55064 if (copy_to_user(buf, &event_count, count))
55065 retval = -EFAULT;
55066 @@ -591,9 +592,13 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,
55067 static int uio_find_mem_index(struct vm_area_struct *vma)
55068 {
55069 struct uio_device *idev = vma->vm_private_data;
55070 + unsigned long size;
55071
55072 if (vma->vm_pgoff < MAX_UIO_MAPS) {
55073 - if (idev->info->mem[vma->vm_pgoff].size == 0)
55074 + size = idev->info->mem[vma->vm_pgoff].size;
55075 + if (size == 0)
55076 + return -1;
55077 + if (vma->vm_end - vma->vm_start > size)
55078 return -1;
55079 return (int)vma->vm_pgoff;
55080 }
55081 @@ -825,7 +830,7 @@ int __uio_register_device(struct module *owner,
55082 idev->owner = owner;
55083 idev->info = info;
55084 init_waitqueue_head(&idev->wait);
55085 - atomic_set(&idev->event, 0);
55086 + atomic_set_unchecked(&idev->event, 0);
55087
55088 ret = uio_get_minor(idev);
55089 if (ret)
55090 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
55091 index 813d4d3..a71934f 100644
55092 --- a/drivers/usb/atm/cxacru.c
55093 +++ b/drivers/usb/atm/cxacru.c
55094 @@ -472,7 +472,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
55095 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
55096 if (ret < 2)
55097 return -EINVAL;
55098 - if (index < 0 || index > 0x7f)
55099 + if (index > 0x7f)
55100 return -EINVAL;
55101 pos += tmp;
55102
55103 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
55104 index dada014..1d0d517 100644
55105 --- a/drivers/usb/atm/usbatm.c
55106 +++ b/drivers/usb/atm/usbatm.c
55107 @@ -331,7 +331,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
55108 if (printk_ratelimit())
55109 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
55110 __func__, vpi, vci);
55111 - atomic_inc(&vcc->stats->rx_err);
55112 + atomic_inc_unchecked(&vcc->stats->rx_err);
55113 return;
55114 }
55115
55116 @@ -358,7 +358,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
55117 if (length > ATM_MAX_AAL5_PDU) {
55118 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
55119 __func__, length, vcc);
55120 - atomic_inc(&vcc->stats->rx_err);
55121 + atomic_inc_unchecked(&vcc->stats->rx_err);
55122 goto out;
55123 }
55124
55125 @@ -367,14 +367,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
55126 if (sarb->len < pdu_length) {
55127 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
55128 __func__, pdu_length, sarb->len, vcc);
55129 - atomic_inc(&vcc->stats->rx_err);
55130 + atomic_inc_unchecked(&vcc->stats->rx_err);
55131 goto out;
55132 }
55133
55134 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
55135 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
55136 __func__, vcc);
55137 - atomic_inc(&vcc->stats->rx_err);
55138 + atomic_inc_unchecked(&vcc->stats->rx_err);
55139 goto out;
55140 }
55141
55142 @@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
55143 if (printk_ratelimit())
55144 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
55145 __func__, length);
55146 - atomic_inc(&vcc->stats->rx_drop);
55147 + atomic_inc_unchecked(&vcc->stats->rx_drop);
55148 goto out;
55149 }
55150
55151 @@ -414,7 +414,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
55152
55153 vcc->push(vcc, skb);
55154
55155 - atomic_inc(&vcc->stats->rx);
55156 + atomic_inc_unchecked(&vcc->stats->rx);
55157 out:
55158 skb_trim(sarb, 0);
55159 }
55160 @@ -612,7 +612,7 @@ static void usbatm_tx_process(unsigned long data)
55161 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
55162
55163 usbatm_pop(vcc, skb);
55164 - atomic_inc(&vcc->stats->tx);
55165 + atomic_inc_unchecked(&vcc->stats->tx);
55166
55167 skb = skb_dequeue(&instance->sndqueue);
55168 }
55169 @@ -756,11 +756,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t *pos, char *page
55170 if (!left--)
55171 return sprintf(page,
55172 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
55173 - atomic_read(&atm_dev->stats.aal5.tx),
55174 - atomic_read(&atm_dev->stats.aal5.tx_err),
55175 - atomic_read(&atm_dev->stats.aal5.rx),
55176 - atomic_read(&atm_dev->stats.aal5.rx_err),
55177 - atomic_read(&atm_dev->stats.aal5.rx_drop));
55178 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
55179 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
55180 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
55181 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
55182 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
55183
55184 if (!left--) {
55185 if (instance->disconnected)
55186 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
55187 index 2a3bbdf..91d72cf 100644
55188 --- a/drivers/usb/core/devices.c
55189 +++ b/drivers/usb/core/devices.c
55190 @@ -126,7 +126,7 @@ static const char format_endpt[] =
55191 * time it gets called.
55192 */
55193 static struct device_connect_event {
55194 - atomic_t count;
55195 + atomic_unchecked_t count;
55196 wait_queue_head_t wait;
55197 } device_event = {
55198 .count = ATOMIC_INIT(1),
55199 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
55200
55201 void usbfs_conn_disc_event(void)
55202 {
55203 - atomic_add(2, &device_event.count);
55204 + atomic_add_unchecked(2, &device_event.count);
55205 wake_up(&device_event.wait);
55206 }
55207
55208 @@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
55209
55210 poll_wait(file, &device_event.wait, wait);
55211
55212 - event_count = atomic_read(&device_event.count);
55213 + event_count = atomic_read_unchecked(&device_event.count);
55214 if (file->f_version != event_count) {
55215 file->f_version = event_count;
55216 return POLLIN | POLLRDNORM;
55217 diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
55218 index 257876e..4304364 100644
55219 --- a/drivers/usb/core/devio.c
55220 +++ b/drivers/usb/core/devio.c
55221 @@ -187,7 +187,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
55222 struct usb_dev_state *ps = file->private_data;
55223 struct usb_device *dev = ps->dev;
55224 ssize_t ret = 0;
55225 - unsigned len;
55226 + size_t len;
55227 loff_t pos;
55228 int i;
55229
55230 @@ -229,22 +229,22 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
55231 for (i = 0; nbytes && i < dev->descriptor.bNumConfigurations; i++) {
55232 struct usb_config_descriptor *config =
55233 (struct usb_config_descriptor *)dev->rawdescriptors[i];
55234 - unsigned int length = le16_to_cpu(config->wTotalLength);
55235 + size_t length = le16_to_cpu(config->wTotalLength);
55236
55237 if (*ppos < pos + length) {
55238
55239 /* The descriptor may claim to be longer than it
55240 * really is. Here is the actual allocated length. */
55241 - unsigned alloclen =
55242 + size_t alloclen =
55243 le16_to_cpu(dev->config[i].desc.wTotalLength);
55244
55245 - len = length - (*ppos - pos);
55246 + len = length + pos - *ppos;
55247 if (len > nbytes)
55248 len = nbytes;
55249
55250 /* Simply don't write (skip over) unallocated parts */
55251 if (alloclen > (*ppos - pos)) {
55252 - alloclen -= (*ppos - pos);
55253 + alloclen = alloclen + pos - *ppos;
55254 if (copy_to_user(buf,
55255 dev->rawdescriptors[i] + (*ppos - pos),
55256 min(len, alloclen))) {
55257 diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
55258 index bec31e2..b8091cd 100644
55259 --- a/drivers/usb/core/hcd.c
55260 +++ b/drivers/usb/core/hcd.c
55261 @@ -1554,7 +1554,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
55262 */
55263 usb_get_urb(urb);
55264 atomic_inc(&urb->use_count);
55265 - atomic_inc(&urb->dev->urbnum);
55266 + atomic_inc_unchecked(&urb->dev->urbnum);
55267 usbmon_urb_submit(&hcd->self, urb);
55268
55269 /* NOTE requirements on root-hub callers (usbfs and the hub
55270 @@ -1581,7 +1581,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
55271 urb->hcpriv = NULL;
55272 INIT_LIST_HEAD(&urb->urb_list);
55273 atomic_dec(&urb->use_count);
55274 - atomic_dec(&urb->dev->urbnum);
55275 + atomic_dec_unchecked(&urb->dev->urbnum);
55276 if (atomic_read(&urb->reject))
55277 wake_up(&usb_kill_urb_queue);
55278 usb_put_urb(urb);
55279 diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
55280 index 0e950ad..a2be5b0 100644
55281 --- a/drivers/usb/core/hub.c
55282 +++ b/drivers/usb/core/hub.c
55283 @@ -27,6 +27,7 @@
55284 #include <linux/freezer.h>
55285 #include <linux/random.h>
55286 #include <linux/pm_qos.h>
55287 +#include <linux/grsecurity.h>
55288
55289 #include <asm/uaccess.h>
55290 #include <asm/byteorder.h>
55291 @@ -4594,6 +4595,10 @@ static void hub_port_connect(struct usb_hub *hub, int port1, u16 portstatus,
55292 goto done;
55293 return;
55294 }
55295 +
55296 + if (gr_handle_new_usb())
55297 + goto done;
55298 +
55299 if (hub_is_superspeed(hub->hdev))
55300 unit_load = 150;
55301 else
55302 diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
55303 index 0c8a7fc..c45b40a 100644
55304 --- a/drivers/usb/core/message.c
55305 +++ b/drivers/usb/core/message.c
55306 @@ -128,7 +128,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
55307 * Return: If successful, the number of bytes transferred. Otherwise, a negative
55308 * error number.
55309 */
55310 -int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
55311 +int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
55312 __u8 requesttype, __u16 value, __u16 index, void *data,
55313 __u16 size, int timeout)
55314 {
55315 @@ -180,7 +180,7 @@ EXPORT_SYMBOL_GPL(usb_control_msg);
55316 * If successful, 0. Otherwise a negative error number. The number of actual
55317 * bytes transferred will be stored in the @actual_length parameter.
55318 */
55319 -int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
55320 +int __intentional_overflow(-1) usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
55321 void *data, int len, int *actual_length, int timeout)
55322 {
55323 return usb_bulk_msg(usb_dev, pipe, data, len, actual_length, timeout);
55324 @@ -220,7 +220,7 @@ EXPORT_SYMBOL_GPL(usb_interrupt_msg);
55325 * bytes transferred will be stored in the @actual_length parameter.
55326 *
55327 */
55328 -int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
55329 +int __intentional_overflow(-1) usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
55330 void *data, int len, int *actual_length, int timeout)
55331 {
55332 struct urb *urb;
55333 diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
55334 index 1236c60..d47a51c 100644
55335 --- a/drivers/usb/core/sysfs.c
55336 +++ b/drivers/usb/core/sysfs.c
55337 @@ -244,7 +244,7 @@ static ssize_t urbnum_show(struct device *dev, struct device_attribute *attr,
55338 struct usb_device *udev;
55339
55340 udev = to_usb_device(dev);
55341 - return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
55342 + return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
55343 }
55344 static DEVICE_ATTR_RO(urbnum);
55345
55346 diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
55347 index 4d11449..f4ccabf 100644
55348 --- a/drivers/usb/core/usb.c
55349 +++ b/drivers/usb/core/usb.c
55350 @@ -433,7 +433,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
55351 set_dev_node(&dev->dev, dev_to_node(bus->controller));
55352 dev->state = USB_STATE_ATTACHED;
55353 dev->lpm_disable_count = 1;
55354 - atomic_set(&dev->urbnum, 0);
55355 + atomic_set_unchecked(&dev->urbnum, 0);
55356
55357 INIT_LIST_HEAD(&dev->ep0.urb_list);
55358 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
55359 diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
55360 index dab7927..6f53afc 100644
55361 --- a/drivers/usb/dwc3/gadget.c
55362 +++ b/drivers/usb/dwc3/gadget.c
55363 @@ -615,8 +615,6 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
55364 if (!usb_endpoint_xfer_isoc(desc))
55365 return 0;
55366
55367 - memset(&trb_link, 0, sizeof(trb_link));
55368 -
55369 /* Link TRB for ISOC. The HWO bit is never reset */
55370 trb_st_hw = &dep->trb_pool[0];
55371
55372 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
55373 index 8cfc319..4868255 100644
55374 --- a/drivers/usb/early/ehci-dbgp.c
55375 +++ b/drivers/usb/early/ehci-dbgp.c
55376 @@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
55377
55378 #ifdef CONFIG_KGDB
55379 static struct kgdb_io kgdbdbgp_io_ops;
55380 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
55381 +static struct kgdb_io kgdbdbgp_io_ops_console;
55382 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
55383 #else
55384 #define dbgp_kgdb_mode (0)
55385 #endif
55386 @@ -1043,6 +1044,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
55387 .write_char = kgdbdbgp_write_char,
55388 };
55389
55390 +static struct kgdb_io kgdbdbgp_io_ops_console = {
55391 + .name = "kgdbdbgp",
55392 + .read_char = kgdbdbgp_read_char,
55393 + .write_char = kgdbdbgp_write_char,
55394 + .is_console = 1
55395 +};
55396 +
55397 static int kgdbdbgp_wait_time;
55398
55399 static int __init kgdbdbgp_parse_config(char *str)
55400 @@ -1058,8 +1066,10 @@ static int __init kgdbdbgp_parse_config(char *str)
55401 ptr++;
55402 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
55403 }
55404 - kgdb_register_io_module(&kgdbdbgp_io_ops);
55405 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
55406 + if (early_dbgp_console.index != -1)
55407 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
55408 + else
55409 + kgdb_register_io_module(&kgdbdbgp_io_ops);
55410
55411 return 0;
55412 }
55413 diff --git a/drivers/usb/gadget/f_uac1.c b/drivers/usb/gadget/f_uac1.c
55414 index 2b4c82d..06a8ee6 100644
55415 --- a/drivers/usb/gadget/f_uac1.c
55416 +++ b/drivers/usb/gadget/f_uac1.c
55417 @@ -13,6 +13,7 @@
55418 #include <linux/kernel.h>
55419 #include <linux/device.h>
55420 #include <linux/atomic.h>
55421 +#include <linux/module.h>
55422
55423 #include "u_uac1.h"
55424
55425 diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
55426 index ad0aca8..8ff84865 100644
55427 --- a/drivers/usb/gadget/u_serial.c
55428 +++ b/drivers/usb/gadget/u_serial.c
55429 @@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
55430 spin_lock_irq(&port->port_lock);
55431
55432 /* already open? Great. */
55433 - if (port->port.count) {
55434 + if (atomic_read(&port->port.count)) {
55435 status = 0;
55436 - port->port.count++;
55437 + atomic_inc(&port->port.count);
55438
55439 /* currently opening/closing? wait ... */
55440 } else if (port->openclose) {
55441 @@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
55442 tty->driver_data = port;
55443 port->port.tty = tty;
55444
55445 - port->port.count = 1;
55446 + atomic_set(&port->port.count, 1);
55447 port->openclose = false;
55448
55449 /* if connected, start the I/O stream */
55450 @@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
55451
55452 spin_lock_irq(&port->port_lock);
55453
55454 - if (port->port.count != 1) {
55455 - if (port->port.count == 0)
55456 + if (atomic_read(&port->port.count) != 1) {
55457 + if (atomic_read(&port->port.count) == 0)
55458 WARN_ON(1);
55459 else
55460 - --port->port.count;
55461 + atomic_dec(&port->port.count);
55462 goto exit;
55463 }
55464
55465 @@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
55466 * and sleep if necessary
55467 */
55468 port->openclose = true;
55469 - port->port.count = 0;
55470 + atomic_set(&port->port.count, 0);
55471
55472 gser = port->port_usb;
55473 if (gser && gser->disconnect)
55474 @@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
55475 int cond;
55476
55477 spin_lock_irq(&port->port_lock);
55478 - cond = (port->port.count == 0) && !port->openclose;
55479 + cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
55480 spin_unlock_irq(&port->port_lock);
55481 return cond;
55482 }
55483 @@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
55484 /* if it's already open, start I/O ... and notify the serial
55485 * protocol about open/close status (connect/disconnect).
55486 */
55487 - if (port->port.count) {
55488 + if (atomic_read(&port->port.count)) {
55489 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
55490 gs_start_io(port);
55491 if (gser->connect)
55492 @@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
55493
55494 port->port_usb = NULL;
55495 gser->ioport = NULL;
55496 - if (port->port.count > 0 || port->openclose) {
55497 + if (atomic_read(&port->port.count) > 0 || port->openclose) {
55498 wake_up_interruptible(&port->drain_wait);
55499 if (port->port.tty)
55500 tty_hangup(port->port.tty);
55501 @@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
55502
55503 /* finally, free any unused/unusable I/O buffers */
55504 spin_lock_irqsave(&port->port_lock, flags);
55505 - if (port->port.count == 0 && !port->openclose)
55506 + if (atomic_read(&port->port.count) == 0 && !port->openclose)
55507 gs_buf_free(&port->port_write_buf);
55508 gs_free_requests(gser->out, &port->read_pool, NULL);
55509 gs_free_requests(gser->out, &port->read_queue, NULL);
55510 diff --git a/drivers/usb/gadget/u_uac1.c b/drivers/usb/gadget/u_uac1.c
55511 index 7a55fea..cc0ed4f 100644
55512 --- a/drivers/usb/gadget/u_uac1.c
55513 +++ b/drivers/usb/gadget/u_uac1.c
55514 @@ -16,6 +16,7 @@
55515 #include <linux/ctype.h>
55516 #include <linux/random.h>
55517 #include <linux/syscalls.h>
55518 +#include <linux/module.h>
55519
55520 #include "u_uac1.h"
55521
55522 diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
55523 index cc305c7..cf6da4a 100644
55524 --- a/drivers/usb/host/ehci-hub.c
55525 +++ b/drivers/usb/host/ehci-hub.c
55526 @@ -771,7 +771,7 @@ static struct urb *request_single_step_set_feature_urb(
55527 urb->transfer_flags = URB_DIR_IN;
55528 usb_get_urb(urb);
55529 atomic_inc(&urb->use_count);
55530 - atomic_inc(&urb->dev->urbnum);
55531 + atomic_inc_unchecked(&urb->dev->urbnum);
55532 urb->setup_dma = dma_map_single(
55533 hcd->self.controller,
55534 urb->setup_packet,
55535 @@ -838,7 +838,7 @@ static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
55536 urb->status = -EINPROGRESS;
55537 usb_get_urb(urb);
55538 atomic_inc(&urb->use_count);
55539 - atomic_inc(&urb->dev->urbnum);
55540 + atomic_inc_unchecked(&urb->dev->urbnum);
55541 retval = submit_single_step_set_feature(hcd, urb, 0);
55542 if (!retval && !wait_for_completion_timeout(&done,
55543 msecs_to_jiffies(2000))) {
55544 diff --git a/drivers/usb/host/hwa-hc.c b/drivers/usb/host/hwa-hc.c
55545 index d0d8fad..668ef7b 100644
55546 --- a/drivers/usb/host/hwa-hc.c
55547 +++ b/drivers/usb/host/hwa-hc.c
55548 @@ -337,7 +337,10 @@ static int __hwahc_op_bwa_set(struct wusbhc *wusbhc, s8 stream_index,
55549 struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc);
55550 struct wahc *wa = &hwahc->wa;
55551 struct device *dev = &wa->usb_iface->dev;
55552 - u8 mas_le[UWB_NUM_MAS/8];
55553 + u8 *mas_le = kmalloc(UWB_NUM_MAS/8, GFP_KERNEL);
55554 +
55555 + if (mas_le == NULL)
55556 + return -ENOMEM;
55557
55558 /* Set the stream index */
55559 result = usb_control_msg(wa->usb_dev, usb_sndctrlpipe(wa->usb_dev, 0),
55560 @@ -356,10 +359,12 @@ static int __hwahc_op_bwa_set(struct wusbhc *wusbhc, s8 stream_index,
55561 WUSB_REQ_SET_WUSB_MAS,
55562 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
55563 0, wa->usb_iface->cur_altsetting->desc.bInterfaceNumber,
55564 - mas_le, 32, USB_CTRL_SET_TIMEOUT);
55565 + mas_le, UWB_NUM_MAS/8, USB_CTRL_SET_TIMEOUT);
55566 if (result < 0)
55567 dev_err(dev, "Cannot set WUSB MAS allocation: %d\n", result);
55568 out:
55569 + kfree(mas_le);
55570 +
55571 return result;
55572 }
55573
55574 diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
55575 index b3d245e..99549ed 100644
55576 --- a/drivers/usb/misc/appledisplay.c
55577 +++ b/drivers/usb/misc/appledisplay.c
55578 @@ -84,7 +84,7 @@ struct appledisplay {
55579 struct mutex sysfslock; /* concurrent read and write */
55580 };
55581
55582 -static atomic_t count_displays = ATOMIC_INIT(0);
55583 +static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
55584 static struct workqueue_struct *wq;
55585
55586 static void appledisplay_complete(struct urb *urb)
55587 @@ -288,7 +288,7 @@ static int appledisplay_probe(struct usb_interface *iface,
55588
55589 /* Register backlight device */
55590 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
55591 - atomic_inc_return(&count_displays) - 1);
55592 + atomic_inc_return_unchecked(&count_displays) - 1);
55593 memset(&props, 0, sizeof(struct backlight_properties));
55594 props.type = BACKLIGHT_RAW;
55595 props.max_brightness = 0xff;
55596 diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
55597 index 8d7fc48..01c4986 100644
55598 --- a/drivers/usb/serial/console.c
55599 +++ b/drivers/usb/serial/console.c
55600 @@ -123,7 +123,7 @@ static int usb_console_setup(struct console *co, char *options)
55601
55602 info->port = port;
55603
55604 - ++port->port.count;
55605 + atomic_inc(&port->port.count);
55606 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
55607 if (serial->type->set_termios) {
55608 /*
55609 @@ -167,7 +167,7 @@ static int usb_console_setup(struct console *co, char *options)
55610 }
55611 /* Now that any required fake tty operations are completed restore
55612 * the tty port count */
55613 - --port->port.count;
55614 + atomic_dec(&port->port.count);
55615 /* The console is special in terms of closing the device so
55616 * indicate this port is now acting as a system console. */
55617 port->port.console = 1;
55618 @@ -180,7 +180,7 @@ static int usb_console_setup(struct console *co, char *options)
55619 free_tty:
55620 kfree(tty);
55621 reset_open_count:
55622 - port->port.count = 0;
55623 + atomic_set(&port->port.count, 0);
55624 usb_autopm_put_interface(serial->interface);
55625 error_get_interface:
55626 usb_serial_put(serial);
55627 @@ -191,7 +191,7 @@ static int usb_console_setup(struct console *co, char *options)
55628 static void usb_console_write(struct console *co,
55629 const char *buf, unsigned count)
55630 {
55631 - static struct usbcons_info *info = &usbcons_info;
55632 + struct usbcons_info *info = &usbcons_info;
55633 struct usb_serial_port *port = info->port;
55634 struct usb_serial *serial;
55635 int retval = -ENODEV;
55636 diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
55637 index 307e339..6aa97cb 100644
55638 --- a/drivers/usb/storage/usb.h
55639 +++ b/drivers/usb/storage/usb.h
55640 @@ -63,7 +63,7 @@ struct us_unusual_dev {
55641 __u8 useProtocol;
55642 __u8 useTransport;
55643 int (*initFunction)(struct us_data *);
55644 -};
55645 +} __do_const;
55646
55647
55648 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
55649 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
55650 index f2a8d29..7bc3fe7 100644
55651 --- a/drivers/usb/wusbcore/wa-hc.h
55652 +++ b/drivers/usb/wusbcore/wa-hc.h
55653 @@ -240,7 +240,7 @@ struct wahc {
55654 spinlock_t xfer_list_lock;
55655 struct work_struct xfer_enqueue_work;
55656 struct work_struct xfer_error_work;
55657 - atomic_t xfer_id_count;
55658 + atomic_unchecked_t xfer_id_count;
55659
55660 kernel_ulong_t quirks;
55661 };
55662 @@ -305,7 +305,7 @@ static inline void wa_init(struct wahc *wa)
55663 INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run);
55664 INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run);
55665 wa->dto_in_use = 0;
55666 - atomic_set(&wa->xfer_id_count, 1);
55667 + atomic_set_unchecked(&wa->xfer_id_count, 1);
55668 /* init the buf in URBs */
55669 for (index = 0; index < WA_MAX_BUF_IN_URBS; ++index)
55670 usb_init_urb(&(wa->buf_in_urbs[index]));
55671 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
55672 index 3e2e4ed..060c9b8 100644
55673 --- a/drivers/usb/wusbcore/wa-xfer.c
55674 +++ b/drivers/usb/wusbcore/wa-xfer.c
55675 @@ -314,7 +314,7 @@ static void wa_xfer_completion(struct wa_xfer *xfer)
55676 */
55677 static void wa_xfer_id_init(struct wa_xfer *xfer)
55678 {
55679 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
55680 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
55681 }
55682
55683 /* Return the xfer's ID. */
55684 diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
55685 index f018d8d..ccab63f 100644
55686 --- a/drivers/vfio/vfio.c
55687 +++ b/drivers/vfio/vfio.c
55688 @@ -481,7 +481,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
55689 return 0;
55690
55691 /* TODO Prevent device auto probing */
55692 - WARN("Device %s added to live group %d!\n", dev_name(dev),
55693 + WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
55694 iommu_group_id(group->iommu_group));
55695
55696 return 0;
55697 diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
55698 index 5174eba..451e6bc 100644
55699 --- a/drivers/vhost/vringh.c
55700 +++ b/drivers/vhost/vringh.c
55701 @@ -530,17 +530,17 @@ static inline void __vringh_notify_disable(struct vringh *vrh,
55702 /* Userspace access helpers: in this case, addresses are really userspace. */
55703 static inline int getu16_user(u16 *val, const u16 *p)
55704 {
55705 - return get_user(*val, (__force u16 __user *)p);
55706 + return get_user(*val, (u16 __force_user *)p);
55707 }
55708
55709 static inline int putu16_user(u16 *p, u16 val)
55710 {
55711 - return put_user(val, (__force u16 __user *)p);
55712 + return put_user(val, (u16 __force_user *)p);
55713 }
55714
55715 static inline int copydesc_user(void *dst, const void *src, size_t len)
55716 {
55717 - return copy_from_user(dst, (__force void __user *)src, len) ?
55718 + return copy_from_user(dst, (void __force_user *)src, len) ?
55719 -EFAULT : 0;
55720 }
55721
55722 @@ -548,19 +548,19 @@ static inline int putused_user(struct vring_used_elem *dst,
55723 const struct vring_used_elem *src,
55724 unsigned int num)
55725 {
55726 - return copy_to_user((__force void __user *)dst, src,
55727 + return copy_to_user((void __force_user *)dst, src,
55728 sizeof(*dst) * num) ? -EFAULT : 0;
55729 }
55730
55731 static inline int xfer_from_user(void *src, void *dst, size_t len)
55732 {
55733 - return copy_from_user(dst, (__force void __user *)src, len) ?
55734 + return copy_from_user(dst, (void __force_user *)src, len) ?
55735 -EFAULT : 0;
55736 }
55737
55738 static inline int xfer_to_user(void *dst, void *src, size_t len)
55739 {
55740 - return copy_to_user((__force void __user *)dst, src, len) ?
55741 + return copy_to_user((void __force_user *)dst, src, len) ?
55742 -EFAULT : 0;
55743 }
55744
55745 @@ -596,9 +596,9 @@ int vringh_init_user(struct vringh *vrh, u32 features,
55746 vrh->last_used_idx = 0;
55747 vrh->vring.num = num;
55748 /* vring expects kernel addresses, but only used via accessors. */
55749 - vrh->vring.desc = (__force struct vring_desc *)desc;
55750 - vrh->vring.avail = (__force struct vring_avail *)avail;
55751 - vrh->vring.used = (__force struct vring_used *)used;
55752 + vrh->vring.desc = (__force_kernel struct vring_desc *)desc;
55753 + vrh->vring.avail = (__force_kernel struct vring_avail *)avail;
55754 + vrh->vring.used = (__force_kernel struct vring_used *)used;
55755 return 0;
55756 }
55757 EXPORT_SYMBOL(vringh_init_user);
55758 @@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
55759
55760 static inline int putu16_kern(u16 *p, u16 val)
55761 {
55762 - ACCESS_ONCE(*p) = val;
55763 + ACCESS_ONCE_RW(*p) = val;
55764 return 0;
55765 }
55766
55767 diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
55768 index 84a110a..96312c3 100644
55769 --- a/drivers/video/backlight/kb3886_bl.c
55770 +++ b/drivers/video/backlight/kb3886_bl.c
55771 @@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
55772 static unsigned long kb3886bl_flags;
55773 #define KB3886BL_SUSPENDED 0x01
55774
55775 -static struct dmi_system_id kb3886bl_device_table[] __initdata = {
55776 +static const struct dmi_system_id kb3886bl_device_table[] __initconst = {
55777 {
55778 .ident = "Sahara Touch-iT",
55779 .matches = {
55780 diff --git a/drivers/video/fbdev/arcfb.c b/drivers/video/fbdev/arcfb.c
55781 index 1b0b233..6f34c2c 100644
55782 --- a/drivers/video/fbdev/arcfb.c
55783 +++ b/drivers/video/fbdev/arcfb.c
55784 @@ -458,7 +458,7 @@ static ssize_t arcfb_write(struct fb_info *info, const char __user *buf,
55785 return -ENOSPC;
55786
55787 err = 0;
55788 - if ((count + p) > fbmemlength) {
55789 + if (count > (fbmemlength - p)) {
55790 count = fbmemlength - p;
55791 err = -ENOSPC;
55792 }
55793 diff --git a/drivers/video/fbdev/aty/aty128fb.c b/drivers/video/fbdev/aty/aty128fb.c
55794 index 52108be..c7c110d 100644
55795 --- a/drivers/video/fbdev/aty/aty128fb.c
55796 +++ b/drivers/video/fbdev/aty/aty128fb.c
55797 @@ -149,7 +149,7 @@ enum {
55798 };
55799
55800 /* Must match above enum */
55801 -static char * const r128_family[] = {
55802 +static const char * const r128_family[] = {
55803 "AGP",
55804 "PCI",
55805 "PRO AGP",
55806 diff --git a/drivers/video/fbdev/aty/atyfb_base.c b/drivers/video/fbdev/aty/atyfb_base.c
55807 index c3d0074..0b9077e 100644
55808 --- a/drivers/video/fbdev/aty/atyfb_base.c
55809 +++ b/drivers/video/fbdev/aty/atyfb_base.c
55810 @@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
55811 par->accel_flags = var->accel_flags; /* hack */
55812
55813 if (var->accel_flags) {
55814 - info->fbops->fb_sync = atyfb_sync;
55815 + pax_open_kernel();
55816 + *(void **)&info->fbops->fb_sync = atyfb_sync;
55817 + pax_close_kernel();
55818 info->flags &= ~FBINFO_HWACCEL_DISABLED;
55819 } else {
55820 - info->fbops->fb_sync = NULL;
55821 + pax_open_kernel();
55822 + *(void **)&info->fbops->fb_sync = NULL;
55823 + pax_close_kernel();
55824 info->flags |= FBINFO_HWACCEL_DISABLED;
55825 }
55826
55827 diff --git a/drivers/video/fbdev/aty/mach64_cursor.c b/drivers/video/fbdev/aty/mach64_cursor.c
55828 index 2fa0317..4983f2a 100644
55829 --- a/drivers/video/fbdev/aty/mach64_cursor.c
55830 +++ b/drivers/video/fbdev/aty/mach64_cursor.c
55831 @@ -8,6 +8,7 @@
55832 #include "../core/fb_draw.h"
55833
55834 #include <asm/io.h>
55835 +#include <asm/pgtable.h>
55836
55837 #ifdef __sparc__
55838 #include <asm/fbio.h>
55839 @@ -218,7 +219,9 @@ int aty_init_cursor(struct fb_info *info)
55840 info->sprite.buf_align = 16; /* and 64 lines tall. */
55841 info->sprite.flags = FB_PIXMAP_IO;
55842
55843 - info->fbops->fb_cursor = atyfb_cursor;
55844 + pax_open_kernel();
55845 + *(void **)&info->fbops->fb_cursor = atyfb_cursor;
55846 + pax_close_kernel();
55847
55848 return 0;
55849 }
55850 diff --git a/drivers/video/fbdev/core/fb_defio.c b/drivers/video/fbdev/core/fb_defio.c
55851 index 900aa4e..6d49418 100644
55852 --- a/drivers/video/fbdev/core/fb_defio.c
55853 +++ b/drivers/video/fbdev/core/fb_defio.c
55854 @@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
55855
55856 BUG_ON(!fbdefio);
55857 mutex_init(&fbdefio->lock);
55858 - info->fbops->fb_mmap = fb_deferred_io_mmap;
55859 + pax_open_kernel();
55860 + *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
55861 + pax_close_kernel();
55862 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
55863 INIT_LIST_HEAD(&fbdefio->pagelist);
55864 if (fbdefio->delay == 0) /* set a default of 1 s */
55865 @@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
55866 page->mapping = NULL;
55867 }
55868
55869 - info->fbops->fb_mmap = NULL;
55870 + *(void **)&info->fbops->fb_mmap = NULL;
55871 mutex_destroy(&fbdefio->lock);
55872 }
55873 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
55874 diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c
55875 index b5e85f6..290f8c7 100644
55876 --- a/drivers/video/fbdev/core/fbmem.c
55877 +++ b/drivers/video/fbdev/core/fbmem.c
55878 @@ -1301,7 +1301,7 @@ static int do_fscreeninfo_to_user(struct fb_fix_screeninfo *fix,
55879 __u32 data;
55880 int err;
55881
55882 - err = copy_to_user(&fix32->id, &fix->id, sizeof(fix32->id));
55883 + err = copy_to_user(fix32->id, &fix->id, sizeof(fix32->id));
55884
55885 data = (__u32) (unsigned long) fix->smem_start;
55886 err |= put_user(data, &fix32->smem_start);
55887 diff --git a/drivers/video/fbdev/hyperv_fb.c b/drivers/video/fbdev/hyperv_fb.c
55888 index e23392e..8a77540 100644
55889 --- a/drivers/video/fbdev/hyperv_fb.c
55890 +++ b/drivers/video/fbdev/hyperv_fb.c
55891 @@ -235,7 +235,7 @@ static uint screen_fb_size;
55892 static inline int synthvid_send(struct hv_device *hdev,
55893 struct synthvid_msg *msg)
55894 {
55895 - static atomic64_t request_id = ATOMIC64_INIT(0);
55896 + static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
55897 int ret;
55898
55899 msg->pipe_hdr.type = PIPE_MSG_DATA;
55900 @@ -243,7 +243,7 @@ static inline int synthvid_send(struct hv_device *hdev,
55901
55902 ret = vmbus_sendpacket(hdev->channel, msg,
55903 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
55904 - atomic64_inc_return(&request_id),
55905 + atomic64_inc_return_unchecked(&request_id),
55906 VM_PKT_DATA_INBAND, 0);
55907
55908 if (ret)
55909 diff --git a/drivers/video/fbdev/i810/i810_accel.c b/drivers/video/fbdev/i810/i810_accel.c
55910 index 7672d2e..b56437f 100644
55911 --- a/drivers/video/fbdev/i810/i810_accel.c
55912 +++ b/drivers/video/fbdev/i810/i810_accel.c
55913 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
55914 }
55915 }
55916 printk("ringbuffer lockup!!!\n");
55917 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
55918 i810_report_error(mmio);
55919 par->dev_flags |= LOCKUP;
55920 info->pixmap.scan_align = 1;
55921 diff --git a/drivers/video/fbdev/matrox/matroxfb_DAC1064.c b/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
55922 index a01147f..5d896f8 100644
55923 --- a/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
55924 +++ b/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
55925 @@ -1088,14 +1088,20 @@ static void MGAG100_restore(struct matrox_fb_info *minfo)
55926
55927 #ifdef CONFIG_FB_MATROX_MYSTIQUE
55928 struct matrox_switch matrox_mystique = {
55929 - MGA1064_preinit, MGA1064_reset, MGA1064_init, MGA1064_restore,
55930 + .preinit = MGA1064_preinit,
55931 + .reset = MGA1064_reset,
55932 + .init = MGA1064_init,
55933 + .restore = MGA1064_restore,
55934 };
55935 EXPORT_SYMBOL(matrox_mystique);
55936 #endif
55937
55938 #ifdef CONFIG_FB_MATROX_G
55939 struct matrox_switch matrox_G100 = {
55940 - MGAG100_preinit, MGAG100_reset, MGAG100_init, MGAG100_restore,
55941 + .preinit = MGAG100_preinit,
55942 + .reset = MGAG100_reset,
55943 + .init = MGAG100_init,
55944 + .restore = MGAG100_restore,
55945 };
55946 EXPORT_SYMBOL(matrox_G100);
55947 #endif
55948 diff --git a/drivers/video/fbdev/matrox/matroxfb_Ti3026.c b/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
55949 index 195ad7c..09743fc 100644
55950 --- a/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
55951 +++ b/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
55952 @@ -738,7 +738,10 @@ static int Ti3026_preinit(struct matrox_fb_info *minfo)
55953 }
55954
55955 struct matrox_switch matrox_millennium = {
55956 - Ti3026_preinit, Ti3026_reset, Ti3026_init, Ti3026_restore
55957 + .preinit = Ti3026_preinit,
55958 + .reset = Ti3026_reset,
55959 + .init = Ti3026_init,
55960 + .restore = Ti3026_restore
55961 };
55962 EXPORT_SYMBOL(matrox_millennium);
55963 #endif
55964 diff --git a/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c b/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
55965 index fe92eed..106e085 100644
55966 --- a/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
55967 +++ b/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
55968 @@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
55969 struct mb862xxfb_par *par = info->par;
55970
55971 if (info->var.bits_per_pixel == 32) {
55972 - info->fbops->fb_fillrect = cfb_fillrect;
55973 - info->fbops->fb_copyarea = cfb_copyarea;
55974 - info->fbops->fb_imageblit = cfb_imageblit;
55975 + pax_open_kernel();
55976 + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
55977 + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
55978 + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
55979 + pax_close_kernel();
55980 } else {
55981 outreg(disp, GC_L0EM, 3);
55982 - info->fbops->fb_fillrect = mb86290fb_fillrect;
55983 - info->fbops->fb_copyarea = mb86290fb_copyarea;
55984 - info->fbops->fb_imageblit = mb86290fb_imageblit;
55985 + pax_open_kernel();
55986 + *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
55987 + *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
55988 + *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
55989 + pax_close_kernel();
55990 }
55991 outreg(draw, GDC_REG_DRAW_BASE, 0);
55992 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
55993 diff --git a/drivers/video/fbdev/nvidia/nvidia.c b/drivers/video/fbdev/nvidia/nvidia.c
55994 index def0412..fed6529 100644
55995 --- a/drivers/video/fbdev/nvidia/nvidia.c
55996 +++ b/drivers/video/fbdev/nvidia/nvidia.c
55997 @@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
55998 info->fix.line_length = (info->var.xres_virtual *
55999 info->var.bits_per_pixel) >> 3;
56000 if (info->var.accel_flags) {
56001 - info->fbops->fb_imageblit = nvidiafb_imageblit;
56002 - info->fbops->fb_fillrect = nvidiafb_fillrect;
56003 - info->fbops->fb_copyarea = nvidiafb_copyarea;
56004 - info->fbops->fb_sync = nvidiafb_sync;
56005 + pax_open_kernel();
56006 + *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
56007 + *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
56008 + *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
56009 + *(void **)&info->fbops->fb_sync = nvidiafb_sync;
56010 + pax_close_kernel();
56011 info->pixmap.scan_align = 4;
56012 info->flags &= ~FBINFO_HWACCEL_DISABLED;
56013 info->flags |= FBINFO_READS_FAST;
56014 NVResetGraphics(info);
56015 } else {
56016 - info->fbops->fb_imageblit = cfb_imageblit;
56017 - info->fbops->fb_fillrect = cfb_fillrect;
56018 - info->fbops->fb_copyarea = cfb_copyarea;
56019 - info->fbops->fb_sync = NULL;
56020 + pax_open_kernel();
56021 + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
56022 + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
56023 + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
56024 + *(void **)&info->fbops->fb_sync = NULL;
56025 + pax_close_kernel();
56026 info->pixmap.scan_align = 1;
56027 info->flags |= FBINFO_HWACCEL_DISABLED;
56028 info->flags &= ~FBINFO_READS_FAST;
56029 @@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
56030 info->pixmap.size = 8 * 1024;
56031 info->pixmap.flags = FB_PIXMAP_SYSTEM;
56032
56033 - if (!hwcur)
56034 - info->fbops->fb_cursor = NULL;
56035 + if (!hwcur) {
56036 + pax_open_kernel();
56037 + *(void **)&info->fbops->fb_cursor = NULL;
56038 + pax_close_kernel();
56039 + }
56040
56041 info->var.accel_flags = (!noaccel);
56042
56043 diff --git a/drivers/video/fbdev/omap2/dss/display.c b/drivers/video/fbdev/omap2/dss/display.c
56044 index 2412a0d..294215b 100644
56045 --- a/drivers/video/fbdev/omap2/dss/display.c
56046 +++ b/drivers/video/fbdev/omap2/dss/display.c
56047 @@ -161,12 +161,14 @@ int omapdss_register_display(struct omap_dss_device *dssdev)
56048 if (dssdev->name == NULL)
56049 dssdev->name = dssdev->alias;
56050
56051 + pax_open_kernel();
56052 if (drv && drv->get_resolution == NULL)
56053 - drv->get_resolution = omapdss_default_get_resolution;
56054 + *(void **)&drv->get_resolution = omapdss_default_get_resolution;
56055 if (drv && drv->get_recommended_bpp == NULL)
56056 - drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
56057 + *(void **)&drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
56058 if (drv && drv->get_timings == NULL)
56059 - drv->get_timings = omapdss_default_get_timings;
56060 + *(void **)&drv->get_timings = omapdss_default_get_timings;
56061 + pax_close_kernel();
56062
56063 mutex_lock(&panel_list_mutex);
56064 list_add_tail(&dssdev->panel_list, &panel_list);
56065 diff --git a/drivers/video/fbdev/s1d13xxxfb.c b/drivers/video/fbdev/s1d13xxxfb.c
56066 index 83433cb..71e9b98 100644
56067 --- a/drivers/video/fbdev/s1d13xxxfb.c
56068 +++ b/drivers/video/fbdev/s1d13xxxfb.c
56069 @@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
56070
56071 switch(prod_id) {
56072 case S1D13506_PROD_ID: /* activate acceleration */
56073 - s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
56074 - s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
56075 + pax_open_kernel();
56076 + *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
56077 + *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
56078 + pax_close_kernel();
56079 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
56080 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
56081 break;
56082 diff --git a/drivers/video/fbdev/sh_mobile_lcdcfb.c b/drivers/video/fbdev/sh_mobile_lcdcfb.c
56083 index 2bcc84a..29dd1ea 100644
56084 --- a/drivers/video/fbdev/sh_mobile_lcdcfb.c
56085 +++ b/drivers/video/fbdev/sh_mobile_lcdcfb.c
56086 @@ -439,9 +439,9 @@ static unsigned long lcdc_sys_read_data(void *handle)
56087 }
56088
56089 static struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = {
56090 - lcdc_sys_write_index,
56091 - lcdc_sys_write_data,
56092 - lcdc_sys_read_data,
56093 + .write_index = lcdc_sys_write_index,
56094 + .write_data = lcdc_sys_write_data,
56095 + .read_data = lcdc_sys_read_data,
56096 };
56097
56098 static int sh_mobile_lcdc_sginit(struct fb_info *info,
56099 diff --git a/drivers/video/fbdev/smscufx.c b/drivers/video/fbdev/smscufx.c
56100 index d513ed6..90b0de9 100644
56101 --- a/drivers/video/fbdev/smscufx.c
56102 +++ b/drivers/video/fbdev/smscufx.c
56103 @@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
56104 fb_deferred_io_cleanup(info);
56105 kfree(info->fbdefio);
56106 info->fbdefio = NULL;
56107 - info->fbops->fb_mmap = ufx_ops_mmap;
56108 + pax_open_kernel();
56109 + *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
56110 + pax_close_kernel();
56111 }
56112
56113 pr_debug("released /dev/fb%d user=%d count=%d",
56114 diff --git a/drivers/video/fbdev/udlfb.c b/drivers/video/fbdev/udlfb.c
56115 index 77b890e..458e666 100644
56116 --- a/drivers/video/fbdev/udlfb.c
56117 +++ b/drivers/video/fbdev/udlfb.c
56118 @@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
56119 dlfb_urb_completion(urb);
56120
56121 error:
56122 - atomic_add(bytes_sent, &dev->bytes_sent);
56123 - atomic_add(bytes_identical, &dev->bytes_identical);
56124 - atomic_add(width*height*2, &dev->bytes_rendered);
56125 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
56126 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
56127 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
56128 end_cycles = get_cycles();
56129 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
56130 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
56131 >> 10)), /* Kcycles */
56132 &dev->cpu_kcycles_used);
56133
56134 @@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
56135 dlfb_urb_completion(urb);
56136
56137 error:
56138 - atomic_add(bytes_sent, &dev->bytes_sent);
56139 - atomic_add(bytes_identical, &dev->bytes_identical);
56140 - atomic_add(bytes_rendered, &dev->bytes_rendered);
56141 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
56142 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
56143 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
56144 end_cycles = get_cycles();
56145 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
56146 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
56147 >> 10)), /* Kcycles */
56148 &dev->cpu_kcycles_used);
56149 }
56150 @@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
56151 fb_deferred_io_cleanup(info);
56152 kfree(info->fbdefio);
56153 info->fbdefio = NULL;
56154 - info->fbops->fb_mmap = dlfb_ops_mmap;
56155 + pax_open_kernel();
56156 + *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
56157 + pax_close_kernel();
56158 }
56159
56160 pr_warn("released /dev/fb%d user=%d count=%d\n",
56161 @@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
56162 struct fb_info *fb_info = dev_get_drvdata(fbdev);
56163 struct dlfb_data *dev = fb_info->par;
56164 return snprintf(buf, PAGE_SIZE, "%u\n",
56165 - atomic_read(&dev->bytes_rendered));
56166 + atomic_read_unchecked(&dev->bytes_rendered));
56167 }
56168
56169 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
56170 @@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
56171 struct fb_info *fb_info = dev_get_drvdata(fbdev);
56172 struct dlfb_data *dev = fb_info->par;
56173 return snprintf(buf, PAGE_SIZE, "%u\n",
56174 - atomic_read(&dev->bytes_identical));
56175 + atomic_read_unchecked(&dev->bytes_identical));
56176 }
56177
56178 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
56179 @@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
56180 struct fb_info *fb_info = dev_get_drvdata(fbdev);
56181 struct dlfb_data *dev = fb_info->par;
56182 return snprintf(buf, PAGE_SIZE, "%u\n",
56183 - atomic_read(&dev->bytes_sent));
56184 + atomic_read_unchecked(&dev->bytes_sent));
56185 }
56186
56187 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
56188 @@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
56189 struct fb_info *fb_info = dev_get_drvdata(fbdev);
56190 struct dlfb_data *dev = fb_info->par;
56191 return snprintf(buf, PAGE_SIZE, "%u\n",
56192 - atomic_read(&dev->cpu_kcycles_used));
56193 + atomic_read_unchecked(&dev->cpu_kcycles_used));
56194 }
56195
56196 static ssize_t edid_show(
56197 @@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
56198 struct fb_info *fb_info = dev_get_drvdata(fbdev);
56199 struct dlfb_data *dev = fb_info->par;
56200
56201 - atomic_set(&dev->bytes_rendered, 0);
56202 - atomic_set(&dev->bytes_identical, 0);
56203 - atomic_set(&dev->bytes_sent, 0);
56204 - atomic_set(&dev->cpu_kcycles_used, 0);
56205 + atomic_set_unchecked(&dev->bytes_rendered, 0);
56206 + atomic_set_unchecked(&dev->bytes_identical, 0);
56207 + atomic_set_unchecked(&dev->bytes_sent, 0);
56208 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
56209
56210 return count;
56211 }
56212 diff --git a/drivers/video/fbdev/uvesafb.c b/drivers/video/fbdev/uvesafb.c
56213 index 509d452..7c9d2de 100644
56214 --- a/drivers/video/fbdev/uvesafb.c
56215 +++ b/drivers/video/fbdev/uvesafb.c
56216 @@ -19,6 +19,7 @@
56217 #include <linux/io.h>
56218 #include <linux/mutex.h>
56219 #include <linux/slab.h>
56220 +#include <linux/moduleloader.h>
56221 #include <video/edid.h>
56222 #include <video/uvesafb.h>
56223 #ifdef CONFIG_X86
56224 @@ -565,10 +566,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
56225 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
56226 par->pmi_setpal = par->ypan = 0;
56227 } else {
56228 +
56229 +#ifdef CONFIG_PAX_KERNEXEC
56230 +#ifdef CONFIG_MODULES
56231 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
56232 +#endif
56233 + if (!par->pmi_code) {
56234 + par->pmi_setpal = par->ypan = 0;
56235 + return 0;
56236 + }
56237 +#endif
56238 +
56239 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
56240 + task->t.regs.edi);
56241 +
56242 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56243 + pax_open_kernel();
56244 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
56245 + pax_close_kernel();
56246 +
56247 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
56248 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
56249 +#else
56250 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
56251 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
56252 +#endif
56253 +
56254 printk(KERN_INFO "uvesafb: protected mode interface info at "
56255 "%04x:%04x\n",
56256 (u16)task->t.regs.es, (u16)task->t.regs.edi);
56257 @@ -813,13 +836,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
56258 par->ypan = ypan;
56259
56260 if (par->pmi_setpal || par->ypan) {
56261 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
56262 if (__supported_pte_mask & _PAGE_NX) {
56263 par->pmi_setpal = par->ypan = 0;
56264 printk(KERN_WARNING "uvesafb: NX protection is active, "
56265 "better not use the PMI.\n");
56266 - } else {
56267 + } else
56268 +#endif
56269 uvesafb_vbe_getpmi(task, par);
56270 - }
56271 }
56272 #else
56273 /* The protected mode interface is not available on non-x86. */
56274 @@ -1453,8 +1477,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
56275 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
56276
56277 /* Disable blanking if the user requested so. */
56278 - if (!blank)
56279 - info->fbops->fb_blank = NULL;
56280 + if (!blank) {
56281 + pax_open_kernel();
56282 + *(void **)&info->fbops->fb_blank = NULL;
56283 + pax_close_kernel();
56284 + }
56285
56286 /*
56287 * Find out how much IO memory is required for the mode with
56288 @@ -1525,8 +1552,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
56289 info->flags = FBINFO_FLAG_DEFAULT |
56290 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
56291
56292 - if (!par->ypan)
56293 - info->fbops->fb_pan_display = NULL;
56294 + if (!par->ypan) {
56295 + pax_open_kernel();
56296 + *(void **)&info->fbops->fb_pan_display = NULL;
56297 + pax_close_kernel();
56298 + }
56299 }
56300
56301 static void uvesafb_init_mtrr(struct fb_info *info)
56302 @@ -1787,6 +1817,11 @@ out_mode:
56303 out:
56304 kfree(par->vbe_modes);
56305
56306 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56307 + if (par->pmi_code)
56308 + module_free_exec(NULL, par->pmi_code);
56309 +#endif
56310 +
56311 framebuffer_release(info);
56312 return err;
56313 }
56314 @@ -1811,6 +1846,11 @@ static int uvesafb_remove(struct platform_device *dev)
56315 kfree(par->vbe_state_orig);
56316 kfree(par->vbe_state_saved);
56317
56318 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56319 + if (par->pmi_code)
56320 + module_free_exec(NULL, par->pmi_code);
56321 +#endif
56322 +
56323 framebuffer_release(info);
56324 }
56325 return 0;
56326 diff --git a/drivers/video/fbdev/vesafb.c b/drivers/video/fbdev/vesafb.c
56327 index 6170e7f..dd63031 100644
56328 --- a/drivers/video/fbdev/vesafb.c
56329 +++ b/drivers/video/fbdev/vesafb.c
56330 @@ -9,6 +9,7 @@
56331 */
56332
56333 #include <linux/module.h>
56334 +#include <linux/moduleloader.h>
56335 #include <linux/kernel.h>
56336 #include <linux/errno.h>
56337 #include <linux/string.h>
56338 @@ -52,8 +53,8 @@ static int vram_remap; /* Set amount of memory to be used */
56339 static int vram_total; /* Set total amount of memory */
56340 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
56341 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
56342 -static void (*pmi_start)(void) __read_mostly;
56343 -static void (*pmi_pal) (void) __read_mostly;
56344 +static void (*pmi_start)(void) __read_only;
56345 +static void (*pmi_pal) (void) __read_only;
56346 static int depth __read_mostly;
56347 static int vga_compat __read_mostly;
56348 /* --------------------------------------------------------------------- */
56349 @@ -233,6 +234,7 @@ static int vesafb_probe(struct platform_device *dev)
56350 unsigned int size_remap;
56351 unsigned int size_total;
56352 char *option = NULL;
56353 + void *pmi_code = NULL;
56354
56355 /* ignore error return of fb_get_options */
56356 fb_get_options("vesafb", &option);
56357 @@ -279,10 +281,6 @@ static int vesafb_probe(struct platform_device *dev)
56358 size_remap = size_total;
56359 vesafb_fix.smem_len = size_remap;
56360
56361 -#ifndef __i386__
56362 - screen_info.vesapm_seg = 0;
56363 -#endif
56364 -
56365 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
56366 printk(KERN_WARNING
56367 "vesafb: cannot reserve video memory at 0x%lx\n",
56368 @@ -312,9 +310,21 @@ static int vesafb_probe(struct platform_device *dev)
56369 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
56370 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
56371
56372 +#ifdef __i386__
56373 +
56374 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56375 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
56376 + if (!pmi_code)
56377 +#elif !defined(CONFIG_PAX_KERNEXEC)
56378 + if (0)
56379 +#endif
56380 +
56381 +#endif
56382 + screen_info.vesapm_seg = 0;
56383 +
56384 if (screen_info.vesapm_seg) {
56385 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
56386 - screen_info.vesapm_seg,screen_info.vesapm_off);
56387 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
56388 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
56389 }
56390
56391 if (screen_info.vesapm_seg < 0xc000)
56392 @@ -322,9 +332,25 @@ static int vesafb_probe(struct platform_device *dev)
56393
56394 if (ypan || pmi_setpal) {
56395 unsigned short *pmi_base;
56396 +
56397 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
56398 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
56399 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
56400 +
56401 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56402 + pax_open_kernel();
56403 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
56404 +#else
56405 + pmi_code = pmi_base;
56406 +#endif
56407 +
56408 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
56409 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
56410 +
56411 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56412 + pmi_start = ktva_ktla(pmi_start);
56413 + pmi_pal = ktva_ktla(pmi_pal);
56414 + pax_close_kernel();
56415 +#endif
56416 +
56417 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
56418 if (pmi_base[3]) {
56419 printk(KERN_INFO "vesafb: pmi: ports = ");
56420 @@ -477,8 +503,11 @@ static int vesafb_probe(struct platform_device *dev)
56421 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
56422 (ypan ? FBINFO_HWACCEL_YPAN : 0);
56423
56424 - if (!ypan)
56425 - info->fbops->fb_pan_display = NULL;
56426 + if (!ypan) {
56427 + pax_open_kernel();
56428 + *(void **)&info->fbops->fb_pan_display = NULL;
56429 + pax_close_kernel();
56430 + }
56431
56432 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
56433 err = -ENOMEM;
56434 @@ -492,6 +521,11 @@ static int vesafb_probe(struct platform_device *dev)
56435 fb_info(info, "%s frame buffer device\n", info->fix.id);
56436 return 0;
56437 err:
56438 +
56439 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56440 + module_free_exec(NULL, pmi_code);
56441 +#endif
56442 +
56443 if (info->screen_base)
56444 iounmap(info->screen_base);
56445 framebuffer_release(info);
56446 diff --git a/drivers/video/fbdev/via/via_clock.h b/drivers/video/fbdev/via/via_clock.h
56447 index 88714ae..16c2e11 100644
56448 --- a/drivers/video/fbdev/via/via_clock.h
56449 +++ b/drivers/video/fbdev/via/via_clock.h
56450 @@ -56,7 +56,7 @@ struct via_clock {
56451
56452 void (*set_engine_pll_state)(u8 state);
56453 void (*set_engine_pll)(struct via_pll_config config);
56454 -};
56455 +} __no_const;
56456
56457
56458 static inline u32 get_pll_internal_frequency(u32 ref_freq,
56459 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
56460 index 3c14e43..2630570 100644
56461 --- a/drivers/video/logo/logo_linux_clut224.ppm
56462 +++ b/drivers/video/logo/logo_linux_clut224.ppm
56463 @@ -2,1603 +2,1123 @@ P3
56464 # Standard 224-color Linux logo
56465 80 80
56466 255
56467 - 0 0 0 0 0 0 0 0 0 0 0 0
56468 - 0 0 0 0 0 0 0 0 0 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 - 0 0 0 0 0 0 0 0 0 0 0 0
56475 - 0 0 0 0 0 0 0 0 0 0 0 0
56476 - 6 6 6 6 6 6 10 10 10 10 10 10
56477 - 10 10 10 6 6 6 6 6 6 6 6 6
56478 - 0 0 0 0 0 0 0 0 0 0 0 0
56479 - 0 0 0 0 0 0 0 0 0 0 0 0
56480 - 0 0 0 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 0 0 0 0 0 0 0 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 - 0 0 0 0 0 0 0 0 0 0 0 0
56495 - 0 0 0 6 6 6 10 10 10 14 14 14
56496 - 22 22 22 26 26 26 30 30 30 34 34 34
56497 - 30 30 30 30 30 30 26 26 26 18 18 18
56498 - 14 14 14 10 10 10 6 6 6 0 0 0
56499 - 0 0 0 0 0 0 0 0 0 0 0 0
56500 - 0 0 0 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 0 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 - 0 0 0 0 0 0 0 0 0 0 0 0
56515 - 6 6 6 14 14 14 26 26 26 42 42 42
56516 - 54 54 54 66 66 66 78 78 78 78 78 78
56517 - 78 78 78 74 74 74 66 66 66 54 54 54
56518 - 42 42 42 26 26 26 18 18 18 10 10 10
56519 - 6 6 6 0 0 0 0 0 0 0 0 0
56520 - 0 0 0 0 0 0 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 1 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 0 0 0
56534 - 0 0 0 0 0 0 0 0 0 10 10 10
56535 - 22 22 22 42 42 42 66 66 66 86 86 86
56536 - 66 66 66 38 38 38 38 38 38 22 22 22
56537 - 26 26 26 34 34 34 54 54 54 66 66 66
56538 - 86 86 86 70 70 70 46 46 46 26 26 26
56539 - 14 14 14 6 6 6 0 0 0 0 0 0
56540 - 0 0 0 0 0 0 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 1 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 0 0 0
56554 - 0 0 0 0 0 0 10 10 10 26 26 26
56555 - 50 50 50 82 82 82 58 58 58 6 6 6
56556 - 2 2 6 2 2 6 2 2 6 2 2 6
56557 - 2 2 6 2 2 6 2 2 6 2 2 6
56558 - 6 6 6 54 54 54 86 86 86 66 66 66
56559 - 38 38 38 18 18 18 6 6 6 0 0 0
56560 - 0 0 0 0 0 0 0 0 0 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 0 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 0 0 0
56574 - 0 0 0 6 6 6 22 22 22 50 50 50
56575 - 78 78 78 34 34 34 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 6 6 6 70 70 70
56579 - 78 78 78 46 46 46 22 22 22 6 6 6
56580 - 0 0 0 0 0 0 0 0 0 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 1 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 0 0 0
56594 - 6 6 6 18 18 18 42 42 42 82 82 82
56595 - 26 26 26 2 2 6 2 2 6 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 14 14 14
56598 - 46 46 46 34 34 34 6 6 6 2 2 6
56599 - 42 42 42 78 78 78 42 42 42 18 18 18
56600 - 6 6 6 0 0 0 0 0 0 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 1 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 0 0 0
56614 - 10 10 10 30 30 30 66 66 66 58 58 58
56615 - 2 2 6 2 2 6 2 2 6 2 2 6
56616 - 2 2 6 2 2 6 2 2 6 2 2 6
56617 - 2 2 6 2 2 6 2 2 6 26 26 26
56618 - 86 86 86 101 101 101 46 46 46 10 10 10
56619 - 2 2 6 58 58 58 70 70 70 34 34 34
56620 - 10 10 10 0 0 0 0 0 0 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 0 0 0
56634 - 14 14 14 42 42 42 86 86 86 10 10 10
56635 - 2 2 6 2 2 6 2 2 6 2 2 6
56636 - 2 2 6 2 2 6 2 2 6 2 2 6
56637 - 2 2 6 2 2 6 2 2 6 30 30 30
56638 - 94 94 94 94 94 94 58 58 58 26 26 26
56639 - 2 2 6 6 6 6 78 78 78 54 54 54
56640 - 22 22 22 6 6 6 0 0 0 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 6 6 6
56654 - 22 22 22 62 62 62 62 62 62 2 2 6
56655 - 2 2 6 2 2 6 2 2 6 2 2 6
56656 - 2 2 6 2 2 6 2 2 6 2 2 6
56657 - 2 2 6 2 2 6 2 2 6 26 26 26
56658 - 54 54 54 38 38 38 18 18 18 10 10 10
56659 - 2 2 6 2 2 6 34 34 34 82 82 82
56660 - 38 38 38 14 14 14 0 0 0 0 0 0
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 0 0 0 0
56668 - 0 0 0 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 6 6 6
56674 - 30 30 30 78 78 78 30 30 30 2 2 6
56675 - 2 2 6 2 2 6 2 2 6 2 2 6
56676 - 2 2 6 2 2 6 2 2 6 2 2 6
56677 - 2 2 6 2 2 6 2 2 6 10 10 10
56678 - 10 10 10 2 2 6 2 2 6 2 2 6
56679 - 2 2 6 2 2 6 2 2 6 78 78 78
56680 - 50 50 50 18 18 18 6 6 6 0 0 0
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 1 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 10 10 10
56694 - 38 38 38 86 86 86 14 14 14 2 2 6
56695 - 2 2 6 2 2 6 2 2 6 2 2 6
56696 - 2 2 6 2 2 6 2 2 6 2 2 6
56697 - 2 2 6 2 2 6 2 2 6 2 2 6
56698 - 2 2 6 2 2 6 2 2 6 2 2 6
56699 - 2 2 6 2 2 6 2 2 6 54 54 54
56700 - 66 66 66 26 26 26 6 6 6 0 0 0
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 0 0 0 0
56708 - 0 0 0 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 82 82 82 2 2 6 2 2 6
56715 - 2 2 6 6 6 6 10 10 10 2 2 6
56716 - 2 2 6 2 2 6 2 2 6 2 2 6
56717 - 2 2 6 2 2 6 2 2 6 6 6 6
56718 - 14 14 14 10 10 10 2 2 6 2 2 6
56719 - 2 2 6 2 2 6 2 2 6 18 18 18
56720 - 82 82 82 34 34 34 10 10 10 0 0 0
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 0 0 0 0
56728 - 0 0 1 0 0 0 0 0 0 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 - 46 46 46 86 86 86 2 2 6 2 2 6
56735 - 6 6 6 6 6 6 22 22 22 34 34 34
56736 - 6 6 6 2 2 6 2 2 6 2 2 6
56737 - 2 2 6 2 2 6 18 18 18 34 34 34
56738 - 10 10 10 50 50 50 22 22 22 2 2 6
56739 - 2 2 6 2 2 6 2 2 6 10 10 10
56740 - 86 86 86 42 42 42 14 14 14 0 0 0
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 0 0 0 0
56748 - 0 0 1 0 0 1 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 14 14 14
56754 - 46 46 46 86 86 86 2 2 6 2 2 6
56755 - 38 38 38 116 116 116 94 94 94 22 22 22
56756 - 22 22 22 2 2 6 2 2 6 2 2 6
56757 - 14 14 14 86 86 86 138 138 138 162 162 162
56758 -154 154 154 38 38 38 26 26 26 6 6 6
56759 - 2 2 6 2 2 6 2 2 6 2 2 6
56760 - 86 86 86 46 46 46 14 14 14 0 0 0
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 14 14 14
56774 - 46 46 46 86 86 86 2 2 6 14 14 14
56775 -134 134 134 198 198 198 195 195 195 116 116 116
56776 - 10 10 10 2 2 6 2 2 6 6 6 6
56777 -101 98 89 187 187 187 210 210 210 218 218 218
56778 -214 214 214 134 134 134 14 14 14 6 6 6
56779 - 2 2 6 2 2 6 2 2 6 2 2 6
56780 - 86 86 86 50 50 50 18 18 18 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 1 0 0 0
56788 - 0 0 1 0 0 1 0 0 1 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 14 14 14
56794 - 46 46 46 86 86 86 2 2 6 54 54 54
56795 -218 218 218 195 195 195 226 226 226 246 246 246
56796 - 58 58 58 2 2 6 2 2 6 30 30 30
56797 -210 210 210 253 253 253 174 174 174 123 123 123
56798 -221 221 221 234 234 234 74 74 74 2 2 6
56799 - 2 2 6 2 2 6 2 2 6 2 2 6
56800 - 70 70 70 58 58 58 22 22 22 6 6 6
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 14 14 14
56814 - 46 46 46 82 82 82 2 2 6 106 106 106
56815 -170 170 170 26 26 26 86 86 86 226 226 226
56816 -123 123 123 10 10 10 14 14 14 46 46 46
56817 -231 231 231 190 190 190 6 6 6 70 70 70
56818 - 90 90 90 238 238 238 158 158 158 2 2 6
56819 - 2 2 6 2 2 6 2 2 6 2 2 6
56820 - 70 70 70 58 58 58 22 22 22 6 6 6
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 1 0 0 0
56828 - 0 0 1 0 0 1 0 0 1 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 14 14 14
56834 - 42 42 42 86 86 86 6 6 6 116 116 116
56835 -106 106 106 6 6 6 70 70 70 149 149 149
56836 -128 128 128 18 18 18 38 38 38 54 54 54
56837 -221 221 221 106 106 106 2 2 6 14 14 14
56838 - 46 46 46 190 190 190 198 198 198 2 2 6
56839 - 2 2 6 2 2 6 2 2 6 2 2 6
56840 - 74 74 74 62 62 62 22 22 22 6 6 6
56841 - 0 0 0 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 1 0 0 0
56848 - 0 0 1 0 0 0 0 0 1 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 14 14 14
56854 - 42 42 42 94 94 94 14 14 14 101 101 101
56855 -128 128 128 2 2 6 18 18 18 116 116 116
56856 -118 98 46 121 92 8 121 92 8 98 78 10
56857 -162 162 162 106 106 106 2 2 6 2 2 6
56858 - 2 2 6 195 195 195 195 195 195 6 6 6
56859 - 2 2 6 2 2 6 2 2 6 2 2 6
56860 - 74 74 74 62 62 62 22 22 22 6 6 6
56861 - 0 0 0 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 1 0 0 1
56868 - 0 0 1 0 0 0 0 0 1 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 - 38 38 38 90 90 90 14 14 14 58 58 58
56875 -210 210 210 26 26 26 54 38 6 154 114 10
56876 -226 170 11 236 186 11 225 175 15 184 144 12
56877 -215 174 15 175 146 61 37 26 9 2 2 6
56878 - 70 70 70 246 246 246 138 138 138 2 2 6
56879 - 2 2 6 2 2 6 2 2 6 2 2 6
56880 - 70 70 70 66 66 66 26 26 26 6 6 6
56881 - 0 0 0 0 0 0 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 14 14 14 10 10 10
56895 -195 195 195 188 164 115 192 133 9 225 175 15
56896 -239 182 13 234 190 10 232 195 16 232 200 30
56897 -245 207 45 241 208 19 232 195 16 184 144 12
56898 -218 194 134 211 206 186 42 42 42 2 2 6
56899 - 2 2 6 2 2 6 2 2 6 2 2 6
56900 - 50 50 50 74 74 74 30 30 30 6 6 6
56901 - 0 0 0 0 0 0 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 0 0 0 10 10 10
56914 - 34 34 34 86 86 86 14 14 14 2 2 6
56915 -121 87 25 192 133 9 219 162 10 239 182 13
56916 -236 186 11 232 195 16 241 208 19 244 214 54
56917 -246 218 60 246 218 38 246 215 20 241 208 19
56918 -241 208 19 226 184 13 121 87 25 2 2 6
56919 - 2 2 6 2 2 6 2 2 6 2 2 6
56920 - 50 50 50 82 82 82 34 34 34 10 10 10
56921 - 0 0 0 0 0 0 0 0 0 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 0 0 0 10 10 10
56934 - 34 34 34 82 82 82 30 30 30 61 42 6
56935 -180 123 7 206 145 10 230 174 11 239 182 13
56936 -234 190 10 238 202 15 241 208 19 246 218 74
56937 -246 218 38 246 215 20 246 215 20 246 215 20
56938 -226 184 13 215 174 15 184 144 12 6 6 6
56939 - 2 2 6 2 2 6 2 2 6 2 2 6
56940 - 26 26 26 94 94 94 42 42 42 14 14 14
56941 - 0 0 0 0 0 0 0 0 0 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 0 0 0 0 0 0 10 10 10
56954 - 30 30 30 78 78 78 50 50 50 104 69 6
56955 -192 133 9 216 158 10 236 178 12 236 186 11
56956 -232 195 16 241 208 19 244 214 54 245 215 43
56957 -246 215 20 246 215 20 241 208 19 198 155 10
56958 -200 144 11 216 158 10 156 118 10 2 2 6
56959 - 2 2 6 2 2 6 2 2 6 2 2 6
56960 - 6 6 6 90 90 90 54 54 54 18 18 18
56961 - 6 6 6 0 0 0 0 0 0 0 0 0
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 - 0 0 0 0 0 0 0 0 0 10 10 10
56974 - 30 30 30 78 78 78 46 46 46 22 22 22
56975 -137 92 6 210 162 10 239 182 13 238 190 10
56976 -238 202 15 241 208 19 246 215 20 246 215 20
56977 -241 208 19 203 166 17 185 133 11 210 150 10
56978 -216 158 10 210 150 10 102 78 10 2 2 6
56979 - 6 6 6 54 54 54 14 14 14 2 2 6
56980 - 2 2 6 62 62 62 74 74 74 30 30 30
56981 - 10 10 10 0 0 0 0 0 0 0 0 0
56982 - 0 0 0 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 0 0 0
56993 - 0 0 0 0 0 0 0 0 0 10 10 10
56994 - 34 34 34 78 78 78 50 50 50 6 6 6
56995 - 94 70 30 139 102 15 190 146 13 226 184 13
56996 -232 200 30 232 195 16 215 174 15 190 146 13
56997 -168 122 10 192 133 9 210 150 10 213 154 11
56998 -202 150 34 182 157 106 101 98 89 2 2 6
56999 - 2 2 6 78 78 78 116 116 116 58 58 58
57000 - 2 2 6 22 22 22 90 90 90 46 46 46
57001 - 18 18 18 6 6 6 0 0 0 0 0 0
57002 - 0 0 0 0 0 0 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 0 0 0
57013 - 0 0 0 0 0 0 0 0 0 10 10 10
57014 - 38 38 38 86 86 86 50 50 50 6 6 6
57015 -128 128 128 174 154 114 156 107 11 168 122 10
57016 -198 155 10 184 144 12 197 138 11 200 144 11
57017 -206 145 10 206 145 10 197 138 11 188 164 115
57018 -195 195 195 198 198 198 174 174 174 14 14 14
57019 - 2 2 6 22 22 22 116 116 116 116 116 116
57020 - 22 22 22 2 2 6 74 74 74 70 70 70
57021 - 30 30 30 10 10 10 0 0 0 0 0 0
57022 - 0 0 0 0 0 0 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 0 0 0 0 0 0
57033 - 0 0 0 0 0 0 6 6 6 18 18 18
57034 - 50 50 50 101 101 101 26 26 26 10 10 10
57035 -138 138 138 190 190 190 174 154 114 156 107 11
57036 -197 138 11 200 144 11 197 138 11 192 133 9
57037 -180 123 7 190 142 34 190 178 144 187 187 187
57038 -202 202 202 221 221 221 214 214 214 66 66 66
57039 - 2 2 6 2 2 6 50 50 50 62 62 62
57040 - 6 6 6 2 2 6 10 10 10 90 90 90
57041 - 50 50 50 18 18 18 6 6 6 0 0 0
57042 - 0 0 0 0 0 0 0 0 0 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 0 0 0 0 0 0 0 0 0
57053 - 0 0 0 0 0 0 10 10 10 34 34 34
57054 - 74 74 74 74 74 74 2 2 6 6 6 6
57055 -144 144 144 198 198 198 190 190 190 178 166 146
57056 -154 121 60 156 107 11 156 107 11 168 124 44
57057 -174 154 114 187 187 187 190 190 190 210 210 210
57058 -246 246 246 253 253 253 253 253 253 182 182 182
57059 - 6 6 6 2 2 6 2 2 6 2 2 6
57060 - 2 2 6 2 2 6 2 2 6 62 62 62
57061 - 74 74 74 34 34 34 14 14 14 0 0 0
57062 - 0 0 0 0 0 0 0 0 0 0 0 0
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 - 0 0 0 0 0 0 0 0 0 0 0 0
57073 - 0 0 0 10 10 10 22 22 22 54 54 54
57074 - 94 94 94 18 18 18 2 2 6 46 46 46
57075 -234 234 234 221 221 221 190 190 190 190 190 190
57076 -190 190 190 187 187 187 187 187 187 190 190 190
57077 -190 190 190 195 195 195 214 214 214 242 242 242
57078 -253 253 253 253 253 253 253 253 253 253 253 253
57079 - 82 82 82 2 2 6 2 2 6 2 2 6
57080 - 2 2 6 2 2 6 2 2 6 14 14 14
57081 - 86 86 86 54 54 54 22 22 22 6 6 6
57082 - 0 0 0 0 0 0 0 0 0 0 0 0
57083 - 0 0 0 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 - 0 0 0 0 0 0 0 0 0 0 0 0
57093 - 6 6 6 18 18 18 46 46 46 90 90 90
57094 - 46 46 46 18 18 18 6 6 6 182 182 182
57095 -253 253 253 246 246 246 206 206 206 190 190 190
57096 -190 190 190 190 190 190 190 190 190 190 190 190
57097 -206 206 206 231 231 231 250 250 250 253 253 253
57098 -253 253 253 253 253 253 253 253 253 253 253 253
57099 -202 202 202 14 14 14 2 2 6 2 2 6
57100 - 2 2 6 2 2 6 2 2 6 2 2 6
57101 - 42 42 42 86 86 86 42 42 42 18 18 18
57102 - 6 6 6 0 0 0 0 0 0 0 0 0
57103 - 0 0 0 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 - 0 0 0 0 0 0 0 0 0 6 6 6
57113 - 14 14 14 38 38 38 74 74 74 66 66 66
57114 - 2 2 6 6 6 6 90 90 90 250 250 250
57115 -253 253 253 253 253 253 238 238 238 198 198 198
57116 -190 190 190 190 190 190 195 195 195 221 221 221
57117 -246 246 246 253 253 253 253 253 253 253 253 253
57118 -253 253 253 253 253 253 253 253 253 253 253 253
57119 -253 253 253 82 82 82 2 2 6 2 2 6
57120 - 2 2 6 2 2 6 2 2 6 2 2 6
57121 - 2 2 6 78 78 78 70 70 70 34 34 34
57122 - 14 14 14 6 6 6 0 0 0 0 0 0
57123 - 0 0 0 0 0 0 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 0 0 0
57132 - 0 0 0 0 0 0 0 0 0 14 14 14
57133 - 34 34 34 66 66 66 78 78 78 6 6 6
57134 - 2 2 6 18 18 18 218 218 218 253 253 253
57135 -253 253 253 253 253 253 253 253 253 246 246 246
57136 -226 226 226 231 231 231 246 246 246 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 253 253 253
57139 -253 253 253 178 178 178 2 2 6 2 2 6
57140 - 2 2 6 2 2 6 2 2 6 2 2 6
57141 - 2 2 6 18 18 18 90 90 90 62 62 62
57142 - 30 30 30 10 10 10 0 0 0 0 0 0
57143 - 0 0 0 0 0 0 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 0 0 0
57152 - 0 0 0 0 0 0 10 10 10 26 26 26
57153 - 58 58 58 90 90 90 18 18 18 2 2 6
57154 - 2 2 6 110 110 110 253 253 253 253 253 253
57155 -253 253 253 253 253 253 253 253 253 253 253 253
57156 -250 250 250 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 231 231 231 18 18 18 2 2 6
57160 - 2 2 6 2 2 6 2 2 6 2 2 6
57161 - 2 2 6 2 2 6 18 18 18 94 94 94
57162 - 54 54 54 26 26 26 10 10 10 0 0 0
57163 - 0 0 0 0 0 0 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 0 0 0
57172 - 0 0 0 6 6 6 22 22 22 50 50 50
57173 - 90 90 90 26 26 26 2 2 6 2 2 6
57174 - 14 14 14 195 195 195 250 250 250 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 -250 250 250 242 242 242 54 54 54 2 2 6
57180 - 2 2 6 2 2 6 2 2 6 2 2 6
57181 - 2 2 6 2 2 6 2 2 6 38 38 38
57182 - 86 86 86 50 50 50 22 22 22 6 6 6
57183 - 0 0 0 0 0 0 0 0 0 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 0 0 0 0 0 0
57192 - 6 6 6 14 14 14 38 38 38 82 82 82
57193 - 34 34 34 2 2 6 2 2 6 2 2 6
57194 - 42 42 42 195 195 195 246 246 246 253 253 253
57195 -253 253 253 253 253 253 253 253 253 250 250 250
57196 -242 242 242 242 242 242 250 250 250 253 253 253
57197 -253 253 253 253 253 253 253 253 253 253 253 253
57198 -253 253 253 250 250 250 246 246 246 238 238 238
57199 -226 226 226 231 231 231 101 101 101 6 6 6
57200 - 2 2 6 2 2 6 2 2 6 2 2 6
57201 - 2 2 6 2 2 6 2 2 6 2 2 6
57202 - 38 38 38 82 82 82 42 42 42 14 14 14
57203 - 6 6 6 0 0 0 0 0 0 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 0 0 0 0 0 0
57212 - 10 10 10 26 26 26 62 62 62 66 66 66
57213 - 2 2 6 2 2 6 2 2 6 6 6 6
57214 - 70 70 70 170 170 170 206 206 206 234 234 234
57215 -246 246 246 250 250 250 250 250 250 238 238 238
57216 -226 226 226 231 231 231 238 238 238 250 250 250
57217 -250 250 250 250 250 250 246 246 246 231 231 231
57218 -214 214 214 206 206 206 202 202 202 202 202 202
57219 -198 198 198 202 202 202 182 182 182 18 18 18
57220 - 2 2 6 2 2 6 2 2 6 2 2 6
57221 - 2 2 6 2 2 6 2 2 6 2 2 6
57222 - 2 2 6 62 62 62 66 66 66 30 30 30
57223 - 10 10 10 0 0 0 0 0 0 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 0 0 0 0 0 0 0 0 0
57232 - 14 14 14 42 42 42 82 82 82 18 18 18
57233 - 2 2 6 2 2 6 2 2 6 10 10 10
57234 - 94 94 94 182 182 182 218 218 218 242 242 242
57235 -250 250 250 253 253 253 253 253 253 250 250 250
57236 -234 234 234 253 253 253 253 253 253 253 253 253
57237 -253 253 253 253 253 253 253 253 253 246 246 246
57238 -238 238 238 226 226 226 210 210 210 202 202 202
57239 -195 195 195 195 195 195 210 210 210 158 158 158
57240 - 6 6 6 14 14 14 50 50 50 14 14 14
57241 - 2 2 6 2 2 6 2 2 6 2 2 6
57242 - 2 2 6 6 6 6 86 86 86 46 46 46
57243 - 18 18 18 6 6 6 0 0 0 0 0 0
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 0 0 0 0 0 0 6 6 6
57252 - 22 22 22 54 54 54 70 70 70 2 2 6
57253 - 2 2 6 10 10 10 2 2 6 22 22 22
57254 -166 166 166 231 231 231 250 250 250 253 253 253
57255 -253 253 253 253 253 253 253 253 253 250 250 250
57256 -242 242 242 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 246 246 246
57259 -231 231 231 206 206 206 198 198 198 226 226 226
57260 - 94 94 94 2 2 6 6 6 6 38 38 38
57261 - 30 30 30 2 2 6 2 2 6 2 2 6
57262 - 2 2 6 2 2 6 62 62 62 66 66 66
57263 - 26 26 26 10 10 10 0 0 0 0 0 0
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 - 0 0 0 0 0 0 0 0 0 10 10 10
57272 - 30 30 30 74 74 74 50 50 50 2 2 6
57273 - 26 26 26 26 26 26 2 2 6 106 106 106
57274 -238 238 238 253 253 253 253 253 253 253 253 253
57275 -253 253 253 253 253 253 253 253 253 253 253 253
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 246 246 246 218 218 218 202 202 202
57280 -210 210 210 14 14 14 2 2 6 2 2 6
57281 - 30 30 30 22 22 22 2 2 6 2 2 6
57282 - 2 2 6 2 2 6 18 18 18 86 86 86
57283 - 42 42 42 14 14 14 0 0 0 0 0 0
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 - 0 0 0 0 0 0 0 0 0 14 14 14
57292 - 42 42 42 90 90 90 22 22 22 2 2 6
57293 - 42 42 42 2 2 6 18 18 18 218 218 218
57294 -253 253 253 253 253 253 253 253 253 253 253 253
57295 -253 253 253 253 253 253 253 253 253 253 253 253
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 250 250 250 221 221 221
57300 -218 218 218 101 101 101 2 2 6 14 14 14
57301 - 18 18 18 38 38 38 10 10 10 2 2 6
57302 - 2 2 6 2 2 6 2 2 6 78 78 78
57303 - 58 58 58 22 22 22 6 6 6 0 0 0
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 0 0 0
57311 - 0 0 0 0 0 0 6 6 6 18 18 18
57312 - 54 54 54 82 82 82 2 2 6 26 26 26
57313 - 22 22 22 2 2 6 123 123 123 253 253 253
57314 -253 253 253 253 253 253 253 253 253 253 253 253
57315 -253 253 253 253 253 253 253 253 253 253 253 253
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 250 250 250
57320 -238 238 238 198 198 198 6 6 6 38 38 38
57321 - 58 58 58 26 26 26 38 38 38 2 2 6
57322 - 2 2 6 2 2 6 2 2 6 46 46 46
57323 - 78 78 78 30 30 30 10 10 10 0 0 0
57324 - 0 0 0 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 0 0 0
57331 - 0 0 0 0 0 0 10 10 10 30 30 30
57332 - 74 74 74 58 58 58 2 2 6 42 42 42
57333 - 2 2 6 22 22 22 231 231 231 253 253 253
57334 -253 253 253 253 253 253 253 253 253 253 253 253
57335 -253 253 253 253 253 253 253 253 253 250 250 250
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 246 246 246 46 46 46 38 38 38
57341 - 42 42 42 14 14 14 38 38 38 14 14 14
57342 - 2 2 6 2 2 6 2 2 6 6 6 6
57343 - 86 86 86 46 46 46 14 14 14 0 0 0
57344 - 0 0 0 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 0 0 0
57351 - 0 0 0 6 6 6 14 14 14 42 42 42
57352 - 90 90 90 18 18 18 18 18 18 26 26 26
57353 - 2 2 6 116 116 116 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 250 250 250 238 238 238
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 94 94 94 6 6 6
57361 - 2 2 6 2 2 6 10 10 10 34 34 34
57362 - 2 2 6 2 2 6 2 2 6 2 2 6
57363 - 74 74 74 58 58 58 22 22 22 6 6 6
57364 - 0 0 0 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 0 0 0 0 0 0
57371 - 0 0 0 10 10 10 26 26 26 66 66 66
57372 - 82 82 82 2 2 6 38 38 38 6 6 6
57373 - 14 14 14 210 210 210 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 246 246 246 242 242 242
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 144 144 144 2 2 6
57381 - 2 2 6 2 2 6 2 2 6 46 46 46
57382 - 2 2 6 2 2 6 2 2 6 2 2 6
57383 - 42 42 42 74 74 74 30 30 30 10 10 10
57384 - 0 0 0 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 0 0 0 0 0 0
57391 - 6 6 6 14 14 14 42 42 42 90 90 90
57392 - 26 26 26 6 6 6 42 42 42 2 2 6
57393 - 74 74 74 250 250 250 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 242 242 242 242 242 242
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 182 182 182 2 2 6
57401 - 2 2 6 2 2 6 2 2 6 46 46 46
57402 - 2 2 6 2 2 6 2 2 6 2 2 6
57403 - 10 10 10 86 86 86 38 38 38 10 10 10
57404 - 0 0 0 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 0 0 0 0 0 0
57411 - 10 10 10 26 26 26 66 66 66 82 82 82
57412 - 2 2 6 22 22 22 18 18 18 2 2 6
57413 -149 149 149 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 234 234 234 242 242 242
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 - 2 2 6 2 2 6 2 2 6 38 38 38
57422 - 2 2 6 2 2 6 2 2 6 2 2 6
57423 - 6 6 6 86 86 86 46 46 46 14 14 14
57424 - 0 0 0 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 0 0 0 6 6 6
57431 - 18 18 18 46 46 46 86 86 86 18 18 18
57432 - 2 2 6 34 34 34 10 10 10 6 6 6
57433 -210 210 210 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 234 234 234 242 242 242
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 221 221 221 6 6 6
57441 - 2 2 6 2 2 6 6 6 6 30 30 30
57442 - 2 2 6 2 2 6 2 2 6 2 2 6
57443 - 2 2 6 82 82 82 54 54 54 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 0 0 0
57450 - 0 0 0 0 0 0 0 0 0 10 10 10
57451 - 26 26 26 66 66 66 62 62 62 2 2 6
57452 - 2 2 6 38 38 38 10 10 10 26 26 26
57453 -238 238 238 253 253 253 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 238 238 238
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 253 253 253
57460 -253 253 253 253 253 253 231 231 231 6 6 6
57461 - 2 2 6 2 2 6 10 10 10 30 30 30
57462 - 2 2 6 2 2 6 2 2 6 2 2 6
57463 - 2 2 6 66 66 66 58 58 58 22 22 22
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 0 0 0 0 0 0 0 0 0
57470 - 0 0 0 0 0 0 0 0 0 10 10 10
57471 - 38 38 38 78 78 78 6 6 6 2 2 6
57472 - 2 2 6 46 46 46 14 14 14 42 42 42
57473 -246 246 246 253 253 253 253 253 253 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 242 242 242
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 253 253 253
57480 -253 253 253 253 253 253 234 234 234 10 10 10
57481 - 2 2 6 2 2 6 22 22 22 14 14 14
57482 - 2 2 6 2 2 6 2 2 6 2 2 6
57483 - 2 2 6 66 66 66 62 62 62 22 22 22
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 - 0 0 0 0 0 0 0 0 0 0 0 0
57490 - 0 0 0 0 0 0 6 6 6 18 18 18
57491 - 50 50 50 74 74 74 2 2 6 2 2 6
57492 - 14 14 14 70 70 70 34 34 34 62 62 62
57493 -250 250 250 253 253 253 253 253 253 253 253 253
57494 -253 253 253 253 253 253 253 253 253 253 253 253
57495 -253 253 253 253 253 253 231 231 231 246 246 246
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 253 253 253
57500 -253 253 253 253 253 253 234 234 234 14 14 14
57501 - 2 2 6 2 2 6 30 30 30 2 2 6
57502 - 2 2 6 2 2 6 2 2 6 2 2 6
57503 - 2 2 6 66 66 66 62 62 62 22 22 22
57504 - 6 6 6 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 - 0 0 0 0 0 0 0 0 0 0 0 0
57510 - 0 0 0 0 0 0 6 6 6 18 18 18
57511 - 54 54 54 62 62 62 2 2 6 2 2 6
57512 - 2 2 6 30 30 30 46 46 46 70 70 70
57513 -250 250 250 253 253 253 253 253 253 253 253 253
57514 -253 253 253 253 253 253 253 253 253 253 253 253
57515 -253 253 253 253 253 253 231 231 231 246 246 246
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 253 253 253 253 253 253 253 253 253
57520 -253 253 253 253 253 253 226 226 226 10 10 10
57521 - 2 2 6 6 6 6 30 30 30 2 2 6
57522 - 2 2 6 2 2 6 2 2 6 2 2 6
57523 - 2 2 6 66 66 66 58 58 58 22 22 22
57524 - 6 6 6 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 0 0 0
57529 - 0 0 0 0 0 0 0 0 0 0 0 0
57530 - 0 0 0 0 0 0 6 6 6 22 22 22
57531 - 58 58 58 62 62 62 2 2 6 2 2 6
57532 - 2 2 6 2 2 6 30 30 30 78 78 78
57533 -250 250 250 253 253 253 253 253 253 253 253 253
57534 -253 253 253 253 253 253 253 253 253 253 253 253
57535 -253 253 253 253 253 253 231 231 231 246 246 246
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 253 253 253 253 253 253 253 253 253
57540 -253 253 253 253 253 253 206 206 206 2 2 6
57541 - 22 22 22 34 34 34 18 14 6 22 22 22
57542 - 26 26 26 18 18 18 6 6 6 2 2 6
57543 - 2 2 6 82 82 82 54 54 54 18 18 18
57544 - 6 6 6 0 0 0 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 0 0 0
57549 - 0 0 0 0 0 0 0 0 0 0 0 0
57550 - 0 0 0 0 0 0 6 6 6 26 26 26
57551 - 62 62 62 106 106 106 74 54 14 185 133 11
57552 -210 162 10 121 92 8 6 6 6 62 62 62
57553 -238 238 238 253 253 253 253 253 253 253 253 253
57554 -253 253 253 253 253 253 253 253 253 253 253 253
57555 -253 253 253 253 253 253 231 231 231 246 246 246
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 253 253 253 253 253 253 253 253 253
57560 -253 253 253 253 253 253 158 158 158 18 18 18
57561 - 14 14 14 2 2 6 2 2 6 2 2 6
57562 - 6 6 6 18 18 18 66 66 66 38 38 38
57563 - 6 6 6 94 94 94 50 50 50 18 18 18
57564 - 6 6 6 0 0 0 0 0 0 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 0 0 0
57569 - 0 0 0 0 0 0 0 0 0 6 6 6
57570 - 10 10 10 10 10 10 18 18 18 38 38 38
57571 - 78 78 78 142 134 106 216 158 10 242 186 14
57572 -246 190 14 246 190 14 156 118 10 10 10 10
57573 - 90 90 90 238 238 238 253 253 253 253 253 253
57574 -253 253 253 253 253 253 253 253 253 253 253 253
57575 -253 253 253 253 253 253 231 231 231 250 250 250
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 -253 253 253 253 253 253 253 253 253 246 230 190
57580 -238 204 91 238 204 91 181 142 44 37 26 9
57581 - 2 2 6 2 2 6 2 2 6 2 2 6
57582 - 2 2 6 2 2 6 38 38 38 46 46 46
57583 - 26 26 26 106 106 106 54 54 54 18 18 18
57584 - 6 6 6 0 0 0 0 0 0 0 0 0
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 0 0 0
57589 - 0 0 0 6 6 6 14 14 14 22 22 22
57590 - 30 30 30 38 38 38 50 50 50 70 70 70
57591 -106 106 106 190 142 34 226 170 11 242 186 14
57592 -246 190 14 246 190 14 246 190 14 154 114 10
57593 - 6 6 6 74 74 74 226 226 226 253 253 253
57594 -253 253 253 253 253 253 253 253 253 253 253 253
57595 -253 253 253 253 253 253 231 231 231 250 250 250
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 -253 253 253 253 253 253 253 253 253 228 184 62
57600 -241 196 14 241 208 19 232 195 16 38 30 10
57601 - 2 2 6 2 2 6 2 2 6 2 2 6
57602 - 2 2 6 6 6 6 30 30 30 26 26 26
57603 -203 166 17 154 142 90 66 66 66 26 26 26
57604 - 6 6 6 0 0 0 0 0 0 0 0 0
57605 - 0 0 0 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 0 0 0
57609 - 6 6 6 18 18 18 38 38 38 58 58 58
57610 - 78 78 78 86 86 86 101 101 101 123 123 123
57611 -175 146 61 210 150 10 234 174 13 246 186 14
57612 -246 190 14 246 190 14 246 190 14 238 190 10
57613 -102 78 10 2 2 6 46 46 46 198 198 198
57614 -253 253 253 253 253 253 253 253 253 253 253 253
57615 -253 253 253 253 253 253 234 234 234 242 242 242
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 253 253 253 253 253 253 224 178 62
57620 -242 186 14 241 196 14 210 166 10 22 18 6
57621 - 2 2 6 2 2 6 2 2 6 2 2 6
57622 - 2 2 6 2 2 6 6 6 6 121 92 8
57623 -238 202 15 232 195 16 82 82 82 34 34 34
57624 - 10 10 10 0 0 0 0 0 0 0 0 0
57625 - 0 0 0 0 0 0 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 0 0 0
57629 - 14 14 14 38 38 38 70 70 70 154 122 46
57630 -190 142 34 200 144 11 197 138 11 197 138 11
57631 -213 154 11 226 170 11 242 186 14 246 190 14
57632 -246 190 14 246 190 14 246 190 14 246 190 14
57633 -225 175 15 46 32 6 2 2 6 22 22 22
57634 -158 158 158 250 250 250 253 253 253 253 253 253
57635 -253 253 253 253 253 253 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 250 250 250 242 242 242 224 178 62
57640 -239 182 13 236 186 11 213 154 11 46 32 6
57641 - 2 2 6 2 2 6 2 2 6 2 2 6
57642 - 2 2 6 2 2 6 61 42 6 225 175 15
57643 -238 190 10 236 186 11 112 100 78 42 42 42
57644 - 14 14 14 0 0 0 0 0 0 0 0 0
57645 - 0 0 0 0 0 0 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 - 22 22 22 54 54 54 154 122 46 213 154 11
57650 -226 170 11 230 174 11 226 170 11 226 170 11
57651 -236 178 12 242 186 14 246 190 14 246 190 14
57652 -246 190 14 246 190 14 246 190 14 246 190 14
57653 -241 196 14 184 144 12 10 10 10 2 2 6
57654 - 6 6 6 116 116 116 242 242 242 253 253 253
57655 -253 253 253 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 -253 253 253 231 231 231 198 198 198 214 170 54
57660 -236 178 12 236 178 12 210 150 10 137 92 6
57661 - 18 14 6 2 2 6 2 2 6 2 2 6
57662 - 6 6 6 70 47 6 200 144 11 236 178 12
57663 -239 182 13 239 182 13 124 112 88 58 58 58
57664 - 22 22 22 6 6 6 0 0 0 0 0 0
57665 - 0 0 0 0 0 0 0 0 0 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 70 70 70 180 133 36 226 170 11
57670 -239 182 13 242 186 14 242 186 14 246 186 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 232 195 16 98 70 6 2 2 6
57674 - 2 2 6 2 2 6 66 66 66 221 221 221
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 253 253 253
57679 -253 253 253 206 206 206 198 198 198 214 166 58
57680 -230 174 11 230 174 11 216 158 10 192 133 9
57681 -163 110 8 116 81 8 102 78 10 116 81 8
57682 -167 114 7 197 138 11 226 170 11 239 182 13
57683 -242 186 14 242 186 14 162 146 94 78 78 78
57684 - 34 34 34 14 14 14 6 6 6 0 0 0
57685 - 0 0 0 0 0 0 0 0 0 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 6 6 6
57689 - 30 30 30 78 78 78 190 142 34 226 170 11
57690 -239 182 13 246 190 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 241 196 14 203 166 17 22 18 6
57694 - 2 2 6 2 2 6 2 2 6 38 38 38
57695 -218 218 218 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 253 253 253 253 253 253 253 253 253
57699 -250 250 250 206 206 206 198 198 198 202 162 69
57700 -226 170 11 236 178 12 224 166 10 210 150 10
57701 -200 144 11 197 138 11 192 133 9 197 138 11
57702 -210 150 10 226 170 11 242 186 14 246 190 14
57703 -246 190 14 246 186 14 225 175 15 124 112 88
57704 - 62 62 62 30 30 30 14 14 14 6 6 6
57705 - 0 0 0 0 0 0 0 0 0 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 0 0 0 10 10 10
57709 - 30 30 30 78 78 78 174 135 50 224 166 10
57710 -239 182 13 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 241 196 14 139 102 15
57714 - 2 2 6 2 2 6 2 2 6 2 2 6
57715 - 78 78 78 250 250 250 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 -253 253 253 253 253 253 253 253 253 253 253 253
57719 -250 250 250 214 214 214 198 198 198 190 150 46
57720 -219 162 10 236 178 12 234 174 13 224 166 10
57721 -216 158 10 213 154 11 213 154 11 216 158 10
57722 -226 170 11 239 182 13 246 190 14 246 190 14
57723 -246 190 14 246 190 14 242 186 14 206 162 42
57724 -101 101 101 58 58 58 30 30 30 14 14 14
57725 - 6 6 6 0 0 0 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 0 0 0 10 10 10
57729 - 30 30 30 74 74 74 174 135 50 216 158 10
57730 -236 178 12 246 190 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 241 196 14 226 184 13
57734 - 61 42 6 2 2 6 2 2 6 2 2 6
57735 - 22 22 22 238 238 238 253 253 253 253 253 253
57736 -253 253 253 253 253 253 253 253 253 253 253 253
57737 -253 253 253 253 253 253 253 253 253 253 253 253
57738 -253 253 253 253 253 253 253 253 253 253 253 253
57739 -253 253 253 226 226 226 187 187 187 180 133 36
57740 -216 158 10 236 178 12 239 182 13 236 178 12
57741 -230 174 11 226 170 11 226 170 11 230 174 11
57742 -236 178 12 242 186 14 246 190 14 246 190 14
57743 -246 190 14 246 190 14 246 186 14 239 182 13
57744 -206 162 42 106 106 106 66 66 66 34 34 34
57745 - 14 14 14 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 0 0 0 6 6 6
57749 - 26 26 26 70 70 70 163 133 67 213 154 11
57750 -236 178 12 246 190 14 246 190 14 246 190 14
57751 -246 190 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 241 196 14
57754 -190 146 13 18 14 6 2 2 6 2 2 6
57755 - 46 46 46 246 246 246 253 253 253 253 253 253
57756 -253 253 253 253 253 253 253 253 253 253 253 253
57757 -253 253 253 253 253 253 253 253 253 253 253 253
57758 -253 253 253 253 253 253 253 253 253 253 253 253
57759 -253 253 253 221 221 221 86 86 86 156 107 11
57760 -216 158 10 236 178 12 242 186 14 246 186 14
57761 -242 186 14 239 182 13 239 182 13 242 186 14
57762 -242 186 14 246 186 14 246 190 14 246 190 14
57763 -246 190 14 246 190 14 246 190 14 246 190 14
57764 -242 186 14 225 175 15 142 122 72 66 66 66
57765 - 30 30 30 10 10 10 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 0 0 0 6 6 6
57769 - 26 26 26 70 70 70 163 133 67 210 150 10
57770 -236 178 12 246 190 14 246 190 14 246 190 14
57771 -246 190 14 246 190 14 246 190 14 246 190 14
57772 -246 190 14 246 190 14 246 190 14 246 190 14
57773 -246 190 14 246 190 14 246 190 14 246 190 14
57774 -232 195 16 121 92 8 34 34 34 106 106 106
57775 -221 221 221 253 253 253 253 253 253 253 253 253
57776 -253 253 253 253 253 253 253 253 253 253 253 253
57777 -253 253 253 253 253 253 253 253 253 253 253 253
57778 -253 253 253 253 253 253 253 253 253 253 253 253
57779 -242 242 242 82 82 82 18 14 6 163 110 8
57780 -216 158 10 236 178 12 242 186 14 246 190 14
57781 -246 190 14 246 190 14 246 190 14 246 190 14
57782 -246 190 14 246 190 14 246 190 14 246 190 14
57783 -246 190 14 246 190 14 246 190 14 246 190 14
57784 -246 190 14 246 190 14 242 186 14 163 133 67
57785 - 46 46 46 18 18 18 6 6 6 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 10 10 10
57789 - 30 30 30 78 78 78 163 133 67 210 150 10
57790 -236 178 12 246 186 14 246 190 14 246 190 14
57791 -246 190 14 246 190 14 246 190 14 246 190 14
57792 -246 190 14 246 190 14 246 190 14 246 190 14
57793 -246 190 14 246 190 14 246 190 14 246 190 14
57794 -241 196 14 215 174 15 190 178 144 253 253 253
57795 -253 253 253 253 253 253 253 253 253 253 253 253
57796 -253 253 253 253 253 253 253 253 253 253 253 253
57797 -253 253 253 253 253 253 253 253 253 253 253 253
57798 -253 253 253 253 253 253 253 253 253 218 218 218
57799 - 58 58 58 2 2 6 22 18 6 167 114 7
57800 -216 158 10 236 178 12 246 186 14 246 190 14
57801 -246 190 14 246 190 14 246 190 14 246 190 14
57802 -246 190 14 246 190 14 246 190 14 246 190 14
57803 -246 190 14 246 190 14 246 190 14 246 190 14
57804 -246 190 14 246 186 14 242 186 14 190 150 46
57805 - 54 54 54 22 22 22 6 6 6 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 14 14 14
57809 - 38 38 38 86 86 86 180 133 36 213 154 11
57810 -236 178 12 246 186 14 246 190 14 246 190 14
57811 -246 190 14 246 190 14 246 190 14 246 190 14
57812 -246 190 14 246 190 14 246 190 14 246 190 14
57813 -246 190 14 246 190 14 246 190 14 246 190 14
57814 -246 190 14 232 195 16 190 146 13 214 214 214
57815 -253 253 253 253 253 253 253 253 253 253 253 253
57816 -253 253 253 253 253 253 253 253 253 253 253 253
57817 -253 253 253 253 253 253 253 253 253 253 253 253
57818 -253 253 253 250 250 250 170 170 170 26 26 26
57819 - 2 2 6 2 2 6 37 26 9 163 110 8
57820 -219 162 10 239 182 13 246 186 14 246 190 14
57821 -246 190 14 246 190 14 246 190 14 246 190 14
57822 -246 190 14 246 190 14 246 190 14 246 190 14
57823 -246 190 14 246 190 14 246 190 14 246 190 14
57824 -246 186 14 236 178 12 224 166 10 142 122 72
57825 - 46 46 46 18 18 18 6 6 6 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 6 6 6 18 18 18
57829 - 50 50 50 109 106 95 192 133 9 224 166 10
57830 -242 186 14 246 190 14 246 190 14 246 190 14
57831 -246 190 14 246 190 14 246 190 14 246 190 14
57832 -246 190 14 246 190 14 246 190 14 246 190 14
57833 -246 190 14 246 190 14 246 190 14 246 190 14
57834 -242 186 14 226 184 13 210 162 10 142 110 46
57835 -226 226 226 253 253 253 253 253 253 253 253 253
57836 -253 253 253 253 253 253 253 253 253 253 253 253
57837 -253 253 253 253 253 253 253 253 253 253 253 253
57838 -198 198 198 66 66 66 2 2 6 2 2 6
57839 - 2 2 6 2 2 6 50 34 6 156 107 11
57840 -219 162 10 239 182 13 246 186 14 246 190 14
57841 -246 190 14 246 190 14 246 190 14 246 190 14
57842 -246 190 14 246 190 14 246 190 14 246 190 14
57843 -246 190 14 246 190 14 246 190 14 242 186 14
57844 -234 174 13 213 154 11 154 122 46 66 66 66
57845 - 30 30 30 10 10 10 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 6 6 6 22 22 22
57849 - 58 58 58 154 121 60 206 145 10 234 174 13
57850 -242 186 14 246 186 14 246 190 14 246 190 14
57851 -246 190 14 246 190 14 246 190 14 246 190 14
57852 -246 190 14 246 190 14 246 190 14 246 190 14
57853 -246 190 14 246 190 14 246 190 14 246 190 14
57854 -246 186 14 236 178 12 210 162 10 163 110 8
57855 - 61 42 6 138 138 138 218 218 218 250 250 250
57856 -253 253 253 253 253 253 253 253 253 250 250 250
57857 -242 242 242 210 210 210 144 144 144 66 66 66
57858 - 6 6 6 2 2 6 2 2 6 2 2 6
57859 - 2 2 6 2 2 6 61 42 6 163 110 8
57860 -216 158 10 236 178 12 246 190 14 246 190 14
57861 -246 190 14 246 190 14 246 190 14 246 190 14
57862 -246 190 14 246 190 14 246 190 14 246 190 14
57863 -246 190 14 239 182 13 230 174 11 216 158 10
57864 -190 142 34 124 112 88 70 70 70 38 38 38
57865 - 18 18 18 6 6 6 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 6 6 6 22 22 22
57869 - 62 62 62 168 124 44 206 145 10 224 166 10
57870 -236 178 12 239 182 13 242 186 14 242 186 14
57871 -246 186 14 246 190 14 246 190 14 246 190 14
57872 -246 190 14 246 190 14 246 190 14 246 190 14
57873 -246 190 14 246 190 14 246 190 14 246 190 14
57874 -246 190 14 236 178 12 216 158 10 175 118 6
57875 - 80 54 7 2 2 6 6 6 6 30 30 30
57876 - 54 54 54 62 62 62 50 50 50 38 38 38
57877 - 14 14 14 2 2 6 2 2 6 2 2 6
57878 - 2 2 6 2 2 6 2 2 6 2 2 6
57879 - 2 2 6 6 6 6 80 54 7 167 114 7
57880 -213 154 11 236 178 12 246 190 14 246 190 14
57881 -246 190 14 246 190 14 246 190 14 246 190 14
57882 -246 190 14 242 186 14 239 182 13 239 182 13
57883 -230 174 11 210 150 10 174 135 50 124 112 88
57884 - 82 82 82 54 54 54 34 34 34 18 18 18
57885 - 6 6 6 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 6 6 6 18 18 18
57889 - 50 50 50 158 118 36 192 133 9 200 144 11
57890 -216 158 10 219 162 10 224 166 10 226 170 11
57891 -230 174 11 236 178 12 239 182 13 239 182 13
57892 -242 186 14 246 186 14 246 190 14 246 190 14
57893 -246 190 14 246 190 14 246 190 14 246 190 14
57894 -246 186 14 230 174 11 210 150 10 163 110 8
57895 -104 69 6 10 10 10 2 2 6 2 2 6
57896 - 2 2 6 2 2 6 2 2 6 2 2 6
57897 - 2 2 6 2 2 6 2 2 6 2 2 6
57898 - 2 2 6 2 2 6 2 2 6 2 2 6
57899 - 2 2 6 6 6 6 91 60 6 167 114 7
57900 -206 145 10 230 174 11 242 186 14 246 190 14
57901 -246 190 14 246 190 14 246 186 14 242 186 14
57902 -239 182 13 230 174 11 224 166 10 213 154 11
57903 -180 133 36 124 112 88 86 86 86 58 58 58
57904 - 38 38 38 22 22 22 10 10 10 6 6 6
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 14 14 14
57909 - 34 34 34 70 70 70 138 110 50 158 118 36
57910 -167 114 7 180 123 7 192 133 9 197 138 11
57911 -200 144 11 206 145 10 213 154 11 219 162 10
57912 -224 166 10 230 174 11 239 182 13 242 186 14
57913 -246 186 14 246 186 14 246 186 14 246 186 14
57914 -239 182 13 216 158 10 185 133 11 152 99 6
57915 -104 69 6 18 14 6 2 2 6 2 2 6
57916 - 2 2 6 2 2 6 2 2 6 2 2 6
57917 - 2 2 6 2 2 6 2 2 6 2 2 6
57918 - 2 2 6 2 2 6 2 2 6 2 2 6
57919 - 2 2 6 6 6 6 80 54 7 152 99 6
57920 -192 133 9 219 162 10 236 178 12 239 182 13
57921 -246 186 14 242 186 14 239 182 13 236 178 12
57922 -224 166 10 206 145 10 192 133 9 154 121 60
57923 - 94 94 94 62 62 62 42 42 42 22 22 22
57924 - 14 14 14 6 6 6 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 6 6 6
57929 - 18 18 18 34 34 34 58 58 58 78 78 78
57930 -101 98 89 124 112 88 142 110 46 156 107 11
57931 -163 110 8 167 114 7 175 118 6 180 123 7
57932 -185 133 11 197 138 11 210 150 10 219 162 10
57933 -226 170 11 236 178 12 236 178 12 234 174 13
57934 -219 162 10 197 138 11 163 110 8 130 83 6
57935 - 91 60 6 10 10 10 2 2 6 2 2 6
57936 - 18 18 18 38 38 38 38 38 38 38 38 38
57937 - 38 38 38 38 38 38 38 38 38 38 38 38
57938 - 38 38 38 38 38 38 26 26 26 2 2 6
57939 - 2 2 6 6 6 6 70 47 6 137 92 6
57940 -175 118 6 200 144 11 219 162 10 230 174 11
57941 -234 174 13 230 174 11 219 162 10 210 150 10
57942 -192 133 9 163 110 8 124 112 88 82 82 82
57943 - 50 50 50 30 30 30 14 14 14 6 6 6
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 - 0 0 0 0 0 0 0 0 0 0 0 0
57948 - 0 0 0 0 0 0 0 0 0 0 0 0
57949 - 6 6 6 14 14 14 22 22 22 34 34 34
57950 - 42 42 42 58 58 58 74 74 74 86 86 86
57951 -101 98 89 122 102 70 130 98 46 121 87 25
57952 -137 92 6 152 99 6 163 110 8 180 123 7
57953 -185 133 11 197 138 11 206 145 10 200 144 11
57954 -180 123 7 156 107 11 130 83 6 104 69 6
57955 - 50 34 6 54 54 54 110 110 110 101 98 89
57956 - 86 86 86 82 82 82 78 78 78 78 78 78
57957 - 78 78 78 78 78 78 78 78 78 78 78 78
57958 - 78 78 78 82 82 82 86 86 86 94 94 94
57959 -106 106 106 101 101 101 86 66 34 124 80 6
57960 -156 107 11 180 123 7 192 133 9 200 144 11
57961 -206 145 10 200 144 11 192 133 9 175 118 6
57962 -139 102 15 109 106 95 70 70 70 42 42 42
57963 - 22 22 22 10 10 10 0 0 0 0 0 0
57964 - 0 0 0 0 0 0 0 0 0 0 0 0
57965 - 0 0 0 0 0 0 0 0 0 0 0 0
57966 - 0 0 0 0 0 0 0 0 0 0 0 0
57967 - 0 0 0 0 0 0 0 0 0 0 0 0
57968 - 0 0 0 0 0 0 0 0 0 0 0 0
57969 - 0 0 0 0 0 0 6 6 6 10 10 10
57970 - 14 14 14 22 22 22 30 30 30 38 38 38
57971 - 50 50 50 62 62 62 74 74 74 90 90 90
57972 -101 98 89 112 100 78 121 87 25 124 80 6
57973 -137 92 6 152 99 6 152 99 6 152 99 6
57974 -138 86 6 124 80 6 98 70 6 86 66 30
57975 -101 98 89 82 82 82 58 58 58 46 46 46
57976 - 38 38 38 34 34 34 34 34 34 34 34 34
57977 - 34 34 34 34 34 34 34 34 34 34 34 34
57978 - 34 34 34 34 34 34 38 38 38 42 42 42
57979 - 54 54 54 82 82 82 94 86 76 91 60 6
57980 -134 86 6 156 107 11 167 114 7 175 118 6
57981 -175 118 6 167 114 7 152 99 6 121 87 25
57982 -101 98 89 62 62 62 34 34 34 18 18 18
57983 - 6 6 6 0 0 0 0 0 0 0 0 0
57984 - 0 0 0 0 0 0 0 0 0 0 0 0
57985 - 0 0 0 0 0 0 0 0 0 0 0 0
57986 - 0 0 0 0 0 0 0 0 0 0 0 0
57987 - 0 0 0 0 0 0 0 0 0 0 0 0
57988 - 0 0 0 0 0 0 0 0 0 0 0 0
57989 - 0 0 0 0 0 0 0 0 0 0 0 0
57990 - 0 0 0 6 6 6 6 6 6 10 10 10
57991 - 18 18 18 22 22 22 30 30 30 42 42 42
57992 - 50 50 50 66 66 66 86 86 86 101 98 89
57993 -106 86 58 98 70 6 104 69 6 104 69 6
57994 -104 69 6 91 60 6 82 62 34 90 90 90
57995 - 62 62 62 38 38 38 22 22 22 14 14 14
57996 - 10 10 10 10 10 10 10 10 10 10 10 10
57997 - 10 10 10 10 10 10 6 6 6 10 10 10
57998 - 10 10 10 10 10 10 10 10 10 14 14 14
57999 - 22 22 22 42 42 42 70 70 70 89 81 66
58000 - 80 54 7 104 69 6 124 80 6 137 92 6
58001 -134 86 6 116 81 8 100 82 52 86 86 86
58002 - 58 58 58 30 30 30 14 14 14 6 6 6
58003 - 0 0 0 0 0 0 0 0 0 0 0 0
58004 - 0 0 0 0 0 0 0 0 0 0 0 0
58005 - 0 0 0 0 0 0 0 0 0 0 0 0
58006 - 0 0 0 0 0 0 0 0 0 0 0 0
58007 - 0 0 0 0 0 0 0 0 0 0 0 0
58008 - 0 0 0 0 0 0 0 0 0 0 0 0
58009 - 0 0 0 0 0 0 0 0 0 0 0 0
58010 - 0 0 0 0 0 0 0 0 0 0 0 0
58011 - 0 0 0 6 6 6 10 10 10 14 14 14
58012 - 18 18 18 26 26 26 38 38 38 54 54 54
58013 - 70 70 70 86 86 86 94 86 76 89 81 66
58014 - 89 81 66 86 86 86 74 74 74 50 50 50
58015 - 30 30 30 14 14 14 6 6 6 0 0 0
58016 - 0 0 0 0 0 0 0 0 0 0 0 0
58017 - 0 0 0 0 0 0 0 0 0 0 0 0
58018 - 0 0 0 0 0 0 0 0 0 0 0 0
58019 - 6 6 6 18 18 18 34 34 34 58 58 58
58020 - 82 82 82 89 81 66 89 81 66 89 81 66
58021 - 94 86 66 94 86 76 74 74 74 50 50 50
58022 - 26 26 26 14 14 14 6 6 6 0 0 0
58023 - 0 0 0 0 0 0 0 0 0 0 0 0
58024 - 0 0 0 0 0 0 0 0 0 0 0 0
58025 - 0 0 0 0 0 0 0 0 0 0 0 0
58026 - 0 0 0 0 0 0 0 0 0 0 0 0
58027 - 0 0 0 0 0 0 0 0 0 0 0 0
58028 - 0 0 0 0 0 0 0 0 0 0 0 0
58029 - 0 0 0 0 0 0 0 0 0 0 0 0
58030 - 0 0 0 0 0 0 0 0 0 0 0 0
58031 - 0 0 0 0 0 0 0 0 0 0 0 0
58032 - 6 6 6 6 6 6 14 14 14 18 18 18
58033 - 30 30 30 38 38 38 46 46 46 54 54 54
58034 - 50 50 50 42 42 42 30 30 30 18 18 18
58035 - 10 10 10 0 0 0 0 0 0 0 0 0
58036 - 0 0 0 0 0 0 0 0 0 0 0 0
58037 - 0 0 0 0 0 0 0 0 0 0 0 0
58038 - 0 0 0 0 0 0 0 0 0 0 0 0
58039 - 0 0 0 6 6 6 14 14 14 26 26 26
58040 - 38 38 38 50 50 50 58 58 58 58 58 58
58041 - 54 54 54 42 42 42 30 30 30 18 18 18
58042 - 10 10 10 0 0 0 0 0 0 0 0 0
58043 - 0 0 0 0 0 0 0 0 0 0 0 0
58044 - 0 0 0 0 0 0 0 0 0 0 0 0
58045 - 0 0 0 0 0 0 0 0 0 0 0 0
58046 - 0 0 0 0 0 0 0 0 0 0 0 0
58047 - 0 0 0 0 0 0 0 0 0 0 0 0
58048 - 0 0 0 0 0 0 0 0 0 0 0 0
58049 - 0 0 0 0 0 0 0 0 0 0 0 0
58050 - 0 0 0 0 0 0 0 0 0 0 0 0
58051 - 0 0 0 0 0 0 0 0 0 0 0 0
58052 - 0 0 0 0 0 0 0 0 0 6 6 6
58053 - 6 6 6 10 10 10 14 14 14 18 18 18
58054 - 18 18 18 14 14 14 10 10 10 6 6 6
58055 - 0 0 0 0 0 0 0 0 0 0 0 0
58056 - 0 0 0 0 0 0 0 0 0 0 0 0
58057 - 0 0 0 0 0 0 0 0 0 0 0 0
58058 - 0 0 0 0 0 0 0 0 0 0 0 0
58059 - 0 0 0 0 0 0 0 0 0 6 6 6
58060 - 14 14 14 18 18 18 22 22 22 22 22 22
58061 - 18 18 18 14 14 14 10 10 10 6 6 6
58062 - 0 0 0 0 0 0 0 0 0 0 0 0
58063 - 0 0 0 0 0 0 0 0 0 0 0 0
58064 - 0 0 0 0 0 0 0 0 0 0 0 0
58065 - 0 0 0 0 0 0 0 0 0 0 0 0
58066 - 0 0 0 0 0 0 0 0 0 0 0 0
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 4 4 4 4 4 4 4 4 4 4 4 4
58069 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58070 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58071 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58072 +4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
58077 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58078 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58079 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58080 +4 4 4 4 4 4
58081 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58082 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58083 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58084 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58085 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58086 +4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58091 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58092 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58093 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58094 +4 4 4 4 4 4
58095 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58096 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58097 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58098 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58099 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58100 +4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4
58104 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58105 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58106 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58107 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58108 +4 4 4 4 4 4
58109 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58110 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58111 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58112 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58113 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58114 +4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4
58118 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58119 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58120 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58121 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58122 +4 4 4 4 4 4
58123 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58124 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58125 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58126 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58127 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58128 +4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4
58132 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58133 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58134 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58135 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58136 +4 4 4 4 4 4
58137 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58138 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58139 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58140 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58141 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58142 +4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58146 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58147 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58148 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58149 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58150 +4 4 4 4 4 4
58151 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58152 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58153 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58154 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58155 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
58156 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 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 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58160 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
58161 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
58162 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
58163 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58164 +4 4 4 4 4 4
58165 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58166 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58167 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58168 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58169 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
58170 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
58171 +5 5 5 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 4 4 4 4 4 4
58173 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58174 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
58175 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
58176 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
58177 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58178 +4 4 4 4 4 4
58179 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58180 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58181 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58182 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58183 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
58184 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
58185 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
58186 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58187 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58188 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
58189 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
58190 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
58191 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
58192 +4 4 4 4 4 4
58193 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58194 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58195 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58196 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
58197 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
58198 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
58199 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
58200 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58201 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
58202 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
58203 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
58204 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
58205 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
58206 +4 4 4 4 4 4
58207 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58208 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58209 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58210 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
58211 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
58212 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
58213 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
58214 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
58215 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
58216 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
58217 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
58218 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
58219 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
58220 +4 4 4 4 4 4
58221 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58222 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58223 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
58224 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
58225 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
58226 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
58227 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
58228 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
58229 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
58230 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
58231 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
58232 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
58233 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
58234 +4 4 4 4 4 4
58235 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58236 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58237 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
58238 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
58239 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
58240 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
58241 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
58242 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
58243 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
58244 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
58245 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
58246 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
58247 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
58248 +4 4 4 4 4 4
58249 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58250 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58251 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
58252 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
58253 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
58254 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
58255 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
58256 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
58257 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
58258 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
58259 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
58260 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
58261 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
58262 +4 4 4 4 4 4
58263 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58264 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58265 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
58266 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
58267 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
58268 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
58269 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
58270 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
58271 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
58272 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
58273 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
58274 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
58275 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
58276 +4 4 4 4 4 4
58277 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58278 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58279 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
58280 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
58281 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
58282 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
58283 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
58284 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
58285 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
58286 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
58287 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
58288 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
58289 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
58290 +4 4 4 4 4 4
58291 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58292 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
58293 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
58294 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
58295 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
58296 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
58297 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
58298 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
58299 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
58300 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
58301 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
58302 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
58303 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
58304 +4 4 4 4 4 4
58305 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58306 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
58307 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
58308 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
58309 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
58310 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
58311 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
58312 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
58313 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
58314 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
58315 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
58316 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
58317 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
58318 +0 0 0 4 4 4
58319 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
58320 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
58321 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
58322 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
58323 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
58324 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
58325 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
58326 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
58327 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
58328 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
58329 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
58330 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
58331 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
58332 +2 0 0 0 0 0
58333 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
58334 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
58335 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
58336 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
58337 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
58338 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
58339 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
58340 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
58341 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
58342 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
58343 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
58344 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
58345 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
58346 +37 38 37 0 0 0
58347 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
58348 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
58349 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
58350 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
58351 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
58352 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
58353 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
58354 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
58355 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
58356 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
58357 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
58358 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
58359 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
58360 +85 115 134 4 0 0
58361 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
58362 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
58363 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
58364 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
58365 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
58366 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
58367 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
58368 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
58369 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
58370 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
58371 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
58372 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
58373 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
58374 +60 73 81 4 0 0
58375 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
58376 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
58377 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
58378 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
58379 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
58380 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
58381 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
58382 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
58383 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
58384 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
58385 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
58386 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
58387 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
58388 +16 19 21 4 0 0
58389 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
58390 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
58391 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
58392 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
58393 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
58394 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
58395 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
58396 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
58397 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
58398 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
58399 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
58400 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
58401 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
58402 +4 0 0 4 3 3
58403 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
58404 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
58405 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
58406 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
58407 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
58408 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
58409 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
58410 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
58411 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
58412 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
58413 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
58414 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
58415 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
58416 +3 2 2 4 4 4
58417 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
58418 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
58419 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
58420 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
58421 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
58422 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
58423 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
58424 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
58425 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
58426 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
58427 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
58428 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
58429 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
58430 +4 4 4 4 4 4
58431 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
58432 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
58433 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
58434 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
58435 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
58436 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
58437 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
58438 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
58439 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
58440 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
58441 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
58442 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
58443 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
58444 +4 4 4 4 4 4
58445 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
58446 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
58447 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
58448 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
58449 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
58450 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
58451 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
58452 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
58453 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
58454 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
58455 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
58456 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
58457 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
58458 +5 5 5 5 5 5
58459 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
58460 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
58461 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
58462 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
58463 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
58464 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
58465 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
58466 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
58467 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
58468 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
58469 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
58470 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
58471 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
58472 +5 5 5 4 4 4
58473 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
58474 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
58475 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
58476 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
58477 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
58478 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
58479 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
58480 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
58481 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
58482 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
58483 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
58484 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
58485 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58486 +4 4 4 4 4 4
58487 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
58488 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
58489 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
58490 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
58491 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
58492 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
58493 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
58494 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
58495 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
58496 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
58497 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
58498 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
58499 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58500 +4 4 4 4 4 4
58501 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
58502 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
58503 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
58504 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
58505 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
58506 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
58507 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
58508 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
58509 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
58510 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
58511 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
58512 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58513 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58514 +4 4 4 4 4 4
58515 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
58516 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
58517 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
58518 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
58519 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
58520 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
58521 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
58522 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
58523 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
58524 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
58525 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
58526 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58527 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58528 +4 4 4 4 4 4
58529 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
58530 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
58531 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
58532 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
58533 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
58534 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
58535 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
58536 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
58537 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
58538 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
58539 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58540 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58541 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58542 +4 4 4 4 4 4
58543 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
58544 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
58545 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
58546 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
58547 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
58548 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
58549 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
58550 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
58551 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
58552 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
58553 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
58554 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58555 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58556 +4 4 4 4 4 4
58557 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
58558 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
58559 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
58560 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
58561 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
58562 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
58563 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
58564 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
58565 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
58566 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
58567 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
58568 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58569 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58570 +4 4 4 4 4 4
58571 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
58572 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
58573 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
58574 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
58575 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
58576 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
58577 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
58578 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
58579 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
58580 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
58581 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58582 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58583 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58584 +4 4 4 4 4 4
58585 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
58586 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
58587 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
58588 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
58589 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
58590 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
58591 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
58592 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
58593 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
58594 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
58595 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58596 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58597 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58598 +4 4 4 4 4 4
58599 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
58600 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
58601 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
58602 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
58603 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
58604 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
58605 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
58606 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
58607 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
58608 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
58609 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58610 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58611 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58612 +4 4 4 4 4 4
58613 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
58614 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
58615 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
58616 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
58617 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
58618 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
58619 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
58620 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
58621 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
58622 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58623 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58624 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58625 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58626 +4 4 4 4 4 4
58627 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
58628 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
58629 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
58630 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
58631 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
58632 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
58633 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
58634 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
58635 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
58636 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58637 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58638 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58639 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58640 +4 4 4 4 4 4
58641 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
58642 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
58643 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
58644 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
58645 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
58646 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
58647 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
58648 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
58649 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
58650 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58651 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58652 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58653 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58654 +4 4 4 4 4 4
58655 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
58656 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
58657 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
58658 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
58659 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
58660 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
58661 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
58662 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
58663 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
58664 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58665 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58666 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58667 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58668 +4 4 4 4 4 4
58669 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
58670 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
58671 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
58672 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
58673 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
58674 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
58675 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
58676 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
58677 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
58678 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58679 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58680 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58681 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58682 +4 4 4 4 4 4
58683 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
58684 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
58685 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
58686 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
58687 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
58688 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
58689 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
58690 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
58691 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
58692 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58693 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58694 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58695 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58696 +4 4 4 4 4 4
58697 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
58698 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
58699 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
58700 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
58701 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
58702 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
58703 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
58704 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
58705 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
58706 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58707 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58708 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58709 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58710 +4 4 4 4 4 4
58711 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
58712 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
58713 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
58714 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
58715 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
58716 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
58717 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
58718 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
58719 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
58720 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58721 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58722 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58723 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58724 +4 4 4 4 4 4
58725 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
58726 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
58727 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
58728 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
58729 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
58730 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
58731 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
58732 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
58733 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
58734 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58735 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58736 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58737 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58738 +4 4 4 4 4 4
58739 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
58740 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
58741 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
58742 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
58743 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
58744 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
58745 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
58746 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
58747 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
58748 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58749 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58750 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58751 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58752 +4 4 4 4 4 4
58753 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
58754 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
58755 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
58756 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
58757 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
58758 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
58759 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
58760 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
58761 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
58762 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58763 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58764 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58765 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58766 +4 4 4 4 4 4
58767 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
58768 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
58769 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
58770 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
58771 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
58772 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
58773 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
58774 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
58775 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
58776 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58777 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58778 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58779 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58780 +4 4 4 4 4 4
58781 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
58782 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
58783 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
58784 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
58785 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
58786 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
58787 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
58788 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
58789 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
58790 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58791 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58792 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58793 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58794 +4 4 4 4 4 4
58795 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
58796 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
58797 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
58798 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
58799 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
58800 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
58801 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
58802 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
58803 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
58804 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58805 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58806 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58807 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58808 +4 4 4 4 4 4
58809 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
58810 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
58811 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
58812 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
58813 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
58814 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
58815 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
58816 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
58817 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
58818 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58819 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58820 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58821 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58822 +4 4 4 4 4 4
58823 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
58824 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
58825 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
58826 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
58827 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
58828 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
58829 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
58830 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
58831 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
58832 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
58833 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58834 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58835 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58836 +4 4 4 4 4 4
58837 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
58838 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
58839 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
58840 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
58841 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
58842 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
58843 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
58844 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
58845 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
58846 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
58847 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58848 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58849 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58850 +4 4 4 4 4 4
58851 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
58852 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
58853 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
58854 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
58855 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
58856 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
58857 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58858 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
58859 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
58860 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
58861 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
58862 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58863 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58864 +4 4 4 4 4 4
58865 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
58866 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
58867 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
58868 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
58869 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
58870 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
58871 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
58872 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
58873 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
58874 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
58875 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58876 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58877 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58878 +4 4 4 4 4 4
58879 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
58880 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
58881 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
58882 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
58883 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
58884 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
58885 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
58886 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
58887 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
58888 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
58889 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58890 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58891 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58892 +4 4 4 4 4 4
58893 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
58894 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
58895 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
58896 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
58897 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
58898 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
58899 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
58900 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
58901 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
58902 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
58903 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58904 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58905 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58906 +4 4 4 4 4 4
58907 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
58908 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
58909 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
58910 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
58911 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
58912 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
58913 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
58914 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
58915 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
58916 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
58917 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58918 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58919 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58920 +4 4 4 4 4 4
58921 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
58922 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
58923 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
58924 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
58925 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
58926 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
58927 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
58928 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
58929 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
58930 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
58931 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58932 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58933 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58934 +4 4 4 4 4 4
58935 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
58936 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
58937 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
58938 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
58939 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
58940 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
58941 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
58942 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
58943 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
58944 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58945 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58946 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58947 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58948 +4 4 4 4 4 4
58949 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
58950 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
58951 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
58952 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
58953 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
58954 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
58955 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
58956 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
58957 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
58958 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58959 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58960 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58961 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58962 +4 4 4 4 4 4
58963 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
58964 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
58965 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
58966 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
58967 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
58968 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
58969 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
58970 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
58971 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58972 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58973 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58974 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58975 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58976 +4 4 4 4 4 4
58977 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
58978 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
58979 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
58980 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
58981 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
58982 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
58983 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
58984 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
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 4 4 4 4 4 4 4 4 4
58987 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58988 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58989 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58990 +4 4 4 4 4 4
58991 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
58992 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
58993 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
58994 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
58995 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
58996 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
58997 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
58998 +6 6 6 4 0 0 4 0 0 4 3 3 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 4 4 4
59001 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59002 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59003 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59004 +4 4 4 4 4 4
59005 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
59006 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
59007 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
59008 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
59009 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
59010 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
59011 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
59012 +4 0 0 4 3 3 6 6 6 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59016 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59017 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59018 +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 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
59021 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
59022 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
59023 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
59024 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
59025 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
59026 +6 6 6 6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59030 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59031 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59032 +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 5 5 5 5 5 5 5 5 5
59035 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
59036 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
59037 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
59038 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
59039 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
59040 +5 5 5 5 5 5 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 4 4 4 4 4 4 4 4 4
59044 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
59050 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
59051 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
59052 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
59053 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
59054 +4 3 3 5 5 5 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 4 4 4 4 4 4
59058 +4 4 4 4 4 4 4 4 4 4 4 4 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
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 5 5 5
59064 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
59065 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
59066 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
59067 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
59068 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59069 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59070 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59071 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59072 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59073 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59074 +4 4 4 4 4 4
59075 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59076 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59077 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59078 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
59079 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
59080 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
59081 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
59082 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59083 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59084 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59085 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59086 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59087 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59088 +4 4 4 4 4 4
59089 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59090 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59091 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59092 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
59093 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
59094 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
59095 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
59096 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59097 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59098 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59099 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59100 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59101 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59102 +4 4 4 4 4 4
59103 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59104 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59105 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59106 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
59107 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
59108 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
59109 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
59110 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59111 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59112 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59113 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59114 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59115 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59116 +4 4 4 4 4 4
59117 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59118 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59119 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59120 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
59121 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
59122 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
59123 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
59124 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59125 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59126 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59127 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59128 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59129 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59130 +4 4 4 4 4 4
59131 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59132 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59133 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59134 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59135 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
59136 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
59137 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
59138 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59139 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59140 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59141 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59142 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59143 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59144 +4 4 4 4 4 4
59145 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59146 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59147 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59148 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59149 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
59150 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
59151 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59152 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59153 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59154 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59155 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59156 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59157 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59158 +4 4 4 4 4 4
59159 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59160 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59161 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59162 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59163 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
59164 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
59165 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59166 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59167 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59168 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59169 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59170 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59171 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59172 +4 4 4 4 4 4
59173 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59174 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59175 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59176 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59177 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
59178 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
59179 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59180 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59181 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59182 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59183 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59184 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59185 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59186 +4 4 4 4 4 4
59187 diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
59188 index fef20db..d28b1ab 100644
59189 --- a/drivers/xen/xenfs/xenstored.c
59190 +++ b/drivers/xen/xenfs/xenstored.c
59191 @@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
59192 static int xsd_kva_open(struct inode *inode, struct file *file)
59193 {
59194 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
59195 +#ifdef CONFIG_GRKERNSEC_HIDESYM
59196 + NULL);
59197 +#else
59198 xen_store_interface);
59199 +#endif
59200 +
59201 if (!file->private_data)
59202 return -ENOMEM;
59203 return 0;
59204 diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
59205 index cc1cfae..41158ad 100644
59206 --- a/fs/9p/vfs_addr.c
59207 +++ b/fs/9p/vfs_addr.c
59208 @@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
59209
59210 retval = v9fs_file_write_internal(inode,
59211 v9inode->writeback_fid,
59212 - (__force const char __user *)buffer,
59213 + (const char __force_user *)buffer,
59214 len, &offset, 0);
59215 if (retval > 0)
59216 retval = 0;
59217 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
59218 index 7fa4f7a..a7ebf8c 100644
59219 --- a/fs/9p/vfs_inode.c
59220 +++ b/fs/9p/vfs_inode.c
59221 @@ -1312,7 +1312,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
59222 void
59223 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
59224 {
59225 - char *s = nd_get_link(nd);
59226 + const char *s = nd_get_link(nd);
59227
59228 p9_debug(P9_DEBUG_VFS, " %s %s\n",
59229 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
59230 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
59231 index 370b24c..ff0be7b 100644
59232 --- a/fs/Kconfig.binfmt
59233 +++ b/fs/Kconfig.binfmt
59234 @@ -103,7 +103,7 @@ config HAVE_AOUT
59235
59236 config BINFMT_AOUT
59237 tristate "Kernel support for a.out and ECOFF binaries"
59238 - depends on HAVE_AOUT
59239 + depends on HAVE_AOUT && BROKEN
59240 ---help---
59241 A.out (Assembler.OUTput) is a set of formats for libraries and
59242 executables used in the earliest versions of UNIX. Linux used
59243 diff --git a/fs/afs/inode.c b/fs/afs/inode.c
59244 index 2946712..f737435 100644
59245 --- a/fs/afs/inode.c
59246 +++ b/fs/afs/inode.c
59247 @@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
59248 struct afs_vnode *vnode;
59249 struct super_block *sb;
59250 struct inode *inode;
59251 - static atomic_t afs_autocell_ino;
59252 + static atomic_unchecked_t afs_autocell_ino;
59253
59254 _enter("{%x:%u},%*.*s,",
59255 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
59256 @@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
59257 data.fid.unique = 0;
59258 data.fid.vnode = 0;
59259
59260 - inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
59261 + inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
59262 afs_iget5_autocell_test, afs_iget5_set,
59263 &data);
59264 if (!inode) {
59265 diff --git a/fs/aio.c b/fs/aio.c
59266 index 1c9c5f0..94455bc 100644
59267 --- a/fs/aio.c
59268 +++ b/fs/aio.c
59269 @@ -141,6 +141,7 @@ struct kioctx {
59270
59271 struct {
59272 unsigned tail;
59273 + unsigned completed_events;
59274 spinlock_t completion_lock;
59275 } ____cacheline_aligned_in_smp;
59276
59277 @@ -380,7 +381,7 @@ static int aio_setup_ring(struct kioctx *ctx)
59278 size += sizeof(struct io_event) * nr_events;
59279
59280 nr_pages = PFN_UP(size);
59281 - if (nr_pages < 0)
59282 + if (nr_pages <= 0)
59283 return -EINVAL;
59284
59285 file = aio_private_file(ctx, nr_pages);
59286 @@ -880,6 +881,68 @@ out:
59287 return ret;
59288 }
59289
59290 +/* refill_reqs_available
59291 + * Updates the reqs_available reference counts used for tracking the
59292 + * number of free slots in the completion ring. This can be called
59293 + * from aio_complete() (to optimistically update reqs_available) or
59294 + * from aio_get_req() (the we're out of events case). It must be
59295 + * called holding ctx->completion_lock.
59296 + */
59297 +static void refill_reqs_available(struct kioctx *ctx, unsigned head,
59298 + unsigned tail)
59299 +{
59300 + unsigned events_in_ring, completed;
59301 +
59302 + /* Clamp head since userland can write to it. */
59303 + head %= ctx->nr_events;
59304 + if (head <= tail)
59305 + events_in_ring = tail - head;
59306 + else
59307 + events_in_ring = ctx->nr_events - (head - tail);
59308 +
59309 + completed = ctx->completed_events;
59310 + if (events_in_ring < completed)
59311 + completed -= events_in_ring;
59312 + else
59313 + completed = 0;
59314 +
59315 + if (!completed)
59316 + return;
59317 +
59318 + ctx->completed_events -= completed;
59319 + put_reqs_available(ctx, completed);
59320 +}
59321 +
59322 +/* user_refill_reqs_available
59323 + * Called to refill reqs_available when aio_get_req() encounters an
59324 + * out of space in the completion ring.
59325 + */
59326 +static void user_refill_reqs_available(struct kioctx *ctx)
59327 +{
59328 + spin_lock_irq(&ctx->completion_lock);
59329 + if (ctx->completed_events) {
59330 + struct aio_ring *ring;
59331 + unsigned head;
59332 +
59333 + /* Access of ring->head may race with aio_read_events_ring()
59334 + * here, but that's okay since whether we read the old version
59335 + * or the new version, and either will be valid. The important
59336 + * part is that head cannot pass tail since we prevent
59337 + * aio_complete() from updating tail by holding
59338 + * ctx->completion_lock. Even if head is invalid, the check
59339 + * against ctx->completed_events below will make sure we do the
59340 + * safe/right thing.
59341 + */
59342 + ring = kmap_atomic(ctx->ring_pages[0]);
59343 + head = ring->head;
59344 + kunmap_atomic(ring);
59345 +
59346 + refill_reqs_available(ctx, head, ctx->tail);
59347 + }
59348 +
59349 + spin_unlock_irq(&ctx->completion_lock);
59350 +}
59351 +
59352 /* aio_get_req
59353 * Allocate a slot for an aio request.
59354 * Returns NULL if no requests are free.
59355 @@ -888,8 +951,11 @@ static inline struct kiocb *aio_get_req(struct kioctx *ctx)
59356 {
59357 struct kiocb *req;
59358
59359 - if (!get_reqs_available(ctx))
59360 - return NULL;
59361 + if (!get_reqs_available(ctx)) {
59362 + user_refill_reqs_available(ctx);
59363 + if (!get_reqs_available(ctx))
59364 + return NULL;
59365 + }
59366
59367 req = kmem_cache_alloc(kiocb_cachep, GFP_KERNEL|__GFP_ZERO);
59368 if (unlikely(!req))
59369 @@ -948,8 +1014,8 @@ void aio_complete(struct kiocb *iocb, long res, long res2)
59370 struct kioctx *ctx = iocb->ki_ctx;
59371 struct aio_ring *ring;
59372 struct io_event *ev_page, *event;
59373 + unsigned tail, pos, head;
59374 unsigned long flags;
59375 - unsigned tail, pos;
59376
59377 /*
59378 * Special case handling for sync iocbs:
59379 @@ -1010,10 +1076,14 @@ void aio_complete(struct kiocb *iocb, long res, long res2)
59380 ctx->tail = tail;
59381
59382 ring = kmap_atomic(ctx->ring_pages[0]);
59383 + head = ring->head;
59384 ring->tail = tail;
59385 kunmap_atomic(ring);
59386 flush_dcache_page(ctx->ring_pages[0]);
59387
59388 + ctx->completed_events++;
59389 + if (ctx->completed_events > 1)
59390 + refill_reqs_available(ctx, head, tail);
59391 spin_unlock_irqrestore(&ctx->completion_lock, flags);
59392
59393 pr_debug("added to ring %p at [%u]\n", iocb, tail);
59394 @@ -1028,7 +1098,6 @@ void aio_complete(struct kiocb *iocb, long res, long res2)
59395
59396 /* everything turned out well, dispose of the aiocb. */
59397 kiocb_free(iocb);
59398 - put_reqs_available(ctx, 1);
59399
59400 /*
59401 * We have to order our ring_info tail store above and test
59402 diff --git a/fs/attr.c b/fs/attr.c
59403 index 6530ced..4a827e2 100644
59404 --- a/fs/attr.c
59405 +++ b/fs/attr.c
59406 @@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
59407 unsigned long limit;
59408
59409 limit = rlimit(RLIMIT_FSIZE);
59410 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
59411 if (limit != RLIM_INFINITY && offset > limit)
59412 goto out_sig;
59413 if (offset > inode->i_sb->s_maxbytes)
59414 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
59415 index 116fd38..c04182da 100644
59416 --- a/fs/autofs4/waitq.c
59417 +++ b/fs/autofs4/waitq.c
59418 @@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
59419 {
59420 unsigned long sigpipe, flags;
59421 mm_segment_t fs;
59422 - const char *data = (const char *)addr;
59423 + const char __user *data = (const char __force_user *)addr;
59424 ssize_t wr = 0;
59425
59426 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
59427 @@ -340,6 +340,10 @@ static int validate_request(struct autofs_wait_queue **wait,
59428 return 1;
59429 }
59430
59431 +#ifdef CONFIG_GRKERNSEC_HIDESYM
59432 +static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
59433 +#endif
59434 +
59435 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
59436 enum autofs_notify notify)
59437 {
59438 @@ -385,7 +389,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
59439
59440 /* If this is a direct mount request create a dummy name */
59441 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
59442 +#ifdef CONFIG_GRKERNSEC_HIDESYM
59443 + /* this name does get written to userland via autofs4_write() */
59444 + qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
59445 +#else
59446 qstr.len = sprintf(name, "%p", dentry);
59447 +#endif
59448 else {
59449 qstr.len = autofs4_getpath(sbi, dentry, &name);
59450 if (!qstr.len) {
59451 diff --git a/fs/befs/endian.h b/fs/befs/endian.h
59452 index 2722387..56059b5 100644
59453 --- a/fs/befs/endian.h
59454 +++ b/fs/befs/endian.h
59455 @@ -11,7 +11,7 @@
59456
59457 #include <asm/byteorder.h>
59458
59459 -static inline u64
59460 +static inline u64 __intentional_overflow(-1)
59461 fs64_to_cpu(const struct super_block *sb, fs64 n)
59462 {
59463 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
59464 @@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
59465 return (__force fs64)cpu_to_be64(n);
59466 }
59467
59468 -static inline u32
59469 +static inline u32 __intentional_overflow(-1)
59470 fs32_to_cpu(const struct super_block *sb, fs32 n)
59471 {
59472 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
59473 @@ -47,7 +47,7 @@ cpu_to_fs32(const struct super_block *sb, u32 n)
59474 return (__force fs32)cpu_to_be32(n);
59475 }
59476
59477 -static inline u16
59478 +static inline u16 __intentional_overflow(-1)
59479 fs16_to_cpu(const struct super_block *sb, fs16 n)
59480 {
59481 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
59482 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
59483 index ca0ba15..0fa3257 100644
59484 --- a/fs/binfmt_aout.c
59485 +++ b/fs/binfmt_aout.c
59486 @@ -16,6 +16,7 @@
59487 #include <linux/string.h>
59488 #include <linux/fs.h>
59489 #include <linux/file.h>
59490 +#include <linux/security.h>
59491 #include <linux/stat.h>
59492 #include <linux/fcntl.h>
59493 #include <linux/ptrace.h>
59494 @@ -58,6 +59,8 @@ static int aout_core_dump(struct coredump_params *cprm)
59495 #endif
59496 # define START_STACK(u) ((void __user *)u.start_stack)
59497
59498 + memset(&dump, 0, sizeof(dump));
59499 +
59500 fs = get_fs();
59501 set_fs(KERNEL_DS);
59502 has_dumped = 1;
59503 @@ -68,10 +71,12 @@ static int aout_core_dump(struct coredump_params *cprm)
59504
59505 /* If the size of the dump file exceeds the rlimit, then see what would happen
59506 if we wrote the stack, but not the data area. */
59507 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
59508 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
59509 dump.u_dsize = 0;
59510
59511 /* Make sure we have enough room to write the stack and data areas. */
59512 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
59513 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
59514 dump.u_ssize = 0;
59515
59516 @@ -232,6 +237,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
59517 rlim = rlimit(RLIMIT_DATA);
59518 if (rlim >= RLIM_INFINITY)
59519 rlim = ~0;
59520 +
59521 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
59522 if (ex.a_data + ex.a_bss > rlim)
59523 return -ENOMEM;
59524
59525 @@ -264,6 +271,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
59526
59527 install_exec_creds(bprm);
59528
59529 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
59530 + current->mm->pax_flags = 0UL;
59531 +#endif
59532 +
59533 +#ifdef CONFIG_PAX_PAGEEXEC
59534 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
59535 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
59536 +
59537 +#ifdef CONFIG_PAX_EMUTRAMP
59538 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
59539 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
59540 +#endif
59541 +
59542 +#ifdef CONFIG_PAX_MPROTECT
59543 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
59544 + current->mm->pax_flags |= MF_PAX_MPROTECT;
59545 +#endif
59546 +
59547 + }
59548 +#endif
59549 +
59550 if (N_MAGIC(ex) == OMAGIC) {
59551 unsigned long text_addr, map_size;
59552 loff_t pos;
59553 @@ -321,7 +349,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
59554 }
59555
59556 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
59557 - PROT_READ | PROT_WRITE | PROT_EXEC,
59558 + PROT_READ | PROT_WRITE,
59559 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
59560 fd_offset + ex.a_text);
59561 if (error != N_DATADDR(ex)) {
59562 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
59563 index 3892c1a..4e27c04 100644
59564 --- a/fs/binfmt_elf.c
59565 +++ b/fs/binfmt_elf.c
59566 @@ -34,6 +34,7 @@
59567 #include <linux/utsname.h>
59568 #include <linux/coredump.h>
59569 #include <linux/sched.h>
59570 +#include <linux/xattr.h>
59571 #include <asm/uaccess.h>
59572 #include <asm/param.h>
59573 #include <asm/page.h>
59574 @@ -47,7 +48,7 @@
59575
59576 static int load_elf_binary(struct linux_binprm *bprm);
59577 static unsigned long elf_map(struct file *, unsigned long, struct elf_phdr *,
59578 - int, int, unsigned long);
59579 + int, int, unsigned long) __intentional_overflow(-1);
59580
59581 #ifdef CONFIG_USELIB
59582 static int load_elf_library(struct file *);
59583 @@ -65,6 +66,14 @@ static int elf_core_dump(struct coredump_params *cprm);
59584 #define elf_core_dump NULL
59585 #endif
59586
59587 +#ifdef CONFIG_PAX_MPROTECT
59588 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
59589 +#endif
59590 +
59591 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59592 +static void elf_handle_mmap(struct file *file);
59593 +#endif
59594 +
59595 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
59596 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
59597 #else
59598 @@ -84,6 +93,15 @@ static struct linux_binfmt elf_format = {
59599 .load_binary = load_elf_binary,
59600 .load_shlib = load_elf_library,
59601 .core_dump = elf_core_dump,
59602 +
59603 +#ifdef CONFIG_PAX_MPROTECT
59604 + .handle_mprotect= elf_handle_mprotect,
59605 +#endif
59606 +
59607 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59608 + .handle_mmap = elf_handle_mmap,
59609 +#endif
59610 +
59611 .min_coredump = ELF_EXEC_PAGESIZE,
59612 };
59613
59614 @@ -91,6 +109,8 @@ static struct linux_binfmt elf_format = {
59615
59616 static int set_brk(unsigned long start, unsigned long end)
59617 {
59618 + unsigned long e = end;
59619 +
59620 start = ELF_PAGEALIGN(start);
59621 end = ELF_PAGEALIGN(end);
59622 if (end > start) {
59623 @@ -99,7 +119,7 @@ static int set_brk(unsigned long start, unsigned long end)
59624 if (BAD_ADDR(addr))
59625 return addr;
59626 }
59627 - current->mm->start_brk = current->mm->brk = end;
59628 + current->mm->start_brk = current->mm->brk = e;
59629 return 0;
59630 }
59631
59632 @@ -160,12 +180,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
59633 elf_addr_t __user *u_rand_bytes;
59634 const char *k_platform = ELF_PLATFORM;
59635 const char *k_base_platform = ELF_BASE_PLATFORM;
59636 - unsigned char k_rand_bytes[16];
59637 + u32 k_rand_bytes[4];
59638 int items;
59639 elf_addr_t *elf_info;
59640 int ei_index = 0;
59641 const struct cred *cred = current_cred();
59642 struct vm_area_struct *vma;
59643 + unsigned long saved_auxv[AT_VECTOR_SIZE];
59644
59645 /*
59646 * In some cases (e.g. Hyper-Threading), we want to avoid L1
59647 @@ -207,8 +228,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
59648 * Generate 16 random bytes for userspace PRNG seeding.
59649 */
59650 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
59651 - u_rand_bytes = (elf_addr_t __user *)
59652 - STACK_ALLOC(p, sizeof(k_rand_bytes));
59653 + prandom_seed(k_rand_bytes[0] ^ prandom_u32());
59654 + prandom_seed(k_rand_bytes[1] ^ prandom_u32());
59655 + prandom_seed(k_rand_bytes[2] ^ prandom_u32());
59656 + prandom_seed(k_rand_bytes[3] ^ prandom_u32());
59657 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
59658 + u_rand_bytes = (elf_addr_t __user *) p;
59659 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
59660 return -EFAULT;
59661
59662 @@ -323,9 +348,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
59663 return -EFAULT;
59664 current->mm->env_end = p;
59665
59666 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
59667 +
59668 /* Put the elf_info on the stack in the right place. */
59669 sp = (elf_addr_t __user *)envp + 1;
59670 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
59671 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
59672 return -EFAULT;
59673 return 0;
59674 }
59675 @@ -393,15 +420,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
59676 an ELF header */
59677
59678 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
59679 - struct file *interpreter, unsigned long *interp_map_addr,
59680 - unsigned long no_base)
59681 + struct file *interpreter, unsigned long no_base)
59682 {
59683 struct elf_phdr *elf_phdata;
59684 struct elf_phdr *eppnt;
59685 - unsigned long load_addr = 0;
59686 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
59687 int load_addr_set = 0;
59688 unsigned long last_bss = 0, elf_bss = 0;
59689 - unsigned long error = ~0UL;
59690 + unsigned long error = -EINVAL;
59691 unsigned long total_size;
59692 int retval, i, size;
59693
59694 @@ -447,6 +473,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
59695 goto out_close;
59696 }
59697
59698 +#ifdef CONFIG_PAX_SEGMEXEC
59699 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
59700 + pax_task_size = SEGMEXEC_TASK_SIZE;
59701 +#endif
59702 +
59703 eppnt = elf_phdata;
59704 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
59705 if (eppnt->p_type == PT_LOAD) {
59706 @@ -470,8 +501,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
59707 map_addr = elf_map(interpreter, load_addr + vaddr,
59708 eppnt, elf_prot, elf_type, total_size);
59709 total_size = 0;
59710 - if (!*interp_map_addr)
59711 - *interp_map_addr = map_addr;
59712 error = map_addr;
59713 if (BAD_ADDR(map_addr))
59714 goto out_close;
59715 @@ -490,8 +519,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
59716 k = load_addr + eppnt->p_vaddr;
59717 if (BAD_ADDR(k) ||
59718 eppnt->p_filesz > eppnt->p_memsz ||
59719 - eppnt->p_memsz > TASK_SIZE ||
59720 - TASK_SIZE - eppnt->p_memsz < k) {
59721 + eppnt->p_memsz > pax_task_size ||
59722 + pax_task_size - eppnt->p_memsz < k) {
59723 error = -ENOMEM;
59724 goto out_close;
59725 }
59726 @@ -530,9 +559,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
59727 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
59728
59729 /* Map the last of the bss segment */
59730 - error = vm_brk(elf_bss, last_bss - elf_bss);
59731 - if (BAD_ADDR(error))
59732 - goto out_close;
59733 + if (last_bss > elf_bss) {
59734 + error = vm_brk(elf_bss, last_bss - elf_bss);
59735 + if (BAD_ADDR(error))
59736 + goto out_close;
59737 + }
59738 }
59739
59740 error = load_addr;
59741 @@ -543,6 +574,336 @@ out:
59742 return error;
59743 }
59744
59745 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
59746 +#ifdef CONFIG_PAX_SOFTMODE
59747 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
59748 +{
59749 + unsigned long pax_flags = 0UL;
59750 +
59751 +#ifdef CONFIG_PAX_PAGEEXEC
59752 + if (elf_phdata->p_flags & PF_PAGEEXEC)
59753 + pax_flags |= MF_PAX_PAGEEXEC;
59754 +#endif
59755 +
59756 +#ifdef CONFIG_PAX_SEGMEXEC
59757 + if (elf_phdata->p_flags & PF_SEGMEXEC)
59758 + pax_flags |= MF_PAX_SEGMEXEC;
59759 +#endif
59760 +
59761 +#ifdef CONFIG_PAX_EMUTRAMP
59762 + if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
59763 + pax_flags |= MF_PAX_EMUTRAMP;
59764 +#endif
59765 +
59766 +#ifdef CONFIG_PAX_MPROTECT
59767 + if (elf_phdata->p_flags & PF_MPROTECT)
59768 + pax_flags |= MF_PAX_MPROTECT;
59769 +#endif
59770 +
59771 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
59772 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
59773 + pax_flags |= MF_PAX_RANDMMAP;
59774 +#endif
59775 +
59776 + return pax_flags;
59777 +}
59778 +#endif
59779 +
59780 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
59781 +{
59782 + unsigned long pax_flags = 0UL;
59783 +
59784 +#ifdef CONFIG_PAX_PAGEEXEC
59785 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
59786 + pax_flags |= MF_PAX_PAGEEXEC;
59787 +#endif
59788 +
59789 +#ifdef CONFIG_PAX_SEGMEXEC
59790 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
59791 + pax_flags |= MF_PAX_SEGMEXEC;
59792 +#endif
59793 +
59794 +#ifdef CONFIG_PAX_EMUTRAMP
59795 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
59796 + pax_flags |= MF_PAX_EMUTRAMP;
59797 +#endif
59798 +
59799 +#ifdef CONFIG_PAX_MPROTECT
59800 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
59801 + pax_flags |= MF_PAX_MPROTECT;
59802 +#endif
59803 +
59804 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
59805 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
59806 + pax_flags |= MF_PAX_RANDMMAP;
59807 +#endif
59808 +
59809 + return pax_flags;
59810 +}
59811 +#endif
59812 +
59813 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
59814 +#ifdef CONFIG_PAX_SOFTMODE
59815 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
59816 +{
59817 + unsigned long pax_flags = 0UL;
59818 +
59819 +#ifdef CONFIG_PAX_PAGEEXEC
59820 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
59821 + pax_flags |= MF_PAX_PAGEEXEC;
59822 +#endif
59823 +
59824 +#ifdef CONFIG_PAX_SEGMEXEC
59825 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
59826 + pax_flags |= MF_PAX_SEGMEXEC;
59827 +#endif
59828 +
59829 +#ifdef CONFIG_PAX_EMUTRAMP
59830 + if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
59831 + pax_flags |= MF_PAX_EMUTRAMP;
59832 +#endif
59833 +
59834 +#ifdef CONFIG_PAX_MPROTECT
59835 + if (pax_flags_softmode & MF_PAX_MPROTECT)
59836 + pax_flags |= MF_PAX_MPROTECT;
59837 +#endif
59838 +
59839 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
59840 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
59841 + pax_flags |= MF_PAX_RANDMMAP;
59842 +#endif
59843 +
59844 + return pax_flags;
59845 +}
59846 +#endif
59847 +
59848 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
59849 +{
59850 + unsigned long pax_flags = 0UL;
59851 +
59852 +#ifdef CONFIG_PAX_PAGEEXEC
59853 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
59854 + pax_flags |= MF_PAX_PAGEEXEC;
59855 +#endif
59856 +
59857 +#ifdef CONFIG_PAX_SEGMEXEC
59858 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
59859 + pax_flags |= MF_PAX_SEGMEXEC;
59860 +#endif
59861 +
59862 +#ifdef CONFIG_PAX_EMUTRAMP
59863 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
59864 + pax_flags |= MF_PAX_EMUTRAMP;
59865 +#endif
59866 +
59867 +#ifdef CONFIG_PAX_MPROTECT
59868 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
59869 + pax_flags |= MF_PAX_MPROTECT;
59870 +#endif
59871 +
59872 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
59873 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
59874 + pax_flags |= MF_PAX_RANDMMAP;
59875 +#endif
59876 +
59877 + return pax_flags;
59878 +}
59879 +#endif
59880 +
59881 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
59882 +static unsigned long pax_parse_defaults(void)
59883 +{
59884 + unsigned long pax_flags = 0UL;
59885 +
59886 +#ifdef CONFIG_PAX_SOFTMODE
59887 + if (pax_softmode)
59888 + return pax_flags;
59889 +#endif
59890 +
59891 +#ifdef CONFIG_PAX_PAGEEXEC
59892 + pax_flags |= MF_PAX_PAGEEXEC;
59893 +#endif
59894 +
59895 +#ifdef CONFIG_PAX_SEGMEXEC
59896 + pax_flags |= MF_PAX_SEGMEXEC;
59897 +#endif
59898 +
59899 +#ifdef CONFIG_PAX_MPROTECT
59900 + pax_flags |= MF_PAX_MPROTECT;
59901 +#endif
59902 +
59903 +#ifdef CONFIG_PAX_RANDMMAP
59904 + if (randomize_va_space)
59905 + pax_flags |= MF_PAX_RANDMMAP;
59906 +#endif
59907 +
59908 + return pax_flags;
59909 +}
59910 +
59911 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
59912 +{
59913 + unsigned long pax_flags = PAX_PARSE_FLAGS_FALLBACK;
59914 +
59915 +#ifdef CONFIG_PAX_EI_PAX
59916 +
59917 +#ifdef CONFIG_PAX_SOFTMODE
59918 + if (pax_softmode)
59919 + return pax_flags;
59920 +#endif
59921 +
59922 + pax_flags = 0UL;
59923 +
59924 +#ifdef CONFIG_PAX_PAGEEXEC
59925 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
59926 + pax_flags |= MF_PAX_PAGEEXEC;
59927 +#endif
59928 +
59929 +#ifdef CONFIG_PAX_SEGMEXEC
59930 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
59931 + pax_flags |= MF_PAX_SEGMEXEC;
59932 +#endif
59933 +
59934 +#ifdef CONFIG_PAX_EMUTRAMP
59935 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
59936 + pax_flags |= MF_PAX_EMUTRAMP;
59937 +#endif
59938 +
59939 +#ifdef CONFIG_PAX_MPROTECT
59940 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
59941 + pax_flags |= MF_PAX_MPROTECT;
59942 +#endif
59943 +
59944 +#ifdef CONFIG_PAX_ASLR
59945 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
59946 + pax_flags |= MF_PAX_RANDMMAP;
59947 +#endif
59948 +
59949 +#endif
59950 +
59951 + return pax_flags;
59952 +
59953 +}
59954 +
59955 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
59956 +{
59957 +
59958 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
59959 + unsigned long i;
59960 +
59961 + for (i = 0UL; i < elf_ex->e_phnum; i++)
59962 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
59963 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
59964 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
59965 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
59966 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
59967 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
59968 + return PAX_PARSE_FLAGS_FALLBACK;
59969 +
59970 +#ifdef CONFIG_PAX_SOFTMODE
59971 + if (pax_softmode)
59972 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
59973 + else
59974 +#endif
59975 +
59976 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
59977 + break;
59978 + }
59979 +#endif
59980 +
59981 + return PAX_PARSE_FLAGS_FALLBACK;
59982 +}
59983 +
59984 +static unsigned long pax_parse_xattr_pax(struct file * const file)
59985 +{
59986 +
59987 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
59988 + ssize_t xattr_size, i;
59989 + unsigned char xattr_value[sizeof("pemrs") - 1];
59990 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
59991 +
59992 + xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
59993 + if (xattr_size < 0 || xattr_size > sizeof xattr_value)
59994 + return PAX_PARSE_FLAGS_FALLBACK;
59995 +
59996 + for (i = 0; i < xattr_size; i++)
59997 + switch (xattr_value[i]) {
59998 + default:
59999 + return PAX_PARSE_FLAGS_FALLBACK;
60000 +
60001 +#define parse_flag(option1, option2, flag) \
60002 + case option1: \
60003 + if (pax_flags_hardmode & MF_PAX_##flag) \
60004 + return PAX_PARSE_FLAGS_FALLBACK;\
60005 + pax_flags_hardmode |= MF_PAX_##flag; \
60006 + break; \
60007 + case option2: \
60008 + if (pax_flags_softmode & MF_PAX_##flag) \
60009 + return PAX_PARSE_FLAGS_FALLBACK;\
60010 + pax_flags_softmode |= MF_PAX_##flag; \
60011 + break;
60012 +
60013 + parse_flag('p', 'P', PAGEEXEC);
60014 + parse_flag('e', 'E', EMUTRAMP);
60015 + parse_flag('m', 'M', MPROTECT);
60016 + parse_flag('r', 'R', RANDMMAP);
60017 + parse_flag('s', 'S', SEGMEXEC);
60018 +
60019 +#undef parse_flag
60020 + }
60021 +
60022 + if (pax_flags_hardmode & pax_flags_softmode)
60023 + return PAX_PARSE_FLAGS_FALLBACK;
60024 +
60025 +#ifdef CONFIG_PAX_SOFTMODE
60026 + if (pax_softmode)
60027 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
60028 + else
60029 +#endif
60030 +
60031 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
60032 +#else
60033 + return PAX_PARSE_FLAGS_FALLBACK;
60034 +#endif
60035 +
60036 +}
60037 +
60038 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
60039 +{
60040 + unsigned long pax_flags, ei_pax_flags, pt_pax_flags, xattr_pax_flags;
60041 +
60042 + pax_flags = pax_parse_defaults();
60043 + ei_pax_flags = pax_parse_ei_pax(elf_ex);
60044 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
60045 + xattr_pax_flags = pax_parse_xattr_pax(file);
60046 +
60047 + if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
60048 + xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
60049 + pt_pax_flags != xattr_pax_flags)
60050 + return -EINVAL;
60051 + if (xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
60052 + pax_flags = xattr_pax_flags;
60053 + else if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
60054 + pax_flags = pt_pax_flags;
60055 + else if (ei_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
60056 + pax_flags = ei_pax_flags;
60057 +
60058 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
60059 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
60060 + if ((__supported_pte_mask & _PAGE_NX))
60061 + pax_flags &= ~MF_PAX_SEGMEXEC;
60062 + else
60063 + pax_flags &= ~MF_PAX_PAGEEXEC;
60064 + }
60065 +#endif
60066 +
60067 + if (0 > pax_check_flags(&pax_flags))
60068 + return -EINVAL;
60069 +
60070 + current->mm->pax_flags = pax_flags;
60071 + return 0;
60072 +}
60073 +#endif
60074 +
60075 /*
60076 * These are the functions used to load ELF style executables and shared
60077 * libraries. There is no binary dependent code anywhere else.
60078 @@ -556,6 +917,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
60079 {
60080 unsigned int random_variable = 0;
60081
60082 +#ifdef CONFIG_PAX_RANDUSTACK
60083 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
60084 + return stack_top - current->mm->delta_stack;
60085 +#endif
60086 +
60087 if ((current->flags & PF_RANDOMIZE) &&
60088 !(current->personality & ADDR_NO_RANDOMIZE)) {
60089 random_variable = get_random_int() & STACK_RND_MASK;
60090 @@ -574,7 +940,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
60091 unsigned long load_addr = 0, load_bias = 0;
60092 int load_addr_set = 0;
60093 char * elf_interpreter = NULL;
60094 - unsigned long error;
60095 + unsigned long error = 0;
60096 struct elf_phdr *elf_ppnt, *elf_phdata;
60097 unsigned long elf_bss, elf_brk;
60098 int retval, i;
60099 @@ -589,6 +955,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
60100 struct elfhdr elf_ex;
60101 struct elfhdr interp_elf_ex;
60102 } *loc;
60103 + unsigned long pax_task_size;
60104
60105 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
60106 if (!loc) {
60107 @@ -726,6 +1093,77 @@ static int load_elf_binary(struct linux_binprm *bprm)
60108 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
60109 may depend on the personality. */
60110 SET_PERSONALITY(loc->elf_ex);
60111 +
60112 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
60113 + current->mm->pax_flags = 0UL;
60114 +#endif
60115 +
60116 +#ifdef CONFIG_PAX_DLRESOLVE
60117 + current->mm->call_dl_resolve = 0UL;
60118 +#endif
60119 +
60120 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
60121 + current->mm->call_syscall = 0UL;
60122 +#endif
60123 +
60124 +#ifdef CONFIG_PAX_ASLR
60125 + current->mm->delta_mmap = 0UL;
60126 + current->mm->delta_stack = 0UL;
60127 +#endif
60128 +
60129 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
60130 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
60131 + send_sig(SIGKILL, current, 0);
60132 + goto out_free_dentry;
60133 + }
60134 +#endif
60135 +
60136 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
60137 + pax_set_initial_flags(bprm);
60138 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
60139 + if (pax_set_initial_flags_func)
60140 + (pax_set_initial_flags_func)(bprm);
60141 +#endif
60142 +
60143 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
60144 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
60145 + current->mm->context.user_cs_limit = PAGE_SIZE;
60146 + current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
60147 + }
60148 +#endif
60149 +
60150 +#ifdef CONFIG_PAX_SEGMEXEC
60151 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
60152 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
60153 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
60154 + pax_task_size = SEGMEXEC_TASK_SIZE;
60155 + current->mm->def_flags |= VM_NOHUGEPAGE;
60156 + } else
60157 +#endif
60158 +
60159 + pax_task_size = TASK_SIZE;
60160 +
60161 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
60162 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
60163 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
60164 + put_cpu();
60165 + }
60166 +#endif
60167 +
60168 +#ifdef CONFIG_PAX_ASLR
60169 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
60170 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
60171 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
60172 + }
60173 +#endif
60174 +
60175 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
60176 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
60177 + executable_stack = EXSTACK_DISABLE_X;
60178 + current->personality &= ~READ_IMPLIES_EXEC;
60179 + } else
60180 +#endif
60181 +
60182 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
60183 current->personality |= READ_IMPLIES_EXEC;
60184
60185 @@ -815,6 +1253,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
60186 #else
60187 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
60188 #endif
60189 +
60190 +#ifdef CONFIG_PAX_RANDMMAP
60191 + /* PaX: randomize base address at the default exe base if requested */
60192 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
60193 +#ifdef CONFIG_SPARC64
60194 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
60195 +#else
60196 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
60197 +#endif
60198 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
60199 + elf_flags |= MAP_FIXED;
60200 + }
60201 +#endif
60202 +
60203 }
60204
60205 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
60206 @@ -847,9 +1299,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
60207 * allowed task size. Note that p_filesz must always be
60208 * <= p_memsz so it is only necessary to check p_memsz.
60209 */
60210 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
60211 - elf_ppnt->p_memsz > TASK_SIZE ||
60212 - TASK_SIZE - elf_ppnt->p_memsz < k) {
60213 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
60214 + elf_ppnt->p_memsz > pax_task_size ||
60215 + pax_task_size - elf_ppnt->p_memsz < k) {
60216 /* set_brk can never work. Avoid overflows. */
60217 send_sig(SIGKILL, current, 0);
60218 retval = -EINVAL;
60219 @@ -888,17 +1340,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
60220 goto out_free_dentry;
60221 }
60222 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
60223 - send_sig(SIGSEGV, current, 0);
60224 - retval = -EFAULT; /* Nobody gets to see this, but.. */
60225 - goto out_free_dentry;
60226 + /*
60227 + * This bss-zeroing can fail if the ELF
60228 + * file specifies odd protections. So
60229 + * we don't check the return value
60230 + */
60231 }
60232
60233 +#ifdef CONFIG_PAX_RANDMMAP
60234 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
60235 + unsigned long start, size, flags;
60236 + vm_flags_t vm_flags;
60237 +
60238 + start = ELF_PAGEALIGN(elf_brk);
60239 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
60240 + flags = MAP_FIXED | MAP_PRIVATE;
60241 + vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
60242 +
60243 + down_write(&current->mm->mmap_sem);
60244 + start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
60245 + retval = -ENOMEM;
60246 + if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
60247 +// if (current->personality & ADDR_NO_RANDOMIZE)
60248 +// vm_flags |= VM_READ | VM_MAYREAD;
60249 + start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
60250 + retval = IS_ERR_VALUE(start) ? start : 0;
60251 + }
60252 + up_write(&current->mm->mmap_sem);
60253 + if (retval == 0)
60254 + retval = set_brk(start + size, start + size + PAGE_SIZE);
60255 + if (retval < 0) {
60256 + send_sig(SIGKILL, current, 0);
60257 + goto out_free_dentry;
60258 + }
60259 + }
60260 +#endif
60261 +
60262 if (elf_interpreter) {
60263 - unsigned long interp_map_addr = 0;
60264 -
60265 elf_entry = load_elf_interp(&loc->interp_elf_ex,
60266 interpreter,
60267 - &interp_map_addr,
60268 load_bias);
60269 if (!IS_ERR((void *)elf_entry)) {
60270 /*
60271 @@ -1130,7 +1610,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
60272 * Decide what to dump of a segment, part, all or none.
60273 */
60274 static unsigned long vma_dump_size(struct vm_area_struct *vma,
60275 - unsigned long mm_flags)
60276 + unsigned long mm_flags, long signr)
60277 {
60278 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
60279
60280 @@ -1168,7 +1648,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
60281 if (vma->vm_file == NULL)
60282 return 0;
60283
60284 - if (FILTER(MAPPED_PRIVATE))
60285 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
60286 goto whole;
60287
60288 /*
60289 @@ -1375,9 +1855,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
60290 {
60291 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
60292 int i = 0;
60293 - do
60294 + do {
60295 i += 2;
60296 - while (auxv[i - 2] != AT_NULL);
60297 + } while (auxv[i - 2] != AT_NULL);
60298 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
60299 }
60300
60301 @@ -1386,7 +1866,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
60302 {
60303 mm_segment_t old_fs = get_fs();
60304 set_fs(KERNEL_DS);
60305 - copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
60306 + copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
60307 set_fs(old_fs);
60308 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
60309 }
60310 @@ -2010,14 +2490,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
60311 }
60312
60313 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
60314 - unsigned long mm_flags)
60315 + struct coredump_params *cprm)
60316 {
60317 struct vm_area_struct *vma;
60318 size_t size = 0;
60319
60320 for (vma = first_vma(current, gate_vma); vma != NULL;
60321 vma = next_vma(vma, gate_vma))
60322 - size += vma_dump_size(vma, mm_flags);
60323 + size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
60324 return size;
60325 }
60326
60327 @@ -2108,7 +2588,7 @@ static int elf_core_dump(struct coredump_params *cprm)
60328
60329 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
60330
60331 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
60332 + offset += elf_core_vma_data_size(gate_vma, cprm);
60333 offset += elf_core_extra_data_size();
60334 e_shoff = offset;
60335
60336 @@ -2136,7 +2616,7 @@ static int elf_core_dump(struct coredump_params *cprm)
60337 phdr.p_offset = offset;
60338 phdr.p_vaddr = vma->vm_start;
60339 phdr.p_paddr = 0;
60340 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
60341 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
60342 phdr.p_memsz = vma->vm_end - vma->vm_start;
60343 offset += phdr.p_filesz;
60344 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
60345 @@ -2169,7 +2649,7 @@ static int elf_core_dump(struct coredump_params *cprm)
60346 unsigned long addr;
60347 unsigned long end;
60348
60349 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
60350 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
60351
60352 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
60353 struct page *page;
60354 @@ -2210,6 +2690,167 @@ out:
60355
60356 #endif /* CONFIG_ELF_CORE */
60357
60358 +#ifdef CONFIG_PAX_MPROTECT
60359 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
60360 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
60361 + * we'll remove VM_MAYWRITE for good on RELRO segments.
60362 + *
60363 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
60364 + * basis because we want to allow the common case and not the special ones.
60365 + */
60366 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
60367 +{
60368 + struct elfhdr elf_h;
60369 + struct elf_phdr elf_p;
60370 + unsigned long i;
60371 + unsigned long oldflags;
60372 + bool is_textrel_rw, is_textrel_rx, is_relro;
60373 +
60374 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
60375 + return;
60376 +
60377 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
60378 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
60379 +
60380 +#ifdef CONFIG_PAX_ELFRELOCS
60381 + /* possible TEXTREL */
60382 + is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
60383 + is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
60384 +#else
60385 + is_textrel_rw = false;
60386 + is_textrel_rx = false;
60387 +#endif
60388 +
60389 + /* possible RELRO */
60390 + is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
60391 +
60392 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
60393 + return;
60394 +
60395 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
60396 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
60397 +
60398 +#ifdef CONFIG_PAX_ETEXECRELOCS
60399 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
60400 +#else
60401 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
60402 +#endif
60403 +
60404 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
60405 + !elf_check_arch(&elf_h) ||
60406 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
60407 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
60408 + return;
60409 +
60410 + for (i = 0UL; i < elf_h.e_phnum; i++) {
60411 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
60412 + return;
60413 + switch (elf_p.p_type) {
60414 + case PT_DYNAMIC:
60415 + if (!is_textrel_rw && !is_textrel_rx)
60416 + continue;
60417 + i = 0UL;
60418 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
60419 + elf_dyn dyn;
60420 +
60421 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
60422 + break;
60423 + if (dyn.d_tag == DT_NULL)
60424 + break;
60425 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
60426 + gr_log_textrel(vma);
60427 + if (is_textrel_rw)
60428 + vma->vm_flags |= VM_MAYWRITE;
60429 + else
60430 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
60431 + vma->vm_flags &= ~VM_MAYWRITE;
60432 + break;
60433 + }
60434 + i++;
60435 + }
60436 + is_textrel_rw = false;
60437 + is_textrel_rx = false;
60438 + continue;
60439 +
60440 + case PT_GNU_RELRO:
60441 + if (!is_relro)
60442 + continue;
60443 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
60444 + vma->vm_flags &= ~VM_MAYWRITE;
60445 + is_relro = false;
60446 + continue;
60447 +
60448 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
60449 + case PT_PAX_FLAGS: {
60450 + const char *msg_mprotect = "", *msg_emutramp = "";
60451 + char *buffer_lib, *buffer_exe;
60452 +
60453 + if (elf_p.p_flags & PF_NOMPROTECT)
60454 + msg_mprotect = "MPROTECT disabled";
60455 +
60456 +#ifdef CONFIG_PAX_EMUTRAMP
60457 + if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
60458 + msg_emutramp = "EMUTRAMP enabled";
60459 +#endif
60460 +
60461 + if (!msg_mprotect[0] && !msg_emutramp[0])
60462 + continue;
60463 +
60464 + if (!printk_ratelimit())
60465 + continue;
60466 +
60467 + buffer_lib = (char *)__get_free_page(GFP_KERNEL);
60468 + buffer_exe = (char *)__get_free_page(GFP_KERNEL);
60469 + if (buffer_lib && buffer_exe) {
60470 + char *path_lib, *path_exe;
60471 +
60472 + path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
60473 + path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
60474 +
60475 + pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
60476 + (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
60477 +
60478 + }
60479 + free_page((unsigned long)buffer_exe);
60480 + free_page((unsigned long)buffer_lib);
60481 + continue;
60482 + }
60483 +#endif
60484 +
60485 + }
60486 + }
60487 +}
60488 +#endif
60489 +
60490 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
60491 +
60492 +extern int grsec_enable_log_rwxmaps;
60493 +
60494 +static void elf_handle_mmap(struct file *file)
60495 +{
60496 + struct elfhdr elf_h;
60497 + struct elf_phdr elf_p;
60498 + unsigned long i;
60499 +
60500 + if (!grsec_enable_log_rwxmaps)
60501 + return;
60502 +
60503 + if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
60504 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
60505 + (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
60506 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
60507 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
60508 + return;
60509 +
60510 + for (i = 0UL; i < elf_h.e_phnum; i++) {
60511 + if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
60512 + return;
60513 + if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
60514 + gr_log_ptgnustack(file);
60515 + }
60516 +}
60517 +#endif
60518 +
60519 static int __init init_elf_binfmt(void)
60520 {
60521 register_binfmt(&elf_format);
60522 diff --git a/fs/block_dev.c b/fs/block_dev.c
60523 index 6d72746..536d1db 100644
60524 --- a/fs/block_dev.c
60525 +++ b/fs/block_dev.c
60526 @@ -701,7 +701,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
60527 else if (bdev->bd_contains == bdev)
60528 return true; /* is a whole device which isn't held */
60529
60530 - else if (whole->bd_holder == bd_may_claim)
60531 + else if (whole->bd_holder == (void *)bd_may_claim)
60532 return true; /* is a partition of a device that is being partitioned */
60533 else if (whole->bd_holder != NULL)
60534 return false; /* is a partition of a held device */
60535 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
60536 index aeab453..48dbafc 100644
60537 --- a/fs/btrfs/ctree.c
60538 +++ b/fs/btrfs/ctree.c
60539 @@ -1184,9 +1184,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
60540 free_extent_buffer(buf);
60541 add_root_to_dirty_list(root);
60542 } else {
60543 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
60544 - parent_start = parent->start;
60545 - else
60546 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
60547 + if (parent)
60548 + parent_start = parent->start;
60549 + else
60550 + parent_start = 0;
60551 + } else
60552 parent_start = 0;
60553
60554 WARN_ON(trans->transid != btrfs_header_generation(parent));
60555 diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
60556 index da775bf..882da68 100644
60557 --- a/fs/btrfs/delayed-inode.c
60558 +++ b/fs/btrfs/delayed-inode.c
60559 @@ -462,7 +462,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
60560
60561 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
60562 {
60563 - int seq = atomic_inc_return(&delayed_root->items_seq);
60564 + int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
60565 if ((atomic_dec_return(&delayed_root->items) <
60566 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
60567 waitqueue_active(&delayed_root->wait))
60568 @@ -1412,7 +1412,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
60569
60570 static int could_end_wait(struct btrfs_delayed_root *delayed_root, int seq)
60571 {
60572 - int val = atomic_read(&delayed_root->items_seq);
60573 + int val = atomic_read_unchecked(&delayed_root->items_seq);
60574
60575 if (val < seq || val >= seq + BTRFS_DELAYED_BATCH)
60576 return 1;
60577 @@ -1436,7 +1436,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
60578 int seq;
60579 int ret;
60580
60581 - seq = atomic_read(&delayed_root->items_seq);
60582 + seq = atomic_read_unchecked(&delayed_root->items_seq);
60583
60584 ret = btrfs_wq_run_delayed_node(delayed_root, root, 0);
60585 if (ret)
60586 diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
60587 index f70119f..ab5894d 100644
60588 --- a/fs/btrfs/delayed-inode.h
60589 +++ b/fs/btrfs/delayed-inode.h
60590 @@ -43,7 +43,7 @@ struct btrfs_delayed_root {
60591 */
60592 struct list_head prepare_list;
60593 atomic_t items; /* for delayed items */
60594 - atomic_t items_seq; /* for delayed items */
60595 + atomic_unchecked_t items_seq; /* for delayed items */
60596 int nodes; /* for delayed nodes */
60597 wait_queue_head_t wait;
60598 };
60599 @@ -90,7 +90,7 @@ static inline void btrfs_init_delayed_root(
60600 struct btrfs_delayed_root *delayed_root)
60601 {
60602 atomic_set(&delayed_root->items, 0);
60603 - atomic_set(&delayed_root->items_seq, 0);
60604 + atomic_set_unchecked(&delayed_root->items_seq, 0);
60605 delayed_root->nodes = 0;
60606 spin_lock_init(&delayed_root->lock);
60607 init_waitqueue_head(&delayed_root->wait);
60608 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
60609 index 47aceb4..7d28b1c 100644
60610 --- a/fs/btrfs/ioctl.c
60611 +++ b/fs/btrfs/ioctl.c
60612 @@ -3965,9 +3965,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
60613 for (i = 0; i < num_types; i++) {
60614 struct btrfs_space_info *tmp;
60615
60616 + /* Don't copy in more than we allocated */
60617 if (!slot_count)
60618 break;
60619
60620 + slot_count--;
60621 +
60622 info = NULL;
60623 rcu_read_lock();
60624 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
60625 @@ -3989,10 +3992,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
60626 memcpy(dest, &space, sizeof(space));
60627 dest++;
60628 space_args.total_spaces++;
60629 - slot_count--;
60630 }
60631 - if (!slot_count)
60632 - break;
60633 }
60634 up_read(&info->groups_sem);
60635 }
60636 diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
60637 index 8e16bca..6eabd9e 100644
60638 --- a/fs/btrfs/super.c
60639 +++ b/fs/btrfs/super.c
60640 @@ -270,7 +270,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
60641 function, line, errstr);
60642 return;
60643 }
60644 - ACCESS_ONCE(trans->transaction->aborted) = errno;
60645 + ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
60646 /* Wake up anybody who may be waiting on this transaction */
60647 wake_up(&root->fs_info->transaction_wait);
60648 wake_up(&root->fs_info->transaction_blocked_wait);
60649 diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
60650 index 7869936..7e153dc 100644
60651 --- a/fs/btrfs/sysfs.c
60652 +++ b/fs/btrfs/sysfs.c
60653 @@ -475,7 +475,7 @@ static int addrm_unknown_feature_attrs(struct btrfs_fs_info *fs_info, bool add)
60654 for (set = 0; set < FEAT_MAX; set++) {
60655 int i;
60656 struct attribute *attrs[2];
60657 - struct attribute_group agroup = {
60658 + attribute_group_no_const agroup = {
60659 .name = "features",
60660 .attrs = attrs,
60661 };
60662 diff --git a/fs/btrfs/tree-log.h b/fs/btrfs/tree-log.h
60663 index 7f5b41b..e589c13 100644
60664 --- a/fs/btrfs/tree-log.h
60665 +++ b/fs/btrfs/tree-log.h
60666 @@ -41,7 +41,7 @@ static inline void btrfs_init_log_ctx(struct btrfs_log_ctx *ctx)
60667 static inline void btrfs_set_log_full_commit(struct btrfs_fs_info *fs_info,
60668 struct btrfs_trans_handle *trans)
60669 {
60670 - ACCESS_ONCE(fs_info->last_trans_log_full_commit) = trans->transid;
60671 + ACCESS_ONCE_RW(fs_info->last_trans_log_full_commit) = trans->transid;
60672 }
60673
60674 static inline int btrfs_need_log_full_commit(struct btrfs_fs_info *fs_info,
60675 diff --git a/fs/buffer.c b/fs/buffer.c
60676 index eba6e4f..af1182c 100644
60677 --- a/fs/buffer.c
60678 +++ b/fs/buffer.c
60679 @@ -3429,7 +3429,7 @@ void __init buffer_init(void)
60680 bh_cachep = kmem_cache_create("buffer_head",
60681 sizeof(struct buffer_head), 0,
60682 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
60683 - SLAB_MEM_SPREAD),
60684 + SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
60685 NULL);
60686
60687 /*
60688 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
60689 index d749731..dd333a6 100644
60690 --- a/fs/cachefiles/bind.c
60691 +++ b/fs/cachefiles/bind.c
60692 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
60693 args);
60694
60695 /* start by checking things over */
60696 - ASSERT(cache->fstop_percent >= 0 &&
60697 - cache->fstop_percent < cache->fcull_percent &&
60698 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
60699 cache->fcull_percent < cache->frun_percent &&
60700 cache->frun_percent < 100);
60701
60702 - ASSERT(cache->bstop_percent >= 0 &&
60703 - cache->bstop_percent < cache->bcull_percent &&
60704 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
60705 cache->bcull_percent < cache->brun_percent &&
60706 cache->brun_percent < 100);
60707
60708 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
60709 index b078d30..db23012 100644
60710 --- a/fs/cachefiles/daemon.c
60711 +++ b/fs/cachefiles/daemon.c
60712 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
60713 if (n > buflen)
60714 return -EMSGSIZE;
60715
60716 - if (copy_to_user(_buffer, buffer, n) != 0)
60717 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
60718 return -EFAULT;
60719
60720 return n;
60721 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
60722 if (test_bit(CACHEFILES_DEAD, &cache->flags))
60723 return -EIO;
60724
60725 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
60726 + if (datalen > PAGE_SIZE - 1)
60727 return -EOPNOTSUPP;
60728
60729 /* drag the command string into the kernel so we can parse it */
60730 @@ -385,7 +385,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
60731 if (args[0] != '%' || args[1] != '\0')
60732 return -EINVAL;
60733
60734 - if (fstop < 0 || fstop >= cache->fcull_percent)
60735 + if (fstop >= cache->fcull_percent)
60736 return cachefiles_daemon_range_error(cache, args);
60737
60738 cache->fstop_percent = fstop;
60739 @@ -457,7 +457,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
60740 if (args[0] != '%' || args[1] != '\0')
60741 return -EINVAL;
60742
60743 - if (bstop < 0 || bstop >= cache->bcull_percent)
60744 + if (bstop >= cache->bcull_percent)
60745 return cachefiles_daemon_range_error(cache, args);
60746
60747 cache->bstop_percent = bstop;
60748 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
60749 index 3d50998..0550d67 100644
60750 --- a/fs/cachefiles/internal.h
60751 +++ b/fs/cachefiles/internal.h
60752 @@ -66,7 +66,7 @@ struct cachefiles_cache {
60753 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
60754 struct rb_root active_nodes; /* active nodes (can't be culled) */
60755 rwlock_t active_lock; /* lock for active_nodes */
60756 - atomic_t gravecounter; /* graveyard uniquifier */
60757 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
60758 unsigned frun_percent; /* when to stop culling (% files) */
60759 unsigned fcull_percent; /* when to start culling (% files) */
60760 unsigned fstop_percent; /* when to stop allocating (% files) */
60761 @@ -178,19 +178,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
60762 * proc.c
60763 */
60764 #ifdef CONFIG_CACHEFILES_HISTOGRAM
60765 -extern atomic_t cachefiles_lookup_histogram[HZ];
60766 -extern atomic_t cachefiles_mkdir_histogram[HZ];
60767 -extern atomic_t cachefiles_create_histogram[HZ];
60768 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
60769 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
60770 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
60771
60772 extern int __init cachefiles_proc_init(void);
60773 extern void cachefiles_proc_cleanup(void);
60774 static inline
60775 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
60776 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
60777 {
60778 unsigned long jif = jiffies - start_jif;
60779 if (jif >= HZ)
60780 jif = HZ - 1;
60781 - atomic_inc(&histogram[jif]);
60782 + atomic_inc_unchecked(&histogram[jif]);
60783 }
60784
60785 #else
60786 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
60787 index 5bf2b41..85b93f9 100644
60788 --- a/fs/cachefiles/namei.c
60789 +++ b/fs/cachefiles/namei.c
60790 @@ -312,7 +312,7 @@ try_again:
60791 /* first step is to make up a grave dentry in the graveyard */
60792 sprintf(nbuffer, "%08x%08x",
60793 (uint32_t) get_seconds(),
60794 - (uint32_t) atomic_inc_return(&cache->gravecounter));
60795 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
60796
60797 /* do the multiway lock magic */
60798 trap = lock_rename(cache->graveyard, dir);
60799 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
60800 index eccd339..4c1d995 100644
60801 --- a/fs/cachefiles/proc.c
60802 +++ b/fs/cachefiles/proc.c
60803 @@ -14,9 +14,9 @@
60804 #include <linux/seq_file.h>
60805 #include "internal.h"
60806
60807 -atomic_t cachefiles_lookup_histogram[HZ];
60808 -atomic_t cachefiles_mkdir_histogram[HZ];
60809 -atomic_t cachefiles_create_histogram[HZ];
60810 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
60811 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
60812 +atomic_unchecked_t cachefiles_create_histogram[HZ];
60813
60814 /*
60815 * display the latency histogram
60816 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
60817 return 0;
60818 default:
60819 index = (unsigned long) v - 3;
60820 - x = atomic_read(&cachefiles_lookup_histogram[index]);
60821 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
60822 - z = atomic_read(&cachefiles_create_histogram[index]);
60823 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
60824 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
60825 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
60826 if (x == 0 && y == 0 && z == 0)
60827 return 0;
60828
60829 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
60830 index 4b1fb5c..0d2a699 100644
60831 --- a/fs/cachefiles/rdwr.c
60832 +++ b/fs/cachefiles/rdwr.c
60833 @@ -943,7 +943,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
60834 old_fs = get_fs();
60835 set_fs(KERNEL_DS);
60836 ret = file->f_op->write(
60837 - file, (const void __user *) data, len, &pos);
60838 + file, (const void __force_user *) data, len, &pos);
60839 set_fs(old_fs);
60840 kunmap(page);
60841 file_end_write(file);
60842 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
60843 index c29d6ae..719b9bb 100644
60844 --- a/fs/ceph/dir.c
60845 +++ b/fs/ceph/dir.c
60846 @@ -129,6 +129,8 @@ static int __dcache_readdir(struct file *file, struct dir_context *ctx,
60847 struct dentry *dentry, *last;
60848 struct ceph_dentry_info *di;
60849 int err = 0;
60850 + char d_name[DNAME_INLINE_LEN];
60851 + const unsigned char *name;
60852
60853 /* claim ref on last dentry we returned */
60854 last = fi->dentry;
60855 @@ -192,7 +194,12 @@ more:
60856
60857 dout(" %llu (%llu) dentry %p %.*s %p\n", di->offset, ctx->pos,
60858 dentry, dentry->d_name.len, dentry->d_name.name, dentry->d_inode);
60859 - if (!dir_emit(ctx, dentry->d_name.name,
60860 + name = dentry->d_name.name;
60861 + if (name == dentry->d_iname) {
60862 + memcpy(d_name, name, dentry->d_name.len);
60863 + name = d_name;
60864 + }
60865 + if (!dir_emit(ctx, name,
60866 dentry->d_name.len,
60867 ceph_translate_ino(dentry->d_sb, dentry->d_inode->i_ino),
60868 dentry->d_inode->i_mode >> 12)) {
60869 @@ -250,7 +257,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
60870 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
60871 struct ceph_mds_client *mdsc = fsc->mdsc;
60872 unsigned frag = fpos_frag(ctx->pos);
60873 - int off = fpos_off(ctx->pos);
60874 + unsigned int off = fpos_off(ctx->pos);
60875 int err;
60876 u32 ftype;
60877 struct ceph_mds_reply_info_parsed *rinfo;
60878 diff --git a/fs/ceph/super.c b/fs/ceph/super.c
60879 index 06150fd..192061b 100644
60880 --- a/fs/ceph/super.c
60881 +++ b/fs/ceph/super.c
60882 @@ -895,7 +895,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
60883 /*
60884 * construct our own bdi so we can control readahead, etc.
60885 */
60886 -static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
60887 +static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
60888
60889 static int ceph_register_bdi(struct super_block *sb,
60890 struct ceph_fs_client *fsc)
60891 @@ -912,7 +912,7 @@ static int ceph_register_bdi(struct super_block *sb,
60892 default_backing_dev_info.ra_pages;
60893
60894 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
60895 - atomic_long_inc_return(&bdi_seq));
60896 + atomic_long_inc_return_unchecked(&bdi_seq));
60897 if (!err)
60898 sb->s_bdi = &fsc->backing_dev_info;
60899 return err;
60900 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
60901 index f3ac415..3d2420c 100644
60902 --- a/fs/cifs/cifs_debug.c
60903 +++ b/fs/cifs/cifs_debug.c
60904 @@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
60905
60906 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
60907 #ifdef CONFIG_CIFS_STATS2
60908 - atomic_set(&totBufAllocCount, 0);
60909 - atomic_set(&totSmBufAllocCount, 0);
60910 + atomic_set_unchecked(&totBufAllocCount, 0);
60911 + atomic_set_unchecked(&totSmBufAllocCount, 0);
60912 #endif /* CONFIG_CIFS_STATS2 */
60913 spin_lock(&cifs_tcp_ses_lock);
60914 list_for_each(tmp1, &cifs_tcp_ses_list) {
60915 @@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
60916 tcon = list_entry(tmp3,
60917 struct cifs_tcon,
60918 tcon_list);
60919 - atomic_set(&tcon->num_smbs_sent, 0);
60920 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
60921 if (server->ops->clear_stats)
60922 server->ops->clear_stats(tcon);
60923 }
60924 @@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
60925 smBufAllocCount.counter, cifs_min_small);
60926 #ifdef CONFIG_CIFS_STATS2
60927 seq_printf(m, "Total Large %d Small %d Allocations\n",
60928 - atomic_read(&totBufAllocCount),
60929 - atomic_read(&totSmBufAllocCount));
60930 + atomic_read_unchecked(&totBufAllocCount),
60931 + atomic_read_unchecked(&totSmBufAllocCount));
60932 #endif /* CONFIG_CIFS_STATS2 */
60933
60934 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
60935 @@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
60936 if (tcon->need_reconnect)
60937 seq_puts(m, "\tDISCONNECTED ");
60938 seq_printf(m, "\nSMBs: %d",
60939 - atomic_read(&tcon->num_smbs_sent));
60940 + atomic_read_unchecked(&tcon->num_smbs_sent));
60941 if (server->ops->print_stats)
60942 server->ops->print_stats(m, tcon);
60943 }
60944 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
60945 index 8883980..c8ade72 100644
60946 --- a/fs/cifs/cifsfs.c
60947 +++ b/fs/cifs/cifsfs.c
60948 @@ -1072,7 +1072,7 @@ cifs_init_request_bufs(void)
60949 */
60950 cifs_req_cachep = kmem_cache_create("cifs_request",
60951 CIFSMaxBufSize + max_hdr_size, 0,
60952 - SLAB_HWCACHE_ALIGN, NULL);
60953 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
60954 if (cifs_req_cachep == NULL)
60955 return -ENOMEM;
60956
60957 @@ -1099,7 +1099,7 @@ cifs_init_request_bufs(void)
60958 efficient to alloc 1 per page off the slab compared to 17K (5page)
60959 alloc of large cifs buffers even when page debugging is on */
60960 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
60961 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
60962 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
60963 NULL);
60964 if (cifs_sm_req_cachep == NULL) {
60965 mempool_destroy(cifs_req_poolp);
60966 @@ -1184,8 +1184,8 @@ init_cifs(void)
60967 atomic_set(&bufAllocCount, 0);
60968 atomic_set(&smBufAllocCount, 0);
60969 #ifdef CONFIG_CIFS_STATS2
60970 - atomic_set(&totBufAllocCount, 0);
60971 - atomic_set(&totSmBufAllocCount, 0);
60972 + atomic_set_unchecked(&totBufAllocCount, 0);
60973 + atomic_set_unchecked(&totSmBufAllocCount, 0);
60974 #endif /* CONFIG_CIFS_STATS2 */
60975
60976 atomic_set(&midCount, 0);
60977 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
60978 index de6aed8..a0a76fd 100644
60979 --- a/fs/cifs/cifsglob.h
60980 +++ b/fs/cifs/cifsglob.h
60981 @@ -807,35 +807,35 @@ struct cifs_tcon {
60982 __u16 Flags; /* optional support bits */
60983 enum statusEnum tidStatus;
60984 #ifdef CONFIG_CIFS_STATS
60985 - atomic_t num_smbs_sent;
60986 + atomic_unchecked_t num_smbs_sent;
60987 union {
60988 struct {
60989 - atomic_t num_writes;
60990 - atomic_t num_reads;
60991 - atomic_t num_flushes;
60992 - atomic_t num_oplock_brks;
60993 - atomic_t num_opens;
60994 - atomic_t num_closes;
60995 - atomic_t num_deletes;
60996 - atomic_t num_mkdirs;
60997 - atomic_t num_posixopens;
60998 - atomic_t num_posixmkdirs;
60999 - atomic_t num_rmdirs;
61000 - atomic_t num_renames;
61001 - atomic_t num_t2renames;
61002 - atomic_t num_ffirst;
61003 - atomic_t num_fnext;
61004 - atomic_t num_fclose;
61005 - atomic_t num_hardlinks;
61006 - atomic_t num_symlinks;
61007 - atomic_t num_locks;
61008 - atomic_t num_acl_get;
61009 - atomic_t num_acl_set;
61010 + atomic_unchecked_t num_writes;
61011 + atomic_unchecked_t num_reads;
61012 + atomic_unchecked_t num_flushes;
61013 + atomic_unchecked_t num_oplock_brks;
61014 + atomic_unchecked_t num_opens;
61015 + atomic_unchecked_t num_closes;
61016 + atomic_unchecked_t num_deletes;
61017 + atomic_unchecked_t num_mkdirs;
61018 + atomic_unchecked_t num_posixopens;
61019 + atomic_unchecked_t num_posixmkdirs;
61020 + atomic_unchecked_t num_rmdirs;
61021 + atomic_unchecked_t num_renames;
61022 + atomic_unchecked_t num_t2renames;
61023 + atomic_unchecked_t num_ffirst;
61024 + atomic_unchecked_t num_fnext;
61025 + atomic_unchecked_t num_fclose;
61026 + atomic_unchecked_t num_hardlinks;
61027 + atomic_unchecked_t num_symlinks;
61028 + atomic_unchecked_t num_locks;
61029 + atomic_unchecked_t num_acl_get;
61030 + atomic_unchecked_t num_acl_set;
61031 } cifs_stats;
61032 #ifdef CONFIG_CIFS_SMB2
61033 struct {
61034 - atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
61035 - atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
61036 + atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
61037 + atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
61038 } smb2_stats;
61039 #endif /* CONFIG_CIFS_SMB2 */
61040 } stats;
61041 @@ -1172,7 +1172,7 @@ convert_delimiter(char *path, char delim)
61042 }
61043
61044 #ifdef CONFIG_CIFS_STATS
61045 -#define cifs_stats_inc atomic_inc
61046 +#define cifs_stats_inc atomic_inc_unchecked
61047
61048 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
61049 unsigned int bytes)
61050 @@ -1538,8 +1538,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
61051 /* Various Debug counters */
61052 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
61053 #ifdef CONFIG_CIFS_STATS2
61054 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
61055 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
61056 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
61057 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
61058 #endif
61059 GLOBAL_EXTERN atomic_t smBufAllocCount;
61060 GLOBAL_EXTERN atomic_t midCount;
61061 diff --git a/fs/cifs/file.c b/fs/cifs/file.c
61062 index e90a1e9..908699d 100644
61063 --- a/fs/cifs/file.c
61064 +++ b/fs/cifs/file.c
61065 @@ -1900,10 +1900,14 @@ static int cifs_writepages(struct address_space *mapping,
61066 index = mapping->writeback_index; /* Start from prev offset */
61067 end = -1;
61068 } else {
61069 - index = wbc->range_start >> PAGE_CACHE_SHIFT;
61070 - end = wbc->range_end >> PAGE_CACHE_SHIFT;
61071 - if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
61072 + if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) {
61073 range_whole = true;
61074 + index = 0;
61075 + end = ULONG_MAX;
61076 + } else {
61077 + index = wbc->range_start >> PAGE_CACHE_SHIFT;
61078 + end = wbc->range_end >> PAGE_CACHE_SHIFT;
61079 + }
61080 scanned = true;
61081 }
61082 retry:
61083 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
61084 index 3b0c62e..f7d090c 100644
61085 --- a/fs/cifs/misc.c
61086 +++ b/fs/cifs/misc.c
61087 @@ -170,7 +170,7 @@ cifs_buf_get(void)
61088 memset(ret_buf, 0, buf_size + 3);
61089 atomic_inc(&bufAllocCount);
61090 #ifdef CONFIG_CIFS_STATS2
61091 - atomic_inc(&totBufAllocCount);
61092 + atomic_inc_unchecked(&totBufAllocCount);
61093 #endif /* CONFIG_CIFS_STATS2 */
61094 }
61095
61096 @@ -205,7 +205,7 @@ cifs_small_buf_get(void)
61097 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
61098 atomic_inc(&smBufAllocCount);
61099 #ifdef CONFIG_CIFS_STATS2
61100 - atomic_inc(&totSmBufAllocCount);
61101 + atomic_inc_unchecked(&totSmBufAllocCount);
61102 #endif /* CONFIG_CIFS_STATS2 */
61103
61104 }
61105 diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
61106 index d1fdfa8..94558f8 100644
61107 --- a/fs/cifs/smb1ops.c
61108 +++ b/fs/cifs/smb1ops.c
61109 @@ -626,27 +626,27 @@ static void
61110 cifs_clear_stats(struct cifs_tcon *tcon)
61111 {
61112 #ifdef CONFIG_CIFS_STATS
61113 - atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
61114 - atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
61115 - atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
61116 - atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
61117 - atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
61118 - atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
61119 - atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
61120 - atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
61121 - atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
61122 - atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
61123 - atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
61124 - atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
61125 - atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
61126 - atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
61127 - atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
61128 - atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
61129 - atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
61130 - atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
61131 - atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
61132 - atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
61133 - atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
61134 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
61135 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
61136 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
61137 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
61138 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
61139 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
61140 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
61141 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
61142 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
61143 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
61144 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
61145 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
61146 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
61147 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
61148 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
61149 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
61150 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
61151 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
61152 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
61153 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
61154 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
61155 #endif
61156 }
61157
61158 @@ -655,36 +655,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
61159 {
61160 #ifdef CONFIG_CIFS_STATS
61161 seq_printf(m, " Oplocks breaks: %d",
61162 - atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
61163 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
61164 seq_printf(m, "\nReads: %d Bytes: %llu",
61165 - atomic_read(&tcon->stats.cifs_stats.num_reads),
61166 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
61167 (long long)(tcon->bytes_read));
61168 seq_printf(m, "\nWrites: %d Bytes: %llu",
61169 - atomic_read(&tcon->stats.cifs_stats.num_writes),
61170 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
61171 (long long)(tcon->bytes_written));
61172 seq_printf(m, "\nFlushes: %d",
61173 - atomic_read(&tcon->stats.cifs_stats.num_flushes));
61174 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
61175 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
61176 - atomic_read(&tcon->stats.cifs_stats.num_locks),
61177 - atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
61178 - atomic_read(&tcon->stats.cifs_stats.num_symlinks));
61179 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
61180 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
61181 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
61182 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
61183 - atomic_read(&tcon->stats.cifs_stats.num_opens),
61184 - atomic_read(&tcon->stats.cifs_stats.num_closes),
61185 - atomic_read(&tcon->stats.cifs_stats.num_deletes));
61186 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
61187 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
61188 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
61189 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
61190 - atomic_read(&tcon->stats.cifs_stats.num_posixopens),
61191 - atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
61192 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
61193 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
61194 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
61195 - atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
61196 - atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
61197 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
61198 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
61199 seq_printf(m, "\nRenames: %d T2 Renames %d",
61200 - atomic_read(&tcon->stats.cifs_stats.num_renames),
61201 - atomic_read(&tcon->stats.cifs_stats.num_t2renames));
61202 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
61203 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
61204 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
61205 - atomic_read(&tcon->stats.cifs_stats.num_ffirst),
61206 - atomic_read(&tcon->stats.cifs_stats.num_fnext),
61207 - atomic_read(&tcon->stats.cifs_stats.num_fclose));
61208 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
61209 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
61210 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
61211 #endif
61212 }
61213
61214 diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
61215 index 787844b..8e7bc7d 100644
61216 --- a/fs/cifs/smb2ops.c
61217 +++ b/fs/cifs/smb2ops.c
61218 @@ -364,8 +364,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
61219 #ifdef CONFIG_CIFS_STATS
61220 int i;
61221 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
61222 - atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
61223 - atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
61224 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
61225 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
61226 }
61227 #endif
61228 }
61229 @@ -405,65 +405,65 @@ static void
61230 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
61231 {
61232 #ifdef CONFIG_CIFS_STATS
61233 - atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
61234 - atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
61235 + atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
61236 + atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
61237 seq_printf(m, "\nNegotiates: %d sent %d failed",
61238 - atomic_read(&sent[SMB2_NEGOTIATE_HE]),
61239 - atomic_read(&failed[SMB2_NEGOTIATE_HE]));
61240 + atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
61241 + atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
61242 seq_printf(m, "\nSessionSetups: %d sent %d failed",
61243 - atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
61244 - atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
61245 + atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
61246 + atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
61247 seq_printf(m, "\nLogoffs: %d sent %d failed",
61248 - atomic_read(&sent[SMB2_LOGOFF_HE]),
61249 - atomic_read(&failed[SMB2_LOGOFF_HE]));
61250 + atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
61251 + atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
61252 seq_printf(m, "\nTreeConnects: %d sent %d failed",
61253 - atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
61254 - atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
61255 + atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
61256 + atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
61257 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
61258 - atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
61259 - atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
61260 + atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
61261 + atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
61262 seq_printf(m, "\nCreates: %d sent %d failed",
61263 - atomic_read(&sent[SMB2_CREATE_HE]),
61264 - atomic_read(&failed[SMB2_CREATE_HE]));
61265 + atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
61266 + atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
61267 seq_printf(m, "\nCloses: %d sent %d failed",
61268 - atomic_read(&sent[SMB2_CLOSE_HE]),
61269 - atomic_read(&failed[SMB2_CLOSE_HE]));
61270 + atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
61271 + atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
61272 seq_printf(m, "\nFlushes: %d sent %d failed",
61273 - atomic_read(&sent[SMB2_FLUSH_HE]),
61274 - atomic_read(&failed[SMB2_FLUSH_HE]));
61275 + atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
61276 + atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
61277 seq_printf(m, "\nReads: %d sent %d failed",
61278 - atomic_read(&sent[SMB2_READ_HE]),
61279 - atomic_read(&failed[SMB2_READ_HE]));
61280 + atomic_read_unchecked(&sent[SMB2_READ_HE]),
61281 + atomic_read_unchecked(&failed[SMB2_READ_HE]));
61282 seq_printf(m, "\nWrites: %d sent %d failed",
61283 - atomic_read(&sent[SMB2_WRITE_HE]),
61284 - atomic_read(&failed[SMB2_WRITE_HE]));
61285 + atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
61286 + atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
61287 seq_printf(m, "\nLocks: %d sent %d failed",
61288 - atomic_read(&sent[SMB2_LOCK_HE]),
61289 - atomic_read(&failed[SMB2_LOCK_HE]));
61290 + atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
61291 + atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
61292 seq_printf(m, "\nIOCTLs: %d sent %d failed",
61293 - atomic_read(&sent[SMB2_IOCTL_HE]),
61294 - atomic_read(&failed[SMB2_IOCTL_HE]));
61295 + atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
61296 + atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
61297 seq_printf(m, "\nCancels: %d sent %d failed",
61298 - atomic_read(&sent[SMB2_CANCEL_HE]),
61299 - atomic_read(&failed[SMB2_CANCEL_HE]));
61300 + atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
61301 + atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
61302 seq_printf(m, "\nEchos: %d sent %d failed",
61303 - atomic_read(&sent[SMB2_ECHO_HE]),
61304 - atomic_read(&failed[SMB2_ECHO_HE]));
61305 + atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
61306 + atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
61307 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
61308 - atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
61309 - atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
61310 + atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
61311 + atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
61312 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
61313 - atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
61314 - atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
61315 + atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
61316 + atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
61317 seq_printf(m, "\nQueryInfos: %d sent %d failed",
61318 - atomic_read(&sent[SMB2_QUERY_INFO_HE]),
61319 - atomic_read(&failed[SMB2_QUERY_INFO_HE]));
61320 + atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
61321 + atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
61322 seq_printf(m, "\nSetInfos: %d sent %d failed",
61323 - atomic_read(&sent[SMB2_SET_INFO_HE]),
61324 - atomic_read(&failed[SMB2_SET_INFO_HE]));
61325 + atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
61326 + atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
61327 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
61328 - atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
61329 - atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
61330 + atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
61331 + atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
61332 #endif
61333 }
61334
61335 diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
61336 index b0b260d..c8927e1 100644
61337 --- a/fs/cifs/smb2pdu.c
61338 +++ b/fs/cifs/smb2pdu.c
61339 @@ -2105,8 +2105,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
61340 default:
61341 cifs_dbg(VFS, "info level %u isn't supported\n",
61342 srch_inf->info_level);
61343 - rc = -EINVAL;
61344 - goto qdir_exit;
61345 + return -EINVAL;
61346 }
61347
61348 req->FileIndex = cpu_to_le32(index);
61349 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
61350 index 1da168c..8bc7ff6 100644
61351 --- a/fs/coda/cache.c
61352 +++ b/fs/coda/cache.c
61353 @@ -24,7 +24,7 @@
61354 #include "coda_linux.h"
61355 #include "coda_cache.h"
61356
61357 -static atomic_t permission_epoch = ATOMIC_INIT(0);
61358 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
61359
61360 /* replace or extend an acl cache hit */
61361 void coda_cache_enter(struct inode *inode, int mask)
61362 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
61363 struct coda_inode_info *cii = ITOC(inode);
61364
61365 spin_lock(&cii->c_lock);
61366 - cii->c_cached_epoch = atomic_read(&permission_epoch);
61367 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
61368 if (!uid_eq(cii->c_uid, current_fsuid())) {
61369 cii->c_uid = current_fsuid();
61370 cii->c_cached_perm = mask;
61371 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
61372 {
61373 struct coda_inode_info *cii = ITOC(inode);
61374 spin_lock(&cii->c_lock);
61375 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
61376 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
61377 spin_unlock(&cii->c_lock);
61378 }
61379
61380 /* remove all acl caches */
61381 void coda_cache_clear_all(struct super_block *sb)
61382 {
61383 - atomic_inc(&permission_epoch);
61384 + atomic_inc_unchecked(&permission_epoch);
61385 }
61386
61387
61388 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
61389 spin_lock(&cii->c_lock);
61390 hit = (mask & cii->c_cached_perm) == mask &&
61391 uid_eq(cii->c_uid, current_fsuid()) &&
61392 - cii->c_cached_epoch == atomic_read(&permission_epoch);
61393 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
61394 spin_unlock(&cii->c_lock);
61395
61396 return hit;
61397 diff --git a/fs/compat.c b/fs/compat.c
61398 index 66d3d3c..9c10175 100644
61399 --- a/fs/compat.c
61400 +++ b/fs/compat.c
61401 @@ -54,7 +54,7 @@
61402 #include <asm/ioctls.h>
61403 #include "internal.h"
61404
61405 -int compat_log = 1;
61406 +int compat_log = 0;
61407
61408 int compat_printk(const char *fmt, ...)
61409 {
61410 @@ -512,7 +512,7 @@ COMPAT_SYSCALL_DEFINE2(io_setup, unsigned, nr_reqs, u32 __user *, ctx32p)
61411
61412 set_fs(KERNEL_DS);
61413 /* The __user pointer cast is valid because of the set_fs() */
61414 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
61415 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
61416 set_fs(oldfs);
61417 /* truncating is ok because it's a user address */
61418 if (!ret)
61419 @@ -562,7 +562,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
61420 goto out;
61421
61422 ret = -EINVAL;
61423 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
61424 + if (nr_segs > UIO_MAXIOV)
61425 goto out;
61426 if (nr_segs > fast_segs) {
61427 ret = -ENOMEM;
61428 @@ -850,6 +850,7 @@ struct compat_old_linux_dirent {
61429 struct compat_readdir_callback {
61430 struct dir_context ctx;
61431 struct compat_old_linux_dirent __user *dirent;
61432 + struct file * file;
61433 int result;
61434 };
61435
61436 @@ -867,6 +868,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
61437 buf->result = -EOVERFLOW;
61438 return -EOVERFLOW;
61439 }
61440 +
61441 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
61442 + return 0;
61443 +
61444 buf->result++;
61445 dirent = buf->dirent;
61446 if (!access_ok(VERIFY_WRITE, dirent,
61447 @@ -898,6 +903,7 @@ COMPAT_SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
61448 if (!f.file)
61449 return -EBADF;
61450
61451 + buf.file = f.file;
61452 error = iterate_dir(f.file, &buf.ctx);
61453 if (buf.result)
61454 error = buf.result;
61455 @@ -917,6 +923,7 @@ struct compat_getdents_callback {
61456 struct dir_context ctx;
61457 struct compat_linux_dirent __user *current_dir;
61458 struct compat_linux_dirent __user *previous;
61459 + struct file * file;
61460 int count;
61461 int error;
61462 };
61463 @@ -938,6 +945,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
61464 buf->error = -EOVERFLOW;
61465 return -EOVERFLOW;
61466 }
61467 +
61468 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
61469 + return 0;
61470 +
61471 dirent = buf->previous;
61472 if (dirent) {
61473 if (__put_user(offset, &dirent->d_off))
61474 @@ -983,6 +994,7 @@ COMPAT_SYSCALL_DEFINE3(getdents, unsigned int, fd,
61475 if (!f.file)
61476 return -EBADF;
61477
61478 + buf.file = f.file;
61479 error = iterate_dir(f.file, &buf.ctx);
61480 if (error >= 0)
61481 error = buf.error;
61482 @@ -1003,6 +1015,7 @@ struct compat_getdents_callback64 {
61483 struct dir_context ctx;
61484 struct linux_dirent64 __user *current_dir;
61485 struct linux_dirent64 __user *previous;
61486 + struct file * file;
61487 int count;
61488 int error;
61489 };
61490 @@ -1019,6 +1032,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
61491 buf->error = -EINVAL; /* only used if we fail.. */
61492 if (reclen > buf->count)
61493 return -EINVAL;
61494 +
61495 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
61496 + return 0;
61497 +
61498 dirent = buf->previous;
61499
61500 if (dirent) {
61501 @@ -1068,6 +1085,7 @@ COMPAT_SYSCALL_DEFINE3(getdents64, unsigned int, fd,
61502 if (!f.file)
61503 return -EBADF;
61504
61505 + buf.file = f.file;
61506 error = iterate_dir(f.file, &buf.ctx);
61507 if (error >= 0)
61508 error = buf.error;
61509 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
61510 index 4d24d17..4f8c09e 100644
61511 --- a/fs/compat_binfmt_elf.c
61512 +++ b/fs/compat_binfmt_elf.c
61513 @@ -30,11 +30,13 @@
61514 #undef elf_phdr
61515 #undef elf_shdr
61516 #undef elf_note
61517 +#undef elf_dyn
61518 #undef elf_addr_t
61519 #define elfhdr elf32_hdr
61520 #define elf_phdr elf32_phdr
61521 #define elf_shdr elf32_shdr
61522 #define elf_note elf32_note
61523 +#define elf_dyn Elf32_Dyn
61524 #define elf_addr_t Elf32_Addr
61525
61526 /*
61527 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
61528 index e822890..fed89d9 100644
61529 --- a/fs/compat_ioctl.c
61530 +++ b/fs/compat_ioctl.c
61531 @@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
61532 return -EFAULT;
61533 if (__get_user(udata, &ss32->iomem_base))
61534 return -EFAULT;
61535 - ss.iomem_base = compat_ptr(udata);
61536 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
61537 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
61538 __get_user(ss.port_high, &ss32->port_high))
61539 return -EFAULT;
61540 @@ -703,8 +703,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
61541 for (i = 0; i < nmsgs; i++) {
61542 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
61543 return -EFAULT;
61544 - if (get_user(datap, &umsgs[i].buf) ||
61545 - put_user(compat_ptr(datap), &tmsgs[i].buf))
61546 + if (get_user(datap, (compat_caddr_t __user *)&umsgs[i].buf) ||
61547 + put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
61548 return -EFAULT;
61549 }
61550 return sys_ioctl(fd, cmd, (unsigned long)tdata);
61551 @@ -797,7 +797,7 @@ static int compat_ioctl_preallocate(struct file *file,
61552 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
61553 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
61554 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
61555 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
61556 + copy_in_user(p->l_pad, p32->l_pad, 4*sizeof(u32)))
61557 return -EFAULT;
61558
61559 return ioctl_preallocate(file, p);
61560 @@ -1618,8 +1618,8 @@ COMPAT_SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd,
61561 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
61562 {
61563 unsigned int a, b;
61564 - a = *(unsigned int *)p;
61565 - b = *(unsigned int *)q;
61566 + a = *(const unsigned int *)p;
61567 + b = *(const unsigned int *)q;
61568 if (a > b)
61569 return 1;
61570 if (a < b)
61571 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
61572 index 668dcab..daebcd6 100644
61573 --- a/fs/configfs/dir.c
61574 +++ b/fs/configfs/dir.c
61575 @@ -1548,7 +1548,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
61576 }
61577 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
61578 struct configfs_dirent *next;
61579 - const char *name;
61580 + const unsigned char * name;
61581 + char d_name[sizeof(next->s_dentry->d_iname)];
61582 int len;
61583 struct inode *inode = NULL;
61584
61585 @@ -1557,7 +1558,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
61586 continue;
61587
61588 name = configfs_get_name(next);
61589 - len = strlen(name);
61590 + if (next->s_dentry && name == next->s_dentry->d_iname) {
61591 + len = next->s_dentry->d_name.len;
61592 + memcpy(d_name, name, len);
61593 + name = d_name;
61594 + } else
61595 + len = strlen(name);
61596
61597 /*
61598 * We'll have a dentry and an inode for
61599 diff --git a/fs/coredump.c b/fs/coredump.c
61600 index a93f7e6..d58bcbe 100644
61601 --- a/fs/coredump.c
61602 +++ b/fs/coredump.c
61603 @@ -442,8 +442,8 @@ static void wait_for_dump_helpers(struct file *file)
61604 struct pipe_inode_info *pipe = file->private_data;
61605
61606 pipe_lock(pipe);
61607 - pipe->readers++;
61608 - pipe->writers--;
61609 + atomic_inc(&pipe->readers);
61610 + atomic_dec(&pipe->writers);
61611 wake_up_interruptible_sync(&pipe->wait);
61612 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
61613 pipe_unlock(pipe);
61614 @@ -452,11 +452,11 @@ static void wait_for_dump_helpers(struct file *file)
61615 * We actually want wait_event_freezable() but then we need
61616 * to clear TIF_SIGPENDING and improve dump_interrupted().
61617 */
61618 - wait_event_interruptible(pipe->wait, pipe->readers == 1);
61619 + wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
61620
61621 pipe_lock(pipe);
61622 - pipe->readers--;
61623 - pipe->writers++;
61624 + atomic_dec(&pipe->readers);
61625 + atomic_inc(&pipe->writers);
61626 pipe_unlock(pipe);
61627 }
61628
61629 @@ -503,7 +503,9 @@ void do_coredump(const siginfo_t *siginfo)
61630 struct files_struct *displaced;
61631 bool need_nonrelative = false;
61632 bool core_dumped = false;
61633 - static atomic_t core_dump_count = ATOMIC_INIT(0);
61634 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
61635 + long signr = siginfo->si_signo;
61636 + int dumpable;
61637 struct coredump_params cprm = {
61638 .siginfo = siginfo,
61639 .regs = signal_pt_regs(),
61640 @@ -516,12 +518,17 @@ void do_coredump(const siginfo_t *siginfo)
61641 .mm_flags = mm->flags,
61642 };
61643
61644 - audit_core_dumps(siginfo->si_signo);
61645 + audit_core_dumps(signr);
61646 +
61647 + dumpable = __get_dumpable(cprm.mm_flags);
61648 +
61649 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
61650 + gr_handle_brute_attach(dumpable);
61651
61652 binfmt = mm->binfmt;
61653 if (!binfmt || !binfmt->core_dump)
61654 goto fail;
61655 - if (!__get_dumpable(cprm.mm_flags))
61656 + if (!dumpable)
61657 goto fail;
61658
61659 cred = prepare_creds();
61660 @@ -540,7 +547,7 @@ void do_coredump(const siginfo_t *siginfo)
61661 need_nonrelative = true;
61662 }
61663
61664 - retval = coredump_wait(siginfo->si_signo, &core_state);
61665 + retval = coredump_wait(signr, &core_state);
61666 if (retval < 0)
61667 goto fail_creds;
61668
61669 @@ -583,7 +590,7 @@ void do_coredump(const siginfo_t *siginfo)
61670 }
61671 cprm.limit = RLIM_INFINITY;
61672
61673 - dump_count = atomic_inc_return(&core_dump_count);
61674 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
61675 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
61676 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
61677 task_tgid_vnr(current), current->comm);
61678 @@ -615,6 +622,8 @@ void do_coredump(const siginfo_t *siginfo)
61679 } else {
61680 struct inode *inode;
61681
61682 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
61683 +
61684 if (cprm.limit < binfmt->min_coredump)
61685 goto fail_unlock;
61686
61687 @@ -673,7 +682,7 @@ close_fail:
61688 filp_close(cprm.file, NULL);
61689 fail_dropcount:
61690 if (ispipe)
61691 - atomic_dec(&core_dump_count);
61692 + atomic_dec_unchecked(&core_dump_count);
61693 fail_unlock:
61694 kfree(cn.corename);
61695 coredump_finish(mm, core_dumped);
61696 @@ -694,6 +703,8 @@ int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
61697 struct file *file = cprm->file;
61698 loff_t pos = file->f_pos;
61699 ssize_t n;
61700 +
61701 + gr_learn_resource(current, RLIMIT_CORE, cprm->written + nr, 1);
61702 if (cprm->written + nr > cprm->limit)
61703 return 0;
61704 while (nr) {
61705 diff --git a/fs/dcache.c b/fs/dcache.c
61706 index 06f6585..f95a6d1 100644
61707 --- a/fs/dcache.c
61708 +++ b/fs/dcache.c
61709 @@ -1445,7 +1445,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
61710 */
61711 dentry->d_iname[DNAME_INLINE_LEN-1] = 0;
61712 if (name->len > DNAME_INLINE_LEN-1) {
61713 - dname = kmalloc(name->len + 1, GFP_KERNEL);
61714 + dname = kmalloc(round_up(name->len + 1, sizeof(unsigned long)), GFP_KERNEL);
61715 if (!dname) {
61716 kmem_cache_free(dentry_cache, dentry);
61717 return NULL;
61718 @@ -3413,7 +3413,8 @@ void __init vfs_caches_init(unsigned long mempages)
61719 mempages -= reserve;
61720
61721 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
61722 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
61723 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
61724 + SLAB_NO_SANITIZE, NULL);
61725
61726 dcache_init();
61727 inode_init();
61728 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
61729 index 8c41b52..145b1b9 100644
61730 --- a/fs/debugfs/inode.c
61731 +++ b/fs/debugfs/inode.c
61732 @@ -416,7 +416,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
61733 */
61734 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
61735 {
61736 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
61737 + return __create_file(name, S_IFDIR | S_IRWXU,
61738 +#else
61739 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
61740 +#endif
61741 parent, NULL, NULL);
61742 }
61743 EXPORT_SYMBOL_GPL(debugfs_create_dir);
61744 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
61745 index d4a9431..77f9b2e 100644
61746 --- a/fs/ecryptfs/inode.c
61747 +++ b/fs/ecryptfs/inode.c
61748 @@ -673,7 +673,7 @@ static char *ecryptfs_readlink_lower(struct dentry *dentry, size_t *bufsiz)
61749 old_fs = get_fs();
61750 set_fs(get_ds());
61751 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
61752 - (char __user *)lower_buf,
61753 + (char __force_user *)lower_buf,
61754 PATH_MAX);
61755 set_fs(old_fs);
61756 if (rc < 0)
61757 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
61758 index e4141f2..d8263e8 100644
61759 --- a/fs/ecryptfs/miscdev.c
61760 +++ b/fs/ecryptfs/miscdev.c
61761 @@ -304,7 +304,7 @@ check_list:
61762 goto out_unlock_msg_ctx;
61763 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
61764 if (msg_ctx->msg) {
61765 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
61766 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
61767 goto out_unlock_msg_ctx;
61768 i += packet_length_size;
61769 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
61770 diff --git a/fs/exec.c b/fs/exec.c
61771 index a3d33fe..49e9bc9 100644
61772 --- a/fs/exec.c
61773 +++ b/fs/exec.c
61774 @@ -56,8 +56,20 @@
61775 #include <linux/pipe_fs_i.h>
61776 #include <linux/oom.h>
61777 #include <linux/compat.h>
61778 +#include <linux/random.h>
61779 +#include <linux/seq_file.h>
61780 +#include <linux/coredump.h>
61781 +#include <linux/mman.h>
61782 +
61783 +#ifdef CONFIG_PAX_REFCOUNT
61784 +#include <linux/kallsyms.h>
61785 +#include <linux/kdebug.h>
61786 +#endif
61787 +
61788 +#include <trace/events/fs.h>
61789
61790 #include <asm/uaccess.h>
61791 +#include <asm/sections.h>
61792 #include <asm/mmu_context.h>
61793 #include <asm/tlb.h>
61794
61795 @@ -66,19 +78,34 @@
61796
61797 #include <trace/events/sched.h>
61798
61799 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
61800 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
61801 +{
61802 + 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");
61803 +}
61804 +#endif
61805 +
61806 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
61807 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
61808 +EXPORT_SYMBOL(pax_set_initial_flags_func);
61809 +#endif
61810 +
61811 int suid_dumpable = 0;
61812
61813 static LIST_HEAD(formats);
61814 static DEFINE_RWLOCK(binfmt_lock);
61815
61816 +extern int gr_process_kernel_exec_ban(void);
61817 +extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
61818 +
61819 void __register_binfmt(struct linux_binfmt * fmt, int insert)
61820 {
61821 BUG_ON(!fmt);
61822 if (WARN_ON(!fmt->load_binary))
61823 return;
61824 write_lock(&binfmt_lock);
61825 - insert ? list_add(&fmt->lh, &formats) :
61826 - list_add_tail(&fmt->lh, &formats);
61827 + insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
61828 + pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
61829 write_unlock(&binfmt_lock);
61830 }
61831
61832 @@ -87,7 +114,7 @@ EXPORT_SYMBOL(__register_binfmt);
61833 void unregister_binfmt(struct linux_binfmt * fmt)
61834 {
61835 write_lock(&binfmt_lock);
61836 - list_del(&fmt->lh);
61837 + pax_list_del((struct list_head *)&fmt->lh);
61838 write_unlock(&binfmt_lock);
61839 }
61840
61841 @@ -183,18 +210,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
61842 int write)
61843 {
61844 struct page *page;
61845 - int ret;
61846
61847 -#ifdef CONFIG_STACK_GROWSUP
61848 - if (write) {
61849 - ret = expand_downwards(bprm->vma, pos);
61850 - if (ret < 0)
61851 - return NULL;
61852 - }
61853 -#endif
61854 - ret = get_user_pages(current, bprm->mm, pos,
61855 - 1, write, 1, &page, NULL);
61856 - if (ret <= 0)
61857 + if (0 > expand_downwards(bprm->vma, pos))
61858 + return NULL;
61859 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
61860 return NULL;
61861
61862 if (write) {
61863 @@ -210,6 +229,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
61864 if (size <= ARG_MAX)
61865 return page;
61866
61867 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61868 + // only allow 512KB for argv+env on suid/sgid binaries
61869 + // to prevent easy ASLR exhaustion
61870 + if (((!uid_eq(bprm->cred->euid, current_euid())) ||
61871 + (!gid_eq(bprm->cred->egid, current_egid()))) &&
61872 + (size > (512 * 1024))) {
61873 + put_page(page);
61874 + return NULL;
61875 + }
61876 +#endif
61877 +
61878 /*
61879 * Limit to 1/4-th the stack size for the argv+env strings.
61880 * This ensures that:
61881 @@ -269,6 +299,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
61882 vma->vm_end = STACK_TOP_MAX;
61883 vma->vm_start = vma->vm_end - PAGE_SIZE;
61884 vma->vm_flags = VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
61885 +
61886 +#ifdef CONFIG_PAX_SEGMEXEC
61887 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
61888 +#endif
61889 +
61890 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
61891 INIT_LIST_HEAD(&vma->anon_vma_chain);
61892
61893 @@ -279,6 +314,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
61894 mm->stack_vm = mm->total_vm = 1;
61895 up_write(&mm->mmap_sem);
61896 bprm->p = vma->vm_end - sizeof(void *);
61897 +
61898 +#ifdef CONFIG_PAX_RANDUSTACK
61899 + if (randomize_va_space)
61900 + bprm->p ^= prandom_u32() & ~PAGE_MASK;
61901 +#endif
61902 +
61903 return 0;
61904 err:
61905 up_write(&mm->mmap_sem);
61906 @@ -399,7 +440,7 @@ struct user_arg_ptr {
61907 } ptr;
61908 };
61909
61910 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
61911 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
61912 {
61913 const char __user *native;
61914
61915 @@ -408,14 +449,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
61916 compat_uptr_t compat;
61917
61918 if (get_user(compat, argv.ptr.compat + nr))
61919 - return ERR_PTR(-EFAULT);
61920 + return (const char __force_user *)ERR_PTR(-EFAULT);
61921
61922 return compat_ptr(compat);
61923 }
61924 #endif
61925
61926 if (get_user(native, argv.ptr.native + nr))
61927 - return ERR_PTR(-EFAULT);
61928 + return (const char __force_user *)ERR_PTR(-EFAULT);
61929
61930 return native;
61931 }
61932 @@ -434,7 +475,7 @@ static int count(struct user_arg_ptr argv, int max)
61933 if (!p)
61934 break;
61935
61936 - if (IS_ERR(p))
61937 + if (IS_ERR((const char __force_kernel *)p))
61938 return -EFAULT;
61939
61940 if (i >= max)
61941 @@ -469,7 +510,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
61942
61943 ret = -EFAULT;
61944 str = get_user_arg_ptr(argv, argc);
61945 - if (IS_ERR(str))
61946 + if (IS_ERR((const char __force_kernel *)str))
61947 goto out;
61948
61949 len = strnlen_user(str, MAX_ARG_STRLEN);
61950 @@ -551,7 +592,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
61951 int r;
61952 mm_segment_t oldfs = get_fs();
61953 struct user_arg_ptr argv = {
61954 - .ptr.native = (const char __user *const __user *)__argv,
61955 + .ptr.native = (const char __user * const __force_user *)__argv,
61956 };
61957
61958 set_fs(KERNEL_DS);
61959 @@ -586,7 +627,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
61960 unsigned long new_end = old_end - shift;
61961 struct mmu_gather tlb;
61962
61963 - BUG_ON(new_start > new_end);
61964 + if (new_start >= new_end || new_start < mmap_min_addr)
61965 + return -ENOMEM;
61966
61967 /*
61968 * ensure there are no vmas between where we want to go
61969 @@ -595,6 +637,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
61970 if (vma != find_vma(mm, new_start))
61971 return -EFAULT;
61972
61973 +#ifdef CONFIG_PAX_SEGMEXEC
61974 + BUG_ON(pax_find_mirror_vma(vma));
61975 +#endif
61976 +
61977 /*
61978 * cover the whole range: [new_start, old_end)
61979 */
61980 @@ -675,10 +721,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
61981 stack_top = arch_align_stack(stack_top);
61982 stack_top = PAGE_ALIGN(stack_top);
61983
61984 - if (unlikely(stack_top < mmap_min_addr) ||
61985 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
61986 - return -ENOMEM;
61987 -
61988 stack_shift = vma->vm_end - stack_top;
61989
61990 bprm->p -= stack_shift;
61991 @@ -690,8 +732,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
61992 bprm->exec -= stack_shift;
61993
61994 down_write(&mm->mmap_sem);
61995 +
61996 + /* Move stack pages down in memory. */
61997 + if (stack_shift) {
61998 + ret = shift_arg_pages(vma, stack_shift);
61999 + if (ret)
62000 + goto out_unlock;
62001 + }
62002 +
62003 vm_flags = VM_STACK_FLAGS;
62004
62005 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
62006 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
62007 + vm_flags &= ~VM_EXEC;
62008 +
62009 +#ifdef CONFIG_PAX_MPROTECT
62010 + if (mm->pax_flags & MF_PAX_MPROTECT)
62011 + vm_flags &= ~VM_MAYEXEC;
62012 +#endif
62013 +
62014 + }
62015 +#endif
62016 +
62017 /*
62018 * Adjust stack execute permissions; explicitly enable for
62019 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
62020 @@ -710,13 +772,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
62021 goto out_unlock;
62022 BUG_ON(prev != vma);
62023
62024 - /* Move stack pages down in memory. */
62025 - if (stack_shift) {
62026 - ret = shift_arg_pages(vma, stack_shift);
62027 - if (ret)
62028 - goto out_unlock;
62029 - }
62030 -
62031 /* mprotect_fixup is overkill to remove the temporary stack flags */
62032 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
62033
62034 @@ -740,6 +795,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
62035 #endif
62036 current->mm->start_stack = bprm->p;
62037 ret = expand_stack(vma, stack_base);
62038 +
62039 +#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
62040 + if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
62041 + unsigned long size;
62042 + vm_flags_t vm_flags;
62043 +
62044 + size = STACK_TOP - vma->vm_end;
62045 + vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
62046 +
62047 + ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
62048 +
62049 +#ifdef CONFIG_X86
62050 + if (!ret) {
62051 + size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
62052 + ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
62053 + }
62054 +#endif
62055 +
62056 + }
62057 +#endif
62058 +
62059 if (ret)
62060 ret = -EFAULT;
62061
62062 @@ -775,6 +851,8 @@ static struct file *do_open_exec(struct filename *name)
62063
62064 fsnotify_open(file);
62065
62066 + trace_open_exec(name->name);
62067 +
62068 err = deny_write_access(file);
62069 if (err)
62070 goto exit;
62071 @@ -804,7 +882,7 @@ int kernel_read(struct file *file, loff_t offset,
62072 old_fs = get_fs();
62073 set_fs(get_ds());
62074 /* The cast to a user pointer is valid due to the set_fs() */
62075 - result = vfs_read(file, (void __user *)addr, count, &pos);
62076 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
62077 set_fs(old_fs);
62078 return result;
62079 }
62080 @@ -849,6 +927,7 @@ static int exec_mmap(struct mm_struct *mm)
62081 tsk->mm = mm;
62082 tsk->active_mm = mm;
62083 activate_mm(active_mm, mm);
62084 + populate_stack();
62085 tsk->mm->vmacache_seqnum = 0;
62086 vmacache_flush(tsk);
62087 task_unlock(tsk);
62088 @@ -1247,7 +1326,7 @@ static void check_unsafe_exec(struct linux_binprm *bprm)
62089 }
62090 rcu_read_unlock();
62091
62092 - if (p->fs->users > n_fs)
62093 + if (atomic_read(&p->fs->users) > n_fs)
62094 bprm->unsafe |= LSM_UNSAFE_SHARE;
62095 else
62096 p->fs->in_exec = 1;
62097 @@ -1423,6 +1502,31 @@ static int exec_binprm(struct linux_binprm *bprm)
62098 return ret;
62099 }
62100
62101 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62102 +static DEFINE_PER_CPU(u64, exec_counter);
62103 +static int __init init_exec_counters(void)
62104 +{
62105 + unsigned int cpu;
62106 +
62107 + for_each_possible_cpu(cpu) {
62108 + per_cpu(exec_counter, cpu) = (u64)cpu;
62109 + }
62110 +
62111 + return 0;
62112 +}
62113 +early_initcall(init_exec_counters);
62114 +static inline void increment_exec_counter(void)
62115 +{
62116 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
62117 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
62118 +}
62119 +#else
62120 +static inline void increment_exec_counter(void) {}
62121 +#endif
62122 +
62123 +extern void gr_handle_exec_args(struct linux_binprm *bprm,
62124 + struct user_arg_ptr argv);
62125 +
62126 /*
62127 * sys_execve() executes a new program.
62128 */
62129 @@ -1430,6 +1534,11 @@ static int do_execve_common(struct filename *filename,
62130 struct user_arg_ptr argv,
62131 struct user_arg_ptr envp)
62132 {
62133 +#ifdef CONFIG_GRKERNSEC
62134 + struct file *old_exec_file;
62135 + struct acl_subject_label *old_acl;
62136 + struct rlimit old_rlim[RLIM_NLIMITS];
62137 +#endif
62138 struct linux_binprm *bprm;
62139 struct file *file;
62140 struct files_struct *displaced;
62141 @@ -1438,6 +1547,8 @@ static int do_execve_common(struct filename *filename,
62142 if (IS_ERR(filename))
62143 return PTR_ERR(filename);
62144
62145 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
62146 +
62147 /*
62148 * We move the actual failure in case of RLIMIT_NPROC excess from
62149 * set*uid() to execve() because too many poorly written programs
62150 @@ -1475,11 +1586,21 @@ static int do_execve_common(struct filename *filename,
62151 if (IS_ERR(file))
62152 goto out_unmark;
62153
62154 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
62155 + retval = -EPERM;
62156 + goto out_unmark;
62157 + }
62158 +
62159 sched_exec();
62160
62161 bprm->file = file;
62162 bprm->filename = bprm->interp = filename->name;
62163
62164 + if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
62165 + retval = -EACCES;
62166 + goto out_unmark;
62167 + }
62168 +
62169 retval = bprm_mm_init(bprm);
62170 if (retval)
62171 goto out_unmark;
62172 @@ -1496,24 +1617,70 @@ static int do_execve_common(struct filename *filename,
62173 if (retval < 0)
62174 goto out;
62175
62176 +#ifdef CONFIG_GRKERNSEC
62177 + old_acl = current->acl;
62178 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
62179 + old_exec_file = current->exec_file;
62180 + get_file(file);
62181 + current->exec_file = file;
62182 +#endif
62183 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62184 + /* limit suid stack to 8MB
62185 + * we saved the old limits above and will restore them if this exec fails
62186 + */
62187 + if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
62188 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
62189 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
62190 +#endif
62191 +
62192 + if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
62193 + retval = -EPERM;
62194 + goto out_fail;
62195 + }
62196 +
62197 + if (!gr_tpe_allow(file)) {
62198 + retval = -EACCES;
62199 + goto out_fail;
62200 + }
62201 +
62202 + if (gr_check_crash_exec(file)) {
62203 + retval = -EACCES;
62204 + goto out_fail;
62205 + }
62206 +
62207 + retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
62208 + bprm->unsafe);
62209 + if (retval < 0)
62210 + goto out_fail;
62211 +
62212 retval = copy_strings_kernel(1, &bprm->filename, bprm);
62213 if (retval < 0)
62214 - goto out;
62215 + goto out_fail;
62216
62217 bprm->exec = bprm->p;
62218 retval = copy_strings(bprm->envc, envp, bprm);
62219 if (retval < 0)
62220 - goto out;
62221 + goto out_fail;
62222
62223 retval = copy_strings(bprm->argc, argv, bprm);
62224 if (retval < 0)
62225 - goto out;
62226 + goto out_fail;
62227 +
62228 + gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
62229 +
62230 + gr_handle_exec_args(bprm, argv);
62231
62232 retval = exec_binprm(bprm);
62233 if (retval < 0)
62234 - goto out;
62235 + goto out_fail;
62236 +#ifdef CONFIG_GRKERNSEC
62237 + if (old_exec_file)
62238 + fput(old_exec_file);
62239 +#endif
62240
62241 /* execve succeeded */
62242 +
62243 + increment_exec_counter();
62244 current->fs->in_exec = 0;
62245 current->in_execve = 0;
62246 acct_update_integrals(current);
62247 @@ -1524,6 +1691,14 @@ static int do_execve_common(struct filename *filename,
62248 put_files_struct(displaced);
62249 return retval;
62250
62251 +out_fail:
62252 +#ifdef CONFIG_GRKERNSEC
62253 + current->acl = old_acl;
62254 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
62255 + fput(current->exec_file);
62256 + current->exec_file = old_exec_file;
62257 +#endif
62258 +
62259 out:
62260 if (bprm->mm) {
62261 acct_arg_size(bprm, 0);
62262 @@ -1615,3 +1790,312 @@ COMPAT_SYSCALL_DEFINE3(execve, const char __user *, filename,
62263 return compat_do_execve(getname(filename), argv, envp);
62264 }
62265 #endif
62266 +
62267 +int pax_check_flags(unsigned long *flags)
62268 +{
62269 + int retval = 0;
62270 +
62271 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
62272 + if (*flags & MF_PAX_SEGMEXEC)
62273 + {
62274 + *flags &= ~MF_PAX_SEGMEXEC;
62275 + retval = -EINVAL;
62276 + }
62277 +#endif
62278 +
62279 + if ((*flags & MF_PAX_PAGEEXEC)
62280 +
62281 +#ifdef CONFIG_PAX_PAGEEXEC
62282 + && (*flags & MF_PAX_SEGMEXEC)
62283 +#endif
62284 +
62285 + )
62286 + {
62287 + *flags &= ~MF_PAX_PAGEEXEC;
62288 + retval = -EINVAL;
62289 + }
62290 +
62291 + if ((*flags & MF_PAX_MPROTECT)
62292 +
62293 +#ifdef CONFIG_PAX_MPROTECT
62294 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
62295 +#endif
62296 +
62297 + )
62298 + {
62299 + *flags &= ~MF_PAX_MPROTECT;
62300 + retval = -EINVAL;
62301 + }
62302 +
62303 + if ((*flags & MF_PAX_EMUTRAMP)
62304 +
62305 +#ifdef CONFIG_PAX_EMUTRAMP
62306 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
62307 +#endif
62308 +
62309 + )
62310 + {
62311 + *flags &= ~MF_PAX_EMUTRAMP;
62312 + retval = -EINVAL;
62313 + }
62314 +
62315 + return retval;
62316 +}
62317 +
62318 +EXPORT_SYMBOL(pax_check_flags);
62319 +
62320 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
62321 +char *pax_get_path(const struct path *path, char *buf, int buflen)
62322 +{
62323 + char *pathname = d_path(path, buf, buflen);
62324 +
62325 + if (IS_ERR(pathname))
62326 + goto toolong;
62327 +
62328 + pathname = mangle_path(buf, pathname, "\t\n\\");
62329 + if (!pathname)
62330 + goto toolong;
62331 +
62332 + *pathname = 0;
62333 + return buf;
62334 +
62335 +toolong:
62336 + return "<path too long>";
62337 +}
62338 +EXPORT_SYMBOL(pax_get_path);
62339 +
62340 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
62341 +{
62342 + struct task_struct *tsk = current;
62343 + struct mm_struct *mm = current->mm;
62344 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
62345 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
62346 + char *path_exec = NULL;
62347 + char *path_fault = NULL;
62348 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
62349 + siginfo_t info = { };
62350 +
62351 + if (buffer_exec && buffer_fault) {
62352 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
62353 +
62354 + down_read(&mm->mmap_sem);
62355 + vma = mm->mmap;
62356 + while (vma && (!vma_exec || !vma_fault)) {
62357 + if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
62358 + vma_exec = vma;
62359 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
62360 + vma_fault = vma;
62361 + vma = vma->vm_next;
62362 + }
62363 + if (vma_exec)
62364 + path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
62365 + if (vma_fault) {
62366 + start = vma_fault->vm_start;
62367 + end = vma_fault->vm_end;
62368 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
62369 + if (vma_fault->vm_file)
62370 + path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
62371 + else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
62372 + path_fault = "<heap>";
62373 + else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
62374 + path_fault = "<stack>";
62375 + else
62376 + path_fault = "<anonymous mapping>";
62377 + }
62378 + up_read(&mm->mmap_sem);
62379 + }
62380 + if (tsk->signal->curr_ip)
62381 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
62382 + else
62383 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
62384 + 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),
62385 + from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
62386 + free_page((unsigned long)buffer_exec);
62387 + free_page((unsigned long)buffer_fault);
62388 + pax_report_insns(regs, pc, sp);
62389 + info.si_signo = SIGKILL;
62390 + info.si_errno = 0;
62391 + info.si_code = SI_KERNEL;
62392 + info.si_pid = 0;
62393 + info.si_uid = 0;
62394 + do_coredump(&info);
62395 +}
62396 +#endif
62397 +
62398 +#ifdef CONFIG_PAX_REFCOUNT
62399 +void pax_report_refcount_overflow(struct pt_regs *regs)
62400 +{
62401 + if (current->signal->curr_ip)
62402 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
62403 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
62404 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
62405 + else
62406 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
62407 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
62408 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
62409 + preempt_disable();
62410 + show_regs(regs);
62411 + preempt_enable();
62412 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
62413 +}
62414 +#endif
62415 +
62416 +#ifdef CONFIG_PAX_USERCOPY
62417 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
62418 +static noinline int check_stack_object(const void *obj, unsigned long len)
62419 +{
62420 + const void * const stack = task_stack_page(current);
62421 + const void * const stackend = stack + THREAD_SIZE;
62422 +
62423 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
62424 + const void *frame = NULL;
62425 + const void *oldframe;
62426 +#endif
62427 +
62428 + if (obj + len < obj)
62429 + return -1;
62430 +
62431 + if (obj + len <= stack || stackend <= obj)
62432 + return 0;
62433 +
62434 + if (obj < stack || stackend < obj + len)
62435 + return -1;
62436 +
62437 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
62438 + oldframe = __builtin_frame_address(1);
62439 + if (oldframe)
62440 + frame = __builtin_frame_address(2);
62441 + /*
62442 + low ----------------------------------------------> high
62443 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
62444 + ^----------------^
62445 + allow copies only within here
62446 + */
62447 + while (stack <= frame && frame < stackend) {
62448 + /* if obj + len extends past the last frame, this
62449 + check won't pass and the next frame will be 0,
62450 + causing us to bail out and correctly report
62451 + the copy as invalid
62452 + */
62453 + if (obj + len <= frame)
62454 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
62455 + oldframe = frame;
62456 + frame = *(const void * const *)frame;
62457 + }
62458 + return -1;
62459 +#else
62460 + return 1;
62461 +#endif
62462 +}
62463 +
62464 +static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
62465 +{
62466 + if (current->signal->curr_ip)
62467 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
62468 + &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
62469 + else
62470 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
62471 + to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
62472 + dump_stack();
62473 + gr_handle_kernel_exploit();
62474 + do_group_exit(SIGKILL);
62475 +}
62476 +#endif
62477 +
62478 +#ifdef CONFIG_PAX_USERCOPY
62479 +
62480 +static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
62481 +{
62482 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
62483 + unsigned long textlow = ktla_ktva((unsigned long)_stext);
62484 +#ifdef CONFIG_MODULES
62485 + unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
62486 +#else
62487 + unsigned long texthigh = ktla_ktva((unsigned long)_etext);
62488 +#endif
62489 +
62490 +#else
62491 + unsigned long textlow = (unsigned long)_stext;
62492 + unsigned long texthigh = (unsigned long)_etext;
62493 +
62494 +#ifdef CONFIG_X86_64
62495 + /* check against linear mapping as well */
62496 + if (high > (unsigned long)__va(__pa(textlow)) &&
62497 + low < (unsigned long)__va(__pa(texthigh)))
62498 + return true;
62499 +#endif
62500 +
62501 +#endif
62502 +
62503 + if (high <= textlow || low >= texthigh)
62504 + return false;
62505 + else
62506 + return true;
62507 +}
62508 +#endif
62509 +
62510 +void __check_object_size(const void *ptr, unsigned long n, bool to_user, bool const_size)
62511 +{
62512 +#ifdef CONFIG_PAX_USERCOPY
62513 + const char *type;
62514 +#endif
62515 +
62516 +#ifndef CONFIG_STACK_GROWSUP
62517 + unsigned long stackstart = (unsigned long)task_stack_page(current);
62518 + unsigned long currentsp = (unsigned long)&stackstart;
62519 + if (unlikely((currentsp < stackstart + 512 ||
62520 + currentsp >= stackstart + THREAD_SIZE) && !in_interrupt()))
62521 + BUG();
62522 +#endif
62523 +
62524 +#ifndef CONFIG_PAX_USERCOPY_DEBUG
62525 + if (const_size)
62526 + return;
62527 +#endif
62528 +
62529 +#ifdef CONFIG_PAX_USERCOPY
62530 + if (!n)
62531 + return;
62532 +
62533 + type = check_heap_object(ptr, n);
62534 + if (!type) {
62535 + int ret = check_stack_object(ptr, n);
62536 + if (ret == 1 || ret == 2)
62537 + return;
62538 + if (ret == 0) {
62539 + if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
62540 + type = "<kernel text>";
62541 + else
62542 + return;
62543 + } else
62544 + type = "<process stack>";
62545 + }
62546 +
62547 + pax_report_usercopy(ptr, n, to_user, type);
62548 +#endif
62549 +
62550 +}
62551 +EXPORT_SYMBOL(__check_object_size);
62552 +
62553 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
62554 +void pax_track_stack(void)
62555 +{
62556 + unsigned long sp = (unsigned long)&sp;
62557 + if (sp < current_thread_info()->lowest_stack &&
62558 + sp > (unsigned long)task_stack_page(current))
62559 + current_thread_info()->lowest_stack = sp;
62560 + if (unlikely((sp & ~(THREAD_SIZE - 1)) < (THREAD_SIZE/16)))
62561 + BUG();
62562 +}
62563 +EXPORT_SYMBOL(pax_track_stack);
62564 +#endif
62565 +
62566 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
62567 +void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
62568 +{
62569 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
62570 + dump_stack();
62571 + do_group_exit(SIGKILL);
62572 +}
62573 +EXPORT_SYMBOL(report_size_overflow);
62574 +#endif
62575 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
62576 index 9f9992b..8b59411 100644
62577 --- a/fs/ext2/balloc.c
62578 +++ b/fs/ext2/balloc.c
62579 @@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
62580
62581 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
62582 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
62583 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
62584 + if (free_blocks < root_blocks + 1 &&
62585 !uid_eq(sbi->s_resuid, current_fsuid()) &&
62586 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
62587 - !in_group_p (sbi->s_resgid))) {
62588 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
62589 return 0;
62590 }
62591 return 1;
62592 diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
62593 index 9142614..97484fa 100644
62594 --- a/fs/ext2/xattr.c
62595 +++ b/fs/ext2/xattr.c
62596 @@ -247,7 +247,7 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
62597 struct buffer_head *bh = NULL;
62598 struct ext2_xattr_entry *entry;
62599 char *end;
62600 - size_t rest = buffer_size;
62601 + size_t rest = buffer_size, total_size = 0;
62602 int error;
62603
62604 ea_idebug(inode, "buffer=%p, buffer_size=%ld",
62605 @@ -305,9 +305,10 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
62606 buffer += size;
62607 }
62608 rest -= size;
62609 + total_size += size;
62610 }
62611 }
62612 - error = buffer_size - rest; /* total size */
62613 + error = total_size;
62614
62615 cleanup:
62616 brelse(bh);
62617 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
62618 index 158b5d4..2432610 100644
62619 --- a/fs/ext3/balloc.c
62620 +++ b/fs/ext3/balloc.c
62621 @@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
62622
62623 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
62624 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
62625 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
62626 + if (free_blocks < root_blocks + 1 &&
62627 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
62628 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
62629 - !in_group_p (sbi->s_resgid))) {
62630 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
62631 return 0;
62632 }
62633 return 1;
62634 diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c
62635 index c6874be..f8a6ae8 100644
62636 --- a/fs/ext3/xattr.c
62637 +++ b/fs/ext3/xattr.c
62638 @@ -330,7 +330,7 @@ static int
62639 ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
62640 char *buffer, size_t buffer_size)
62641 {
62642 - size_t rest = buffer_size;
62643 + size_t rest = buffer_size, total_size = 0;
62644
62645 for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) {
62646 const struct xattr_handler *handler =
62647 @@ -347,9 +347,10 @@ ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
62648 buffer += size;
62649 }
62650 rest -= size;
62651 + total_size += size;
62652 }
62653 }
62654 - return buffer_size - rest;
62655 + return total_size;
62656 }
62657
62658 static int
62659 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
62660 index fca3820..e1ea241 100644
62661 --- a/fs/ext4/balloc.c
62662 +++ b/fs/ext4/balloc.c
62663 @@ -553,8 +553,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
62664 /* Hm, nope. Are (enough) root reserved clusters available? */
62665 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
62666 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
62667 - capable(CAP_SYS_RESOURCE) ||
62668 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
62669 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
62670 + capable_nolog(CAP_SYS_RESOURCE)) {
62671
62672 if (free_clusters >= (nclusters + dirty_clusters +
62673 resv_clusters))
62674 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
62675 index 7cc5a0e..851f176 100644
62676 --- a/fs/ext4/ext4.h
62677 +++ b/fs/ext4/ext4.h
62678 @@ -1276,19 +1276,19 @@ struct ext4_sb_info {
62679 unsigned long s_mb_last_start;
62680
62681 /* stats for buddy allocator */
62682 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
62683 - atomic_t s_bal_success; /* we found long enough chunks */
62684 - atomic_t s_bal_allocated; /* in blocks */
62685 - atomic_t s_bal_ex_scanned; /* total extents scanned */
62686 - atomic_t s_bal_goals; /* goal hits */
62687 - atomic_t s_bal_breaks; /* too long searches */
62688 - atomic_t s_bal_2orders; /* 2^order hits */
62689 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
62690 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
62691 + atomic_unchecked_t s_bal_allocated; /* in blocks */
62692 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
62693 + atomic_unchecked_t s_bal_goals; /* goal hits */
62694 + atomic_unchecked_t s_bal_breaks; /* too long searches */
62695 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
62696 spinlock_t s_bal_lock;
62697 unsigned long s_mb_buddies_generated;
62698 unsigned long long s_mb_generation_time;
62699 - atomic_t s_mb_lost_chunks;
62700 - atomic_t s_mb_preallocated;
62701 - atomic_t s_mb_discarded;
62702 + atomic_unchecked_t s_mb_lost_chunks;
62703 + atomic_unchecked_t s_mb_preallocated;
62704 + atomic_unchecked_t s_mb_discarded;
62705 atomic_t s_lock_busy;
62706
62707 /* locality groups */
62708 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
62709 index 2dcb936..f5625a0 100644
62710 --- a/fs/ext4/mballoc.c
62711 +++ b/fs/ext4/mballoc.c
62712 @@ -1899,7 +1899,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
62713 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
62714
62715 if (EXT4_SB(sb)->s_mb_stats)
62716 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
62717 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
62718
62719 break;
62720 }
62721 @@ -2209,7 +2209,7 @@ repeat:
62722 ac->ac_status = AC_STATUS_CONTINUE;
62723 ac->ac_flags |= EXT4_MB_HINT_FIRST;
62724 cr = 3;
62725 - atomic_inc(&sbi->s_mb_lost_chunks);
62726 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
62727 goto repeat;
62728 }
62729 }
62730 @@ -2715,25 +2715,25 @@ int ext4_mb_release(struct super_block *sb)
62731 if (sbi->s_mb_stats) {
62732 ext4_msg(sb, KERN_INFO,
62733 "mballoc: %u blocks %u reqs (%u success)",
62734 - atomic_read(&sbi->s_bal_allocated),
62735 - atomic_read(&sbi->s_bal_reqs),
62736 - atomic_read(&sbi->s_bal_success));
62737 + atomic_read_unchecked(&sbi->s_bal_allocated),
62738 + atomic_read_unchecked(&sbi->s_bal_reqs),
62739 + atomic_read_unchecked(&sbi->s_bal_success));
62740 ext4_msg(sb, KERN_INFO,
62741 "mballoc: %u extents scanned, %u goal hits, "
62742 "%u 2^N hits, %u breaks, %u lost",
62743 - atomic_read(&sbi->s_bal_ex_scanned),
62744 - atomic_read(&sbi->s_bal_goals),
62745 - atomic_read(&sbi->s_bal_2orders),
62746 - atomic_read(&sbi->s_bal_breaks),
62747 - atomic_read(&sbi->s_mb_lost_chunks));
62748 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
62749 + atomic_read_unchecked(&sbi->s_bal_goals),
62750 + atomic_read_unchecked(&sbi->s_bal_2orders),
62751 + atomic_read_unchecked(&sbi->s_bal_breaks),
62752 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
62753 ext4_msg(sb, KERN_INFO,
62754 "mballoc: %lu generated and it took %Lu",
62755 sbi->s_mb_buddies_generated,
62756 sbi->s_mb_generation_time);
62757 ext4_msg(sb, KERN_INFO,
62758 "mballoc: %u preallocated, %u discarded",
62759 - atomic_read(&sbi->s_mb_preallocated),
62760 - atomic_read(&sbi->s_mb_discarded));
62761 + atomic_read_unchecked(&sbi->s_mb_preallocated),
62762 + atomic_read_unchecked(&sbi->s_mb_discarded));
62763 }
62764
62765 free_percpu(sbi->s_locality_groups);
62766 @@ -3189,16 +3189,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
62767 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
62768
62769 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
62770 - atomic_inc(&sbi->s_bal_reqs);
62771 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
62772 + atomic_inc_unchecked(&sbi->s_bal_reqs);
62773 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
62774 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
62775 - atomic_inc(&sbi->s_bal_success);
62776 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
62777 + atomic_inc_unchecked(&sbi->s_bal_success);
62778 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
62779 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
62780 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
62781 - atomic_inc(&sbi->s_bal_goals);
62782 + atomic_inc_unchecked(&sbi->s_bal_goals);
62783 if (ac->ac_found > sbi->s_mb_max_to_scan)
62784 - atomic_inc(&sbi->s_bal_breaks);
62785 + atomic_inc_unchecked(&sbi->s_bal_breaks);
62786 }
62787
62788 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
62789 @@ -3603,7 +3603,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
62790 trace_ext4_mb_new_inode_pa(ac, pa);
62791
62792 ext4_mb_use_inode_pa(ac, pa);
62793 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
62794 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
62795
62796 ei = EXT4_I(ac->ac_inode);
62797 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
62798 @@ -3663,7 +3663,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
62799 trace_ext4_mb_new_group_pa(ac, pa);
62800
62801 ext4_mb_use_group_pa(ac, pa);
62802 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
62803 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
62804
62805 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
62806 lg = ac->ac_lg;
62807 @@ -3752,7 +3752,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
62808 * from the bitmap and continue.
62809 */
62810 }
62811 - atomic_add(free, &sbi->s_mb_discarded);
62812 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
62813
62814 return err;
62815 }
62816 @@ -3770,7 +3770,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
62817 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
62818 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
62819 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
62820 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
62821 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
62822 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
62823
62824 return 0;
62825 diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
62826 index 32bce84..112d969 100644
62827 --- a/fs/ext4/mmp.c
62828 +++ b/fs/ext4/mmp.c
62829 @@ -113,7 +113,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
62830 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
62831 const char *function, unsigned int line, const char *msg)
62832 {
62833 - __ext4_warning(sb, function, line, msg);
62834 + __ext4_warning(sb, function, line, "%s", msg);
62835 __ext4_warning(sb, function, line,
62836 "MMP failure info: last update time: %llu, last update "
62837 "node: %s, last update device: %s\n",
62838 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
62839 index 6df7bc6..410a655 100644
62840 --- a/fs/ext4/super.c
62841 +++ b/fs/ext4/super.c
62842 @@ -1276,7 +1276,7 @@ static ext4_fsblk_t get_sb_block(void **data)
62843 }
62844
62845 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
62846 -static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
62847 +static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
62848 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
62849
62850 #ifdef CONFIG_QUOTA
62851 @@ -2464,7 +2464,7 @@ struct ext4_attr {
62852 int offset;
62853 int deprecated_val;
62854 } u;
62855 -};
62856 +} __do_const;
62857
62858 static int parse_strtoull(const char *buf,
62859 unsigned long long max, unsigned long long *value)
62860 diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
62861 index e738733..9843a6c 100644
62862 --- a/fs/ext4/xattr.c
62863 +++ b/fs/ext4/xattr.c
62864 @@ -386,7 +386,7 @@ static int
62865 ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
62866 char *buffer, size_t buffer_size)
62867 {
62868 - size_t rest = buffer_size;
62869 + size_t rest = buffer_size, total_size = 0;
62870
62871 for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
62872 const struct xattr_handler *handler =
62873 @@ -403,9 +403,10 @@ ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
62874 buffer += size;
62875 }
62876 rest -= size;
62877 + total_size += size;
62878 }
62879 }
62880 - return buffer_size - rest;
62881 + return total_size;
62882 }
62883
62884 static int
62885 diff --git a/fs/fcntl.c b/fs/fcntl.c
62886 index 72c82f6..a18b263 100644
62887 --- a/fs/fcntl.c
62888 +++ b/fs/fcntl.c
62889 @@ -106,6 +106,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
62890 if (err)
62891 return err;
62892
62893 + if (gr_handle_chroot_fowner(pid, type))
62894 + return -ENOENT;
62895 + if (gr_check_protected_task_fowner(pid, type))
62896 + return -EACCES;
62897 +
62898 f_modown(filp, pid, type, force);
62899 return 0;
62900 }
62901 diff --git a/fs/fhandle.c b/fs/fhandle.c
62902 index 999ff5c..ac037c9 100644
62903 --- a/fs/fhandle.c
62904 +++ b/fs/fhandle.c
62905 @@ -8,6 +8,7 @@
62906 #include <linux/fs_struct.h>
62907 #include <linux/fsnotify.h>
62908 #include <linux/personality.h>
62909 +#include <linux/grsecurity.h>
62910 #include <asm/uaccess.h>
62911 #include "internal.h"
62912 #include "mount.h"
62913 @@ -67,8 +68,7 @@ static long do_sys_name_to_handle(struct path *path,
62914 } else
62915 retval = 0;
62916 /* copy the mount id */
62917 - if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
62918 - sizeof(*mnt_id)) ||
62919 + if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
62920 copy_to_user(ufh, handle,
62921 sizeof(struct file_handle) + handle_bytes))
62922 retval = -EFAULT;
62923 @@ -175,7 +175,7 @@ static int handle_to_path(int mountdirfd, struct file_handle __user *ufh,
62924 * the directory. Ideally we would like CAP_DAC_SEARCH.
62925 * But we don't have that
62926 */
62927 - if (!capable(CAP_DAC_READ_SEARCH)) {
62928 + if (!capable(CAP_DAC_READ_SEARCH) || !gr_chroot_fhandle()) {
62929 retval = -EPERM;
62930 goto out_err;
62931 }
62932 diff --git a/fs/file.c b/fs/file.c
62933 index 66923fe..2849783 100644
62934 --- a/fs/file.c
62935 +++ b/fs/file.c
62936 @@ -16,6 +16,7 @@
62937 #include <linux/slab.h>
62938 #include <linux/vmalloc.h>
62939 #include <linux/file.h>
62940 +#include <linux/security.h>
62941 #include <linux/fdtable.h>
62942 #include <linux/bitops.h>
62943 #include <linux/interrupt.h>
62944 @@ -139,7 +140,7 @@ out:
62945 * Return <0 error code on error; 1 on successful completion.
62946 * The files->file_lock should be held on entry, and will be held on exit.
62947 */
62948 -static int expand_fdtable(struct files_struct *files, int nr)
62949 +static int expand_fdtable(struct files_struct *files, unsigned int nr)
62950 __releases(files->file_lock)
62951 __acquires(files->file_lock)
62952 {
62953 @@ -184,7 +185,7 @@ static int expand_fdtable(struct files_struct *files, int nr)
62954 * expanded and execution may have blocked.
62955 * The files->file_lock should be held on entry, and will be held on exit.
62956 */
62957 -static int expand_files(struct files_struct *files, int nr)
62958 +static int expand_files(struct files_struct *files, unsigned int nr)
62959 {
62960 struct fdtable *fdt;
62961
62962 @@ -799,6 +800,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
62963 if (!file)
62964 return __close_fd(files, fd);
62965
62966 + gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
62967 if (fd >= rlimit(RLIMIT_NOFILE))
62968 return -EBADF;
62969
62970 @@ -825,6 +827,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
62971 if (unlikely(oldfd == newfd))
62972 return -EINVAL;
62973
62974 + gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
62975 if (newfd >= rlimit(RLIMIT_NOFILE))
62976 return -EBADF;
62977
62978 @@ -880,6 +883,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
62979 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
62980 {
62981 int err;
62982 + gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
62983 if (from >= rlimit(RLIMIT_NOFILE))
62984 return -EINVAL;
62985 err = alloc_fd(from, flags);
62986 diff --git a/fs/filesystems.c b/fs/filesystems.c
62987 index 5797d45..7d7d79a 100644
62988 --- a/fs/filesystems.c
62989 +++ b/fs/filesystems.c
62990 @@ -275,7 +275,11 @@ struct file_system_type *get_fs_type(const char *name)
62991 int len = dot ? dot - name : strlen(name);
62992
62993 fs = __get_fs_type(name, len);
62994 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
62995 + if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
62996 +#else
62997 if (!fs && (request_module("fs-%.*s", len, name) == 0))
62998 +#endif
62999 fs = __get_fs_type(name, len);
63000
63001 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
63002 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
63003 index 7dca743..543d620 100644
63004 --- a/fs/fs_struct.c
63005 +++ b/fs/fs_struct.c
63006 @@ -4,6 +4,7 @@
63007 #include <linux/path.h>
63008 #include <linux/slab.h>
63009 #include <linux/fs_struct.h>
63010 +#include <linux/grsecurity.h>
63011 #include "internal.h"
63012
63013 /*
63014 @@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
63015 write_seqcount_begin(&fs->seq);
63016 old_root = fs->root;
63017 fs->root = *path;
63018 + gr_set_chroot_entries(current, path);
63019 write_seqcount_end(&fs->seq);
63020 spin_unlock(&fs->lock);
63021 if (old_root.dentry)
63022 @@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
63023 int hits = 0;
63024 spin_lock(&fs->lock);
63025 write_seqcount_begin(&fs->seq);
63026 + /* this root replacement is only done by pivot_root,
63027 + leave grsec's chroot tagging alone for this task
63028 + so that a pivoted root isn't treated as a chroot
63029 + */
63030 hits += replace_path(&fs->root, old_root, new_root);
63031 hits += replace_path(&fs->pwd, old_root, new_root);
63032 write_seqcount_end(&fs->seq);
63033 @@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
63034 task_lock(tsk);
63035 spin_lock(&fs->lock);
63036 tsk->fs = NULL;
63037 - kill = !--fs->users;
63038 + gr_clear_chroot_entries(tsk);
63039 + kill = !atomic_dec_return(&fs->users);
63040 spin_unlock(&fs->lock);
63041 task_unlock(tsk);
63042 if (kill)
63043 @@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
63044 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
63045 /* We don't need to lock fs - think why ;-) */
63046 if (fs) {
63047 - fs->users = 1;
63048 + atomic_set(&fs->users, 1);
63049 fs->in_exec = 0;
63050 spin_lock_init(&fs->lock);
63051 seqcount_init(&fs->seq);
63052 @@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
63053 spin_lock(&old->lock);
63054 fs->root = old->root;
63055 path_get(&fs->root);
63056 + /* instead of calling gr_set_chroot_entries here,
63057 + we call it from every caller of this function
63058 + */
63059 fs->pwd = old->pwd;
63060 path_get(&fs->pwd);
63061 spin_unlock(&old->lock);
63062 @@ -139,8 +149,9 @@ int unshare_fs_struct(void)
63063
63064 task_lock(current);
63065 spin_lock(&fs->lock);
63066 - kill = !--fs->users;
63067 + kill = !atomic_dec_return(&fs->users);
63068 current->fs = new_fs;
63069 + gr_set_chroot_entries(current, &new_fs->root);
63070 spin_unlock(&fs->lock);
63071 task_unlock(current);
63072
63073 @@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
63074
63075 int current_umask(void)
63076 {
63077 - return current->fs->umask;
63078 + return current->fs->umask | gr_acl_umask();
63079 }
63080 EXPORT_SYMBOL(current_umask);
63081
63082 /* to be mentioned only in INIT_TASK */
63083 struct fs_struct init_fs = {
63084 - .users = 1,
63085 + .users = ATOMIC_INIT(1),
63086 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
63087 .seq = SEQCNT_ZERO(init_fs.seq),
63088 .umask = 0022,
63089 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
63090 index aec01be..cf81ff9 100644
63091 --- a/fs/fscache/cookie.c
63092 +++ b/fs/fscache/cookie.c
63093 @@ -19,7 +19,7 @@
63094
63095 struct kmem_cache *fscache_cookie_jar;
63096
63097 -static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
63098 +static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
63099
63100 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
63101 static int fscache_alloc_object(struct fscache_cache *cache,
63102 @@ -69,11 +69,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
63103 parent ? (char *) parent->def->name : "<no-parent>",
63104 def->name, netfs_data, enable);
63105
63106 - fscache_stat(&fscache_n_acquires);
63107 + fscache_stat_unchecked(&fscache_n_acquires);
63108
63109 /* if there's no parent cookie, then we don't create one here either */
63110 if (!parent) {
63111 - fscache_stat(&fscache_n_acquires_null);
63112 + fscache_stat_unchecked(&fscache_n_acquires_null);
63113 _leave(" [no parent]");
63114 return NULL;
63115 }
63116 @@ -88,7 +88,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
63117 /* allocate and initialise a cookie */
63118 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
63119 if (!cookie) {
63120 - fscache_stat(&fscache_n_acquires_oom);
63121 + fscache_stat_unchecked(&fscache_n_acquires_oom);
63122 _leave(" [ENOMEM]");
63123 return NULL;
63124 }
63125 @@ -115,13 +115,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
63126
63127 switch (cookie->def->type) {
63128 case FSCACHE_COOKIE_TYPE_INDEX:
63129 - fscache_stat(&fscache_n_cookie_index);
63130 + fscache_stat_unchecked(&fscache_n_cookie_index);
63131 break;
63132 case FSCACHE_COOKIE_TYPE_DATAFILE:
63133 - fscache_stat(&fscache_n_cookie_data);
63134 + fscache_stat_unchecked(&fscache_n_cookie_data);
63135 break;
63136 default:
63137 - fscache_stat(&fscache_n_cookie_special);
63138 + fscache_stat_unchecked(&fscache_n_cookie_special);
63139 break;
63140 }
63141
63142 @@ -135,7 +135,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
63143 } else {
63144 atomic_dec(&parent->n_children);
63145 __fscache_cookie_put(cookie);
63146 - fscache_stat(&fscache_n_acquires_nobufs);
63147 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
63148 _leave(" = NULL");
63149 return NULL;
63150 }
63151 @@ -144,7 +144,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
63152 }
63153 }
63154
63155 - fscache_stat(&fscache_n_acquires_ok);
63156 + fscache_stat_unchecked(&fscache_n_acquires_ok);
63157 _leave(" = %p", cookie);
63158 return cookie;
63159 }
63160 @@ -213,7 +213,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
63161 cache = fscache_select_cache_for_object(cookie->parent);
63162 if (!cache) {
63163 up_read(&fscache_addremove_sem);
63164 - fscache_stat(&fscache_n_acquires_no_cache);
63165 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
63166 _leave(" = -ENOMEDIUM [no cache]");
63167 return -ENOMEDIUM;
63168 }
63169 @@ -297,14 +297,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
63170 object = cache->ops->alloc_object(cache, cookie);
63171 fscache_stat_d(&fscache_n_cop_alloc_object);
63172 if (IS_ERR(object)) {
63173 - fscache_stat(&fscache_n_object_no_alloc);
63174 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
63175 ret = PTR_ERR(object);
63176 goto error;
63177 }
63178
63179 - fscache_stat(&fscache_n_object_alloc);
63180 + fscache_stat_unchecked(&fscache_n_object_alloc);
63181
63182 - object->debug_id = atomic_inc_return(&fscache_object_debug_id);
63183 + object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
63184
63185 _debug("ALLOC OBJ%x: %s {%lx}",
63186 object->debug_id, cookie->def->name, object->events);
63187 @@ -418,7 +418,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
63188
63189 _enter("{%s}", cookie->def->name);
63190
63191 - fscache_stat(&fscache_n_invalidates);
63192 + fscache_stat_unchecked(&fscache_n_invalidates);
63193
63194 /* Only permit invalidation of data files. Invalidating an index will
63195 * require the caller to release all its attachments to the tree rooted
63196 @@ -477,10 +477,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
63197 {
63198 struct fscache_object *object;
63199
63200 - fscache_stat(&fscache_n_updates);
63201 + fscache_stat_unchecked(&fscache_n_updates);
63202
63203 if (!cookie) {
63204 - fscache_stat(&fscache_n_updates_null);
63205 + fscache_stat_unchecked(&fscache_n_updates_null);
63206 _leave(" [no cookie]");
63207 return;
63208 }
63209 @@ -581,12 +581,12 @@ EXPORT_SYMBOL(__fscache_disable_cookie);
63210 */
63211 void __fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire)
63212 {
63213 - fscache_stat(&fscache_n_relinquishes);
63214 + fscache_stat_unchecked(&fscache_n_relinquishes);
63215 if (retire)
63216 - fscache_stat(&fscache_n_relinquishes_retire);
63217 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
63218
63219 if (!cookie) {
63220 - fscache_stat(&fscache_n_relinquishes_null);
63221 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
63222 _leave(" [no cookie]");
63223 return;
63224 }
63225 @@ -687,7 +687,7 @@ int __fscache_check_consistency(struct fscache_cookie *cookie)
63226 if (test_bit(FSCACHE_IOERROR, &object->cache->flags))
63227 goto inconsistent;
63228
63229 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
63230 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
63231
63232 __fscache_use_cookie(cookie);
63233 if (fscache_submit_op(object, op) < 0)
63234 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
63235 index bc6c08f..09c0d96 100644
63236 --- a/fs/fscache/internal.h
63237 +++ b/fs/fscache/internal.h
63238 @@ -139,8 +139,8 @@ extern void fscache_operation_gc(struct work_struct *);
63239 extern int fscache_wait_for_deferred_lookup(struct fscache_cookie *);
63240 extern int fscache_wait_for_operation_activation(struct fscache_object *,
63241 struct fscache_operation *,
63242 - atomic_t *,
63243 - atomic_t *,
63244 + atomic_unchecked_t *,
63245 + atomic_unchecked_t *,
63246 void (*)(struct fscache_operation *));
63247 extern void fscache_invalidate_writes(struct fscache_cookie *);
63248
63249 @@ -159,101 +159,101 @@ extern void fscache_proc_cleanup(void);
63250 * stats.c
63251 */
63252 #ifdef CONFIG_FSCACHE_STATS
63253 -extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
63254 -extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
63255 +extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
63256 +extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
63257
63258 -extern atomic_t fscache_n_op_pend;
63259 -extern atomic_t fscache_n_op_run;
63260 -extern atomic_t fscache_n_op_enqueue;
63261 -extern atomic_t fscache_n_op_deferred_release;
63262 -extern atomic_t fscache_n_op_release;
63263 -extern atomic_t fscache_n_op_gc;
63264 -extern atomic_t fscache_n_op_cancelled;
63265 -extern atomic_t fscache_n_op_rejected;
63266 +extern atomic_unchecked_t fscache_n_op_pend;
63267 +extern atomic_unchecked_t fscache_n_op_run;
63268 +extern atomic_unchecked_t fscache_n_op_enqueue;
63269 +extern atomic_unchecked_t fscache_n_op_deferred_release;
63270 +extern atomic_unchecked_t fscache_n_op_release;
63271 +extern atomic_unchecked_t fscache_n_op_gc;
63272 +extern atomic_unchecked_t fscache_n_op_cancelled;
63273 +extern atomic_unchecked_t fscache_n_op_rejected;
63274
63275 -extern atomic_t fscache_n_attr_changed;
63276 -extern atomic_t fscache_n_attr_changed_ok;
63277 -extern atomic_t fscache_n_attr_changed_nobufs;
63278 -extern atomic_t fscache_n_attr_changed_nomem;
63279 -extern atomic_t fscache_n_attr_changed_calls;
63280 +extern atomic_unchecked_t fscache_n_attr_changed;
63281 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
63282 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
63283 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
63284 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
63285
63286 -extern atomic_t fscache_n_allocs;
63287 -extern atomic_t fscache_n_allocs_ok;
63288 -extern atomic_t fscache_n_allocs_wait;
63289 -extern atomic_t fscache_n_allocs_nobufs;
63290 -extern atomic_t fscache_n_allocs_intr;
63291 -extern atomic_t fscache_n_allocs_object_dead;
63292 -extern atomic_t fscache_n_alloc_ops;
63293 -extern atomic_t fscache_n_alloc_op_waits;
63294 +extern atomic_unchecked_t fscache_n_allocs;
63295 +extern atomic_unchecked_t fscache_n_allocs_ok;
63296 +extern atomic_unchecked_t fscache_n_allocs_wait;
63297 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
63298 +extern atomic_unchecked_t fscache_n_allocs_intr;
63299 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
63300 +extern atomic_unchecked_t fscache_n_alloc_ops;
63301 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
63302
63303 -extern atomic_t fscache_n_retrievals;
63304 -extern atomic_t fscache_n_retrievals_ok;
63305 -extern atomic_t fscache_n_retrievals_wait;
63306 -extern atomic_t fscache_n_retrievals_nodata;
63307 -extern atomic_t fscache_n_retrievals_nobufs;
63308 -extern atomic_t fscache_n_retrievals_intr;
63309 -extern atomic_t fscache_n_retrievals_nomem;
63310 -extern atomic_t fscache_n_retrievals_object_dead;
63311 -extern atomic_t fscache_n_retrieval_ops;
63312 -extern atomic_t fscache_n_retrieval_op_waits;
63313 +extern atomic_unchecked_t fscache_n_retrievals;
63314 +extern atomic_unchecked_t fscache_n_retrievals_ok;
63315 +extern atomic_unchecked_t fscache_n_retrievals_wait;
63316 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
63317 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
63318 +extern atomic_unchecked_t fscache_n_retrievals_intr;
63319 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
63320 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
63321 +extern atomic_unchecked_t fscache_n_retrieval_ops;
63322 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
63323
63324 -extern atomic_t fscache_n_stores;
63325 -extern atomic_t fscache_n_stores_ok;
63326 -extern atomic_t fscache_n_stores_again;
63327 -extern atomic_t fscache_n_stores_nobufs;
63328 -extern atomic_t fscache_n_stores_oom;
63329 -extern atomic_t fscache_n_store_ops;
63330 -extern atomic_t fscache_n_store_calls;
63331 -extern atomic_t fscache_n_store_pages;
63332 -extern atomic_t fscache_n_store_radix_deletes;
63333 -extern atomic_t fscache_n_store_pages_over_limit;
63334 +extern atomic_unchecked_t fscache_n_stores;
63335 +extern atomic_unchecked_t fscache_n_stores_ok;
63336 +extern atomic_unchecked_t fscache_n_stores_again;
63337 +extern atomic_unchecked_t fscache_n_stores_nobufs;
63338 +extern atomic_unchecked_t fscache_n_stores_oom;
63339 +extern atomic_unchecked_t fscache_n_store_ops;
63340 +extern atomic_unchecked_t fscache_n_store_calls;
63341 +extern atomic_unchecked_t fscache_n_store_pages;
63342 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
63343 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
63344
63345 -extern atomic_t fscache_n_store_vmscan_not_storing;
63346 -extern atomic_t fscache_n_store_vmscan_gone;
63347 -extern atomic_t fscache_n_store_vmscan_busy;
63348 -extern atomic_t fscache_n_store_vmscan_cancelled;
63349 -extern atomic_t fscache_n_store_vmscan_wait;
63350 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
63351 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
63352 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
63353 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
63354 +extern atomic_unchecked_t fscache_n_store_vmscan_wait;
63355
63356 -extern atomic_t fscache_n_marks;
63357 -extern atomic_t fscache_n_uncaches;
63358 +extern atomic_unchecked_t fscache_n_marks;
63359 +extern atomic_unchecked_t fscache_n_uncaches;
63360
63361 -extern atomic_t fscache_n_acquires;
63362 -extern atomic_t fscache_n_acquires_null;
63363 -extern atomic_t fscache_n_acquires_no_cache;
63364 -extern atomic_t fscache_n_acquires_ok;
63365 -extern atomic_t fscache_n_acquires_nobufs;
63366 -extern atomic_t fscache_n_acquires_oom;
63367 +extern atomic_unchecked_t fscache_n_acquires;
63368 +extern atomic_unchecked_t fscache_n_acquires_null;
63369 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
63370 +extern atomic_unchecked_t fscache_n_acquires_ok;
63371 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
63372 +extern atomic_unchecked_t fscache_n_acquires_oom;
63373
63374 -extern atomic_t fscache_n_invalidates;
63375 -extern atomic_t fscache_n_invalidates_run;
63376 +extern atomic_unchecked_t fscache_n_invalidates;
63377 +extern atomic_unchecked_t fscache_n_invalidates_run;
63378
63379 -extern atomic_t fscache_n_updates;
63380 -extern atomic_t fscache_n_updates_null;
63381 -extern atomic_t fscache_n_updates_run;
63382 +extern atomic_unchecked_t fscache_n_updates;
63383 +extern atomic_unchecked_t fscache_n_updates_null;
63384 +extern atomic_unchecked_t fscache_n_updates_run;
63385
63386 -extern atomic_t fscache_n_relinquishes;
63387 -extern atomic_t fscache_n_relinquishes_null;
63388 -extern atomic_t fscache_n_relinquishes_waitcrt;
63389 -extern atomic_t fscache_n_relinquishes_retire;
63390 +extern atomic_unchecked_t fscache_n_relinquishes;
63391 +extern atomic_unchecked_t fscache_n_relinquishes_null;
63392 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
63393 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
63394
63395 -extern atomic_t fscache_n_cookie_index;
63396 -extern atomic_t fscache_n_cookie_data;
63397 -extern atomic_t fscache_n_cookie_special;
63398 +extern atomic_unchecked_t fscache_n_cookie_index;
63399 +extern atomic_unchecked_t fscache_n_cookie_data;
63400 +extern atomic_unchecked_t fscache_n_cookie_special;
63401
63402 -extern atomic_t fscache_n_object_alloc;
63403 -extern atomic_t fscache_n_object_no_alloc;
63404 -extern atomic_t fscache_n_object_lookups;
63405 -extern atomic_t fscache_n_object_lookups_negative;
63406 -extern atomic_t fscache_n_object_lookups_positive;
63407 -extern atomic_t fscache_n_object_lookups_timed_out;
63408 -extern atomic_t fscache_n_object_created;
63409 -extern atomic_t fscache_n_object_avail;
63410 -extern atomic_t fscache_n_object_dead;
63411 +extern atomic_unchecked_t fscache_n_object_alloc;
63412 +extern atomic_unchecked_t fscache_n_object_no_alloc;
63413 +extern atomic_unchecked_t fscache_n_object_lookups;
63414 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
63415 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
63416 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
63417 +extern atomic_unchecked_t fscache_n_object_created;
63418 +extern atomic_unchecked_t fscache_n_object_avail;
63419 +extern atomic_unchecked_t fscache_n_object_dead;
63420
63421 -extern atomic_t fscache_n_checkaux_none;
63422 -extern atomic_t fscache_n_checkaux_okay;
63423 -extern atomic_t fscache_n_checkaux_update;
63424 -extern atomic_t fscache_n_checkaux_obsolete;
63425 +extern atomic_unchecked_t fscache_n_checkaux_none;
63426 +extern atomic_unchecked_t fscache_n_checkaux_okay;
63427 +extern atomic_unchecked_t fscache_n_checkaux_update;
63428 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
63429
63430 extern atomic_t fscache_n_cop_alloc_object;
63431 extern atomic_t fscache_n_cop_lookup_object;
63432 @@ -278,6 +278,11 @@ static inline void fscache_stat(atomic_t *stat)
63433 atomic_inc(stat);
63434 }
63435
63436 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
63437 +{
63438 + atomic_inc_unchecked(stat);
63439 +}
63440 +
63441 static inline void fscache_stat_d(atomic_t *stat)
63442 {
63443 atomic_dec(stat);
63444 @@ -290,6 +295,7 @@ extern const struct file_operations fscache_stats_fops;
63445
63446 #define __fscache_stat(stat) (NULL)
63447 #define fscache_stat(stat) do {} while (0)
63448 +#define fscache_stat_unchecked(stat) do {} while (0)
63449 #define fscache_stat_d(stat) do {} while (0)
63450 #endif
63451
63452 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
63453 index d3b4539..ed0c659 100644
63454 --- a/fs/fscache/object.c
63455 +++ b/fs/fscache/object.c
63456 @@ -454,7 +454,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
63457 _debug("LOOKUP \"%s\" in \"%s\"",
63458 cookie->def->name, object->cache->tag->name);
63459
63460 - fscache_stat(&fscache_n_object_lookups);
63461 + fscache_stat_unchecked(&fscache_n_object_lookups);
63462 fscache_stat(&fscache_n_cop_lookup_object);
63463 ret = object->cache->ops->lookup_object(object);
63464 fscache_stat_d(&fscache_n_cop_lookup_object);
63465 @@ -464,7 +464,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
63466 if (ret == -ETIMEDOUT) {
63467 /* probably stuck behind another object, so move this one to
63468 * the back of the queue */
63469 - fscache_stat(&fscache_n_object_lookups_timed_out);
63470 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
63471 _leave(" [timeout]");
63472 return NO_TRANSIT;
63473 }
63474 @@ -492,7 +492,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
63475 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
63476
63477 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
63478 - fscache_stat(&fscache_n_object_lookups_negative);
63479 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
63480
63481 /* Allow write requests to begin stacking up and read requests to begin
63482 * returning ENODATA.
63483 @@ -527,7 +527,7 @@ void fscache_obtained_object(struct fscache_object *object)
63484 /* if we were still looking up, then we must have a positive lookup
63485 * result, in which case there may be data available */
63486 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
63487 - fscache_stat(&fscache_n_object_lookups_positive);
63488 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
63489
63490 /* We do (presumably) have data */
63491 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
63492 @@ -539,7 +539,7 @@ void fscache_obtained_object(struct fscache_object *object)
63493 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
63494 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
63495 } else {
63496 - fscache_stat(&fscache_n_object_created);
63497 + fscache_stat_unchecked(&fscache_n_object_created);
63498 }
63499
63500 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
63501 @@ -575,7 +575,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
63502 fscache_stat_d(&fscache_n_cop_lookup_complete);
63503
63504 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
63505 - fscache_stat(&fscache_n_object_avail);
63506 + fscache_stat_unchecked(&fscache_n_object_avail);
63507
63508 _leave("");
63509 return transit_to(JUMPSTART_DEPS);
63510 @@ -722,7 +722,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
63511
63512 /* this just shifts the object release to the work processor */
63513 fscache_put_object(object);
63514 - fscache_stat(&fscache_n_object_dead);
63515 + fscache_stat_unchecked(&fscache_n_object_dead);
63516
63517 _leave("");
63518 return transit_to(OBJECT_DEAD);
63519 @@ -887,7 +887,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
63520 enum fscache_checkaux result;
63521
63522 if (!object->cookie->def->check_aux) {
63523 - fscache_stat(&fscache_n_checkaux_none);
63524 + fscache_stat_unchecked(&fscache_n_checkaux_none);
63525 return FSCACHE_CHECKAUX_OKAY;
63526 }
63527
63528 @@ -896,17 +896,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
63529 switch (result) {
63530 /* entry okay as is */
63531 case FSCACHE_CHECKAUX_OKAY:
63532 - fscache_stat(&fscache_n_checkaux_okay);
63533 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
63534 break;
63535
63536 /* entry requires update */
63537 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
63538 - fscache_stat(&fscache_n_checkaux_update);
63539 + fscache_stat_unchecked(&fscache_n_checkaux_update);
63540 break;
63541
63542 /* entry requires deletion */
63543 case FSCACHE_CHECKAUX_OBSOLETE:
63544 - fscache_stat(&fscache_n_checkaux_obsolete);
63545 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
63546 break;
63547
63548 default:
63549 @@ -992,7 +992,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
63550 {
63551 const struct fscache_state *s;
63552
63553 - fscache_stat(&fscache_n_invalidates_run);
63554 + fscache_stat_unchecked(&fscache_n_invalidates_run);
63555 fscache_stat(&fscache_n_cop_invalidate_object);
63556 s = _fscache_invalidate_object(object, event);
63557 fscache_stat_d(&fscache_n_cop_invalidate_object);
63558 @@ -1007,7 +1007,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
63559 {
63560 _enter("{OBJ%x},%d", object->debug_id, event);
63561
63562 - fscache_stat(&fscache_n_updates_run);
63563 + fscache_stat_unchecked(&fscache_n_updates_run);
63564 fscache_stat(&fscache_n_cop_update_object);
63565 object->cache->ops->update_object(object);
63566 fscache_stat_d(&fscache_n_cop_update_object);
63567 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
63568 index e7b87a0..a85d47a 100644
63569 --- a/fs/fscache/operation.c
63570 +++ b/fs/fscache/operation.c
63571 @@ -17,7 +17,7 @@
63572 #include <linux/slab.h>
63573 #include "internal.h"
63574
63575 -atomic_t fscache_op_debug_id;
63576 +atomic_unchecked_t fscache_op_debug_id;
63577 EXPORT_SYMBOL(fscache_op_debug_id);
63578
63579 /**
63580 @@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
63581 ASSERTCMP(atomic_read(&op->usage), >, 0);
63582 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
63583
63584 - fscache_stat(&fscache_n_op_enqueue);
63585 + fscache_stat_unchecked(&fscache_n_op_enqueue);
63586 switch (op->flags & FSCACHE_OP_TYPE) {
63587 case FSCACHE_OP_ASYNC:
63588 _debug("queue async");
63589 @@ -72,7 +72,7 @@ static void fscache_run_op(struct fscache_object *object,
63590 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
63591 if (op->processor)
63592 fscache_enqueue_operation(op);
63593 - fscache_stat(&fscache_n_op_run);
63594 + fscache_stat_unchecked(&fscache_n_op_run);
63595 }
63596
63597 /*
63598 @@ -104,11 +104,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
63599 if (object->n_in_progress > 0) {
63600 atomic_inc(&op->usage);
63601 list_add_tail(&op->pend_link, &object->pending_ops);
63602 - fscache_stat(&fscache_n_op_pend);
63603 + fscache_stat_unchecked(&fscache_n_op_pend);
63604 } else if (!list_empty(&object->pending_ops)) {
63605 atomic_inc(&op->usage);
63606 list_add_tail(&op->pend_link, &object->pending_ops);
63607 - fscache_stat(&fscache_n_op_pend);
63608 + fscache_stat_unchecked(&fscache_n_op_pend);
63609 fscache_start_operations(object);
63610 } else {
63611 ASSERTCMP(object->n_in_progress, ==, 0);
63612 @@ -124,7 +124,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
63613 object->n_exclusive++; /* reads and writes must wait */
63614 atomic_inc(&op->usage);
63615 list_add_tail(&op->pend_link, &object->pending_ops);
63616 - fscache_stat(&fscache_n_op_pend);
63617 + fscache_stat_unchecked(&fscache_n_op_pend);
63618 ret = 0;
63619 } else {
63620 /* If we're in any other state, there must have been an I/O
63621 @@ -211,11 +211,11 @@ int fscache_submit_op(struct fscache_object *object,
63622 if (object->n_exclusive > 0) {
63623 atomic_inc(&op->usage);
63624 list_add_tail(&op->pend_link, &object->pending_ops);
63625 - fscache_stat(&fscache_n_op_pend);
63626 + fscache_stat_unchecked(&fscache_n_op_pend);
63627 } else if (!list_empty(&object->pending_ops)) {
63628 atomic_inc(&op->usage);
63629 list_add_tail(&op->pend_link, &object->pending_ops);
63630 - fscache_stat(&fscache_n_op_pend);
63631 + fscache_stat_unchecked(&fscache_n_op_pend);
63632 fscache_start_operations(object);
63633 } else {
63634 ASSERTCMP(object->n_exclusive, ==, 0);
63635 @@ -227,10 +227,10 @@ int fscache_submit_op(struct fscache_object *object,
63636 object->n_ops++;
63637 atomic_inc(&op->usage);
63638 list_add_tail(&op->pend_link, &object->pending_ops);
63639 - fscache_stat(&fscache_n_op_pend);
63640 + fscache_stat_unchecked(&fscache_n_op_pend);
63641 ret = 0;
63642 } else if (fscache_object_is_dying(object)) {
63643 - fscache_stat(&fscache_n_op_rejected);
63644 + fscache_stat_unchecked(&fscache_n_op_rejected);
63645 op->state = FSCACHE_OP_ST_CANCELLED;
63646 ret = -ENOBUFS;
63647 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
63648 @@ -309,7 +309,7 @@ int fscache_cancel_op(struct fscache_operation *op,
63649 ret = -EBUSY;
63650 if (op->state == FSCACHE_OP_ST_PENDING) {
63651 ASSERT(!list_empty(&op->pend_link));
63652 - fscache_stat(&fscache_n_op_cancelled);
63653 + fscache_stat_unchecked(&fscache_n_op_cancelled);
63654 list_del_init(&op->pend_link);
63655 if (do_cancel)
63656 do_cancel(op);
63657 @@ -341,7 +341,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
63658 while (!list_empty(&object->pending_ops)) {
63659 op = list_entry(object->pending_ops.next,
63660 struct fscache_operation, pend_link);
63661 - fscache_stat(&fscache_n_op_cancelled);
63662 + fscache_stat_unchecked(&fscache_n_op_cancelled);
63663 list_del_init(&op->pend_link);
63664
63665 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
63666 @@ -413,7 +413,7 @@ void fscache_put_operation(struct fscache_operation *op)
63667 op->state, ==, FSCACHE_OP_ST_CANCELLED);
63668 op->state = FSCACHE_OP_ST_DEAD;
63669
63670 - fscache_stat(&fscache_n_op_release);
63671 + fscache_stat_unchecked(&fscache_n_op_release);
63672
63673 if (op->release) {
63674 op->release(op);
63675 @@ -432,7 +432,7 @@ void fscache_put_operation(struct fscache_operation *op)
63676 * lock, and defer it otherwise */
63677 if (!spin_trylock(&object->lock)) {
63678 _debug("defer put");
63679 - fscache_stat(&fscache_n_op_deferred_release);
63680 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
63681
63682 cache = object->cache;
63683 spin_lock(&cache->op_gc_list_lock);
63684 @@ -485,7 +485,7 @@ void fscache_operation_gc(struct work_struct *work)
63685
63686 _debug("GC DEFERRED REL OBJ%x OP%x",
63687 object->debug_id, op->debug_id);
63688 - fscache_stat(&fscache_n_op_gc);
63689 + fscache_stat_unchecked(&fscache_n_op_gc);
63690
63691 ASSERTCMP(atomic_read(&op->usage), ==, 0);
63692 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
63693 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
63694 index ed70714..67f4982 100644
63695 --- a/fs/fscache/page.c
63696 +++ b/fs/fscache/page.c
63697 @@ -61,7 +61,7 @@ try_again:
63698 val = radix_tree_lookup(&cookie->stores, page->index);
63699 if (!val) {
63700 rcu_read_unlock();
63701 - fscache_stat(&fscache_n_store_vmscan_not_storing);
63702 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
63703 __fscache_uncache_page(cookie, page);
63704 return true;
63705 }
63706 @@ -91,11 +91,11 @@ try_again:
63707 spin_unlock(&cookie->stores_lock);
63708
63709 if (xpage) {
63710 - fscache_stat(&fscache_n_store_vmscan_cancelled);
63711 - fscache_stat(&fscache_n_store_radix_deletes);
63712 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
63713 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
63714 ASSERTCMP(xpage, ==, page);
63715 } else {
63716 - fscache_stat(&fscache_n_store_vmscan_gone);
63717 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
63718 }
63719
63720 wake_up_bit(&cookie->flags, 0);
63721 @@ -110,11 +110,11 @@ page_busy:
63722 * sleeping on memory allocation, so we may need to impose a timeout
63723 * too. */
63724 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
63725 - fscache_stat(&fscache_n_store_vmscan_busy);
63726 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
63727 return false;
63728 }
63729
63730 - fscache_stat(&fscache_n_store_vmscan_wait);
63731 + fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
63732 __fscache_wait_on_page_write(cookie, page);
63733 gfp &= ~__GFP_WAIT;
63734 goto try_again;
63735 @@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
63736 FSCACHE_COOKIE_STORING_TAG);
63737 if (!radix_tree_tag_get(&cookie->stores, page->index,
63738 FSCACHE_COOKIE_PENDING_TAG)) {
63739 - fscache_stat(&fscache_n_store_radix_deletes);
63740 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
63741 xpage = radix_tree_delete(&cookie->stores, page->index);
63742 }
63743 spin_unlock(&cookie->stores_lock);
63744 @@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
63745
63746 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
63747
63748 - fscache_stat(&fscache_n_attr_changed_calls);
63749 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
63750
63751 if (fscache_object_is_active(object)) {
63752 fscache_stat(&fscache_n_cop_attr_changed);
63753 @@ -188,11 +188,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
63754
63755 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
63756
63757 - fscache_stat(&fscache_n_attr_changed);
63758 + fscache_stat_unchecked(&fscache_n_attr_changed);
63759
63760 op = kzalloc(sizeof(*op), GFP_KERNEL);
63761 if (!op) {
63762 - fscache_stat(&fscache_n_attr_changed_nomem);
63763 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
63764 _leave(" = -ENOMEM");
63765 return -ENOMEM;
63766 }
63767 @@ -214,7 +214,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
63768 if (fscache_submit_exclusive_op(object, op) < 0)
63769 goto nobufs;
63770 spin_unlock(&cookie->lock);
63771 - fscache_stat(&fscache_n_attr_changed_ok);
63772 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
63773 fscache_put_operation(op);
63774 _leave(" = 0");
63775 return 0;
63776 @@ -225,7 +225,7 @@ nobufs:
63777 kfree(op);
63778 if (wake_cookie)
63779 __fscache_wake_unused_cookie(cookie);
63780 - fscache_stat(&fscache_n_attr_changed_nobufs);
63781 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
63782 _leave(" = %d", -ENOBUFS);
63783 return -ENOBUFS;
63784 }
63785 @@ -264,7 +264,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
63786 /* allocate a retrieval operation and attempt to submit it */
63787 op = kzalloc(sizeof(*op), GFP_NOIO);
63788 if (!op) {
63789 - fscache_stat(&fscache_n_retrievals_nomem);
63790 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
63791 return NULL;
63792 }
63793
63794 @@ -294,13 +294,13 @@ int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
63795 return 0;
63796 }
63797
63798 - fscache_stat(&fscache_n_retrievals_wait);
63799 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
63800
63801 jif = jiffies;
63802 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
63803 fscache_wait_bit_interruptible,
63804 TASK_INTERRUPTIBLE) != 0) {
63805 - fscache_stat(&fscache_n_retrievals_intr);
63806 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
63807 _leave(" = -ERESTARTSYS");
63808 return -ERESTARTSYS;
63809 }
63810 @@ -329,8 +329,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
63811 */
63812 int fscache_wait_for_operation_activation(struct fscache_object *object,
63813 struct fscache_operation *op,
63814 - atomic_t *stat_op_waits,
63815 - atomic_t *stat_object_dead,
63816 + atomic_unchecked_t *stat_op_waits,
63817 + atomic_unchecked_t *stat_object_dead,
63818 void (*do_cancel)(struct fscache_operation *))
63819 {
63820 int ret;
63821 @@ -340,7 +340,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
63822
63823 _debug(">>> WT");
63824 if (stat_op_waits)
63825 - fscache_stat(stat_op_waits);
63826 + fscache_stat_unchecked(stat_op_waits);
63827 if (wait_on_bit(&op->flags, FSCACHE_OP_WAITING,
63828 fscache_wait_bit_interruptible,
63829 TASK_INTERRUPTIBLE) != 0) {
63830 @@ -358,7 +358,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
63831 check_if_dead:
63832 if (op->state == FSCACHE_OP_ST_CANCELLED) {
63833 if (stat_object_dead)
63834 - fscache_stat(stat_object_dead);
63835 + fscache_stat_unchecked(stat_object_dead);
63836 _leave(" = -ENOBUFS [cancelled]");
63837 return -ENOBUFS;
63838 }
63839 @@ -366,7 +366,7 @@ check_if_dead:
63840 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->state);
63841 fscache_cancel_op(op, do_cancel);
63842 if (stat_object_dead)
63843 - fscache_stat(stat_object_dead);
63844 + fscache_stat_unchecked(stat_object_dead);
63845 return -ENOBUFS;
63846 }
63847 return 0;
63848 @@ -394,7 +394,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
63849
63850 _enter("%p,%p,,,", cookie, page);
63851
63852 - fscache_stat(&fscache_n_retrievals);
63853 + fscache_stat_unchecked(&fscache_n_retrievals);
63854
63855 if (hlist_empty(&cookie->backing_objects))
63856 goto nobufs;
63857 @@ -436,7 +436,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
63858 goto nobufs_unlock_dec;
63859 spin_unlock(&cookie->lock);
63860
63861 - fscache_stat(&fscache_n_retrieval_ops);
63862 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
63863
63864 /* pin the netfs read context in case we need to do the actual netfs
63865 * read because we've encountered a cache read failure */
63866 @@ -467,15 +467,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
63867
63868 error:
63869 if (ret == -ENOMEM)
63870 - fscache_stat(&fscache_n_retrievals_nomem);
63871 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
63872 else if (ret == -ERESTARTSYS)
63873 - fscache_stat(&fscache_n_retrievals_intr);
63874 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
63875 else if (ret == -ENODATA)
63876 - fscache_stat(&fscache_n_retrievals_nodata);
63877 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
63878 else if (ret < 0)
63879 - fscache_stat(&fscache_n_retrievals_nobufs);
63880 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
63881 else
63882 - fscache_stat(&fscache_n_retrievals_ok);
63883 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
63884
63885 fscache_put_retrieval(op);
63886 _leave(" = %d", ret);
63887 @@ -490,7 +490,7 @@ nobufs_unlock:
63888 __fscache_wake_unused_cookie(cookie);
63889 kfree(op);
63890 nobufs:
63891 - fscache_stat(&fscache_n_retrievals_nobufs);
63892 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
63893 _leave(" = -ENOBUFS");
63894 return -ENOBUFS;
63895 }
63896 @@ -529,7 +529,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
63897
63898 _enter("%p,,%d,,,", cookie, *nr_pages);
63899
63900 - fscache_stat(&fscache_n_retrievals);
63901 + fscache_stat_unchecked(&fscache_n_retrievals);
63902
63903 if (hlist_empty(&cookie->backing_objects))
63904 goto nobufs;
63905 @@ -567,7 +567,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
63906 goto nobufs_unlock_dec;
63907 spin_unlock(&cookie->lock);
63908
63909 - fscache_stat(&fscache_n_retrieval_ops);
63910 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
63911
63912 /* pin the netfs read context in case we need to do the actual netfs
63913 * read because we've encountered a cache read failure */
63914 @@ -598,15 +598,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
63915
63916 error:
63917 if (ret == -ENOMEM)
63918 - fscache_stat(&fscache_n_retrievals_nomem);
63919 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
63920 else if (ret == -ERESTARTSYS)
63921 - fscache_stat(&fscache_n_retrievals_intr);
63922 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
63923 else if (ret == -ENODATA)
63924 - fscache_stat(&fscache_n_retrievals_nodata);
63925 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
63926 else if (ret < 0)
63927 - fscache_stat(&fscache_n_retrievals_nobufs);
63928 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
63929 else
63930 - fscache_stat(&fscache_n_retrievals_ok);
63931 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
63932
63933 fscache_put_retrieval(op);
63934 _leave(" = %d", ret);
63935 @@ -621,7 +621,7 @@ nobufs_unlock:
63936 if (wake_cookie)
63937 __fscache_wake_unused_cookie(cookie);
63938 nobufs:
63939 - fscache_stat(&fscache_n_retrievals_nobufs);
63940 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
63941 _leave(" = -ENOBUFS");
63942 return -ENOBUFS;
63943 }
63944 @@ -646,7 +646,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
63945
63946 _enter("%p,%p,,,", cookie, page);
63947
63948 - fscache_stat(&fscache_n_allocs);
63949 + fscache_stat_unchecked(&fscache_n_allocs);
63950
63951 if (hlist_empty(&cookie->backing_objects))
63952 goto nobufs;
63953 @@ -680,7 +680,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
63954 goto nobufs_unlock_dec;
63955 spin_unlock(&cookie->lock);
63956
63957 - fscache_stat(&fscache_n_alloc_ops);
63958 + fscache_stat_unchecked(&fscache_n_alloc_ops);
63959
63960 ret = fscache_wait_for_operation_activation(
63961 object, &op->op,
63962 @@ -697,11 +697,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
63963
63964 error:
63965 if (ret == -ERESTARTSYS)
63966 - fscache_stat(&fscache_n_allocs_intr);
63967 + fscache_stat_unchecked(&fscache_n_allocs_intr);
63968 else if (ret < 0)
63969 - fscache_stat(&fscache_n_allocs_nobufs);
63970 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
63971 else
63972 - fscache_stat(&fscache_n_allocs_ok);
63973 + fscache_stat_unchecked(&fscache_n_allocs_ok);
63974
63975 fscache_put_retrieval(op);
63976 _leave(" = %d", ret);
63977 @@ -715,7 +715,7 @@ nobufs_unlock:
63978 if (wake_cookie)
63979 __fscache_wake_unused_cookie(cookie);
63980 nobufs:
63981 - fscache_stat(&fscache_n_allocs_nobufs);
63982 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
63983 _leave(" = -ENOBUFS");
63984 return -ENOBUFS;
63985 }
63986 @@ -791,7 +791,7 @@ static void fscache_write_op(struct fscache_operation *_op)
63987
63988 spin_lock(&cookie->stores_lock);
63989
63990 - fscache_stat(&fscache_n_store_calls);
63991 + fscache_stat_unchecked(&fscache_n_store_calls);
63992
63993 /* find a page to store */
63994 page = NULL;
63995 @@ -802,7 +802,7 @@ static void fscache_write_op(struct fscache_operation *_op)
63996 page = results[0];
63997 _debug("gang %d [%lx]", n, page->index);
63998 if (page->index > op->store_limit) {
63999 - fscache_stat(&fscache_n_store_pages_over_limit);
64000 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
64001 goto superseded;
64002 }
64003
64004 @@ -814,7 +814,7 @@ static void fscache_write_op(struct fscache_operation *_op)
64005 spin_unlock(&cookie->stores_lock);
64006 spin_unlock(&object->lock);
64007
64008 - fscache_stat(&fscache_n_store_pages);
64009 + fscache_stat_unchecked(&fscache_n_store_pages);
64010 fscache_stat(&fscache_n_cop_write_page);
64011 ret = object->cache->ops->write_page(op, page);
64012 fscache_stat_d(&fscache_n_cop_write_page);
64013 @@ -918,7 +918,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
64014 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
64015 ASSERT(PageFsCache(page));
64016
64017 - fscache_stat(&fscache_n_stores);
64018 + fscache_stat_unchecked(&fscache_n_stores);
64019
64020 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
64021 _leave(" = -ENOBUFS [invalidating]");
64022 @@ -977,7 +977,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
64023 spin_unlock(&cookie->stores_lock);
64024 spin_unlock(&object->lock);
64025
64026 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
64027 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
64028 op->store_limit = object->store_limit;
64029
64030 __fscache_use_cookie(cookie);
64031 @@ -986,8 +986,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
64032
64033 spin_unlock(&cookie->lock);
64034 radix_tree_preload_end();
64035 - fscache_stat(&fscache_n_store_ops);
64036 - fscache_stat(&fscache_n_stores_ok);
64037 + fscache_stat_unchecked(&fscache_n_store_ops);
64038 + fscache_stat_unchecked(&fscache_n_stores_ok);
64039
64040 /* the work queue now carries its own ref on the object */
64041 fscache_put_operation(&op->op);
64042 @@ -995,14 +995,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
64043 return 0;
64044
64045 already_queued:
64046 - fscache_stat(&fscache_n_stores_again);
64047 + fscache_stat_unchecked(&fscache_n_stores_again);
64048 already_pending:
64049 spin_unlock(&cookie->stores_lock);
64050 spin_unlock(&object->lock);
64051 spin_unlock(&cookie->lock);
64052 radix_tree_preload_end();
64053 kfree(op);
64054 - fscache_stat(&fscache_n_stores_ok);
64055 + fscache_stat_unchecked(&fscache_n_stores_ok);
64056 _leave(" = 0");
64057 return 0;
64058
64059 @@ -1024,14 +1024,14 @@ nobufs:
64060 kfree(op);
64061 if (wake_cookie)
64062 __fscache_wake_unused_cookie(cookie);
64063 - fscache_stat(&fscache_n_stores_nobufs);
64064 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
64065 _leave(" = -ENOBUFS");
64066 return -ENOBUFS;
64067
64068 nomem_free:
64069 kfree(op);
64070 nomem:
64071 - fscache_stat(&fscache_n_stores_oom);
64072 + fscache_stat_unchecked(&fscache_n_stores_oom);
64073 _leave(" = -ENOMEM");
64074 return -ENOMEM;
64075 }
64076 @@ -1049,7 +1049,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
64077 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
64078 ASSERTCMP(page, !=, NULL);
64079
64080 - fscache_stat(&fscache_n_uncaches);
64081 + fscache_stat_unchecked(&fscache_n_uncaches);
64082
64083 /* cache withdrawal may beat us to it */
64084 if (!PageFsCache(page))
64085 @@ -1100,7 +1100,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
64086 struct fscache_cookie *cookie = op->op.object->cookie;
64087
64088 #ifdef CONFIG_FSCACHE_STATS
64089 - atomic_inc(&fscache_n_marks);
64090 + atomic_inc_unchecked(&fscache_n_marks);
64091 #endif
64092
64093 _debug("- mark %p{%lx}", page, page->index);
64094 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
64095 index 40d13c7..ddf52b9 100644
64096 --- a/fs/fscache/stats.c
64097 +++ b/fs/fscache/stats.c
64098 @@ -18,99 +18,99 @@
64099 /*
64100 * operation counters
64101 */
64102 -atomic_t fscache_n_op_pend;
64103 -atomic_t fscache_n_op_run;
64104 -atomic_t fscache_n_op_enqueue;
64105 -atomic_t fscache_n_op_requeue;
64106 -atomic_t fscache_n_op_deferred_release;
64107 -atomic_t fscache_n_op_release;
64108 -atomic_t fscache_n_op_gc;
64109 -atomic_t fscache_n_op_cancelled;
64110 -atomic_t fscache_n_op_rejected;
64111 +atomic_unchecked_t fscache_n_op_pend;
64112 +atomic_unchecked_t fscache_n_op_run;
64113 +atomic_unchecked_t fscache_n_op_enqueue;
64114 +atomic_unchecked_t fscache_n_op_requeue;
64115 +atomic_unchecked_t fscache_n_op_deferred_release;
64116 +atomic_unchecked_t fscache_n_op_release;
64117 +atomic_unchecked_t fscache_n_op_gc;
64118 +atomic_unchecked_t fscache_n_op_cancelled;
64119 +atomic_unchecked_t fscache_n_op_rejected;
64120
64121 -atomic_t fscache_n_attr_changed;
64122 -atomic_t fscache_n_attr_changed_ok;
64123 -atomic_t fscache_n_attr_changed_nobufs;
64124 -atomic_t fscache_n_attr_changed_nomem;
64125 -atomic_t fscache_n_attr_changed_calls;
64126 +atomic_unchecked_t fscache_n_attr_changed;
64127 +atomic_unchecked_t fscache_n_attr_changed_ok;
64128 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
64129 +atomic_unchecked_t fscache_n_attr_changed_nomem;
64130 +atomic_unchecked_t fscache_n_attr_changed_calls;
64131
64132 -atomic_t fscache_n_allocs;
64133 -atomic_t fscache_n_allocs_ok;
64134 -atomic_t fscache_n_allocs_wait;
64135 -atomic_t fscache_n_allocs_nobufs;
64136 -atomic_t fscache_n_allocs_intr;
64137 -atomic_t fscache_n_allocs_object_dead;
64138 -atomic_t fscache_n_alloc_ops;
64139 -atomic_t fscache_n_alloc_op_waits;
64140 +atomic_unchecked_t fscache_n_allocs;
64141 +atomic_unchecked_t fscache_n_allocs_ok;
64142 +atomic_unchecked_t fscache_n_allocs_wait;
64143 +atomic_unchecked_t fscache_n_allocs_nobufs;
64144 +atomic_unchecked_t fscache_n_allocs_intr;
64145 +atomic_unchecked_t fscache_n_allocs_object_dead;
64146 +atomic_unchecked_t fscache_n_alloc_ops;
64147 +atomic_unchecked_t fscache_n_alloc_op_waits;
64148
64149 -atomic_t fscache_n_retrievals;
64150 -atomic_t fscache_n_retrievals_ok;
64151 -atomic_t fscache_n_retrievals_wait;
64152 -atomic_t fscache_n_retrievals_nodata;
64153 -atomic_t fscache_n_retrievals_nobufs;
64154 -atomic_t fscache_n_retrievals_intr;
64155 -atomic_t fscache_n_retrievals_nomem;
64156 -atomic_t fscache_n_retrievals_object_dead;
64157 -atomic_t fscache_n_retrieval_ops;
64158 -atomic_t fscache_n_retrieval_op_waits;
64159 +atomic_unchecked_t fscache_n_retrievals;
64160 +atomic_unchecked_t fscache_n_retrievals_ok;
64161 +atomic_unchecked_t fscache_n_retrievals_wait;
64162 +atomic_unchecked_t fscache_n_retrievals_nodata;
64163 +atomic_unchecked_t fscache_n_retrievals_nobufs;
64164 +atomic_unchecked_t fscache_n_retrievals_intr;
64165 +atomic_unchecked_t fscache_n_retrievals_nomem;
64166 +atomic_unchecked_t fscache_n_retrievals_object_dead;
64167 +atomic_unchecked_t fscache_n_retrieval_ops;
64168 +atomic_unchecked_t fscache_n_retrieval_op_waits;
64169
64170 -atomic_t fscache_n_stores;
64171 -atomic_t fscache_n_stores_ok;
64172 -atomic_t fscache_n_stores_again;
64173 -atomic_t fscache_n_stores_nobufs;
64174 -atomic_t fscache_n_stores_oom;
64175 -atomic_t fscache_n_store_ops;
64176 -atomic_t fscache_n_store_calls;
64177 -atomic_t fscache_n_store_pages;
64178 -atomic_t fscache_n_store_radix_deletes;
64179 -atomic_t fscache_n_store_pages_over_limit;
64180 +atomic_unchecked_t fscache_n_stores;
64181 +atomic_unchecked_t fscache_n_stores_ok;
64182 +atomic_unchecked_t fscache_n_stores_again;
64183 +atomic_unchecked_t fscache_n_stores_nobufs;
64184 +atomic_unchecked_t fscache_n_stores_oom;
64185 +atomic_unchecked_t fscache_n_store_ops;
64186 +atomic_unchecked_t fscache_n_store_calls;
64187 +atomic_unchecked_t fscache_n_store_pages;
64188 +atomic_unchecked_t fscache_n_store_radix_deletes;
64189 +atomic_unchecked_t fscache_n_store_pages_over_limit;
64190
64191 -atomic_t fscache_n_store_vmscan_not_storing;
64192 -atomic_t fscache_n_store_vmscan_gone;
64193 -atomic_t fscache_n_store_vmscan_busy;
64194 -atomic_t fscache_n_store_vmscan_cancelled;
64195 -atomic_t fscache_n_store_vmscan_wait;
64196 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
64197 +atomic_unchecked_t fscache_n_store_vmscan_gone;
64198 +atomic_unchecked_t fscache_n_store_vmscan_busy;
64199 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
64200 +atomic_unchecked_t fscache_n_store_vmscan_wait;
64201
64202 -atomic_t fscache_n_marks;
64203 -atomic_t fscache_n_uncaches;
64204 +atomic_unchecked_t fscache_n_marks;
64205 +atomic_unchecked_t fscache_n_uncaches;
64206
64207 -atomic_t fscache_n_acquires;
64208 -atomic_t fscache_n_acquires_null;
64209 -atomic_t fscache_n_acquires_no_cache;
64210 -atomic_t fscache_n_acquires_ok;
64211 -atomic_t fscache_n_acquires_nobufs;
64212 -atomic_t fscache_n_acquires_oom;
64213 +atomic_unchecked_t fscache_n_acquires;
64214 +atomic_unchecked_t fscache_n_acquires_null;
64215 +atomic_unchecked_t fscache_n_acquires_no_cache;
64216 +atomic_unchecked_t fscache_n_acquires_ok;
64217 +atomic_unchecked_t fscache_n_acquires_nobufs;
64218 +atomic_unchecked_t fscache_n_acquires_oom;
64219
64220 -atomic_t fscache_n_invalidates;
64221 -atomic_t fscache_n_invalidates_run;
64222 +atomic_unchecked_t fscache_n_invalidates;
64223 +atomic_unchecked_t fscache_n_invalidates_run;
64224
64225 -atomic_t fscache_n_updates;
64226 -atomic_t fscache_n_updates_null;
64227 -atomic_t fscache_n_updates_run;
64228 +atomic_unchecked_t fscache_n_updates;
64229 +atomic_unchecked_t fscache_n_updates_null;
64230 +atomic_unchecked_t fscache_n_updates_run;
64231
64232 -atomic_t fscache_n_relinquishes;
64233 -atomic_t fscache_n_relinquishes_null;
64234 -atomic_t fscache_n_relinquishes_waitcrt;
64235 -atomic_t fscache_n_relinquishes_retire;
64236 +atomic_unchecked_t fscache_n_relinquishes;
64237 +atomic_unchecked_t fscache_n_relinquishes_null;
64238 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
64239 +atomic_unchecked_t fscache_n_relinquishes_retire;
64240
64241 -atomic_t fscache_n_cookie_index;
64242 -atomic_t fscache_n_cookie_data;
64243 -atomic_t fscache_n_cookie_special;
64244 +atomic_unchecked_t fscache_n_cookie_index;
64245 +atomic_unchecked_t fscache_n_cookie_data;
64246 +atomic_unchecked_t fscache_n_cookie_special;
64247
64248 -atomic_t fscache_n_object_alloc;
64249 -atomic_t fscache_n_object_no_alloc;
64250 -atomic_t fscache_n_object_lookups;
64251 -atomic_t fscache_n_object_lookups_negative;
64252 -atomic_t fscache_n_object_lookups_positive;
64253 -atomic_t fscache_n_object_lookups_timed_out;
64254 -atomic_t fscache_n_object_created;
64255 -atomic_t fscache_n_object_avail;
64256 -atomic_t fscache_n_object_dead;
64257 +atomic_unchecked_t fscache_n_object_alloc;
64258 +atomic_unchecked_t fscache_n_object_no_alloc;
64259 +atomic_unchecked_t fscache_n_object_lookups;
64260 +atomic_unchecked_t fscache_n_object_lookups_negative;
64261 +atomic_unchecked_t fscache_n_object_lookups_positive;
64262 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
64263 +atomic_unchecked_t fscache_n_object_created;
64264 +atomic_unchecked_t fscache_n_object_avail;
64265 +atomic_unchecked_t fscache_n_object_dead;
64266
64267 -atomic_t fscache_n_checkaux_none;
64268 -atomic_t fscache_n_checkaux_okay;
64269 -atomic_t fscache_n_checkaux_update;
64270 -atomic_t fscache_n_checkaux_obsolete;
64271 +atomic_unchecked_t fscache_n_checkaux_none;
64272 +atomic_unchecked_t fscache_n_checkaux_okay;
64273 +atomic_unchecked_t fscache_n_checkaux_update;
64274 +atomic_unchecked_t fscache_n_checkaux_obsolete;
64275
64276 atomic_t fscache_n_cop_alloc_object;
64277 atomic_t fscache_n_cop_lookup_object;
64278 @@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
64279 seq_puts(m, "FS-Cache statistics\n");
64280
64281 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
64282 - atomic_read(&fscache_n_cookie_index),
64283 - atomic_read(&fscache_n_cookie_data),
64284 - atomic_read(&fscache_n_cookie_special));
64285 + atomic_read_unchecked(&fscache_n_cookie_index),
64286 + atomic_read_unchecked(&fscache_n_cookie_data),
64287 + atomic_read_unchecked(&fscache_n_cookie_special));
64288
64289 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
64290 - atomic_read(&fscache_n_object_alloc),
64291 - atomic_read(&fscache_n_object_no_alloc),
64292 - atomic_read(&fscache_n_object_avail),
64293 - atomic_read(&fscache_n_object_dead));
64294 + atomic_read_unchecked(&fscache_n_object_alloc),
64295 + atomic_read_unchecked(&fscache_n_object_no_alloc),
64296 + atomic_read_unchecked(&fscache_n_object_avail),
64297 + atomic_read_unchecked(&fscache_n_object_dead));
64298 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
64299 - atomic_read(&fscache_n_checkaux_none),
64300 - atomic_read(&fscache_n_checkaux_okay),
64301 - atomic_read(&fscache_n_checkaux_update),
64302 - atomic_read(&fscache_n_checkaux_obsolete));
64303 + atomic_read_unchecked(&fscache_n_checkaux_none),
64304 + atomic_read_unchecked(&fscache_n_checkaux_okay),
64305 + atomic_read_unchecked(&fscache_n_checkaux_update),
64306 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
64307
64308 seq_printf(m, "Pages : mrk=%u unc=%u\n",
64309 - atomic_read(&fscache_n_marks),
64310 - atomic_read(&fscache_n_uncaches));
64311 + atomic_read_unchecked(&fscache_n_marks),
64312 + atomic_read_unchecked(&fscache_n_uncaches));
64313
64314 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
64315 " oom=%u\n",
64316 - atomic_read(&fscache_n_acquires),
64317 - atomic_read(&fscache_n_acquires_null),
64318 - atomic_read(&fscache_n_acquires_no_cache),
64319 - atomic_read(&fscache_n_acquires_ok),
64320 - atomic_read(&fscache_n_acquires_nobufs),
64321 - atomic_read(&fscache_n_acquires_oom));
64322 + atomic_read_unchecked(&fscache_n_acquires),
64323 + atomic_read_unchecked(&fscache_n_acquires_null),
64324 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
64325 + atomic_read_unchecked(&fscache_n_acquires_ok),
64326 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
64327 + atomic_read_unchecked(&fscache_n_acquires_oom));
64328
64329 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
64330 - atomic_read(&fscache_n_object_lookups),
64331 - atomic_read(&fscache_n_object_lookups_negative),
64332 - atomic_read(&fscache_n_object_lookups_positive),
64333 - atomic_read(&fscache_n_object_created),
64334 - atomic_read(&fscache_n_object_lookups_timed_out));
64335 + atomic_read_unchecked(&fscache_n_object_lookups),
64336 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
64337 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
64338 + atomic_read_unchecked(&fscache_n_object_created),
64339 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
64340
64341 seq_printf(m, "Invals : n=%u run=%u\n",
64342 - atomic_read(&fscache_n_invalidates),
64343 - atomic_read(&fscache_n_invalidates_run));
64344 + atomic_read_unchecked(&fscache_n_invalidates),
64345 + atomic_read_unchecked(&fscache_n_invalidates_run));
64346
64347 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
64348 - atomic_read(&fscache_n_updates),
64349 - atomic_read(&fscache_n_updates_null),
64350 - atomic_read(&fscache_n_updates_run));
64351 + atomic_read_unchecked(&fscache_n_updates),
64352 + atomic_read_unchecked(&fscache_n_updates_null),
64353 + atomic_read_unchecked(&fscache_n_updates_run));
64354
64355 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
64356 - atomic_read(&fscache_n_relinquishes),
64357 - atomic_read(&fscache_n_relinquishes_null),
64358 - atomic_read(&fscache_n_relinquishes_waitcrt),
64359 - atomic_read(&fscache_n_relinquishes_retire));
64360 + atomic_read_unchecked(&fscache_n_relinquishes),
64361 + atomic_read_unchecked(&fscache_n_relinquishes_null),
64362 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
64363 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
64364
64365 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
64366 - atomic_read(&fscache_n_attr_changed),
64367 - atomic_read(&fscache_n_attr_changed_ok),
64368 - atomic_read(&fscache_n_attr_changed_nobufs),
64369 - atomic_read(&fscache_n_attr_changed_nomem),
64370 - atomic_read(&fscache_n_attr_changed_calls));
64371 + atomic_read_unchecked(&fscache_n_attr_changed),
64372 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
64373 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
64374 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
64375 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
64376
64377 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
64378 - atomic_read(&fscache_n_allocs),
64379 - atomic_read(&fscache_n_allocs_ok),
64380 - atomic_read(&fscache_n_allocs_wait),
64381 - atomic_read(&fscache_n_allocs_nobufs),
64382 - atomic_read(&fscache_n_allocs_intr));
64383 + atomic_read_unchecked(&fscache_n_allocs),
64384 + atomic_read_unchecked(&fscache_n_allocs_ok),
64385 + atomic_read_unchecked(&fscache_n_allocs_wait),
64386 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
64387 + atomic_read_unchecked(&fscache_n_allocs_intr));
64388 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
64389 - atomic_read(&fscache_n_alloc_ops),
64390 - atomic_read(&fscache_n_alloc_op_waits),
64391 - atomic_read(&fscache_n_allocs_object_dead));
64392 + atomic_read_unchecked(&fscache_n_alloc_ops),
64393 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
64394 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
64395
64396 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
64397 " int=%u oom=%u\n",
64398 - atomic_read(&fscache_n_retrievals),
64399 - atomic_read(&fscache_n_retrievals_ok),
64400 - atomic_read(&fscache_n_retrievals_wait),
64401 - atomic_read(&fscache_n_retrievals_nodata),
64402 - atomic_read(&fscache_n_retrievals_nobufs),
64403 - atomic_read(&fscache_n_retrievals_intr),
64404 - atomic_read(&fscache_n_retrievals_nomem));
64405 + atomic_read_unchecked(&fscache_n_retrievals),
64406 + atomic_read_unchecked(&fscache_n_retrievals_ok),
64407 + atomic_read_unchecked(&fscache_n_retrievals_wait),
64408 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
64409 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
64410 + atomic_read_unchecked(&fscache_n_retrievals_intr),
64411 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
64412 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
64413 - atomic_read(&fscache_n_retrieval_ops),
64414 - atomic_read(&fscache_n_retrieval_op_waits),
64415 - atomic_read(&fscache_n_retrievals_object_dead));
64416 + atomic_read_unchecked(&fscache_n_retrieval_ops),
64417 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
64418 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
64419
64420 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
64421 - atomic_read(&fscache_n_stores),
64422 - atomic_read(&fscache_n_stores_ok),
64423 - atomic_read(&fscache_n_stores_again),
64424 - atomic_read(&fscache_n_stores_nobufs),
64425 - atomic_read(&fscache_n_stores_oom));
64426 + atomic_read_unchecked(&fscache_n_stores),
64427 + atomic_read_unchecked(&fscache_n_stores_ok),
64428 + atomic_read_unchecked(&fscache_n_stores_again),
64429 + atomic_read_unchecked(&fscache_n_stores_nobufs),
64430 + atomic_read_unchecked(&fscache_n_stores_oom));
64431 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
64432 - atomic_read(&fscache_n_store_ops),
64433 - atomic_read(&fscache_n_store_calls),
64434 - atomic_read(&fscache_n_store_pages),
64435 - atomic_read(&fscache_n_store_radix_deletes),
64436 - atomic_read(&fscache_n_store_pages_over_limit));
64437 + atomic_read_unchecked(&fscache_n_store_ops),
64438 + atomic_read_unchecked(&fscache_n_store_calls),
64439 + atomic_read_unchecked(&fscache_n_store_pages),
64440 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
64441 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
64442
64443 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
64444 - atomic_read(&fscache_n_store_vmscan_not_storing),
64445 - atomic_read(&fscache_n_store_vmscan_gone),
64446 - atomic_read(&fscache_n_store_vmscan_busy),
64447 - atomic_read(&fscache_n_store_vmscan_cancelled),
64448 - atomic_read(&fscache_n_store_vmscan_wait));
64449 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
64450 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
64451 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
64452 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
64453 + atomic_read_unchecked(&fscache_n_store_vmscan_wait));
64454
64455 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
64456 - atomic_read(&fscache_n_op_pend),
64457 - atomic_read(&fscache_n_op_run),
64458 - atomic_read(&fscache_n_op_enqueue),
64459 - atomic_read(&fscache_n_op_cancelled),
64460 - atomic_read(&fscache_n_op_rejected));
64461 + atomic_read_unchecked(&fscache_n_op_pend),
64462 + atomic_read_unchecked(&fscache_n_op_run),
64463 + atomic_read_unchecked(&fscache_n_op_enqueue),
64464 + atomic_read_unchecked(&fscache_n_op_cancelled),
64465 + atomic_read_unchecked(&fscache_n_op_rejected));
64466 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
64467 - atomic_read(&fscache_n_op_deferred_release),
64468 - atomic_read(&fscache_n_op_release),
64469 - atomic_read(&fscache_n_op_gc));
64470 + atomic_read_unchecked(&fscache_n_op_deferred_release),
64471 + atomic_read_unchecked(&fscache_n_op_release),
64472 + atomic_read_unchecked(&fscache_n_op_gc));
64473
64474 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
64475 atomic_read(&fscache_n_cop_alloc_object),
64476 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
64477 index 966ace8..030a03a 100644
64478 --- a/fs/fuse/cuse.c
64479 +++ b/fs/fuse/cuse.c
64480 @@ -611,10 +611,12 @@ static int __init cuse_init(void)
64481 INIT_LIST_HEAD(&cuse_conntbl[i]);
64482
64483 /* inherit and extend fuse_dev_operations */
64484 - cuse_channel_fops = fuse_dev_operations;
64485 - cuse_channel_fops.owner = THIS_MODULE;
64486 - cuse_channel_fops.open = cuse_channel_open;
64487 - cuse_channel_fops.release = cuse_channel_release;
64488 + pax_open_kernel();
64489 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
64490 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
64491 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
64492 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
64493 + pax_close_kernel();
64494
64495 cuse_class = class_create(THIS_MODULE, "cuse");
64496 if (IS_ERR(cuse_class))
64497 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
64498 index ca88731..8e9c55d 100644
64499 --- a/fs/fuse/dev.c
64500 +++ b/fs/fuse/dev.c
64501 @@ -1318,7 +1318,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
64502 ret = 0;
64503 pipe_lock(pipe);
64504
64505 - if (!pipe->readers) {
64506 + if (!atomic_read(&pipe->readers)) {
64507 send_sig(SIGPIPE, current, 0);
64508 if (!ret)
64509 ret = -EPIPE;
64510 @@ -1347,7 +1347,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
64511 page_nr++;
64512 ret += buf->len;
64513
64514 - if (pipe->files)
64515 + if (atomic_read(&pipe->files))
64516 do_wakeup = 1;
64517 }
64518
64519 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
64520 index 0c60482..025724f 100644
64521 --- a/fs/fuse/dir.c
64522 +++ b/fs/fuse/dir.c
64523 @@ -1485,7 +1485,7 @@ static char *read_link(struct dentry *dentry)
64524 return link;
64525 }
64526
64527 -static void free_link(char *link)
64528 +static void free_link(const char *link)
64529 {
64530 if (!IS_ERR(link))
64531 free_page((unsigned long) link);
64532 diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
64533 index bb529f3..454c253 100644
64534 --- a/fs/hostfs/hostfs_kern.c
64535 +++ b/fs/hostfs/hostfs_kern.c
64536 @@ -898,7 +898,7 @@ static void *hostfs_follow_link(struct dentry *dentry, struct nameidata *nd)
64537
64538 static void hostfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
64539 {
64540 - char *s = nd_get_link(nd);
64541 + const char *s = nd_get_link(nd);
64542 if (!IS_ERR(s))
64543 __putname(s);
64544 }
64545 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
64546 index 1e2872b..7aea000 100644
64547 --- a/fs/hugetlbfs/inode.c
64548 +++ b/fs/hugetlbfs/inode.c
64549 @@ -154,6 +154,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
64550 struct mm_struct *mm = current->mm;
64551 struct vm_area_struct *vma;
64552 struct hstate *h = hstate_file(file);
64553 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
64554 struct vm_unmapped_area_info info;
64555
64556 if (len & ~huge_page_mask(h))
64557 @@ -167,17 +168,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
64558 return addr;
64559 }
64560
64561 +#ifdef CONFIG_PAX_RANDMMAP
64562 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
64563 +#endif
64564 +
64565 if (addr) {
64566 addr = ALIGN(addr, huge_page_size(h));
64567 vma = find_vma(mm, addr);
64568 - if (TASK_SIZE - len >= addr &&
64569 - (!vma || addr + len <= vma->vm_start))
64570 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
64571 return addr;
64572 }
64573
64574 info.flags = 0;
64575 info.length = len;
64576 info.low_limit = TASK_UNMAPPED_BASE;
64577 +
64578 +#ifdef CONFIG_PAX_RANDMMAP
64579 + if (mm->pax_flags & MF_PAX_RANDMMAP)
64580 + info.low_limit += mm->delta_mmap;
64581 +#endif
64582 +
64583 info.high_limit = TASK_SIZE;
64584 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
64585 info.align_offset = 0;
64586 @@ -919,7 +929,7 @@ static struct file_system_type hugetlbfs_fs_type = {
64587 };
64588 MODULE_ALIAS_FS("hugetlbfs");
64589
64590 -static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
64591 +struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
64592
64593 static int can_do_hugetlb_shm(void)
64594 {
64595 diff --git a/fs/inode.c b/fs/inode.c
64596 index 6eecb7f..abec305 100644
64597 --- a/fs/inode.c
64598 +++ b/fs/inode.c
64599 @@ -839,16 +839,20 @@ unsigned int get_next_ino(void)
64600 unsigned int *p = &get_cpu_var(last_ino);
64601 unsigned int res = *p;
64602
64603 +start:
64604 +
64605 #ifdef CONFIG_SMP
64606 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
64607 - static atomic_t shared_last_ino;
64608 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
64609 + static atomic_unchecked_t shared_last_ino;
64610 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
64611
64612 res = next - LAST_INO_BATCH;
64613 }
64614 #endif
64615
64616 - *p = ++res;
64617 + if (unlikely(!++res))
64618 + goto start; /* never zero */
64619 + *p = res;
64620 put_cpu_var(last_ino);
64621 return res;
64622 }
64623 diff --git a/fs/isofs/inode.c b/fs/isofs/inode.c
64624 index 4556ce1..5ddaf86 100644
64625 --- a/fs/isofs/inode.c
64626 +++ b/fs/isofs/inode.c
64627 @@ -61,7 +61,7 @@ static void isofs_put_super(struct super_block *sb)
64628 return;
64629 }
64630
64631 -static int isofs_read_inode(struct inode *);
64632 +static int isofs_read_inode(struct inode *, int relocated);
64633 static int isofs_statfs (struct dentry *, struct kstatfs *);
64634
64635 static struct kmem_cache *isofs_inode_cachep;
64636 @@ -1259,7 +1259,7 @@ out_toomany:
64637 goto out;
64638 }
64639
64640 -static int isofs_read_inode(struct inode *inode)
64641 +static int isofs_read_inode(struct inode *inode, int relocated)
64642 {
64643 struct super_block *sb = inode->i_sb;
64644 struct isofs_sb_info *sbi = ISOFS_SB(sb);
64645 @@ -1404,7 +1404,7 @@ static int isofs_read_inode(struct inode *inode)
64646 */
64647
64648 if (!high_sierra) {
64649 - parse_rock_ridge_inode(de, inode);
64650 + parse_rock_ridge_inode(de, inode, relocated);
64651 /* if we want uid/gid set, override the rock ridge setting */
64652 if (sbi->s_uid_set)
64653 inode->i_uid = sbi->s_uid;
64654 @@ -1483,9 +1483,10 @@ static int isofs_iget5_set(struct inode *ino, void *data)
64655 * offset that point to the underlying meta-data for the inode. The
64656 * code below is otherwise similar to the iget() code in
64657 * include/linux/fs.h */
64658 -struct inode *isofs_iget(struct super_block *sb,
64659 - unsigned long block,
64660 - unsigned long offset)
64661 +struct inode *__isofs_iget(struct super_block *sb,
64662 + unsigned long block,
64663 + unsigned long offset,
64664 + int relocated)
64665 {
64666 unsigned long hashval;
64667 struct inode *inode;
64668 @@ -1507,7 +1508,7 @@ struct inode *isofs_iget(struct super_block *sb,
64669 return ERR_PTR(-ENOMEM);
64670
64671 if (inode->i_state & I_NEW) {
64672 - ret = isofs_read_inode(inode);
64673 + ret = isofs_read_inode(inode, relocated);
64674 if (ret < 0) {
64675 iget_failed(inode);
64676 inode = ERR_PTR(ret);
64677 diff --git a/fs/isofs/isofs.h b/fs/isofs/isofs.h
64678 index 9916723..0ac4c1f 100644
64679 --- a/fs/isofs/isofs.h
64680 +++ b/fs/isofs/isofs.h
64681 @@ -107,7 +107,7 @@ extern int iso_date(char *, int);
64682
64683 struct inode; /* To make gcc happy */
64684
64685 -extern int parse_rock_ridge_inode(struct iso_directory_record *, struct inode *);
64686 +extern int parse_rock_ridge_inode(struct iso_directory_record *, struct inode *, int relocated);
64687 extern int get_rock_ridge_filename(struct iso_directory_record *, char *, struct inode *);
64688 extern int isofs_name_translate(struct iso_directory_record *, char *, struct inode *);
64689
64690 @@ -118,9 +118,24 @@ extern struct dentry *isofs_lookup(struct inode *, struct dentry *, unsigned int
64691 extern struct buffer_head *isofs_bread(struct inode *, sector_t);
64692 extern int isofs_get_blocks(struct inode *, sector_t, struct buffer_head **, unsigned long);
64693
64694 -extern struct inode *isofs_iget(struct super_block *sb,
64695 - unsigned long block,
64696 - unsigned long offset);
64697 +struct inode *__isofs_iget(struct super_block *sb,
64698 + unsigned long block,
64699 + unsigned long offset,
64700 + int relocated);
64701 +
64702 +static inline struct inode *isofs_iget(struct super_block *sb,
64703 + unsigned long block,
64704 + unsigned long offset)
64705 +{
64706 + return __isofs_iget(sb, block, offset, 0);
64707 +}
64708 +
64709 +static inline struct inode *isofs_iget_reloc(struct super_block *sb,
64710 + unsigned long block,
64711 + unsigned long offset)
64712 +{
64713 + return __isofs_iget(sb, block, offset, 1);
64714 +}
64715
64716 /* Because the inode number is no longer relevant to finding the
64717 * underlying meta-data for an inode, we are free to choose a more
64718 diff --git a/fs/isofs/rock.c b/fs/isofs/rock.c
64719 index c0bf424..f488bba 100644
64720 --- a/fs/isofs/rock.c
64721 +++ b/fs/isofs/rock.c
64722 @@ -288,12 +288,16 @@ eio:
64723 goto out;
64724 }
64725
64726 +#define RR_REGARD_XA 1
64727 +#define RR_RELOC_DE 2
64728 +
64729 static int
64730 parse_rock_ridge_inode_internal(struct iso_directory_record *de,
64731 - struct inode *inode, int regard_xa)
64732 + struct inode *inode, int flags)
64733 {
64734 int symlink_len = 0;
64735 int cnt, sig;
64736 + unsigned int reloc_block;
64737 struct inode *reloc;
64738 struct rock_ridge *rr;
64739 int rootflag;
64740 @@ -305,7 +309,7 @@ parse_rock_ridge_inode_internal(struct iso_directory_record *de,
64741
64742 init_rock_state(&rs, inode);
64743 setup_rock_ridge(de, inode, &rs);
64744 - if (regard_xa) {
64745 + if (flags & RR_REGARD_XA) {
64746 rs.chr += 14;
64747 rs.len -= 14;
64748 if (rs.len < 0)
64749 @@ -485,12 +489,22 @@ repeat:
64750 "relocated directory\n");
64751 goto out;
64752 case SIG('C', 'L'):
64753 - ISOFS_I(inode)->i_first_extent =
64754 - isonum_733(rr->u.CL.location);
64755 - reloc =
64756 - isofs_iget(inode->i_sb,
64757 - ISOFS_I(inode)->i_first_extent,
64758 - 0);
64759 + if (flags & RR_RELOC_DE) {
64760 + printk(KERN_ERR
64761 + "ISOFS: Recursive directory relocation "
64762 + "is not supported\n");
64763 + goto eio;
64764 + }
64765 + reloc_block = isonum_733(rr->u.CL.location);
64766 + if (reloc_block == ISOFS_I(inode)->i_iget5_block &&
64767 + ISOFS_I(inode)->i_iget5_offset == 0) {
64768 + printk(KERN_ERR
64769 + "ISOFS: Directory relocation points to "
64770 + "itself\n");
64771 + goto eio;
64772 + }
64773 + ISOFS_I(inode)->i_first_extent = reloc_block;
64774 + reloc = isofs_iget_reloc(inode->i_sb, reloc_block, 0);
64775 if (IS_ERR(reloc)) {
64776 ret = PTR_ERR(reloc);
64777 goto out;
64778 @@ -637,9 +651,11 @@ static char *get_symlink_chunk(char *rpnt, struct rock_ridge *rr, char *plimit)
64779 return rpnt;
64780 }
64781
64782 -int parse_rock_ridge_inode(struct iso_directory_record *de, struct inode *inode)
64783 +int parse_rock_ridge_inode(struct iso_directory_record *de, struct inode *inode,
64784 + int relocated)
64785 {
64786 - int result = parse_rock_ridge_inode_internal(de, inode, 0);
64787 + int flags = relocated ? RR_RELOC_DE : 0;
64788 + int result = parse_rock_ridge_inode_internal(de, inode, flags);
64789
64790 /*
64791 * if rockridge flag was reset and we didn't look for attributes
64792 @@ -647,7 +663,8 @@ int parse_rock_ridge_inode(struct iso_directory_record *de, struct inode *inode)
64793 */
64794 if ((ISOFS_SB(inode->i_sb)->s_rock_offset == -1)
64795 && (ISOFS_SB(inode->i_sb)->s_rock == 2)) {
64796 - result = parse_rock_ridge_inode_internal(de, inode, 14);
64797 + result = parse_rock_ridge_inode_internal(de, inode,
64798 + flags | RR_REGARD_XA);
64799 }
64800 return result;
64801 }
64802 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
64803 index 4a6cf28..d3a29d3 100644
64804 --- a/fs/jffs2/erase.c
64805 +++ b/fs/jffs2/erase.c
64806 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
64807 struct jffs2_unknown_node marker = {
64808 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
64809 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
64810 - .totlen = cpu_to_je32(c->cleanmarker_size)
64811 + .totlen = cpu_to_je32(c->cleanmarker_size),
64812 + .hdr_crc = cpu_to_je32(0)
64813 };
64814
64815 jffs2_prealloc_raw_node_refs(c, jeb, 1);
64816 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
64817 index a6597d6..41b30ec 100644
64818 --- a/fs/jffs2/wbuf.c
64819 +++ b/fs/jffs2/wbuf.c
64820 @@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
64821 {
64822 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
64823 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
64824 - .totlen = constant_cpu_to_je32(8)
64825 + .totlen = constant_cpu_to_je32(8),
64826 + .hdr_crc = constant_cpu_to_je32(0)
64827 };
64828
64829 /*
64830 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
64831 index adf8cb0..bb935fa 100644
64832 --- a/fs/jfs/super.c
64833 +++ b/fs/jfs/super.c
64834 @@ -893,7 +893,7 @@ static int __init init_jfs_fs(void)
64835
64836 jfs_inode_cachep =
64837 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
64838 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
64839 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
64840 init_once);
64841 if (jfs_inode_cachep == NULL)
64842 return -ENOMEM;
64843 diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
64844 index a693f5b..82276a1 100644
64845 --- a/fs/kernfs/dir.c
64846 +++ b/fs/kernfs/dir.c
64847 @@ -182,7 +182,7 @@ struct kernfs_node *kernfs_get_parent(struct kernfs_node *kn)
64848 *
64849 * Returns 31 bit hash of ns + name (so it fits in an off_t )
64850 */
64851 -static unsigned int kernfs_name_hash(const char *name, const void *ns)
64852 +static unsigned int kernfs_name_hash(const unsigned char *name, const void *ns)
64853 {
64854 unsigned long hash = init_name_hash();
64855 unsigned int len = strlen(name);
64856 diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c
64857 index d895b4b..0b8af77 100644
64858 --- a/fs/kernfs/file.c
64859 +++ b/fs/kernfs/file.c
64860 @@ -34,7 +34,7 @@ static DEFINE_MUTEX(kernfs_open_file_mutex);
64861
64862 struct kernfs_open_node {
64863 atomic_t refcnt;
64864 - atomic_t event;
64865 + atomic_unchecked_t event;
64866 wait_queue_head_t poll;
64867 struct list_head files; /* goes through kernfs_open_file.list */
64868 };
64869 @@ -163,7 +163,7 @@ static int kernfs_seq_show(struct seq_file *sf, void *v)
64870 {
64871 struct kernfs_open_file *of = sf->private;
64872
64873 - of->event = atomic_read(&of->kn->attr.open->event);
64874 + of->event = atomic_read_unchecked(&of->kn->attr.open->event);
64875
64876 return of->kn->attr.ops->seq_show(sf, v);
64877 }
64878 @@ -375,12 +375,12 @@ static int kernfs_vma_page_mkwrite(struct vm_area_struct *vma,
64879 return ret;
64880 }
64881
64882 -static int kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
64883 - void *buf, int len, int write)
64884 +static ssize_t kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
64885 + void *buf, size_t len, int write)
64886 {
64887 struct file *file = vma->vm_file;
64888 struct kernfs_open_file *of = kernfs_of(file);
64889 - int ret;
64890 + ssize_t ret;
64891
64892 if (!of->vm_ops)
64893 return -EINVAL;
64894 @@ -581,7 +581,7 @@ static int kernfs_get_open_node(struct kernfs_node *kn,
64895 return -ENOMEM;
64896
64897 atomic_set(&new_on->refcnt, 0);
64898 - atomic_set(&new_on->event, 1);
64899 + atomic_set_unchecked(&new_on->event, 1);
64900 init_waitqueue_head(&new_on->poll);
64901 INIT_LIST_HEAD(&new_on->files);
64902 goto retry;
64903 @@ -787,7 +787,7 @@ static unsigned int kernfs_fop_poll(struct file *filp, poll_table *wait)
64904
64905 kernfs_put_active(kn);
64906
64907 - if (of->event != atomic_read(&on->event))
64908 + if (of->event != atomic_read_unchecked(&on->event))
64909 goto trigger;
64910
64911 return DEFAULT_POLLMASK;
64912 @@ -818,7 +818,7 @@ repeat:
64913
64914 on = kn->attr.open;
64915 if (on) {
64916 - atomic_inc(&on->event);
64917 + atomic_inc_unchecked(&on->event);
64918 wake_up_interruptible(&on->poll);
64919 }
64920
64921 diff --git a/fs/kernfs/symlink.c b/fs/kernfs/symlink.c
64922 index 8a19889..4c3069a 100644
64923 --- a/fs/kernfs/symlink.c
64924 +++ b/fs/kernfs/symlink.c
64925 @@ -128,7 +128,7 @@ static void *kernfs_iop_follow_link(struct dentry *dentry, struct nameidata *nd)
64926 static void kernfs_iop_put_link(struct dentry *dentry, struct nameidata *nd,
64927 void *cookie)
64928 {
64929 - char *page = nd_get_link(nd);
64930 + const char *page = nd_get_link(nd);
64931 if (!IS_ERR(page))
64932 free_page((unsigned long)page);
64933 }
64934 diff --git a/fs/libfs.c b/fs/libfs.c
64935 index 88e3e00..979c262 100644
64936 --- a/fs/libfs.c
64937 +++ b/fs/libfs.c
64938 @@ -160,6 +160,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
64939
64940 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
64941 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
64942 + char d_name[sizeof(next->d_iname)];
64943 + const unsigned char *name;
64944 +
64945 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
64946 if (!simple_positive(next)) {
64947 spin_unlock(&next->d_lock);
64948 @@ -168,7 +171,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
64949
64950 spin_unlock(&next->d_lock);
64951 spin_unlock(&dentry->d_lock);
64952 - if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
64953 + name = next->d_name.name;
64954 + if (name == next->d_iname) {
64955 + memcpy(d_name, name, next->d_name.len);
64956 + name = d_name;
64957 + }
64958 + if (!dir_emit(ctx, name, next->d_name.len,
64959 next->d_inode->i_ino, dt_type(next->d_inode)))
64960 return 0;
64961 spin_lock(&dentry->d_lock);
64962 @@ -1027,7 +1035,7 @@ EXPORT_SYMBOL(noop_fsync);
64963 void kfree_put_link(struct dentry *dentry, struct nameidata *nd,
64964 void *cookie)
64965 {
64966 - char *s = nd_get_link(nd);
64967 + const char *s = nd_get_link(nd);
64968 if (!IS_ERR(s))
64969 kfree(s);
64970 }
64971 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
64972 index acd3947..1f896e2 100644
64973 --- a/fs/lockd/clntproc.c
64974 +++ b/fs/lockd/clntproc.c
64975 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
64976 /*
64977 * Cookie counter for NLM requests
64978 */
64979 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
64980 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
64981
64982 void nlmclnt_next_cookie(struct nlm_cookie *c)
64983 {
64984 - u32 cookie = atomic_inc_return(&nlm_cookie);
64985 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
64986
64987 memcpy(c->data, &cookie, 4);
64988 c->len=4;
64989 diff --git a/fs/locks.c b/fs/locks.c
64990 index 717fbc4..74628c3 100644
64991 --- a/fs/locks.c
64992 +++ b/fs/locks.c
64993 @@ -2327,7 +2327,7 @@ void locks_remove_file(struct file *filp)
64994 locks_remove_posix(filp, (fl_owner_t)filp);
64995
64996 if (filp->f_op->flock) {
64997 - struct file_lock fl = {
64998 + struct file_lock flock = {
64999 .fl_owner = (fl_owner_t)filp,
65000 .fl_pid = current->tgid,
65001 .fl_file = filp,
65002 @@ -2335,9 +2335,9 @@ void locks_remove_file(struct file *filp)
65003 .fl_type = F_UNLCK,
65004 .fl_end = OFFSET_MAX,
65005 };
65006 - filp->f_op->flock(filp, F_SETLKW, &fl);
65007 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
65008 - fl.fl_ops->fl_release_private(&fl);
65009 + filp->f_op->flock(filp, F_SETLKW, &flock);
65010 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
65011 + flock.fl_ops->fl_release_private(&flock);
65012 }
65013
65014 spin_lock(&inode->i_lock);
65015 diff --git a/fs/mount.h b/fs/mount.h
65016 index d55297f..f5b28c5 100644
65017 --- a/fs/mount.h
65018 +++ b/fs/mount.h
65019 @@ -11,7 +11,7 @@ struct mnt_namespace {
65020 u64 seq; /* Sequence number to prevent loops */
65021 wait_queue_head_t poll;
65022 u64 event;
65023 -};
65024 +} __randomize_layout;
65025
65026 struct mnt_pcp {
65027 int mnt_count;
65028 @@ -57,7 +57,7 @@ struct mount {
65029 int mnt_expiry_mark; /* true if marked for expiry */
65030 int mnt_pinned;
65031 struct path mnt_ex_mountpoint;
65032 -};
65033 +} __randomize_layout;
65034
65035 #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
65036
65037 diff --git a/fs/namei.c b/fs/namei.c
65038 index 9eb787e..5f520b67 100644
65039 --- a/fs/namei.c
65040 +++ b/fs/namei.c
65041 @@ -330,17 +330,32 @@ int generic_permission(struct inode *inode, int mask)
65042 if (ret != -EACCES)
65043 return ret;
65044
65045 +#ifdef CONFIG_GRKERNSEC
65046 + /* we'll block if we have to log due to a denied capability use */
65047 + if (mask & MAY_NOT_BLOCK)
65048 + return -ECHILD;
65049 +#endif
65050 +
65051 if (S_ISDIR(inode->i_mode)) {
65052 /* DACs are overridable for directories */
65053 - if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
65054 - return 0;
65055 if (!(mask & MAY_WRITE))
65056 - if (capable_wrt_inode_uidgid(inode,
65057 - CAP_DAC_READ_SEARCH))
65058 + if (capable_wrt_inode_uidgid_nolog(inode, CAP_DAC_OVERRIDE) ||
65059 + capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
65060 return 0;
65061 + if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
65062 + return 0;
65063 return -EACCES;
65064 }
65065 /*
65066 + * Searching includes executable on directories, else just read.
65067 + */
65068 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
65069 + if (mask == MAY_READ)
65070 + if (capable_wrt_inode_uidgid_nolog(inode, CAP_DAC_OVERRIDE) ||
65071 + capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
65072 + return 0;
65073 +
65074 + /*
65075 * Read/write DACs are always overridable.
65076 * Executable DACs are overridable when there is
65077 * at least one exec bit set.
65078 @@ -349,14 +364,6 @@ int generic_permission(struct inode *inode, int mask)
65079 if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
65080 return 0;
65081
65082 - /*
65083 - * Searching includes executable on directories, else just read.
65084 - */
65085 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
65086 - if (mask == MAY_READ)
65087 - if (capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
65088 - return 0;
65089 -
65090 return -EACCES;
65091 }
65092 EXPORT_SYMBOL(generic_permission);
65093 @@ -824,7 +831,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
65094 {
65095 struct dentry *dentry = link->dentry;
65096 int error;
65097 - char *s;
65098 + const char *s;
65099
65100 BUG_ON(nd->flags & LOOKUP_RCU);
65101
65102 @@ -845,6 +852,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
65103 if (error)
65104 goto out_put_nd_path;
65105
65106 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
65107 + dentry->d_inode, dentry, nd->path.mnt)) {
65108 + error = -EACCES;
65109 + goto out_put_nd_path;
65110 + }
65111 +
65112 nd->last_type = LAST_BIND;
65113 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
65114 error = PTR_ERR(*p);
65115 @@ -1596,6 +1609,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
65116 if (res)
65117 break;
65118 res = walk_component(nd, path, LOOKUP_FOLLOW);
65119 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
65120 + res = -EACCES;
65121 put_link(nd, &link, cookie);
65122 } while (res > 0);
65123
65124 @@ -1669,7 +1684,7 @@ EXPORT_SYMBOL(full_name_hash);
65125 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
65126 {
65127 unsigned long a, b, adata, bdata, mask, hash, len;
65128 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
65129 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
65130
65131 hash = a = 0;
65132 len = -sizeof(unsigned long);
65133 @@ -1953,6 +1968,8 @@ static int path_lookupat(int dfd, const char *name,
65134 if (err)
65135 break;
65136 err = lookup_last(nd, &path);
65137 + if (!err && gr_handle_symlink_owner(&link, nd->inode))
65138 + err = -EACCES;
65139 put_link(nd, &link, cookie);
65140 }
65141 }
65142 @@ -1960,6 +1977,13 @@ static int path_lookupat(int dfd, const char *name,
65143 if (!err)
65144 err = complete_walk(nd);
65145
65146 + if (!err && !(nd->flags & LOOKUP_PARENT)) {
65147 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
65148 + path_put(&nd->path);
65149 + err = -ENOENT;
65150 + }
65151 + }
65152 +
65153 if (!err && nd->flags & LOOKUP_DIRECTORY) {
65154 if (!d_can_lookup(nd->path.dentry)) {
65155 path_put(&nd->path);
65156 @@ -1987,8 +2011,15 @@ static int filename_lookup(int dfd, struct filename *name,
65157 retval = path_lookupat(dfd, name->name,
65158 flags | LOOKUP_REVAL, nd);
65159
65160 - if (likely(!retval))
65161 + if (likely(!retval)) {
65162 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
65163 + if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
65164 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
65165 + path_put(&nd->path);
65166 + return -ENOENT;
65167 + }
65168 + }
65169 + }
65170 return retval;
65171 }
65172
65173 @@ -2570,6 +2601,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
65174 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
65175 return -EPERM;
65176
65177 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
65178 + return -EPERM;
65179 + if (gr_handle_rawio(inode))
65180 + return -EPERM;
65181 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
65182 + return -EACCES;
65183 +
65184 return 0;
65185 }
65186
65187 @@ -2801,7 +2839,7 @@ looked_up:
65188 * cleared otherwise prior to returning.
65189 */
65190 static int lookup_open(struct nameidata *nd, struct path *path,
65191 - struct file *file,
65192 + struct path *link, struct file *file,
65193 const struct open_flags *op,
65194 bool got_write, int *opened)
65195 {
65196 @@ -2836,6 +2874,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
65197 /* Negative dentry, just create the file */
65198 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
65199 umode_t mode = op->mode;
65200 +
65201 + if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
65202 + error = -EACCES;
65203 + goto out_dput;
65204 + }
65205 +
65206 + if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
65207 + error = -EACCES;
65208 + goto out_dput;
65209 + }
65210 +
65211 if (!IS_POSIXACL(dir->d_inode))
65212 mode &= ~current_umask();
65213 /*
65214 @@ -2857,6 +2906,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
65215 nd->flags & LOOKUP_EXCL);
65216 if (error)
65217 goto out_dput;
65218 + else
65219 + gr_handle_create(dentry, nd->path.mnt);
65220 }
65221 out_no_open:
65222 path->dentry = dentry;
65223 @@ -2871,7 +2922,7 @@ out_dput:
65224 /*
65225 * Handle the last step of open()
65226 */
65227 -static int do_last(struct nameidata *nd, struct path *path,
65228 +static int do_last(struct nameidata *nd, struct path *path, struct path *link,
65229 struct file *file, const struct open_flags *op,
65230 int *opened, struct filename *name)
65231 {
65232 @@ -2921,6 +2972,15 @@ static int do_last(struct nameidata *nd, struct path *path,
65233 if (error)
65234 return error;
65235
65236 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
65237 + error = -ENOENT;
65238 + goto out;
65239 + }
65240 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
65241 + error = -EACCES;
65242 + goto out;
65243 + }
65244 +
65245 audit_inode(name, dir, LOOKUP_PARENT);
65246 error = -EISDIR;
65247 /* trailing slashes? */
65248 @@ -2940,7 +3000,7 @@ retry_lookup:
65249 */
65250 }
65251 mutex_lock(&dir->d_inode->i_mutex);
65252 - error = lookup_open(nd, path, file, op, got_write, opened);
65253 + error = lookup_open(nd, path, link, file, op, got_write, opened);
65254 mutex_unlock(&dir->d_inode->i_mutex);
65255
65256 if (error <= 0) {
65257 @@ -2964,11 +3024,28 @@ retry_lookup:
65258 goto finish_open_created;
65259 }
65260
65261 + if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
65262 + error = -ENOENT;
65263 + goto exit_dput;
65264 + }
65265 + if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
65266 + error = -EACCES;
65267 + goto exit_dput;
65268 + }
65269 +
65270 /*
65271 * create/update audit record if it already exists.
65272 */
65273 - if (d_is_positive(path->dentry))
65274 + if (d_is_positive(path->dentry)) {
65275 + /* only check if O_CREAT is specified, all other checks need to go
65276 + into may_open */
65277 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
65278 + error = -EACCES;
65279 + goto exit_dput;
65280 + }
65281 +
65282 audit_inode(name, path->dentry, 0);
65283 + }
65284
65285 /*
65286 * If atomic_open() acquired write access it is dropped now due to
65287 @@ -3009,6 +3086,11 @@ finish_lookup:
65288 }
65289 }
65290 BUG_ON(inode != path->dentry->d_inode);
65291 + /* if we're resolving a symlink to another symlink */
65292 + if (link && gr_handle_symlink_owner(link, inode)) {
65293 + error = -EACCES;
65294 + goto out;
65295 + }
65296 return 1;
65297 }
65298
65299 @@ -3018,7 +3100,6 @@ finish_lookup:
65300 save_parent.dentry = nd->path.dentry;
65301 save_parent.mnt = mntget(path->mnt);
65302 nd->path.dentry = path->dentry;
65303 -
65304 }
65305 nd->inode = inode;
65306 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
65307 @@ -3028,7 +3109,18 @@ finish_open:
65308 path_put(&save_parent);
65309 return error;
65310 }
65311 +
65312 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
65313 + error = -ENOENT;
65314 + goto out;
65315 + }
65316 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
65317 + error = -EACCES;
65318 + goto out;
65319 + }
65320 +
65321 audit_inode(name, nd->path.dentry, 0);
65322 +
65323 error = -EISDIR;
65324 if ((open_flag & O_CREAT) && d_is_dir(nd->path.dentry))
65325 goto out;
65326 @@ -3191,7 +3283,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
65327 if (unlikely(error))
65328 goto out;
65329
65330 - error = do_last(nd, &path, file, op, &opened, pathname);
65331 + error = do_last(nd, &path, NULL, file, op, &opened, pathname);
65332 while (unlikely(error > 0)) { /* trailing symlink */
65333 struct path link = path;
65334 void *cookie;
65335 @@ -3209,7 +3301,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
65336 error = follow_link(&link, nd, &cookie);
65337 if (unlikely(error))
65338 break;
65339 - error = do_last(nd, &path, file, op, &opened, pathname);
65340 + error = do_last(nd, &path, &link, file, op, &opened, pathname);
65341 put_link(nd, &link, cookie);
65342 }
65343 out:
65344 @@ -3309,9 +3401,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
65345 goto unlock;
65346
65347 error = -EEXIST;
65348 - if (d_is_positive(dentry))
65349 + if (d_is_positive(dentry)) {
65350 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt))
65351 + error = -ENOENT;
65352 goto fail;
65353 -
65354 + }
65355 /*
65356 * Special case - lookup gave negative, but... we had foo/bar/
65357 * From the vfs_mknod() POV we just have a negative dentry -
65358 @@ -3363,6 +3457,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
65359 }
65360 EXPORT_SYMBOL(user_path_create);
65361
65362 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
65363 +{
65364 + struct filename *tmp = getname(pathname);
65365 + struct dentry *res;
65366 + if (IS_ERR(tmp))
65367 + return ERR_CAST(tmp);
65368 + res = kern_path_create(dfd, tmp->name, path, lookup_flags);
65369 + if (IS_ERR(res))
65370 + putname(tmp);
65371 + else
65372 + *to = tmp;
65373 + return res;
65374 +}
65375 +
65376 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
65377 {
65378 int error = may_create(dir, dentry);
65379 @@ -3426,6 +3534,17 @@ retry:
65380
65381 if (!IS_POSIXACL(path.dentry->d_inode))
65382 mode &= ~current_umask();
65383 +
65384 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
65385 + error = -EPERM;
65386 + goto out;
65387 + }
65388 +
65389 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
65390 + error = -EACCES;
65391 + goto out;
65392 + }
65393 +
65394 error = security_path_mknod(&path, dentry, mode, dev);
65395 if (error)
65396 goto out;
65397 @@ -3442,6 +3561,8 @@ retry:
65398 break;
65399 }
65400 out:
65401 + if (!error)
65402 + gr_handle_create(dentry, path.mnt);
65403 done_path_create(&path, dentry);
65404 if (retry_estale(error, lookup_flags)) {
65405 lookup_flags |= LOOKUP_REVAL;
65406 @@ -3495,9 +3616,16 @@ retry:
65407
65408 if (!IS_POSIXACL(path.dentry->d_inode))
65409 mode &= ~current_umask();
65410 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
65411 + error = -EACCES;
65412 + goto out;
65413 + }
65414 error = security_path_mkdir(&path, dentry, mode);
65415 if (!error)
65416 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
65417 + if (!error)
65418 + gr_handle_create(dentry, path.mnt);
65419 +out:
65420 done_path_create(&path, dentry);
65421 if (retry_estale(error, lookup_flags)) {
65422 lookup_flags |= LOOKUP_REVAL;
65423 @@ -3580,6 +3708,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
65424 struct filename *name;
65425 struct dentry *dentry;
65426 struct nameidata nd;
65427 + ino_t saved_ino = 0;
65428 + dev_t saved_dev = 0;
65429 unsigned int lookup_flags = 0;
65430 retry:
65431 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
65432 @@ -3612,10 +3742,21 @@ retry:
65433 error = -ENOENT;
65434 goto exit3;
65435 }
65436 +
65437 + saved_ino = dentry->d_inode->i_ino;
65438 + saved_dev = gr_get_dev_from_dentry(dentry);
65439 +
65440 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
65441 + error = -EACCES;
65442 + goto exit3;
65443 + }
65444 +
65445 error = security_path_rmdir(&nd.path, dentry);
65446 if (error)
65447 goto exit3;
65448 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
65449 + if (!error && (saved_dev || saved_ino))
65450 + gr_handle_delete(saved_ino, saved_dev);
65451 exit3:
65452 dput(dentry);
65453 exit2:
65454 @@ -3706,6 +3847,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
65455 struct nameidata nd;
65456 struct inode *inode = NULL;
65457 struct inode *delegated_inode = NULL;
65458 + ino_t saved_ino = 0;
65459 + dev_t saved_dev = 0;
65460 unsigned int lookup_flags = 0;
65461 retry:
65462 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
65463 @@ -3732,10 +3875,22 @@ retry_deleg:
65464 if (d_is_negative(dentry))
65465 goto slashes;
65466 ihold(inode);
65467 +
65468 + if (inode->i_nlink <= 1) {
65469 + saved_ino = inode->i_ino;
65470 + saved_dev = gr_get_dev_from_dentry(dentry);
65471 + }
65472 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
65473 + error = -EACCES;
65474 + goto exit2;
65475 + }
65476 +
65477 error = security_path_unlink(&nd.path, dentry);
65478 if (error)
65479 goto exit2;
65480 error = vfs_unlink(nd.path.dentry->d_inode, dentry, &delegated_inode);
65481 + if (!error && (saved_ino || saved_dev))
65482 + gr_handle_delete(saved_ino, saved_dev);
65483 exit2:
65484 dput(dentry);
65485 }
65486 @@ -3824,9 +3979,17 @@ retry:
65487 if (IS_ERR(dentry))
65488 goto out_putname;
65489
65490 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
65491 + error = -EACCES;
65492 + goto out;
65493 + }
65494 +
65495 error = security_path_symlink(&path, dentry, from->name);
65496 if (!error)
65497 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
65498 + if (!error)
65499 + gr_handle_create(dentry, path.mnt);
65500 +out:
65501 done_path_create(&path, dentry);
65502 if (retry_estale(error, lookup_flags)) {
65503 lookup_flags |= LOOKUP_REVAL;
65504 @@ -3930,6 +4093,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
65505 struct dentry *new_dentry;
65506 struct path old_path, new_path;
65507 struct inode *delegated_inode = NULL;
65508 + struct filename *to = NULL;
65509 int how = 0;
65510 int error;
65511
65512 @@ -3953,7 +4117,7 @@ retry:
65513 if (error)
65514 return error;
65515
65516 - new_dentry = user_path_create(newdfd, newname, &new_path,
65517 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
65518 (how & LOOKUP_REVAL));
65519 error = PTR_ERR(new_dentry);
65520 if (IS_ERR(new_dentry))
65521 @@ -3965,11 +4129,28 @@ retry:
65522 error = may_linkat(&old_path);
65523 if (unlikely(error))
65524 goto out_dput;
65525 +
65526 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
65527 + old_path.dentry->d_inode,
65528 + old_path.dentry->d_inode->i_mode, to)) {
65529 + error = -EACCES;
65530 + goto out_dput;
65531 + }
65532 +
65533 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
65534 + old_path.dentry, old_path.mnt, to)) {
65535 + error = -EACCES;
65536 + goto out_dput;
65537 + }
65538 +
65539 error = security_path_link(old_path.dentry, &new_path, new_dentry);
65540 if (error)
65541 goto out_dput;
65542 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry, &delegated_inode);
65543 + if (!error)
65544 + gr_handle_create(new_dentry, new_path.mnt);
65545 out_dput:
65546 + putname(to);
65547 done_path_create(&new_path, new_dentry);
65548 if (delegated_inode) {
65549 error = break_deleg_wait(&delegated_inode);
65550 @@ -4279,6 +4460,12 @@ retry_deleg:
65551 if (new_dentry == trap)
65552 goto exit5;
65553
65554 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
65555 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
65556 + to, flags);
65557 + if (error)
65558 + goto exit5;
65559 +
65560 error = security_path_rename(&oldnd.path, old_dentry,
65561 &newnd.path, new_dentry, flags);
65562 if (error)
65563 @@ -4286,6 +4473,9 @@ retry_deleg:
65564 error = vfs_rename(old_dir->d_inode, old_dentry,
65565 new_dir->d_inode, new_dentry,
65566 &delegated_inode, flags);
65567 + if (!error)
65568 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
65569 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0, flags);
65570 exit5:
65571 dput(new_dentry);
65572 exit4:
65573 @@ -4328,14 +4518,24 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
65574
65575 int readlink_copy(char __user *buffer, int buflen, const char *link)
65576 {
65577 + char tmpbuf[64];
65578 + const char *newlink;
65579 int len = PTR_ERR(link);
65580 +
65581 if (IS_ERR(link))
65582 goto out;
65583
65584 len = strlen(link);
65585 if (len > (unsigned) buflen)
65586 len = buflen;
65587 - if (copy_to_user(buffer, link, len))
65588 +
65589 + if (len < sizeof(tmpbuf)) {
65590 + memcpy(tmpbuf, link, len);
65591 + newlink = tmpbuf;
65592 + } else
65593 + newlink = link;
65594 +
65595 + if (copy_to_user(buffer, newlink, len))
65596 len = -EFAULT;
65597 out:
65598 return len;
65599 diff --git a/fs/namespace.c b/fs/namespace.c
65600 index 182bc41..72e3cf1 100644
65601 --- a/fs/namespace.c
65602 +++ b/fs/namespace.c
65603 @@ -1348,6 +1348,9 @@ static int do_umount(struct mount *mnt, int flags)
65604 if (!(sb->s_flags & MS_RDONLY))
65605 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
65606 up_write(&sb->s_umount);
65607 +
65608 + gr_log_remount(mnt->mnt_devname, retval);
65609 +
65610 return retval;
65611 }
65612
65613 @@ -1370,6 +1373,9 @@ static int do_umount(struct mount *mnt, int flags)
65614 }
65615 unlock_mount_hash();
65616 namespace_unlock();
65617 +
65618 + gr_log_unmount(mnt->mnt_devname, retval);
65619 +
65620 return retval;
65621 }
65622
65623 @@ -1389,7 +1395,7 @@ static inline bool may_mount(void)
65624 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
65625 */
65626
65627 -SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
65628 +SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
65629 {
65630 struct path path;
65631 struct mount *mnt;
65632 @@ -1431,7 +1437,7 @@ out:
65633 /*
65634 * The 2.0 compatible umount. No flags.
65635 */
65636 -SYSCALL_DEFINE1(oldumount, char __user *, name)
65637 +SYSCALL_DEFINE1(oldumount, const char __user *, name)
65638 {
65639 return sys_umount(name, 0);
65640 }
65641 @@ -2440,6 +2446,16 @@ long do_mount(const char *dev_name, const char *dir_name,
65642 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
65643 MS_STRICTATIME);
65644
65645 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
65646 + retval = -EPERM;
65647 + goto dput_out;
65648 + }
65649 +
65650 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
65651 + retval = -EPERM;
65652 + goto dput_out;
65653 + }
65654 +
65655 if (flags & MS_REMOUNT)
65656 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
65657 data_page);
65658 @@ -2454,6 +2470,9 @@ long do_mount(const char *dev_name, const char *dir_name,
65659 dev_name, data_page);
65660 dput_out:
65661 path_put(&path);
65662 +
65663 + gr_log_mount(dev_name, dir_name, retval);
65664 +
65665 return retval;
65666 }
65667
65668 @@ -2471,7 +2490,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
65669 * number incrementing at 10Ghz will take 12,427 years to wrap which
65670 * is effectively never, so we can ignore the possibility.
65671 */
65672 -static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
65673 +static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
65674
65675 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
65676 {
65677 @@ -2486,7 +2505,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
65678 kfree(new_ns);
65679 return ERR_PTR(ret);
65680 }
65681 - new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
65682 + new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
65683 atomic_set(&new_ns->count, 1);
65684 new_ns->root = NULL;
65685 INIT_LIST_HEAD(&new_ns->list);
65686 @@ -2496,7 +2515,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
65687 return new_ns;
65688 }
65689
65690 -struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
65691 +__latent_entropy struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
65692 struct user_namespace *user_ns, struct fs_struct *new_fs)
65693 {
65694 struct mnt_namespace *new_ns;
65695 @@ -2617,8 +2636,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
65696 }
65697 EXPORT_SYMBOL(mount_subtree);
65698
65699 -SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
65700 - char __user *, type, unsigned long, flags, void __user *, data)
65701 +SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
65702 + const char __user *, type, unsigned long, flags, void __user *, data)
65703 {
65704 int ret;
65705 char *kernel_type;
65706 @@ -2731,6 +2750,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
65707 if (error)
65708 goto out2;
65709
65710 + if (gr_handle_chroot_pivot()) {
65711 + error = -EPERM;
65712 + goto out2;
65713 + }
65714 +
65715 get_fs_root(current->fs, &root);
65716 old_mp = lock_mount(&old);
65717 error = PTR_ERR(old_mp);
65718 @@ -2999,7 +3023,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
65719 !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
65720 return -EPERM;
65721
65722 - if (fs->users != 1)
65723 + if (atomic_read(&fs->users) != 1)
65724 return -EINVAL;
65725
65726 get_mnt_ns(mnt_ns);
65727 diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
65728 index f4ccfe6..a5cf064 100644
65729 --- a/fs/nfs/callback_xdr.c
65730 +++ b/fs/nfs/callback_xdr.c
65731 @@ -51,7 +51,7 @@ struct callback_op {
65732 callback_decode_arg_t decode_args;
65733 callback_encode_res_t encode_res;
65734 long res_maxsize;
65735 -};
65736 +} __do_const;
65737
65738 static struct callback_op callback_ops[];
65739
65740 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
65741 index 9927913..faffc5c 100644
65742 --- a/fs/nfs/inode.c
65743 +++ b/fs/nfs/inode.c
65744 @@ -1219,16 +1219,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
65745 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
65746 }
65747
65748 -static atomic_long_t nfs_attr_generation_counter;
65749 +static atomic_long_unchecked_t nfs_attr_generation_counter;
65750
65751 static unsigned long nfs_read_attr_generation_counter(void)
65752 {
65753 - return atomic_long_read(&nfs_attr_generation_counter);
65754 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
65755 }
65756
65757 unsigned long nfs_inc_attr_generation_counter(void)
65758 {
65759 - return atomic_long_inc_return(&nfs_attr_generation_counter);
65760 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
65761 }
65762
65763 void nfs_fattr_init(struct nfs_fattr *fattr)
65764 diff --git a/fs/nfs/nfs3acl.c b/fs/nfs/nfs3acl.c
65765 index 8f854dd..d0fec26 100644
65766 --- a/fs/nfs/nfs3acl.c
65767 +++ b/fs/nfs/nfs3acl.c
65768 @@ -256,7 +256,7 @@ nfs3_list_one_acl(struct inode *inode, int type, const char *name, void *data,
65769 char *p = data + *result;
65770
65771 acl = get_acl(inode, type);
65772 - if (!acl)
65773 + if (IS_ERR_OR_NULL(acl))
65774 return 0;
65775
65776 posix_acl_release(acl);
65777 diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
65778 index 8f029db..3688b84 100644
65779 --- a/fs/nfsd/nfs4proc.c
65780 +++ b/fs/nfsd/nfs4proc.c
65781 @@ -1157,7 +1157,7 @@ struct nfsd4_operation {
65782 nfsd4op_rsize op_rsize_bop;
65783 stateid_getter op_get_currentstateid;
65784 stateid_setter op_set_currentstateid;
65785 -};
65786 +} __do_const;
65787
65788 static struct nfsd4_operation nfsd4_ops[];
65789
65790 diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
65791 index 944275c..6fc40a7 100644
65792 --- a/fs/nfsd/nfs4xdr.c
65793 +++ b/fs/nfsd/nfs4xdr.c
65794 @@ -1539,7 +1539,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
65795
65796 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
65797
65798 -static nfsd4_dec nfsd4_dec_ops[] = {
65799 +static const nfsd4_dec nfsd4_dec_ops[] = {
65800 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
65801 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
65802 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
65803 diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
65804 index 6040da8..4348565 100644
65805 --- a/fs/nfsd/nfscache.c
65806 +++ b/fs/nfsd/nfscache.c
65807 @@ -518,17 +518,20 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
65808 {
65809 struct svc_cacherep *rp = rqstp->rq_cacherep;
65810 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
65811 - int len;
65812 + long len;
65813 size_t bufsize = 0;
65814
65815 if (!rp)
65816 return;
65817
65818 - len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
65819 - len >>= 2;
65820 + if (statp) {
65821 + len = (char*)statp - (char*)resv->iov_base;
65822 + len = resv->iov_len - len;
65823 + len >>= 2;
65824 + }
65825
65826 /* Don't cache excessive amounts of data and XDR failures */
65827 - if (!statp || len > (256 >> 2)) {
65828 + if (!statp || len > (256 >> 2) || len < 0) {
65829 nfsd_reply_cache_free(rp);
65830 return;
65831 }
65832 @@ -536,7 +539,7 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
65833 switch (cachetype) {
65834 case RC_REPLSTAT:
65835 if (len != 1)
65836 - printk("nfsd: RC_REPLSTAT/reply len %d!\n",len);
65837 + printk("nfsd: RC_REPLSTAT/reply len %ld!\n",len);
65838 rp->c_replstat = *statp;
65839 break;
65840 case RC_REPLBUFF:
65841 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
65842 index 140c496..e9cbf14 100644
65843 --- a/fs/nfsd/vfs.c
65844 +++ b/fs/nfsd/vfs.c
65845 @@ -855,7 +855,7 @@ int nfsd_readv(struct file *file, loff_t offset, struct kvec *vec, int vlen,
65846
65847 oldfs = get_fs();
65848 set_fs(KERNEL_DS);
65849 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
65850 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
65851 set_fs(oldfs);
65852 return nfsd_finish_read(file, count, host_err);
65853 }
65854 @@ -943,7 +943,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
65855
65856 /* Write the data. */
65857 oldfs = get_fs(); set_fs(KERNEL_DS);
65858 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
65859 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
65860 set_fs(oldfs);
65861 if (host_err < 0)
65862 goto out_nfserr;
65863 @@ -1482,7 +1482,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
65864 */
65865
65866 oldfs = get_fs(); set_fs(KERNEL_DS);
65867 - host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
65868 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
65869 set_fs(oldfs);
65870
65871 if (host_err < 0)
65872 diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
65873 index 52ccd34..7a6b202 100644
65874 --- a/fs/nls/nls_base.c
65875 +++ b/fs/nls/nls_base.c
65876 @@ -234,21 +234,25 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
65877
65878 int __register_nls(struct nls_table *nls, struct module *owner)
65879 {
65880 - struct nls_table ** tmp = &tables;
65881 + struct nls_table *tmp = tables;
65882
65883 if (nls->next)
65884 return -EBUSY;
65885
65886 - nls->owner = owner;
65887 + pax_open_kernel();
65888 + *(void **)&nls->owner = owner;
65889 + pax_close_kernel();
65890 spin_lock(&nls_lock);
65891 - while (*tmp) {
65892 - if (nls == *tmp) {
65893 + while (tmp) {
65894 + if (nls == tmp) {
65895 spin_unlock(&nls_lock);
65896 return -EBUSY;
65897 }
65898 - tmp = &(*tmp)->next;
65899 + tmp = tmp->next;
65900 }
65901 - nls->next = tables;
65902 + pax_open_kernel();
65903 + *(struct nls_table **)&nls->next = tables;
65904 + pax_close_kernel();
65905 tables = nls;
65906 spin_unlock(&nls_lock);
65907 return 0;
65908 @@ -257,12 +261,14 @@ EXPORT_SYMBOL(__register_nls);
65909
65910 int unregister_nls(struct nls_table * nls)
65911 {
65912 - struct nls_table ** tmp = &tables;
65913 + struct nls_table * const * tmp = &tables;
65914
65915 spin_lock(&nls_lock);
65916 while (*tmp) {
65917 if (nls == *tmp) {
65918 - *tmp = nls->next;
65919 + pax_open_kernel();
65920 + *(struct nls_table **)tmp = nls->next;
65921 + pax_close_kernel();
65922 spin_unlock(&nls_lock);
65923 return 0;
65924 }
65925 @@ -272,7 +278,7 @@ int unregister_nls(struct nls_table * nls)
65926 return -EINVAL;
65927 }
65928
65929 -static struct nls_table *find_nls(char *charset)
65930 +static struct nls_table *find_nls(const char *charset)
65931 {
65932 struct nls_table *nls;
65933 spin_lock(&nls_lock);
65934 @@ -288,7 +294,7 @@ static struct nls_table *find_nls(char *charset)
65935 return nls;
65936 }
65937
65938 -struct nls_table *load_nls(char *charset)
65939 +struct nls_table *load_nls(const char *charset)
65940 {
65941 return try_then_request_module(find_nls(charset), "nls_%s", charset);
65942 }
65943 diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
65944 index 162b3f1..6076a7c 100644
65945 --- a/fs/nls/nls_euc-jp.c
65946 +++ b/fs/nls/nls_euc-jp.c
65947 @@ -560,8 +560,10 @@ static int __init init_nls_euc_jp(void)
65948 p_nls = load_nls("cp932");
65949
65950 if (p_nls) {
65951 - table.charset2upper = p_nls->charset2upper;
65952 - table.charset2lower = p_nls->charset2lower;
65953 + pax_open_kernel();
65954 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
65955 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
65956 + pax_close_kernel();
65957 return register_nls(&table);
65958 }
65959
65960 diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
65961 index a80a741..7b96e1b 100644
65962 --- a/fs/nls/nls_koi8-ru.c
65963 +++ b/fs/nls/nls_koi8-ru.c
65964 @@ -62,8 +62,10 @@ static int __init init_nls_koi8_ru(void)
65965 p_nls = load_nls("koi8-u");
65966
65967 if (p_nls) {
65968 - table.charset2upper = p_nls->charset2upper;
65969 - table.charset2lower = p_nls->charset2lower;
65970 + pax_open_kernel();
65971 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
65972 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
65973 + pax_close_kernel();
65974 return register_nls(&table);
65975 }
65976
65977 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
65978 index 3fdc8a3..5888623 100644
65979 --- a/fs/notify/fanotify/fanotify_user.c
65980 +++ b/fs/notify/fanotify/fanotify_user.c
65981 @@ -216,8 +216,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
65982
65983 fd = fanotify_event_metadata.fd;
65984 ret = -EFAULT;
65985 - if (copy_to_user(buf, &fanotify_event_metadata,
65986 - fanotify_event_metadata.event_len))
65987 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
65988 + copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
65989 goto out_close_fd;
65990
65991 #ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
65992 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
65993 index 1e58402..bb2d6f4 100644
65994 --- a/fs/notify/notification.c
65995 +++ b/fs/notify/notification.c
65996 @@ -48,7 +48,7 @@
65997 #include <linux/fsnotify_backend.h>
65998 #include "fsnotify.h"
65999
66000 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
66001 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
66002
66003 /**
66004 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
66005 @@ -56,7 +56,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
66006 */
66007 u32 fsnotify_get_cookie(void)
66008 {
66009 - return atomic_inc_return(&fsnotify_sync_cookie);
66010 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
66011 }
66012 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
66013
66014 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
66015 index 9e38daf..5727cae 100644
66016 --- a/fs/ntfs/dir.c
66017 +++ b/fs/ntfs/dir.c
66018 @@ -1310,7 +1310,7 @@ find_next_index_buffer:
66019 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
66020 ~(s64)(ndir->itype.index.block_size - 1)));
66021 /* Bounds checks. */
66022 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
66023 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
66024 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
66025 "inode 0x%lx or driver bug.", vdir->i_ino);
66026 goto err_out;
66027 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
66028 index 5c9e2c8..96e4ba0 100644
66029 --- a/fs/ntfs/file.c
66030 +++ b/fs/ntfs/file.c
66031 @@ -1282,7 +1282,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
66032 char *addr;
66033 size_t total = 0;
66034 unsigned len;
66035 - int left;
66036 + unsigned left;
66037
66038 do {
66039 len = PAGE_CACHE_SIZE - ofs;
66040 diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
66041 index 6c3296e..c0b99f0 100644
66042 --- a/fs/ntfs/super.c
66043 +++ b/fs/ntfs/super.c
66044 @@ -688,7 +688,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
66045 if (!silent)
66046 ntfs_error(sb, "Primary boot sector is invalid.");
66047 } else if (!silent)
66048 - ntfs_error(sb, read_err_str, "primary");
66049 + ntfs_error(sb, read_err_str, "%s", "primary");
66050 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
66051 if (bh_primary)
66052 brelse(bh_primary);
66053 @@ -704,7 +704,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
66054 goto hotfix_primary_boot_sector;
66055 brelse(bh_backup);
66056 } else if (!silent)
66057 - ntfs_error(sb, read_err_str, "backup");
66058 + ntfs_error(sb, read_err_str, "%s", "backup");
66059 /* Try to read NT3.51- backup boot sector. */
66060 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
66061 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
66062 @@ -715,7 +715,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
66063 "sector.");
66064 brelse(bh_backup);
66065 } else if (!silent)
66066 - ntfs_error(sb, read_err_str, "backup");
66067 + ntfs_error(sb, read_err_str, "%s", "backup");
66068 /* We failed. Cleanup and return. */
66069 if (bh_primary)
66070 brelse(bh_primary);
66071 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
66072 index 0440134..d52c93a 100644
66073 --- a/fs/ocfs2/localalloc.c
66074 +++ b/fs/ocfs2/localalloc.c
66075 @@ -1320,7 +1320,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
66076 goto bail;
66077 }
66078
66079 - atomic_inc(&osb->alloc_stats.moves);
66080 + atomic_inc_unchecked(&osb->alloc_stats.moves);
66081
66082 bail:
66083 if (handle)
66084 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
66085 index bbec539..7b266d5 100644
66086 --- a/fs/ocfs2/ocfs2.h
66087 +++ b/fs/ocfs2/ocfs2.h
66088 @@ -236,11 +236,11 @@ enum ocfs2_vol_state
66089
66090 struct ocfs2_alloc_stats
66091 {
66092 - atomic_t moves;
66093 - atomic_t local_data;
66094 - atomic_t bitmap_data;
66095 - atomic_t bg_allocs;
66096 - atomic_t bg_extends;
66097 + atomic_unchecked_t moves;
66098 + atomic_unchecked_t local_data;
66099 + atomic_unchecked_t bitmap_data;
66100 + atomic_unchecked_t bg_allocs;
66101 + atomic_unchecked_t bg_extends;
66102 };
66103
66104 enum ocfs2_local_alloc_state
66105 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
66106 index 0cb889a..6a26b24 100644
66107 --- a/fs/ocfs2/suballoc.c
66108 +++ b/fs/ocfs2/suballoc.c
66109 @@ -867,7 +867,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
66110 mlog_errno(status);
66111 goto bail;
66112 }
66113 - atomic_inc(&osb->alloc_stats.bg_extends);
66114 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
66115
66116 /* You should never ask for this much metadata */
66117 BUG_ON(bits_wanted >
66118 @@ -2014,7 +2014,7 @@ int ocfs2_claim_metadata(handle_t *handle,
66119 mlog_errno(status);
66120 goto bail;
66121 }
66122 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
66123 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
66124
66125 *suballoc_loc = res.sr_bg_blkno;
66126 *suballoc_bit_start = res.sr_bit_offset;
66127 @@ -2180,7 +2180,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
66128 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
66129 res->sr_bits);
66130
66131 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
66132 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
66133
66134 BUG_ON(res->sr_bits != 1);
66135
66136 @@ -2222,7 +2222,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
66137 mlog_errno(status);
66138 goto bail;
66139 }
66140 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
66141 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
66142
66143 BUG_ON(res.sr_bits != 1);
66144
66145 @@ -2326,7 +2326,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
66146 cluster_start,
66147 num_clusters);
66148 if (!status)
66149 - atomic_inc(&osb->alloc_stats.local_data);
66150 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
66151 } else {
66152 if (min_clusters > (osb->bitmap_cpg - 1)) {
66153 /* The only paths asking for contiguousness
66154 @@ -2352,7 +2352,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
66155 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
66156 res.sr_bg_blkno,
66157 res.sr_bit_offset);
66158 - atomic_inc(&osb->alloc_stats.bitmap_data);
66159 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
66160 *num_clusters = res.sr_bits;
66161 }
66162 }
66163 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
66164 index ddb662b..f701c83 100644
66165 --- a/fs/ocfs2/super.c
66166 +++ b/fs/ocfs2/super.c
66167 @@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
66168 "%10s => GlobalAllocs: %d LocalAllocs: %d "
66169 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
66170 "Stats",
66171 - atomic_read(&osb->alloc_stats.bitmap_data),
66172 - atomic_read(&osb->alloc_stats.local_data),
66173 - atomic_read(&osb->alloc_stats.bg_allocs),
66174 - atomic_read(&osb->alloc_stats.moves),
66175 - atomic_read(&osb->alloc_stats.bg_extends));
66176 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
66177 + atomic_read_unchecked(&osb->alloc_stats.local_data),
66178 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
66179 + atomic_read_unchecked(&osb->alloc_stats.moves),
66180 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
66181
66182 out += snprintf(buf + out, len - out,
66183 "%10s => State: %u Descriptor: %llu Size: %u bits "
66184 @@ -2100,11 +2100,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
66185
66186 mutex_init(&osb->system_file_mutex);
66187
66188 - atomic_set(&osb->alloc_stats.moves, 0);
66189 - atomic_set(&osb->alloc_stats.local_data, 0);
66190 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
66191 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
66192 - atomic_set(&osb->alloc_stats.bg_extends, 0);
66193 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
66194 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
66195 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
66196 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
66197 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
66198
66199 /* Copy the blockcheck stats from the superblock probe */
66200 osb->osb_ecc_stats = *stats;
66201 diff --git a/fs/open.c b/fs/open.c
66202 index d6fd3ac..6ccf474 100644
66203 --- a/fs/open.c
66204 +++ b/fs/open.c
66205 @@ -32,6 +32,8 @@
66206 #include <linux/dnotify.h>
66207 #include <linux/compat.h>
66208
66209 +#define CREATE_TRACE_POINTS
66210 +#include <trace/events/fs.h>
66211 #include "internal.h"
66212
66213 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
66214 @@ -103,6 +105,8 @@ long vfs_truncate(struct path *path, loff_t length)
66215 error = locks_verify_truncate(inode, NULL, length);
66216 if (!error)
66217 error = security_path_truncate(path);
66218 + if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
66219 + error = -EACCES;
66220 if (!error)
66221 error = do_truncate(path->dentry, length, 0, NULL);
66222
66223 @@ -187,6 +191,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
66224 error = locks_verify_truncate(inode, f.file, length);
66225 if (!error)
66226 error = security_path_truncate(&f.file->f_path);
66227 + if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
66228 + error = -EACCES;
66229 if (!error)
66230 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
66231 sb_end_write(inode->i_sb);
66232 @@ -380,6 +386,9 @@ retry:
66233 if (__mnt_is_readonly(path.mnt))
66234 res = -EROFS;
66235
66236 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
66237 + res = -EACCES;
66238 +
66239 out_path_release:
66240 path_put(&path);
66241 if (retry_estale(res, lookup_flags)) {
66242 @@ -411,6 +420,8 @@ retry:
66243 if (error)
66244 goto dput_and_out;
66245
66246 + gr_log_chdir(path.dentry, path.mnt);
66247 +
66248 set_fs_pwd(current->fs, &path);
66249
66250 dput_and_out:
66251 @@ -440,6 +451,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
66252 goto out_putf;
66253
66254 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
66255 +
66256 + if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
66257 + error = -EPERM;
66258 +
66259 + if (!error)
66260 + gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
66261 +
66262 if (!error)
66263 set_fs_pwd(current->fs, &f.file->f_path);
66264 out_putf:
66265 @@ -469,7 +487,13 @@ retry:
66266 if (error)
66267 goto dput_and_out;
66268
66269 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
66270 + goto dput_and_out;
66271 +
66272 set_fs_root(current->fs, &path);
66273 +
66274 + gr_handle_chroot_chdir(&path);
66275 +
66276 error = 0;
66277 dput_and_out:
66278 path_put(&path);
66279 @@ -493,6 +517,16 @@ static int chmod_common(struct path *path, umode_t mode)
66280 return error;
66281 retry_deleg:
66282 mutex_lock(&inode->i_mutex);
66283 +
66284 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
66285 + error = -EACCES;
66286 + goto out_unlock;
66287 + }
66288 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
66289 + error = -EACCES;
66290 + goto out_unlock;
66291 + }
66292 +
66293 error = security_path_chmod(path, mode);
66294 if (error)
66295 goto out_unlock;
66296 @@ -558,6 +592,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
66297 uid = make_kuid(current_user_ns(), user);
66298 gid = make_kgid(current_user_ns(), group);
66299
66300 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
66301 + return -EACCES;
66302 +
66303 newattrs.ia_valid = ATTR_CTIME;
66304 if (user != (uid_t) -1) {
66305 if (!uid_valid(uid))
66306 @@ -983,6 +1020,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
66307 } else {
66308 fsnotify_open(f);
66309 fd_install(fd, f);
66310 + trace_do_sys_open(tmp->name, flags, mode);
66311 }
66312 }
66313 putname(tmp);
66314 diff --git a/fs/pipe.c b/fs/pipe.c
66315 index 21981e5..3d5f55c 100644
66316 --- a/fs/pipe.c
66317 +++ b/fs/pipe.c
66318 @@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
66319
66320 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
66321 {
66322 - if (pipe->files)
66323 + if (atomic_read(&pipe->files))
66324 mutex_lock_nested(&pipe->mutex, subclass);
66325 }
66326
66327 @@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
66328
66329 void pipe_unlock(struct pipe_inode_info *pipe)
66330 {
66331 - if (pipe->files)
66332 + if (atomic_read(&pipe->files))
66333 mutex_unlock(&pipe->mutex);
66334 }
66335 EXPORT_SYMBOL(pipe_unlock);
66336 @@ -292,9 +292,9 @@ pipe_read(struct kiocb *iocb, struct iov_iter *to)
66337 }
66338 if (bufs) /* More to do? */
66339 continue;
66340 - if (!pipe->writers)
66341 + if (!atomic_read(&pipe->writers))
66342 break;
66343 - if (!pipe->waiting_writers) {
66344 + if (!atomic_read(&pipe->waiting_writers)) {
66345 /* syscall merging: Usually we must not sleep
66346 * if O_NONBLOCK is set, or if we got some data.
66347 * But if a writer sleeps in kernel space, then
66348 @@ -351,7 +351,7 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
66349
66350 __pipe_lock(pipe);
66351
66352 - if (!pipe->readers) {
66353 + if (!atomic_read(&pipe->readers)) {
66354 send_sig(SIGPIPE, current, 0);
66355 ret = -EPIPE;
66356 goto out;
66357 @@ -387,7 +387,7 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
66358 for (;;) {
66359 int bufs;
66360
66361 - if (!pipe->readers) {
66362 + if (!atomic_read(&pipe->readers)) {
66363 send_sig(SIGPIPE, current, 0);
66364 if (!ret)
66365 ret = -EPIPE;
66366 @@ -455,9 +455,9 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
66367 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
66368 do_wakeup = 0;
66369 }
66370 - pipe->waiting_writers++;
66371 + atomic_inc(&pipe->waiting_writers);
66372 pipe_wait(pipe);
66373 - pipe->waiting_writers--;
66374 + atomic_dec(&pipe->waiting_writers);
66375 }
66376 out:
66377 __pipe_unlock(pipe);
66378 @@ -512,7 +512,7 @@ pipe_poll(struct file *filp, poll_table *wait)
66379 mask = 0;
66380 if (filp->f_mode & FMODE_READ) {
66381 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
66382 - if (!pipe->writers && filp->f_version != pipe->w_counter)
66383 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
66384 mask |= POLLHUP;
66385 }
66386
66387 @@ -522,7 +522,7 @@ pipe_poll(struct file *filp, poll_table *wait)
66388 * Most Unices do not set POLLERR for FIFOs but on Linux they
66389 * behave exactly like pipes for poll().
66390 */
66391 - if (!pipe->readers)
66392 + if (!atomic_read(&pipe->readers))
66393 mask |= POLLERR;
66394 }
66395
66396 @@ -534,7 +534,7 @@ static void put_pipe_info(struct inode *inode, struct pipe_inode_info *pipe)
66397 int kill = 0;
66398
66399 spin_lock(&inode->i_lock);
66400 - if (!--pipe->files) {
66401 + if (atomic_dec_and_test(&pipe->files)) {
66402 inode->i_pipe = NULL;
66403 kill = 1;
66404 }
66405 @@ -551,11 +551,11 @@ pipe_release(struct inode *inode, struct file *file)
66406
66407 __pipe_lock(pipe);
66408 if (file->f_mode & FMODE_READ)
66409 - pipe->readers--;
66410 + atomic_dec(&pipe->readers);
66411 if (file->f_mode & FMODE_WRITE)
66412 - pipe->writers--;
66413 + atomic_dec(&pipe->writers);
66414
66415 - if (pipe->readers || pipe->writers) {
66416 + if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
66417 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
66418 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
66419 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
66420 @@ -620,7 +620,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
66421 kfree(pipe);
66422 }
66423
66424 -static struct vfsmount *pipe_mnt __read_mostly;
66425 +struct vfsmount *pipe_mnt __read_mostly;
66426
66427 /*
66428 * pipefs_dname() is called from d_path().
66429 @@ -650,8 +650,9 @@ static struct inode * get_pipe_inode(void)
66430 goto fail_iput;
66431
66432 inode->i_pipe = pipe;
66433 - pipe->files = 2;
66434 - pipe->readers = pipe->writers = 1;
66435 + atomic_set(&pipe->files, 2);
66436 + atomic_set(&pipe->readers, 1);
66437 + atomic_set(&pipe->writers, 1);
66438 inode->i_fop = &pipefifo_fops;
66439
66440 /*
66441 @@ -830,17 +831,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
66442 spin_lock(&inode->i_lock);
66443 if (inode->i_pipe) {
66444 pipe = inode->i_pipe;
66445 - pipe->files++;
66446 + atomic_inc(&pipe->files);
66447 spin_unlock(&inode->i_lock);
66448 } else {
66449 spin_unlock(&inode->i_lock);
66450 pipe = alloc_pipe_info();
66451 if (!pipe)
66452 return -ENOMEM;
66453 - pipe->files = 1;
66454 + atomic_set(&pipe->files, 1);
66455 spin_lock(&inode->i_lock);
66456 if (unlikely(inode->i_pipe)) {
66457 - inode->i_pipe->files++;
66458 + atomic_inc(&inode->i_pipe->files);
66459 spin_unlock(&inode->i_lock);
66460 free_pipe_info(pipe);
66461 pipe = inode->i_pipe;
66462 @@ -865,10 +866,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
66463 * opened, even when there is no process writing the FIFO.
66464 */
66465 pipe->r_counter++;
66466 - if (pipe->readers++ == 0)
66467 + if (atomic_inc_return(&pipe->readers) == 1)
66468 wake_up_partner(pipe);
66469
66470 - if (!is_pipe && !pipe->writers) {
66471 + if (!is_pipe && !atomic_read(&pipe->writers)) {
66472 if ((filp->f_flags & O_NONBLOCK)) {
66473 /* suppress POLLHUP until we have
66474 * seen a writer */
66475 @@ -887,14 +888,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
66476 * errno=ENXIO when there is no process reading the FIFO.
66477 */
66478 ret = -ENXIO;
66479 - if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
66480 + if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
66481 goto err;
66482
66483 pipe->w_counter++;
66484 - if (!pipe->writers++)
66485 + if (atomic_inc_return(&pipe->writers) == 1)
66486 wake_up_partner(pipe);
66487
66488 - if (!is_pipe && !pipe->readers) {
66489 + if (!is_pipe && !atomic_read(&pipe->readers)) {
66490 if (wait_for_partner(pipe, &pipe->r_counter))
66491 goto err_wr;
66492 }
66493 @@ -908,11 +909,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
66494 * the process can at least talk to itself.
66495 */
66496
66497 - pipe->readers++;
66498 - pipe->writers++;
66499 + atomic_inc(&pipe->readers);
66500 + atomic_inc(&pipe->writers);
66501 pipe->r_counter++;
66502 pipe->w_counter++;
66503 - if (pipe->readers == 1 || pipe->writers == 1)
66504 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
66505 wake_up_partner(pipe);
66506 break;
66507
66508 @@ -926,13 +927,13 @@ static int fifo_open(struct inode *inode, struct file *filp)
66509 return 0;
66510
66511 err_rd:
66512 - if (!--pipe->readers)
66513 + if (atomic_dec_and_test(&pipe->readers))
66514 wake_up_interruptible(&pipe->wait);
66515 ret = -ERESTARTSYS;
66516 goto err;
66517
66518 err_wr:
66519 - if (!--pipe->writers)
66520 + if (atomic_dec_and_test(&pipe->writers))
66521 wake_up_interruptible(&pipe->wait);
66522 ret = -ERESTARTSYS;
66523 goto err;
66524 diff --git a/fs/posix_acl.c b/fs/posix_acl.c
66525 index 0855f77..6787d50 100644
66526 --- a/fs/posix_acl.c
66527 +++ b/fs/posix_acl.c
66528 @@ -20,6 +20,7 @@
66529 #include <linux/xattr.h>
66530 #include <linux/export.h>
66531 #include <linux/user_namespace.h>
66532 +#include <linux/grsecurity.h>
66533
66534 struct posix_acl **acl_by_type(struct inode *inode, int type)
66535 {
66536 @@ -277,7 +278,7 @@ posix_acl_equiv_mode(const struct posix_acl *acl, umode_t *mode_p)
66537 }
66538 }
66539 if (mode_p)
66540 - *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
66541 + *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
66542 return not_equiv;
66543 }
66544 EXPORT_SYMBOL(posix_acl_equiv_mode);
66545 @@ -427,7 +428,7 @@ static int posix_acl_create_masq(struct posix_acl *acl, umode_t *mode_p)
66546 mode &= (group_obj->e_perm << 3) | ~S_IRWXG;
66547 }
66548
66549 - *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
66550 + *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
66551 return not_equiv;
66552 }
66553
66554 @@ -485,6 +486,8 @@ __posix_acl_create(struct posix_acl **acl, gfp_t gfp, umode_t *mode_p)
66555 struct posix_acl *clone = posix_acl_clone(*acl, gfp);
66556 int err = -ENOMEM;
66557 if (clone) {
66558 + *mode_p &= ~gr_acl_umask();
66559 +
66560 err = posix_acl_create_masq(clone, mode_p);
66561 if (err < 0) {
66562 posix_acl_release(clone);
66563 @@ -659,11 +662,12 @@ struct posix_acl *
66564 posix_acl_from_xattr(struct user_namespace *user_ns,
66565 const void *value, size_t size)
66566 {
66567 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
66568 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
66569 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
66570 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
66571 int count;
66572 struct posix_acl *acl;
66573 struct posix_acl_entry *acl_e;
66574 + umode_t umask = gr_acl_umask();
66575
66576 if (!value)
66577 return NULL;
66578 @@ -689,12 +693,18 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
66579
66580 switch(acl_e->e_tag) {
66581 case ACL_USER_OBJ:
66582 + acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
66583 + break;
66584 case ACL_GROUP_OBJ:
66585 case ACL_MASK:
66586 + acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
66587 + break;
66588 case ACL_OTHER:
66589 + acl_e->e_perm &= ~(umask & S_IRWXO);
66590 break;
66591
66592 case ACL_USER:
66593 + acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
66594 acl_e->e_uid =
66595 make_kuid(user_ns,
66596 le32_to_cpu(entry->e_id));
66597 @@ -702,6 +712,7 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
66598 goto fail;
66599 break;
66600 case ACL_GROUP:
66601 + acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
66602 acl_e->e_gid =
66603 make_kgid(user_ns,
66604 le32_to_cpu(entry->e_id));
66605 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
66606 index 2183fcf..3c32a98 100644
66607 --- a/fs/proc/Kconfig
66608 +++ b/fs/proc/Kconfig
66609 @@ -30,7 +30,7 @@ config PROC_FS
66610
66611 config PROC_KCORE
66612 bool "/proc/kcore support" if !ARM
66613 - depends on PROC_FS && MMU
66614 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
66615 help
66616 Provides a virtual ELF core file of the live kernel. This can
66617 be read with gdb and other ELF tools. No modifications can be
66618 @@ -38,8 +38,8 @@ config PROC_KCORE
66619
66620 config PROC_VMCORE
66621 bool "/proc/vmcore support"
66622 - depends on PROC_FS && CRASH_DUMP
66623 - default y
66624 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
66625 + default n
66626 help
66627 Exports the dump image of crashed kernel in ELF format.
66628
66629 @@ -63,8 +63,8 @@ config PROC_SYSCTL
66630 limited in memory.
66631
66632 config PROC_PAGE_MONITOR
66633 - default y
66634 - depends on PROC_FS && MMU
66635 + default n
66636 + depends on PROC_FS && MMU && !GRKERNSEC
66637 bool "Enable /proc page monitoring" if EXPERT
66638 help
66639 Various /proc files exist to monitor process memory utilization:
66640 diff --git a/fs/proc/array.c b/fs/proc/array.c
66641 index 64db2bc..a8185d6 100644
66642 --- a/fs/proc/array.c
66643 +++ b/fs/proc/array.c
66644 @@ -60,6 +60,7 @@
66645 #include <linux/tty.h>
66646 #include <linux/string.h>
66647 #include <linux/mman.h>
66648 +#include <linux/grsecurity.h>
66649 #include <linux/proc_fs.h>
66650 #include <linux/ioport.h>
66651 #include <linux/uaccess.h>
66652 @@ -356,6 +357,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
66653 seq_putc(m, '\n');
66654 }
66655
66656 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
66657 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
66658 +{
66659 + if (p->mm)
66660 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
66661 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
66662 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
66663 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
66664 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
66665 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
66666 + else
66667 + seq_printf(m, "PaX:\t-----\n");
66668 +}
66669 +#endif
66670 +
66671 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
66672 struct pid *pid, struct task_struct *task)
66673 {
66674 @@ -374,9 +390,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
66675 task_cpus_allowed(m, task);
66676 cpuset_task_status_allowed(m, task);
66677 task_context_switch_counts(m, task);
66678 +
66679 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
66680 + task_pax(m, task);
66681 +#endif
66682 +
66683 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
66684 + task_grsec_rbac(m, task);
66685 +#endif
66686 +
66687 return 0;
66688 }
66689
66690 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66691 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
66692 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
66693 + _mm->pax_flags & MF_PAX_SEGMEXEC))
66694 +#endif
66695 +
66696 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
66697 struct pid *pid, struct task_struct *task, int whole)
66698 {
66699 @@ -398,6 +429,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
66700 char tcomm[sizeof(task->comm)];
66701 unsigned long flags;
66702
66703 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66704 + if (current->exec_id != m->exec_id) {
66705 + gr_log_badprocpid("stat");
66706 + return 0;
66707 + }
66708 +#endif
66709 +
66710 state = *get_task_state(task);
66711 vsize = eip = esp = 0;
66712 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
66713 @@ -468,6 +506,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
66714 gtime = task_gtime(task);
66715 }
66716
66717 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66718 + if (PAX_RAND_FLAGS(mm)) {
66719 + eip = 0;
66720 + esp = 0;
66721 + wchan = 0;
66722 + }
66723 +#endif
66724 +#ifdef CONFIG_GRKERNSEC_HIDESYM
66725 + wchan = 0;
66726 + eip =0;
66727 + esp =0;
66728 +#endif
66729 +
66730 /* scale priority and nice values from timeslices to -20..20 */
66731 /* to make it look like a "normal" Unix priority/nice value */
66732 priority = task_prio(task);
66733 @@ -504,9 +555,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
66734 seq_put_decimal_ull(m, ' ', vsize);
66735 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
66736 seq_put_decimal_ull(m, ' ', rsslim);
66737 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66738 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
66739 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
66740 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
66741 +#else
66742 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
66743 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
66744 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
66745 +#endif
66746 seq_put_decimal_ull(m, ' ', esp);
66747 seq_put_decimal_ull(m, ' ', eip);
66748 /* The signal information here is obsolete.
66749 @@ -528,7 +585,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
66750 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
66751 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
66752
66753 - if (mm && permitted) {
66754 + if (mm && permitted
66755 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66756 + && !PAX_RAND_FLAGS(mm)
66757 +#endif
66758 + ) {
66759 seq_put_decimal_ull(m, ' ', mm->start_data);
66760 seq_put_decimal_ull(m, ' ', mm->end_data);
66761 seq_put_decimal_ull(m, ' ', mm->start_brk);
66762 @@ -566,8 +627,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
66763 struct pid *pid, struct task_struct *task)
66764 {
66765 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
66766 - struct mm_struct *mm = get_task_mm(task);
66767 + struct mm_struct *mm;
66768
66769 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66770 + if (current->exec_id != m->exec_id) {
66771 + gr_log_badprocpid("statm");
66772 + return 0;
66773 + }
66774 +#endif
66775 + mm = get_task_mm(task);
66776 if (mm) {
66777 size = task_statm(mm, &shared, &text, &data, &resident);
66778 mmput(mm);
66779 @@ -590,6 +658,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
66780 return 0;
66781 }
66782
66783 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
66784 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
66785 +{
66786 + return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
66787 +}
66788 +#endif
66789 +
66790 #ifdef CONFIG_CHECKPOINT_RESTORE
66791 static struct pid *
66792 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
66793 diff --git a/fs/proc/base.c b/fs/proc/base.c
66794 index 2d696b0..b9da447 100644
66795 --- a/fs/proc/base.c
66796 +++ b/fs/proc/base.c
66797 @@ -113,6 +113,14 @@ struct pid_entry {
66798 union proc_op op;
66799 };
66800
66801 +struct getdents_callback {
66802 + struct linux_dirent __user * current_dir;
66803 + struct linux_dirent __user * previous;
66804 + struct file * file;
66805 + int count;
66806 + int error;
66807 +};
66808 +
66809 #define NOD(NAME, MODE, IOP, FOP, OP) { \
66810 .name = (NAME), \
66811 .len = sizeof(NAME) - 1, \
66812 @@ -205,12 +213,28 @@ static int proc_pid_cmdline(struct task_struct *task, char *buffer)
66813 return get_cmdline(task, buffer, PAGE_SIZE);
66814 }
66815
66816 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66817 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
66818 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
66819 + _mm->pax_flags & MF_PAX_SEGMEXEC))
66820 +#endif
66821 +
66822 static int proc_pid_auxv(struct task_struct *task, char *buffer)
66823 {
66824 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
66825 int res = PTR_ERR(mm);
66826 if (mm && !IS_ERR(mm)) {
66827 unsigned int nwords = 0;
66828 +
66829 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66830 + /* allow if we're currently ptracing this task */
66831 + if (PAX_RAND_FLAGS(mm) &&
66832 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
66833 + mmput(mm);
66834 + return 0;
66835 + }
66836 +#endif
66837 +
66838 do {
66839 nwords += 2;
66840 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
66841 @@ -224,7 +248,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
66842 }
66843
66844
66845 -#ifdef CONFIG_KALLSYMS
66846 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66847 /*
66848 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
66849 * Returns the resolved symbol. If that fails, simply return the address.
66850 @@ -263,7 +287,7 @@ static void unlock_trace(struct task_struct *task)
66851 mutex_unlock(&task->signal->cred_guard_mutex);
66852 }
66853
66854 -#ifdef CONFIG_STACKTRACE
66855 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66856
66857 #define MAX_STACK_TRACE_DEPTH 64
66858
66859 @@ -486,7 +510,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
66860 return count;
66861 }
66862
66863 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
66864 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
66865 static int proc_pid_syscall(struct task_struct *task, char *buffer)
66866 {
66867 long nr;
66868 @@ -515,7 +539,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
66869 /************************************************************************/
66870
66871 /* permission checks */
66872 -static int proc_fd_access_allowed(struct inode *inode)
66873 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
66874 {
66875 struct task_struct *task;
66876 int allowed = 0;
66877 @@ -525,7 +549,10 @@ static int proc_fd_access_allowed(struct inode *inode)
66878 */
66879 task = get_proc_task(inode);
66880 if (task) {
66881 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
66882 + if (log)
66883 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
66884 + else
66885 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
66886 put_task_struct(task);
66887 }
66888 return allowed;
66889 @@ -556,10 +583,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
66890 struct task_struct *task,
66891 int hide_pid_min)
66892 {
66893 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
66894 + return false;
66895 +
66896 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66897 + rcu_read_lock();
66898 + {
66899 + const struct cred *tmpcred = current_cred();
66900 + const struct cred *cred = __task_cred(task);
66901 +
66902 + if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
66903 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66904 + || in_group_p(grsec_proc_gid)
66905 +#endif
66906 + ) {
66907 + rcu_read_unlock();
66908 + return true;
66909 + }
66910 + }
66911 + rcu_read_unlock();
66912 +
66913 + if (!pid->hide_pid)
66914 + return false;
66915 +#endif
66916 +
66917 if (pid->hide_pid < hide_pid_min)
66918 return true;
66919 if (in_group_p(pid->pid_gid))
66920 return true;
66921 +
66922 return ptrace_may_access(task, PTRACE_MODE_READ);
66923 }
66924
66925 @@ -577,7 +629,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
66926 put_task_struct(task);
66927
66928 if (!has_perms) {
66929 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66930 + {
66931 +#else
66932 if (pid->hide_pid == 2) {
66933 +#endif
66934 /*
66935 * Let's make getdents(), stat(), and open()
66936 * consistent with each other. If a process
66937 @@ -675,6 +731,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
66938 if (!task)
66939 return -ESRCH;
66940
66941 + if (gr_acl_handle_procpidmem(task)) {
66942 + put_task_struct(task);
66943 + return -EPERM;
66944 + }
66945 +
66946 mm = mm_access(task, mode);
66947 put_task_struct(task);
66948
66949 @@ -690,6 +751,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
66950
66951 file->private_data = mm;
66952
66953 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66954 + file->f_version = current->exec_id;
66955 +#endif
66956 +
66957 return 0;
66958 }
66959
66960 @@ -711,6 +776,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
66961 ssize_t copied;
66962 char *page;
66963
66964 +#ifdef CONFIG_GRKERNSEC
66965 + if (write)
66966 + return -EPERM;
66967 +#endif
66968 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66969 + if (file->f_version != current->exec_id) {
66970 + gr_log_badprocpid("mem");
66971 + return 0;
66972 + }
66973 +#endif
66974 +
66975 if (!mm)
66976 return 0;
66977
66978 @@ -723,7 +799,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
66979 goto free;
66980
66981 while (count > 0) {
66982 - int this_len = min_t(int, count, PAGE_SIZE);
66983 + ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
66984
66985 if (write && copy_from_user(page, buf, this_len)) {
66986 copied = -EFAULT;
66987 @@ -815,6 +891,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
66988 if (!mm)
66989 return 0;
66990
66991 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66992 + if (file->f_version != current->exec_id) {
66993 + gr_log_badprocpid("environ");
66994 + return 0;
66995 + }
66996 +#endif
66997 +
66998 page = (char *)__get_free_page(GFP_TEMPORARY);
66999 if (!page)
67000 return -ENOMEM;
67001 @@ -824,7 +907,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
67002 goto free;
67003 while (count > 0) {
67004 size_t this_len, max_len;
67005 - int retval;
67006 + ssize_t retval;
67007
67008 if (src >= (mm->env_end - mm->env_start))
67009 break;
67010 @@ -1438,7 +1521,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
67011 int error = -EACCES;
67012
67013 /* Are we allowed to snoop on the tasks file descriptors? */
67014 - if (!proc_fd_access_allowed(inode))
67015 + if (!proc_fd_access_allowed(inode, 0))
67016 goto out;
67017
67018 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
67019 @@ -1482,8 +1565,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
67020 struct path path;
67021
67022 /* Are we allowed to snoop on the tasks file descriptors? */
67023 - if (!proc_fd_access_allowed(inode))
67024 - goto out;
67025 + /* logging this is needed for learning on chromium to work properly,
67026 + but we don't want to flood the logs from 'ps' which does a readlink
67027 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
67028 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
67029 + */
67030 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
67031 + if (!proc_fd_access_allowed(inode,0))
67032 + goto out;
67033 + } else {
67034 + if (!proc_fd_access_allowed(inode,1))
67035 + goto out;
67036 + }
67037
67038 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
67039 if (error)
67040 @@ -1533,7 +1626,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
67041 rcu_read_lock();
67042 cred = __task_cred(task);
67043 inode->i_uid = cred->euid;
67044 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
67045 + inode->i_gid = grsec_proc_gid;
67046 +#else
67047 inode->i_gid = cred->egid;
67048 +#endif
67049 rcu_read_unlock();
67050 }
67051 security_task_to_inode(task, inode);
67052 @@ -1569,10 +1666,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
67053 return -ENOENT;
67054 }
67055 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
67056 +#ifdef CONFIG_GRKERNSEC_PROC_USER
67057 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
67058 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67059 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
67060 +#endif
67061 task_dumpable(task)) {
67062 cred = __task_cred(task);
67063 stat->uid = cred->euid;
67064 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
67065 + stat->gid = grsec_proc_gid;
67066 +#else
67067 stat->gid = cred->egid;
67068 +#endif
67069 }
67070 }
67071 rcu_read_unlock();
67072 @@ -1610,11 +1716,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
67073
67074 if (task) {
67075 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
67076 +#ifdef CONFIG_GRKERNSEC_PROC_USER
67077 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
67078 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67079 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
67080 +#endif
67081 task_dumpable(task)) {
67082 rcu_read_lock();
67083 cred = __task_cred(task);
67084 inode->i_uid = cred->euid;
67085 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
67086 + inode->i_gid = grsec_proc_gid;
67087 +#else
67088 inode->i_gid = cred->egid;
67089 +#endif
67090 rcu_read_unlock();
67091 } else {
67092 inode->i_uid = GLOBAL_ROOT_UID;
67093 @@ -2149,6 +2264,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
67094 if (!task)
67095 goto out_no_task;
67096
67097 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
67098 + goto out;
67099 +
67100 /*
67101 * Yes, it does not scale. And it should not. Don't add
67102 * new entries into /proc/<tgid>/ without very good reasons.
67103 @@ -2179,6 +2297,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
67104 if (!task)
67105 return -ENOENT;
67106
67107 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
67108 + goto out;
67109 +
67110 if (!dir_emit_dots(file, ctx))
67111 goto out;
67112
67113 @@ -2568,7 +2689,7 @@ static const struct pid_entry tgid_base_stuff[] = {
67114 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
67115 #endif
67116 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
67117 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
67118 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
67119 INF("syscall", S_IRUSR, proc_pid_syscall),
67120 #endif
67121 INF("cmdline", S_IRUGO, proc_pid_cmdline),
67122 @@ -2593,10 +2714,10 @@ static const struct pid_entry tgid_base_stuff[] = {
67123 #ifdef CONFIG_SECURITY
67124 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
67125 #endif
67126 -#ifdef CONFIG_KALLSYMS
67127 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
67128 INF("wchan", S_IRUGO, proc_pid_wchan),
67129 #endif
67130 -#ifdef CONFIG_STACKTRACE
67131 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
67132 ONE("stack", S_IRUSR, proc_pid_stack),
67133 #endif
67134 #ifdef CONFIG_SCHEDSTATS
67135 @@ -2630,6 +2751,9 @@ static const struct pid_entry tgid_base_stuff[] = {
67136 #ifdef CONFIG_HARDWALL
67137 INF("hardwall", S_IRUGO, proc_pid_hardwall),
67138 #endif
67139 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
67140 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
67141 +#endif
67142 #ifdef CONFIG_USER_NS
67143 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
67144 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
67145 @@ -2760,7 +2884,14 @@ static int proc_pid_instantiate(struct inode *dir,
67146 if (!inode)
67147 goto out;
67148
67149 +#ifdef CONFIG_GRKERNSEC_PROC_USER
67150 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
67151 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67152 + inode->i_gid = grsec_proc_gid;
67153 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
67154 +#else
67155 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
67156 +#endif
67157 inode->i_op = &proc_tgid_base_inode_operations;
67158 inode->i_fop = &proc_tgid_base_operations;
67159 inode->i_flags|=S_IMMUTABLE;
67160 @@ -2798,7 +2929,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
67161 if (!task)
67162 goto out;
67163
67164 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
67165 + goto out_put_task;
67166 +
67167 result = proc_pid_instantiate(dir, dentry, task, NULL);
67168 +out_put_task:
67169 put_task_struct(task);
67170 out:
67171 return ERR_PTR(result);
67172 @@ -2904,7 +3039,7 @@ static const struct pid_entry tid_base_stuff[] = {
67173 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
67174 #endif
67175 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
67176 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
67177 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
67178 INF("syscall", S_IRUSR, proc_pid_syscall),
67179 #endif
67180 INF("cmdline", S_IRUGO, proc_pid_cmdline),
67181 @@ -2931,10 +3066,10 @@ static const struct pid_entry tid_base_stuff[] = {
67182 #ifdef CONFIG_SECURITY
67183 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
67184 #endif
67185 -#ifdef CONFIG_KALLSYMS
67186 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
67187 INF("wchan", S_IRUGO, proc_pid_wchan),
67188 #endif
67189 -#ifdef CONFIG_STACKTRACE
67190 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
67191 ONE("stack", S_IRUSR, proc_pid_stack),
67192 #endif
67193 #ifdef CONFIG_SCHEDSTATS
67194 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
67195 index cbd82df..c0407d2 100644
67196 --- a/fs/proc/cmdline.c
67197 +++ b/fs/proc/cmdline.c
67198 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
67199
67200 static int __init proc_cmdline_init(void)
67201 {
67202 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
67203 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
67204 +#else
67205 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
67206 +#endif
67207 return 0;
67208 }
67209 fs_initcall(proc_cmdline_init);
67210 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
67211 index 50493ed..248166b 100644
67212 --- a/fs/proc/devices.c
67213 +++ b/fs/proc/devices.c
67214 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
67215
67216 static int __init proc_devices_init(void)
67217 {
67218 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
67219 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
67220 +#else
67221 proc_create("devices", 0, NULL, &proc_devinfo_operations);
67222 +#endif
67223 return 0;
67224 }
67225 fs_initcall(proc_devices_init);
67226 diff --git a/fs/proc/fd.c b/fs/proc/fd.c
67227 index 0788d09..9cc1385 100644
67228 --- a/fs/proc/fd.c
67229 +++ b/fs/proc/fd.c
67230 @@ -26,7 +26,8 @@ static int seq_show(struct seq_file *m, void *v)
67231 if (!task)
67232 return -ENOENT;
67233
67234 - files = get_files_struct(task);
67235 + if (!gr_acl_handle_procpidmem(task))
67236 + files = get_files_struct(task);
67237 put_task_struct(task);
67238
67239 if (files) {
67240 @@ -285,11 +286,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
67241 */
67242 int proc_fd_permission(struct inode *inode, int mask)
67243 {
67244 + struct task_struct *task;
67245 int rv = generic_permission(inode, mask);
67246 - if (rv == 0)
67247 - return 0;
67248 +
67249 if (task_tgid(current) == proc_pid(inode))
67250 rv = 0;
67251 +
67252 + task = get_proc_task(inode);
67253 + if (task == NULL)
67254 + return rv;
67255 +
67256 + if (gr_acl_handle_procpidmem(task))
67257 + rv = -EACCES;
67258 +
67259 + put_task_struct(task);
67260 +
67261 return rv;
67262 }
67263
67264 diff --git a/fs/proc/generic.c b/fs/proc/generic.c
67265 index b7f268e..3bea6b7 100644
67266 --- a/fs/proc/generic.c
67267 +++ b/fs/proc/generic.c
67268 @@ -23,6 +23,7 @@
67269 #include <linux/bitops.h>
67270 #include <linux/spinlock.h>
67271 #include <linux/completion.h>
67272 +#include <linux/grsecurity.h>
67273 #include <asm/uaccess.h>
67274
67275 #include "internal.h"
67276 @@ -207,6 +208,15 @@ struct dentry *proc_lookup(struct inode *dir, struct dentry *dentry,
67277 return proc_lookup_de(PDE(dir), dir, dentry);
67278 }
67279
67280 +struct dentry *proc_lookup_restrict(struct inode *dir, struct dentry *dentry,
67281 + unsigned int flags)
67282 +{
67283 + if (gr_proc_is_restricted())
67284 + return ERR_PTR(-EACCES);
67285 +
67286 + return proc_lookup_de(PDE(dir), dir, dentry);
67287 +}
67288 +
67289 /*
67290 * This returns non-zero if at EOF, so that the /proc
67291 * root directory can use this and check if it should
67292 @@ -264,6 +274,16 @@ int proc_readdir(struct file *file, struct dir_context *ctx)
67293 return proc_readdir_de(PDE(inode), file, ctx);
67294 }
67295
67296 +int proc_readdir_restrict(struct file *file, struct dir_context *ctx)
67297 +{
67298 + struct inode *inode = file_inode(file);
67299 +
67300 + if (gr_proc_is_restricted())
67301 + return -EACCES;
67302 +
67303 + return proc_readdir_de(PDE(inode), file, ctx);
67304 +}
67305 +
67306 /*
67307 * These are the generic /proc directory operations. They
67308 * use the in-memory "struct proc_dir_entry" tree to parse
67309 @@ -275,6 +295,12 @@ static const struct file_operations proc_dir_operations = {
67310 .iterate = proc_readdir,
67311 };
67312
67313 +static const struct file_operations proc_dir_restricted_operations = {
67314 + .llseek = generic_file_llseek,
67315 + .read = generic_read_dir,
67316 + .iterate = proc_readdir_restrict,
67317 +};
67318 +
67319 /*
67320 * proc directories can do almost nothing..
67321 */
67322 @@ -284,6 +310,12 @@ static const struct inode_operations proc_dir_inode_operations = {
67323 .setattr = proc_notify_change,
67324 };
67325
67326 +static const struct inode_operations proc_dir_restricted_inode_operations = {
67327 + .lookup = proc_lookup_restrict,
67328 + .getattr = proc_getattr,
67329 + .setattr = proc_notify_change,
67330 +};
67331 +
67332 static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp)
67333 {
67334 struct proc_dir_entry *tmp;
67335 @@ -294,8 +326,13 @@ static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp
67336 return ret;
67337
67338 if (S_ISDIR(dp->mode)) {
67339 - dp->proc_fops = &proc_dir_operations;
67340 - dp->proc_iops = &proc_dir_inode_operations;
67341 + if (dp->restricted) {
67342 + dp->proc_fops = &proc_dir_restricted_operations;
67343 + dp->proc_iops = &proc_dir_restricted_inode_operations;
67344 + } else {
67345 + dp->proc_fops = &proc_dir_operations;
67346 + dp->proc_iops = &proc_dir_inode_operations;
67347 + }
67348 dir->nlink++;
67349 } else if (S_ISLNK(dp->mode)) {
67350 dp->proc_iops = &proc_link_inode_operations;
67351 @@ -407,6 +444,27 @@ struct proc_dir_entry *proc_mkdir_data(const char *name, umode_t mode,
67352 }
67353 EXPORT_SYMBOL_GPL(proc_mkdir_data);
67354
67355 +struct proc_dir_entry *proc_mkdir_data_restrict(const char *name, umode_t mode,
67356 + struct proc_dir_entry *parent, void *data)
67357 +{
67358 + struct proc_dir_entry *ent;
67359 +
67360 + if (mode == 0)
67361 + mode = S_IRUGO | S_IXUGO;
67362 +
67363 + ent = __proc_create(&parent, name, S_IFDIR | mode, 2);
67364 + if (ent) {
67365 + ent->data = data;
67366 + ent->restricted = 1;
67367 + if (proc_register(parent, ent) < 0) {
67368 + kfree(ent);
67369 + ent = NULL;
67370 + }
67371 + }
67372 + return ent;
67373 +}
67374 +EXPORT_SYMBOL_GPL(proc_mkdir_data_restrict);
67375 +
67376 struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode,
67377 struct proc_dir_entry *parent)
67378 {
67379 @@ -421,6 +479,13 @@ struct proc_dir_entry *proc_mkdir(const char *name,
67380 }
67381 EXPORT_SYMBOL(proc_mkdir);
67382
67383 +struct proc_dir_entry *proc_mkdir_restrict(const char *name,
67384 + struct proc_dir_entry *parent)
67385 +{
67386 + return proc_mkdir_data_restrict(name, 0, parent, NULL);
67387 +}
67388 +EXPORT_SYMBOL(proc_mkdir_restrict);
67389 +
67390 struct proc_dir_entry *proc_create_data(const char *name, umode_t mode,
67391 struct proc_dir_entry *parent,
67392 const struct file_operations *proc_fops,
67393 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
67394 index 0adbc02..bee4d0b 100644
67395 --- a/fs/proc/inode.c
67396 +++ b/fs/proc/inode.c
67397 @@ -23,11 +23,17 @@
67398 #include <linux/slab.h>
67399 #include <linux/mount.h>
67400 #include <linux/magic.h>
67401 +#include <linux/grsecurity.h>
67402
67403 #include <asm/uaccess.h>
67404
67405 #include "internal.h"
67406
67407 +#ifdef CONFIG_PROC_SYSCTL
67408 +extern const struct inode_operations proc_sys_inode_operations;
67409 +extern const struct inode_operations proc_sys_dir_operations;
67410 +#endif
67411 +
67412 static void proc_evict_inode(struct inode *inode)
67413 {
67414 struct proc_dir_entry *de;
67415 @@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
67416 ns = PROC_I(inode)->ns.ns;
67417 if (ns_ops && ns)
67418 ns_ops->put(ns);
67419 +
67420 +#ifdef CONFIG_PROC_SYSCTL
67421 + if (inode->i_op == &proc_sys_inode_operations ||
67422 + inode->i_op == &proc_sys_dir_operations)
67423 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
67424 +#endif
67425 +
67426 }
67427
67428 static struct kmem_cache * proc_inode_cachep;
67429 @@ -413,7 +426,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
67430 if (de->mode) {
67431 inode->i_mode = de->mode;
67432 inode->i_uid = de->uid;
67433 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
67434 + inode->i_gid = grsec_proc_gid;
67435 +#else
67436 inode->i_gid = de->gid;
67437 +#endif
67438 }
67439 if (de->size)
67440 inode->i_size = de->size;
67441 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
67442 index 3ab6d14..b26174e 100644
67443 --- a/fs/proc/internal.h
67444 +++ b/fs/proc/internal.h
67445 @@ -46,9 +46,10 @@ struct proc_dir_entry {
67446 struct completion *pde_unload_completion;
67447 struct list_head pde_openers; /* who did ->open, but not ->release */
67448 spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
67449 + u8 restricted; /* a directory in /proc/net that should be restricted via GRKERNSEC_PROC */
67450 u8 namelen;
67451 char name[];
67452 -};
67453 +} __randomize_layout;
67454
67455 union proc_op {
67456 int (*proc_get_link)(struct dentry *, struct path *);
67457 @@ -67,7 +68,7 @@ struct proc_inode {
67458 struct ctl_table *sysctl_entry;
67459 struct proc_ns ns;
67460 struct inode vfs_inode;
67461 -};
67462 +} __randomize_layout;
67463
67464 /*
67465 * General functions
67466 @@ -155,6 +156,9 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
67467 struct pid *, struct task_struct *);
67468 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
67469 struct pid *, struct task_struct *);
67470 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
67471 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
67472 +#endif
67473
67474 /*
67475 * base.c
67476 @@ -181,9 +185,11 @@ extern bool proc_fill_cache(struct file *, struct dir_context *, const char *, i
67477 extern spinlock_t proc_subdir_lock;
67478
67479 extern struct dentry *proc_lookup(struct inode *, struct dentry *, unsigned int);
67480 +extern struct dentry *proc_lookup_restrict(struct inode *, struct dentry *, unsigned int);
67481 extern struct dentry *proc_lookup_de(struct proc_dir_entry *, struct inode *,
67482 struct dentry *);
67483 extern int proc_readdir(struct file *, struct dir_context *);
67484 +extern int proc_readdir_restrict(struct file *, struct dir_context *);
67485 extern int proc_readdir_de(struct proc_dir_entry *, struct file *, struct dir_context *);
67486
67487 static inline struct proc_dir_entry *pde_get(struct proc_dir_entry *pde)
67488 diff --git a/fs/proc/interrupts.c b/fs/proc/interrupts.c
67489 index a352d57..cb94a5c 100644
67490 --- a/fs/proc/interrupts.c
67491 +++ b/fs/proc/interrupts.c
67492 @@ -47,7 +47,11 @@ static const struct file_operations proc_interrupts_operations = {
67493
67494 static int __init proc_interrupts_init(void)
67495 {
67496 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
67497 + proc_create_grsec("interrupts", 0, NULL, &proc_interrupts_operations);
67498 +#else
67499 proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
67500 +#endif
67501 return 0;
67502 }
67503 fs_initcall(proc_interrupts_init);
67504 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
67505 index 39e6ef3..2f9cb5e 100644
67506 --- a/fs/proc/kcore.c
67507 +++ b/fs/proc/kcore.c
67508 @@ -483,9 +483,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
67509 * the addresses in the elf_phdr on our list.
67510 */
67511 start = kc_offset_to_vaddr(*fpos - elf_buflen);
67512 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
67513 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
67514 + if (tsz > buflen)
67515 tsz = buflen;
67516 -
67517 +
67518 while (buflen) {
67519 struct kcore_list *m;
67520
67521 @@ -514,20 +515,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
67522 kfree(elf_buf);
67523 } else {
67524 if (kern_addr_valid(start)) {
67525 - unsigned long n;
67526 + char *elf_buf;
67527 + mm_segment_t oldfs;
67528
67529 - n = copy_to_user(buffer, (char *)start, tsz);
67530 - /*
67531 - * We cannot distinguish between fault on source
67532 - * and fault on destination. When this happens
67533 - * we clear too and hope it will trigger the
67534 - * EFAULT again.
67535 - */
67536 - if (n) {
67537 - if (clear_user(buffer + tsz - n,
67538 - n))
67539 + elf_buf = kmalloc(tsz, GFP_KERNEL);
67540 + if (!elf_buf)
67541 + return -ENOMEM;
67542 + oldfs = get_fs();
67543 + set_fs(KERNEL_DS);
67544 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
67545 + set_fs(oldfs);
67546 + if (copy_to_user(buffer, elf_buf, tsz)) {
67547 + kfree(elf_buf);
67548 return -EFAULT;
67549 + }
67550 }
67551 + set_fs(oldfs);
67552 + kfree(elf_buf);
67553 } else {
67554 if (clear_user(buffer, tsz))
67555 return -EFAULT;
67556 @@ -547,6 +551,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
67557
67558 static int open_kcore(struct inode *inode, struct file *filp)
67559 {
67560 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
67561 + return -EPERM;
67562 +#endif
67563 if (!capable(CAP_SYS_RAWIO))
67564 return -EPERM;
67565 if (kcore_need_update)
67566 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
67567 index 7445af0..7c5113c 100644
67568 --- a/fs/proc/meminfo.c
67569 +++ b/fs/proc/meminfo.c
67570 @@ -187,7 +187,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
67571 vmi.used >> 10,
67572 vmi.largest_chunk >> 10
67573 #ifdef CONFIG_MEMORY_FAILURE
67574 - ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
67575 + ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
67576 #endif
67577 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
67578 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
67579 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
67580 index d4a3574..b421ce9 100644
67581 --- a/fs/proc/nommu.c
67582 +++ b/fs/proc/nommu.c
67583 @@ -64,7 +64,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
67584
67585 if (file) {
67586 seq_pad(m, ' ');
67587 - seq_path(m, &file->f_path, "");
67588 + seq_path(m, &file->f_path, "\n\\");
67589 }
67590
67591 seq_putc(m, '\n');
67592 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
67593 index 4677bb7..dad3045 100644
67594 --- a/fs/proc/proc_net.c
67595 +++ b/fs/proc/proc_net.c
67596 @@ -23,9 +23,27 @@
67597 #include <linux/nsproxy.h>
67598 #include <net/net_namespace.h>
67599 #include <linux/seq_file.h>
67600 +#include <linux/grsecurity.h>
67601
67602 #include "internal.h"
67603
67604 +#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
67605 +static struct seq_operations *ipv6_seq_ops_addr;
67606 +
67607 +void register_ipv6_seq_ops_addr(struct seq_operations *addr)
67608 +{
67609 + ipv6_seq_ops_addr = addr;
67610 +}
67611 +
67612 +void unregister_ipv6_seq_ops_addr(void)
67613 +{
67614 + ipv6_seq_ops_addr = NULL;
67615 +}
67616 +
67617 +EXPORT_SYMBOL_GPL(register_ipv6_seq_ops_addr);
67618 +EXPORT_SYMBOL_GPL(unregister_ipv6_seq_ops_addr);
67619 +#endif
67620 +
67621 static inline struct net *PDE_NET(struct proc_dir_entry *pde)
67622 {
67623 return pde->parent->data;
67624 @@ -36,6 +54,8 @@ static struct net *get_proc_net(const struct inode *inode)
67625 return maybe_get_net(PDE_NET(PDE(inode)));
67626 }
67627
67628 +extern const struct seq_operations dev_seq_ops;
67629 +
67630 int seq_open_net(struct inode *ino, struct file *f,
67631 const struct seq_operations *ops, int size)
67632 {
67633 @@ -44,6 +64,14 @@ int seq_open_net(struct inode *ino, struct file *f,
67634
67635 BUG_ON(size < sizeof(*p));
67636
67637 + /* only permit access to /proc/net/dev */
67638 + if (
67639 +#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
67640 + ops != ipv6_seq_ops_addr &&
67641 +#endif
67642 + ops != &dev_seq_ops && gr_proc_is_restricted())
67643 + return -EACCES;
67644 +
67645 net = get_proc_net(ino);
67646 if (net == NULL)
67647 return -ENXIO;
67648 @@ -66,6 +94,9 @@ int single_open_net(struct inode *inode, struct file *file,
67649 int err;
67650 struct net *net;
67651
67652 + if (gr_proc_is_restricted())
67653 + return -EACCES;
67654 +
67655 err = -ENXIO;
67656 net = get_proc_net(inode);
67657 if (net == NULL)
67658 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
67659 index 7129046..6914844 100644
67660 --- a/fs/proc/proc_sysctl.c
67661 +++ b/fs/proc/proc_sysctl.c
67662 @@ -11,13 +11,21 @@
67663 #include <linux/namei.h>
67664 #include <linux/mm.h>
67665 #include <linux/module.h>
67666 +#include <linux/nsproxy.h>
67667 +#ifdef CONFIG_GRKERNSEC
67668 +#include <net/net_namespace.h>
67669 +#endif
67670 #include "internal.h"
67671
67672 +extern int gr_handle_chroot_sysctl(const int op);
67673 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
67674 + const int op);
67675 +
67676 static const struct dentry_operations proc_sys_dentry_operations;
67677 static const struct file_operations proc_sys_file_operations;
67678 -static const struct inode_operations proc_sys_inode_operations;
67679 +const struct inode_operations proc_sys_inode_operations;
67680 static const struct file_operations proc_sys_dir_file_operations;
67681 -static const struct inode_operations proc_sys_dir_operations;
67682 +const struct inode_operations proc_sys_dir_operations;
67683
67684 void proc_sys_poll_notify(struct ctl_table_poll *poll)
67685 {
67686 @@ -467,6 +475,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
67687
67688 err = NULL;
67689 d_set_d_op(dentry, &proc_sys_dentry_operations);
67690 +
67691 + gr_handle_proc_create(dentry, inode);
67692 +
67693 d_add(dentry, inode);
67694
67695 out:
67696 @@ -482,6 +493,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
67697 struct inode *inode = file_inode(filp);
67698 struct ctl_table_header *head = grab_header(inode);
67699 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
67700 + int op = write ? MAY_WRITE : MAY_READ;
67701 ssize_t error;
67702 size_t res;
67703
67704 @@ -493,7 +505,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
67705 * and won't be until we finish.
67706 */
67707 error = -EPERM;
67708 - if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
67709 + if (sysctl_perm(head, table, op))
67710 goto out;
67711
67712 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
67713 @@ -501,6 +513,27 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
67714 if (!table->proc_handler)
67715 goto out;
67716
67717 +#ifdef CONFIG_GRKERNSEC
67718 + error = -EPERM;
67719 + if (gr_handle_chroot_sysctl(op))
67720 + goto out;
67721 + dget(filp->f_path.dentry);
67722 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
67723 + dput(filp->f_path.dentry);
67724 + goto out;
67725 + }
67726 + dput(filp->f_path.dentry);
67727 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
67728 + goto out;
67729 + if (write) {
67730 + if (current->nsproxy->net_ns != table->extra2) {
67731 + if (!capable(CAP_SYS_ADMIN))
67732 + goto out;
67733 + } else if (!ns_capable(current->nsproxy->net_ns->user_ns, CAP_NET_ADMIN))
67734 + goto out;
67735 + }
67736 +#endif
67737 +
67738 /* careful: calling conventions are nasty here */
67739 res = count;
67740 error = table->proc_handler(table, write, buf, &res, ppos);
67741 @@ -598,6 +631,9 @@ static bool proc_sys_fill_cache(struct file *file,
67742 return false;
67743 } else {
67744 d_set_d_op(child, &proc_sys_dentry_operations);
67745 +
67746 + gr_handle_proc_create(child, inode);
67747 +
67748 d_add(child, inode);
67749 }
67750 } else {
67751 @@ -641,6 +677,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
67752 if ((*pos)++ < ctx->pos)
67753 return true;
67754
67755 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
67756 + return 0;
67757 +
67758 if (unlikely(S_ISLNK(table->mode)))
67759 res = proc_sys_link_fill_cache(file, ctx, head, table);
67760 else
67761 @@ -734,6 +773,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
67762 if (IS_ERR(head))
67763 return PTR_ERR(head);
67764
67765 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
67766 + return -ENOENT;
67767 +
67768 generic_fillattr(inode, stat);
67769 if (table)
67770 stat->mode = (stat->mode & S_IFMT) | table->mode;
67771 @@ -756,13 +798,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
67772 .llseek = generic_file_llseek,
67773 };
67774
67775 -static const struct inode_operations proc_sys_inode_operations = {
67776 +const struct inode_operations proc_sys_inode_operations = {
67777 .permission = proc_sys_permission,
67778 .setattr = proc_sys_setattr,
67779 .getattr = proc_sys_getattr,
67780 };
67781
67782 -static const struct inode_operations proc_sys_dir_operations = {
67783 +const struct inode_operations proc_sys_dir_operations = {
67784 .lookup = proc_sys_lookup,
67785 .permission = proc_sys_permission,
67786 .setattr = proc_sys_setattr,
67787 @@ -839,7 +881,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
67788 static struct ctl_dir *new_dir(struct ctl_table_set *set,
67789 const char *name, int namelen)
67790 {
67791 - struct ctl_table *table;
67792 + ctl_table_no_const *table;
67793 struct ctl_dir *new;
67794 struct ctl_node *node;
67795 char *new_name;
67796 @@ -851,7 +893,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
67797 return NULL;
67798
67799 node = (struct ctl_node *)(new + 1);
67800 - table = (struct ctl_table *)(node + 1);
67801 + table = (ctl_table_no_const *)(node + 1);
67802 new_name = (char *)(table + 2);
67803 memcpy(new_name, name, namelen);
67804 new_name[namelen] = '\0';
67805 @@ -1020,7 +1062,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
67806 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
67807 struct ctl_table_root *link_root)
67808 {
67809 - struct ctl_table *link_table, *entry, *link;
67810 + ctl_table_no_const *link_table, *link;
67811 + struct ctl_table *entry;
67812 struct ctl_table_header *links;
67813 struct ctl_node *node;
67814 char *link_name;
67815 @@ -1043,7 +1086,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
67816 return NULL;
67817
67818 node = (struct ctl_node *)(links + 1);
67819 - link_table = (struct ctl_table *)(node + nr_entries);
67820 + link_table = (ctl_table_no_const *)(node + nr_entries);
67821 link_name = (char *)&link_table[nr_entries + 1];
67822
67823 for (link = link_table, entry = table; entry->procname; link++, entry++) {
67824 @@ -1291,8 +1334,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
67825 struct ctl_table_header ***subheader, struct ctl_table_set *set,
67826 struct ctl_table *table)
67827 {
67828 - struct ctl_table *ctl_table_arg = NULL;
67829 - struct ctl_table *entry, *files;
67830 + ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
67831 + struct ctl_table *entry;
67832 int nr_files = 0;
67833 int nr_dirs = 0;
67834 int err = -ENOMEM;
67835 @@ -1304,10 +1347,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
67836 nr_files++;
67837 }
67838
67839 - files = table;
67840 /* If there are mixed files and directories we need a new table */
67841 if (nr_dirs && nr_files) {
67842 - struct ctl_table *new;
67843 + ctl_table_no_const *new;
67844 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
67845 GFP_KERNEL);
67846 if (!files)
67847 @@ -1325,7 +1367,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
67848 /* Register everything except a directory full of subdirectories */
67849 if (nr_files || !nr_dirs) {
67850 struct ctl_table_header *header;
67851 - header = __register_sysctl_table(set, path, files);
67852 + header = __register_sysctl_table(set, path, files ? files : table);
67853 if (!header) {
67854 kfree(ctl_table_arg);
67855 goto out;
67856 diff --git a/fs/proc/root.c b/fs/proc/root.c
67857 index 5dbadec..473af2f 100644
67858 --- a/fs/proc/root.c
67859 +++ b/fs/proc/root.c
67860 @@ -185,7 +185,15 @@ void __init proc_root_init(void)
67861 proc_mkdir("openprom", NULL);
67862 #endif
67863 proc_tty_init();
67864 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
67865 +#ifdef CONFIG_GRKERNSEC_PROC_USER
67866 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
67867 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67868 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
67869 +#endif
67870 +#else
67871 proc_mkdir("bus", NULL);
67872 +#endif
67873 proc_sys_init();
67874 }
67875
67876 diff --git a/fs/proc/stat.c b/fs/proc/stat.c
67877 index bf2d03f..f058f9c 100644
67878 --- a/fs/proc/stat.c
67879 +++ b/fs/proc/stat.c
67880 @@ -11,6 +11,7 @@
67881 #include <linux/irqnr.h>
67882 #include <linux/cputime.h>
67883 #include <linux/tick.h>
67884 +#include <linux/grsecurity.h>
67885
67886 #ifndef arch_irq_stat_cpu
67887 #define arch_irq_stat_cpu(cpu) 0
67888 @@ -87,6 +88,18 @@ static int show_stat(struct seq_file *p, void *v)
67889 u64 sum_softirq = 0;
67890 unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
67891 struct timespec boottime;
67892 + int unrestricted = 1;
67893 +
67894 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
67895 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67896 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
67897 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
67898 + && !in_group_p(grsec_proc_gid)
67899 +#endif
67900 + )
67901 + unrestricted = 0;
67902 +#endif
67903 +#endif
67904
67905 user = nice = system = idle = iowait =
67906 irq = softirq = steal = 0;
67907 @@ -99,23 +112,25 @@ static int show_stat(struct seq_file *p, void *v)
67908 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
67909 system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
67910 idle += get_idle_time(i);
67911 - iowait += get_iowait_time(i);
67912 - irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
67913 - softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
67914 - steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
67915 - guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
67916 - guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
67917 - sum += kstat_cpu_irqs_sum(i);
67918 - sum += arch_irq_stat_cpu(i);
67919 + if (unrestricted) {
67920 + iowait += get_iowait_time(i);
67921 + irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
67922 + softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
67923 + steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
67924 + guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
67925 + guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
67926 + sum += kstat_cpu_irqs_sum(i);
67927 + sum += arch_irq_stat_cpu(i);
67928 + for (j = 0; j < NR_SOFTIRQS; j++) {
67929 + unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
67930
67931 - for (j = 0; j < NR_SOFTIRQS; j++) {
67932 - unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
67933 -
67934 - per_softirq_sums[j] += softirq_stat;
67935 - sum_softirq += softirq_stat;
67936 + per_softirq_sums[j] += softirq_stat;
67937 + sum_softirq += softirq_stat;
67938 + }
67939 }
67940 }
67941 - sum += arch_irq_stat();
67942 + if (unrestricted)
67943 + sum += arch_irq_stat();
67944
67945 seq_puts(p, "cpu ");
67946 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
67947 @@ -136,12 +151,14 @@ static int show_stat(struct seq_file *p, void *v)
67948 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
67949 system = kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
67950 idle = get_idle_time(i);
67951 - iowait = get_iowait_time(i);
67952 - irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
67953 - softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
67954 - steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
67955 - guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
67956 - guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
67957 + if (unrestricted) {
67958 + iowait = get_iowait_time(i);
67959 + irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
67960 + softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
67961 + steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
67962 + guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
67963 + guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
67964 + }
67965 seq_printf(p, "cpu%d", i);
67966 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
67967 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(nice));
67968 @@ -159,7 +176,7 @@ static int show_stat(struct seq_file *p, void *v)
67969
67970 /* sum again ? it could be updated? */
67971 for_each_irq_nr(j)
67972 - seq_put_decimal_ull(p, ' ', kstat_irqs(j));
67973 + seq_put_decimal_ull(p, ' ', unrestricted ? kstat_irqs(j) : 0ULL);
67974
67975 seq_printf(p,
67976 "\nctxt %llu\n"
67977 @@ -167,11 +184,11 @@ static int show_stat(struct seq_file *p, void *v)
67978 "processes %lu\n"
67979 "procs_running %lu\n"
67980 "procs_blocked %lu\n",
67981 - nr_context_switches(),
67982 + unrestricted ? nr_context_switches() : 0ULL,
67983 (unsigned long)jif,
67984 - total_forks,
67985 - nr_running(),
67986 - nr_iowait());
67987 + unrestricted ? total_forks : 0UL,
67988 + unrestricted ? nr_running() : 0UL,
67989 + unrestricted ? nr_iowait() : 0UL);
67990
67991 seq_printf(p, "softirq %llu", (unsigned long long)sum_softirq);
67992
67993 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
67994 index cfa63ee..fce112e 100644
67995 --- a/fs/proc/task_mmu.c
67996 +++ b/fs/proc/task_mmu.c
67997 @@ -13,12 +13,19 @@
67998 #include <linux/swap.h>
67999 #include <linux/swapops.h>
68000 #include <linux/mmu_notifier.h>
68001 +#include <linux/grsecurity.h>
68002
68003 #include <asm/elf.h>
68004 #include <asm/uaccess.h>
68005 #include <asm/tlbflush.h>
68006 #include "internal.h"
68007
68008 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
68009 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
68010 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
68011 + _mm->pax_flags & MF_PAX_SEGMEXEC))
68012 +#endif
68013 +
68014 void task_mem(struct seq_file *m, struct mm_struct *mm)
68015 {
68016 unsigned long data, text, lib, swap;
68017 @@ -54,8 +61,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
68018 "VmExe:\t%8lu kB\n"
68019 "VmLib:\t%8lu kB\n"
68020 "VmPTE:\t%8lu kB\n"
68021 - "VmSwap:\t%8lu kB\n",
68022 - hiwater_vm << (PAGE_SHIFT-10),
68023 + "VmSwap:\t%8lu kB\n"
68024 +
68025 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
68026 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
68027 +#endif
68028 +
68029 + ,hiwater_vm << (PAGE_SHIFT-10),
68030 total_vm << (PAGE_SHIFT-10),
68031 mm->locked_vm << (PAGE_SHIFT-10),
68032 mm->pinned_vm << (PAGE_SHIFT-10),
68033 @@ -65,7 +77,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
68034 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
68035 (PTRS_PER_PTE * sizeof(pte_t) *
68036 atomic_long_read(&mm->nr_ptes)) >> 10,
68037 - swap << (PAGE_SHIFT-10));
68038 + swap << (PAGE_SHIFT-10)
68039 +
68040 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
68041 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
68042 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
68043 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
68044 +#else
68045 + , mm->context.user_cs_base
68046 + , mm->context.user_cs_limit
68047 +#endif
68048 +#endif
68049 +
68050 + );
68051 }
68052
68053 unsigned long task_vsize(struct mm_struct *mm)
68054 @@ -271,13 +295,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
68055 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
68056 }
68057
68058 - /* We don't show the stack guard page in /proc/maps */
68059 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
68060 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
68061 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
68062 +#else
68063 start = vma->vm_start;
68064 - if (stack_guard_page_start(vma, start))
68065 - start += PAGE_SIZE;
68066 end = vma->vm_end;
68067 - if (stack_guard_page_end(vma, end))
68068 - end -= PAGE_SIZE;
68069 +#endif
68070
68071 seq_setwidth(m, 25 + sizeof(void *) * 6 - 1);
68072 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu ",
68073 @@ -287,7 +311,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
68074 flags & VM_WRITE ? 'w' : '-',
68075 flags & VM_EXEC ? 'x' : '-',
68076 flags & VM_MAYSHARE ? 's' : 'p',
68077 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
68078 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
68079 +#else
68080 pgoff,
68081 +#endif
68082 MAJOR(dev), MINOR(dev), ino);
68083
68084 /*
68085 @@ -296,7 +324,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
68086 */
68087 if (file) {
68088 seq_pad(m, ' ');
68089 - seq_path(m, &file->f_path, "\n");
68090 + seq_path(m, &file->f_path, "\n\\");
68091 goto done;
68092 }
68093
68094 @@ -328,8 +356,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
68095 * Thread stack in /proc/PID/task/TID/maps or
68096 * the main process stack.
68097 */
68098 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
68099 - vma->vm_end >= mm->start_stack)) {
68100 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
68101 + (vma->vm_start <= mm->start_stack &&
68102 + vma->vm_end >= mm->start_stack)) {
68103 name = "[stack]";
68104 } else {
68105 /* Thread stack in /proc/PID/maps */
68106 @@ -353,6 +382,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
68107 struct proc_maps_private *priv = m->private;
68108 struct task_struct *task = priv->task;
68109
68110 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
68111 + if (current->exec_id != m->exec_id) {
68112 + gr_log_badprocpid("maps");
68113 + return 0;
68114 + }
68115 +#endif
68116 +
68117 show_map_vma(m, vma, is_pid);
68118
68119 if (m->count < m->size) /* vma is copied successfully */
68120 @@ -593,12 +629,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
68121 .private = &mss,
68122 };
68123
68124 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
68125 + if (current->exec_id != m->exec_id) {
68126 + gr_log_badprocpid("smaps");
68127 + return 0;
68128 + }
68129 +#endif
68130 memset(&mss, 0, sizeof mss);
68131 - mss.vma = vma;
68132 - /* mmap_sem is held in m_start */
68133 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
68134 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
68135 -
68136 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
68137 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
68138 +#endif
68139 + mss.vma = vma;
68140 + /* mmap_sem is held in m_start */
68141 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
68142 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
68143 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
68144 + }
68145 +#endif
68146 show_map_vma(m, vma, is_pid);
68147
68148 seq_printf(m,
68149 @@ -616,7 +663,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
68150 "KernelPageSize: %8lu kB\n"
68151 "MMUPageSize: %8lu kB\n"
68152 "Locked: %8lu kB\n",
68153 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
68154 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
68155 +#else
68156 (vma->vm_end - vma->vm_start) >> 10,
68157 +#endif
68158 mss.resident >> 10,
68159 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
68160 mss.shared_clean >> 10,
68161 @@ -1398,6 +1449,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
68162 char buffer[64];
68163 int nid;
68164
68165 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
68166 + if (current->exec_id != m->exec_id) {
68167 + gr_log_badprocpid("numa_maps");
68168 + return 0;
68169 + }
68170 +#endif
68171 +
68172 if (!mm)
68173 return 0;
68174
68175 @@ -1415,11 +1473,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
68176 mpol_to_str(buffer, sizeof(buffer), pol);
68177 mpol_cond_put(pol);
68178
68179 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
68180 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
68181 +#else
68182 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
68183 +#endif
68184
68185 if (file) {
68186 seq_puts(m, " file=");
68187 - seq_path(m, &file->f_path, "\n\t= ");
68188 + seq_path(m, &file->f_path, "\n\t\\= ");
68189 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
68190 seq_puts(m, " heap");
68191 } else {
68192 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
68193 index 678455d..ebd3245 100644
68194 --- a/fs/proc/task_nommu.c
68195 +++ b/fs/proc/task_nommu.c
68196 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
68197 else
68198 bytes += kobjsize(mm);
68199
68200 - if (current->fs && current->fs->users > 1)
68201 + if (current->fs && atomic_read(&current->fs->users) > 1)
68202 sbytes += kobjsize(current->fs);
68203 else
68204 bytes += kobjsize(current->fs);
68205 @@ -161,7 +161,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
68206
68207 if (file) {
68208 seq_pad(m, ' ');
68209 - seq_path(m, &file->f_path, "");
68210 + seq_path(m, &file->f_path, "\n\\");
68211 } else if (mm) {
68212 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
68213
68214 diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
68215 index 382aa89..6b03974 100644
68216 --- a/fs/proc/vmcore.c
68217 +++ b/fs/proc/vmcore.c
68218 @@ -105,9 +105,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
68219 nr_bytes = count;
68220
68221 /* If pfn is not ram, return zeros for sparse dump files */
68222 - if (pfn_is_ram(pfn) == 0)
68223 - memset(buf, 0, nr_bytes);
68224 - else {
68225 + if (pfn_is_ram(pfn) == 0) {
68226 + if (userbuf) {
68227 + if (clear_user((char __force_user *)buf, nr_bytes))
68228 + return -EFAULT;
68229 + } else
68230 + memset(buf, 0, nr_bytes);
68231 + } else {
68232 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
68233 offset, userbuf);
68234 if (tmp < 0)
68235 @@ -170,7 +174,7 @@ int __weak remap_oldmem_pfn_range(struct vm_area_struct *vma,
68236 static int copy_to(void *target, void *src, size_t size, int userbuf)
68237 {
68238 if (userbuf) {
68239 - if (copy_to_user((char __user *) target, src, size))
68240 + if (copy_to_user((char __force_user *) target, src, size))
68241 return -EFAULT;
68242 } else {
68243 memcpy(target, src, size);
68244 @@ -233,7 +237,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
68245 if (*fpos < m->offset + m->size) {
68246 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
68247 start = m->paddr + *fpos - m->offset;
68248 - tmp = read_from_oldmem(buffer, tsz, &start, userbuf);
68249 + tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, userbuf);
68250 if (tmp < 0)
68251 return tmp;
68252 buflen -= tsz;
68253 @@ -253,7 +257,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
68254 static ssize_t read_vmcore(struct file *file, char __user *buffer,
68255 size_t buflen, loff_t *fpos)
68256 {
68257 - return __read_vmcore((__force char *) buffer, buflen, fpos, 1);
68258 + return __read_vmcore((__force_kernel char *) buffer, buflen, fpos, 1);
68259 }
68260
68261 /*
68262 diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
68263 index b00fcc9..e0c6381 100644
68264 --- a/fs/qnx6/qnx6.h
68265 +++ b/fs/qnx6/qnx6.h
68266 @@ -74,7 +74,7 @@ enum {
68267 BYTESEX_BE,
68268 };
68269
68270 -static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
68271 +static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
68272 {
68273 if (sbi->s_bytesex == BYTESEX_LE)
68274 return le64_to_cpu((__force __le64)n);
68275 @@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
68276 return (__force __fs64)cpu_to_be64(n);
68277 }
68278
68279 -static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
68280 +static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
68281 {
68282 if (sbi->s_bytesex == BYTESEX_LE)
68283 return le32_to_cpu((__force __le32)n);
68284 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
68285 index 72d2917..c917c12 100644
68286 --- a/fs/quota/netlink.c
68287 +++ b/fs/quota/netlink.c
68288 @@ -45,7 +45,7 @@ static struct genl_family quota_genl_family = {
68289 void quota_send_warning(struct kqid qid, dev_t dev,
68290 const char warntype)
68291 {
68292 - static atomic_t seq;
68293 + static atomic_unchecked_t seq;
68294 struct sk_buff *skb;
68295 void *msg_head;
68296 int ret;
68297 @@ -61,7 +61,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
68298 "VFS: Not enough memory to send quota warning.\n");
68299 return;
68300 }
68301 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
68302 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
68303 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
68304 if (!msg_head) {
68305 printk(KERN_ERR
68306 diff --git a/fs/read_write.c b/fs/read_write.c
68307 index 009d854..16ce214 100644
68308 --- a/fs/read_write.c
68309 +++ b/fs/read_write.c
68310 @@ -495,7 +495,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
68311
68312 old_fs = get_fs();
68313 set_fs(get_ds());
68314 - p = (__force const char __user *)buf;
68315 + p = (const char __force_user *)buf;
68316 if (count > MAX_RW_COUNT)
68317 count = MAX_RW_COUNT;
68318 if (file->f_op->write)
68319 diff --git a/fs/readdir.c b/fs/readdir.c
68320 index 33fd922..e0d6094 100644
68321 --- a/fs/readdir.c
68322 +++ b/fs/readdir.c
68323 @@ -18,6 +18,7 @@
68324 #include <linux/security.h>
68325 #include <linux/syscalls.h>
68326 #include <linux/unistd.h>
68327 +#include <linux/namei.h>
68328
68329 #include <asm/uaccess.h>
68330
68331 @@ -71,6 +72,7 @@ struct old_linux_dirent {
68332 struct readdir_callback {
68333 struct dir_context ctx;
68334 struct old_linux_dirent __user * dirent;
68335 + struct file * file;
68336 int result;
68337 };
68338
68339 @@ -88,6 +90,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
68340 buf->result = -EOVERFLOW;
68341 return -EOVERFLOW;
68342 }
68343 +
68344 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
68345 + return 0;
68346 +
68347 buf->result++;
68348 dirent = buf->dirent;
68349 if (!access_ok(VERIFY_WRITE, dirent,
68350 @@ -119,6 +125,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
68351 if (!f.file)
68352 return -EBADF;
68353
68354 + buf.file = f.file;
68355 error = iterate_dir(f.file, &buf.ctx);
68356 if (buf.result)
68357 error = buf.result;
68358 @@ -144,6 +151,7 @@ struct getdents_callback {
68359 struct dir_context ctx;
68360 struct linux_dirent __user * current_dir;
68361 struct linux_dirent __user * previous;
68362 + struct file * file;
68363 int count;
68364 int error;
68365 };
68366 @@ -165,6 +173,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
68367 buf->error = -EOVERFLOW;
68368 return -EOVERFLOW;
68369 }
68370 +
68371 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
68372 + return 0;
68373 +
68374 dirent = buf->previous;
68375 if (dirent) {
68376 if (__put_user(offset, &dirent->d_off))
68377 @@ -210,6 +222,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
68378 if (!f.file)
68379 return -EBADF;
68380
68381 + buf.file = f.file;
68382 error = iterate_dir(f.file, &buf.ctx);
68383 if (error >= 0)
68384 error = buf.error;
68385 @@ -228,6 +241,7 @@ struct getdents_callback64 {
68386 struct dir_context ctx;
68387 struct linux_dirent64 __user * current_dir;
68388 struct linux_dirent64 __user * previous;
68389 + struct file *file;
68390 int count;
68391 int error;
68392 };
68393 @@ -243,6 +257,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
68394 buf->error = -EINVAL; /* only used if we fail.. */
68395 if (reclen > buf->count)
68396 return -EINVAL;
68397 +
68398 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
68399 + return 0;
68400 +
68401 dirent = buf->previous;
68402 if (dirent) {
68403 if (__put_user(offset, &dirent->d_off))
68404 @@ -290,6 +308,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
68405 if (!f.file)
68406 return -EBADF;
68407
68408 + buf.file = f.file;
68409 error = iterate_dir(f.file, &buf.ctx);
68410 if (error >= 0)
68411 error = buf.error;
68412 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
68413 index 54fdf19..987862b 100644
68414 --- a/fs/reiserfs/do_balan.c
68415 +++ b/fs/reiserfs/do_balan.c
68416 @@ -1872,7 +1872,7 @@ void do_balance(struct tree_balance *tb, struct item_head *ih,
68417 return;
68418 }
68419
68420 - atomic_inc(&fs_generation(tb->tb_sb));
68421 + atomic_inc_unchecked(&fs_generation(tb->tb_sb));
68422 do_balance_starts(tb);
68423
68424 /*
68425 diff --git a/fs/reiserfs/item_ops.c b/fs/reiserfs/item_ops.c
68426 index cfaee91..b9d0d60 100644
68427 --- a/fs/reiserfs/item_ops.c
68428 +++ b/fs/reiserfs/item_ops.c
68429 @@ -724,18 +724,18 @@ static void errcatch_print_vi(struct virtual_item *vi)
68430 }
68431
68432 static struct item_operations errcatch_ops = {
68433 - errcatch_bytes_number,
68434 - errcatch_decrement_key,
68435 - errcatch_is_left_mergeable,
68436 - errcatch_print_item,
68437 - errcatch_check_item,
68438 + .bytes_number = errcatch_bytes_number,
68439 + .decrement_key = errcatch_decrement_key,
68440 + .is_left_mergeable = errcatch_is_left_mergeable,
68441 + .print_item = errcatch_print_item,
68442 + .check_item = errcatch_check_item,
68443
68444 - errcatch_create_vi,
68445 - errcatch_check_left,
68446 - errcatch_check_right,
68447 - errcatch_part_size,
68448 - errcatch_unit_num,
68449 - errcatch_print_vi
68450 + .create_vi = errcatch_create_vi,
68451 + .check_left = errcatch_check_left,
68452 + .check_right = errcatch_check_right,
68453 + .part_size = errcatch_part_size,
68454 + .unit_num = errcatch_unit_num,
68455 + .print_vi = errcatch_print_vi
68456 };
68457
68458 #if ! (TYPE_STAT_DATA == 0 && TYPE_INDIRECT == 1 && TYPE_DIRECT == 2 && TYPE_DIRENTRY == 3)
68459 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
68460 index 02b0b7d..c85018b 100644
68461 --- a/fs/reiserfs/procfs.c
68462 +++ b/fs/reiserfs/procfs.c
68463 @@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
68464 "SMALL_TAILS " : "NO_TAILS ",
68465 replay_only(sb) ? "REPLAY_ONLY " : "",
68466 convert_reiserfs(sb) ? "CONV " : "",
68467 - atomic_read(&r->s_generation_counter),
68468 + atomic_read_unchecked(&r->s_generation_counter),
68469 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
68470 SF(s_do_balance), SF(s_unneeded_left_neighbor),
68471 SF(s_good_search_by_key_reada), SF(s_bmaps),
68472 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
68473 index bf53888..227f5ae 100644
68474 --- a/fs/reiserfs/reiserfs.h
68475 +++ b/fs/reiserfs/reiserfs.h
68476 @@ -573,7 +573,7 @@ struct reiserfs_sb_info {
68477 /* Comment? -Hans */
68478 wait_queue_head_t s_wait;
68479 /* increased by one every time the tree gets re-balanced */
68480 - atomic_t s_generation_counter;
68481 + atomic_unchecked_t s_generation_counter;
68482
68483 /* File system properties. Currently holds on-disk FS format */
68484 unsigned long s_properties;
68485 @@ -2294,7 +2294,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
68486 #define REISERFS_USER_MEM 1 /* user memory mode */
68487
68488 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
68489 -#define get_generation(s) atomic_read (&fs_generation(s))
68490 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
68491 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
68492 #define __fs_changed(gen,s) (gen != get_generation (s))
68493 #define fs_changed(gen,s) \
68494 diff --git a/fs/select.c b/fs/select.c
68495 index 467bb1c..cf9d65a 100644
68496 --- a/fs/select.c
68497 +++ b/fs/select.c
68498 @@ -20,6 +20,7 @@
68499 #include <linux/export.h>
68500 #include <linux/slab.h>
68501 #include <linux/poll.h>
68502 +#include <linux/security.h>
68503 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
68504 #include <linux/file.h>
68505 #include <linux/fdtable.h>
68506 @@ -880,6 +881,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
68507 struct poll_list *walk = head;
68508 unsigned long todo = nfds;
68509
68510 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
68511 if (nfds > rlimit(RLIMIT_NOFILE))
68512 return -EINVAL;
68513
68514 diff --git a/fs/seq_file.c b/fs/seq_file.c
68515 index 3857b72..0b7281e 100644
68516 --- a/fs/seq_file.c
68517 +++ b/fs/seq_file.c
68518 @@ -12,6 +12,8 @@
68519 #include <linux/slab.h>
68520 #include <linux/cred.h>
68521 #include <linux/mm.h>
68522 +#include <linux/sched.h>
68523 +#include <linux/grsecurity.h>
68524
68525 #include <asm/uaccess.h>
68526 #include <asm/page.h>
68527 @@ -34,12 +36,7 @@ static void seq_set_overflow(struct seq_file *m)
68528
68529 static void *seq_buf_alloc(unsigned long size)
68530 {
68531 - void *buf;
68532 -
68533 - buf = kmalloc(size, GFP_KERNEL | __GFP_NOWARN);
68534 - if (!buf && size > PAGE_SIZE)
68535 - buf = vmalloc(size);
68536 - return buf;
68537 + return kmalloc(size, GFP_KERNEL | GFP_USERCOPY);
68538 }
68539
68540 /**
68541 @@ -72,6 +69,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
68542 #ifdef CONFIG_USER_NS
68543 p->user_ns = file->f_cred->user_ns;
68544 #endif
68545 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
68546 + p->exec_id = current->exec_id;
68547 +#endif
68548
68549 /*
68550 * Wrappers around seq_open(e.g. swaps_open) need to be
68551 @@ -94,6 +94,16 @@ int seq_open(struct file *file, const struct seq_operations *op)
68552 }
68553 EXPORT_SYMBOL(seq_open);
68554
68555 +
68556 +int seq_open_restrict(struct file *file, const struct seq_operations *op)
68557 +{
68558 + if (gr_proc_is_restricted())
68559 + return -EACCES;
68560 +
68561 + return seq_open(file, op);
68562 +}
68563 +EXPORT_SYMBOL(seq_open_restrict);
68564 +
68565 static int traverse(struct seq_file *m, loff_t offset)
68566 {
68567 loff_t pos = 0, index;
68568 @@ -165,7 +175,7 @@ Eoverflow:
68569 ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
68570 {
68571 struct seq_file *m = file->private_data;
68572 - size_t copied = 0;
68573 + ssize_t copied = 0;
68574 loff_t pos;
68575 size_t n;
68576 void *p;
68577 @@ -596,7 +606,7 @@ static void single_stop(struct seq_file *p, void *v)
68578 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
68579 void *data)
68580 {
68581 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
68582 + seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
68583 int res = -ENOMEM;
68584
68585 if (op) {
68586 @@ -632,6 +642,17 @@ int single_open_size(struct file *file, int (*show)(struct seq_file *, void *),
68587 }
68588 EXPORT_SYMBOL(single_open_size);
68589
68590 +int single_open_restrict(struct file *file, int (*show)(struct seq_file *, void *),
68591 + void *data)
68592 +{
68593 + if (gr_proc_is_restricted())
68594 + return -EACCES;
68595 +
68596 + return single_open(file, show, data);
68597 +}
68598 +EXPORT_SYMBOL(single_open_restrict);
68599 +
68600 +
68601 int single_release(struct inode *inode, struct file *file)
68602 {
68603 const struct seq_operations *op = ((struct seq_file *)file->private_data)->op;
68604 diff --git a/fs/splice.c b/fs/splice.c
68605 index f5cb9ba..8ddb1e9 100644
68606 --- a/fs/splice.c
68607 +++ b/fs/splice.c
68608 @@ -193,7 +193,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
68609 pipe_lock(pipe);
68610
68611 for (;;) {
68612 - if (!pipe->readers) {
68613 + if (!atomic_read(&pipe->readers)) {
68614 send_sig(SIGPIPE, current, 0);
68615 if (!ret)
68616 ret = -EPIPE;
68617 @@ -216,7 +216,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
68618 page_nr++;
68619 ret += buf->len;
68620
68621 - if (pipe->files)
68622 + if (atomic_read(&pipe->files))
68623 do_wakeup = 1;
68624
68625 if (!--spd->nr_pages)
68626 @@ -247,9 +247,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
68627 do_wakeup = 0;
68628 }
68629
68630 - pipe->waiting_writers++;
68631 + atomic_inc(&pipe->waiting_writers);
68632 pipe_wait(pipe);
68633 - pipe->waiting_writers--;
68634 + atomic_dec(&pipe->waiting_writers);
68635 }
68636
68637 pipe_unlock(pipe);
68638 @@ -576,7 +576,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
68639 old_fs = get_fs();
68640 set_fs(get_ds());
68641 /* The cast to a user pointer is valid due to the set_fs() */
68642 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
68643 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
68644 set_fs(old_fs);
68645
68646 return res;
68647 @@ -591,7 +591,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
68648 old_fs = get_fs();
68649 set_fs(get_ds());
68650 /* The cast to a user pointer is valid due to the set_fs() */
68651 - res = vfs_write(file, (__force const char __user *)buf, count, &pos);
68652 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
68653 set_fs(old_fs);
68654
68655 return res;
68656 @@ -644,7 +644,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
68657 goto err;
68658
68659 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
68660 - vec[i].iov_base = (void __user *) page_address(page);
68661 + vec[i].iov_base = (void __force_user *) page_address(page);
68662 vec[i].iov_len = this_len;
68663 spd.pages[i] = page;
68664 spd.nr_pages++;
68665 @@ -783,7 +783,7 @@ static int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_des
68666 ops->release(pipe, buf);
68667 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
68668 pipe->nrbufs--;
68669 - if (pipe->files)
68670 + if (atomic_read(&pipe->files))
68671 sd->need_wakeup = true;
68672 }
68673
68674 @@ -807,10 +807,10 @@ static int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_des
68675 static int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
68676 {
68677 while (!pipe->nrbufs) {
68678 - if (!pipe->writers)
68679 + if (!atomic_read(&pipe->writers))
68680 return 0;
68681
68682 - if (!pipe->waiting_writers && sd->num_spliced)
68683 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
68684 return 0;
68685
68686 if (sd->flags & SPLICE_F_NONBLOCK)
68687 @@ -1040,7 +1040,7 @@ iter_file_splice_write(struct pipe_inode_info *pipe, struct file *out,
68688 ops->release(pipe, buf);
68689 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
68690 pipe->nrbufs--;
68691 - if (pipe->files)
68692 + if (atomic_read(&pipe->files))
68693 sd.need_wakeup = true;
68694 } else {
68695 buf->offset += ret;
68696 @@ -1200,7 +1200,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
68697 * out of the pipe right after the splice_to_pipe(). So set
68698 * PIPE_READERS appropriately.
68699 */
68700 - pipe->readers = 1;
68701 + atomic_set(&pipe->readers, 1);
68702
68703 current->splice_pipe = pipe;
68704 }
68705 @@ -1496,6 +1496,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
68706
68707 partial[buffers].offset = off;
68708 partial[buffers].len = plen;
68709 + partial[buffers].private = 0;
68710
68711 off = 0;
68712 len -= plen;
68713 @@ -1732,9 +1733,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
68714 ret = -ERESTARTSYS;
68715 break;
68716 }
68717 - if (!pipe->writers)
68718 + if (!atomic_read(&pipe->writers))
68719 break;
68720 - if (!pipe->waiting_writers) {
68721 + if (!atomic_read(&pipe->waiting_writers)) {
68722 if (flags & SPLICE_F_NONBLOCK) {
68723 ret = -EAGAIN;
68724 break;
68725 @@ -1766,7 +1767,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
68726 pipe_lock(pipe);
68727
68728 while (pipe->nrbufs >= pipe->buffers) {
68729 - if (!pipe->readers) {
68730 + if (!atomic_read(&pipe->readers)) {
68731 send_sig(SIGPIPE, current, 0);
68732 ret = -EPIPE;
68733 break;
68734 @@ -1779,9 +1780,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
68735 ret = -ERESTARTSYS;
68736 break;
68737 }
68738 - pipe->waiting_writers++;
68739 + atomic_inc(&pipe->waiting_writers);
68740 pipe_wait(pipe);
68741 - pipe->waiting_writers--;
68742 + atomic_dec(&pipe->waiting_writers);
68743 }
68744
68745 pipe_unlock(pipe);
68746 @@ -1817,14 +1818,14 @@ retry:
68747 pipe_double_lock(ipipe, opipe);
68748
68749 do {
68750 - if (!opipe->readers) {
68751 + if (!atomic_read(&opipe->readers)) {
68752 send_sig(SIGPIPE, current, 0);
68753 if (!ret)
68754 ret = -EPIPE;
68755 break;
68756 }
68757
68758 - if (!ipipe->nrbufs && !ipipe->writers)
68759 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
68760 break;
68761
68762 /*
68763 @@ -1921,7 +1922,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
68764 pipe_double_lock(ipipe, opipe);
68765
68766 do {
68767 - if (!opipe->readers) {
68768 + if (!atomic_read(&opipe->readers)) {
68769 send_sig(SIGPIPE, current, 0);
68770 if (!ret)
68771 ret = -EPIPE;
68772 @@ -1966,7 +1967,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
68773 * return EAGAIN if we have the potential of some data in the
68774 * future, otherwise just return 0
68775 */
68776 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
68777 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
68778 ret = -EAGAIN;
68779
68780 pipe_unlock(ipipe);
68781 diff --git a/fs/stat.c b/fs/stat.c
68782 index ae0c3ce..9ee641c 100644
68783 --- a/fs/stat.c
68784 +++ b/fs/stat.c
68785 @@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
68786 stat->gid = inode->i_gid;
68787 stat->rdev = inode->i_rdev;
68788 stat->size = i_size_read(inode);
68789 - stat->atime = inode->i_atime;
68790 - stat->mtime = inode->i_mtime;
68791 + if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
68792 + stat->atime = inode->i_ctime;
68793 + stat->mtime = inode->i_ctime;
68794 + } else {
68795 + stat->atime = inode->i_atime;
68796 + stat->mtime = inode->i_mtime;
68797 + }
68798 stat->ctime = inode->i_ctime;
68799 stat->blksize = (1 << inode->i_blkbits);
68800 stat->blocks = inode->i_blocks;
68801 @@ -52,9 +57,16 @@ EXPORT_SYMBOL(generic_fillattr);
68802 int vfs_getattr_nosec(struct path *path, struct kstat *stat)
68803 {
68804 struct inode *inode = path->dentry->d_inode;
68805 + int retval;
68806
68807 - if (inode->i_op->getattr)
68808 - return inode->i_op->getattr(path->mnt, path->dentry, stat);
68809 + if (inode->i_op->getattr) {
68810 + retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
68811 + if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
68812 + stat->atime = stat->ctime;
68813 + stat->mtime = stat->ctime;
68814 + }
68815 + return retval;
68816 + }
68817
68818 generic_fillattr(inode, stat);
68819 return 0;
68820 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
68821 index 0b45ff4..847de5b 100644
68822 --- a/fs/sysfs/dir.c
68823 +++ b/fs/sysfs/dir.c
68824 @@ -41,9 +41,16 @@ void sysfs_warn_dup(struct kernfs_node *parent, const char *name)
68825 int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
68826 {
68827 struct kernfs_node *parent, *kn;
68828 + const char *name;
68829 + umode_t mode = S_IRWXU | S_IRUGO | S_IXUGO;
68830 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
68831 + const char *parent_name;
68832 +#endif
68833
68834 BUG_ON(!kobj);
68835
68836 + name = kobject_name(kobj);
68837 +
68838 if (kobj->parent)
68839 parent = kobj->parent->sd;
68840 else
68841 @@ -52,11 +59,22 @@ int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
68842 if (!parent)
68843 return -ENOENT;
68844
68845 - kn = kernfs_create_dir_ns(parent, kobject_name(kobj),
68846 - S_IRWXU | S_IRUGO | S_IXUGO, kobj, ns);
68847 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
68848 + parent_name = parent->name;
68849 + mode = S_IRWXU;
68850 +
68851 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
68852 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
68853 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
68854 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
68855 + mode = S_IRWXU | S_IRUGO | S_IXUGO;
68856 +#endif
68857 +
68858 + kn = kernfs_create_dir_ns(parent, name,
68859 + mode, kobj, ns);
68860 if (IS_ERR(kn)) {
68861 if (PTR_ERR(kn) == -EEXIST)
68862 - sysfs_warn_dup(parent, kobject_name(kobj));
68863 + sysfs_warn_dup(parent, name);
68864 return PTR_ERR(kn);
68865 }
68866
68867 diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
68868 index 69d4889..a810bd4 100644
68869 --- a/fs/sysv/sysv.h
68870 +++ b/fs/sysv/sysv.h
68871 @@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
68872 #endif
68873 }
68874
68875 -static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
68876 +static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
68877 {
68878 if (sbi->s_bytesex == BYTESEX_PDP)
68879 return PDP_swab((__force __u32)n);
68880 diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
68881 index 2290d58..7791371 100644
68882 --- a/fs/ubifs/io.c
68883 +++ b/fs/ubifs/io.c
68884 @@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
68885 return err;
68886 }
68887
68888 -int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
68889 +int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
68890 {
68891 int err;
68892
68893 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
68894 index c175b4d..8f36a16 100644
68895 --- a/fs/udf/misc.c
68896 +++ b/fs/udf/misc.c
68897 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
68898
68899 u8 udf_tag_checksum(const struct tag *t)
68900 {
68901 - u8 *data = (u8 *)t;
68902 + const u8 *data = (const u8 *)t;
68903 u8 checksum = 0;
68904 int i;
68905 for (i = 0; i < sizeof(struct tag); ++i)
68906 diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
68907 index 8d974c4..b82f6ec 100644
68908 --- a/fs/ufs/swab.h
68909 +++ b/fs/ufs/swab.h
68910 @@ -22,7 +22,7 @@ enum {
68911 BYTESEX_BE
68912 };
68913
68914 -static inline u64
68915 +static inline u64 __intentional_overflow(-1)
68916 fs64_to_cpu(struct super_block *sbp, __fs64 n)
68917 {
68918 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
68919 @@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
68920 return (__force __fs64)cpu_to_be64(n);
68921 }
68922
68923 -static inline u32
68924 +static inline u32 __intentional_overflow(-1)
68925 fs32_to_cpu(struct super_block *sbp, __fs32 n)
68926 {
68927 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
68928 diff --git a/fs/utimes.c b/fs/utimes.c
68929 index aa138d6..5f3a811 100644
68930 --- a/fs/utimes.c
68931 +++ b/fs/utimes.c
68932 @@ -1,6 +1,7 @@
68933 #include <linux/compiler.h>
68934 #include <linux/file.h>
68935 #include <linux/fs.h>
68936 +#include <linux/security.h>
68937 #include <linux/linkage.h>
68938 #include <linux/mount.h>
68939 #include <linux/namei.h>
68940 @@ -103,6 +104,12 @@ static int utimes_common(struct path *path, struct timespec *times)
68941 }
68942 }
68943 retry_deleg:
68944 +
68945 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
68946 + error = -EACCES;
68947 + goto mnt_drop_write_and_out;
68948 + }
68949 +
68950 mutex_lock(&inode->i_mutex);
68951 error = notify_change(path->dentry, &newattrs, &delegated_inode);
68952 mutex_unlock(&inode->i_mutex);
68953 diff --git a/fs/xattr.c b/fs/xattr.c
68954 index c69e6d4..cc56af5 100644
68955 --- a/fs/xattr.c
68956 +++ b/fs/xattr.c
68957 @@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
68958 return rc;
68959 }
68960
68961 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
68962 +ssize_t
68963 +pax_getxattr(struct dentry *dentry, void *value, size_t size)
68964 +{
68965 + struct inode *inode = dentry->d_inode;
68966 + ssize_t error;
68967 +
68968 + error = inode_permission(inode, MAY_EXEC);
68969 + if (error)
68970 + return error;
68971 +
68972 + if (inode->i_op->getxattr)
68973 + error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
68974 + else
68975 + error = -EOPNOTSUPP;
68976 +
68977 + return error;
68978 +}
68979 +EXPORT_SYMBOL(pax_getxattr);
68980 +#endif
68981 +
68982 ssize_t
68983 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
68984 {
68985 @@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
68986 * Extended attribute SET operations
68987 */
68988 static long
68989 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
68990 +setxattr(struct path *path, const char __user *name, const void __user *value,
68991 size_t size, int flags)
68992 {
68993 int error;
68994 @@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
68995 posix_acl_fix_xattr_from_user(kvalue, size);
68996 }
68997
68998 - error = vfs_setxattr(d, kname, kvalue, size, flags);
68999 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
69000 + error = -EACCES;
69001 + goto out;
69002 + }
69003 +
69004 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
69005 out:
69006 if (vvalue)
69007 vfree(vvalue);
69008 @@ -377,7 +403,7 @@ retry:
69009 return error;
69010 error = mnt_want_write(path.mnt);
69011 if (!error) {
69012 - error = setxattr(path.dentry, name, value, size, flags);
69013 + error = setxattr(&path, name, value, size, flags);
69014 mnt_drop_write(path.mnt);
69015 }
69016 path_put(&path);
69017 @@ -401,7 +427,7 @@ retry:
69018 return error;
69019 error = mnt_want_write(path.mnt);
69020 if (!error) {
69021 - error = setxattr(path.dentry, name, value, size, flags);
69022 + error = setxattr(&path, name, value, size, flags);
69023 mnt_drop_write(path.mnt);
69024 }
69025 path_put(&path);
69026 @@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
69027 const void __user *,value, size_t, size, int, flags)
69028 {
69029 struct fd f = fdget(fd);
69030 - struct dentry *dentry;
69031 int error = -EBADF;
69032
69033 if (!f.file)
69034 return error;
69035 - dentry = f.file->f_path.dentry;
69036 - audit_inode(NULL, dentry, 0);
69037 + audit_inode(NULL, f.file->f_path.dentry, 0);
69038 error = mnt_want_write_file(f.file);
69039 if (!error) {
69040 - error = setxattr(dentry, name, value, size, flags);
69041 + error = setxattr(&f.file->f_path, name, value, size, flags);
69042 mnt_drop_write_file(f.file);
69043 }
69044 fdput(f);
69045 @@ -626,7 +650,7 @@ SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
69046 * Extended attribute REMOVE operations
69047 */
69048 static long
69049 -removexattr(struct dentry *d, const char __user *name)
69050 +removexattr(struct path *path, const char __user *name)
69051 {
69052 int error;
69053 char kname[XATTR_NAME_MAX + 1];
69054 @@ -637,7 +661,10 @@ removexattr(struct dentry *d, const char __user *name)
69055 if (error < 0)
69056 return error;
69057
69058 - return vfs_removexattr(d, kname);
69059 + if (!gr_acl_handle_removexattr(path->dentry, path->mnt))
69060 + return -EACCES;
69061 +
69062 + return vfs_removexattr(path->dentry, kname);
69063 }
69064
69065 SYSCALL_DEFINE2(removexattr, const char __user *, pathname,
69066 @@ -652,7 +679,7 @@ retry:
69067 return error;
69068 error = mnt_want_write(path.mnt);
69069 if (!error) {
69070 - error = removexattr(path.dentry, name);
69071 + error = removexattr(&path, name);
69072 mnt_drop_write(path.mnt);
69073 }
69074 path_put(&path);
69075 @@ -675,7 +702,7 @@ retry:
69076 return error;
69077 error = mnt_want_write(path.mnt);
69078 if (!error) {
69079 - error = removexattr(path.dentry, name);
69080 + error = removexattr(&path, name);
69081 mnt_drop_write(path.mnt);
69082 }
69083 path_put(&path);
69084 @@ -689,16 +716,16 @@ retry:
69085 SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
69086 {
69087 struct fd f = fdget(fd);
69088 - struct dentry *dentry;
69089 + struct path *path;
69090 int error = -EBADF;
69091
69092 if (!f.file)
69093 return error;
69094 - dentry = f.file->f_path.dentry;
69095 - audit_inode(NULL, dentry, 0);
69096 + path = &f.file->f_path;
69097 + audit_inode(NULL, path->dentry, 0);
69098 error = mnt_want_write_file(f.file);
69099 if (!error) {
69100 - error = removexattr(dentry, name);
69101 + error = removexattr(path, name);
69102 mnt_drop_write_file(f.file);
69103 }
69104 fdput(f);
69105 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
69106 index 75c3fe5..b0f6bbe 100644
69107 --- a/fs/xfs/xfs_bmap.c
69108 +++ b/fs/xfs/xfs_bmap.c
69109 @@ -583,7 +583,7 @@ xfs_bmap_validate_ret(
69110
69111 #else
69112 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
69113 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
69114 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
69115 #endif /* DEBUG */
69116
69117 /*
69118 diff --git a/fs/xfs/xfs_dir2_readdir.c b/fs/xfs/xfs_dir2_readdir.c
69119 index 48e99af..54ebae3 100644
69120 --- a/fs/xfs/xfs_dir2_readdir.c
69121 +++ b/fs/xfs/xfs_dir2_readdir.c
69122 @@ -159,7 +159,12 @@ xfs_dir2_sf_getdents(
69123 ino = dp->d_ops->sf_get_ino(sfp, sfep);
69124 filetype = dp->d_ops->sf_get_ftype(sfep);
69125 ctx->pos = off & 0x7fffffff;
69126 - if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
69127 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
69128 + char name[sfep->namelen];
69129 + memcpy(name, sfep->name, sfep->namelen);
69130 + if (!dir_emit(ctx, name, sfep->namelen, ino, xfs_dir3_get_dtype(dp->i_mount, filetype)))
69131 + return 0;
69132 + } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
69133 xfs_dir3_get_dtype(dp->i_mount, filetype)))
69134 return 0;
69135 sfep = dp->d_ops->sf_nextentry(sfp, sfep);
69136 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
69137 index 8bc1bbc..0d6911b 100644
69138 --- a/fs/xfs/xfs_ioctl.c
69139 +++ b/fs/xfs/xfs_ioctl.c
69140 @@ -122,7 +122,7 @@ xfs_find_handle(
69141 }
69142
69143 error = -EFAULT;
69144 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
69145 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
69146 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
69147 goto out_put;
69148
69149 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
69150 new file mode 100644
69151 index 0000000..27cec32
69152 --- /dev/null
69153 +++ b/grsecurity/Kconfig
69154 @@ -0,0 +1,1166 @@
69155 +#
69156 +# grecurity configuration
69157 +#
69158 +menu "Memory Protections"
69159 +depends on GRKERNSEC
69160 +
69161 +config GRKERNSEC_KMEM
69162 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
69163 + default y if GRKERNSEC_CONFIG_AUTO
69164 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
69165 + help
69166 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
69167 + be written to or read from to modify or leak the contents of the running
69168 + kernel. /dev/port will also not be allowed to be opened, writing to
69169 + /dev/cpu/*/msr will be prevented, and support for kexec will be removed.
69170 + If you have module support disabled, enabling this will close up several
69171 + ways that are currently used to insert malicious code into the running
69172 + kernel.
69173 +
69174 + Even with this feature enabled, we still highly recommend that
69175 + you use the RBAC system, as it is still possible for an attacker to
69176 + modify the running kernel through other more obscure methods.
69177 +
69178 + It is highly recommended that you say Y here if you meet all the
69179 + conditions above.
69180 +
69181 +config GRKERNSEC_VM86
69182 + bool "Restrict VM86 mode"
69183 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
69184 + depends on X86_32
69185 +
69186 + help
69187 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
69188 + make use of a special execution mode on 32bit x86 processors called
69189 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
69190 + video cards and will still work with this option enabled. The purpose
69191 + of the option is to prevent exploitation of emulation errors in
69192 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
69193 + Nearly all users should be able to enable this option.
69194 +
69195 +config GRKERNSEC_IO
69196 + bool "Disable privileged I/O"
69197 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
69198 + depends on X86
69199 + select RTC_CLASS
69200 + select RTC_INTF_DEV
69201 + select RTC_DRV_CMOS
69202 +
69203 + help
69204 + If you say Y here, all ioperm and iopl calls will return an error.
69205 + Ioperm and iopl can be used to modify the running kernel.
69206 + Unfortunately, some programs need this access to operate properly,
69207 + the most notable of which are XFree86 and hwclock. hwclock can be
69208 + remedied by having RTC support in the kernel, so real-time
69209 + clock support is enabled if this option is enabled, to ensure
69210 + that hwclock operates correctly. If hwclock still does not work,
69211 + either update udev or symlink /dev/rtc to /dev/rtc0.
69212 +
69213 + If you're using XFree86 or a version of Xorg from 2012 or earlier,
69214 + you may not be able to boot into a graphical environment with this
69215 + option enabled. In this case, you should use the RBAC system instead.
69216 +
69217 +config GRKERNSEC_JIT_HARDEN
69218 + bool "Harden BPF JIT against spray attacks"
69219 + default y if GRKERNSEC_CONFIG_AUTO
69220 + depends on BPF_JIT && X86
69221 + help
69222 + If you say Y here, the native code generated by the kernel's Berkeley
69223 + Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
69224 + attacks that attempt to fit attacker-beneficial instructions in
69225 + 32bit immediate fields of JIT-generated native instructions. The
69226 + attacker will generally aim to cause an unintended instruction sequence
69227 + of JIT-generated native code to execute by jumping into the middle of
69228 + a generated instruction. This feature effectively randomizes the 32bit
69229 + immediate constants present in the generated code to thwart such attacks.
69230 +
69231 + If you're using KERNEXEC, it's recommended that you enable this option
69232 + to supplement the hardening of the kernel.
69233 +
69234 +config GRKERNSEC_PERF_HARDEN
69235 + bool "Disable unprivileged PERF_EVENTS usage by default"
69236 + default y if GRKERNSEC_CONFIG_AUTO
69237 + depends on PERF_EVENTS
69238 + help
69239 + If you say Y here, the range of acceptable values for the
69240 + /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
69241 + default to a new value: 3. When the sysctl is set to this value, no
69242 + unprivileged use of the PERF_EVENTS syscall interface will be permitted.
69243 +
69244 + Though PERF_EVENTS can be used legitimately for performance monitoring
69245 + and low-level application profiling, it is forced on regardless of
69246 + configuration, has been at fault for several vulnerabilities, and
69247 + creates new opportunities for side channels and other information leaks.
69248 +
69249 + This feature puts PERF_EVENTS into a secure default state and permits
69250 + the administrator to change out of it temporarily if unprivileged
69251 + application profiling is needed.
69252 +
69253 +config GRKERNSEC_RAND_THREADSTACK
69254 + bool "Insert random gaps between thread stacks"
69255 + default y if GRKERNSEC_CONFIG_AUTO
69256 + depends on PAX_RANDMMAP && !PPC
69257 + help
69258 + If you say Y here, a random-sized gap will be enforced between allocated
69259 + thread stacks. Glibc's NPTL and other threading libraries that
69260 + pass MAP_STACK to the kernel for thread stack allocation are supported.
69261 + The implementation currently provides 8 bits of entropy for the gap.
69262 +
69263 + Many distributions do not compile threaded remote services with the
69264 + -fstack-check argument to GCC, causing the variable-sized stack-based
69265 + allocator, alloca(), to not probe the stack on allocation. This
69266 + permits an unbounded alloca() to skip over any guard page and potentially
69267 + modify another thread's stack reliably. An enforced random gap
69268 + reduces the reliability of such an attack and increases the chance
69269 + that such a read/write to another thread's stack instead lands in
69270 + an unmapped area, causing a crash and triggering grsecurity's
69271 + anti-bruteforcing logic.
69272 +
69273 +config GRKERNSEC_PROC_MEMMAP
69274 + bool "Harden ASLR against information leaks and entropy reduction"
69275 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
69276 + depends on PAX_NOEXEC || PAX_ASLR
69277 + help
69278 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
69279 + give no information about the addresses of its mappings if
69280 + PaX features that rely on random addresses are enabled on the task.
69281 + In addition to sanitizing this information and disabling other
69282 + dangerous sources of information, this option causes reads of sensitive
69283 + /proc/<pid> entries where the file descriptor was opened in a different
69284 + task than the one performing the read. Such attempts are logged.
69285 + This option also limits argv/env strings for suid/sgid binaries
69286 + to 512KB to prevent a complete exhaustion of the stack entropy provided
69287 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
69288 + binaries to prevent alternative mmap layouts from being abused.
69289 +
69290 + If you use PaX it is essential that you say Y here as it closes up
69291 + several holes that make full ASLR useless locally.
69292 +
69293 +
69294 +config GRKERNSEC_KSTACKOVERFLOW
69295 + bool "Prevent kernel stack overflows"
69296 + default y if GRKERNSEC_CONFIG_AUTO
69297 + depends on !IA64 && 64BIT
69298 + help
69299 + If you say Y here, the kernel's process stacks will be allocated
69300 + with vmalloc instead of the kernel's default allocator. This
69301 + introduces guard pages that in combination with the alloca checking
69302 + of the STACKLEAK feature prevents all forms of kernel process stack
69303 + overflow abuse. Note that this is different from kernel stack
69304 + buffer overflows.
69305 +
69306 +config GRKERNSEC_BRUTE
69307 + bool "Deter exploit bruteforcing"
69308 + default y if GRKERNSEC_CONFIG_AUTO
69309 + help
69310 + If you say Y here, attempts to bruteforce exploits against forking
69311 + daemons such as apache or sshd, as well as against suid/sgid binaries
69312 + will be deterred. When a child of a forking daemon is killed by PaX
69313 + or crashes due to an illegal instruction or other suspicious signal,
69314 + the parent process will be delayed 30 seconds upon every subsequent
69315 + fork until the administrator is able to assess the situation and
69316 + restart the daemon.
69317 + In the suid/sgid case, the attempt is logged, the user has all their
69318 + existing instances of the suid/sgid binary terminated and will
69319 + be unable to execute any suid/sgid binaries for 15 minutes.
69320 +
69321 + It is recommended that you also enable signal logging in the auditing
69322 + section so that logs are generated when a process triggers a suspicious
69323 + signal.
69324 + If the sysctl option is enabled, a sysctl option with name
69325 + "deter_bruteforce" is created.
69326 +
69327 +config GRKERNSEC_MODHARDEN
69328 + bool "Harden module auto-loading"
69329 + default y if GRKERNSEC_CONFIG_AUTO
69330 + depends on MODULES
69331 + help
69332 + If you say Y here, module auto-loading in response to use of some
69333 + feature implemented by an unloaded module will be restricted to
69334 + root users. Enabling this option helps defend against attacks
69335 + by unprivileged users who abuse the auto-loading behavior to
69336 + cause a vulnerable module to load that is then exploited.
69337 +
69338 + If this option prevents a legitimate use of auto-loading for a
69339 + non-root user, the administrator can execute modprobe manually
69340 + with the exact name of the module mentioned in the alert log.
69341 + Alternatively, the administrator can add the module to the list
69342 + of modules loaded at boot by modifying init scripts.
69343 +
69344 + Modification of init scripts will most likely be needed on
69345 + Ubuntu servers with encrypted home directory support enabled,
69346 + as the first non-root user logging in will cause the ecb(aes),
69347 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
69348 +
69349 +config GRKERNSEC_HIDESYM
69350 + bool "Hide kernel symbols"
69351 + default y if GRKERNSEC_CONFIG_AUTO
69352 + select PAX_USERCOPY_SLABS
69353 + help
69354 + If you say Y here, getting information on loaded modules, and
69355 + displaying all kernel symbols through a syscall will be restricted
69356 + to users with CAP_SYS_MODULE. For software compatibility reasons,
69357 + /proc/kallsyms will be restricted to the root user. The RBAC
69358 + system can hide that entry even from root.
69359 +
69360 + This option also prevents leaking of kernel addresses through
69361 + several /proc entries.
69362 +
69363 + Note that this option is only effective provided the following
69364 + conditions are met:
69365 + 1) The kernel using grsecurity is not precompiled by some distribution
69366 + 2) You have also enabled GRKERNSEC_DMESG
69367 + 3) You are using the RBAC system and hiding other files such as your
69368 + kernel image and System.map. Alternatively, enabling this option
69369 + causes the permissions on /boot, /lib/modules, and the kernel
69370 + source directory to change at compile time to prevent
69371 + reading by non-root users.
69372 + If the above conditions are met, this option will aid in providing a
69373 + useful protection against local kernel exploitation of overflows
69374 + and arbitrary read/write vulnerabilities.
69375 +
69376 + It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
69377 + in addition to this feature.
69378 +
69379 +config GRKERNSEC_RANDSTRUCT
69380 + bool "Randomize layout of sensitive kernel structures"
69381 + default y if GRKERNSEC_CONFIG_AUTO
69382 + select GRKERNSEC_HIDESYM
69383 + select MODVERSIONS if MODULES
69384 + help
69385 + If you say Y here, the layouts of a number of sensitive kernel
69386 + structures (task, fs, cred, etc) and all structures composed entirely
69387 + of function pointers (aka "ops" structs) will be randomized at compile-time.
69388 + This can introduce the requirement of an additional infoleak
69389 + vulnerability for exploits targeting these structure types.
69390 +
69391 + Enabling this feature will introduce some performance impact, slightly
69392 + increase memory usage, and prevent the use of forensic tools like
69393 + Volatility against the system (unless the kernel source tree isn't
69394 + cleaned after kernel installation).
69395 +
69396 + The seed used for compilation is located at tools/gcc/randomize_layout_seed.h.
69397 + It remains after a make clean to allow for external modules to be compiled
69398 + with the existing seed and will be removed by a make mrproper or
69399 + make distclean.
69400 +
69401 + Note that the implementation requires gcc 4.6.4. or newer. You may need
69402 + to install the supporting headers explicitly in addition to the normal
69403 + gcc package.
69404 +
69405 +config GRKERNSEC_RANDSTRUCT_PERFORMANCE
69406 + bool "Use cacheline-aware structure randomization"
69407 + depends on GRKERNSEC_RANDSTRUCT
69408 + default y if GRKERNSEC_CONFIG_PRIORITY_PERF
69409 + help
69410 + If you say Y here, the RANDSTRUCT randomization will make a best effort
69411 + at restricting randomization to cacheline-sized groups of elements. It
69412 + will further not randomize bitfields in structures. This reduces the
69413 + performance hit of RANDSTRUCT at the cost of weakened randomization.
69414 +
69415 +config GRKERNSEC_KERN_LOCKOUT
69416 + bool "Active kernel exploit response"
69417 + default y if GRKERNSEC_CONFIG_AUTO
69418 + depends on X86 || ARM || PPC || SPARC
69419 + help
69420 + If you say Y here, when a PaX alert is triggered due to suspicious
69421 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
69422 + or an OOPS occurs due to bad memory accesses, instead of just
69423 + terminating the offending process (and potentially allowing
69424 + a subsequent exploit from the same user), we will take one of two
69425 + actions:
69426 + If the user was root, we will panic the system
69427 + If the user was non-root, we will log the attempt, terminate
69428 + all processes owned by the user, then prevent them from creating
69429 + any new processes until the system is restarted
69430 + This deters repeated kernel exploitation/bruteforcing attempts
69431 + and is useful for later forensics.
69432 +
69433 +config GRKERNSEC_OLD_ARM_USERLAND
69434 + bool "Old ARM userland compatibility"
69435 + depends on ARM && (CPU_V6 || CPU_V6K || CPU_V7)
69436 + help
69437 + If you say Y here, stubs of executable code to perform such operations
69438 + as "compare-exchange" will be placed at fixed locations in the ARM vector
69439 + table. This is unfortunately needed for old ARM userland meant to run
69440 + across a wide range of processors. Without this option enabled,
69441 + the get_tls and data memory barrier stubs will be emulated by the kernel,
69442 + which is enough for Linaro userlands or other userlands designed for v6
69443 + and newer ARM CPUs. It's recommended that you try without this option enabled
69444 + first, and only enable it if your userland does not boot (it will likely fail
69445 + at init time).
69446 +
69447 +endmenu
69448 +menu "Role Based Access Control Options"
69449 +depends on GRKERNSEC
69450 +
69451 +config GRKERNSEC_RBAC_DEBUG
69452 + bool
69453 +
69454 +config GRKERNSEC_NO_RBAC
69455 + bool "Disable RBAC system"
69456 + help
69457 + If you say Y here, the /dev/grsec device will be removed from the kernel,
69458 + preventing the RBAC system from being enabled. You should only say Y
69459 + here if you have no intention of using the RBAC system, so as to prevent
69460 + an attacker with root access from misusing the RBAC system to hide files
69461 + and processes when loadable module support and /dev/[k]mem have been
69462 + locked down.
69463 +
69464 +config GRKERNSEC_ACL_HIDEKERN
69465 + bool "Hide kernel processes"
69466 + help
69467 + If you say Y here, all kernel threads will be hidden to all
69468 + processes but those whose subject has the "view hidden processes"
69469 + flag.
69470 +
69471 +config GRKERNSEC_ACL_MAXTRIES
69472 + int "Maximum tries before password lockout"
69473 + default 3
69474 + help
69475 + This option enforces the maximum number of times a user can attempt
69476 + to authorize themselves with the grsecurity RBAC system before being
69477 + denied the ability to attempt authorization again for a specified time.
69478 + The lower the number, the harder it will be to brute-force a password.
69479 +
69480 +config GRKERNSEC_ACL_TIMEOUT
69481 + int "Time to wait after max password tries, in seconds"
69482 + default 30
69483 + help
69484 + This option specifies the time the user must wait after attempting to
69485 + authorize to the RBAC system with the maximum number of invalid
69486 + passwords. The higher the number, the harder it will be to brute-force
69487 + a password.
69488 +
69489 +endmenu
69490 +menu "Filesystem Protections"
69491 +depends on GRKERNSEC
69492 +
69493 +config GRKERNSEC_PROC
69494 + bool "Proc restrictions"
69495 + default y if GRKERNSEC_CONFIG_AUTO
69496 + help
69497 + If you say Y here, the permissions of the /proc filesystem
69498 + will be altered to enhance system security and privacy. You MUST
69499 + choose either a user only restriction or a user and group restriction.
69500 + Depending upon the option you choose, you can either restrict users to
69501 + see only the processes they themselves run, or choose a group that can
69502 + view all processes and files normally restricted to root if you choose
69503 + the "restrict to user only" option. NOTE: If you're running identd or
69504 + ntpd as a non-root user, you will have to run it as the group you
69505 + specify here.
69506 +
69507 +config GRKERNSEC_PROC_USER
69508 + bool "Restrict /proc to user only"
69509 + depends on GRKERNSEC_PROC
69510 + help
69511 + If you say Y here, non-root users will only be able to view their own
69512 + processes, and restricts them from viewing network-related information,
69513 + and viewing kernel symbol and module information.
69514 +
69515 +config GRKERNSEC_PROC_USERGROUP
69516 + bool "Allow special group"
69517 + default y if GRKERNSEC_CONFIG_AUTO
69518 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
69519 + help
69520 + If you say Y here, you will be able to select a group that will be
69521 + able to view all processes and network-related information. If you've
69522 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
69523 + remain hidden. This option is useful if you want to run identd as
69524 + a non-root user. The group you select may also be chosen at boot time
69525 + via "grsec_proc_gid=" on the kernel commandline.
69526 +
69527 +config GRKERNSEC_PROC_GID
69528 + int "GID for special group"
69529 + depends on GRKERNSEC_PROC_USERGROUP
69530 + default 1001
69531 +
69532 +config GRKERNSEC_PROC_ADD
69533 + bool "Additional restrictions"
69534 + default y if GRKERNSEC_CONFIG_AUTO
69535 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
69536 + help
69537 + If you say Y here, additional restrictions will be placed on
69538 + /proc that keep normal users from viewing device information and
69539 + slabinfo information that could be useful for exploits.
69540 +
69541 +config GRKERNSEC_LINK
69542 + bool "Linking restrictions"
69543 + default y if GRKERNSEC_CONFIG_AUTO
69544 + help
69545 + If you say Y here, /tmp race exploits will be prevented, since users
69546 + will no longer be able to follow symlinks owned by other users in
69547 + world-writable +t directories (e.g. /tmp), unless the owner of the
69548 + symlink is the owner of the directory. users will also not be
69549 + able to hardlink to files they do not own. If the sysctl option is
69550 + enabled, a sysctl option with name "linking_restrictions" is created.
69551 +
69552 +config GRKERNSEC_SYMLINKOWN
69553 + bool "Kernel-enforced SymlinksIfOwnerMatch"
69554 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
69555 + help
69556 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
69557 + that prevents it from being used as a security feature. As Apache
69558 + verifies the symlink by performing a stat() against the target of
69559 + the symlink before it is followed, an attacker can setup a symlink
69560 + to point to a same-owned file, then replace the symlink with one
69561 + that targets another user's file just after Apache "validates" the
69562 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
69563 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
69564 + will be in place for the group you specify. If the sysctl option
69565 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
69566 + created.
69567 +
69568 +config GRKERNSEC_SYMLINKOWN_GID
69569 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
69570 + depends on GRKERNSEC_SYMLINKOWN
69571 + default 1006
69572 + help
69573 + Setting this GID determines what group kernel-enforced
69574 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
69575 + is enabled, a sysctl option with name "symlinkown_gid" is created.
69576 +
69577 +config GRKERNSEC_FIFO
69578 + bool "FIFO restrictions"
69579 + default y if GRKERNSEC_CONFIG_AUTO
69580 + help
69581 + If you say Y here, users will not be able to write to FIFOs they don't
69582 + own in world-writable +t directories (e.g. /tmp), unless the owner of
69583 + the FIFO is the same owner of the directory it's held in. If the sysctl
69584 + option is enabled, a sysctl option with name "fifo_restrictions" is
69585 + created.
69586 +
69587 +config GRKERNSEC_SYSFS_RESTRICT
69588 + bool "Sysfs/debugfs restriction"
69589 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
69590 + depends on SYSFS
69591 + help
69592 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
69593 + any filesystem normally mounted under it (e.g. debugfs) will be
69594 + mostly accessible only by root. These filesystems generally provide access
69595 + to hardware and debug information that isn't appropriate for unprivileged
69596 + users of the system. Sysfs and debugfs have also become a large source
69597 + of new vulnerabilities, ranging from infoleaks to local compromise.
69598 + There has been very little oversight with an eye toward security involved
69599 + in adding new exporters of information to these filesystems, so their
69600 + use is discouraged.
69601 + For reasons of compatibility, a few directories have been whitelisted
69602 + for access by non-root users:
69603 + /sys/fs/selinux
69604 + /sys/fs/fuse
69605 + /sys/devices/system/cpu
69606 +
69607 +config GRKERNSEC_ROFS
69608 + bool "Runtime read-only mount protection"
69609 + depends on SYSCTL
69610 + help
69611 + If you say Y here, a sysctl option with name "romount_protect" will
69612 + be created. By setting this option to 1 at runtime, filesystems
69613 + will be protected in the following ways:
69614 + * No new writable mounts will be allowed
69615 + * Existing read-only mounts won't be able to be remounted read/write
69616 + * Write operations will be denied on all block devices
69617 + This option acts independently of grsec_lock: once it is set to 1,
69618 + it cannot be turned off. Therefore, please be mindful of the resulting
69619 + behavior if this option is enabled in an init script on a read-only
69620 + filesystem.
69621 + Also be aware that as with other root-focused features, GRKERNSEC_KMEM
69622 + and GRKERNSEC_IO should be enabled and module loading disabled via
69623 + config or at runtime.
69624 + This feature is mainly intended for secure embedded systems.
69625 +
69626 +
69627 +config GRKERNSEC_DEVICE_SIDECHANNEL
69628 + bool "Eliminate stat/notify-based device sidechannels"
69629 + default y if GRKERNSEC_CONFIG_AUTO
69630 + help
69631 + If you say Y here, timing analyses on block or character
69632 + devices like /dev/ptmx using stat or inotify/dnotify/fanotify
69633 + will be thwarted for unprivileged users. If a process without
69634 + CAP_MKNOD stats such a device, the last access and last modify times
69635 + will match the device's create time. No access or modify events
69636 + will be triggered through inotify/dnotify/fanotify for such devices.
69637 + This feature will prevent attacks that may at a minimum
69638 + allow an attacker to determine the administrator's password length.
69639 +
69640 +config GRKERNSEC_CHROOT
69641 + bool "Chroot jail restrictions"
69642 + default y if GRKERNSEC_CONFIG_AUTO
69643 + help
69644 + If you say Y here, you will be able to choose several options that will
69645 + make breaking out of a chrooted jail much more difficult. If you
69646 + encounter no software incompatibilities with the following options, it
69647 + is recommended that you enable each one.
69648 +
69649 + Note that the chroot restrictions are not intended to apply to "chroots"
69650 + to directories that are simple bind mounts of the global root filesystem.
69651 + For several other reasons, a user shouldn't expect any significant
69652 + security by performing such a chroot.
69653 +
69654 +config GRKERNSEC_CHROOT_MOUNT
69655 + bool "Deny mounts"
69656 + default y if GRKERNSEC_CONFIG_AUTO
69657 + depends on GRKERNSEC_CHROOT
69658 + help
69659 + If you say Y here, processes inside a chroot will not be able to
69660 + mount or remount filesystems. If the sysctl option is enabled, a
69661 + sysctl option with name "chroot_deny_mount" is created.
69662 +
69663 +config GRKERNSEC_CHROOT_DOUBLE
69664 + bool "Deny double-chroots"
69665 + default y if GRKERNSEC_CONFIG_AUTO
69666 + depends on GRKERNSEC_CHROOT
69667 + help
69668 + If you say Y here, processes inside a chroot will not be able to chroot
69669 + again outside the chroot. This is a widely used method of breaking
69670 + out of a chroot jail and should not be allowed. If the sysctl
69671 + option is enabled, a sysctl option with name
69672 + "chroot_deny_chroot" is created.
69673 +
69674 +config GRKERNSEC_CHROOT_PIVOT
69675 + bool "Deny pivot_root in chroot"
69676 + default y if GRKERNSEC_CONFIG_AUTO
69677 + depends on GRKERNSEC_CHROOT
69678 + help
69679 + If you say Y here, processes inside a chroot will not be able to use
69680 + a function called pivot_root() that was introduced in Linux 2.3.41. It
69681 + works similar to chroot in that it changes the root filesystem. This
69682 + function could be misused in a chrooted process to attempt to break out
69683 + of the chroot, and therefore should not be allowed. If the sysctl
69684 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
69685 + created.
69686 +
69687 +config GRKERNSEC_CHROOT_CHDIR
69688 + bool "Enforce chdir(\"/\") on all chroots"
69689 + default y if GRKERNSEC_CONFIG_AUTO
69690 + depends on GRKERNSEC_CHROOT
69691 + help
69692 + If you say Y here, the current working directory of all newly-chrooted
69693 + applications will be set to the the root directory of the chroot.
69694 + The man page on chroot(2) states:
69695 + Note that this call does not change the current working
69696 + directory, so that `.' can be outside the tree rooted at
69697 + `/'. In particular, the super-user can escape from a
69698 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
69699 +
69700 + It is recommended that you say Y here, since it's not known to break
69701 + any software. If the sysctl option is enabled, a sysctl option with
69702 + name "chroot_enforce_chdir" is created.
69703 +
69704 +config GRKERNSEC_CHROOT_CHMOD
69705 + bool "Deny (f)chmod +s"
69706 + default y if GRKERNSEC_CONFIG_AUTO
69707 + depends on GRKERNSEC_CHROOT
69708 + help
69709 + If you say Y here, processes inside a chroot will not be able to chmod
69710 + or fchmod files to make them have suid or sgid bits. This protects
69711 + against another published method of breaking a chroot. If the sysctl
69712 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
69713 + created.
69714 +
69715 +config GRKERNSEC_CHROOT_FCHDIR
69716 + bool "Deny fchdir and fhandle out of chroot"
69717 + default y if GRKERNSEC_CONFIG_AUTO
69718 + depends on GRKERNSEC_CHROOT
69719 + help
69720 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
69721 + to a file descriptor of the chrooting process that points to a directory
69722 + outside the filesystem will be stopped. Additionally, this option prevents
69723 + use of the recently-created syscall for opening files by a guessable "file
69724 + handle" inside a chroot. If the sysctl option is enabled, a sysctl option
69725 + with name "chroot_deny_fchdir" is created.
69726 +
69727 +config GRKERNSEC_CHROOT_MKNOD
69728 + bool "Deny mknod"
69729 + default y if GRKERNSEC_CONFIG_AUTO
69730 + depends on GRKERNSEC_CHROOT
69731 + help
69732 + If you say Y here, processes inside a chroot will not be allowed to
69733 + mknod. The problem with using mknod inside a chroot is that it
69734 + would allow an attacker to create a device entry that is the same
69735 + as one on the physical root of your system, which could range from
69736 + anything from the console device to a device for your harddrive (which
69737 + they could then use to wipe the drive or steal data). It is recommended
69738 + that you say Y here, unless you run into software incompatibilities.
69739 + If the sysctl option is enabled, a sysctl option with name
69740 + "chroot_deny_mknod" is created.
69741 +
69742 +config GRKERNSEC_CHROOT_SHMAT
69743 + bool "Deny shmat() out of chroot"
69744 + default y if GRKERNSEC_CONFIG_AUTO
69745 + depends on GRKERNSEC_CHROOT
69746 + help
69747 + If you say Y here, processes inside a chroot will not be able to attach
69748 + to shared memory segments that were created outside of the chroot jail.
69749 + It is recommended that you say Y here. If the sysctl option is enabled,
69750 + a sysctl option with name "chroot_deny_shmat" is created.
69751 +
69752 +config GRKERNSEC_CHROOT_UNIX
69753 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
69754 + default y if GRKERNSEC_CONFIG_AUTO
69755 + depends on GRKERNSEC_CHROOT
69756 + help
69757 + If you say Y here, processes inside a chroot will not be able to
69758 + connect to abstract (meaning not belonging to a filesystem) Unix
69759 + domain sockets that were bound outside of a chroot. It is recommended
69760 + that you say Y here. If the sysctl option is enabled, a sysctl option
69761 + with name "chroot_deny_unix" is created.
69762 +
69763 +config GRKERNSEC_CHROOT_FINDTASK
69764 + bool "Protect outside processes"
69765 + default y if GRKERNSEC_CONFIG_AUTO
69766 + depends on GRKERNSEC_CHROOT
69767 + help
69768 + If you say Y here, processes inside a chroot will not be able to
69769 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
69770 + getsid, or view any process outside of the chroot. If the sysctl
69771 + option is enabled, a sysctl option with name "chroot_findtask" is
69772 + created.
69773 +
69774 +config GRKERNSEC_CHROOT_NICE
69775 + bool "Restrict priority changes"
69776 + default y if GRKERNSEC_CONFIG_AUTO
69777 + depends on GRKERNSEC_CHROOT
69778 + help
69779 + If you say Y here, processes inside a chroot will not be able to raise
69780 + the priority of processes in the chroot, or alter the priority of
69781 + processes outside the chroot. This provides more security than simply
69782 + removing CAP_SYS_NICE from the process' capability set. If the
69783 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
69784 + is created.
69785 +
69786 +config GRKERNSEC_CHROOT_SYSCTL
69787 + bool "Deny sysctl writes"
69788 + default y if GRKERNSEC_CONFIG_AUTO
69789 + depends on GRKERNSEC_CHROOT
69790 + help
69791 + If you say Y here, an attacker in a chroot will not be able to
69792 + write to sysctl entries, either by sysctl(2) or through a /proc
69793 + interface. It is strongly recommended that you say Y here. If the
69794 + sysctl option is enabled, a sysctl option with name
69795 + "chroot_deny_sysctl" is created.
69796 +
69797 +config GRKERNSEC_CHROOT_CAPS
69798 + bool "Capability restrictions"
69799 + default y if GRKERNSEC_CONFIG_AUTO
69800 + depends on GRKERNSEC_CHROOT
69801 + help
69802 + If you say Y here, the capabilities on all processes within a
69803 + chroot jail will be lowered to stop module insertion, raw i/o,
69804 + system and net admin tasks, rebooting the system, modifying immutable
69805 + files, modifying IPC owned by another, and changing the system time.
69806 + This is left an option because it can break some apps. Disable this
69807 + if your chrooted apps are having problems performing those kinds of
69808 + tasks. If the sysctl option is enabled, a sysctl option with
69809 + name "chroot_caps" is created.
69810 +
69811 +config GRKERNSEC_CHROOT_INITRD
69812 + bool "Exempt initrd tasks from restrictions"
69813 + default y if GRKERNSEC_CONFIG_AUTO
69814 + depends on GRKERNSEC_CHROOT && BLK_DEV_INITRD
69815 + help
69816 + If you say Y here, tasks started prior to init will be exempted from
69817 + grsecurity's chroot restrictions. This option is mainly meant to
69818 + resolve Plymouth's performing privileged operations unnecessarily
69819 + in a chroot.
69820 +
69821 +endmenu
69822 +menu "Kernel Auditing"
69823 +depends on GRKERNSEC
69824 +
69825 +config GRKERNSEC_AUDIT_GROUP
69826 + bool "Single group for auditing"
69827 + help
69828 + If you say Y here, the exec and chdir logging features will only operate
69829 + on a group you specify. This option is recommended if you only want to
69830 + watch certain users instead of having a large amount of logs from the
69831 + entire system. If the sysctl option is enabled, a sysctl option with
69832 + name "audit_group" is created.
69833 +
69834 +config GRKERNSEC_AUDIT_GID
69835 + int "GID for auditing"
69836 + depends on GRKERNSEC_AUDIT_GROUP
69837 + default 1007
69838 +
69839 +config GRKERNSEC_EXECLOG
69840 + bool "Exec logging"
69841 + help
69842 + If you say Y here, all execve() calls will be logged (since the
69843 + other exec*() calls are frontends to execve(), all execution
69844 + will be logged). Useful for shell-servers that like to keep track
69845 + of their users. If the sysctl option is enabled, a sysctl option with
69846 + name "exec_logging" is created.
69847 + WARNING: This option when enabled will produce a LOT of logs, especially
69848 + on an active system.
69849 +
69850 +config GRKERNSEC_RESLOG
69851 + bool "Resource logging"
69852 + default y if GRKERNSEC_CONFIG_AUTO
69853 + help
69854 + If you say Y here, all attempts to overstep resource limits will
69855 + be logged with the resource name, the requested size, and the current
69856 + limit. It is highly recommended that you say Y here. If the sysctl
69857 + option is enabled, a sysctl option with name "resource_logging" is
69858 + created. If the RBAC system is enabled, the sysctl value is ignored.
69859 +
69860 +config GRKERNSEC_CHROOT_EXECLOG
69861 + bool "Log execs within chroot"
69862 + help
69863 + If you say Y here, all executions inside a chroot jail will be logged
69864 + to syslog. This can cause a large amount of logs if certain
69865 + applications (eg. djb's daemontools) are installed on the system, and
69866 + is therefore left as an option. If the sysctl option is enabled, a
69867 + sysctl option with name "chroot_execlog" is created.
69868 +
69869 +config GRKERNSEC_AUDIT_PTRACE
69870 + bool "Ptrace logging"
69871 + help
69872 + If you say Y here, all attempts to attach to a process via ptrace
69873 + will be logged. If the sysctl option is enabled, a sysctl option
69874 + with name "audit_ptrace" is created.
69875 +
69876 +config GRKERNSEC_AUDIT_CHDIR
69877 + bool "Chdir logging"
69878 + help
69879 + If you say Y here, all chdir() calls will be logged. If the sysctl
69880 + option is enabled, a sysctl option with name "audit_chdir" is created.
69881 +
69882 +config GRKERNSEC_AUDIT_MOUNT
69883 + bool "(Un)Mount logging"
69884 + help
69885 + If you say Y here, all mounts and unmounts will be logged. If the
69886 + sysctl option is enabled, a sysctl option with name "audit_mount" is
69887 + created.
69888 +
69889 +config GRKERNSEC_SIGNAL
69890 + bool "Signal logging"
69891 + default y if GRKERNSEC_CONFIG_AUTO
69892 + help
69893 + If you say Y here, certain important signals will be logged, such as
69894 + SIGSEGV, which will as a result inform you of when a error in a program
69895 + occurred, which in some cases could mean a possible exploit attempt.
69896 + If the sysctl option is enabled, a sysctl option with name
69897 + "signal_logging" is created.
69898 +
69899 +config GRKERNSEC_FORKFAIL
69900 + bool "Fork failure logging"
69901 + help
69902 + If you say Y here, all failed fork() attempts will be logged.
69903 + This could suggest a fork bomb, or someone attempting to overstep
69904 + their process limit. If the sysctl option is enabled, a sysctl option
69905 + with name "forkfail_logging" is created.
69906 +
69907 +config GRKERNSEC_TIME
69908 + bool "Time change logging"
69909 + default y if GRKERNSEC_CONFIG_AUTO
69910 + help
69911 + If you say Y here, any changes of the system clock will be logged.
69912 + If the sysctl option is enabled, a sysctl option with name
69913 + "timechange_logging" is created.
69914 +
69915 +config GRKERNSEC_PROC_IPADDR
69916 + bool "/proc/<pid>/ipaddr support"
69917 + default y if GRKERNSEC_CONFIG_AUTO
69918 + help
69919 + If you say Y here, a new entry will be added to each /proc/<pid>
69920 + directory that contains the IP address of the person using the task.
69921 + The IP is carried across local TCP and AF_UNIX stream sockets.
69922 + This information can be useful for IDS/IPSes to perform remote response
69923 + to a local attack. The entry is readable by only the owner of the
69924 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
69925 + the RBAC system), and thus does not create privacy concerns.
69926 +
69927 +config GRKERNSEC_RWXMAP_LOG
69928 + bool 'Denied RWX mmap/mprotect logging'
69929 + default y if GRKERNSEC_CONFIG_AUTO
69930 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
69931 + help
69932 + If you say Y here, calls to mmap() and mprotect() with explicit
69933 + usage of PROT_WRITE and PROT_EXEC together will be logged when
69934 + denied by the PAX_MPROTECT feature. This feature will also
69935 + log other problematic scenarios that can occur when PAX_MPROTECT
69936 + is enabled on a binary, like textrels and PT_GNU_STACK. If the
69937 + sysctl option is enabled, a sysctl option with name "rwxmap_logging"
69938 + is created.
69939 +
69940 +endmenu
69941 +
69942 +menu "Executable Protections"
69943 +depends on GRKERNSEC
69944 +
69945 +config GRKERNSEC_DMESG
69946 + bool "Dmesg(8) restriction"
69947 + default y if GRKERNSEC_CONFIG_AUTO
69948 + help
69949 + If you say Y here, non-root users will not be able to use dmesg(8)
69950 + to view the contents of the kernel's circular log buffer.
69951 + The kernel's log buffer often contains kernel addresses and other
69952 + identifying information useful to an attacker in fingerprinting a
69953 + system for a targeted exploit.
69954 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
69955 + created.
69956 +
69957 +config GRKERNSEC_HARDEN_PTRACE
69958 + bool "Deter ptrace-based process snooping"
69959 + default y if GRKERNSEC_CONFIG_AUTO
69960 + help
69961 + If you say Y here, TTY sniffers and other malicious monitoring
69962 + programs implemented through ptrace will be defeated. If you
69963 + have been using the RBAC system, this option has already been
69964 + enabled for several years for all users, with the ability to make
69965 + fine-grained exceptions.
69966 +
69967 + This option only affects the ability of non-root users to ptrace
69968 + processes that are not a descendent of the ptracing process.
69969 + This means that strace ./binary and gdb ./binary will still work,
69970 + but attaching to arbitrary processes will not. If the sysctl
69971 + option is enabled, a sysctl option with name "harden_ptrace" is
69972 + created.
69973 +
69974 +config GRKERNSEC_PTRACE_READEXEC
69975 + bool "Require read access to ptrace sensitive binaries"
69976 + default y if GRKERNSEC_CONFIG_AUTO
69977 + help
69978 + If you say Y here, unprivileged users will not be able to ptrace unreadable
69979 + binaries. This option is useful in environments that
69980 + remove the read bits (e.g. file mode 4711) from suid binaries to
69981 + prevent infoleaking of their contents. This option adds
69982 + consistency to the use of that file mode, as the binary could normally
69983 + be read out when run without privileges while ptracing.
69984 +
69985 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
69986 + is created.
69987 +
69988 +config GRKERNSEC_SETXID
69989 + bool "Enforce consistent multithreaded privileges"
69990 + default y if GRKERNSEC_CONFIG_AUTO
69991 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
69992 + help
69993 + If you say Y here, a change from a root uid to a non-root uid
69994 + in a multithreaded application will cause the resulting uids,
69995 + gids, supplementary groups, and capabilities in that thread
69996 + to be propagated to the other threads of the process. In most
69997 + cases this is unnecessary, as glibc will emulate this behavior
69998 + on behalf of the application. Other libcs do not act in the
69999 + same way, allowing the other threads of the process to continue
70000 + running with root privileges. If the sysctl option is enabled,
70001 + a sysctl option with name "consistent_setxid" is created.
70002 +
70003 +config GRKERNSEC_HARDEN_IPC
70004 + bool "Disallow access to overly-permissive IPC objects"
70005 + default y if GRKERNSEC_CONFIG_AUTO
70006 + depends on SYSVIPC
70007 + help
70008 + If you say Y here, access to overly-permissive IPC objects (shared
70009 + memory, message queues, and semaphores) will be denied for processes
70010 + given the following criteria beyond normal permission checks:
70011 + 1) If the IPC object is world-accessible and the euid doesn't match
70012 + that of the creator or current uid for the IPC object
70013 + 2) If the IPC object is group-accessible and the egid doesn't
70014 + match that of the creator or current gid for the IPC object
70015 + It's a common error to grant too much permission to these objects,
70016 + with impact ranging from denial of service and information leaking to
70017 + privilege escalation. This feature was developed in response to
70018 + research by Tim Brown:
70019 + http://labs.portcullis.co.uk/whitepapers/memory-squatting-attacks-on-system-v-shared-memory/
70020 + who found hundreds of such insecure usages. Processes with
70021 + CAP_IPC_OWNER are still permitted to access these IPC objects.
70022 + If the sysctl option is enabled, a sysctl option with name
70023 + "harden_ipc" is created.
70024 +
70025 +config GRKERNSEC_TPE
70026 + bool "Trusted Path Execution (TPE)"
70027 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
70028 + help
70029 + If you say Y here, you will be able to choose a gid to add to the
70030 + supplementary groups of users you want to mark as "untrusted."
70031 + These users will not be able to execute any files that are not in
70032 + root-owned directories writable only by root. If the sysctl option
70033 + is enabled, a sysctl option with name "tpe" is created.
70034 +
70035 +config GRKERNSEC_TPE_ALL
70036 + bool "Partially restrict all non-root users"
70037 + depends on GRKERNSEC_TPE
70038 + help
70039 + If you say Y here, all non-root users will be covered under
70040 + a weaker TPE restriction. This is separate from, and in addition to,
70041 + the main TPE options that you have selected elsewhere. Thus, if a
70042 + "trusted" GID is chosen, this restriction applies to even that GID.
70043 + Under this restriction, all non-root users will only be allowed to
70044 + execute files in directories they own that are not group or
70045 + world-writable, or in directories owned by root and writable only by
70046 + root. If the sysctl option is enabled, a sysctl option with name
70047 + "tpe_restrict_all" is created.
70048 +
70049 +config GRKERNSEC_TPE_INVERT
70050 + bool "Invert GID option"
70051 + depends on GRKERNSEC_TPE
70052 + help
70053 + If you say Y here, the group you specify in the TPE configuration will
70054 + decide what group TPE restrictions will be *disabled* for. This
70055 + option is useful if you want TPE restrictions to be applied to most
70056 + users on the system. If the sysctl option is enabled, a sysctl option
70057 + with name "tpe_invert" is created. Unlike other sysctl options, this
70058 + entry will default to on for backward-compatibility.
70059 +
70060 +config GRKERNSEC_TPE_GID
70061 + int
70062 + default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
70063 + default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
70064 +
70065 +config GRKERNSEC_TPE_UNTRUSTED_GID
70066 + int "GID for TPE-untrusted users"
70067 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
70068 + default 1005
70069 + help
70070 + Setting this GID determines what group TPE restrictions will be
70071 + *enabled* for. If the sysctl option is enabled, a sysctl option
70072 + with name "tpe_gid" is created.
70073 +
70074 +config GRKERNSEC_TPE_TRUSTED_GID
70075 + int "GID for TPE-trusted users"
70076 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
70077 + default 1005
70078 + help
70079 + Setting this GID determines what group TPE restrictions will be
70080 + *disabled* for. If the sysctl option is enabled, a sysctl option
70081 + with name "tpe_gid" is created.
70082 +
70083 +endmenu
70084 +menu "Network Protections"
70085 +depends on GRKERNSEC
70086 +
70087 +config GRKERNSEC_BLACKHOLE
70088 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
70089 + default y if GRKERNSEC_CONFIG_AUTO
70090 + depends on NET
70091 + help
70092 + If you say Y here, neither TCP resets nor ICMP
70093 + destination-unreachable packets will be sent in response to packets
70094 + sent to ports for which no associated listening process exists.
70095 + This feature supports both IPV4 and IPV6 and exempts the
70096 + loopback interface from blackholing. Enabling this feature
70097 + makes a host more resilient to DoS attacks and reduces network
70098 + visibility against scanners.
70099 +
70100 + The blackhole feature as-implemented is equivalent to the FreeBSD
70101 + blackhole feature, as it prevents RST responses to all packets, not
70102 + just SYNs. Under most application behavior this causes no
70103 + problems, but applications (like haproxy) may not close certain
70104 + connections in a way that cleanly terminates them on the remote
70105 + end, leaving the remote host in LAST_ACK state. Because of this
70106 + side-effect and to prevent intentional LAST_ACK DoSes, this
70107 + feature also adds automatic mitigation against such attacks.
70108 + The mitigation drastically reduces the amount of time a socket
70109 + can spend in LAST_ACK state. If you're using haproxy and not
70110 + all servers it connects to have this option enabled, consider
70111 + disabling this feature on the haproxy host.
70112 +
70113 + If the sysctl option is enabled, two sysctl options with names
70114 + "ip_blackhole" and "lastack_retries" will be created.
70115 + While "ip_blackhole" takes the standard zero/non-zero on/off
70116 + toggle, "lastack_retries" uses the same kinds of values as
70117 + "tcp_retries1" and "tcp_retries2". The default value of 4
70118 + prevents a socket from lasting more than 45 seconds in LAST_ACK
70119 + state.
70120 +
70121 +config GRKERNSEC_NO_SIMULT_CONNECT
70122 + bool "Disable TCP Simultaneous Connect"
70123 + default y if GRKERNSEC_CONFIG_AUTO
70124 + depends on NET
70125 + help
70126 + If you say Y here, a feature by Willy Tarreau will be enabled that
70127 + removes a weakness in Linux's strict implementation of TCP that
70128 + allows two clients to connect to each other without either entering
70129 + a listening state. The weakness allows an attacker to easily prevent
70130 + a client from connecting to a known server provided the source port
70131 + for the connection is guessed correctly.
70132 +
70133 + As the weakness could be used to prevent an antivirus or IPS from
70134 + fetching updates, or prevent an SSL gateway from fetching a CRL,
70135 + it should be eliminated by enabling this option. Though Linux is
70136 + one of few operating systems supporting simultaneous connect, it
70137 + has no legitimate use in practice and is rarely supported by firewalls.
70138 +
70139 +config GRKERNSEC_SOCKET
70140 + bool "Socket restrictions"
70141 + depends on NET
70142 + help
70143 + If you say Y here, you will be able to choose from several options.
70144 + If you assign a GID on your system and add it to the supplementary
70145 + groups of users you want to restrict socket access to, this patch
70146 + will perform up to three things, based on the option(s) you choose.
70147 +
70148 +config GRKERNSEC_SOCKET_ALL
70149 + bool "Deny any sockets to group"
70150 + depends on GRKERNSEC_SOCKET
70151 + help
70152 + If you say Y here, you will be able to choose a GID of whose users will
70153 + be unable to connect to other hosts from your machine or run server
70154 + applications from your machine. If the sysctl option is enabled, a
70155 + sysctl option with name "socket_all" is created.
70156 +
70157 +config GRKERNSEC_SOCKET_ALL_GID
70158 + int "GID to deny all sockets for"
70159 + depends on GRKERNSEC_SOCKET_ALL
70160 + default 1004
70161 + help
70162 + Here you can choose the GID to disable socket access for. Remember to
70163 + add the users you want socket access disabled for to the GID
70164 + specified here. If the sysctl option is enabled, a sysctl option
70165 + with name "socket_all_gid" is created.
70166 +
70167 +config GRKERNSEC_SOCKET_CLIENT
70168 + bool "Deny client sockets to group"
70169 + depends on GRKERNSEC_SOCKET
70170 + help
70171 + If you say Y here, you will be able to choose a GID of whose users will
70172 + be unable to connect to other hosts from your machine, but will be
70173 + able to run servers. If this option is enabled, all users in the group
70174 + you specify will have to use passive mode when initiating ftp transfers
70175 + from the shell on your machine. If the sysctl option is enabled, a
70176 + sysctl option with name "socket_client" is created.
70177 +
70178 +config GRKERNSEC_SOCKET_CLIENT_GID
70179 + int "GID to deny client sockets for"
70180 + depends on GRKERNSEC_SOCKET_CLIENT
70181 + default 1003
70182 + help
70183 + Here you can choose the GID to disable client socket access for.
70184 + Remember to add the users you want client socket access disabled for to
70185 + the GID specified here. If the sysctl option is enabled, a sysctl
70186 + option with name "socket_client_gid" is created.
70187 +
70188 +config GRKERNSEC_SOCKET_SERVER
70189 + bool "Deny server sockets to group"
70190 + depends on GRKERNSEC_SOCKET
70191 + help
70192 + If you say Y here, you will be able to choose a GID of whose users will
70193 + be unable to run server applications from your machine. If the sysctl
70194 + option is enabled, a sysctl option with name "socket_server" is created.
70195 +
70196 +config GRKERNSEC_SOCKET_SERVER_GID
70197 + int "GID to deny server sockets for"
70198 + depends on GRKERNSEC_SOCKET_SERVER
70199 + default 1002
70200 + help
70201 + Here you can choose the GID to disable server socket access for.
70202 + Remember to add the users you want server socket access disabled for to
70203 + the GID specified here. If the sysctl option is enabled, a sysctl
70204 + option with name "socket_server_gid" is created.
70205 +
70206 +endmenu
70207 +
70208 +menu "Physical Protections"
70209 +depends on GRKERNSEC
70210 +
70211 +config GRKERNSEC_DENYUSB
70212 + bool "Deny new USB connections after toggle"
70213 + default y if GRKERNSEC_CONFIG_AUTO
70214 + depends on SYSCTL && USB_SUPPORT
70215 + help
70216 + If you say Y here, a new sysctl option with name "deny_new_usb"
70217 + will be created. Setting its value to 1 will prevent any new
70218 + USB devices from being recognized by the OS. Any attempted USB
70219 + device insertion will be logged. This option is intended to be
70220 + used against custom USB devices designed to exploit vulnerabilities
70221 + in various USB device drivers.
70222 +
70223 + For greatest effectiveness, this sysctl should be set after any
70224 + relevant init scripts. This option is safe to enable in distros
70225 + as each user can choose whether or not to toggle the sysctl.
70226 +
70227 +config GRKERNSEC_DENYUSB_FORCE
70228 + bool "Reject all USB devices not connected at boot"
70229 + select USB
70230 + depends on GRKERNSEC_DENYUSB
70231 + help
70232 + If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
70233 + that doesn't involve a sysctl entry. This option should only be
70234 + enabled if you're sure you want to deny all new USB connections
70235 + at runtime and don't want to modify init scripts. This should not
70236 + be enabled by distros. It forces the core USB code to be built
70237 + into the kernel image so that all devices connected at boot time
70238 + can be recognized and new USB device connections can be prevented
70239 + prior to init running.
70240 +
70241 +endmenu
70242 +
70243 +menu "Sysctl Support"
70244 +depends on GRKERNSEC && SYSCTL
70245 +
70246 +config GRKERNSEC_SYSCTL
70247 + bool "Sysctl support"
70248 + default y if GRKERNSEC_CONFIG_AUTO
70249 + help
70250 + If you say Y here, you will be able to change the options that
70251 + grsecurity runs with at bootup, without having to recompile your
70252 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
70253 + to enable (1) or disable (0) various features. All the sysctl entries
70254 + are mutable until the "grsec_lock" entry is set to a non-zero value.
70255 + All features enabled in the kernel configuration are disabled at boot
70256 + if you do not say Y to the "Turn on features by default" option.
70257 + All options should be set at startup, and the grsec_lock entry should
70258 + be set to a non-zero value after all the options are set.
70259 + *THIS IS EXTREMELY IMPORTANT*
70260 +
70261 +config GRKERNSEC_SYSCTL_DISTRO
70262 + bool "Extra sysctl support for distro makers (READ HELP)"
70263 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
70264 + help
70265 + If you say Y here, additional sysctl options will be created
70266 + for features that affect processes running as root. Therefore,
70267 + it is critical when using this option that the grsec_lock entry be
70268 + enabled after boot. Only distros with prebuilt kernel packages
70269 + with this option enabled that can ensure grsec_lock is enabled
70270 + after boot should use this option.
70271 + *Failure to set grsec_lock after boot makes all grsec features
70272 + this option covers useless*
70273 +
70274 + Currently this option creates the following sysctl entries:
70275 + "Disable Privileged I/O": "disable_priv_io"
70276 +
70277 +config GRKERNSEC_SYSCTL_ON
70278 + bool "Turn on features by default"
70279 + default y if GRKERNSEC_CONFIG_AUTO
70280 + depends on GRKERNSEC_SYSCTL
70281 + help
70282 + If you say Y here, instead of having all features enabled in the
70283 + kernel configuration disabled at boot time, the features will be
70284 + enabled at boot time. It is recommended you say Y here unless
70285 + there is some reason you would want all sysctl-tunable features to
70286 + be disabled by default. As mentioned elsewhere, it is important
70287 + to enable the grsec_lock entry once you have finished modifying
70288 + the sysctl entries.
70289 +
70290 +endmenu
70291 +menu "Logging Options"
70292 +depends on GRKERNSEC
70293 +
70294 +config GRKERNSEC_FLOODTIME
70295 + int "Seconds in between log messages (minimum)"
70296 + default 10
70297 + help
70298 + This option allows you to enforce the number of seconds between
70299 + grsecurity log messages. The default should be suitable for most
70300 + people, however, if you choose to change it, choose a value small enough
70301 + to allow informative logs to be produced, but large enough to
70302 + prevent flooding.
70303 +
70304 + Setting both this value and GRKERNSEC_FLOODBURST to 0 will disable
70305 + any rate limiting on grsecurity log messages.
70306 +
70307 +config GRKERNSEC_FLOODBURST
70308 + int "Number of messages in a burst (maximum)"
70309 + default 6
70310 + help
70311 + This option allows you to choose the maximum number of messages allowed
70312 + within the flood time interval you chose in a separate option. The
70313 + default should be suitable for most people, however if you find that
70314 + many of your logs are being interpreted as flooding, you may want to
70315 + raise this value.
70316 +
70317 + Setting both this value and GRKERNSEC_FLOODTIME to 0 will disable
70318 + any rate limiting on grsecurity log messages.
70319 +
70320 +endmenu
70321 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
70322 new file mode 100644
70323 index 0000000..30ababb
70324 --- /dev/null
70325 +++ b/grsecurity/Makefile
70326 @@ -0,0 +1,54 @@
70327 +# grsecurity – access control and security hardening for Linux
70328 +# All code in this directory and various hooks located throughout the Linux kernel are
70329 +# Copyright (C) 2001-2014 Bradley Spengler, Open Source Security, Inc.
70330 +# http://www.grsecurity.net spender@grsecurity.net
70331 +#
70332 +# This program is free software; you can redistribute it and/or
70333 +# modify it under the terms of the GNU General Public License version 2
70334 +# as published by the Free Software Foundation.
70335 +#
70336 +# This program is distributed in the hope that it will be useful,
70337 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
70338 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
70339 +# GNU General Public License for more details.
70340 +#
70341 +# You should have received a copy of the GNU General Public License
70342 +# along with this program; if not, write to the Free Software
70343 +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
70344 +
70345 +KBUILD_CFLAGS += -Werror
70346 +
70347 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
70348 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
70349 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
70350 + grsec_usb.o grsec_ipc.o grsec_proc.o
70351 +
70352 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
70353 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
70354 + gracl_learn.o grsec_log.o gracl_policy.o
70355 +ifdef CONFIG_COMPAT
70356 +obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
70357 +endif
70358 +
70359 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
70360 +
70361 +ifdef CONFIG_NET
70362 +obj-y += grsec_sock.o
70363 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
70364 +endif
70365 +
70366 +ifndef CONFIG_GRKERNSEC
70367 +obj-y += grsec_disabled.o
70368 +endif
70369 +
70370 +ifdef CONFIG_GRKERNSEC_HIDESYM
70371 +extra-y := grsec_hidesym.o
70372 +$(obj)/grsec_hidesym.o:
70373 + @-chmod -f 500 /boot
70374 + @-chmod -f 500 /lib/modules
70375 + @-chmod -f 500 /lib64/modules
70376 + @-chmod -f 500 /lib32/modules
70377 + @-chmod -f 700 .
70378 + @-chmod -f 700 $(objtree)
70379 + @echo ' grsec: protected kernel image paths'
70380 +endif
70381 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
70382 new file mode 100644
70383 index 0000000..58223f6
70384 --- /dev/null
70385 +++ b/grsecurity/gracl.c
70386 @@ -0,0 +1,2702 @@
70387 +#include <linux/kernel.h>
70388 +#include <linux/module.h>
70389 +#include <linux/sched.h>
70390 +#include <linux/mm.h>
70391 +#include <linux/file.h>
70392 +#include <linux/fs.h>
70393 +#include <linux/namei.h>
70394 +#include <linux/mount.h>
70395 +#include <linux/tty.h>
70396 +#include <linux/proc_fs.h>
70397 +#include <linux/lglock.h>
70398 +#include <linux/slab.h>
70399 +#include <linux/vmalloc.h>
70400 +#include <linux/types.h>
70401 +#include <linux/sysctl.h>
70402 +#include <linux/netdevice.h>
70403 +#include <linux/ptrace.h>
70404 +#include <linux/gracl.h>
70405 +#include <linux/gralloc.h>
70406 +#include <linux/security.h>
70407 +#include <linux/grinternal.h>
70408 +#include <linux/pid_namespace.h>
70409 +#include <linux/stop_machine.h>
70410 +#include <linux/fdtable.h>
70411 +#include <linux/percpu.h>
70412 +#include <linux/lglock.h>
70413 +#include <linux/hugetlb.h>
70414 +#include <linux/posix-timers.h>
70415 +#include <linux/prefetch.h>
70416 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
70417 +#include <linux/magic.h>
70418 +#include <linux/pagemap.h>
70419 +#include "../fs/btrfs/async-thread.h"
70420 +#include "../fs/btrfs/ctree.h"
70421 +#include "../fs/btrfs/btrfs_inode.h"
70422 +#endif
70423 +#include "../fs/mount.h"
70424 +
70425 +#include <asm/uaccess.h>
70426 +#include <asm/errno.h>
70427 +#include <asm/mman.h>
70428 +
70429 +#define FOR_EACH_ROLE_START(role) \
70430 + role = running_polstate.role_list; \
70431 + while (role) {
70432 +
70433 +#define FOR_EACH_ROLE_END(role) \
70434 + role = role->prev; \
70435 + }
70436 +
70437 +extern struct path gr_real_root;
70438 +
70439 +static struct gr_policy_state running_polstate;
70440 +struct gr_policy_state *polstate = &running_polstate;
70441 +extern struct gr_alloc_state *current_alloc_state;
70442 +
70443 +extern char *gr_shared_page[4];
70444 +DEFINE_RWLOCK(gr_inode_lock);
70445 +
70446 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
70447 +
70448 +#ifdef CONFIG_NET
70449 +extern struct vfsmount *sock_mnt;
70450 +#endif
70451 +
70452 +extern struct vfsmount *pipe_mnt;
70453 +extern struct vfsmount *shm_mnt;
70454 +
70455 +#ifdef CONFIG_HUGETLBFS
70456 +extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
70457 +#endif
70458 +
70459 +extern u16 acl_sp_role_value;
70460 +extern struct acl_object_label *fakefs_obj_rw;
70461 +extern struct acl_object_label *fakefs_obj_rwx;
70462 +
70463 +int gr_acl_is_enabled(void)
70464 +{
70465 + return (gr_status & GR_READY);
70466 +}
70467 +
70468 +void gr_enable_rbac_system(void)
70469 +{
70470 + pax_open_kernel();
70471 + gr_status |= GR_READY;
70472 + pax_close_kernel();
70473 +}
70474 +
70475 +int gr_rbac_disable(void *unused)
70476 +{
70477 + pax_open_kernel();
70478 + gr_status &= ~GR_READY;
70479 + pax_close_kernel();
70480 +
70481 + return 0;
70482 +}
70483 +
70484 +static inline dev_t __get_dev(const struct dentry *dentry)
70485 +{
70486 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
70487 + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
70488 + return BTRFS_I(dentry->d_inode)->root->anon_dev;
70489 + else
70490 +#endif
70491 + return dentry->d_sb->s_dev;
70492 +}
70493 +
70494 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
70495 +{
70496 + return __get_dev(dentry);
70497 +}
70498 +
70499 +static char gr_task_roletype_to_char(struct task_struct *task)
70500 +{
70501 + switch (task->role->roletype &
70502 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
70503 + GR_ROLE_SPECIAL)) {
70504 + case GR_ROLE_DEFAULT:
70505 + return 'D';
70506 + case GR_ROLE_USER:
70507 + return 'U';
70508 + case GR_ROLE_GROUP:
70509 + return 'G';
70510 + case GR_ROLE_SPECIAL:
70511 + return 'S';
70512 + }
70513 +
70514 + return 'X';
70515 +}
70516 +
70517 +char gr_roletype_to_char(void)
70518 +{
70519 + return gr_task_roletype_to_char(current);
70520 +}
70521 +
70522 +__inline__ int
70523 +gr_acl_tpe_check(void)
70524 +{
70525 + if (unlikely(!(gr_status & GR_READY)))
70526 + return 0;
70527 + if (current->role->roletype & GR_ROLE_TPE)
70528 + return 1;
70529 + else
70530 + return 0;
70531 +}
70532 +
70533 +int
70534 +gr_handle_rawio(const struct inode *inode)
70535 +{
70536 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
70537 + if (inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR)) &&
70538 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
70539 + !capable(CAP_SYS_RAWIO))
70540 + return 1;
70541 +#endif
70542 + return 0;
70543 +}
70544 +
70545 +int
70546 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
70547 +{
70548 + if (likely(lena != lenb))
70549 + return 0;
70550 +
70551 + return !memcmp(a, b, lena);
70552 +}
70553 +
70554 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
70555 +{
70556 + *buflen -= namelen;
70557 + if (*buflen < 0)
70558 + return -ENAMETOOLONG;
70559 + *buffer -= namelen;
70560 + memcpy(*buffer, str, namelen);
70561 + return 0;
70562 +}
70563 +
70564 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
70565 +{
70566 + return prepend(buffer, buflen, name->name, name->len);
70567 +}
70568 +
70569 +static int prepend_path(const struct path *path, struct path *root,
70570 + char **buffer, int *buflen)
70571 +{
70572 + struct dentry *dentry = path->dentry;
70573 + struct vfsmount *vfsmnt = path->mnt;
70574 + struct mount *mnt = real_mount(vfsmnt);
70575 + bool slash = false;
70576 + int error = 0;
70577 +
70578 + while (dentry != root->dentry || vfsmnt != root->mnt) {
70579 + struct dentry * parent;
70580 +
70581 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
70582 + /* Global root? */
70583 + if (!mnt_has_parent(mnt)) {
70584 + goto out;
70585 + }
70586 + dentry = mnt->mnt_mountpoint;
70587 + mnt = mnt->mnt_parent;
70588 + vfsmnt = &mnt->mnt;
70589 + continue;
70590 + }
70591 + parent = dentry->d_parent;
70592 + prefetch(parent);
70593 + spin_lock(&dentry->d_lock);
70594 + error = prepend_name(buffer, buflen, &dentry->d_name);
70595 + spin_unlock(&dentry->d_lock);
70596 + if (!error)
70597 + error = prepend(buffer, buflen, "/", 1);
70598 + if (error)
70599 + break;
70600 +
70601 + slash = true;
70602 + dentry = parent;
70603 + }
70604 +
70605 +out:
70606 + if (!error && !slash)
70607 + error = prepend(buffer, buflen, "/", 1);
70608 +
70609 + return error;
70610 +}
70611 +
70612 +/* this must be called with mount_lock and rename_lock held */
70613 +
70614 +static char *__our_d_path(const struct path *path, struct path *root,
70615 + char *buf, int buflen)
70616 +{
70617 + char *res = buf + buflen;
70618 + int error;
70619 +
70620 + prepend(&res, &buflen, "\0", 1);
70621 + error = prepend_path(path, root, &res, &buflen);
70622 + if (error)
70623 + return ERR_PTR(error);
70624 +
70625 + return res;
70626 +}
70627 +
70628 +static char *
70629 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
70630 +{
70631 + char *retval;
70632 +
70633 + retval = __our_d_path(path, root, buf, buflen);
70634 + if (unlikely(IS_ERR(retval)))
70635 + retval = strcpy(buf, "<path too long>");
70636 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
70637 + retval[1] = '\0';
70638 +
70639 + return retval;
70640 +}
70641 +
70642 +static char *
70643 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
70644 + char *buf, int buflen)
70645 +{
70646 + struct path path;
70647 + char *res;
70648 +
70649 + path.dentry = (struct dentry *)dentry;
70650 + path.mnt = (struct vfsmount *)vfsmnt;
70651 +
70652 + /* we can use gr_real_root.dentry, gr_real_root.mnt, because this is only called
70653 + by the RBAC system */
70654 + res = gen_full_path(&path, &gr_real_root, buf, buflen);
70655 +
70656 + return res;
70657 +}
70658 +
70659 +static char *
70660 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
70661 + char *buf, int buflen)
70662 +{
70663 + char *res;
70664 + struct path path;
70665 + struct path root;
70666 + struct task_struct *reaper = init_pid_ns.child_reaper;
70667 +
70668 + path.dentry = (struct dentry *)dentry;
70669 + path.mnt = (struct vfsmount *)vfsmnt;
70670 +
70671 + /* we can't use gr_real_root.dentry, gr_real_root.mnt, because they belong only to the RBAC system */
70672 + get_fs_root(reaper->fs, &root);
70673 +
70674 + read_seqlock_excl(&mount_lock);
70675 + write_seqlock(&rename_lock);
70676 + res = gen_full_path(&path, &root, buf, buflen);
70677 + write_sequnlock(&rename_lock);
70678 + read_sequnlock_excl(&mount_lock);
70679 +
70680 + path_put(&root);
70681 + return res;
70682 +}
70683 +
70684 +char *
70685 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
70686 +{
70687 + char *ret;
70688 + read_seqlock_excl(&mount_lock);
70689 + write_seqlock(&rename_lock);
70690 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
70691 + PAGE_SIZE);
70692 + write_sequnlock(&rename_lock);
70693 + read_sequnlock_excl(&mount_lock);
70694 + return ret;
70695 +}
70696 +
70697 +static char *
70698 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
70699 +{
70700 + char *ret;
70701 + char *buf;
70702 + int buflen;
70703 +
70704 + read_seqlock_excl(&mount_lock);
70705 + write_seqlock(&rename_lock);
70706 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
70707 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
70708 + buflen = (int)(ret - buf);
70709 + if (buflen >= 5)
70710 + prepend(&ret, &buflen, "/proc", 5);
70711 + else
70712 + ret = strcpy(buf, "<path too long>");
70713 + write_sequnlock(&rename_lock);
70714 + read_sequnlock_excl(&mount_lock);
70715 + return ret;
70716 +}
70717 +
70718 +char *
70719 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
70720 +{
70721 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
70722 + PAGE_SIZE);
70723 +}
70724 +
70725 +char *
70726 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
70727 +{
70728 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
70729 + PAGE_SIZE);
70730 +}
70731 +
70732 +char *
70733 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
70734 +{
70735 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
70736 + PAGE_SIZE);
70737 +}
70738 +
70739 +char *
70740 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
70741 +{
70742 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
70743 + PAGE_SIZE);
70744 +}
70745 +
70746 +char *
70747 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
70748 +{
70749 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
70750 + PAGE_SIZE);
70751 +}
70752 +
70753 +__inline__ __u32
70754 +to_gr_audit(const __u32 reqmode)
70755 +{
70756 + /* masks off auditable permission flags, then shifts them to create
70757 + auditing flags, and adds the special case of append auditing if
70758 + we're requesting write */
70759 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
70760 +}
70761 +
70762 +struct acl_role_label *
70763 +__lookup_acl_role_label(const struct gr_policy_state *state, const struct task_struct *task, const uid_t uid,
70764 + const gid_t gid)
70765 +{
70766 + unsigned int index = gr_rhash(uid, GR_ROLE_USER, state->acl_role_set.r_size);
70767 + struct acl_role_label *match;
70768 + struct role_allowed_ip *ipp;
70769 + unsigned int x;
70770 + u32 curr_ip = task->signal->saved_ip;
70771 +
70772 + match = state->acl_role_set.r_hash[index];
70773 +
70774 + while (match) {
70775 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
70776 + for (x = 0; x < match->domain_child_num; x++) {
70777 + if (match->domain_children[x] == uid)
70778 + goto found;
70779 + }
70780 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
70781 + break;
70782 + match = match->next;
70783 + }
70784 +found:
70785 + if (match == NULL) {
70786 + try_group:
70787 + index = gr_rhash(gid, GR_ROLE_GROUP, state->acl_role_set.r_size);
70788 + match = state->acl_role_set.r_hash[index];
70789 +
70790 + while (match) {
70791 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
70792 + for (x = 0; x < match->domain_child_num; x++) {
70793 + if (match->domain_children[x] == gid)
70794 + goto found2;
70795 + }
70796 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
70797 + break;
70798 + match = match->next;
70799 + }
70800 +found2:
70801 + if (match == NULL)
70802 + match = state->default_role;
70803 + if (match->allowed_ips == NULL)
70804 + return match;
70805 + else {
70806 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
70807 + if (likely
70808 + ((ntohl(curr_ip) & ipp->netmask) ==
70809 + (ntohl(ipp->addr) & ipp->netmask)))
70810 + return match;
70811 + }
70812 + match = state->default_role;
70813 + }
70814 + } else if (match->allowed_ips == NULL) {
70815 + return match;
70816 + } else {
70817 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
70818 + if (likely
70819 + ((ntohl(curr_ip) & ipp->netmask) ==
70820 + (ntohl(ipp->addr) & ipp->netmask)))
70821 + return match;
70822 + }
70823 + goto try_group;
70824 + }
70825 +
70826 + return match;
70827 +}
70828 +
70829 +static struct acl_role_label *
70830 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
70831 + const gid_t gid)
70832 +{
70833 + return __lookup_acl_role_label(&running_polstate, task, uid, gid);
70834 +}
70835 +
70836 +struct acl_subject_label *
70837 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
70838 + const struct acl_role_label *role)
70839 +{
70840 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
70841 + struct acl_subject_label *match;
70842 +
70843 + match = role->subj_hash[index];
70844 +
70845 + while (match && (match->inode != ino || match->device != dev ||
70846 + (match->mode & GR_DELETED))) {
70847 + match = match->next;
70848 + }
70849 +
70850 + if (match && !(match->mode & GR_DELETED))
70851 + return match;
70852 + else
70853 + return NULL;
70854 +}
70855 +
70856 +struct acl_subject_label *
70857 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
70858 + const struct acl_role_label *role)
70859 +{
70860 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
70861 + struct acl_subject_label *match;
70862 +
70863 + match = role->subj_hash[index];
70864 +
70865 + while (match && (match->inode != ino || match->device != dev ||
70866 + !(match->mode & GR_DELETED))) {
70867 + match = match->next;
70868 + }
70869 +
70870 + if (match && (match->mode & GR_DELETED))
70871 + return match;
70872 + else
70873 + return NULL;
70874 +}
70875 +
70876 +static struct acl_object_label *
70877 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
70878 + const struct acl_subject_label *subj)
70879 +{
70880 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
70881 + struct acl_object_label *match;
70882 +
70883 + match = subj->obj_hash[index];
70884 +
70885 + while (match && (match->inode != ino || match->device != dev ||
70886 + (match->mode & GR_DELETED))) {
70887 + match = match->next;
70888 + }
70889 +
70890 + if (match && !(match->mode & GR_DELETED))
70891 + return match;
70892 + else
70893 + return NULL;
70894 +}
70895 +
70896 +static struct acl_object_label *
70897 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
70898 + const struct acl_subject_label *subj)
70899 +{
70900 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
70901 + struct acl_object_label *match;
70902 +
70903 + match = subj->obj_hash[index];
70904 +
70905 + while (match && (match->inode != ino || match->device != dev ||
70906 + !(match->mode & GR_DELETED))) {
70907 + match = match->next;
70908 + }
70909 +
70910 + if (match && (match->mode & GR_DELETED))
70911 + return match;
70912 +
70913 + match = subj->obj_hash[index];
70914 +
70915 + while (match && (match->inode != ino || match->device != dev ||
70916 + (match->mode & GR_DELETED))) {
70917 + match = match->next;
70918 + }
70919 +
70920 + if (match && !(match->mode & GR_DELETED))
70921 + return match;
70922 + else
70923 + return NULL;
70924 +}
70925 +
70926 +struct name_entry *
70927 +__lookup_name_entry(const struct gr_policy_state *state, const char *name)
70928 +{
70929 + unsigned int len = strlen(name);
70930 + unsigned int key = full_name_hash(name, len);
70931 + unsigned int index = key % state->name_set.n_size;
70932 + struct name_entry *match;
70933 +
70934 + match = state->name_set.n_hash[index];
70935 +
70936 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
70937 + match = match->next;
70938 +
70939 + return match;
70940 +}
70941 +
70942 +static struct name_entry *
70943 +lookup_name_entry(const char *name)
70944 +{
70945 + return __lookup_name_entry(&running_polstate, name);
70946 +}
70947 +
70948 +static struct name_entry *
70949 +lookup_name_entry_create(const char *name)
70950 +{
70951 + unsigned int len = strlen(name);
70952 + unsigned int key = full_name_hash(name, len);
70953 + unsigned int index = key % running_polstate.name_set.n_size;
70954 + struct name_entry *match;
70955 +
70956 + match = running_polstate.name_set.n_hash[index];
70957 +
70958 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
70959 + !match->deleted))
70960 + match = match->next;
70961 +
70962 + if (match && match->deleted)
70963 + return match;
70964 +
70965 + match = running_polstate.name_set.n_hash[index];
70966 +
70967 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
70968 + match->deleted))
70969 + match = match->next;
70970 +
70971 + if (match && !match->deleted)
70972 + return match;
70973 + else
70974 + return NULL;
70975 +}
70976 +
70977 +static struct inodev_entry *
70978 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
70979 +{
70980 + unsigned int index = gr_fhash(ino, dev, running_polstate.inodev_set.i_size);
70981 + struct inodev_entry *match;
70982 +
70983 + match = running_polstate.inodev_set.i_hash[index];
70984 +
70985 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
70986 + match = match->next;
70987 +
70988 + return match;
70989 +}
70990 +
70991 +void
70992 +__insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry)
70993 +{
70994 + unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
70995 + state->inodev_set.i_size);
70996 + struct inodev_entry **curr;
70997 +
70998 + entry->prev = NULL;
70999 +
71000 + curr = &state->inodev_set.i_hash[index];
71001 + if (*curr != NULL)
71002 + (*curr)->prev = entry;
71003 +
71004 + entry->next = *curr;
71005 + *curr = entry;
71006 +
71007 + return;
71008 +}
71009 +
71010 +static void
71011 +insert_inodev_entry(struct inodev_entry *entry)
71012 +{
71013 + __insert_inodev_entry(&running_polstate, entry);
71014 +}
71015 +
71016 +void
71017 +insert_acl_obj_label(struct acl_object_label *obj,
71018 + struct acl_subject_label *subj)
71019 +{
71020 + unsigned int index =
71021 + gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
71022 + struct acl_object_label **curr;
71023 +
71024 + obj->prev = NULL;
71025 +
71026 + curr = &subj->obj_hash[index];
71027 + if (*curr != NULL)
71028 + (*curr)->prev = obj;
71029 +
71030 + obj->next = *curr;
71031 + *curr = obj;
71032 +
71033 + return;
71034 +}
71035 +
71036 +void
71037 +insert_acl_subj_label(struct acl_subject_label *obj,
71038 + struct acl_role_label *role)
71039 +{
71040 + unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
71041 + struct acl_subject_label **curr;
71042 +
71043 + obj->prev = NULL;
71044 +
71045 + curr = &role->subj_hash[index];
71046 + if (*curr != NULL)
71047 + (*curr)->prev = obj;
71048 +
71049 + obj->next = *curr;
71050 + *curr = obj;
71051 +
71052 + return;
71053 +}
71054 +
71055 +/* derived from glibc fnmatch() 0: match, 1: no match*/
71056 +
71057 +static int
71058 +glob_match(const char *p, const char *n)
71059 +{
71060 + char c;
71061 +
71062 + while ((c = *p++) != '\0') {
71063 + switch (c) {
71064 + case '?':
71065 + if (*n == '\0')
71066 + return 1;
71067 + else if (*n == '/')
71068 + return 1;
71069 + break;
71070 + case '\\':
71071 + if (*n != c)
71072 + return 1;
71073 + break;
71074 + case '*':
71075 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
71076 + if (*n == '/')
71077 + return 1;
71078 + else if (c == '?') {
71079 + if (*n == '\0')
71080 + return 1;
71081 + else
71082 + ++n;
71083 + }
71084 + }
71085 + if (c == '\0') {
71086 + return 0;
71087 + } else {
71088 + const char *endp;
71089 +
71090 + if ((endp = strchr(n, '/')) == NULL)
71091 + endp = n + strlen(n);
71092 +
71093 + if (c == '[') {
71094 + for (--p; n < endp; ++n)
71095 + if (!glob_match(p, n))
71096 + return 0;
71097 + } else if (c == '/') {
71098 + while (*n != '\0' && *n != '/')
71099 + ++n;
71100 + if (*n == '/' && !glob_match(p, n + 1))
71101 + return 0;
71102 + } else {
71103 + for (--p; n < endp; ++n)
71104 + if (*n == c && !glob_match(p, n))
71105 + return 0;
71106 + }
71107 +
71108 + return 1;
71109 + }
71110 + case '[':
71111 + {
71112 + int not;
71113 + char cold;
71114 +
71115 + if (*n == '\0' || *n == '/')
71116 + return 1;
71117 +
71118 + not = (*p == '!' || *p == '^');
71119 + if (not)
71120 + ++p;
71121 +
71122 + c = *p++;
71123 + for (;;) {
71124 + unsigned char fn = (unsigned char)*n;
71125 +
71126 + if (c == '\0')
71127 + return 1;
71128 + else {
71129 + if (c == fn)
71130 + goto matched;
71131 + cold = c;
71132 + c = *p++;
71133 +
71134 + if (c == '-' && *p != ']') {
71135 + unsigned char cend = *p++;
71136 +
71137 + if (cend == '\0')
71138 + return 1;
71139 +
71140 + if (cold <= fn && fn <= cend)
71141 + goto matched;
71142 +
71143 + c = *p++;
71144 + }
71145 + }
71146 +
71147 + if (c == ']')
71148 + break;
71149 + }
71150 + if (!not)
71151 + return 1;
71152 + break;
71153 + matched:
71154 + while (c != ']') {
71155 + if (c == '\0')
71156 + return 1;
71157 +
71158 + c = *p++;
71159 + }
71160 + if (not)
71161 + return 1;
71162 + }
71163 + break;
71164 + default:
71165 + if (c != *n)
71166 + return 1;
71167 + }
71168 +
71169 + ++n;
71170 + }
71171 +
71172 + if (*n == '\0')
71173 + return 0;
71174 +
71175 + if (*n == '/')
71176 + return 0;
71177 +
71178 + return 1;
71179 +}
71180 +
71181 +static struct acl_object_label *
71182 +chk_glob_label(struct acl_object_label *globbed,
71183 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
71184 +{
71185 + struct acl_object_label *tmp;
71186 +
71187 + if (*path == NULL)
71188 + *path = gr_to_filename_nolock(dentry, mnt);
71189 +
71190 + tmp = globbed;
71191 +
71192 + while (tmp) {
71193 + if (!glob_match(tmp->filename, *path))
71194 + return tmp;
71195 + tmp = tmp->next;
71196 + }
71197 +
71198 + return NULL;
71199 +}
71200 +
71201 +static struct acl_object_label *
71202 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
71203 + const ino_t curr_ino, const dev_t curr_dev,
71204 + const struct acl_subject_label *subj, char **path, const int checkglob)
71205 +{
71206 + struct acl_subject_label *tmpsubj;
71207 + struct acl_object_label *retval;
71208 + struct acl_object_label *retval2;
71209 +
71210 + tmpsubj = (struct acl_subject_label *) subj;
71211 + read_lock(&gr_inode_lock);
71212 + do {
71213 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
71214 + if (retval) {
71215 + if (checkglob && retval->globbed) {
71216 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
71217 + if (retval2)
71218 + retval = retval2;
71219 + }
71220 + break;
71221 + }
71222 + } while ((tmpsubj = tmpsubj->parent_subject));
71223 + read_unlock(&gr_inode_lock);
71224 +
71225 + return retval;
71226 +}
71227 +
71228 +static __inline__ struct acl_object_label *
71229 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
71230 + struct dentry *curr_dentry,
71231 + const struct acl_subject_label *subj, char **path, const int checkglob)
71232 +{
71233 + int newglob = checkglob;
71234 + ino_t inode;
71235 + dev_t device;
71236 +
71237 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
71238 + as we don't want a / * rule to match instead of the / object
71239 + don't do this for create lookups that call this function though, since they're looking up
71240 + on the parent and thus need globbing checks on all paths
71241 + */
71242 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
71243 + newglob = GR_NO_GLOB;
71244 +
71245 + spin_lock(&curr_dentry->d_lock);
71246 + inode = curr_dentry->d_inode->i_ino;
71247 + device = __get_dev(curr_dentry);
71248 + spin_unlock(&curr_dentry->d_lock);
71249 +
71250 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
71251 +}
71252 +
71253 +#ifdef CONFIG_HUGETLBFS
71254 +static inline bool
71255 +is_hugetlbfs_mnt(const struct vfsmount *mnt)
71256 +{
71257 + int i;
71258 + for (i = 0; i < HUGE_MAX_HSTATE; i++) {
71259 + if (unlikely(hugetlbfs_vfsmount[i] == mnt))
71260 + return true;
71261 + }
71262 +
71263 + return false;
71264 +}
71265 +#endif
71266 +
71267 +static struct acl_object_label *
71268 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
71269 + const struct acl_subject_label *subj, char *path, const int checkglob)
71270 +{
71271 + struct dentry *dentry = (struct dentry *) l_dentry;
71272 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
71273 + struct mount *real_mnt = real_mount(mnt);
71274 + struct acl_object_label *retval;
71275 + struct dentry *parent;
71276 +
71277 + read_seqlock_excl(&mount_lock);
71278 + write_seqlock(&rename_lock);
71279 +
71280 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
71281 +#ifdef CONFIG_NET
71282 + mnt == sock_mnt ||
71283 +#endif
71284 +#ifdef CONFIG_HUGETLBFS
71285 + (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
71286 +#endif
71287 + /* ignore Eric Biederman */
71288 + IS_PRIVATE(l_dentry->d_inode))) {
71289 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
71290 + goto out;
71291 + }
71292 +
71293 + for (;;) {
71294 + if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
71295 + break;
71296 +
71297 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
71298 + if (!mnt_has_parent(real_mnt))
71299 + break;
71300 +
71301 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
71302 + if (retval != NULL)
71303 + goto out;
71304 +
71305 + dentry = real_mnt->mnt_mountpoint;
71306 + real_mnt = real_mnt->mnt_parent;
71307 + mnt = &real_mnt->mnt;
71308 + continue;
71309 + }
71310 +
71311 + parent = dentry->d_parent;
71312 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
71313 + if (retval != NULL)
71314 + goto out;
71315 +
71316 + dentry = parent;
71317 + }
71318 +
71319 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
71320 +
71321 + /* gr_real_root is pinned so we don't have to hold a reference */
71322 + if (retval == NULL)
71323 + retval = full_lookup(l_dentry, l_mnt, gr_real_root.dentry, subj, &path, checkglob);
71324 +out:
71325 + write_sequnlock(&rename_lock);
71326 + read_sequnlock_excl(&mount_lock);
71327 +
71328 + BUG_ON(retval == NULL);
71329 +
71330 + return retval;
71331 +}
71332 +
71333 +static __inline__ struct acl_object_label *
71334 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
71335 + const struct acl_subject_label *subj)
71336 +{
71337 + char *path = NULL;
71338 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
71339 +}
71340 +
71341 +static __inline__ struct acl_object_label *
71342 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
71343 + const struct acl_subject_label *subj)
71344 +{
71345 + char *path = NULL;
71346 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
71347 +}
71348 +
71349 +static __inline__ struct acl_object_label *
71350 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
71351 + const struct acl_subject_label *subj, char *path)
71352 +{
71353 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
71354 +}
71355 +
71356 +struct acl_subject_label *
71357 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
71358 + const struct acl_role_label *role)
71359 +{
71360 + struct dentry *dentry = (struct dentry *) l_dentry;
71361 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
71362 + struct mount *real_mnt = real_mount(mnt);
71363 + struct acl_subject_label *retval;
71364 + struct dentry *parent;
71365 +
71366 + read_seqlock_excl(&mount_lock);
71367 + write_seqlock(&rename_lock);
71368 +
71369 + for (;;) {
71370 + if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
71371 + break;
71372 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
71373 + if (!mnt_has_parent(real_mnt))
71374 + break;
71375 +
71376 + spin_lock(&dentry->d_lock);
71377 + read_lock(&gr_inode_lock);
71378 + retval =
71379 + lookup_acl_subj_label(dentry->d_inode->i_ino,
71380 + __get_dev(dentry), role);
71381 + read_unlock(&gr_inode_lock);
71382 + spin_unlock(&dentry->d_lock);
71383 + if (retval != NULL)
71384 + goto out;
71385 +
71386 + dentry = real_mnt->mnt_mountpoint;
71387 + real_mnt = real_mnt->mnt_parent;
71388 + mnt = &real_mnt->mnt;
71389 + continue;
71390 + }
71391 +
71392 + spin_lock(&dentry->d_lock);
71393 + read_lock(&gr_inode_lock);
71394 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
71395 + __get_dev(dentry), role);
71396 + read_unlock(&gr_inode_lock);
71397 + parent = dentry->d_parent;
71398 + spin_unlock(&dentry->d_lock);
71399 +
71400 + if (retval != NULL)
71401 + goto out;
71402 +
71403 + dentry = parent;
71404 + }
71405 +
71406 + spin_lock(&dentry->d_lock);
71407 + read_lock(&gr_inode_lock);
71408 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
71409 + __get_dev(dentry), role);
71410 + read_unlock(&gr_inode_lock);
71411 + spin_unlock(&dentry->d_lock);
71412 +
71413 + if (unlikely(retval == NULL)) {
71414 + /* gr_real_root is pinned, we don't need to hold a reference */
71415 + read_lock(&gr_inode_lock);
71416 + retval = lookup_acl_subj_label(gr_real_root.dentry->d_inode->i_ino,
71417 + __get_dev(gr_real_root.dentry), role);
71418 + read_unlock(&gr_inode_lock);
71419 + }
71420 +out:
71421 + write_sequnlock(&rename_lock);
71422 + read_sequnlock_excl(&mount_lock);
71423 +
71424 + BUG_ON(retval == NULL);
71425 +
71426 + return retval;
71427 +}
71428 +
71429 +void
71430 +assign_special_role(const char *rolename)
71431 +{
71432 + struct acl_object_label *obj;
71433 + struct acl_role_label *r;
71434 + struct acl_role_label *assigned = NULL;
71435 + struct task_struct *tsk;
71436 + struct file *filp;
71437 +
71438 + FOR_EACH_ROLE_START(r)
71439 + if (!strcmp(rolename, r->rolename) &&
71440 + (r->roletype & GR_ROLE_SPECIAL)) {
71441 + assigned = r;
71442 + break;
71443 + }
71444 + FOR_EACH_ROLE_END(r)
71445 +
71446 + if (!assigned)
71447 + return;
71448 +
71449 + read_lock(&tasklist_lock);
71450 + read_lock(&grsec_exec_file_lock);
71451 +
71452 + tsk = current->real_parent;
71453 + if (tsk == NULL)
71454 + goto out_unlock;
71455 +
71456 + filp = tsk->exec_file;
71457 + if (filp == NULL)
71458 + goto out_unlock;
71459 +
71460 + tsk->is_writable = 0;
71461 + tsk->inherited = 0;
71462 +
71463 + tsk->acl_sp_role = 1;
71464 + tsk->acl_role_id = ++acl_sp_role_value;
71465 + tsk->role = assigned;
71466 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
71467 +
71468 + /* ignore additional mmap checks for processes that are writable
71469 + by the default ACL */
71470 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
71471 + if (unlikely(obj->mode & GR_WRITE))
71472 + tsk->is_writable = 1;
71473 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
71474 + if (unlikely(obj->mode & GR_WRITE))
71475 + tsk->is_writable = 1;
71476 +
71477 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71478 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename,
71479 + tsk->acl->filename, tsk->comm, task_pid_nr(tsk));
71480 +#endif
71481 +
71482 +out_unlock:
71483 + read_unlock(&grsec_exec_file_lock);
71484 + read_unlock(&tasklist_lock);
71485 + return;
71486 +}
71487 +
71488 +
71489 +static void
71490 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
71491 +{
71492 + struct task_struct *task = current;
71493 + const struct cred *cred = current_cred();
71494 +
71495 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
71496 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
71497 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
71498 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
71499 +
71500 + return;
71501 +}
71502 +
71503 +static void
71504 +gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
71505 +{
71506 + struct task_struct *task = current;
71507 + const struct cred *cred = current_cred();
71508 +
71509 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
71510 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
71511 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
71512 + 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
71513 +
71514 + return;
71515 +}
71516 +
71517 +static void
71518 +gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
71519 +{
71520 + struct task_struct *task = current;
71521 + const struct cred *cred = current_cred();
71522 +
71523 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
71524 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
71525 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
71526 + 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
71527 +
71528 + return;
71529 +}
71530 +
71531 +static void
71532 +gr_set_proc_res(struct task_struct *task)
71533 +{
71534 + struct acl_subject_label *proc;
71535 + unsigned short i;
71536 +
71537 + proc = task->acl;
71538 +
71539 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
71540 + return;
71541 +
71542 + for (i = 0; i < RLIM_NLIMITS; i++) {
71543 + if (!(proc->resmask & (1U << i)))
71544 + continue;
71545 +
71546 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
71547 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
71548 +
71549 + if (i == RLIMIT_CPU)
71550 + update_rlimit_cpu(task, proc->res[i].rlim_cur);
71551 + }
71552 +
71553 + return;
71554 +}
71555 +
71556 +/* both of the below must be called with
71557 + rcu_read_lock();
71558 + read_lock(&tasklist_lock);
71559 + read_lock(&grsec_exec_file_lock);
71560 +*/
71561 +
71562 +struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename)
71563 +{
71564 + char *tmpname;
71565 + struct acl_subject_label *tmpsubj;
71566 + struct file *filp;
71567 + struct name_entry *nmatch;
71568 +
71569 + filp = task->exec_file;
71570 + if (filp == NULL)
71571 + return NULL;
71572 +
71573 + /* the following is to apply the correct subject
71574 + on binaries running when the RBAC system
71575 + is enabled, when the binaries have been
71576 + replaced or deleted since their execution
71577 + -----
71578 + when the RBAC system starts, the inode/dev
71579 + from exec_file will be one the RBAC system
71580 + is unaware of. It only knows the inode/dev
71581 + of the present file on disk, or the absence
71582 + of it.
71583 + */
71584 +
71585 + if (filename)
71586 + nmatch = __lookup_name_entry(state, filename);
71587 + else {
71588 + preempt_disable();
71589 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
71590 +
71591 + nmatch = __lookup_name_entry(state, tmpname);
71592 + preempt_enable();
71593 + }
71594 + tmpsubj = NULL;
71595 + if (nmatch) {
71596 + if (nmatch->deleted)
71597 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
71598 + else
71599 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
71600 + }
71601 + /* this also works for the reload case -- if we don't match a potentially inherited subject
71602 + then we fall back to a normal lookup based on the binary's ino/dev
71603 + */
71604 + if (tmpsubj == NULL)
71605 + tmpsubj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, task->role);
71606 +
71607 + return tmpsubj;
71608 +}
71609 +
71610 +static struct acl_subject_label *gr_get_subject_for_task(struct task_struct *task, const char *filename)
71611 +{
71612 + return __gr_get_subject_for_task(&running_polstate, task, filename);
71613 +}
71614 +
71615 +void __gr_apply_subject_to_task(const struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj)
71616 +{
71617 + struct acl_object_label *obj;
71618 + struct file *filp;
71619 +
71620 + filp = task->exec_file;
71621 +
71622 + task->acl = subj;
71623 + task->is_writable = 0;
71624 + /* ignore additional mmap checks for processes that are writable
71625 + by the default ACL */
71626 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, state->default_role->root_label);
71627 + if (unlikely(obj->mode & GR_WRITE))
71628 + task->is_writable = 1;
71629 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
71630 + if (unlikely(obj->mode & GR_WRITE))
71631 + task->is_writable = 1;
71632 +
71633 + gr_set_proc_res(task);
71634 +
71635 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71636 + 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);
71637 +#endif
71638 +}
71639 +
71640 +static void gr_apply_subject_to_task(struct task_struct *task, struct acl_subject_label *subj)
71641 +{
71642 + __gr_apply_subject_to_task(&running_polstate, task, subj);
71643 +}
71644 +
71645 +__u32
71646 +gr_search_file(const struct dentry * dentry, const __u32 mode,
71647 + const struct vfsmount * mnt)
71648 +{
71649 + __u32 retval = mode;
71650 + struct acl_subject_label *curracl;
71651 + struct acl_object_label *currobj;
71652 +
71653 + if (unlikely(!(gr_status & GR_READY)))
71654 + return (mode & ~GR_AUDITS);
71655 +
71656 + curracl = current->acl;
71657 +
71658 + currobj = chk_obj_label(dentry, mnt, curracl);
71659 + retval = currobj->mode & mode;
71660 +
71661 + /* if we're opening a specified transfer file for writing
71662 + (e.g. /dev/initctl), then transfer our role to init
71663 + */
71664 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
71665 + current->role->roletype & GR_ROLE_PERSIST)) {
71666 + struct task_struct *task = init_pid_ns.child_reaper;
71667 +
71668 + if (task->role != current->role) {
71669 + struct acl_subject_label *subj;
71670 +
71671 + task->acl_sp_role = 0;
71672 + task->acl_role_id = current->acl_role_id;
71673 + task->role = current->role;
71674 + rcu_read_lock();
71675 + read_lock(&grsec_exec_file_lock);
71676 + subj = gr_get_subject_for_task(task, NULL);
71677 + gr_apply_subject_to_task(task, subj);
71678 + read_unlock(&grsec_exec_file_lock);
71679 + rcu_read_unlock();
71680 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
71681 + }
71682 + }
71683 +
71684 + if (unlikely
71685 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
71686 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
71687 + __u32 new_mode = mode;
71688 +
71689 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
71690 +
71691 + retval = new_mode;
71692 +
71693 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
71694 + new_mode |= GR_INHERIT;
71695 +
71696 + if (!(mode & GR_NOLEARN))
71697 + gr_log_learn(dentry, mnt, new_mode);
71698 + }
71699 +
71700 + return retval;
71701 +}
71702 +
71703 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
71704 + const struct dentry *parent,
71705 + const struct vfsmount *mnt)
71706 +{
71707 + struct name_entry *match;
71708 + struct acl_object_label *matchpo;
71709 + struct acl_subject_label *curracl;
71710 + char *path;
71711 +
71712 + if (unlikely(!(gr_status & GR_READY)))
71713 + return NULL;
71714 +
71715 + preempt_disable();
71716 + path = gr_to_filename_rbac(new_dentry, mnt);
71717 + match = lookup_name_entry_create(path);
71718 +
71719 + curracl = current->acl;
71720 +
71721 + if (match) {
71722 + read_lock(&gr_inode_lock);
71723 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
71724 + read_unlock(&gr_inode_lock);
71725 +
71726 + if (matchpo) {
71727 + preempt_enable();
71728 + return matchpo;
71729 + }
71730 + }
71731 +
71732 + // lookup parent
71733 +
71734 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
71735 +
71736 + preempt_enable();
71737 + return matchpo;
71738 +}
71739 +
71740 +__u32
71741 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
71742 + const struct vfsmount * mnt, const __u32 mode)
71743 +{
71744 + struct acl_object_label *matchpo;
71745 + __u32 retval;
71746 +
71747 + if (unlikely(!(gr_status & GR_READY)))
71748 + return (mode & ~GR_AUDITS);
71749 +
71750 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
71751 +
71752 + retval = matchpo->mode & mode;
71753 +
71754 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
71755 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
71756 + __u32 new_mode = mode;
71757 +
71758 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
71759 +
71760 + gr_log_learn(new_dentry, mnt, new_mode);
71761 + return new_mode;
71762 + }
71763 +
71764 + return retval;
71765 +}
71766 +
71767 +__u32
71768 +gr_check_link(const struct dentry * new_dentry,
71769 + const struct dentry * parent_dentry,
71770 + const struct vfsmount * parent_mnt,
71771 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
71772 +{
71773 + struct acl_object_label *obj;
71774 + __u32 oldmode, newmode;
71775 + __u32 needmode;
71776 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
71777 + GR_DELETE | GR_INHERIT;
71778 +
71779 + if (unlikely(!(gr_status & GR_READY)))
71780 + return (GR_CREATE | GR_LINK);
71781 +
71782 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
71783 + oldmode = obj->mode;
71784 +
71785 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
71786 + newmode = obj->mode;
71787 +
71788 + needmode = newmode & checkmodes;
71789 +
71790 + // old name for hardlink must have at least the permissions of the new name
71791 + if ((oldmode & needmode) != needmode)
71792 + goto bad;
71793 +
71794 + // if old name had restrictions/auditing, make sure the new name does as well
71795 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
71796 +
71797 + // don't allow hardlinking of suid/sgid/fcapped files without permission
71798 + if (is_privileged_binary(old_dentry))
71799 + needmode |= GR_SETID;
71800 +
71801 + if ((newmode & needmode) != needmode)
71802 + goto bad;
71803 +
71804 + // enforce minimum permissions
71805 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
71806 + return newmode;
71807 +bad:
71808 + needmode = oldmode;
71809 + if (is_privileged_binary(old_dentry))
71810 + needmode |= GR_SETID;
71811 +
71812 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
71813 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
71814 + return (GR_CREATE | GR_LINK);
71815 + } else if (newmode & GR_SUPPRESS)
71816 + return GR_SUPPRESS;
71817 + else
71818 + return 0;
71819 +}
71820 +
71821 +int
71822 +gr_check_hidden_task(const struct task_struct *task)
71823 +{
71824 + if (unlikely(!(gr_status & GR_READY)))
71825 + return 0;
71826 +
71827 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
71828 + return 1;
71829 +
71830 + return 0;
71831 +}
71832 +
71833 +int
71834 +gr_check_protected_task(const struct task_struct *task)
71835 +{
71836 + if (unlikely(!(gr_status & GR_READY) || !task))
71837 + return 0;
71838 +
71839 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
71840 + task->acl != current->acl)
71841 + return 1;
71842 +
71843 + return 0;
71844 +}
71845 +
71846 +int
71847 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
71848 +{
71849 + struct task_struct *p;
71850 + int ret = 0;
71851 +
71852 + if (unlikely(!(gr_status & GR_READY) || !pid))
71853 + return ret;
71854 +
71855 + read_lock(&tasklist_lock);
71856 + do_each_pid_task(pid, type, p) {
71857 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
71858 + p->acl != current->acl) {
71859 + ret = 1;
71860 + goto out;
71861 + }
71862 + } while_each_pid_task(pid, type, p);
71863 +out:
71864 + read_unlock(&tasklist_lock);
71865 +
71866 + return ret;
71867 +}
71868 +
71869 +void
71870 +gr_copy_label(struct task_struct *tsk)
71871 +{
71872 + struct task_struct *p = current;
71873 +
71874 + tsk->inherited = p->inherited;
71875 + tsk->acl_sp_role = 0;
71876 + tsk->acl_role_id = p->acl_role_id;
71877 + tsk->acl = p->acl;
71878 + tsk->role = p->role;
71879 + tsk->signal->used_accept = 0;
71880 + tsk->signal->curr_ip = p->signal->curr_ip;
71881 + tsk->signal->saved_ip = p->signal->saved_ip;
71882 + if (p->exec_file)
71883 + get_file(p->exec_file);
71884 + tsk->exec_file = p->exec_file;
71885 + tsk->is_writable = p->is_writable;
71886 + if (unlikely(p->signal->used_accept)) {
71887 + p->signal->curr_ip = 0;
71888 + p->signal->saved_ip = 0;
71889 + }
71890 +
71891 + return;
71892 +}
71893 +
71894 +extern int gr_process_kernel_setuid_ban(struct user_struct *user);
71895 +
71896 +int
71897 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
71898 +{
71899 + unsigned int i;
71900 + __u16 num;
71901 + uid_t *uidlist;
71902 + uid_t curuid;
71903 + int realok = 0;
71904 + int effectiveok = 0;
71905 + int fsok = 0;
71906 + uid_t globalreal, globaleffective, globalfs;
71907 +
71908 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
71909 + struct user_struct *user;
71910 +
71911 + if (!uid_valid(real))
71912 + goto skipit;
71913 +
71914 + /* find user based on global namespace */
71915 +
71916 + globalreal = GR_GLOBAL_UID(real);
71917 +
71918 + user = find_user(make_kuid(&init_user_ns, globalreal));
71919 + if (user == NULL)
71920 + goto skipit;
71921 +
71922 + if (gr_process_kernel_setuid_ban(user)) {
71923 + /* for find_user */
71924 + free_uid(user);
71925 + return 1;
71926 + }
71927 +
71928 + /* for find_user */
71929 + free_uid(user);
71930 +
71931 +skipit:
71932 +#endif
71933 +
71934 + if (unlikely(!(gr_status & GR_READY)))
71935 + return 0;
71936 +
71937 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
71938 + gr_log_learn_uid_change(real, effective, fs);
71939 +
71940 + num = current->acl->user_trans_num;
71941 + uidlist = current->acl->user_transitions;
71942 +
71943 + if (uidlist == NULL)
71944 + return 0;
71945 +
71946 + if (!uid_valid(real)) {
71947 + realok = 1;
71948 + globalreal = (uid_t)-1;
71949 + } else {
71950 + globalreal = GR_GLOBAL_UID(real);
71951 + }
71952 + if (!uid_valid(effective)) {
71953 + effectiveok = 1;
71954 + globaleffective = (uid_t)-1;
71955 + } else {
71956 + globaleffective = GR_GLOBAL_UID(effective);
71957 + }
71958 + if (!uid_valid(fs)) {
71959 + fsok = 1;
71960 + globalfs = (uid_t)-1;
71961 + } else {
71962 + globalfs = GR_GLOBAL_UID(fs);
71963 + }
71964 +
71965 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
71966 + for (i = 0; i < num; i++) {
71967 + curuid = uidlist[i];
71968 + if (globalreal == curuid)
71969 + realok = 1;
71970 + if (globaleffective == curuid)
71971 + effectiveok = 1;
71972 + if (globalfs == curuid)
71973 + fsok = 1;
71974 + }
71975 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
71976 + for (i = 0; i < num; i++) {
71977 + curuid = uidlist[i];
71978 + if (globalreal == curuid)
71979 + break;
71980 + if (globaleffective == curuid)
71981 + break;
71982 + if (globalfs == curuid)
71983 + break;
71984 + }
71985 + /* not in deny list */
71986 + if (i == num) {
71987 + realok = 1;
71988 + effectiveok = 1;
71989 + fsok = 1;
71990 + }
71991 + }
71992 +
71993 + if (realok && effectiveok && fsok)
71994 + return 0;
71995 + else {
71996 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
71997 + return 1;
71998 + }
71999 +}
72000 +
72001 +int
72002 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
72003 +{
72004 + unsigned int i;
72005 + __u16 num;
72006 + gid_t *gidlist;
72007 + gid_t curgid;
72008 + int realok = 0;
72009 + int effectiveok = 0;
72010 + int fsok = 0;
72011 + gid_t globalreal, globaleffective, globalfs;
72012 +
72013 + if (unlikely(!(gr_status & GR_READY)))
72014 + return 0;
72015 +
72016 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
72017 + gr_log_learn_gid_change(real, effective, fs);
72018 +
72019 + num = current->acl->group_trans_num;
72020 + gidlist = current->acl->group_transitions;
72021 +
72022 + if (gidlist == NULL)
72023 + return 0;
72024 +
72025 + if (!gid_valid(real)) {
72026 + realok = 1;
72027 + globalreal = (gid_t)-1;
72028 + } else {
72029 + globalreal = GR_GLOBAL_GID(real);
72030 + }
72031 + if (!gid_valid(effective)) {
72032 + effectiveok = 1;
72033 + globaleffective = (gid_t)-1;
72034 + } else {
72035 + globaleffective = GR_GLOBAL_GID(effective);
72036 + }
72037 + if (!gid_valid(fs)) {
72038 + fsok = 1;
72039 + globalfs = (gid_t)-1;
72040 + } else {
72041 + globalfs = GR_GLOBAL_GID(fs);
72042 + }
72043 +
72044 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
72045 + for (i = 0; i < num; i++) {
72046 + curgid = gidlist[i];
72047 + if (globalreal == curgid)
72048 + realok = 1;
72049 + if (globaleffective == curgid)
72050 + effectiveok = 1;
72051 + if (globalfs == curgid)
72052 + fsok = 1;
72053 + }
72054 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
72055 + for (i = 0; i < num; i++) {
72056 + curgid = gidlist[i];
72057 + if (globalreal == curgid)
72058 + break;
72059 + if (globaleffective == curgid)
72060 + break;
72061 + if (globalfs == curgid)
72062 + break;
72063 + }
72064 + /* not in deny list */
72065 + if (i == num) {
72066 + realok = 1;
72067 + effectiveok = 1;
72068 + fsok = 1;
72069 + }
72070 + }
72071 +
72072 + if (realok && effectiveok && fsok)
72073 + return 0;
72074 + else {
72075 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
72076 + return 1;
72077 + }
72078 +}
72079 +
72080 +extern int gr_acl_is_capable(const int cap);
72081 +
72082 +void
72083 +gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
72084 +{
72085 + struct acl_role_label *role = task->role;
72086 + struct acl_subject_label *subj = NULL;
72087 + struct acl_object_label *obj;
72088 + struct file *filp;
72089 + uid_t uid;
72090 + gid_t gid;
72091 +
72092 + if (unlikely(!(gr_status & GR_READY)))
72093 + return;
72094 +
72095 + uid = GR_GLOBAL_UID(kuid);
72096 + gid = GR_GLOBAL_GID(kgid);
72097 +
72098 + filp = task->exec_file;
72099 +
72100 + /* kernel process, we'll give them the kernel role */
72101 + if (unlikely(!filp)) {
72102 + task->role = running_polstate.kernel_role;
72103 + task->acl = running_polstate.kernel_role->root_label;
72104 + return;
72105 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL)) {
72106 + /* save the current ip at time of role lookup so that the proper
72107 + IP will be learned for role_allowed_ip */
72108 + task->signal->saved_ip = task->signal->curr_ip;
72109 + role = lookup_acl_role_label(task, uid, gid);
72110 + }
72111 +
72112 + /* don't change the role if we're not a privileged process */
72113 + if (role && task->role != role &&
72114 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
72115 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
72116 + return;
72117 +
72118 + /* perform subject lookup in possibly new role
72119 + we can use this result below in the case where role == task->role
72120 + */
72121 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
72122 +
72123 + /* if we changed uid/gid, but result in the same role
72124 + and are using inheritance, don't lose the inherited subject
72125 + if current subject is other than what normal lookup
72126 + would result in, we arrived via inheritance, don't
72127 + lose subject
72128 + */
72129 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
72130 + (subj == task->acl)))
72131 + task->acl = subj;
72132 +
72133 + /* leave task->inherited unaffected */
72134 +
72135 + task->role = role;
72136 +
72137 + task->is_writable = 0;
72138 +
72139 + /* ignore additional mmap checks for processes that are writable
72140 + by the default ACL */
72141 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
72142 + if (unlikely(obj->mode & GR_WRITE))
72143 + task->is_writable = 1;
72144 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
72145 + if (unlikely(obj->mode & GR_WRITE))
72146 + task->is_writable = 1;
72147 +
72148 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
72149 + 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);
72150 +#endif
72151 +
72152 + gr_set_proc_res(task);
72153 +
72154 + return;
72155 +}
72156 +
72157 +int
72158 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
72159 + const int unsafe_flags)
72160 +{
72161 + struct task_struct *task = current;
72162 + struct acl_subject_label *newacl;
72163 + struct acl_object_label *obj;
72164 + __u32 retmode;
72165 +
72166 + if (unlikely(!(gr_status & GR_READY)))
72167 + return 0;
72168 +
72169 + newacl = chk_subj_label(dentry, mnt, task->role);
72170 +
72171 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
72172 + did an exec
72173 + */
72174 + rcu_read_lock();
72175 + read_lock(&tasklist_lock);
72176 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
72177 + (task->parent->acl->mode & GR_POVERRIDE))) {
72178 + read_unlock(&tasklist_lock);
72179 + rcu_read_unlock();
72180 + goto skip_check;
72181 + }
72182 + read_unlock(&tasklist_lock);
72183 + rcu_read_unlock();
72184 +
72185 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
72186 + !(task->role->roletype & GR_ROLE_GOD) &&
72187 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
72188 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
72189 + if (unsafe_flags & LSM_UNSAFE_SHARE)
72190 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
72191 + else
72192 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
72193 + return -EACCES;
72194 + }
72195 +
72196 +skip_check:
72197 +
72198 + obj = chk_obj_label(dentry, mnt, task->acl);
72199 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
72200 +
72201 + if (!(task->acl->mode & GR_INHERITLEARN) &&
72202 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
72203 + if (obj->nested)
72204 + task->acl = obj->nested;
72205 + else
72206 + task->acl = newacl;
72207 + task->inherited = 0;
72208 + } else {
72209 + task->inherited = 1;
72210 + if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
72211 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
72212 + }
72213 +
72214 + task->is_writable = 0;
72215 +
72216 + /* ignore additional mmap checks for processes that are writable
72217 + by the default ACL */
72218 + obj = chk_obj_label(dentry, mnt, running_polstate.default_role->root_label);
72219 + if (unlikely(obj->mode & GR_WRITE))
72220 + task->is_writable = 1;
72221 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
72222 + if (unlikely(obj->mode & GR_WRITE))
72223 + task->is_writable = 1;
72224 +
72225 + gr_set_proc_res(task);
72226 +
72227 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
72228 + 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);
72229 +#endif
72230 + return 0;
72231 +}
72232 +
72233 +/* always called with valid inodev ptr */
72234 +static void
72235 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
72236 +{
72237 + struct acl_object_label *matchpo;
72238 + struct acl_subject_label *matchps;
72239 + struct acl_subject_label *subj;
72240 + struct acl_role_label *role;
72241 + unsigned int x;
72242 +
72243 + FOR_EACH_ROLE_START(role)
72244 + FOR_EACH_SUBJECT_START(role, subj, x)
72245 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
72246 + matchpo->mode |= GR_DELETED;
72247 + FOR_EACH_SUBJECT_END(subj,x)
72248 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
72249 + /* nested subjects aren't in the role's subj_hash table */
72250 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
72251 + matchpo->mode |= GR_DELETED;
72252 + FOR_EACH_NESTED_SUBJECT_END(subj)
72253 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
72254 + matchps->mode |= GR_DELETED;
72255 + FOR_EACH_ROLE_END(role)
72256 +
72257 + inodev->nentry->deleted = 1;
72258 +
72259 + return;
72260 +}
72261 +
72262 +void
72263 +gr_handle_delete(const ino_t ino, const dev_t dev)
72264 +{
72265 + struct inodev_entry *inodev;
72266 +
72267 + if (unlikely(!(gr_status & GR_READY)))
72268 + return;
72269 +
72270 + write_lock(&gr_inode_lock);
72271 + inodev = lookup_inodev_entry(ino, dev);
72272 + if (inodev != NULL)
72273 + do_handle_delete(inodev, ino, dev);
72274 + write_unlock(&gr_inode_lock);
72275 +
72276 + return;
72277 +}
72278 +
72279 +static void
72280 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
72281 + const ino_t newinode, const dev_t newdevice,
72282 + struct acl_subject_label *subj)
72283 +{
72284 + unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
72285 + struct acl_object_label *match;
72286 +
72287 + match = subj->obj_hash[index];
72288 +
72289 + while (match && (match->inode != oldinode ||
72290 + match->device != olddevice ||
72291 + !(match->mode & GR_DELETED)))
72292 + match = match->next;
72293 +
72294 + if (match && (match->inode == oldinode)
72295 + && (match->device == olddevice)
72296 + && (match->mode & GR_DELETED)) {
72297 + if (match->prev == NULL) {
72298 + subj->obj_hash[index] = match->next;
72299 + if (match->next != NULL)
72300 + match->next->prev = NULL;
72301 + } else {
72302 + match->prev->next = match->next;
72303 + if (match->next != NULL)
72304 + match->next->prev = match->prev;
72305 + }
72306 + match->prev = NULL;
72307 + match->next = NULL;
72308 + match->inode = newinode;
72309 + match->device = newdevice;
72310 + match->mode &= ~GR_DELETED;
72311 +
72312 + insert_acl_obj_label(match, subj);
72313 + }
72314 +
72315 + return;
72316 +}
72317 +
72318 +static void
72319 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
72320 + const ino_t newinode, const dev_t newdevice,
72321 + struct acl_role_label *role)
72322 +{
72323 + unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
72324 + struct acl_subject_label *match;
72325 +
72326 + match = role->subj_hash[index];
72327 +
72328 + while (match && (match->inode != oldinode ||
72329 + match->device != olddevice ||
72330 + !(match->mode & GR_DELETED)))
72331 + match = match->next;
72332 +
72333 + if (match && (match->inode == oldinode)
72334 + && (match->device == olddevice)
72335 + && (match->mode & GR_DELETED)) {
72336 + if (match->prev == NULL) {
72337 + role->subj_hash[index] = match->next;
72338 + if (match->next != NULL)
72339 + match->next->prev = NULL;
72340 + } else {
72341 + match->prev->next = match->next;
72342 + if (match->next != NULL)
72343 + match->next->prev = match->prev;
72344 + }
72345 + match->prev = NULL;
72346 + match->next = NULL;
72347 + match->inode = newinode;
72348 + match->device = newdevice;
72349 + match->mode &= ~GR_DELETED;
72350 +
72351 + insert_acl_subj_label(match, role);
72352 + }
72353 +
72354 + return;
72355 +}
72356 +
72357 +static void
72358 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
72359 + const ino_t newinode, const dev_t newdevice)
72360 +{
72361 + unsigned int index = gr_fhash(oldinode, olddevice, running_polstate.inodev_set.i_size);
72362 + struct inodev_entry *match;
72363 +
72364 + match = running_polstate.inodev_set.i_hash[index];
72365 +
72366 + while (match && (match->nentry->inode != oldinode ||
72367 + match->nentry->device != olddevice || !match->nentry->deleted))
72368 + match = match->next;
72369 +
72370 + if (match && (match->nentry->inode == oldinode)
72371 + && (match->nentry->device == olddevice) &&
72372 + match->nentry->deleted) {
72373 + if (match->prev == NULL) {
72374 + running_polstate.inodev_set.i_hash[index] = match->next;
72375 + if (match->next != NULL)
72376 + match->next->prev = NULL;
72377 + } else {
72378 + match->prev->next = match->next;
72379 + if (match->next != NULL)
72380 + match->next->prev = match->prev;
72381 + }
72382 + match->prev = NULL;
72383 + match->next = NULL;
72384 + match->nentry->inode = newinode;
72385 + match->nentry->device = newdevice;
72386 + match->nentry->deleted = 0;
72387 +
72388 + insert_inodev_entry(match);
72389 + }
72390 +
72391 + return;
72392 +}
72393 +
72394 +static void
72395 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
72396 +{
72397 + struct acl_subject_label *subj;
72398 + struct acl_role_label *role;
72399 + unsigned int x;
72400 +
72401 + FOR_EACH_ROLE_START(role)
72402 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
72403 +
72404 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
72405 + if ((subj->inode == ino) && (subj->device == dev)) {
72406 + subj->inode = ino;
72407 + subj->device = dev;
72408 + }
72409 + /* nested subjects aren't in the role's subj_hash table */
72410 + update_acl_obj_label(matchn->inode, matchn->device,
72411 + ino, dev, subj);
72412 + FOR_EACH_NESTED_SUBJECT_END(subj)
72413 + FOR_EACH_SUBJECT_START(role, subj, x)
72414 + update_acl_obj_label(matchn->inode, matchn->device,
72415 + ino, dev, subj);
72416 + FOR_EACH_SUBJECT_END(subj,x)
72417 + FOR_EACH_ROLE_END(role)
72418 +
72419 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
72420 +
72421 + return;
72422 +}
72423 +
72424 +static void
72425 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
72426 + const struct vfsmount *mnt)
72427 +{
72428 + ino_t ino = dentry->d_inode->i_ino;
72429 + dev_t dev = __get_dev(dentry);
72430 +
72431 + __do_handle_create(matchn, ino, dev);
72432 +
72433 + return;
72434 +}
72435 +
72436 +void
72437 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
72438 +{
72439 + struct name_entry *matchn;
72440 +
72441 + if (unlikely(!(gr_status & GR_READY)))
72442 + return;
72443 +
72444 + preempt_disable();
72445 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
72446 +
72447 + if (unlikely((unsigned long)matchn)) {
72448 + write_lock(&gr_inode_lock);
72449 + do_handle_create(matchn, dentry, mnt);
72450 + write_unlock(&gr_inode_lock);
72451 + }
72452 + preempt_enable();
72453 +
72454 + return;
72455 +}
72456 +
72457 +void
72458 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
72459 +{
72460 + struct name_entry *matchn;
72461 +
72462 + if (unlikely(!(gr_status & GR_READY)))
72463 + return;
72464 +
72465 + preempt_disable();
72466 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
72467 +
72468 + if (unlikely((unsigned long)matchn)) {
72469 + write_lock(&gr_inode_lock);
72470 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
72471 + write_unlock(&gr_inode_lock);
72472 + }
72473 + preempt_enable();
72474 +
72475 + return;
72476 +}
72477 +
72478 +void
72479 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
72480 + struct dentry *old_dentry,
72481 + struct dentry *new_dentry,
72482 + struct vfsmount *mnt, const __u8 replace, unsigned int flags)
72483 +{
72484 + struct name_entry *matchn;
72485 + struct name_entry *matchn2 = NULL;
72486 + struct inodev_entry *inodev;
72487 + struct inode *inode = new_dentry->d_inode;
72488 + ino_t old_ino = old_dentry->d_inode->i_ino;
72489 + dev_t old_dev = __get_dev(old_dentry);
72490 + unsigned int exchange = flags & RENAME_EXCHANGE;
72491 +
72492 + /* vfs_rename swaps the name and parent link for old_dentry and
72493 + new_dentry
72494 + at this point, old_dentry has the new name, parent link, and inode
72495 + for the renamed file
72496 + if a file is being replaced by a rename, new_dentry has the inode
72497 + and name for the replaced file
72498 + */
72499 +
72500 + if (unlikely(!(gr_status & GR_READY)))
72501 + return;
72502 +
72503 + preempt_disable();
72504 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
72505 +
72506 + /* exchange cases:
72507 + a filename exists for the source, but not dest
72508 + do a recreate on source
72509 + a filename exists for the dest, but not source
72510 + do a recreate on dest
72511 + a filename exists for both source and dest
72512 + delete source and dest, then create source and dest
72513 + a filename exists for neither source nor dest
72514 + no updates needed
72515 +
72516 + the name entry lookups get us the old inode/dev associated with
72517 + each name, so do the deletes first (if possible) so that when
72518 + we do the create, we pick up on the right entries
72519 + */
72520 +
72521 + if (exchange)
72522 + matchn2 = lookup_name_entry(gr_to_filename_rbac(new_dentry, mnt));
72523 +
72524 + /* we wouldn't have to check d_inode if it weren't for
72525 + NFS silly-renaming
72526 + */
72527 +
72528 + write_lock(&gr_inode_lock);
72529 + if (unlikely((replace || exchange) && inode)) {
72530 + ino_t new_ino = inode->i_ino;
72531 + dev_t new_dev = __get_dev(new_dentry);
72532 +
72533 + inodev = lookup_inodev_entry(new_ino, new_dev);
72534 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
72535 + do_handle_delete(inodev, new_ino, new_dev);
72536 + }
72537 +
72538 + inodev = lookup_inodev_entry(old_ino, old_dev);
72539 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
72540 + do_handle_delete(inodev, old_ino, old_dev);
72541 +
72542 + if (unlikely(matchn != NULL))
72543 + do_handle_create(matchn, old_dentry, mnt);
72544 +
72545 + if (unlikely(matchn2 != NULL))
72546 + do_handle_create(matchn2, new_dentry, mnt);
72547 +
72548 + write_unlock(&gr_inode_lock);
72549 + preempt_enable();
72550 +
72551 + return;
72552 +}
72553 +
72554 +#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
72555 +static const unsigned long res_learn_bumps[GR_NLIMITS] = {
72556 + [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
72557 + [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
72558 + [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
72559 + [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
72560 + [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
72561 + [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
72562 + [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
72563 + [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
72564 + [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
72565 + [RLIMIT_AS] = GR_RLIM_AS_BUMP,
72566 + [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
72567 + [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
72568 + [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
72569 + [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
72570 + [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
72571 + [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
72572 +};
72573 +
72574 +void
72575 +gr_learn_resource(const struct task_struct *task,
72576 + const int res, const unsigned long wanted, const int gt)
72577 +{
72578 + struct acl_subject_label *acl;
72579 + const struct cred *cred;
72580 +
72581 + if (unlikely((gr_status & GR_READY) &&
72582 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
72583 + goto skip_reslog;
72584 +
72585 + gr_log_resource(task, res, wanted, gt);
72586 +skip_reslog:
72587 +
72588 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
72589 + return;
72590 +
72591 + acl = task->acl;
72592 +
72593 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
72594 + !(acl->resmask & (1U << (unsigned short) res))))
72595 + return;
72596 +
72597 + if (wanted >= acl->res[res].rlim_cur) {
72598 + unsigned long res_add;
72599 +
72600 + res_add = wanted + res_learn_bumps[res];
72601 +
72602 + acl->res[res].rlim_cur = res_add;
72603 +
72604 + if (wanted > acl->res[res].rlim_max)
72605 + acl->res[res].rlim_max = res_add;
72606 +
72607 + /* only log the subject filename, since resource logging is supported for
72608 + single-subject learning only */
72609 + rcu_read_lock();
72610 + cred = __task_cred(task);
72611 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
72612 + task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
72613 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
72614 + "", (unsigned long) res, &task->signal->saved_ip);
72615 + rcu_read_unlock();
72616 + }
72617 +
72618 + return;
72619 +}
72620 +EXPORT_SYMBOL_GPL(gr_learn_resource);
72621 +#endif
72622 +
72623 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
72624 +void
72625 +pax_set_initial_flags(struct linux_binprm *bprm)
72626 +{
72627 + struct task_struct *task = current;
72628 + struct acl_subject_label *proc;
72629 + unsigned long flags;
72630 +
72631 + if (unlikely(!(gr_status & GR_READY)))
72632 + return;
72633 +
72634 + flags = pax_get_flags(task);
72635 +
72636 + proc = task->acl;
72637 +
72638 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
72639 + flags &= ~MF_PAX_PAGEEXEC;
72640 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
72641 + flags &= ~MF_PAX_SEGMEXEC;
72642 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
72643 + flags &= ~MF_PAX_RANDMMAP;
72644 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
72645 + flags &= ~MF_PAX_EMUTRAMP;
72646 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
72647 + flags &= ~MF_PAX_MPROTECT;
72648 +
72649 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
72650 + flags |= MF_PAX_PAGEEXEC;
72651 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
72652 + flags |= MF_PAX_SEGMEXEC;
72653 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
72654 + flags |= MF_PAX_RANDMMAP;
72655 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
72656 + flags |= MF_PAX_EMUTRAMP;
72657 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
72658 + flags |= MF_PAX_MPROTECT;
72659 +
72660 + pax_set_flags(task, flags);
72661 +
72662 + return;
72663 +}
72664 +#endif
72665 +
72666 +int
72667 +gr_handle_proc_ptrace(struct task_struct *task)
72668 +{
72669 + struct file *filp;
72670 + struct task_struct *tmp = task;
72671 + struct task_struct *curtemp = current;
72672 + __u32 retmode;
72673 +
72674 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
72675 + if (unlikely(!(gr_status & GR_READY)))
72676 + return 0;
72677 +#endif
72678 +
72679 + read_lock(&tasklist_lock);
72680 + read_lock(&grsec_exec_file_lock);
72681 + filp = task->exec_file;
72682 +
72683 + while (task_pid_nr(tmp) > 0) {
72684 + if (tmp == curtemp)
72685 + break;
72686 + tmp = tmp->real_parent;
72687 + }
72688 +
72689 + if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
72690 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
72691 + read_unlock(&grsec_exec_file_lock);
72692 + read_unlock(&tasklist_lock);
72693 + return 1;
72694 + }
72695 +
72696 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
72697 + if (!(gr_status & GR_READY)) {
72698 + read_unlock(&grsec_exec_file_lock);
72699 + read_unlock(&tasklist_lock);
72700 + return 0;
72701 + }
72702 +#endif
72703 +
72704 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
72705 + read_unlock(&grsec_exec_file_lock);
72706 + read_unlock(&tasklist_lock);
72707 +
72708 + if (retmode & GR_NOPTRACE)
72709 + return 1;
72710 +
72711 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
72712 + && (current->acl != task->acl || (current->acl != current->role->root_label
72713 + && task_pid_nr(current) != task_pid_nr(task))))
72714 + return 1;
72715 +
72716 + return 0;
72717 +}
72718 +
72719 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
72720 +{
72721 + if (unlikely(!(gr_status & GR_READY)))
72722 + return;
72723 +
72724 + if (!(current->role->roletype & GR_ROLE_GOD))
72725 + return;
72726 +
72727 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
72728 + p->role->rolename, gr_task_roletype_to_char(p),
72729 + p->acl->filename);
72730 +}
72731 +
72732 +int
72733 +gr_handle_ptrace(struct task_struct *task, const long request)
72734 +{
72735 + struct task_struct *tmp = task;
72736 + struct task_struct *curtemp = current;
72737 + __u32 retmode;
72738 +
72739 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
72740 + if (unlikely(!(gr_status & GR_READY)))
72741 + return 0;
72742 +#endif
72743 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
72744 + read_lock(&tasklist_lock);
72745 + while (task_pid_nr(tmp) > 0) {
72746 + if (tmp == curtemp)
72747 + break;
72748 + tmp = tmp->real_parent;
72749 + }
72750 +
72751 + if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
72752 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
72753 + read_unlock(&tasklist_lock);
72754 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
72755 + return 1;
72756 + }
72757 + read_unlock(&tasklist_lock);
72758 + }
72759 +
72760 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
72761 + if (!(gr_status & GR_READY))
72762 + return 0;
72763 +#endif
72764 +
72765 + read_lock(&grsec_exec_file_lock);
72766 + if (unlikely(!task->exec_file)) {
72767 + read_unlock(&grsec_exec_file_lock);
72768 + return 0;
72769 + }
72770 +
72771 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
72772 + read_unlock(&grsec_exec_file_lock);
72773 +
72774 + if (retmode & GR_NOPTRACE) {
72775 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
72776 + return 1;
72777 + }
72778 +
72779 + if (retmode & GR_PTRACERD) {
72780 + switch (request) {
72781 + case PTRACE_SEIZE:
72782 + case PTRACE_POKETEXT:
72783 + case PTRACE_POKEDATA:
72784 + case PTRACE_POKEUSR:
72785 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
72786 + case PTRACE_SETREGS:
72787 + case PTRACE_SETFPREGS:
72788 +#endif
72789 +#ifdef CONFIG_X86
72790 + case PTRACE_SETFPXREGS:
72791 +#endif
72792 +#ifdef CONFIG_ALTIVEC
72793 + case PTRACE_SETVRREGS:
72794 +#endif
72795 + return 1;
72796 + default:
72797 + return 0;
72798 + }
72799 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
72800 + !(current->role->roletype & GR_ROLE_GOD) &&
72801 + (current->acl != task->acl)) {
72802 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
72803 + return 1;
72804 + }
72805 +
72806 + return 0;
72807 +}
72808 +
72809 +static int is_writable_mmap(const struct file *filp)
72810 +{
72811 + struct task_struct *task = current;
72812 + struct acl_object_label *obj, *obj2;
72813 +
72814 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
72815 + !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))) {
72816 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
72817 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
72818 + task->role->root_label);
72819 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
72820 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
72821 + return 1;
72822 + }
72823 + }
72824 + return 0;
72825 +}
72826 +
72827 +int
72828 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
72829 +{
72830 + __u32 mode;
72831 +
72832 + if (unlikely(!file || !(prot & PROT_EXEC)))
72833 + return 1;
72834 +
72835 + if (is_writable_mmap(file))
72836 + return 0;
72837 +
72838 + mode =
72839 + gr_search_file(file->f_path.dentry,
72840 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
72841 + file->f_path.mnt);
72842 +
72843 + if (!gr_tpe_allow(file))
72844 + return 0;
72845 +
72846 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
72847 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
72848 + return 0;
72849 + } else if (unlikely(!(mode & GR_EXEC))) {
72850 + return 0;
72851 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
72852 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
72853 + return 1;
72854 + }
72855 +
72856 + return 1;
72857 +}
72858 +
72859 +int
72860 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
72861 +{
72862 + __u32 mode;
72863 +
72864 + if (unlikely(!file || !(prot & PROT_EXEC)))
72865 + return 1;
72866 +
72867 + if (is_writable_mmap(file))
72868 + return 0;
72869 +
72870 + mode =
72871 + gr_search_file(file->f_path.dentry,
72872 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
72873 + file->f_path.mnt);
72874 +
72875 + if (!gr_tpe_allow(file))
72876 + return 0;
72877 +
72878 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
72879 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
72880 + return 0;
72881 + } else if (unlikely(!(mode & GR_EXEC))) {
72882 + return 0;
72883 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
72884 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
72885 + return 1;
72886 + }
72887 +
72888 + return 1;
72889 +}
72890 +
72891 +void
72892 +gr_acl_handle_psacct(struct task_struct *task, const long code)
72893 +{
72894 + unsigned long runtime, cputime;
72895 + cputime_t utime, stime;
72896 + unsigned int wday, cday;
72897 + __u8 whr, chr;
72898 + __u8 wmin, cmin;
72899 + __u8 wsec, csec;
72900 + struct timespec timeval;
72901 +
72902 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
72903 + !(task->acl->mode & GR_PROCACCT)))
72904 + return;
72905 +
72906 + do_posix_clock_monotonic_gettime(&timeval);
72907 + runtime = timeval.tv_sec - task->start_time.tv_sec;
72908 + wday = runtime / (60 * 60 * 24);
72909 + runtime -= wday * (60 * 60 * 24);
72910 + whr = runtime / (60 * 60);
72911 + runtime -= whr * (60 * 60);
72912 + wmin = runtime / 60;
72913 + runtime -= wmin * 60;
72914 + wsec = runtime;
72915 +
72916 + task_cputime(task, &utime, &stime);
72917 + cputime = cputime_to_secs(utime + stime);
72918 + cday = cputime / (60 * 60 * 24);
72919 + cputime -= cday * (60 * 60 * 24);
72920 + chr = cputime / (60 * 60);
72921 + cputime -= chr * (60 * 60);
72922 + cmin = cputime / 60;
72923 + cputime -= cmin * 60;
72924 + csec = cputime;
72925 +
72926 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
72927 +
72928 + return;
72929 +}
72930 +
72931 +#ifdef CONFIG_TASKSTATS
72932 +int gr_is_taskstats_denied(int pid)
72933 +{
72934 + struct task_struct *task;
72935 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
72936 + const struct cred *cred;
72937 +#endif
72938 + int ret = 0;
72939 +
72940 + /* restrict taskstats viewing to un-chrooted root users
72941 + who have the 'view' subject flag if the RBAC system is enabled
72942 + */
72943 +
72944 + rcu_read_lock();
72945 + read_lock(&tasklist_lock);
72946 + task = find_task_by_vpid(pid);
72947 + if (task) {
72948 +#ifdef CONFIG_GRKERNSEC_CHROOT
72949 + if (proc_is_chrooted(task))
72950 + ret = -EACCES;
72951 +#endif
72952 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
72953 + cred = __task_cred(task);
72954 +#ifdef CONFIG_GRKERNSEC_PROC_USER
72955 + if (gr_is_global_nonroot(cred->uid))
72956 + ret = -EACCES;
72957 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
72958 + if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
72959 + ret = -EACCES;
72960 +#endif
72961 +#endif
72962 + if (gr_status & GR_READY) {
72963 + if (!(task->acl->mode & GR_VIEW))
72964 + ret = -EACCES;
72965 + }
72966 + } else
72967 + ret = -ENOENT;
72968 +
72969 + read_unlock(&tasklist_lock);
72970 + rcu_read_unlock();
72971 +
72972 + return ret;
72973 +}
72974 +#endif
72975 +
72976 +/* AUXV entries are filled via a descendant of search_binary_handler
72977 + after we've already applied the subject for the target
72978 +*/
72979 +int gr_acl_enable_at_secure(void)
72980 +{
72981 + if (unlikely(!(gr_status & GR_READY)))
72982 + return 0;
72983 +
72984 + if (current->acl->mode & GR_ATSECURE)
72985 + return 1;
72986 +
72987 + return 0;
72988 +}
72989 +
72990 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
72991 +{
72992 + struct task_struct *task = current;
72993 + struct dentry *dentry = file->f_path.dentry;
72994 + struct vfsmount *mnt = file->f_path.mnt;
72995 + struct acl_object_label *obj, *tmp;
72996 + struct acl_subject_label *subj;
72997 + unsigned int bufsize;
72998 + int is_not_root;
72999 + char *path;
73000 + dev_t dev = __get_dev(dentry);
73001 +
73002 + if (unlikely(!(gr_status & GR_READY)))
73003 + return 1;
73004 +
73005 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
73006 + return 1;
73007 +
73008 + /* ignore Eric Biederman */
73009 + if (IS_PRIVATE(dentry->d_inode))
73010 + return 1;
73011 +
73012 + subj = task->acl;
73013 + read_lock(&gr_inode_lock);
73014 + do {
73015 + obj = lookup_acl_obj_label(ino, dev, subj);
73016 + if (obj != NULL) {
73017 + read_unlock(&gr_inode_lock);
73018 + return (obj->mode & GR_FIND) ? 1 : 0;
73019 + }
73020 + } while ((subj = subj->parent_subject));
73021 + read_unlock(&gr_inode_lock);
73022 +
73023 + /* this is purely an optimization since we're looking for an object
73024 + for the directory we're doing a readdir on
73025 + if it's possible for any globbed object to match the entry we're
73026 + filling into the directory, then the object we find here will be
73027 + an anchor point with attached globbed objects
73028 + */
73029 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
73030 + if (obj->globbed == NULL)
73031 + return (obj->mode & GR_FIND) ? 1 : 0;
73032 +
73033 + is_not_root = ((obj->filename[0] == '/') &&
73034 + (obj->filename[1] == '\0')) ? 0 : 1;
73035 + bufsize = PAGE_SIZE - namelen - is_not_root;
73036 +
73037 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
73038 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
73039 + return 1;
73040 +
73041 + preempt_disable();
73042 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
73043 + bufsize);
73044 +
73045 + bufsize = strlen(path);
73046 +
73047 + /* if base is "/", don't append an additional slash */
73048 + if (is_not_root)
73049 + *(path + bufsize) = '/';
73050 + memcpy(path + bufsize + is_not_root, name, namelen);
73051 + *(path + bufsize + namelen + is_not_root) = '\0';
73052 +
73053 + tmp = obj->globbed;
73054 + while (tmp) {
73055 + if (!glob_match(tmp->filename, path)) {
73056 + preempt_enable();
73057 + return (tmp->mode & GR_FIND) ? 1 : 0;
73058 + }
73059 + tmp = tmp->next;
73060 + }
73061 + preempt_enable();
73062 + return (obj->mode & GR_FIND) ? 1 : 0;
73063 +}
73064 +
73065 +void gr_put_exec_file(struct task_struct *task)
73066 +{
73067 + struct file *filp;
73068 +
73069 + write_lock(&grsec_exec_file_lock);
73070 + filp = task->exec_file;
73071 + task->exec_file = NULL;
73072 + write_unlock(&grsec_exec_file_lock);
73073 +
73074 + if (filp)
73075 + fput(filp);
73076 +
73077 + return;
73078 +}
73079 +
73080 +
73081 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
73082 +EXPORT_SYMBOL_GPL(gr_acl_is_enabled);
73083 +#endif
73084 +#ifdef CONFIG_SECURITY
73085 +EXPORT_SYMBOL_GPL(gr_check_user_change);
73086 +EXPORT_SYMBOL_GPL(gr_check_group_change);
73087 +#endif
73088 +
73089 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
73090 new file mode 100644
73091 index 0000000..18ffbbd
73092 --- /dev/null
73093 +++ b/grsecurity/gracl_alloc.c
73094 @@ -0,0 +1,105 @@
73095 +#include <linux/kernel.h>
73096 +#include <linux/mm.h>
73097 +#include <linux/slab.h>
73098 +#include <linux/vmalloc.h>
73099 +#include <linux/gracl.h>
73100 +#include <linux/grsecurity.h>
73101 +
73102 +static struct gr_alloc_state __current_alloc_state = { 1, 1, NULL };
73103 +struct gr_alloc_state *current_alloc_state = &__current_alloc_state;
73104 +
73105 +static __inline__ int
73106 +alloc_pop(void)
73107 +{
73108 + if (current_alloc_state->alloc_stack_next == 1)
73109 + return 0;
73110 +
73111 + kfree(current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 2]);
73112 +
73113 + current_alloc_state->alloc_stack_next--;
73114 +
73115 + return 1;
73116 +}
73117 +
73118 +static __inline__ int
73119 +alloc_push(void *buf)
73120 +{
73121 + if (current_alloc_state->alloc_stack_next >= current_alloc_state->alloc_stack_size)
73122 + return 1;
73123 +
73124 + current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 1] = buf;
73125 +
73126 + current_alloc_state->alloc_stack_next++;
73127 +
73128 + return 0;
73129 +}
73130 +
73131 +void *
73132 +acl_alloc(unsigned long len)
73133 +{
73134 + void *ret = NULL;
73135 +
73136 + if (!len || len > PAGE_SIZE)
73137 + goto out;
73138 +
73139 + ret = kmalloc(len, GFP_KERNEL);
73140 +
73141 + if (ret) {
73142 + if (alloc_push(ret)) {
73143 + kfree(ret);
73144 + ret = NULL;
73145 + }
73146 + }
73147 +
73148 +out:
73149 + return ret;
73150 +}
73151 +
73152 +void *
73153 +acl_alloc_num(unsigned long num, unsigned long len)
73154 +{
73155 + if (!len || (num > (PAGE_SIZE / len)))
73156 + return NULL;
73157 +
73158 + return acl_alloc(num * len);
73159 +}
73160 +
73161 +void
73162 +acl_free_all(void)
73163 +{
73164 + if (!current_alloc_state->alloc_stack)
73165 + return;
73166 +
73167 + while (alloc_pop()) ;
73168 +
73169 + if (current_alloc_state->alloc_stack) {
73170 + if ((current_alloc_state->alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
73171 + kfree(current_alloc_state->alloc_stack);
73172 + else
73173 + vfree(current_alloc_state->alloc_stack);
73174 + }
73175 +
73176 + current_alloc_state->alloc_stack = NULL;
73177 + current_alloc_state->alloc_stack_size = 1;
73178 + current_alloc_state->alloc_stack_next = 1;
73179 +
73180 + return;
73181 +}
73182 +
73183 +int
73184 +acl_alloc_stack_init(unsigned long size)
73185 +{
73186 + if ((size * sizeof (void *)) <= PAGE_SIZE)
73187 + current_alloc_state->alloc_stack =
73188 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
73189 + else
73190 + current_alloc_state->alloc_stack = (void **) vmalloc(size * sizeof (void *));
73191 +
73192 + current_alloc_state->alloc_stack_size = size;
73193 + current_alloc_state->alloc_stack_next = 1;
73194 +
73195 + if (!current_alloc_state->alloc_stack)
73196 + return 0;
73197 + else
73198 + return 1;
73199 +}
73200 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
73201 new file mode 100644
73202 index 0000000..1a94c11
73203 --- /dev/null
73204 +++ b/grsecurity/gracl_cap.c
73205 @@ -0,0 +1,127 @@
73206 +#include <linux/kernel.h>
73207 +#include <linux/module.h>
73208 +#include <linux/sched.h>
73209 +#include <linux/gracl.h>
73210 +#include <linux/grsecurity.h>
73211 +#include <linux/grinternal.h>
73212 +
73213 +extern const char *captab_log[];
73214 +extern int captab_log_entries;
73215 +
73216 +int gr_learn_cap(const struct task_struct *task, const struct cred *cred, const int cap)
73217 +{
73218 + struct acl_subject_label *curracl;
73219 +
73220 + if (!gr_acl_is_enabled())
73221 + return 1;
73222 +
73223 + curracl = task->acl;
73224 +
73225 + if (curracl->mode & (GR_LEARN | GR_INHERITLEARN)) {
73226 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
73227 + task->role->roletype, GR_GLOBAL_UID(cred->uid),
73228 + GR_GLOBAL_GID(cred->gid), task->exec_file ?
73229 + gr_to_filename(task->exec_file->f_path.dentry,
73230 + task->exec_file->f_path.mnt) : curracl->filename,
73231 + curracl->filename, 0UL,
73232 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
73233 + return 1;
73234 + }
73235 +
73236 + return 0;
73237 +}
73238 +
73239 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
73240 +{
73241 + struct acl_subject_label *curracl;
73242 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
73243 + kernel_cap_t cap_audit = __cap_empty_set;
73244 +
73245 + if (!gr_acl_is_enabled())
73246 + return 1;
73247 +
73248 + curracl = task->acl;
73249 +
73250 + cap_drop = curracl->cap_lower;
73251 + cap_mask = curracl->cap_mask;
73252 + cap_audit = curracl->cap_invert_audit;
73253 +
73254 + while ((curracl = curracl->parent_subject)) {
73255 + /* if the cap isn't specified in the current computed mask but is specified in the
73256 + current level subject, and is lowered in the current level subject, then add
73257 + it to the set of dropped capabilities
73258 + otherwise, add the current level subject's mask to the current computed mask
73259 + */
73260 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
73261 + cap_raise(cap_mask, cap);
73262 + if (cap_raised(curracl->cap_lower, cap))
73263 + cap_raise(cap_drop, cap);
73264 + if (cap_raised(curracl->cap_invert_audit, cap))
73265 + cap_raise(cap_audit, cap);
73266 + }
73267 + }
73268 +
73269 + if (!cap_raised(cap_drop, cap)) {
73270 + if (cap_raised(cap_audit, cap))
73271 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
73272 + return 1;
73273 + }
73274 +
73275 + /* only learn the capability use if the process has the capability in the
73276 + general case, the two uses in sys.c of gr_learn_cap are an exception
73277 + to this rule to ensure any role transition involves what the full-learned
73278 + policy believes in a privileged process
73279 + */
73280 + if (cap_raised(cred->cap_effective, cap) && gr_learn_cap(task, cred, cap))
73281 + return 1;
73282 +
73283 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
73284 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
73285 +
73286 + return 0;
73287 +}
73288 +
73289 +int
73290 +gr_acl_is_capable(const int cap)
73291 +{
73292 + return gr_task_acl_is_capable(current, current_cred(), cap);
73293 +}
73294 +
73295 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
73296 +{
73297 + struct acl_subject_label *curracl;
73298 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
73299 +
73300 + if (!gr_acl_is_enabled())
73301 + return 1;
73302 +
73303 + curracl = task->acl;
73304 +
73305 + cap_drop = curracl->cap_lower;
73306 + cap_mask = curracl->cap_mask;
73307 +
73308 + while ((curracl = curracl->parent_subject)) {
73309 + /* if the cap isn't specified in the current computed mask but is specified in the
73310 + current level subject, and is lowered in the current level subject, then add
73311 + it to the set of dropped capabilities
73312 + otherwise, add the current level subject's mask to the current computed mask
73313 + */
73314 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
73315 + cap_raise(cap_mask, cap);
73316 + if (cap_raised(curracl->cap_lower, cap))
73317 + cap_raise(cap_drop, cap);
73318 + }
73319 + }
73320 +
73321 + if (!cap_raised(cap_drop, cap))
73322 + return 1;
73323 +
73324 + return 0;
73325 +}
73326 +
73327 +int
73328 +gr_acl_is_capable_nolog(const int cap)
73329 +{
73330 + return gr_task_acl_is_capable_nolog(current, cap);
73331 +}
73332 +
73333 diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
73334 new file mode 100644
73335 index 0000000..ca25605
73336 --- /dev/null
73337 +++ b/grsecurity/gracl_compat.c
73338 @@ -0,0 +1,270 @@
73339 +#include <linux/kernel.h>
73340 +#include <linux/gracl.h>
73341 +#include <linux/compat.h>
73342 +#include <linux/gracl_compat.h>
73343 +
73344 +#include <asm/uaccess.h>
73345 +
73346 +int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
73347 +{
73348 + struct gr_arg_wrapper_compat uwrapcompat;
73349 +
73350 + if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
73351 + return -EFAULT;
73352 +
73353 + if (((uwrapcompat.version != GRSECURITY_VERSION) &&
73354 + (uwrapcompat.version != 0x2901)) ||
73355 + (uwrapcompat.size != sizeof(struct gr_arg_compat)))
73356 + return -EINVAL;
73357 +
73358 + uwrap->arg = compat_ptr(uwrapcompat.arg);
73359 + uwrap->version = uwrapcompat.version;
73360 + uwrap->size = sizeof(struct gr_arg);
73361 +
73362 + return 0;
73363 +}
73364 +
73365 +int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
73366 +{
73367 + struct gr_arg_compat argcompat;
73368 +
73369 + if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
73370 + return -EFAULT;
73371 +
73372 + arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
73373 + arg->role_db.num_pointers = argcompat.role_db.num_pointers;
73374 + arg->role_db.num_roles = argcompat.role_db.num_roles;
73375 + arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
73376 + arg->role_db.num_subjects = argcompat.role_db.num_subjects;
73377 + arg->role_db.num_objects = argcompat.role_db.num_objects;
73378 +
73379 + memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
73380 + memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
73381 + memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
73382 + memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
73383 + arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
73384 + arg->segv_device = argcompat.segv_device;
73385 + arg->segv_inode = argcompat.segv_inode;
73386 + arg->segv_uid = argcompat.segv_uid;
73387 + arg->num_sprole_pws = argcompat.num_sprole_pws;
73388 + arg->mode = argcompat.mode;
73389 +
73390 + return 0;
73391 +}
73392 +
73393 +int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
73394 +{
73395 + struct acl_object_label_compat objcompat;
73396 +
73397 + if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
73398 + return -EFAULT;
73399 +
73400 + obj->filename = compat_ptr(objcompat.filename);
73401 + obj->inode = objcompat.inode;
73402 + obj->device = objcompat.device;
73403 + obj->mode = objcompat.mode;
73404 +
73405 + obj->nested = compat_ptr(objcompat.nested);
73406 + obj->globbed = compat_ptr(objcompat.globbed);
73407 +
73408 + obj->prev = compat_ptr(objcompat.prev);
73409 + obj->next = compat_ptr(objcompat.next);
73410 +
73411 + return 0;
73412 +}
73413 +
73414 +int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
73415 +{
73416 + unsigned int i;
73417 + struct acl_subject_label_compat subjcompat;
73418 +
73419 + if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
73420 + return -EFAULT;
73421 +
73422 + subj->filename = compat_ptr(subjcompat.filename);
73423 + subj->inode = subjcompat.inode;
73424 + subj->device = subjcompat.device;
73425 + subj->mode = subjcompat.mode;
73426 + subj->cap_mask = subjcompat.cap_mask;
73427 + subj->cap_lower = subjcompat.cap_lower;
73428 + subj->cap_invert_audit = subjcompat.cap_invert_audit;
73429 +
73430 + for (i = 0; i < GR_NLIMITS; i++) {
73431 + if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
73432 + subj->res[i].rlim_cur = RLIM_INFINITY;
73433 + else
73434 + subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
73435 + if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
73436 + subj->res[i].rlim_max = RLIM_INFINITY;
73437 + else
73438 + subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
73439 + }
73440 + subj->resmask = subjcompat.resmask;
73441 +
73442 + subj->user_trans_type = subjcompat.user_trans_type;
73443 + subj->group_trans_type = subjcompat.group_trans_type;
73444 + subj->user_transitions = compat_ptr(subjcompat.user_transitions);
73445 + subj->group_transitions = compat_ptr(subjcompat.group_transitions);
73446 + subj->user_trans_num = subjcompat.user_trans_num;
73447 + subj->group_trans_num = subjcompat.group_trans_num;
73448 +
73449 + memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
73450 + memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
73451 + subj->ip_type = subjcompat.ip_type;
73452 + subj->ips = compat_ptr(subjcompat.ips);
73453 + subj->ip_num = subjcompat.ip_num;
73454 + subj->inaddr_any_override = subjcompat.inaddr_any_override;
73455 +
73456 + subj->crashes = subjcompat.crashes;
73457 + subj->expires = subjcompat.expires;
73458 +
73459 + subj->parent_subject = compat_ptr(subjcompat.parent_subject);
73460 + subj->hash = compat_ptr(subjcompat.hash);
73461 + subj->prev = compat_ptr(subjcompat.prev);
73462 + subj->next = compat_ptr(subjcompat.next);
73463 +
73464 + subj->obj_hash = compat_ptr(subjcompat.obj_hash);
73465 + subj->obj_hash_size = subjcompat.obj_hash_size;
73466 + subj->pax_flags = subjcompat.pax_flags;
73467 +
73468 + return 0;
73469 +}
73470 +
73471 +int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
73472 +{
73473 + struct acl_role_label_compat rolecompat;
73474 +
73475 + if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
73476 + return -EFAULT;
73477 +
73478 + role->rolename = compat_ptr(rolecompat.rolename);
73479 + role->uidgid = rolecompat.uidgid;
73480 + role->roletype = rolecompat.roletype;
73481 +
73482 + role->auth_attempts = rolecompat.auth_attempts;
73483 + role->expires = rolecompat.expires;
73484 +
73485 + role->root_label = compat_ptr(rolecompat.root_label);
73486 + role->hash = compat_ptr(rolecompat.hash);
73487 +
73488 + role->prev = compat_ptr(rolecompat.prev);
73489 + role->next = compat_ptr(rolecompat.next);
73490 +
73491 + role->transitions = compat_ptr(rolecompat.transitions);
73492 + role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
73493 + role->domain_children = compat_ptr(rolecompat.domain_children);
73494 + role->domain_child_num = rolecompat.domain_child_num;
73495 +
73496 + role->umask = rolecompat.umask;
73497 +
73498 + role->subj_hash = compat_ptr(rolecompat.subj_hash);
73499 + role->subj_hash_size = rolecompat.subj_hash_size;
73500 +
73501 + return 0;
73502 +}
73503 +
73504 +int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
73505 +{
73506 + struct role_allowed_ip_compat roleip_compat;
73507 +
73508 + if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
73509 + return -EFAULT;
73510 +
73511 + roleip->addr = roleip_compat.addr;
73512 + roleip->netmask = roleip_compat.netmask;
73513 +
73514 + roleip->prev = compat_ptr(roleip_compat.prev);
73515 + roleip->next = compat_ptr(roleip_compat.next);
73516 +
73517 + return 0;
73518 +}
73519 +
73520 +int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
73521 +{
73522 + struct role_transition_compat trans_compat;
73523 +
73524 + if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
73525 + return -EFAULT;
73526 +
73527 + trans->rolename = compat_ptr(trans_compat.rolename);
73528 +
73529 + trans->prev = compat_ptr(trans_compat.prev);
73530 + trans->next = compat_ptr(trans_compat.next);
73531 +
73532 + return 0;
73533 +
73534 +}
73535 +
73536 +int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
73537 +{
73538 + struct gr_hash_struct_compat hash_compat;
73539 +
73540 + if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
73541 + return -EFAULT;
73542 +
73543 + hash->table = compat_ptr(hash_compat.table);
73544 + hash->nametable = compat_ptr(hash_compat.nametable);
73545 + hash->first = compat_ptr(hash_compat.first);
73546 +
73547 + hash->table_size = hash_compat.table_size;
73548 + hash->used_size = hash_compat.used_size;
73549 +
73550 + hash->type = hash_compat.type;
73551 +
73552 + return 0;
73553 +}
73554 +
73555 +int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
73556 +{
73557 + compat_uptr_t ptrcompat;
73558 +
73559 + if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
73560 + return -EFAULT;
73561 +
73562 + *(void **)ptr = compat_ptr(ptrcompat);
73563 +
73564 + return 0;
73565 +}
73566 +
73567 +int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
73568 +{
73569 + struct acl_ip_label_compat ip_compat;
73570 +
73571 + if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
73572 + return -EFAULT;
73573 +
73574 + ip->iface = compat_ptr(ip_compat.iface);
73575 + ip->addr = ip_compat.addr;
73576 + ip->netmask = ip_compat.netmask;
73577 + ip->low = ip_compat.low;
73578 + ip->high = ip_compat.high;
73579 + ip->mode = ip_compat.mode;
73580 + ip->type = ip_compat.type;
73581 +
73582 + memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
73583 +
73584 + ip->prev = compat_ptr(ip_compat.prev);
73585 + ip->next = compat_ptr(ip_compat.next);
73586 +
73587 + return 0;
73588 +}
73589 +
73590 +int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
73591 +{
73592 + struct sprole_pw_compat pw_compat;
73593 +
73594 + if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
73595 + return -EFAULT;
73596 +
73597 + pw->rolename = compat_ptr(pw_compat.rolename);
73598 + memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
73599 + memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
73600 +
73601 + return 0;
73602 +}
73603 +
73604 +size_t get_gr_arg_wrapper_size_compat(void)
73605 +{
73606 + return sizeof(struct gr_arg_wrapper_compat);
73607 +}
73608 +
73609 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
73610 new file mode 100644
73611 index 0000000..4008fdc
73612 --- /dev/null
73613 +++ b/grsecurity/gracl_fs.c
73614 @@ -0,0 +1,445 @@
73615 +#include <linux/kernel.h>
73616 +#include <linux/sched.h>
73617 +#include <linux/types.h>
73618 +#include <linux/fs.h>
73619 +#include <linux/file.h>
73620 +#include <linux/stat.h>
73621 +#include <linux/grsecurity.h>
73622 +#include <linux/grinternal.h>
73623 +#include <linux/gracl.h>
73624 +
73625 +umode_t
73626 +gr_acl_umask(void)
73627 +{
73628 + if (unlikely(!gr_acl_is_enabled()))
73629 + return 0;
73630 +
73631 + return current->role->umask;
73632 +}
73633 +
73634 +__u32
73635 +gr_acl_handle_hidden_file(const struct dentry * dentry,
73636 + const struct vfsmount * mnt)
73637 +{
73638 + __u32 mode;
73639 +
73640 + if (unlikely(d_is_negative(dentry)))
73641 + return GR_FIND;
73642 +
73643 + mode =
73644 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
73645 +
73646 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
73647 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
73648 + return mode;
73649 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
73650 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
73651 + return 0;
73652 + } else if (unlikely(!(mode & GR_FIND)))
73653 + return 0;
73654 +
73655 + return GR_FIND;
73656 +}
73657 +
73658 +__u32
73659 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
73660 + int acc_mode)
73661 +{
73662 + __u32 reqmode = GR_FIND;
73663 + __u32 mode;
73664 +
73665 + if (unlikely(d_is_negative(dentry)))
73666 + return reqmode;
73667 +
73668 + if (acc_mode & MAY_APPEND)
73669 + reqmode |= GR_APPEND;
73670 + else if (acc_mode & MAY_WRITE)
73671 + reqmode |= GR_WRITE;
73672 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
73673 + reqmode |= GR_READ;
73674 +
73675 + mode =
73676 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
73677 + mnt);
73678 +
73679 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
73680 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
73681 + reqmode & GR_READ ? " reading" : "",
73682 + reqmode & GR_WRITE ? " writing" : reqmode &
73683 + GR_APPEND ? " appending" : "");
73684 + return reqmode;
73685 + } else
73686 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
73687 + {
73688 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
73689 + reqmode & GR_READ ? " reading" : "",
73690 + reqmode & GR_WRITE ? " writing" : reqmode &
73691 + GR_APPEND ? " appending" : "");
73692 + return 0;
73693 + } else if (unlikely((mode & reqmode) != reqmode))
73694 + return 0;
73695 +
73696 + return reqmode;
73697 +}
73698 +
73699 +__u32
73700 +gr_acl_handle_creat(const struct dentry * dentry,
73701 + const struct dentry * p_dentry,
73702 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
73703 + const int imode)
73704 +{
73705 + __u32 reqmode = GR_WRITE | GR_CREATE;
73706 + __u32 mode;
73707 +
73708 + if (acc_mode & MAY_APPEND)
73709 + reqmode |= GR_APPEND;
73710 + // if a directory was required or the directory already exists, then
73711 + // don't count this open as a read
73712 + if ((acc_mode & MAY_READ) &&
73713 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
73714 + reqmode |= GR_READ;
73715 + if ((open_flags & O_CREAT) &&
73716 + ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
73717 + reqmode |= GR_SETID;
73718 +
73719 + mode =
73720 + gr_check_create(dentry, p_dentry, p_mnt,
73721 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
73722 +
73723 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
73724 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
73725 + reqmode & GR_READ ? " reading" : "",
73726 + reqmode & GR_WRITE ? " writing" : reqmode &
73727 + GR_APPEND ? " appending" : "");
73728 + return reqmode;
73729 + } else
73730 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
73731 + {
73732 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
73733 + reqmode & GR_READ ? " reading" : "",
73734 + reqmode & GR_WRITE ? " writing" : reqmode &
73735 + GR_APPEND ? " appending" : "");
73736 + return 0;
73737 + } else if (unlikely((mode & reqmode) != reqmode))
73738 + return 0;
73739 +
73740 + return reqmode;
73741 +}
73742 +
73743 +__u32
73744 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
73745 + const int fmode)
73746 +{
73747 + __u32 mode, reqmode = GR_FIND;
73748 +
73749 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
73750 + reqmode |= GR_EXEC;
73751 + if (fmode & S_IWOTH)
73752 + reqmode |= GR_WRITE;
73753 + if (fmode & S_IROTH)
73754 + reqmode |= GR_READ;
73755 +
73756 + mode =
73757 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
73758 + mnt);
73759 +
73760 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
73761 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
73762 + reqmode & GR_READ ? " reading" : "",
73763 + reqmode & GR_WRITE ? " writing" : "",
73764 + reqmode & GR_EXEC ? " executing" : "");
73765 + return reqmode;
73766 + } else
73767 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
73768 + {
73769 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
73770 + reqmode & GR_READ ? " reading" : "",
73771 + reqmode & GR_WRITE ? " writing" : "",
73772 + reqmode & GR_EXEC ? " executing" : "");
73773 + return 0;
73774 + } else if (unlikely((mode & reqmode) != reqmode))
73775 + return 0;
73776 +
73777 + return reqmode;
73778 +}
73779 +
73780 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
73781 +{
73782 + __u32 mode;
73783 +
73784 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
73785 +
73786 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
73787 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
73788 + return mode;
73789 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
73790 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
73791 + return 0;
73792 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
73793 + return 0;
73794 +
73795 + return (reqmode);
73796 +}
73797 +
73798 +__u32
73799 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
73800 +{
73801 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
73802 +}
73803 +
73804 +__u32
73805 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
73806 +{
73807 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
73808 +}
73809 +
73810 +__u32
73811 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
73812 +{
73813 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
73814 +}
73815 +
73816 +__u32
73817 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
73818 +{
73819 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
73820 +}
73821 +
73822 +__u32
73823 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
73824 + umode_t *modeptr)
73825 +{
73826 + umode_t mode;
73827 +
73828 + *modeptr &= ~gr_acl_umask();
73829 + mode = *modeptr;
73830 +
73831 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
73832 + return 1;
73833 +
73834 + if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
73835 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
73836 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
73837 + GR_CHMOD_ACL_MSG);
73838 + } else {
73839 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
73840 + }
73841 +}
73842 +
73843 +__u32
73844 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
73845 +{
73846 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
73847 +}
73848 +
73849 +__u32
73850 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
73851 +{
73852 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
73853 +}
73854 +
73855 +__u32
73856 +gr_acl_handle_removexattr(const struct dentry *dentry, const struct vfsmount *mnt)
73857 +{
73858 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_REMOVEXATTR_ACL_MSG);
73859 +}
73860 +
73861 +__u32
73862 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
73863 +{
73864 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
73865 +}
73866 +
73867 +__u32
73868 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
73869 +{
73870 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
73871 + GR_UNIXCONNECT_ACL_MSG);
73872 +}
73873 +
73874 +/* hardlinks require at minimum create and link permission,
73875 + any additional privilege required is based on the
73876 + privilege of the file being linked to
73877 +*/
73878 +__u32
73879 +gr_acl_handle_link(const struct dentry * new_dentry,
73880 + const struct dentry * parent_dentry,
73881 + const struct vfsmount * parent_mnt,
73882 + const struct dentry * old_dentry,
73883 + const struct vfsmount * old_mnt, const struct filename *to)
73884 +{
73885 + __u32 mode;
73886 + __u32 needmode = GR_CREATE | GR_LINK;
73887 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
73888 +
73889 + mode =
73890 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
73891 + old_mnt);
73892 +
73893 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
73894 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
73895 + return mode;
73896 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
73897 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
73898 + return 0;
73899 + } else if (unlikely((mode & needmode) != needmode))
73900 + return 0;
73901 +
73902 + return 1;
73903 +}
73904 +
73905 +__u32
73906 +gr_acl_handle_symlink(const struct dentry * new_dentry,
73907 + const struct dentry * parent_dentry,
73908 + const struct vfsmount * parent_mnt, const struct filename *from)
73909 +{
73910 + __u32 needmode = GR_WRITE | GR_CREATE;
73911 + __u32 mode;
73912 +
73913 + mode =
73914 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
73915 + GR_CREATE | GR_AUDIT_CREATE |
73916 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
73917 +
73918 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
73919 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
73920 + return mode;
73921 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
73922 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
73923 + return 0;
73924 + } else if (unlikely((mode & needmode) != needmode))
73925 + return 0;
73926 +
73927 + return (GR_WRITE | GR_CREATE);
73928 +}
73929 +
73930 +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)
73931 +{
73932 + __u32 mode;
73933 +
73934 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
73935 +
73936 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
73937 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
73938 + return mode;
73939 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
73940 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
73941 + return 0;
73942 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
73943 + return 0;
73944 +
73945 + return (reqmode);
73946 +}
73947 +
73948 +__u32
73949 +gr_acl_handle_mknod(const struct dentry * new_dentry,
73950 + const struct dentry * parent_dentry,
73951 + const struct vfsmount * parent_mnt,
73952 + const int mode)
73953 +{
73954 + __u32 reqmode = GR_WRITE | GR_CREATE;
73955 + if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
73956 + reqmode |= GR_SETID;
73957 +
73958 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
73959 + reqmode, GR_MKNOD_ACL_MSG);
73960 +}
73961 +
73962 +__u32
73963 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
73964 + const struct dentry *parent_dentry,
73965 + const struct vfsmount *parent_mnt)
73966 +{
73967 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
73968 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
73969 +}
73970 +
73971 +#define RENAME_CHECK_SUCCESS(old, new) \
73972 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
73973 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
73974 +
73975 +int
73976 +gr_acl_handle_rename(struct dentry *new_dentry,
73977 + struct dentry *parent_dentry,
73978 + const struct vfsmount *parent_mnt,
73979 + struct dentry *old_dentry,
73980 + struct inode *old_parent_inode,
73981 + struct vfsmount *old_mnt, const struct filename *newname, unsigned int flags)
73982 +{
73983 + __u32 comp1, comp2;
73984 + int error = 0;
73985 +
73986 + if (unlikely(!gr_acl_is_enabled()))
73987 + return 0;
73988 +
73989 + if (flags & RENAME_EXCHANGE) {
73990 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
73991 + GR_AUDIT_READ | GR_AUDIT_WRITE |
73992 + GR_SUPPRESS, parent_mnt);
73993 + comp2 =
73994 + gr_search_file(old_dentry,
73995 + GR_READ | GR_WRITE | GR_AUDIT_READ |
73996 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
73997 + } else if (d_is_negative(new_dentry)) {
73998 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
73999 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
74000 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
74001 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
74002 + GR_DELETE | GR_AUDIT_DELETE |
74003 + GR_AUDIT_READ | GR_AUDIT_WRITE |
74004 + GR_SUPPRESS, old_mnt);
74005 + } else {
74006 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
74007 + GR_CREATE | GR_DELETE |
74008 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
74009 + GR_AUDIT_READ | GR_AUDIT_WRITE |
74010 + GR_SUPPRESS, parent_mnt);
74011 + comp2 =
74012 + gr_search_file(old_dentry,
74013 + GR_READ | GR_WRITE | GR_AUDIT_READ |
74014 + GR_DELETE | GR_AUDIT_DELETE |
74015 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
74016 + }
74017 +
74018 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
74019 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
74020 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
74021 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
74022 + && !(comp2 & GR_SUPPRESS)) {
74023 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
74024 + error = -EACCES;
74025 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
74026 + error = -EACCES;
74027 +
74028 + return error;
74029 +}
74030 +
74031 +void
74032 +gr_acl_handle_exit(void)
74033 +{
74034 + u16 id;
74035 + char *rolename;
74036 +
74037 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
74038 + !(current->role->roletype & GR_ROLE_PERSIST))) {
74039 + id = current->acl_role_id;
74040 + rolename = current->role->rolename;
74041 + gr_set_acls(1);
74042 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
74043 + }
74044 +
74045 + gr_put_exec_file(current);
74046 + return;
74047 +}
74048 +
74049 +int
74050 +gr_acl_handle_procpidmem(const struct task_struct *task)
74051 +{
74052 + if (unlikely(!gr_acl_is_enabled()))
74053 + return 0;
74054 +
74055 + if (task != current && task->acl->mode & GR_PROTPROCFD)
74056 + return -EACCES;
74057 +
74058 + return 0;
74059 +}
74060 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
74061 new file mode 100644
74062 index 0000000..f056b81
74063 --- /dev/null
74064 +++ b/grsecurity/gracl_ip.c
74065 @@ -0,0 +1,386 @@
74066 +#include <linux/kernel.h>
74067 +#include <asm/uaccess.h>
74068 +#include <asm/errno.h>
74069 +#include <net/sock.h>
74070 +#include <linux/file.h>
74071 +#include <linux/fs.h>
74072 +#include <linux/net.h>
74073 +#include <linux/in.h>
74074 +#include <linux/skbuff.h>
74075 +#include <linux/ip.h>
74076 +#include <linux/udp.h>
74077 +#include <linux/types.h>
74078 +#include <linux/sched.h>
74079 +#include <linux/netdevice.h>
74080 +#include <linux/inetdevice.h>
74081 +#include <linux/gracl.h>
74082 +#include <linux/grsecurity.h>
74083 +#include <linux/grinternal.h>
74084 +
74085 +#define GR_BIND 0x01
74086 +#define GR_CONNECT 0x02
74087 +#define GR_INVERT 0x04
74088 +#define GR_BINDOVERRIDE 0x08
74089 +#define GR_CONNECTOVERRIDE 0x10
74090 +#define GR_SOCK_FAMILY 0x20
74091 +
74092 +static const char * gr_protocols[IPPROTO_MAX] = {
74093 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
74094 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
74095 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
74096 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
74097 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
74098 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
74099 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
74100 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
74101 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
74102 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
74103 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
74104 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
74105 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
74106 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
74107 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
74108 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
74109 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
74110 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
74111 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
74112 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
74113 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
74114 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
74115 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
74116 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
74117 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
74118 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
74119 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
74120 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
74121 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
74122 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
74123 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
74124 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
74125 + };
74126 +
74127 +static const char * gr_socktypes[SOCK_MAX] = {
74128 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
74129 + "unknown:7", "unknown:8", "unknown:9", "packet"
74130 + };
74131 +
74132 +static const char * gr_sockfamilies[AF_MAX+1] = {
74133 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
74134 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
74135 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
74136 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
74137 + };
74138 +
74139 +const char *
74140 +gr_proto_to_name(unsigned char proto)
74141 +{
74142 + return gr_protocols[proto];
74143 +}
74144 +
74145 +const char *
74146 +gr_socktype_to_name(unsigned char type)
74147 +{
74148 + return gr_socktypes[type];
74149 +}
74150 +
74151 +const char *
74152 +gr_sockfamily_to_name(unsigned char family)
74153 +{
74154 + return gr_sockfamilies[family];
74155 +}
74156 +
74157 +extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
74158 +
74159 +int
74160 +gr_search_socket(const int domain, const int type, const int protocol)
74161 +{
74162 + struct acl_subject_label *curr;
74163 + const struct cred *cred = current_cred();
74164 +
74165 + if (unlikely(!gr_acl_is_enabled()))
74166 + goto exit;
74167 +
74168 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
74169 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
74170 + goto exit; // let the kernel handle it
74171 +
74172 + curr = current->acl;
74173 +
74174 + if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
74175 + /* the family is allowed, if this is PF_INET allow it only if
74176 + the extra sock type/protocol checks pass */
74177 + if (domain == PF_INET)
74178 + goto inet_check;
74179 + goto exit;
74180 + } else {
74181 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
74182 + __u32 fakeip = 0;
74183 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
74184 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
74185 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
74186 + gr_to_filename(current->exec_file->f_path.dentry,
74187 + current->exec_file->f_path.mnt) :
74188 + curr->filename, curr->filename,
74189 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
74190 + &current->signal->saved_ip);
74191 + goto exit;
74192 + }
74193 + goto exit_fail;
74194 + }
74195 +
74196 +inet_check:
74197 + /* the rest of this checking is for IPv4 only */
74198 + if (!curr->ips)
74199 + goto exit;
74200 +
74201 + if ((curr->ip_type & (1U << type)) &&
74202 + (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
74203 + goto exit;
74204 +
74205 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
74206 + /* we don't place acls on raw sockets , and sometimes
74207 + dgram/ip sockets are opened for ioctl and not
74208 + bind/connect, so we'll fake a bind learn log */
74209 + if (type == SOCK_RAW || type == SOCK_PACKET) {
74210 + __u32 fakeip = 0;
74211 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
74212 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
74213 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
74214 + gr_to_filename(current->exec_file->f_path.dentry,
74215 + current->exec_file->f_path.mnt) :
74216 + curr->filename, curr->filename,
74217 + &fakeip, 0, type,
74218 + protocol, GR_CONNECT, &current->signal->saved_ip);
74219 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
74220 + __u32 fakeip = 0;
74221 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
74222 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
74223 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
74224 + gr_to_filename(current->exec_file->f_path.dentry,
74225 + current->exec_file->f_path.mnt) :
74226 + curr->filename, curr->filename,
74227 + &fakeip, 0, type,
74228 + protocol, GR_BIND, &current->signal->saved_ip);
74229 + }
74230 + /* we'll log when they use connect or bind */
74231 + goto exit;
74232 + }
74233 +
74234 +exit_fail:
74235 + if (domain == PF_INET)
74236 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
74237 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
74238 + else if (rcu_access_pointer(net_families[domain]) != NULL)
74239 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
74240 + gr_socktype_to_name(type), protocol);
74241 +
74242 + return 0;
74243 +exit:
74244 + return 1;
74245 +}
74246 +
74247 +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)
74248 +{
74249 + if ((ip->mode & mode) &&
74250 + (ip_port >= ip->low) &&
74251 + (ip_port <= ip->high) &&
74252 + ((ntohl(ip_addr) & our_netmask) ==
74253 + (ntohl(our_addr) & our_netmask))
74254 + && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
74255 + && (ip->type & (1U << type))) {
74256 + if (ip->mode & GR_INVERT)
74257 + return 2; // specifically denied
74258 + else
74259 + return 1; // allowed
74260 + }
74261 +
74262 + return 0; // not specifically allowed, may continue parsing
74263 +}
74264 +
74265 +static int
74266 +gr_search_connectbind(const int full_mode, struct sock *sk,
74267 + struct sockaddr_in *addr, const int type)
74268 +{
74269 + char iface[IFNAMSIZ] = {0};
74270 + struct acl_subject_label *curr;
74271 + struct acl_ip_label *ip;
74272 + struct inet_sock *isk;
74273 + struct net_device *dev;
74274 + struct in_device *idev;
74275 + unsigned long i;
74276 + int ret;
74277 + int mode = full_mode & (GR_BIND | GR_CONNECT);
74278 + __u32 ip_addr = 0;
74279 + __u32 our_addr;
74280 + __u32 our_netmask;
74281 + char *p;
74282 + __u16 ip_port = 0;
74283 + const struct cred *cred = current_cred();
74284 +
74285 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
74286 + return 0;
74287 +
74288 + curr = current->acl;
74289 + isk = inet_sk(sk);
74290 +
74291 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
74292 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
74293 + addr->sin_addr.s_addr = curr->inaddr_any_override;
74294 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
74295 + struct sockaddr_in saddr;
74296 + int err;
74297 +
74298 + saddr.sin_family = AF_INET;
74299 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
74300 + saddr.sin_port = isk->inet_sport;
74301 +
74302 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
74303 + if (err)
74304 + return err;
74305 +
74306 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
74307 + if (err)
74308 + return err;
74309 + }
74310 +
74311 + if (!curr->ips)
74312 + return 0;
74313 +
74314 + ip_addr = addr->sin_addr.s_addr;
74315 + ip_port = ntohs(addr->sin_port);
74316 +
74317 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
74318 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
74319 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
74320 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
74321 + gr_to_filename(current->exec_file->f_path.dentry,
74322 + current->exec_file->f_path.mnt) :
74323 + curr->filename, curr->filename,
74324 + &ip_addr, ip_port, type,
74325 + sk->sk_protocol, mode, &current->signal->saved_ip);
74326 + return 0;
74327 + }
74328 +
74329 + for (i = 0; i < curr->ip_num; i++) {
74330 + ip = *(curr->ips + i);
74331 + if (ip->iface != NULL) {
74332 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
74333 + p = strchr(iface, ':');
74334 + if (p != NULL)
74335 + *p = '\0';
74336 + dev = dev_get_by_name(sock_net(sk), iface);
74337 + if (dev == NULL)
74338 + continue;
74339 + idev = in_dev_get(dev);
74340 + if (idev == NULL) {
74341 + dev_put(dev);
74342 + continue;
74343 + }
74344 + rcu_read_lock();
74345 + for_ifa(idev) {
74346 + if (!strcmp(ip->iface, ifa->ifa_label)) {
74347 + our_addr = ifa->ifa_address;
74348 + our_netmask = 0xffffffff;
74349 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
74350 + if (ret == 1) {
74351 + rcu_read_unlock();
74352 + in_dev_put(idev);
74353 + dev_put(dev);
74354 + return 0;
74355 + } else if (ret == 2) {
74356 + rcu_read_unlock();
74357 + in_dev_put(idev);
74358 + dev_put(dev);
74359 + goto denied;
74360 + }
74361 + }
74362 + } endfor_ifa(idev);
74363 + rcu_read_unlock();
74364 + in_dev_put(idev);
74365 + dev_put(dev);
74366 + } else {
74367 + our_addr = ip->addr;
74368 + our_netmask = ip->netmask;
74369 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
74370 + if (ret == 1)
74371 + return 0;
74372 + else if (ret == 2)
74373 + goto denied;
74374 + }
74375 + }
74376 +
74377 +denied:
74378 + if (mode == GR_BIND)
74379 + 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));
74380 + else if (mode == GR_CONNECT)
74381 + 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));
74382 +
74383 + return -EACCES;
74384 +}
74385 +
74386 +int
74387 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
74388 +{
74389 + /* always allow disconnection of dgram sockets with connect */
74390 + if (addr->sin_family == AF_UNSPEC)
74391 + return 0;
74392 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
74393 +}
74394 +
74395 +int
74396 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
74397 +{
74398 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
74399 +}
74400 +
74401 +int gr_search_listen(struct socket *sock)
74402 +{
74403 + struct sock *sk = sock->sk;
74404 + struct sockaddr_in addr;
74405 +
74406 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
74407 + addr.sin_port = inet_sk(sk)->inet_sport;
74408 +
74409 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
74410 +}
74411 +
74412 +int gr_search_accept(struct socket *sock)
74413 +{
74414 + struct sock *sk = sock->sk;
74415 + struct sockaddr_in addr;
74416 +
74417 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
74418 + addr.sin_port = inet_sk(sk)->inet_sport;
74419 +
74420 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
74421 +}
74422 +
74423 +int
74424 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
74425 +{
74426 + if (addr)
74427 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
74428 + else {
74429 + struct sockaddr_in sin;
74430 + const struct inet_sock *inet = inet_sk(sk);
74431 +
74432 + sin.sin_addr.s_addr = inet->inet_daddr;
74433 + sin.sin_port = inet->inet_dport;
74434 +
74435 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
74436 + }
74437 +}
74438 +
74439 +int
74440 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
74441 +{
74442 + struct sockaddr_in sin;
74443 +
74444 + if (unlikely(skb->len < sizeof (struct udphdr)))
74445 + return 0; // skip this packet
74446 +
74447 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
74448 + sin.sin_port = udp_hdr(skb)->source;
74449 +
74450 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
74451 +}
74452 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
74453 new file mode 100644
74454 index 0000000..25f54ef
74455 --- /dev/null
74456 +++ b/grsecurity/gracl_learn.c
74457 @@ -0,0 +1,207 @@
74458 +#include <linux/kernel.h>
74459 +#include <linux/mm.h>
74460 +#include <linux/sched.h>
74461 +#include <linux/poll.h>
74462 +#include <linux/string.h>
74463 +#include <linux/file.h>
74464 +#include <linux/types.h>
74465 +#include <linux/vmalloc.h>
74466 +#include <linux/grinternal.h>
74467 +
74468 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
74469 + size_t count, loff_t *ppos);
74470 +extern int gr_acl_is_enabled(void);
74471 +
74472 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
74473 +static int gr_learn_attached;
74474 +
74475 +/* use a 512k buffer */
74476 +#define LEARN_BUFFER_SIZE (512 * 1024)
74477 +
74478 +static DEFINE_SPINLOCK(gr_learn_lock);
74479 +static DEFINE_MUTEX(gr_learn_user_mutex);
74480 +
74481 +/* we need to maintain two buffers, so that the kernel context of grlearn
74482 + uses a semaphore around the userspace copying, and the other kernel contexts
74483 + use a spinlock when copying into the buffer, since they cannot sleep
74484 +*/
74485 +static char *learn_buffer;
74486 +static char *learn_buffer_user;
74487 +static int learn_buffer_len;
74488 +static int learn_buffer_user_len;
74489 +
74490 +static ssize_t
74491 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
74492 +{
74493 + DECLARE_WAITQUEUE(wait, current);
74494 + ssize_t retval = 0;
74495 +
74496 + add_wait_queue(&learn_wait, &wait);
74497 + set_current_state(TASK_INTERRUPTIBLE);
74498 + do {
74499 + mutex_lock(&gr_learn_user_mutex);
74500 + spin_lock(&gr_learn_lock);
74501 + if (learn_buffer_len)
74502 + break;
74503 + spin_unlock(&gr_learn_lock);
74504 + mutex_unlock(&gr_learn_user_mutex);
74505 + if (file->f_flags & O_NONBLOCK) {
74506 + retval = -EAGAIN;
74507 + goto out;
74508 + }
74509 + if (signal_pending(current)) {
74510 + retval = -ERESTARTSYS;
74511 + goto out;
74512 + }
74513 +
74514 + schedule();
74515 + } while (1);
74516 +
74517 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
74518 + learn_buffer_user_len = learn_buffer_len;
74519 + retval = learn_buffer_len;
74520 + learn_buffer_len = 0;
74521 +
74522 + spin_unlock(&gr_learn_lock);
74523 +
74524 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
74525 + retval = -EFAULT;
74526 +
74527 + mutex_unlock(&gr_learn_user_mutex);
74528 +out:
74529 + set_current_state(TASK_RUNNING);
74530 + remove_wait_queue(&learn_wait, &wait);
74531 + return retval;
74532 +}
74533 +
74534 +static unsigned int
74535 +poll_learn(struct file * file, poll_table * wait)
74536 +{
74537 + poll_wait(file, &learn_wait, wait);
74538 +
74539 + if (learn_buffer_len)
74540 + return (POLLIN | POLLRDNORM);
74541 +
74542 + return 0;
74543 +}
74544 +
74545 +void
74546 +gr_clear_learn_entries(void)
74547 +{
74548 + char *tmp;
74549 +
74550 + mutex_lock(&gr_learn_user_mutex);
74551 + spin_lock(&gr_learn_lock);
74552 + tmp = learn_buffer;
74553 + learn_buffer = NULL;
74554 + spin_unlock(&gr_learn_lock);
74555 + if (tmp)
74556 + vfree(tmp);
74557 + if (learn_buffer_user != NULL) {
74558 + vfree(learn_buffer_user);
74559 + learn_buffer_user = NULL;
74560 + }
74561 + learn_buffer_len = 0;
74562 + mutex_unlock(&gr_learn_user_mutex);
74563 +
74564 + return;
74565 +}
74566 +
74567 +void
74568 +gr_add_learn_entry(const char *fmt, ...)
74569 +{
74570 + va_list args;
74571 + unsigned int len;
74572 +
74573 + if (!gr_learn_attached)
74574 + return;
74575 +
74576 + spin_lock(&gr_learn_lock);
74577 +
74578 + /* leave a gap at the end so we know when it's "full" but don't have to
74579 + compute the exact length of the string we're trying to append
74580 + */
74581 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
74582 + spin_unlock(&gr_learn_lock);
74583 + wake_up_interruptible(&learn_wait);
74584 + return;
74585 + }
74586 + if (learn_buffer == NULL) {
74587 + spin_unlock(&gr_learn_lock);
74588 + return;
74589 + }
74590 +
74591 + va_start(args, fmt);
74592 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
74593 + va_end(args);
74594 +
74595 + learn_buffer_len += len + 1;
74596 +
74597 + spin_unlock(&gr_learn_lock);
74598 + wake_up_interruptible(&learn_wait);
74599 +
74600 + return;
74601 +}
74602 +
74603 +static int
74604 +open_learn(struct inode *inode, struct file *file)
74605 +{
74606 + if (file->f_mode & FMODE_READ && gr_learn_attached)
74607 + return -EBUSY;
74608 + if (file->f_mode & FMODE_READ) {
74609 + int retval = 0;
74610 + mutex_lock(&gr_learn_user_mutex);
74611 + if (learn_buffer == NULL)
74612 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
74613 + if (learn_buffer_user == NULL)
74614 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
74615 + if (learn_buffer == NULL) {
74616 + retval = -ENOMEM;
74617 + goto out_error;
74618 + }
74619 + if (learn_buffer_user == NULL) {
74620 + retval = -ENOMEM;
74621 + goto out_error;
74622 + }
74623 + learn_buffer_len = 0;
74624 + learn_buffer_user_len = 0;
74625 + gr_learn_attached = 1;
74626 +out_error:
74627 + mutex_unlock(&gr_learn_user_mutex);
74628 + return retval;
74629 + }
74630 + return 0;
74631 +}
74632 +
74633 +static int
74634 +close_learn(struct inode *inode, struct file *file)
74635 +{
74636 + if (file->f_mode & FMODE_READ) {
74637 + char *tmp = NULL;
74638 + mutex_lock(&gr_learn_user_mutex);
74639 + spin_lock(&gr_learn_lock);
74640 + tmp = learn_buffer;
74641 + learn_buffer = NULL;
74642 + spin_unlock(&gr_learn_lock);
74643 + if (tmp)
74644 + vfree(tmp);
74645 + if (learn_buffer_user != NULL) {
74646 + vfree(learn_buffer_user);
74647 + learn_buffer_user = NULL;
74648 + }
74649 + learn_buffer_len = 0;
74650 + learn_buffer_user_len = 0;
74651 + gr_learn_attached = 0;
74652 + mutex_unlock(&gr_learn_user_mutex);
74653 + }
74654 +
74655 + return 0;
74656 +}
74657 +
74658 +const struct file_operations grsec_fops = {
74659 + .read = read_learn,
74660 + .write = write_grsec_handler,
74661 + .open = open_learn,
74662 + .release = close_learn,
74663 + .poll = poll_learn,
74664 +};
74665 diff --git a/grsecurity/gracl_policy.c b/grsecurity/gracl_policy.c
74666 new file mode 100644
74667 index 0000000..3f8ade0
74668 --- /dev/null
74669 +++ b/grsecurity/gracl_policy.c
74670 @@ -0,0 +1,1782 @@
74671 +#include <linux/kernel.h>
74672 +#include <linux/module.h>
74673 +#include <linux/sched.h>
74674 +#include <linux/mm.h>
74675 +#include <linux/file.h>
74676 +#include <linux/fs.h>
74677 +#include <linux/namei.h>
74678 +#include <linux/mount.h>
74679 +#include <linux/tty.h>
74680 +#include <linux/proc_fs.h>
74681 +#include <linux/lglock.h>
74682 +#include <linux/slab.h>
74683 +#include <linux/vmalloc.h>
74684 +#include <linux/types.h>
74685 +#include <linux/sysctl.h>
74686 +#include <linux/netdevice.h>
74687 +#include <linux/ptrace.h>
74688 +#include <linux/gracl.h>
74689 +#include <linux/gralloc.h>
74690 +#include <linux/security.h>
74691 +#include <linux/grinternal.h>
74692 +#include <linux/pid_namespace.h>
74693 +#include <linux/stop_machine.h>
74694 +#include <linux/fdtable.h>
74695 +#include <linux/percpu.h>
74696 +#include <linux/lglock.h>
74697 +#include <linux/hugetlb.h>
74698 +#include <linux/posix-timers.h>
74699 +#include "../fs/mount.h"
74700 +
74701 +#include <asm/uaccess.h>
74702 +#include <asm/errno.h>
74703 +#include <asm/mman.h>
74704 +
74705 +extern struct gr_policy_state *polstate;
74706 +
74707 +#define FOR_EACH_ROLE_START(role) \
74708 + role = polstate->role_list; \
74709 + while (role) {
74710 +
74711 +#define FOR_EACH_ROLE_END(role) \
74712 + role = role->prev; \
74713 + }
74714 +
74715 +struct path gr_real_root;
74716 +
74717 +extern struct gr_alloc_state *current_alloc_state;
74718 +
74719 +u16 acl_sp_role_value;
74720 +
74721 +static DEFINE_MUTEX(gr_dev_mutex);
74722 +
74723 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
74724 +extern void gr_clear_learn_entries(void);
74725 +
74726 +struct gr_arg *gr_usermode __read_only;
74727 +unsigned char *gr_system_salt __read_only;
74728 +unsigned char *gr_system_sum __read_only;
74729 +
74730 +static unsigned int gr_auth_attempts = 0;
74731 +static unsigned long gr_auth_expires = 0UL;
74732 +
74733 +struct acl_object_label *fakefs_obj_rw;
74734 +struct acl_object_label *fakefs_obj_rwx;
74735 +
74736 +extern int gr_init_uidset(void);
74737 +extern void gr_free_uidset(void);
74738 +extern void gr_remove_uid(uid_t uid);
74739 +extern int gr_find_uid(uid_t uid);
74740 +
74741 +extern struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename);
74742 +extern void __gr_apply_subject_to_task(struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj);
74743 +extern int gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb);
74744 +extern void __insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry);
74745 +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);
74746 +extern void insert_acl_obj_label(struct acl_object_label *obj, struct acl_subject_label *subj);
74747 +extern void insert_acl_subj_label(struct acl_subject_label *obj, struct acl_role_label *role);
74748 +extern struct name_entry * __lookup_name_entry(const struct gr_policy_state *state, const char *name);
74749 +extern char *gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt);
74750 +extern struct acl_subject_label *lookup_acl_subj_label(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
74751 +extern struct acl_subject_label *lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
74752 +extern void assign_special_role(const char *rolename);
74753 +extern struct acl_subject_label *chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt, const struct acl_role_label *role);
74754 +extern int gr_rbac_disable(void *unused);
74755 +extern void gr_enable_rbac_system(void);
74756 +
74757 +static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
74758 +{
74759 + if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
74760 + return -EFAULT;
74761 +
74762 + return 0;
74763 +}
74764 +
74765 +static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
74766 +{
74767 + if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
74768 + return -EFAULT;
74769 +
74770 + return 0;
74771 +}
74772 +
74773 +static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
74774 +{
74775 + if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
74776 + return -EFAULT;
74777 +
74778 + return 0;
74779 +}
74780 +
74781 +static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
74782 +{
74783 + if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
74784 + return -EFAULT;
74785 +
74786 + return 0;
74787 +}
74788 +
74789 +static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
74790 +{
74791 + if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
74792 + return -EFAULT;
74793 +
74794 + return 0;
74795 +}
74796 +
74797 +static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
74798 +{
74799 + if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
74800 + return -EFAULT;
74801 +
74802 + return 0;
74803 +}
74804 +
74805 +static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
74806 +{
74807 + if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
74808 + return -EFAULT;
74809 +
74810 + return 0;
74811 +}
74812 +
74813 +static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
74814 +{
74815 + if (copy_from_user(trans, userp, sizeof(struct role_transition)))
74816 + return -EFAULT;
74817 +
74818 + return 0;
74819 +}
74820 +
74821 +int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
74822 +{
74823 + if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
74824 + return -EFAULT;
74825 +
74826 + return 0;
74827 +}
74828 +
74829 +static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
74830 +{
74831 + if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
74832 + return -EFAULT;
74833 +
74834 + if (((uwrap->version != GRSECURITY_VERSION) &&
74835 + (uwrap->version != 0x2901)) ||
74836 + (uwrap->size != sizeof(struct gr_arg)))
74837 + return -EINVAL;
74838 +
74839 + return 0;
74840 +}
74841 +
74842 +static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
74843 +{
74844 + if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
74845 + return -EFAULT;
74846 +
74847 + return 0;
74848 +}
74849 +
74850 +static size_t get_gr_arg_wrapper_size_normal(void)
74851 +{
74852 + return sizeof(struct gr_arg_wrapper);
74853 +}
74854 +
74855 +#ifdef CONFIG_COMPAT
74856 +extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
74857 +extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
74858 +extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
74859 +extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
74860 +extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
74861 +extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
74862 +extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
74863 +extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
74864 +extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
74865 +extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
74866 +extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
74867 +extern size_t get_gr_arg_wrapper_size_compat(void);
74868 +
74869 +int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
74870 +int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
74871 +int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
74872 +int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
74873 +int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
74874 +int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
74875 +int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
74876 +int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
74877 +int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
74878 +int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
74879 +int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
74880 +size_t (* get_gr_arg_wrapper_size)(void) __read_only;
74881 +
74882 +#else
74883 +#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
74884 +#define copy_gr_arg copy_gr_arg_normal
74885 +#define copy_gr_hash_struct copy_gr_hash_struct_normal
74886 +#define copy_acl_object_label copy_acl_object_label_normal
74887 +#define copy_acl_subject_label copy_acl_subject_label_normal
74888 +#define copy_acl_role_label copy_acl_role_label_normal
74889 +#define copy_acl_ip_label copy_acl_ip_label_normal
74890 +#define copy_pointer_from_array copy_pointer_from_array_normal
74891 +#define copy_sprole_pw copy_sprole_pw_normal
74892 +#define copy_role_transition copy_role_transition_normal
74893 +#define copy_role_allowed_ip copy_role_allowed_ip_normal
74894 +#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
74895 +#endif
74896 +
74897 +static struct acl_subject_label *
74898 +lookup_subject_map(const struct acl_subject_label *userp)
74899 +{
74900 + unsigned int index = gr_shash(userp, polstate->subj_map_set.s_size);
74901 + struct subject_map *match;
74902 +
74903 + match = polstate->subj_map_set.s_hash[index];
74904 +
74905 + while (match && match->user != userp)
74906 + match = match->next;
74907 +
74908 + if (match != NULL)
74909 + return match->kernel;
74910 + else
74911 + return NULL;
74912 +}
74913 +
74914 +static void
74915 +insert_subj_map_entry(struct subject_map *subjmap)
74916 +{
74917 + unsigned int index = gr_shash(subjmap->user, polstate->subj_map_set.s_size);
74918 + struct subject_map **curr;
74919 +
74920 + subjmap->prev = NULL;
74921 +
74922 + curr = &polstate->subj_map_set.s_hash[index];
74923 + if (*curr != NULL)
74924 + (*curr)->prev = subjmap;
74925 +
74926 + subjmap->next = *curr;
74927 + *curr = subjmap;
74928 +
74929 + return;
74930 +}
74931 +
74932 +static void
74933 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
74934 +{
74935 + unsigned int index =
74936 + gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), polstate->acl_role_set.r_size);
74937 + struct acl_role_label **curr;
74938 + struct acl_role_label *tmp, *tmp2;
74939 +
74940 + curr = &polstate->acl_role_set.r_hash[index];
74941 +
74942 + /* simple case, slot is empty, just set it to our role */
74943 + if (*curr == NULL) {
74944 + *curr = role;
74945 + } else {
74946 + /* example:
74947 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
74948 + 2 -> 3
74949 + */
74950 + /* first check to see if we can already be reached via this slot */
74951 + tmp = *curr;
74952 + while (tmp && tmp != role)
74953 + tmp = tmp->next;
74954 + if (tmp == role) {
74955 + /* we don't need to add ourselves to this slot's chain */
74956 + return;
74957 + }
74958 + /* we need to add ourselves to this chain, two cases */
74959 + if (role->next == NULL) {
74960 + /* simple case, append the current chain to our role */
74961 + role->next = *curr;
74962 + *curr = role;
74963 + } else {
74964 + /* 1 -> 2 -> 3 -> 4
74965 + 2 -> 3 -> 4
74966 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
74967 + */
74968 + /* trickier case: walk our role's chain until we find
74969 + the role for the start of the current slot's chain */
74970 + tmp = role;
74971 + tmp2 = *curr;
74972 + while (tmp->next && tmp->next != tmp2)
74973 + tmp = tmp->next;
74974 + if (tmp->next == tmp2) {
74975 + /* from example above, we found 3, so just
74976 + replace this slot's chain with ours */
74977 + *curr = role;
74978 + } else {
74979 + /* we didn't find a subset of our role's chain
74980 + in the current slot's chain, so append their
74981 + chain to ours, and set us as the first role in
74982 + the slot's chain
74983 +
74984 + we could fold this case with the case above,
74985 + but making it explicit for clarity
74986 + */
74987 + tmp->next = tmp2;
74988 + *curr = role;
74989 + }
74990 + }
74991 + }
74992 +
74993 + return;
74994 +}
74995 +
74996 +static void
74997 +insert_acl_role_label(struct acl_role_label *role)
74998 +{
74999 + int i;
75000 +
75001 + if (polstate->role_list == NULL) {
75002 + polstate->role_list = role;
75003 + role->prev = NULL;
75004 + } else {
75005 + role->prev = polstate->role_list;
75006 + polstate->role_list = role;
75007 + }
75008 +
75009 + /* used for hash chains */
75010 + role->next = NULL;
75011 +
75012 + if (role->roletype & GR_ROLE_DOMAIN) {
75013 + for (i = 0; i < role->domain_child_num; i++)
75014 + __insert_acl_role_label(role, role->domain_children[i]);
75015 + } else
75016 + __insert_acl_role_label(role, role->uidgid);
75017 +}
75018 +
75019 +static int
75020 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
75021 +{
75022 + struct name_entry **curr, *nentry;
75023 + struct inodev_entry *ientry;
75024 + unsigned int len = strlen(name);
75025 + unsigned int key = full_name_hash(name, len);
75026 + unsigned int index = key % polstate->name_set.n_size;
75027 +
75028 + curr = &polstate->name_set.n_hash[index];
75029 +
75030 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
75031 + curr = &((*curr)->next);
75032 +
75033 + if (*curr != NULL)
75034 + return 1;
75035 +
75036 + nentry = acl_alloc(sizeof (struct name_entry));
75037 + if (nentry == NULL)
75038 + return 0;
75039 + ientry = acl_alloc(sizeof (struct inodev_entry));
75040 + if (ientry == NULL)
75041 + return 0;
75042 + ientry->nentry = nentry;
75043 +
75044 + nentry->key = key;
75045 + nentry->name = name;
75046 + nentry->inode = inode;
75047 + nentry->device = device;
75048 + nentry->len = len;
75049 + nentry->deleted = deleted;
75050 +
75051 + nentry->prev = NULL;
75052 + curr = &polstate->name_set.n_hash[index];
75053 + if (*curr != NULL)
75054 + (*curr)->prev = nentry;
75055 + nentry->next = *curr;
75056 + *curr = nentry;
75057 +
75058 + /* insert us into the table searchable by inode/dev */
75059 + __insert_inodev_entry(polstate, ientry);
75060 +
75061 + return 1;
75062 +}
75063 +
75064 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
75065 +
75066 +static void *
75067 +create_table(__u32 * len, int elementsize)
75068 +{
75069 + unsigned int table_sizes[] = {
75070 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
75071 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
75072 + 4194301, 8388593, 16777213, 33554393, 67108859
75073 + };
75074 + void *newtable = NULL;
75075 + unsigned int pwr = 0;
75076 +
75077 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
75078 + table_sizes[pwr] <= *len)
75079 + pwr++;
75080 +
75081 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
75082 + return newtable;
75083 +
75084 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
75085 + newtable =
75086 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
75087 + else
75088 + newtable = vmalloc(table_sizes[pwr] * elementsize);
75089 +
75090 + *len = table_sizes[pwr];
75091 +
75092 + return newtable;
75093 +}
75094 +
75095 +static int
75096 +init_variables(const struct gr_arg *arg, bool reload)
75097 +{
75098 + struct task_struct *reaper = init_pid_ns.child_reaper;
75099 + unsigned int stacksize;
75100 +
75101 + polstate->subj_map_set.s_size = arg->role_db.num_subjects;
75102 + polstate->acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
75103 + polstate->name_set.n_size = arg->role_db.num_objects;
75104 + polstate->inodev_set.i_size = arg->role_db.num_objects;
75105 +
75106 + if (!polstate->subj_map_set.s_size || !polstate->acl_role_set.r_size ||
75107 + !polstate->name_set.n_size || !polstate->inodev_set.i_size)
75108 + return 1;
75109 +
75110 + if (!reload) {
75111 + if (!gr_init_uidset())
75112 + return 1;
75113 + }
75114 +
75115 + /* set up the stack that holds allocation info */
75116 +
75117 + stacksize = arg->role_db.num_pointers + 5;
75118 +
75119 + if (!acl_alloc_stack_init(stacksize))
75120 + return 1;
75121 +
75122 + if (!reload) {
75123 + /* grab reference for the real root dentry and vfsmount */
75124 + get_fs_root(reaper->fs, &gr_real_root);
75125 +
75126 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
75127 + 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);
75128 +#endif
75129 +
75130 + fakefs_obj_rw = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
75131 + if (fakefs_obj_rw == NULL)
75132 + return 1;
75133 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
75134 +
75135 + fakefs_obj_rwx = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
75136 + if (fakefs_obj_rwx == NULL)
75137 + return 1;
75138 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
75139 + }
75140 +
75141 + polstate->subj_map_set.s_hash =
75142 + (struct subject_map **) create_table(&polstate->subj_map_set.s_size, sizeof(void *));
75143 + polstate->acl_role_set.r_hash =
75144 + (struct acl_role_label **) create_table(&polstate->acl_role_set.r_size, sizeof(void *));
75145 + polstate->name_set.n_hash = (struct name_entry **) create_table(&polstate->name_set.n_size, sizeof(void *));
75146 + polstate->inodev_set.i_hash =
75147 + (struct inodev_entry **) create_table(&polstate->inodev_set.i_size, sizeof(void *));
75148 +
75149 + if (!polstate->subj_map_set.s_hash || !polstate->acl_role_set.r_hash ||
75150 + !polstate->name_set.n_hash || !polstate->inodev_set.i_hash)
75151 + return 1;
75152 +
75153 + memset(polstate->subj_map_set.s_hash, 0,
75154 + sizeof(struct subject_map *) * polstate->subj_map_set.s_size);
75155 + memset(polstate->acl_role_set.r_hash, 0,
75156 + sizeof (struct acl_role_label *) * polstate->acl_role_set.r_size);
75157 + memset(polstate->name_set.n_hash, 0,
75158 + sizeof (struct name_entry *) * polstate->name_set.n_size);
75159 + memset(polstate->inodev_set.i_hash, 0,
75160 + sizeof (struct inodev_entry *) * polstate->inodev_set.i_size);
75161 +
75162 + return 0;
75163 +}
75164 +
75165 +/* free information not needed after startup
75166 + currently contains user->kernel pointer mappings for subjects
75167 +*/
75168 +
75169 +static void
75170 +free_init_variables(void)
75171 +{
75172 + __u32 i;
75173 +
75174 + if (polstate->subj_map_set.s_hash) {
75175 + for (i = 0; i < polstate->subj_map_set.s_size; i++) {
75176 + if (polstate->subj_map_set.s_hash[i]) {
75177 + kfree(polstate->subj_map_set.s_hash[i]);
75178 + polstate->subj_map_set.s_hash[i] = NULL;
75179 + }
75180 + }
75181 +
75182 + if ((polstate->subj_map_set.s_size * sizeof (struct subject_map *)) <=
75183 + PAGE_SIZE)
75184 + kfree(polstate->subj_map_set.s_hash);
75185 + else
75186 + vfree(polstate->subj_map_set.s_hash);
75187 + }
75188 +
75189 + return;
75190 +}
75191 +
75192 +static void
75193 +free_variables(bool reload)
75194 +{
75195 + struct acl_subject_label *s;
75196 + struct acl_role_label *r;
75197 + struct task_struct *task, *task2;
75198 + unsigned int x;
75199 +
75200 + if (!reload) {
75201 + gr_clear_learn_entries();
75202 +
75203 + read_lock(&tasklist_lock);
75204 + do_each_thread(task2, task) {
75205 + task->acl_sp_role = 0;
75206 + task->acl_role_id = 0;
75207 + task->inherited = 0;
75208 + task->acl = NULL;
75209 + task->role = NULL;
75210 + } while_each_thread(task2, task);
75211 + read_unlock(&tasklist_lock);
75212 +
75213 + kfree(fakefs_obj_rw);
75214 + fakefs_obj_rw = NULL;
75215 + kfree(fakefs_obj_rwx);
75216 + fakefs_obj_rwx = NULL;
75217 +
75218 + /* release the reference to the real root dentry and vfsmount */
75219 + path_put(&gr_real_root);
75220 + memset(&gr_real_root, 0, sizeof(gr_real_root));
75221 + }
75222 +
75223 + /* free all object hash tables */
75224 +
75225 + FOR_EACH_ROLE_START(r)
75226 + if (r->subj_hash == NULL)
75227 + goto next_role;
75228 + FOR_EACH_SUBJECT_START(r, s, x)
75229 + if (s->obj_hash == NULL)
75230 + break;
75231 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
75232 + kfree(s->obj_hash);
75233 + else
75234 + vfree(s->obj_hash);
75235 + FOR_EACH_SUBJECT_END(s, x)
75236 + FOR_EACH_NESTED_SUBJECT_START(r, s)
75237 + if (s->obj_hash == NULL)
75238 + break;
75239 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
75240 + kfree(s->obj_hash);
75241 + else
75242 + vfree(s->obj_hash);
75243 + FOR_EACH_NESTED_SUBJECT_END(s)
75244 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
75245 + kfree(r->subj_hash);
75246 + else
75247 + vfree(r->subj_hash);
75248 + r->subj_hash = NULL;
75249 +next_role:
75250 + FOR_EACH_ROLE_END(r)
75251 +
75252 + acl_free_all();
75253 +
75254 + if (polstate->acl_role_set.r_hash) {
75255 + if ((polstate->acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
75256 + PAGE_SIZE)
75257 + kfree(polstate->acl_role_set.r_hash);
75258 + else
75259 + vfree(polstate->acl_role_set.r_hash);
75260 + }
75261 + if (polstate->name_set.n_hash) {
75262 + if ((polstate->name_set.n_size * sizeof (struct name_entry *)) <=
75263 + PAGE_SIZE)
75264 + kfree(polstate->name_set.n_hash);
75265 + else
75266 + vfree(polstate->name_set.n_hash);
75267 + }
75268 +
75269 + if (polstate->inodev_set.i_hash) {
75270 + if ((polstate->inodev_set.i_size * sizeof (struct inodev_entry *)) <=
75271 + PAGE_SIZE)
75272 + kfree(polstate->inodev_set.i_hash);
75273 + else
75274 + vfree(polstate->inodev_set.i_hash);
75275 + }
75276 +
75277 + if (!reload)
75278 + gr_free_uidset();
75279 +
75280 + memset(&polstate->name_set, 0, sizeof (struct name_db));
75281 + memset(&polstate->inodev_set, 0, sizeof (struct inodev_db));
75282 + memset(&polstate->acl_role_set, 0, sizeof (struct acl_role_db));
75283 + memset(&polstate->subj_map_set, 0, sizeof (struct acl_subj_map_db));
75284 +
75285 + polstate->default_role = NULL;
75286 + polstate->kernel_role = NULL;
75287 + polstate->role_list = NULL;
75288 +
75289 + return;
75290 +}
75291 +
75292 +static struct acl_subject_label *
75293 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
75294 +
75295 +static int alloc_and_copy_string(char **name, unsigned int maxlen)
75296 +{
75297 + unsigned int len = strnlen_user(*name, maxlen);
75298 + char *tmp;
75299 +
75300 + if (!len || len >= maxlen)
75301 + return -EINVAL;
75302 +
75303 + if ((tmp = (char *) acl_alloc(len)) == NULL)
75304 + return -ENOMEM;
75305 +
75306 + if (copy_from_user(tmp, *name, len))
75307 + return -EFAULT;
75308 +
75309 + tmp[len-1] = '\0';
75310 + *name = tmp;
75311 +
75312 + return 0;
75313 +}
75314 +
75315 +static int
75316 +copy_user_glob(struct acl_object_label *obj)
75317 +{
75318 + struct acl_object_label *g_tmp, **guser;
75319 + int error;
75320 +
75321 + if (obj->globbed == NULL)
75322 + return 0;
75323 +
75324 + guser = &obj->globbed;
75325 + while (*guser) {
75326 + g_tmp = (struct acl_object_label *)
75327 + acl_alloc(sizeof (struct acl_object_label));
75328 + if (g_tmp == NULL)
75329 + return -ENOMEM;
75330 +
75331 + if (copy_acl_object_label(g_tmp, *guser))
75332 + return -EFAULT;
75333 +
75334 + error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
75335 + if (error)
75336 + return error;
75337 +
75338 + *guser = g_tmp;
75339 + guser = &(g_tmp->next);
75340 + }
75341 +
75342 + return 0;
75343 +}
75344 +
75345 +static int
75346 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
75347 + struct acl_role_label *role)
75348 +{
75349 + struct acl_object_label *o_tmp;
75350 + int ret;
75351 +
75352 + while (userp) {
75353 + if ((o_tmp = (struct acl_object_label *)
75354 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
75355 + return -ENOMEM;
75356 +
75357 + if (copy_acl_object_label(o_tmp, userp))
75358 + return -EFAULT;
75359 +
75360 + userp = o_tmp->prev;
75361 +
75362 + ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
75363 + if (ret)
75364 + return ret;
75365 +
75366 + insert_acl_obj_label(o_tmp, subj);
75367 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
75368 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
75369 + return -ENOMEM;
75370 +
75371 + ret = copy_user_glob(o_tmp);
75372 + if (ret)
75373 + return ret;
75374 +
75375 + if (o_tmp->nested) {
75376 + int already_copied;
75377 +
75378 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
75379 + if (IS_ERR(o_tmp->nested))
75380 + return PTR_ERR(o_tmp->nested);
75381 +
75382 + /* insert into nested subject list if we haven't copied this one yet
75383 + to prevent duplicate entries */
75384 + if (!already_copied) {
75385 + o_tmp->nested->next = role->hash->first;
75386 + role->hash->first = o_tmp->nested;
75387 + }
75388 + }
75389 + }
75390 +
75391 + return 0;
75392 +}
75393 +
75394 +static __u32
75395 +count_user_subjs(struct acl_subject_label *userp)
75396 +{
75397 + struct acl_subject_label s_tmp;
75398 + __u32 num = 0;
75399 +
75400 + while (userp) {
75401 + if (copy_acl_subject_label(&s_tmp, userp))
75402 + break;
75403 +
75404 + userp = s_tmp.prev;
75405 + }
75406 +
75407 + return num;
75408 +}
75409 +
75410 +static int
75411 +copy_user_allowedips(struct acl_role_label *rolep)
75412 +{
75413 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
75414 +
75415 + ruserip = rolep->allowed_ips;
75416 +
75417 + while (ruserip) {
75418 + rlast = rtmp;
75419 +
75420 + if ((rtmp = (struct role_allowed_ip *)
75421 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
75422 + return -ENOMEM;
75423 +
75424 + if (copy_role_allowed_ip(rtmp, ruserip))
75425 + return -EFAULT;
75426 +
75427 + ruserip = rtmp->prev;
75428 +
75429 + if (!rlast) {
75430 + rtmp->prev = NULL;
75431 + rolep->allowed_ips = rtmp;
75432 + } else {
75433 + rlast->next = rtmp;
75434 + rtmp->prev = rlast;
75435 + }
75436 +
75437 + if (!ruserip)
75438 + rtmp->next = NULL;
75439 + }
75440 +
75441 + return 0;
75442 +}
75443 +
75444 +static int
75445 +copy_user_transitions(struct acl_role_label *rolep)
75446 +{
75447 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
75448 + int error;
75449 +
75450 + rusertp = rolep->transitions;
75451 +
75452 + while (rusertp) {
75453 + rlast = rtmp;
75454 +
75455 + if ((rtmp = (struct role_transition *)
75456 + acl_alloc(sizeof (struct role_transition))) == NULL)
75457 + return -ENOMEM;
75458 +
75459 + if (copy_role_transition(rtmp, rusertp))
75460 + return -EFAULT;
75461 +
75462 + rusertp = rtmp->prev;
75463 +
75464 + error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
75465 + if (error)
75466 + return error;
75467 +
75468 + if (!rlast) {
75469 + rtmp->prev = NULL;
75470 + rolep->transitions = rtmp;
75471 + } else {
75472 + rlast->next = rtmp;
75473 + rtmp->prev = rlast;
75474 + }
75475 +
75476 + if (!rusertp)
75477 + rtmp->next = NULL;
75478 + }
75479 +
75480 + return 0;
75481 +}
75482 +
75483 +static __u32 count_user_objs(const struct acl_object_label __user *userp)
75484 +{
75485 + struct acl_object_label o_tmp;
75486 + __u32 num = 0;
75487 +
75488 + while (userp) {
75489 + if (copy_acl_object_label(&o_tmp, userp))
75490 + break;
75491 +
75492 + userp = o_tmp.prev;
75493 + num++;
75494 + }
75495 +
75496 + return num;
75497 +}
75498 +
75499 +static struct acl_subject_label *
75500 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
75501 +{
75502 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
75503 + __u32 num_objs;
75504 + struct acl_ip_label **i_tmp, *i_utmp2;
75505 + struct gr_hash_struct ghash;
75506 + struct subject_map *subjmap;
75507 + unsigned int i_num;
75508 + int err;
75509 +
75510 + if (already_copied != NULL)
75511 + *already_copied = 0;
75512 +
75513 + s_tmp = lookup_subject_map(userp);
75514 +
75515 + /* we've already copied this subject into the kernel, just return
75516 + the reference to it, and don't copy it over again
75517 + */
75518 + if (s_tmp) {
75519 + if (already_copied != NULL)
75520 + *already_copied = 1;
75521 + return(s_tmp);
75522 + }
75523 +
75524 + if ((s_tmp = (struct acl_subject_label *)
75525 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
75526 + return ERR_PTR(-ENOMEM);
75527 +
75528 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
75529 + if (subjmap == NULL)
75530 + return ERR_PTR(-ENOMEM);
75531 +
75532 + subjmap->user = userp;
75533 + subjmap->kernel = s_tmp;
75534 + insert_subj_map_entry(subjmap);
75535 +
75536 + if (copy_acl_subject_label(s_tmp, userp))
75537 + return ERR_PTR(-EFAULT);
75538 +
75539 + err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
75540 + if (err)
75541 + return ERR_PTR(err);
75542 +
75543 + if (!strcmp(s_tmp->filename, "/"))
75544 + role->root_label = s_tmp;
75545 +
75546 + if (copy_gr_hash_struct(&ghash, s_tmp->hash))
75547 + return ERR_PTR(-EFAULT);
75548 +
75549 + /* copy user and group transition tables */
75550 +
75551 + if (s_tmp->user_trans_num) {
75552 + uid_t *uidlist;
75553 +
75554 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
75555 + if (uidlist == NULL)
75556 + return ERR_PTR(-ENOMEM);
75557 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
75558 + return ERR_PTR(-EFAULT);
75559 +
75560 + s_tmp->user_transitions = uidlist;
75561 + }
75562 +
75563 + if (s_tmp->group_trans_num) {
75564 + gid_t *gidlist;
75565 +
75566 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
75567 + if (gidlist == NULL)
75568 + return ERR_PTR(-ENOMEM);
75569 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
75570 + return ERR_PTR(-EFAULT);
75571 +
75572 + s_tmp->group_transitions = gidlist;
75573 + }
75574 +
75575 + /* set up object hash table */
75576 + num_objs = count_user_objs(ghash.first);
75577 +
75578 + s_tmp->obj_hash_size = num_objs;
75579 + s_tmp->obj_hash =
75580 + (struct acl_object_label **)
75581 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
75582 +
75583 + if (!s_tmp->obj_hash)
75584 + return ERR_PTR(-ENOMEM);
75585 +
75586 + memset(s_tmp->obj_hash, 0,
75587 + s_tmp->obj_hash_size *
75588 + sizeof (struct acl_object_label *));
75589 +
75590 + /* add in objects */
75591 + err = copy_user_objs(ghash.first, s_tmp, role);
75592 +
75593 + if (err)
75594 + return ERR_PTR(err);
75595 +
75596 + /* set pointer for parent subject */
75597 + if (s_tmp->parent_subject) {
75598 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
75599 +
75600 + if (IS_ERR(s_tmp2))
75601 + return s_tmp2;
75602 +
75603 + s_tmp->parent_subject = s_tmp2;
75604 + }
75605 +
75606 + /* add in ip acls */
75607 +
75608 + if (!s_tmp->ip_num) {
75609 + s_tmp->ips = NULL;
75610 + goto insert;
75611 + }
75612 +
75613 + i_tmp =
75614 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
75615 + sizeof (struct acl_ip_label *));
75616 +
75617 + if (!i_tmp)
75618 + return ERR_PTR(-ENOMEM);
75619 +
75620 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
75621 + *(i_tmp + i_num) =
75622 + (struct acl_ip_label *)
75623 + acl_alloc(sizeof (struct acl_ip_label));
75624 + if (!*(i_tmp + i_num))
75625 + return ERR_PTR(-ENOMEM);
75626 +
75627 + if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
75628 + return ERR_PTR(-EFAULT);
75629 +
75630 + if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
75631 + return ERR_PTR(-EFAULT);
75632 +
75633 + if ((*(i_tmp + i_num))->iface == NULL)
75634 + continue;
75635 +
75636 + err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
75637 + if (err)
75638 + return ERR_PTR(err);
75639 + }
75640 +
75641 + s_tmp->ips = i_tmp;
75642 +
75643 +insert:
75644 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
75645 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
75646 + return ERR_PTR(-ENOMEM);
75647 +
75648 + return s_tmp;
75649 +}
75650 +
75651 +static int
75652 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
75653 +{
75654 + struct acl_subject_label s_pre;
75655 + struct acl_subject_label * ret;
75656 + int err;
75657 +
75658 + while (userp) {
75659 + if (copy_acl_subject_label(&s_pre, userp))
75660 + return -EFAULT;
75661 +
75662 + ret = do_copy_user_subj(userp, role, NULL);
75663 +
75664 + err = PTR_ERR(ret);
75665 + if (IS_ERR(ret))
75666 + return err;
75667 +
75668 + insert_acl_subj_label(ret, role);
75669 +
75670 + userp = s_pre.prev;
75671 + }
75672 +
75673 + return 0;
75674 +}
75675 +
75676 +static int
75677 +copy_user_acl(struct gr_arg *arg)
75678 +{
75679 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
75680 + struct acl_subject_label *subj_list;
75681 + struct sprole_pw *sptmp;
75682 + struct gr_hash_struct *ghash;
75683 + uid_t *domainlist;
75684 + unsigned int r_num;
75685 + int err = 0;
75686 + __u16 i;
75687 + __u32 num_subjs;
75688 +
75689 + /* we need a default and kernel role */
75690 + if (arg->role_db.num_roles < 2)
75691 + return -EINVAL;
75692 +
75693 + /* copy special role authentication info from userspace */
75694 +
75695 + polstate->num_sprole_pws = arg->num_sprole_pws;
75696 + polstate->acl_special_roles = (struct sprole_pw **) acl_alloc_num(polstate->num_sprole_pws, sizeof(struct sprole_pw *));
75697 +
75698 + if (!polstate->acl_special_roles && polstate->num_sprole_pws)
75699 + return -ENOMEM;
75700 +
75701 + for (i = 0; i < polstate->num_sprole_pws; i++) {
75702 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
75703 + if (!sptmp)
75704 + return -ENOMEM;
75705 + if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
75706 + return -EFAULT;
75707 +
75708 + err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
75709 + if (err)
75710 + return err;
75711 +
75712 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
75713 + printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
75714 +#endif
75715 +
75716 + polstate->acl_special_roles[i] = sptmp;
75717 + }
75718 +
75719 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
75720 +
75721 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
75722 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
75723 +
75724 + if (!r_tmp)
75725 + return -ENOMEM;
75726 +
75727 + if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
75728 + return -EFAULT;
75729 +
75730 + if (copy_acl_role_label(r_tmp, r_utmp2))
75731 + return -EFAULT;
75732 +
75733 + err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
75734 + if (err)
75735 + return err;
75736 +
75737 + if (!strcmp(r_tmp->rolename, "default")
75738 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
75739 + polstate->default_role = r_tmp;
75740 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
75741 + polstate->kernel_role = r_tmp;
75742 + }
75743 +
75744 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
75745 + return -ENOMEM;
75746 +
75747 + if (copy_gr_hash_struct(ghash, r_tmp->hash))
75748 + return -EFAULT;
75749 +
75750 + r_tmp->hash = ghash;
75751 +
75752 + num_subjs = count_user_subjs(r_tmp->hash->first);
75753 +
75754 + r_tmp->subj_hash_size = num_subjs;
75755 + r_tmp->subj_hash =
75756 + (struct acl_subject_label **)
75757 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
75758 +
75759 + if (!r_tmp->subj_hash)
75760 + return -ENOMEM;
75761 +
75762 + err = copy_user_allowedips(r_tmp);
75763 + if (err)
75764 + return err;
75765 +
75766 + /* copy domain info */
75767 + if (r_tmp->domain_children != NULL) {
75768 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
75769 + if (domainlist == NULL)
75770 + return -ENOMEM;
75771 +
75772 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
75773 + return -EFAULT;
75774 +
75775 + r_tmp->domain_children = domainlist;
75776 + }
75777 +
75778 + err = copy_user_transitions(r_tmp);
75779 + if (err)
75780 + return err;
75781 +
75782 + memset(r_tmp->subj_hash, 0,
75783 + r_tmp->subj_hash_size *
75784 + sizeof (struct acl_subject_label *));
75785 +
75786 + /* acquire the list of subjects, then NULL out
75787 + the list prior to parsing the subjects for this role,
75788 + as during this parsing the list is replaced with a list
75789 + of *nested* subjects for the role
75790 + */
75791 + subj_list = r_tmp->hash->first;
75792 +
75793 + /* set nested subject list to null */
75794 + r_tmp->hash->first = NULL;
75795 +
75796 + err = copy_user_subjs(subj_list, r_tmp);
75797 +
75798 + if (err)
75799 + return err;
75800 +
75801 + insert_acl_role_label(r_tmp);
75802 + }
75803 +
75804 + if (polstate->default_role == NULL || polstate->kernel_role == NULL)
75805 + return -EINVAL;
75806 +
75807 + return err;
75808 +}
75809 +
75810 +static int gracl_reload_apply_policies(void *reload)
75811 +{
75812 + struct gr_reload_state *reload_state = (struct gr_reload_state *)reload;
75813 + struct task_struct *task, *task2;
75814 + struct acl_role_label *role, *rtmp;
75815 + struct acl_subject_label *subj;
75816 + const struct cred *cred;
75817 + int role_applied;
75818 + int ret = 0;
75819 +
75820 + memcpy(&reload_state->oldpolicy, reload_state->oldpolicy_ptr, sizeof(struct gr_policy_state));
75821 + memcpy(&reload_state->oldalloc, reload_state->oldalloc_ptr, sizeof(struct gr_alloc_state));
75822 +
75823 + /* first make sure we'll be able to apply the new policy cleanly */
75824 + do_each_thread(task2, task) {
75825 + if (task->exec_file == NULL)
75826 + continue;
75827 + role_applied = 0;
75828 + if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
75829 + /* preserve special roles */
75830 + FOR_EACH_ROLE_START(role)
75831 + if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
75832 + rtmp = task->role;
75833 + task->role = role;
75834 + role_applied = 1;
75835 + break;
75836 + }
75837 + FOR_EACH_ROLE_END(role)
75838 + }
75839 + if (!role_applied) {
75840 + cred = __task_cred(task);
75841 + rtmp = task->role;
75842 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
75843 + }
75844 + /* this handles non-nested inherited subjects, nested subjects will still
75845 + be dropped currently */
75846 + subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
75847 + task->tmpacl = __gr_get_subject_for_task(polstate, task, NULL);
75848 + /* change the role back so that we've made no modifications to the policy */
75849 + task->role = rtmp;
75850 +
75851 + if (subj == NULL || task->tmpacl == NULL) {
75852 + ret = -EINVAL;
75853 + goto out;
75854 + }
75855 + } while_each_thread(task2, task);
75856 +
75857 + /* now actually apply the policy */
75858 +
75859 + do_each_thread(task2, task) {
75860 + if (task->exec_file) {
75861 + role_applied = 0;
75862 + if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
75863 + /* preserve special roles */
75864 + FOR_EACH_ROLE_START(role)
75865 + if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
75866 + task->role = role;
75867 + role_applied = 1;
75868 + break;
75869 + }
75870 + FOR_EACH_ROLE_END(role)
75871 + }
75872 + if (!role_applied) {
75873 + cred = __task_cred(task);
75874 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
75875 + }
75876 + /* this handles non-nested inherited subjects, nested subjects will still
75877 + be dropped currently */
75878 + if (!reload_state->oldmode && task->inherited)
75879 + subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
75880 + else {
75881 + /* looked up and tagged to the task previously */
75882 + subj = task->tmpacl;
75883 + }
75884 + /* subj will be non-null */
75885 + __gr_apply_subject_to_task(polstate, task, subj);
75886 + if (reload_state->oldmode) {
75887 + task->acl_role_id = 0;
75888 + task->acl_sp_role = 0;
75889 + task->inherited = 0;
75890 + }
75891 + } else {
75892 + // it's a kernel process
75893 + task->role = polstate->kernel_role;
75894 + task->acl = polstate->kernel_role->root_label;
75895 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
75896 + task->acl->mode &= ~GR_PROCFIND;
75897 +#endif
75898 + }
75899 + } while_each_thread(task2, task);
75900 +
75901 + memcpy(reload_state->oldpolicy_ptr, &reload_state->newpolicy, sizeof(struct gr_policy_state));
75902 + memcpy(reload_state->oldalloc_ptr, &reload_state->newalloc, sizeof(struct gr_alloc_state));
75903 +
75904 +out:
75905 +
75906 + return ret;
75907 +}
75908 +
75909 +static int gracl_reload(struct gr_arg *args, unsigned char oldmode)
75910 +{
75911 + struct gr_reload_state new_reload_state = { };
75912 + int err;
75913 +
75914 + new_reload_state.oldpolicy_ptr = polstate;
75915 + new_reload_state.oldalloc_ptr = current_alloc_state;
75916 + new_reload_state.oldmode = oldmode;
75917 +
75918 + current_alloc_state = &new_reload_state.newalloc;
75919 + polstate = &new_reload_state.newpolicy;
75920 +
75921 + /* everything relevant is now saved off, copy in the new policy */
75922 + if (init_variables(args, true)) {
75923 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
75924 + err = -ENOMEM;
75925 + goto error;
75926 + }
75927 +
75928 + err = copy_user_acl(args);
75929 + free_init_variables();
75930 + if (err)
75931 + goto error;
75932 + /* the new policy is copied in, with the old policy available via saved_state
75933 + first go through applying roles, making sure to preserve special roles
75934 + then apply new subjects, making sure to preserve inherited and nested subjects,
75935 + though currently only inherited subjects will be preserved
75936 + */
75937 + err = stop_machine(gracl_reload_apply_policies, &new_reload_state, NULL);
75938 + if (err)
75939 + goto error;
75940 +
75941 + /* we've now applied the new policy, so restore the old policy state to free it */
75942 + polstate = &new_reload_state.oldpolicy;
75943 + current_alloc_state = &new_reload_state.oldalloc;
75944 + free_variables(true);
75945 +
75946 + /* oldpolicy/oldalloc_ptr point to the new policy/alloc states as they were copied
75947 + to running_polstate/current_alloc_state inside stop_machine
75948 + */
75949 + err = 0;
75950 + goto out;
75951 +error:
75952 + /* on error of loading the new policy, we'll just keep the previous
75953 + policy set around
75954 + */
75955 + free_variables(true);
75956 +
75957 + /* doesn't affect runtime, but maintains consistent state */
75958 +out:
75959 + polstate = new_reload_state.oldpolicy_ptr;
75960 + current_alloc_state = new_reload_state.oldalloc_ptr;
75961 +
75962 + return err;
75963 +}
75964 +
75965 +static int
75966 +gracl_init(struct gr_arg *args)
75967 +{
75968 + int error = 0;
75969 +
75970 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
75971 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
75972 +
75973 + if (init_variables(args, false)) {
75974 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
75975 + error = -ENOMEM;
75976 + goto out;
75977 + }
75978 +
75979 + error = copy_user_acl(args);
75980 + free_init_variables();
75981 + if (error)
75982 + goto out;
75983 +
75984 + error = gr_set_acls(0);
75985 + if (error)
75986 + goto out;
75987 +
75988 + gr_enable_rbac_system();
75989 +
75990 + return 0;
75991 +
75992 +out:
75993 + free_variables(false);
75994 + return error;
75995 +}
75996 +
75997 +static int
75998 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
75999 + unsigned char **sum)
76000 +{
76001 + struct acl_role_label *r;
76002 + struct role_allowed_ip *ipp;
76003 + struct role_transition *trans;
76004 + unsigned int i;
76005 + int found = 0;
76006 + u32 curr_ip = current->signal->curr_ip;
76007 +
76008 + current->signal->saved_ip = curr_ip;
76009 +
76010 + /* check transition table */
76011 +
76012 + for (trans = current->role->transitions; trans; trans = trans->next) {
76013 + if (!strcmp(rolename, trans->rolename)) {
76014 + found = 1;
76015 + break;
76016 + }
76017 + }
76018 +
76019 + if (!found)
76020 + return 0;
76021 +
76022 + /* handle special roles that do not require authentication
76023 + and check ip */
76024 +
76025 + FOR_EACH_ROLE_START(r)
76026 + if (!strcmp(rolename, r->rolename) &&
76027 + (r->roletype & GR_ROLE_SPECIAL)) {
76028 + found = 0;
76029 + if (r->allowed_ips != NULL) {
76030 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
76031 + if ((ntohl(curr_ip) & ipp->netmask) ==
76032 + (ntohl(ipp->addr) & ipp->netmask))
76033 + found = 1;
76034 + }
76035 + } else
76036 + found = 2;
76037 + if (!found)
76038 + return 0;
76039 +
76040 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
76041 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
76042 + *salt = NULL;
76043 + *sum = NULL;
76044 + return 1;
76045 + }
76046 + }
76047 + FOR_EACH_ROLE_END(r)
76048 +
76049 + for (i = 0; i < polstate->num_sprole_pws; i++) {
76050 + if (!strcmp(rolename, polstate->acl_special_roles[i]->rolename)) {
76051 + *salt = polstate->acl_special_roles[i]->salt;
76052 + *sum = polstate->acl_special_roles[i]->sum;
76053 + return 1;
76054 + }
76055 + }
76056 +
76057 + return 0;
76058 +}
76059 +
76060 +int gr_check_secure_terminal(struct task_struct *task)
76061 +{
76062 + struct task_struct *p, *p2, *p3;
76063 + struct files_struct *files;
76064 + struct fdtable *fdt;
76065 + struct file *our_file = NULL, *file;
76066 + int i;
76067 +
76068 + if (task->signal->tty == NULL)
76069 + return 1;
76070 +
76071 + files = get_files_struct(task);
76072 + if (files != NULL) {
76073 + rcu_read_lock();
76074 + fdt = files_fdtable(files);
76075 + for (i=0; i < fdt->max_fds; i++) {
76076 + file = fcheck_files(files, i);
76077 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
76078 + get_file(file);
76079 + our_file = file;
76080 + }
76081 + }
76082 + rcu_read_unlock();
76083 + put_files_struct(files);
76084 + }
76085 +
76086 + if (our_file == NULL)
76087 + return 1;
76088 +
76089 + read_lock(&tasklist_lock);
76090 + do_each_thread(p2, p) {
76091 + files = get_files_struct(p);
76092 + if (files == NULL ||
76093 + (p->signal && p->signal->tty == task->signal->tty)) {
76094 + if (files != NULL)
76095 + put_files_struct(files);
76096 + continue;
76097 + }
76098 + rcu_read_lock();
76099 + fdt = files_fdtable(files);
76100 + for (i=0; i < fdt->max_fds; i++) {
76101 + file = fcheck_files(files, i);
76102 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
76103 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
76104 + p3 = task;
76105 + while (task_pid_nr(p3) > 0) {
76106 + if (p3 == p)
76107 + break;
76108 + p3 = p3->real_parent;
76109 + }
76110 + if (p3 == p)
76111 + break;
76112 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
76113 + gr_handle_alertkill(p);
76114 + rcu_read_unlock();
76115 + put_files_struct(files);
76116 + read_unlock(&tasklist_lock);
76117 + fput(our_file);
76118 + return 0;
76119 + }
76120 + }
76121 + rcu_read_unlock();
76122 + put_files_struct(files);
76123 + } while_each_thread(p2, p);
76124 + read_unlock(&tasklist_lock);
76125 +
76126 + fput(our_file);
76127 + return 1;
76128 +}
76129 +
76130 +ssize_t
76131 +write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
76132 +{
76133 + struct gr_arg_wrapper uwrap;
76134 + unsigned char *sprole_salt = NULL;
76135 + unsigned char *sprole_sum = NULL;
76136 + int error = 0;
76137 + int error2 = 0;
76138 + size_t req_count = 0;
76139 + unsigned char oldmode = 0;
76140 +
76141 + mutex_lock(&gr_dev_mutex);
76142 +
76143 + if (gr_acl_is_enabled() && !(current->acl->mode & GR_KERNELAUTH)) {
76144 + error = -EPERM;
76145 + goto out;
76146 + }
76147 +
76148 +#ifdef CONFIG_COMPAT
76149 + pax_open_kernel();
76150 + if (is_compat_task()) {
76151 + copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
76152 + copy_gr_arg = &copy_gr_arg_compat;
76153 + copy_acl_object_label = &copy_acl_object_label_compat;
76154 + copy_acl_subject_label = &copy_acl_subject_label_compat;
76155 + copy_acl_role_label = &copy_acl_role_label_compat;
76156 + copy_acl_ip_label = &copy_acl_ip_label_compat;
76157 + copy_role_allowed_ip = &copy_role_allowed_ip_compat;
76158 + copy_role_transition = &copy_role_transition_compat;
76159 + copy_sprole_pw = &copy_sprole_pw_compat;
76160 + copy_gr_hash_struct = &copy_gr_hash_struct_compat;
76161 + copy_pointer_from_array = &copy_pointer_from_array_compat;
76162 + get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
76163 + } else {
76164 + copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
76165 + copy_gr_arg = &copy_gr_arg_normal;
76166 + copy_acl_object_label = &copy_acl_object_label_normal;
76167 + copy_acl_subject_label = &copy_acl_subject_label_normal;
76168 + copy_acl_role_label = &copy_acl_role_label_normal;
76169 + copy_acl_ip_label = &copy_acl_ip_label_normal;
76170 + copy_role_allowed_ip = &copy_role_allowed_ip_normal;
76171 + copy_role_transition = &copy_role_transition_normal;
76172 + copy_sprole_pw = &copy_sprole_pw_normal;
76173 + copy_gr_hash_struct = &copy_gr_hash_struct_normal;
76174 + copy_pointer_from_array = &copy_pointer_from_array_normal;
76175 + get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
76176 + }
76177 + pax_close_kernel();
76178 +#endif
76179 +
76180 + req_count = get_gr_arg_wrapper_size();
76181 +
76182 + if (count != req_count) {
76183 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
76184 + error = -EINVAL;
76185 + goto out;
76186 + }
76187 +
76188 +
76189 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
76190 + gr_auth_expires = 0;
76191 + gr_auth_attempts = 0;
76192 + }
76193 +
76194 + error = copy_gr_arg_wrapper(buf, &uwrap);
76195 + if (error)
76196 + goto out;
76197 +
76198 + error = copy_gr_arg(uwrap.arg, gr_usermode);
76199 + if (error)
76200 + goto out;
76201 +
76202 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
76203 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
76204 + time_after(gr_auth_expires, get_seconds())) {
76205 + error = -EBUSY;
76206 + goto out;
76207 + }
76208 +
76209 + /* if non-root trying to do anything other than use a special role,
76210 + do not attempt authentication, do not count towards authentication
76211 + locking
76212 + */
76213 +
76214 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
76215 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
76216 + gr_is_global_nonroot(current_uid())) {
76217 + error = -EPERM;
76218 + goto out;
76219 + }
76220 +
76221 + /* ensure pw and special role name are null terminated */
76222 +
76223 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
76224 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
76225 +
76226 + /* Okay.
76227 + * We have our enough of the argument structure..(we have yet
76228 + * to copy_from_user the tables themselves) . Copy the tables
76229 + * only if we need them, i.e. for loading operations. */
76230 +
76231 + switch (gr_usermode->mode) {
76232 + case GR_STATUS:
76233 + if (gr_acl_is_enabled()) {
76234 + error = 1;
76235 + if (!gr_check_secure_terminal(current))
76236 + error = 3;
76237 + } else
76238 + error = 2;
76239 + goto out;
76240 + case GR_SHUTDOWN:
76241 + if (gr_acl_is_enabled() && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
76242 + stop_machine(gr_rbac_disable, NULL, NULL);
76243 + free_variables(false);
76244 + memset(gr_usermode, 0, sizeof(struct gr_arg));
76245 + memset(gr_system_salt, 0, GR_SALT_LEN);
76246 + memset(gr_system_sum, 0, GR_SHA_LEN);
76247 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
76248 + } else if (gr_acl_is_enabled()) {
76249 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
76250 + error = -EPERM;
76251 + } else {
76252 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
76253 + error = -EAGAIN;
76254 + }
76255 + break;
76256 + case GR_ENABLE:
76257 + if (!gr_acl_is_enabled() && !(error2 = gracl_init(gr_usermode)))
76258 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
76259 + else {
76260 + if (gr_acl_is_enabled())
76261 + error = -EAGAIN;
76262 + else
76263 + error = error2;
76264 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
76265 + }
76266 + break;
76267 + case GR_OLDRELOAD:
76268 + oldmode = 1;
76269 + case GR_RELOAD:
76270 + if (!gr_acl_is_enabled()) {
76271 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
76272 + error = -EAGAIN;
76273 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
76274 + error2 = gracl_reload(gr_usermode, oldmode);
76275 + if (!error2)
76276 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
76277 + else {
76278 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
76279 + error = error2;
76280 + }
76281 + } else {
76282 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
76283 + error = -EPERM;
76284 + }
76285 + break;
76286 + case GR_SEGVMOD:
76287 + if (unlikely(!gr_acl_is_enabled())) {
76288 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
76289 + error = -EAGAIN;
76290 + break;
76291 + }
76292 +
76293 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
76294 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
76295 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
76296 + struct acl_subject_label *segvacl;
76297 + segvacl =
76298 + lookup_acl_subj_label(gr_usermode->segv_inode,
76299 + gr_usermode->segv_device,
76300 + current->role);
76301 + if (segvacl) {
76302 + segvacl->crashes = 0;
76303 + segvacl->expires = 0;
76304 + }
76305 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
76306 + gr_remove_uid(gr_usermode->segv_uid);
76307 + }
76308 + } else {
76309 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
76310 + error = -EPERM;
76311 + }
76312 + break;
76313 + case GR_SPROLE:
76314 + case GR_SPROLEPAM:
76315 + if (unlikely(!gr_acl_is_enabled())) {
76316 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
76317 + error = -EAGAIN;
76318 + break;
76319 + }
76320 +
76321 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
76322 + current->role->expires = 0;
76323 + current->role->auth_attempts = 0;
76324 + }
76325 +
76326 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
76327 + time_after(current->role->expires, get_seconds())) {
76328 + error = -EBUSY;
76329 + goto out;
76330 + }
76331 +
76332 + if (lookup_special_role_auth
76333 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
76334 + && ((!sprole_salt && !sprole_sum)
76335 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
76336 + char *p = "";
76337 + assign_special_role(gr_usermode->sp_role);
76338 + read_lock(&tasklist_lock);
76339 + if (current->real_parent)
76340 + p = current->real_parent->role->rolename;
76341 + read_unlock(&tasklist_lock);
76342 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
76343 + p, acl_sp_role_value);
76344 + } else {
76345 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
76346 + error = -EPERM;
76347 + if(!(current->role->auth_attempts++))
76348 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
76349 +
76350 + goto out;
76351 + }
76352 + break;
76353 + case GR_UNSPROLE:
76354 + if (unlikely(!gr_acl_is_enabled())) {
76355 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
76356 + error = -EAGAIN;
76357 + break;
76358 + }
76359 +
76360 + if (current->role->roletype & GR_ROLE_SPECIAL) {
76361 + char *p = "";
76362 + int i = 0;
76363 +
76364 + read_lock(&tasklist_lock);
76365 + if (current->real_parent) {
76366 + p = current->real_parent->role->rolename;
76367 + i = current->real_parent->acl_role_id;
76368 + }
76369 + read_unlock(&tasklist_lock);
76370 +
76371 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
76372 + gr_set_acls(1);
76373 + } else {
76374 + error = -EPERM;
76375 + goto out;
76376 + }
76377 + break;
76378 + default:
76379 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
76380 + error = -EINVAL;
76381 + break;
76382 + }
76383 +
76384 + if (error != -EPERM)
76385 + goto out;
76386 +
76387 + if(!(gr_auth_attempts++))
76388 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
76389 +
76390 + out:
76391 + mutex_unlock(&gr_dev_mutex);
76392 +
76393 + if (!error)
76394 + error = req_count;
76395 +
76396 + return error;
76397 +}
76398 +
76399 +int
76400 +gr_set_acls(const int type)
76401 +{
76402 + struct task_struct *task, *task2;
76403 + struct acl_role_label *role = current->role;
76404 + struct acl_subject_label *subj;
76405 + __u16 acl_role_id = current->acl_role_id;
76406 + const struct cred *cred;
76407 + int ret;
76408 +
76409 + rcu_read_lock();
76410 + read_lock(&tasklist_lock);
76411 + read_lock(&grsec_exec_file_lock);
76412 + do_each_thread(task2, task) {
76413 + /* check to see if we're called from the exit handler,
76414 + if so, only replace ACLs that have inherited the admin
76415 + ACL */
76416 +
76417 + if (type && (task->role != role ||
76418 + task->acl_role_id != acl_role_id))
76419 + continue;
76420 +
76421 + task->acl_role_id = 0;
76422 + task->acl_sp_role = 0;
76423 + task->inherited = 0;
76424 +
76425 + if (task->exec_file) {
76426 + cred = __task_cred(task);
76427 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
76428 + subj = __gr_get_subject_for_task(polstate, task, NULL);
76429 + if (subj == NULL) {
76430 + ret = -EINVAL;
76431 + read_unlock(&grsec_exec_file_lock);
76432 + read_unlock(&tasklist_lock);
76433 + rcu_read_unlock();
76434 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
76435 + return ret;
76436 + }
76437 + __gr_apply_subject_to_task(polstate, task, subj);
76438 + } else {
76439 + // it's a kernel process
76440 + task->role = polstate->kernel_role;
76441 + task->acl = polstate->kernel_role->root_label;
76442 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
76443 + task->acl->mode &= ~GR_PROCFIND;
76444 +#endif
76445 + }
76446 + } while_each_thread(task2, task);
76447 + read_unlock(&grsec_exec_file_lock);
76448 + read_unlock(&tasklist_lock);
76449 + rcu_read_unlock();
76450 +
76451 + return 0;
76452 +}
76453 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
76454 new file mode 100644
76455 index 0000000..39645c9
76456 --- /dev/null
76457 +++ b/grsecurity/gracl_res.c
76458 @@ -0,0 +1,68 @@
76459 +#include <linux/kernel.h>
76460 +#include <linux/sched.h>
76461 +#include <linux/gracl.h>
76462 +#include <linux/grinternal.h>
76463 +
76464 +static const char *restab_log[] = {
76465 + [RLIMIT_CPU] = "RLIMIT_CPU",
76466 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
76467 + [RLIMIT_DATA] = "RLIMIT_DATA",
76468 + [RLIMIT_STACK] = "RLIMIT_STACK",
76469 + [RLIMIT_CORE] = "RLIMIT_CORE",
76470 + [RLIMIT_RSS] = "RLIMIT_RSS",
76471 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
76472 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
76473 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
76474 + [RLIMIT_AS] = "RLIMIT_AS",
76475 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
76476 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
76477 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
76478 + [RLIMIT_NICE] = "RLIMIT_NICE",
76479 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
76480 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
76481 + [GR_CRASH_RES] = "RLIMIT_CRASH"
76482 +};
76483 +
76484 +void
76485 +gr_log_resource(const struct task_struct *task,
76486 + const int res, const unsigned long wanted, const int gt)
76487 +{
76488 + const struct cred *cred;
76489 + unsigned long rlim;
76490 +
76491 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
76492 + return;
76493 +
76494 + // not yet supported resource
76495 + if (unlikely(!restab_log[res]))
76496 + return;
76497 +
76498 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
76499 + rlim = task_rlimit_max(task, res);
76500 + else
76501 + rlim = task_rlimit(task, res);
76502 +
76503 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
76504 + return;
76505 +
76506 + rcu_read_lock();
76507 + cred = __task_cred(task);
76508 +
76509 + if (res == RLIMIT_NPROC &&
76510 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
76511 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
76512 + goto out_rcu_unlock;
76513 + else if (res == RLIMIT_MEMLOCK &&
76514 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
76515 + goto out_rcu_unlock;
76516 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
76517 + goto out_rcu_unlock;
76518 + rcu_read_unlock();
76519 +
76520 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
76521 +
76522 + return;
76523 +out_rcu_unlock:
76524 + rcu_read_unlock();
76525 + return;
76526 +}
76527 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
76528 new file mode 100644
76529 index 0000000..2040e61
76530 --- /dev/null
76531 +++ b/grsecurity/gracl_segv.c
76532 @@ -0,0 +1,313 @@
76533 +#include <linux/kernel.h>
76534 +#include <linux/mm.h>
76535 +#include <asm/uaccess.h>
76536 +#include <asm/errno.h>
76537 +#include <asm/mman.h>
76538 +#include <net/sock.h>
76539 +#include <linux/file.h>
76540 +#include <linux/fs.h>
76541 +#include <linux/net.h>
76542 +#include <linux/in.h>
76543 +#include <linux/slab.h>
76544 +#include <linux/types.h>
76545 +#include <linux/sched.h>
76546 +#include <linux/timer.h>
76547 +#include <linux/gracl.h>
76548 +#include <linux/grsecurity.h>
76549 +#include <linux/grinternal.h>
76550 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
76551 +#include <linux/magic.h>
76552 +#include <linux/pagemap.h>
76553 +#include "../fs/btrfs/async-thread.h"
76554 +#include "../fs/btrfs/ctree.h"
76555 +#include "../fs/btrfs/btrfs_inode.h"
76556 +#endif
76557 +
76558 +static struct crash_uid *uid_set;
76559 +static unsigned short uid_used;
76560 +static DEFINE_SPINLOCK(gr_uid_lock);
76561 +extern rwlock_t gr_inode_lock;
76562 +extern struct acl_subject_label *
76563 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
76564 + struct acl_role_label *role);
76565 +
76566 +static inline dev_t __get_dev(const struct dentry *dentry)
76567 +{
76568 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
76569 + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
76570 + return BTRFS_I(dentry->d_inode)->root->anon_dev;
76571 + else
76572 +#endif
76573 + return dentry->d_sb->s_dev;
76574 +}
76575 +
76576 +int
76577 +gr_init_uidset(void)
76578 +{
76579 + uid_set =
76580 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
76581 + uid_used = 0;
76582 +
76583 + return uid_set ? 1 : 0;
76584 +}
76585 +
76586 +void
76587 +gr_free_uidset(void)
76588 +{
76589 + if (uid_set) {
76590 + struct crash_uid *tmpset;
76591 + spin_lock(&gr_uid_lock);
76592 + tmpset = uid_set;
76593 + uid_set = NULL;
76594 + uid_used = 0;
76595 + spin_unlock(&gr_uid_lock);
76596 + if (tmpset)
76597 + kfree(tmpset);
76598 + }
76599 +
76600 + return;
76601 +}
76602 +
76603 +int
76604 +gr_find_uid(const uid_t uid)
76605 +{
76606 + struct crash_uid *tmp = uid_set;
76607 + uid_t buid;
76608 + int low = 0, high = uid_used - 1, mid;
76609 +
76610 + while (high >= low) {
76611 + mid = (low + high) >> 1;
76612 + buid = tmp[mid].uid;
76613 + if (buid == uid)
76614 + return mid;
76615 + if (buid > uid)
76616 + high = mid - 1;
76617 + if (buid < uid)
76618 + low = mid + 1;
76619 + }
76620 +
76621 + return -1;
76622 +}
76623 +
76624 +static __inline__ void
76625 +gr_insertsort(void)
76626 +{
76627 + unsigned short i, j;
76628 + struct crash_uid index;
76629 +
76630 + for (i = 1; i < uid_used; i++) {
76631 + index = uid_set[i];
76632 + j = i;
76633 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
76634 + uid_set[j] = uid_set[j - 1];
76635 + j--;
76636 + }
76637 + uid_set[j] = index;
76638 + }
76639 +
76640 + return;
76641 +}
76642 +
76643 +static __inline__ void
76644 +gr_insert_uid(const kuid_t kuid, const unsigned long expires)
76645 +{
76646 + int loc;
76647 + uid_t uid = GR_GLOBAL_UID(kuid);
76648 +
76649 + if (uid_used == GR_UIDTABLE_MAX)
76650 + return;
76651 +
76652 + loc = gr_find_uid(uid);
76653 +
76654 + if (loc >= 0) {
76655 + uid_set[loc].expires = expires;
76656 + return;
76657 + }
76658 +
76659 + uid_set[uid_used].uid = uid;
76660 + uid_set[uid_used].expires = expires;
76661 + uid_used++;
76662 +
76663 + gr_insertsort();
76664 +
76665 + return;
76666 +}
76667 +
76668 +void
76669 +gr_remove_uid(const unsigned short loc)
76670 +{
76671 + unsigned short i;
76672 +
76673 + for (i = loc + 1; i < uid_used; i++)
76674 + uid_set[i - 1] = uid_set[i];
76675 +
76676 + uid_used--;
76677 +
76678 + return;
76679 +}
76680 +
76681 +int
76682 +gr_check_crash_uid(const kuid_t kuid)
76683 +{
76684 + int loc;
76685 + int ret = 0;
76686 + uid_t uid;
76687 +
76688 + if (unlikely(!gr_acl_is_enabled()))
76689 + return 0;
76690 +
76691 + uid = GR_GLOBAL_UID(kuid);
76692 +
76693 + spin_lock(&gr_uid_lock);
76694 + loc = gr_find_uid(uid);
76695 +
76696 + if (loc < 0)
76697 + goto out_unlock;
76698 +
76699 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
76700 + gr_remove_uid(loc);
76701 + else
76702 + ret = 1;
76703 +
76704 +out_unlock:
76705 + spin_unlock(&gr_uid_lock);
76706 + return ret;
76707 +}
76708 +
76709 +static __inline__ int
76710 +proc_is_setxid(const struct cred *cred)
76711 +{
76712 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
76713 + !uid_eq(cred->uid, cred->fsuid))
76714 + return 1;
76715 + if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
76716 + !gid_eq(cred->gid, cred->fsgid))
76717 + return 1;
76718 +
76719 + return 0;
76720 +}
76721 +
76722 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
76723 +
76724 +void
76725 +gr_handle_crash(struct task_struct *task, const int sig)
76726 +{
76727 + struct acl_subject_label *curr;
76728 + struct task_struct *tsk, *tsk2;
76729 + const struct cred *cred;
76730 + const struct cred *cred2;
76731 +
76732 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
76733 + return;
76734 +
76735 + if (unlikely(!gr_acl_is_enabled()))
76736 + return;
76737 +
76738 + curr = task->acl;
76739 +
76740 + if (!(curr->resmask & (1U << GR_CRASH_RES)))
76741 + return;
76742 +
76743 + if (time_before_eq(curr->expires, get_seconds())) {
76744 + curr->expires = 0;
76745 + curr->crashes = 0;
76746 + }
76747 +
76748 + curr->crashes++;
76749 +
76750 + if (!curr->expires)
76751 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
76752 +
76753 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
76754 + time_after(curr->expires, get_seconds())) {
76755 + rcu_read_lock();
76756 + cred = __task_cred(task);
76757 + if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
76758 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
76759 + spin_lock(&gr_uid_lock);
76760 + gr_insert_uid(cred->uid, curr->expires);
76761 + spin_unlock(&gr_uid_lock);
76762 + curr->expires = 0;
76763 + curr->crashes = 0;
76764 + read_lock(&tasklist_lock);
76765 + do_each_thread(tsk2, tsk) {
76766 + cred2 = __task_cred(tsk);
76767 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
76768 + gr_fake_force_sig(SIGKILL, tsk);
76769 + } while_each_thread(tsk2, tsk);
76770 + read_unlock(&tasklist_lock);
76771 + } else {
76772 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
76773 + read_lock(&tasklist_lock);
76774 + read_lock(&grsec_exec_file_lock);
76775 + do_each_thread(tsk2, tsk) {
76776 + if (likely(tsk != task)) {
76777 + // if this thread has the same subject as the one that triggered
76778 + // RES_CRASH and it's the same binary, kill it
76779 + if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
76780 + gr_fake_force_sig(SIGKILL, tsk);
76781 + }
76782 + } while_each_thread(tsk2, tsk);
76783 + read_unlock(&grsec_exec_file_lock);
76784 + read_unlock(&tasklist_lock);
76785 + }
76786 + rcu_read_unlock();
76787 + }
76788 +
76789 + return;
76790 +}
76791 +
76792 +int
76793 +gr_check_crash_exec(const struct file *filp)
76794 +{
76795 + struct acl_subject_label *curr;
76796 +
76797 + if (unlikely(!gr_acl_is_enabled()))
76798 + return 0;
76799 +
76800 + read_lock(&gr_inode_lock);
76801 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
76802 + __get_dev(filp->f_path.dentry),
76803 + current->role);
76804 + read_unlock(&gr_inode_lock);
76805 +
76806 + if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
76807 + (!curr->crashes && !curr->expires))
76808 + return 0;
76809 +
76810 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
76811 + time_after(curr->expires, get_seconds()))
76812 + return 1;
76813 + else if (time_before_eq(curr->expires, get_seconds())) {
76814 + curr->crashes = 0;
76815 + curr->expires = 0;
76816 + }
76817 +
76818 + return 0;
76819 +}
76820 +
76821 +void
76822 +gr_handle_alertkill(struct task_struct *task)
76823 +{
76824 + struct acl_subject_label *curracl;
76825 + __u32 curr_ip;
76826 + struct task_struct *p, *p2;
76827 +
76828 + if (unlikely(!gr_acl_is_enabled()))
76829 + return;
76830 +
76831 + curracl = task->acl;
76832 + curr_ip = task->signal->curr_ip;
76833 +
76834 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
76835 + read_lock(&tasklist_lock);
76836 + do_each_thread(p2, p) {
76837 + if (p->signal->curr_ip == curr_ip)
76838 + gr_fake_force_sig(SIGKILL, p);
76839 + } while_each_thread(p2, p);
76840 + read_unlock(&tasklist_lock);
76841 + } else if (curracl->mode & GR_KILLPROC)
76842 + gr_fake_force_sig(SIGKILL, task);
76843 +
76844 + return;
76845 +}
76846 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
76847 new file mode 100644
76848 index 0000000..98011b0
76849 --- /dev/null
76850 +++ b/grsecurity/gracl_shm.c
76851 @@ -0,0 +1,40 @@
76852 +#include <linux/kernel.h>
76853 +#include <linux/mm.h>
76854 +#include <linux/sched.h>
76855 +#include <linux/file.h>
76856 +#include <linux/ipc.h>
76857 +#include <linux/gracl.h>
76858 +#include <linux/grsecurity.h>
76859 +#include <linux/grinternal.h>
76860 +
76861 +int
76862 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
76863 + const time_t shm_createtime, const kuid_t cuid, const int shmid)
76864 +{
76865 + struct task_struct *task;
76866 +
76867 + if (!gr_acl_is_enabled())
76868 + return 1;
76869 +
76870 + rcu_read_lock();
76871 + read_lock(&tasklist_lock);
76872 +
76873 + task = find_task_by_vpid(shm_cprid);
76874 +
76875 + if (unlikely(!task))
76876 + task = find_task_by_vpid(shm_lapid);
76877 +
76878 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
76879 + (task_pid_nr(task) == shm_lapid)) &&
76880 + (task->acl->mode & GR_PROTSHM) &&
76881 + (task->acl != current->acl))) {
76882 + read_unlock(&tasklist_lock);
76883 + rcu_read_unlock();
76884 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
76885 + return 0;
76886 + }
76887 + read_unlock(&tasklist_lock);
76888 + rcu_read_unlock();
76889 +
76890 + return 1;
76891 +}
76892 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
76893 new file mode 100644
76894 index 0000000..bc0be01
76895 --- /dev/null
76896 +++ b/grsecurity/grsec_chdir.c
76897 @@ -0,0 +1,19 @@
76898 +#include <linux/kernel.h>
76899 +#include <linux/sched.h>
76900 +#include <linux/fs.h>
76901 +#include <linux/file.h>
76902 +#include <linux/grsecurity.h>
76903 +#include <linux/grinternal.h>
76904 +
76905 +void
76906 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
76907 +{
76908 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
76909 + if ((grsec_enable_chdir && grsec_enable_group &&
76910 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
76911 + !grsec_enable_group)) {
76912 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
76913 + }
76914 +#endif
76915 + return;
76916 +}
76917 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
76918 new file mode 100644
76919 index 0000000..baa635c
76920 --- /dev/null
76921 +++ b/grsecurity/grsec_chroot.c
76922 @@ -0,0 +1,387 @@
76923 +#include <linux/kernel.h>
76924 +#include <linux/module.h>
76925 +#include <linux/sched.h>
76926 +#include <linux/file.h>
76927 +#include <linux/fs.h>
76928 +#include <linux/mount.h>
76929 +#include <linux/types.h>
76930 +#include "../fs/mount.h"
76931 +#include <linux/grsecurity.h>
76932 +#include <linux/grinternal.h>
76933 +
76934 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
76935 +int gr_init_ran;
76936 +#endif
76937 +
76938 +void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
76939 +{
76940 +#ifdef CONFIG_GRKERNSEC
76941 + if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
76942 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
76943 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
76944 + && gr_init_ran
76945 +#endif
76946 + )
76947 + task->gr_is_chrooted = 1;
76948 + else {
76949 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
76950 + if (task_pid_nr(task) == 1 && !gr_init_ran)
76951 + gr_init_ran = 1;
76952 +#endif
76953 + task->gr_is_chrooted = 0;
76954 + }
76955 +
76956 + task->gr_chroot_dentry = path->dentry;
76957 +#endif
76958 + return;
76959 +}
76960 +
76961 +void gr_clear_chroot_entries(struct task_struct *task)
76962 +{
76963 +#ifdef CONFIG_GRKERNSEC
76964 + task->gr_is_chrooted = 0;
76965 + task->gr_chroot_dentry = NULL;
76966 +#endif
76967 + return;
76968 +}
76969 +
76970 +int
76971 +gr_handle_chroot_unix(const pid_t pid)
76972 +{
76973 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
76974 + struct task_struct *p;
76975 +
76976 + if (unlikely(!grsec_enable_chroot_unix))
76977 + return 1;
76978 +
76979 + if (likely(!proc_is_chrooted(current)))
76980 + return 1;
76981 +
76982 + rcu_read_lock();
76983 + read_lock(&tasklist_lock);
76984 + p = find_task_by_vpid_unrestricted(pid);
76985 + if (unlikely(p && !have_same_root(current, p))) {
76986 + read_unlock(&tasklist_lock);
76987 + rcu_read_unlock();
76988 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
76989 + return 0;
76990 + }
76991 + read_unlock(&tasklist_lock);
76992 + rcu_read_unlock();
76993 +#endif
76994 + return 1;
76995 +}
76996 +
76997 +int
76998 +gr_handle_chroot_nice(void)
76999 +{
77000 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
77001 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
77002 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
77003 + return -EPERM;
77004 + }
77005 +#endif
77006 + return 0;
77007 +}
77008 +
77009 +int
77010 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
77011 +{
77012 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
77013 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
77014 + && proc_is_chrooted(current)) {
77015 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
77016 + return -EACCES;
77017 + }
77018 +#endif
77019 + return 0;
77020 +}
77021 +
77022 +int
77023 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
77024 +{
77025 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
77026 + struct task_struct *p;
77027 + int ret = 0;
77028 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
77029 + return ret;
77030 +
77031 + read_lock(&tasklist_lock);
77032 + do_each_pid_task(pid, type, p) {
77033 + if (!have_same_root(current, p)) {
77034 + ret = 1;
77035 + goto out;
77036 + }
77037 + } while_each_pid_task(pid, type, p);
77038 +out:
77039 + read_unlock(&tasklist_lock);
77040 + return ret;
77041 +#endif
77042 + return 0;
77043 +}
77044 +
77045 +int
77046 +gr_pid_is_chrooted(struct task_struct *p)
77047 +{
77048 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
77049 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
77050 + return 0;
77051 +
77052 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
77053 + !have_same_root(current, p)) {
77054 + return 1;
77055 + }
77056 +#endif
77057 + return 0;
77058 +}
77059 +
77060 +EXPORT_SYMBOL_GPL(gr_pid_is_chrooted);
77061 +
77062 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
77063 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
77064 +{
77065 + struct path path, currentroot;
77066 + int ret = 0;
77067 +
77068 + path.dentry = (struct dentry *)u_dentry;
77069 + path.mnt = (struct vfsmount *)u_mnt;
77070 + get_fs_root(current->fs, &currentroot);
77071 + if (path_is_under(&path, &currentroot))
77072 + ret = 1;
77073 + path_put(&currentroot);
77074 +
77075 + return ret;
77076 +}
77077 +#endif
77078 +
77079 +int
77080 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
77081 +{
77082 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
77083 + if (!grsec_enable_chroot_fchdir)
77084 + return 1;
77085 +
77086 + if (!proc_is_chrooted(current))
77087 + return 1;
77088 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
77089 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
77090 + return 0;
77091 + }
77092 +#endif
77093 + return 1;
77094 +}
77095 +
77096 +int
77097 +gr_chroot_fhandle(void)
77098 +{
77099 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
77100 + if (!grsec_enable_chroot_fchdir)
77101 + return 1;
77102 +
77103 + if (!proc_is_chrooted(current))
77104 + return 1;
77105 + else {
77106 + gr_log_noargs(GR_DONT_AUDIT, GR_CHROOT_FHANDLE_MSG);
77107 + return 0;
77108 + }
77109 +#endif
77110 + return 1;
77111 +}
77112 +
77113 +int
77114 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
77115 + const time_t shm_createtime)
77116 +{
77117 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
77118 + struct task_struct *p;
77119 + time_t starttime;
77120 +
77121 + if (unlikely(!grsec_enable_chroot_shmat))
77122 + return 1;
77123 +
77124 + if (likely(!proc_is_chrooted(current)))
77125 + return 1;
77126 +
77127 + rcu_read_lock();
77128 + read_lock(&tasklist_lock);
77129 +
77130 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
77131 + starttime = p->start_time.tv_sec;
77132 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
77133 + if (have_same_root(current, p)) {
77134 + goto allow;
77135 + } else {
77136 + read_unlock(&tasklist_lock);
77137 + rcu_read_unlock();
77138 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
77139 + return 0;
77140 + }
77141 + }
77142 + /* creator exited, pid reuse, fall through to next check */
77143 + }
77144 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
77145 + if (unlikely(!have_same_root(current, p))) {
77146 + read_unlock(&tasklist_lock);
77147 + rcu_read_unlock();
77148 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
77149 + return 0;
77150 + }
77151 + }
77152 +
77153 +allow:
77154 + read_unlock(&tasklist_lock);
77155 + rcu_read_unlock();
77156 +#endif
77157 + return 1;
77158 +}
77159 +
77160 +void
77161 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
77162 +{
77163 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
77164 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
77165 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
77166 +#endif
77167 + return;
77168 +}
77169 +
77170 +int
77171 +gr_handle_chroot_mknod(const struct dentry *dentry,
77172 + const struct vfsmount *mnt, const int mode)
77173 +{
77174 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
77175 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
77176 + proc_is_chrooted(current)) {
77177 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
77178 + return -EPERM;
77179 + }
77180 +#endif
77181 + return 0;
77182 +}
77183 +
77184 +int
77185 +gr_handle_chroot_mount(const struct dentry *dentry,
77186 + const struct vfsmount *mnt, const char *dev_name)
77187 +{
77188 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
77189 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
77190 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
77191 + return -EPERM;
77192 + }
77193 +#endif
77194 + return 0;
77195 +}
77196 +
77197 +int
77198 +gr_handle_chroot_pivot(void)
77199 +{
77200 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
77201 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
77202 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
77203 + return -EPERM;
77204 + }
77205 +#endif
77206 + return 0;
77207 +}
77208 +
77209 +int
77210 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
77211 +{
77212 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
77213 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
77214 + !gr_is_outside_chroot(dentry, mnt)) {
77215 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
77216 + return -EPERM;
77217 + }
77218 +#endif
77219 + return 0;
77220 +}
77221 +
77222 +extern const char *captab_log[];
77223 +extern int captab_log_entries;
77224 +
77225 +int
77226 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
77227 +{
77228 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
77229 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
77230 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
77231 + if (cap_raised(chroot_caps, cap)) {
77232 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
77233 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
77234 + }
77235 + return 0;
77236 + }
77237 + }
77238 +#endif
77239 + return 1;
77240 +}
77241 +
77242 +int
77243 +gr_chroot_is_capable(const int cap)
77244 +{
77245 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
77246 + return gr_task_chroot_is_capable(current, current_cred(), cap);
77247 +#endif
77248 + return 1;
77249 +}
77250 +
77251 +int
77252 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
77253 +{
77254 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
77255 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
77256 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
77257 + if (cap_raised(chroot_caps, cap)) {
77258 + return 0;
77259 + }
77260 + }
77261 +#endif
77262 + return 1;
77263 +}
77264 +
77265 +int
77266 +gr_chroot_is_capable_nolog(const int cap)
77267 +{
77268 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
77269 + return gr_task_chroot_is_capable_nolog(current, cap);
77270 +#endif
77271 + return 1;
77272 +}
77273 +
77274 +int
77275 +gr_handle_chroot_sysctl(const int op)
77276 +{
77277 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
77278 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
77279 + proc_is_chrooted(current))
77280 + return -EACCES;
77281 +#endif
77282 + return 0;
77283 +}
77284 +
77285 +void
77286 +gr_handle_chroot_chdir(const struct path *path)
77287 +{
77288 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
77289 + if (grsec_enable_chroot_chdir)
77290 + set_fs_pwd(current->fs, path);
77291 +#endif
77292 + return;
77293 +}
77294 +
77295 +int
77296 +gr_handle_chroot_chmod(const struct dentry *dentry,
77297 + const struct vfsmount *mnt, const int mode)
77298 +{
77299 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
77300 + /* allow chmod +s on directories, but not files */
77301 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
77302 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
77303 + proc_is_chrooted(current)) {
77304 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
77305 + return -EPERM;
77306 + }
77307 +#endif
77308 + return 0;
77309 +}
77310 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
77311 new file mode 100644
77312 index 0000000..2d3bcb7
77313 --- /dev/null
77314 +++ b/grsecurity/grsec_disabled.c
77315 @@ -0,0 +1,440 @@
77316 +#include <linux/kernel.h>
77317 +#include <linux/module.h>
77318 +#include <linux/sched.h>
77319 +#include <linux/file.h>
77320 +#include <linux/fs.h>
77321 +#include <linux/kdev_t.h>
77322 +#include <linux/net.h>
77323 +#include <linux/in.h>
77324 +#include <linux/ip.h>
77325 +#include <linux/skbuff.h>
77326 +#include <linux/sysctl.h>
77327 +
77328 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
77329 +void
77330 +pax_set_initial_flags(struct linux_binprm *bprm)
77331 +{
77332 + return;
77333 +}
77334 +#endif
77335 +
77336 +#ifdef CONFIG_SYSCTL
77337 +__u32
77338 +gr_handle_sysctl(const struct ctl_table * table, const int op)
77339 +{
77340 + return 0;
77341 +}
77342 +#endif
77343 +
77344 +#ifdef CONFIG_TASKSTATS
77345 +int gr_is_taskstats_denied(int pid)
77346 +{
77347 + return 0;
77348 +}
77349 +#endif
77350 +
77351 +int
77352 +gr_acl_is_enabled(void)
77353 +{
77354 + return 0;
77355 +}
77356 +
77357 +int
77358 +gr_learn_cap(const struct task_struct *task, const struct cred *cred, const int cap)
77359 +{
77360 + return 0;
77361 +}
77362 +
77363 +void
77364 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
77365 +{
77366 + return;
77367 +}
77368 +
77369 +int
77370 +gr_handle_rawio(const struct inode *inode)
77371 +{
77372 + return 0;
77373 +}
77374 +
77375 +void
77376 +gr_acl_handle_psacct(struct task_struct *task, const long code)
77377 +{
77378 + return;
77379 +}
77380 +
77381 +int
77382 +gr_handle_ptrace(struct task_struct *task, const long request)
77383 +{
77384 + return 0;
77385 +}
77386 +
77387 +int
77388 +gr_handle_proc_ptrace(struct task_struct *task)
77389 +{
77390 + return 0;
77391 +}
77392 +
77393 +int
77394 +gr_set_acls(const int type)
77395 +{
77396 + return 0;
77397 +}
77398 +
77399 +int
77400 +gr_check_hidden_task(const struct task_struct *tsk)
77401 +{
77402 + return 0;
77403 +}
77404 +
77405 +int
77406 +gr_check_protected_task(const struct task_struct *task)
77407 +{
77408 + return 0;
77409 +}
77410 +
77411 +int
77412 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
77413 +{
77414 + return 0;
77415 +}
77416 +
77417 +void
77418 +gr_copy_label(struct task_struct *tsk)
77419 +{
77420 + return;
77421 +}
77422 +
77423 +void
77424 +gr_set_pax_flags(struct task_struct *task)
77425 +{
77426 + return;
77427 +}
77428 +
77429 +int
77430 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
77431 + const int unsafe_share)
77432 +{
77433 + return 0;
77434 +}
77435 +
77436 +void
77437 +gr_handle_delete(const ino_t ino, const dev_t dev)
77438 +{
77439 + return;
77440 +}
77441 +
77442 +void
77443 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
77444 +{
77445 + return;
77446 +}
77447 +
77448 +void
77449 +gr_handle_crash(struct task_struct *task, const int sig)
77450 +{
77451 + return;
77452 +}
77453 +
77454 +int
77455 +gr_check_crash_exec(const struct file *filp)
77456 +{
77457 + return 0;
77458 +}
77459 +
77460 +int
77461 +gr_check_crash_uid(const kuid_t uid)
77462 +{
77463 + return 0;
77464 +}
77465 +
77466 +void
77467 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
77468 + struct dentry *old_dentry,
77469 + struct dentry *new_dentry,
77470 + struct vfsmount *mnt, const __u8 replace, unsigned int flags)
77471 +{
77472 + return;
77473 +}
77474 +
77475 +int
77476 +gr_search_socket(const int family, const int type, const int protocol)
77477 +{
77478 + return 1;
77479 +}
77480 +
77481 +int
77482 +gr_search_connectbind(const int mode, const struct socket *sock,
77483 + const struct sockaddr_in *addr)
77484 +{
77485 + return 0;
77486 +}
77487 +
77488 +void
77489 +gr_handle_alertkill(struct task_struct *task)
77490 +{
77491 + return;
77492 +}
77493 +
77494 +__u32
77495 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
77496 +{
77497 + return 1;
77498 +}
77499 +
77500 +__u32
77501 +gr_acl_handle_hidden_file(const struct dentry * dentry,
77502 + const struct vfsmount * mnt)
77503 +{
77504 + return 1;
77505 +}
77506 +
77507 +__u32
77508 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
77509 + int acc_mode)
77510 +{
77511 + return 1;
77512 +}
77513 +
77514 +__u32
77515 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
77516 +{
77517 + return 1;
77518 +}
77519 +
77520 +__u32
77521 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
77522 +{
77523 + return 1;
77524 +}
77525 +
77526 +int
77527 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
77528 + unsigned int *vm_flags)
77529 +{
77530 + return 1;
77531 +}
77532 +
77533 +__u32
77534 +gr_acl_handle_truncate(const struct dentry * dentry,
77535 + const struct vfsmount * mnt)
77536 +{
77537 + return 1;
77538 +}
77539 +
77540 +__u32
77541 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
77542 +{
77543 + return 1;
77544 +}
77545 +
77546 +__u32
77547 +gr_acl_handle_access(const struct dentry * dentry,
77548 + const struct vfsmount * mnt, const int fmode)
77549 +{
77550 + return 1;
77551 +}
77552 +
77553 +__u32
77554 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
77555 + umode_t *mode)
77556 +{
77557 + return 1;
77558 +}
77559 +
77560 +__u32
77561 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
77562 +{
77563 + return 1;
77564 +}
77565 +
77566 +__u32
77567 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
77568 +{
77569 + return 1;
77570 +}
77571 +
77572 +__u32
77573 +gr_acl_handle_removexattr(const struct dentry * dentry, const struct vfsmount * mnt)
77574 +{
77575 + return 1;
77576 +}
77577 +
77578 +void
77579 +grsecurity_init(void)
77580 +{
77581 + return;
77582 +}
77583 +
77584 +umode_t gr_acl_umask(void)
77585 +{
77586 + return 0;
77587 +}
77588 +
77589 +__u32
77590 +gr_acl_handle_mknod(const struct dentry * new_dentry,
77591 + const struct dentry * parent_dentry,
77592 + const struct vfsmount * parent_mnt,
77593 + const int mode)
77594 +{
77595 + return 1;
77596 +}
77597 +
77598 +__u32
77599 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
77600 + const struct dentry * parent_dentry,
77601 + const struct vfsmount * parent_mnt)
77602 +{
77603 + return 1;
77604 +}
77605 +
77606 +__u32
77607 +gr_acl_handle_symlink(const struct dentry * new_dentry,
77608 + const struct dentry * parent_dentry,
77609 + const struct vfsmount * parent_mnt, const struct filename *from)
77610 +{
77611 + return 1;
77612 +}
77613 +
77614 +__u32
77615 +gr_acl_handle_link(const struct dentry * new_dentry,
77616 + const struct dentry * parent_dentry,
77617 + const struct vfsmount * parent_mnt,
77618 + const struct dentry * old_dentry,
77619 + const struct vfsmount * old_mnt, const struct filename *to)
77620 +{
77621 + return 1;
77622 +}
77623 +
77624 +int
77625 +gr_acl_handle_rename(const struct dentry *new_dentry,
77626 + const struct dentry *parent_dentry,
77627 + const struct vfsmount *parent_mnt,
77628 + const struct dentry *old_dentry,
77629 + const struct inode *old_parent_inode,
77630 + const struct vfsmount *old_mnt, const struct filename *newname,
77631 + unsigned int flags)
77632 +{
77633 + return 0;
77634 +}
77635 +
77636 +int
77637 +gr_acl_handle_filldir(const struct file *file, const char *name,
77638 + const int namelen, const ino_t ino)
77639 +{
77640 + return 1;
77641 +}
77642 +
77643 +int
77644 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
77645 + const time_t shm_createtime, const kuid_t cuid, const int shmid)
77646 +{
77647 + return 1;
77648 +}
77649 +
77650 +int
77651 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
77652 +{
77653 + return 0;
77654 +}
77655 +
77656 +int
77657 +gr_search_accept(const struct socket *sock)
77658 +{
77659 + return 0;
77660 +}
77661 +
77662 +int
77663 +gr_search_listen(const struct socket *sock)
77664 +{
77665 + return 0;
77666 +}
77667 +
77668 +int
77669 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
77670 +{
77671 + return 0;
77672 +}
77673 +
77674 +__u32
77675 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
77676 +{
77677 + return 1;
77678 +}
77679 +
77680 +__u32
77681 +gr_acl_handle_creat(const struct dentry * dentry,
77682 + const struct dentry * p_dentry,
77683 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
77684 + const int imode)
77685 +{
77686 + return 1;
77687 +}
77688 +
77689 +void
77690 +gr_acl_handle_exit(void)
77691 +{
77692 + return;
77693 +}
77694 +
77695 +int
77696 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
77697 +{
77698 + return 1;
77699 +}
77700 +
77701 +void
77702 +gr_set_role_label(const kuid_t uid, const kgid_t gid)
77703 +{
77704 + return;
77705 +}
77706 +
77707 +int
77708 +gr_acl_handle_procpidmem(const struct task_struct *task)
77709 +{
77710 + return 0;
77711 +}
77712 +
77713 +int
77714 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
77715 +{
77716 + return 0;
77717 +}
77718 +
77719 +int
77720 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
77721 +{
77722 + return 0;
77723 +}
77724 +
77725 +int
77726 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
77727 +{
77728 + return 0;
77729 +}
77730 +
77731 +int
77732 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
77733 +{
77734 + return 0;
77735 +}
77736 +
77737 +int gr_acl_enable_at_secure(void)
77738 +{
77739 + return 0;
77740 +}
77741 +
77742 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
77743 +{
77744 + return dentry->d_sb->s_dev;
77745 +}
77746 +
77747 +void gr_put_exec_file(struct task_struct *task)
77748 +{
77749 + return;
77750 +}
77751 +
77752 +#ifdef CONFIG_SECURITY
77753 +EXPORT_SYMBOL_GPL(gr_check_user_change);
77754 +EXPORT_SYMBOL_GPL(gr_check_group_change);
77755 +#endif
77756 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
77757 new file mode 100644
77758 index 0000000..14638ff
77759 --- /dev/null
77760 +++ b/grsecurity/grsec_exec.c
77761 @@ -0,0 +1,188 @@
77762 +#include <linux/kernel.h>
77763 +#include <linux/sched.h>
77764 +#include <linux/file.h>
77765 +#include <linux/binfmts.h>
77766 +#include <linux/fs.h>
77767 +#include <linux/types.h>
77768 +#include <linux/grdefs.h>
77769 +#include <linux/grsecurity.h>
77770 +#include <linux/grinternal.h>
77771 +#include <linux/capability.h>
77772 +#include <linux/module.h>
77773 +#include <linux/compat.h>
77774 +
77775 +#include <asm/uaccess.h>
77776 +
77777 +#ifdef CONFIG_GRKERNSEC_EXECLOG
77778 +static char gr_exec_arg_buf[132];
77779 +static DEFINE_MUTEX(gr_exec_arg_mutex);
77780 +#endif
77781 +
77782 +struct user_arg_ptr {
77783 +#ifdef CONFIG_COMPAT
77784 + bool is_compat;
77785 +#endif
77786 + union {
77787 + const char __user *const __user *native;
77788 +#ifdef CONFIG_COMPAT
77789 + const compat_uptr_t __user *compat;
77790 +#endif
77791 + } ptr;
77792 +};
77793 +
77794 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
77795 +
77796 +void
77797 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
77798 +{
77799 +#ifdef CONFIG_GRKERNSEC_EXECLOG
77800 + char *grarg = gr_exec_arg_buf;
77801 + unsigned int i, x, execlen = 0;
77802 + char c;
77803 +
77804 + if (!((grsec_enable_execlog && grsec_enable_group &&
77805 + in_group_p(grsec_audit_gid))
77806 + || (grsec_enable_execlog && !grsec_enable_group)))
77807 + return;
77808 +
77809 + mutex_lock(&gr_exec_arg_mutex);
77810 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
77811 +
77812 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
77813 + const char __user *p;
77814 + unsigned int len;
77815 +
77816 + p = get_user_arg_ptr(argv, i);
77817 + if (IS_ERR(p))
77818 + goto log;
77819 +
77820 + len = strnlen_user(p, 128 - execlen);
77821 + if (len > 128 - execlen)
77822 + len = 128 - execlen;
77823 + else if (len > 0)
77824 + len--;
77825 + if (copy_from_user(grarg + execlen, p, len))
77826 + goto log;
77827 +
77828 + /* rewrite unprintable characters */
77829 + for (x = 0; x < len; x++) {
77830 + c = *(grarg + execlen + x);
77831 + if (c < 32 || c > 126)
77832 + *(grarg + execlen + x) = ' ';
77833 + }
77834 +
77835 + execlen += len;
77836 + *(grarg + execlen) = ' ';
77837 + *(grarg + execlen + 1) = '\0';
77838 + execlen++;
77839 + }
77840 +
77841 + log:
77842 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
77843 + bprm->file->f_path.mnt, grarg);
77844 + mutex_unlock(&gr_exec_arg_mutex);
77845 +#endif
77846 + return;
77847 +}
77848 +
77849 +#ifdef CONFIG_GRKERNSEC
77850 +extern int gr_acl_is_capable(const int cap);
77851 +extern int gr_acl_is_capable_nolog(const int cap);
77852 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
77853 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
77854 +extern int gr_chroot_is_capable(const int cap);
77855 +extern int gr_chroot_is_capable_nolog(const int cap);
77856 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
77857 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
77858 +#endif
77859 +
77860 +const char *captab_log[] = {
77861 + "CAP_CHOWN",
77862 + "CAP_DAC_OVERRIDE",
77863 + "CAP_DAC_READ_SEARCH",
77864 + "CAP_FOWNER",
77865 + "CAP_FSETID",
77866 + "CAP_KILL",
77867 + "CAP_SETGID",
77868 + "CAP_SETUID",
77869 + "CAP_SETPCAP",
77870 + "CAP_LINUX_IMMUTABLE",
77871 + "CAP_NET_BIND_SERVICE",
77872 + "CAP_NET_BROADCAST",
77873 + "CAP_NET_ADMIN",
77874 + "CAP_NET_RAW",
77875 + "CAP_IPC_LOCK",
77876 + "CAP_IPC_OWNER",
77877 + "CAP_SYS_MODULE",
77878 + "CAP_SYS_RAWIO",
77879 + "CAP_SYS_CHROOT",
77880 + "CAP_SYS_PTRACE",
77881 + "CAP_SYS_PACCT",
77882 + "CAP_SYS_ADMIN",
77883 + "CAP_SYS_BOOT",
77884 + "CAP_SYS_NICE",
77885 + "CAP_SYS_RESOURCE",
77886 + "CAP_SYS_TIME",
77887 + "CAP_SYS_TTY_CONFIG",
77888 + "CAP_MKNOD",
77889 + "CAP_LEASE",
77890 + "CAP_AUDIT_WRITE",
77891 + "CAP_AUDIT_CONTROL",
77892 + "CAP_SETFCAP",
77893 + "CAP_MAC_OVERRIDE",
77894 + "CAP_MAC_ADMIN",
77895 + "CAP_SYSLOG",
77896 + "CAP_WAKE_ALARM",
77897 + "CAP_BLOCK_SUSPEND"
77898 +};
77899 +
77900 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
77901 +
77902 +int gr_is_capable(const int cap)
77903 +{
77904 +#ifdef CONFIG_GRKERNSEC
77905 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
77906 + return 1;
77907 + return 0;
77908 +#else
77909 + return 1;
77910 +#endif
77911 +}
77912 +
77913 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
77914 +{
77915 +#ifdef CONFIG_GRKERNSEC
77916 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
77917 + return 1;
77918 + return 0;
77919 +#else
77920 + return 1;
77921 +#endif
77922 +}
77923 +
77924 +int gr_is_capable_nolog(const int cap)
77925 +{
77926 +#ifdef CONFIG_GRKERNSEC
77927 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
77928 + return 1;
77929 + return 0;
77930 +#else
77931 + return 1;
77932 +#endif
77933 +}
77934 +
77935 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
77936 +{
77937 +#ifdef CONFIG_GRKERNSEC
77938 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
77939 + return 1;
77940 + return 0;
77941 +#else
77942 + return 1;
77943 +#endif
77944 +}
77945 +
77946 +EXPORT_SYMBOL_GPL(gr_is_capable);
77947 +EXPORT_SYMBOL_GPL(gr_is_capable_nolog);
77948 +EXPORT_SYMBOL_GPL(gr_task_is_capable);
77949 +EXPORT_SYMBOL_GPL(gr_task_is_capable_nolog);
77950 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
77951 new file mode 100644
77952 index 0000000..06cc6ea
77953 --- /dev/null
77954 +++ b/grsecurity/grsec_fifo.c
77955 @@ -0,0 +1,24 @@
77956 +#include <linux/kernel.h>
77957 +#include <linux/sched.h>
77958 +#include <linux/fs.h>
77959 +#include <linux/file.h>
77960 +#include <linux/grinternal.h>
77961 +
77962 +int
77963 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
77964 + const struct dentry *dir, const int flag, const int acc_mode)
77965 +{
77966 +#ifdef CONFIG_GRKERNSEC_FIFO
77967 + const struct cred *cred = current_cred();
77968 +
77969 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
77970 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
77971 + !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
77972 + !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
77973 + if (!inode_permission(dentry->d_inode, acc_mode))
77974 + 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));
77975 + return -EACCES;
77976 + }
77977 +#endif
77978 + return 0;
77979 +}
77980 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
77981 new file mode 100644
77982 index 0000000..8ca18bf
77983 --- /dev/null
77984 +++ b/grsecurity/grsec_fork.c
77985 @@ -0,0 +1,23 @@
77986 +#include <linux/kernel.h>
77987 +#include <linux/sched.h>
77988 +#include <linux/grsecurity.h>
77989 +#include <linux/grinternal.h>
77990 +#include <linux/errno.h>
77991 +
77992 +void
77993 +gr_log_forkfail(const int retval)
77994 +{
77995 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
77996 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
77997 + switch (retval) {
77998 + case -EAGAIN:
77999 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
78000 + break;
78001 + case -ENOMEM:
78002 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
78003 + break;
78004 + }
78005 + }
78006 +#endif
78007 + return;
78008 +}
78009 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
78010 new file mode 100644
78011 index 0000000..b7cb191
78012 --- /dev/null
78013 +++ b/grsecurity/grsec_init.c
78014 @@ -0,0 +1,286 @@
78015 +#include <linux/kernel.h>
78016 +#include <linux/sched.h>
78017 +#include <linux/mm.h>
78018 +#include <linux/gracl.h>
78019 +#include <linux/slab.h>
78020 +#include <linux/vmalloc.h>
78021 +#include <linux/percpu.h>
78022 +#include <linux/module.h>
78023 +
78024 +int grsec_enable_ptrace_readexec;
78025 +int grsec_enable_setxid;
78026 +int grsec_enable_symlinkown;
78027 +kgid_t grsec_symlinkown_gid;
78028 +int grsec_enable_brute;
78029 +int grsec_enable_link;
78030 +int grsec_enable_dmesg;
78031 +int grsec_enable_harden_ptrace;
78032 +int grsec_enable_harden_ipc;
78033 +int grsec_enable_fifo;
78034 +int grsec_enable_execlog;
78035 +int grsec_enable_signal;
78036 +int grsec_enable_forkfail;
78037 +int grsec_enable_audit_ptrace;
78038 +int grsec_enable_time;
78039 +int grsec_enable_group;
78040 +kgid_t grsec_audit_gid;
78041 +int grsec_enable_chdir;
78042 +int grsec_enable_mount;
78043 +int grsec_enable_rofs;
78044 +int grsec_deny_new_usb;
78045 +int grsec_enable_chroot_findtask;
78046 +int grsec_enable_chroot_mount;
78047 +int grsec_enable_chroot_shmat;
78048 +int grsec_enable_chroot_fchdir;
78049 +int grsec_enable_chroot_double;
78050 +int grsec_enable_chroot_pivot;
78051 +int grsec_enable_chroot_chdir;
78052 +int grsec_enable_chroot_chmod;
78053 +int grsec_enable_chroot_mknod;
78054 +int grsec_enable_chroot_nice;
78055 +int grsec_enable_chroot_execlog;
78056 +int grsec_enable_chroot_caps;
78057 +int grsec_enable_chroot_sysctl;
78058 +int grsec_enable_chroot_unix;
78059 +int grsec_enable_tpe;
78060 +kgid_t grsec_tpe_gid;
78061 +int grsec_enable_blackhole;
78062 +#ifdef CONFIG_IPV6_MODULE
78063 +EXPORT_SYMBOL_GPL(grsec_enable_blackhole);
78064 +#endif
78065 +int grsec_lastack_retries;
78066 +int grsec_enable_tpe_all;
78067 +int grsec_enable_tpe_invert;
78068 +int grsec_enable_socket_all;
78069 +kgid_t grsec_socket_all_gid;
78070 +int grsec_enable_socket_client;
78071 +kgid_t grsec_socket_client_gid;
78072 +int grsec_enable_socket_server;
78073 +kgid_t grsec_socket_server_gid;
78074 +int grsec_resource_logging;
78075 +int grsec_disable_privio;
78076 +int grsec_enable_log_rwxmaps;
78077 +int grsec_lock;
78078 +
78079 +DEFINE_SPINLOCK(grsec_alert_lock);
78080 +unsigned long grsec_alert_wtime = 0;
78081 +unsigned long grsec_alert_fyet = 0;
78082 +
78083 +DEFINE_SPINLOCK(grsec_audit_lock);
78084 +
78085 +DEFINE_RWLOCK(grsec_exec_file_lock);
78086 +
78087 +char *gr_shared_page[4];
78088 +
78089 +char *gr_alert_log_fmt;
78090 +char *gr_audit_log_fmt;
78091 +char *gr_alert_log_buf;
78092 +char *gr_audit_log_buf;
78093 +
78094 +extern struct gr_arg *gr_usermode;
78095 +extern unsigned char *gr_system_salt;
78096 +extern unsigned char *gr_system_sum;
78097 +
78098 +void __init
78099 +grsecurity_init(void)
78100 +{
78101 + int j;
78102 + /* create the per-cpu shared pages */
78103 +
78104 +#ifdef CONFIG_X86
78105 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
78106 +#endif
78107 +
78108 + for (j = 0; j < 4; j++) {
78109 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
78110 + if (gr_shared_page[j] == NULL) {
78111 + panic("Unable to allocate grsecurity shared page");
78112 + return;
78113 + }
78114 + }
78115 +
78116 + /* allocate log buffers */
78117 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
78118 + if (!gr_alert_log_fmt) {
78119 + panic("Unable to allocate grsecurity alert log format buffer");
78120 + return;
78121 + }
78122 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
78123 + if (!gr_audit_log_fmt) {
78124 + panic("Unable to allocate grsecurity audit log format buffer");
78125 + return;
78126 + }
78127 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
78128 + if (!gr_alert_log_buf) {
78129 + panic("Unable to allocate grsecurity alert log buffer");
78130 + return;
78131 + }
78132 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
78133 + if (!gr_audit_log_buf) {
78134 + panic("Unable to allocate grsecurity audit log buffer");
78135 + return;
78136 + }
78137 +
78138 + /* allocate memory for authentication structure */
78139 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
78140 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
78141 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
78142 +
78143 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
78144 + panic("Unable to allocate grsecurity authentication structure");
78145 + return;
78146 + }
78147 +
78148 +#ifdef CONFIG_GRKERNSEC_IO
78149 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
78150 + grsec_disable_privio = 1;
78151 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
78152 + grsec_disable_privio = 1;
78153 +#else
78154 + grsec_disable_privio = 0;
78155 +#endif
78156 +#endif
78157 +
78158 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
78159 + /* for backward compatibility, tpe_invert always defaults to on if
78160 + enabled in the kernel
78161 + */
78162 + grsec_enable_tpe_invert = 1;
78163 +#endif
78164 +
78165 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
78166 +#ifndef CONFIG_GRKERNSEC_SYSCTL
78167 + grsec_lock = 1;
78168 +#endif
78169 +
78170 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78171 + grsec_enable_log_rwxmaps = 1;
78172 +#endif
78173 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
78174 + grsec_enable_group = 1;
78175 + grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
78176 +#endif
78177 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
78178 + grsec_enable_ptrace_readexec = 1;
78179 +#endif
78180 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
78181 + grsec_enable_chdir = 1;
78182 +#endif
78183 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
78184 + grsec_enable_harden_ptrace = 1;
78185 +#endif
78186 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
78187 + grsec_enable_harden_ipc = 1;
78188 +#endif
78189 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
78190 + grsec_enable_mount = 1;
78191 +#endif
78192 +#ifdef CONFIG_GRKERNSEC_LINK
78193 + grsec_enable_link = 1;
78194 +#endif
78195 +#ifdef CONFIG_GRKERNSEC_BRUTE
78196 + grsec_enable_brute = 1;
78197 +#endif
78198 +#ifdef CONFIG_GRKERNSEC_DMESG
78199 + grsec_enable_dmesg = 1;
78200 +#endif
78201 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78202 + grsec_enable_blackhole = 1;
78203 + grsec_lastack_retries = 4;
78204 +#endif
78205 +#ifdef CONFIG_GRKERNSEC_FIFO
78206 + grsec_enable_fifo = 1;
78207 +#endif
78208 +#ifdef CONFIG_GRKERNSEC_EXECLOG
78209 + grsec_enable_execlog = 1;
78210 +#endif
78211 +#ifdef CONFIG_GRKERNSEC_SETXID
78212 + grsec_enable_setxid = 1;
78213 +#endif
78214 +#ifdef CONFIG_GRKERNSEC_SIGNAL
78215 + grsec_enable_signal = 1;
78216 +#endif
78217 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
78218 + grsec_enable_forkfail = 1;
78219 +#endif
78220 +#ifdef CONFIG_GRKERNSEC_TIME
78221 + grsec_enable_time = 1;
78222 +#endif
78223 +#ifdef CONFIG_GRKERNSEC_RESLOG
78224 + grsec_resource_logging = 1;
78225 +#endif
78226 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
78227 + grsec_enable_chroot_findtask = 1;
78228 +#endif
78229 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
78230 + grsec_enable_chroot_unix = 1;
78231 +#endif
78232 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
78233 + grsec_enable_chroot_mount = 1;
78234 +#endif
78235 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
78236 + grsec_enable_chroot_fchdir = 1;
78237 +#endif
78238 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
78239 + grsec_enable_chroot_shmat = 1;
78240 +#endif
78241 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
78242 + grsec_enable_audit_ptrace = 1;
78243 +#endif
78244 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
78245 + grsec_enable_chroot_double = 1;
78246 +#endif
78247 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
78248 + grsec_enable_chroot_pivot = 1;
78249 +#endif
78250 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
78251 + grsec_enable_chroot_chdir = 1;
78252 +#endif
78253 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
78254 + grsec_enable_chroot_chmod = 1;
78255 +#endif
78256 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
78257 + grsec_enable_chroot_mknod = 1;
78258 +#endif
78259 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
78260 + grsec_enable_chroot_nice = 1;
78261 +#endif
78262 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
78263 + grsec_enable_chroot_execlog = 1;
78264 +#endif
78265 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
78266 + grsec_enable_chroot_caps = 1;
78267 +#endif
78268 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
78269 + grsec_enable_chroot_sysctl = 1;
78270 +#endif
78271 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
78272 + grsec_enable_symlinkown = 1;
78273 + grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
78274 +#endif
78275 +#ifdef CONFIG_GRKERNSEC_TPE
78276 + grsec_enable_tpe = 1;
78277 + grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
78278 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
78279 + grsec_enable_tpe_all = 1;
78280 +#endif
78281 +#endif
78282 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
78283 + grsec_enable_socket_all = 1;
78284 + grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
78285 +#endif
78286 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
78287 + grsec_enable_socket_client = 1;
78288 + grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
78289 +#endif
78290 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
78291 + grsec_enable_socket_server = 1;
78292 + grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
78293 +#endif
78294 +#endif
78295 +#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
78296 + grsec_deny_new_usb = 1;
78297 +#endif
78298 +
78299 + return;
78300 +}
78301 diff --git a/grsecurity/grsec_ipc.c b/grsecurity/grsec_ipc.c
78302 new file mode 100644
78303 index 0000000..1773300
78304 --- /dev/null
78305 +++ b/grsecurity/grsec_ipc.c
78306 @@ -0,0 +1,48 @@
78307 +#include <linux/kernel.h>
78308 +#include <linux/mm.h>
78309 +#include <linux/sched.h>
78310 +#include <linux/file.h>
78311 +#include <linux/ipc.h>
78312 +#include <linux/ipc_namespace.h>
78313 +#include <linux/grsecurity.h>
78314 +#include <linux/grinternal.h>
78315 +
78316 +int
78317 +gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode)
78318 +{
78319 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
78320 + int write;
78321 + int orig_granted_mode;
78322 + kuid_t euid;
78323 + kgid_t egid;
78324 +
78325 + if (!grsec_enable_harden_ipc)
78326 + return 1;
78327 +
78328 + euid = current_euid();
78329 + egid = current_egid();
78330 +
78331 + write = requested_mode & 00002;
78332 + orig_granted_mode = ipcp->mode;
78333 +
78334 + if (uid_eq(euid, ipcp->cuid) || uid_eq(euid, ipcp->uid))
78335 + orig_granted_mode >>= 6;
78336 + else {
78337 + /* if likely wrong permissions, lock to user */
78338 + if (orig_granted_mode & 0007)
78339 + orig_granted_mode = 0;
78340 + /* otherwise do a egid-only check */
78341 + else if (gid_eq(egid, ipcp->cgid) || gid_eq(egid, ipcp->gid))
78342 + orig_granted_mode >>= 3;
78343 + /* otherwise, no access */
78344 + else
78345 + orig_granted_mode = 0;
78346 + }
78347 + if (!(requested_mode & ~granted_mode & 0007) && (requested_mode & ~orig_granted_mode & 0007) &&
78348 + !ns_capable_nolog(ns->user_ns, CAP_IPC_OWNER)) {
78349 + gr_log_str_int(GR_DONT_AUDIT, GR_IPC_DENIED_MSG, write ? "write" : "read", GR_GLOBAL_UID(ipcp->cuid));
78350 + return 0;
78351 + }
78352 +#endif
78353 + return 1;
78354 +}
78355 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
78356 new file mode 100644
78357 index 0000000..5e05e20
78358 --- /dev/null
78359 +++ b/grsecurity/grsec_link.c
78360 @@ -0,0 +1,58 @@
78361 +#include <linux/kernel.h>
78362 +#include <linux/sched.h>
78363 +#include <linux/fs.h>
78364 +#include <linux/file.h>
78365 +#include <linux/grinternal.h>
78366 +
78367 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
78368 +{
78369 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
78370 + const struct inode *link_inode = link->dentry->d_inode;
78371 +
78372 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
78373 + /* ignore root-owned links, e.g. /proc/self */
78374 + gr_is_global_nonroot(link_inode->i_uid) && target &&
78375 + !uid_eq(link_inode->i_uid, target->i_uid)) {
78376 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
78377 + return 1;
78378 + }
78379 +#endif
78380 + return 0;
78381 +}
78382 +
78383 +int
78384 +gr_handle_follow_link(const struct inode *parent,
78385 + const struct inode *inode,
78386 + const struct dentry *dentry, const struct vfsmount *mnt)
78387 +{
78388 +#ifdef CONFIG_GRKERNSEC_LINK
78389 + const struct cred *cred = current_cred();
78390 +
78391 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
78392 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
78393 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
78394 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
78395 + return -EACCES;
78396 + }
78397 +#endif
78398 + return 0;
78399 +}
78400 +
78401 +int
78402 +gr_handle_hardlink(const struct dentry *dentry,
78403 + const struct vfsmount *mnt,
78404 + struct inode *inode, const int mode, const struct filename *to)
78405 +{
78406 +#ifdef CONFIG_GRKERNSEC_LINK
78407 + const struct cred *cred = current_cred();
78408 +
78409 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
78410 + (!S_ISREG(mode) || is_privileged_binary(dentry) ||
78411 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
78412 + !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
78413 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
78414 + return -EPERM;
78415 + }
78416 +#endif
78417 + return 0;
78418 +}
78419 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
78420 new file mode 100644
78421 index 0000000..dbe0a6b
78422 --- /dev/null
78423 +++ b/grsecurity/grsec_log.c
78424 @@ -0,0 +1,341 @@
78425 +#include <linux/kernel.h>
78426 +#include <linux/sched.h>
78427 +#include <linux/file.h>
78428 +#include <linux/tty.h>
78429 +#include <linux/fs.h>
78430 +#include <linux/mm.h>
78431 +#include <linux/grinternal.h>
78432 +
78433 +#ifdef CONFIG_TREE_PREEMPT_RCU
78434 +#define DISABLE_PREEMPT() preempt_disable()
78435 +#define ENABLE_PREEMPT() preempt_enable()
78436 +#else
78437 +#define DISABLE_PREEMPT()
78438 +#define ENABLE_PREEMPT()
78439 +#endif
78440 +
78441 +#define BEGIN_LOCKS(x) \
78442 + DISABLE_PREEMPT(); \
78443 + rcu_read_lock(); \
78444 + read_lock(&tasklist_lock); \
78445 + read_lock(&grsec_exec_file_lock); \
78446 + if (x != GR_DO_AUDIT) \
78447 + spin_lock(&grsec_alert_lock); \
78448 + else \
78449 + spin_lock(&grsec_audit_lock)
78450 +
78451 +#define END_LOCKS(x) \
78452 + if (x != GR_DO_AUDIT) \
78453 + spin_unlock(&grsec_alert_lock); \
78454 + else \
78455 + spin_unlock(&grsec_audit_lock); \
78456 + read_unlock(&grsec_exec_file_lock); \
78457 + read_unlock(&tasklist_lock); \
78458 + rcu_read_unlock(); \
78459 + ENABLE_PREEMPT(); \
78460 + if (x == GR_DONT_AUDIT) \
78461 + gr_handle_alertkill(current)
78462 +
78463 +enum {
78464 + FLOODING,
78465 + NO_FLOODING
78466 +};
78467 +
78468 +extern char *gr_alert_log_fmt;
78469 +extern char *gr_audit_log_fmt;
78470 +extern char *gr_alert_log_buf;
78471 +extern char *gr_audit_log_buf;
78472 +
78473 +static int gr_log_start(int audit)
78474 +{
78475 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
78476 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
78477 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
78478 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
78479 + unsigned long curr_secs = get_seconds();
78480 +
78481 + if (audit == GR_DO_AUDIT)
78482 + goto set_fmt;
78483 +
78484 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
78485 + grsec_alert_wtime = curr_secs;
78486 + grsec_alert_fyet = 0;
78487 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
78488 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
78489 + grsec_alert_fyet++;
78490 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
78491 + grsec_alert_wtime = curr_secs;
78492 + grsec_alert_fyet++;
78493 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
78494 + return FLOODING;
78495 + }
78496 + else return FLOODING;
78497 +
78498 +set_fmt:
78499 +#endif
78500 + memset(buf, 0, PAGE_SIZE);
78501 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
78502 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
78503 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
78504 + } else if (current->signal->curr_ip) {
78505 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
78506 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
78507 + } else if (gr_acl_is_enabled()) {
78508 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
78509 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
78510 + } else {
78511 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
78512 + strcpy(buf, fmt);
78513 + }
78514 +
78515 + return NO_FLOODING;
78516 +}
78517 +
78518 +static void gr_log_middle(int audit, const char *msg, va_list ap)
78519 + __attribute__ ((format (printf, 2, 0)));
78520 +
78521 +static void gr_log_middle(int audit, const char *msg, va_list ap)
78522 +{
78523 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
78524 + unsigned int len = strlen(buf);
78525 +
78526 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
78527 +
78528 + return;
78529 +}
78530 +
78531 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
78532 + __attribute__ ((format (printf, 2, 3)));
78533 +
78534 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
78535 +{
78536 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
78537 + unsigned int len = strlen(buf);
78538 + va_list ap;
78539 +
78540 + va_start(ap, msg);
78541 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
78542 + va_end(ap);
78543 +
78544 + return;
78545 +}
78546 +
78547 +static void gr_log_end(int audit, int append_default)
78548 +{
78549 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
78550 + if (append_default) {
78551 + struct task_struct *task = current;
78552 + struct task_struct *parent = task->real_parent;
78553 + const struct cred *cred = __task_cred(task);
78554 + const struct cred *pcred = __task_cred(parent);
78555 + unsigned int len = strlen(buf);
78556 +
78557 + 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));
78558 + }
78559 +
78560 + printk("%s\n", buf);
78561 +
78562 + return;
78563 +}
78564 +
78565 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
78566 +{
78567 + int logtype;
78568 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
78569 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
78570 + void *voidptr = NULL;
78571 + int num1 = 0, num2 = 0;
78572 + unsigned long ulong1 = 0, ulong2 = 0;
78573 + struct dentry *dentry = NULL;
78574 + struct vfsmount *mnt = NULL;
78575 + struct file *file = NULL;
78576 + struct task_struct *task = NULL;
78577 + struct vm_area_struct *vma = NULL;
78578 + const struct cred *cred, *pcred;
78579 + va_list ap;
78580 +
78581 + BEGIN_LOCKS(audit);
78582 + logtype = gr_log_start(audit);
78583 + if (logtype == FLOODING) {
78584 + END_LOCKS(audit);
78585 + return;
78586 + }
78587 + va_start(ap, argtypes);
78588 + switch (argtypes) {
78589 + case GR_TTYSNIFF:
78590 + task = va_arg(ap, struct task_struct *);
78591 + 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));
78592 + break;
78593 + case GR_SYSCTL_HIDDEN:
78594 + str1 = va_arg(ap, char *);
78595 + gr_log_middle_varargs(audit, msg, result, str1);
78596 + break;
78597 + case GR_RBAC:
78598 + dentry = va_arg(ap, struct dentry *);
78599 + mnt = va_arg(ap, struct vfsmount *);
78600 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
78601 + break;
78602 + case GR_RBAC_STR:
78603 + dentry = va_arg(ap, struct dentry *);
78604 + mnt = va_arg(ap, struct vfsmount *);
78605 + str1 = va_arg(ap, char *);
78606 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
78607 + break;
78608 + case GR_STR_RBAC:
78609 + str1 = va_arg(ap, char *);
78610 + dentry = va_arg(ap, struct dentry *);
78611 + mnt = va_arg(ap, struct vfsmount *);
78612 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
78613 + break;
78614 + case GR_RBAC_MODE2:
78615 + dentry = va_arg(ap, struct dentry *);
78616 + mnt = va_arg(ap, struct vfsmount *);
78617 + str1 = va_arg(ap, char *);
78618 + str2 = va_arg(ap, char *);
78619 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
78620 + break;
78621 + case GR_RBAC_MODE3:
78622 + dentry = va_arg(ap, struct dentry *);
78623 + mnt = va_arg(ap, struct vfsmount *);
78624 + str1 = va_arg(ap, char *);
78625 + str2 = va_arg(ap, char *);
78626 + str3 = va_arg(ap, char *);
78627 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
78628 + break;
78629 + case GR_FILENAME:
78630 + dentry = va_arg(ap, struct dentry *);
78631 + mnt = va_arg(ap, struct vfsmount *);
78632 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
78633 + break;
78634 + case GR_STR_FILENAME:
78635 + str1 = va_arg(ap, char *);
78636 + dentry = va_arg(ap, struct dentry *);
78637 + mnt = va_arg(ap, struct vfsmount *);
78638 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
78639 + break;
78640 + case GR_FILENAME_STR:
78641 + dentry = va_arg(ap, struct dentry *);
78642 + mnt = va_arg(ap, struct vfsmount *);
78643 + str1 = va_arg(ap, char *);
78644 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
78645 + break;
78646 + case GR_FILENAME_TWO_INT:
78647 + dentry = va_arg(ap, struct dentry *);
78648 + mnt = va_arg(ap, struct vfsmount *);
78649 + num1 = va_arg(ap, int);
78650 + num2 = va_arg(ap, int);
78651 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
78652 + break;
78653 + case GR_FILENAME_TWO_INT_STR:
78654 + dentry = va_arg(ap, struct dentry *);
78655 + mnt = va_arg(ap, struct vfsmount *);
78656 + num1 = va_arg(ap, int);
78657 + num2 = va_arg(ap, int);
78658 + str1 = va_arg(ap, char *);
78659 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
78660 + break;
78661 + case GR_TEXTREL:
78662 + file = va_arg(ap, struct file *);
78663 + ulong1 = va_arg(ap, unsigned long);
78664 + ulong2 = va_arg(ap, unsigned long);
78665 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
78666 + break;
78667 + case GR_PTRACE:
78668 + task = va_arg(ap, struct task_struct *);
78669 + 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));
78670 + break;
78671 + case GR_RESOURCE:
78672 + task = va_arg(ap, struct task_struct *);
78673 + cred = __task_cred(task);
78674 + pcred = __task_cred(task->real_parent);
78675 + ulong1 = va_arg(ap, unsigned long);
78676 + str1 = va_arg(ap, char *);
78677 + ulong2 = va_arg(ap, unsigned long);
78678 + 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));
78679 + break;
78680 + case GR_CAP:
78681 + task = va_arg(ap, struct task_struct *);
78682 + cred = __task_cred(task);
78683 + pcred = __task_cred(task->real_parent);
78684 + str1 = va_arg(ap, char *);
78685 + 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));
78686 + break;
78687 + case GR_SIG:
78688 + str1 = va_arg(ap, char *);
78689 + voidptr = va_arg(ap, void *);
78690 + gr_log_middle_varargs(audit, msg, str1, voidptr);
78691 + break;
78692 + case GR_SIG2:
78693 + task = va_arg(ap, struct task_struct *);
78694 + cred = __task_cred(task);
78695 + pcred = __task_cred(task->real_parent);
78696 + num1 = va_arg(ap, int);
78697 + 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));
78698 + break;
78699 + case GR_CRASH1:
78700 + task = va_arg(ap, struct task_struct *);
78701 + cred = __task_cred(task);
78702 + pcred = __task_cred(task->real_parent);
78703 + ulong1 = va_arg(ap, unsigned long);
78704 + 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);
78705 + break;
78706 + case GR_CRASH2:
78707 + task = va_arg(ap, struct task_struct *);
78708 + cred = __task_cred(task);
78709 + pcred = __task_cred(task->real_parent);
78710 + ulong1 = va_arg(ap, unsigned long);
78711 + 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);
78712 + break;
78713 + case GR_RWXMAP:
78714 + file = va_arg(ap, struct file *);
78715 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
78716 + break;
78717 + case GR_RWXMAPVMA:
78718 + vma = va_arg(ap, struct vm_area_struct *);
78719 + if (vma->vm_file)
78720 + str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
78721 + else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
78722 + str1 = "<stack>";
78723 + else if (vma->vm_start <= current->mm->brk &&
78724 + vma->vm_end >= current->mm->start_brk)
78725 + str1 = "<heap>";
78726 + else
78727 + str1 = "<anonymous mapping>";
78728 + gr_log_middle_varargs(audit, msg, str1);
78729 + break;
78730 + case GR_PSACCT:
78731 + {
78732 + unsigned int wday, cday;
78733 + __u8 whr, chr;
78734 + __u8 wmin, cmin;
78735 + __u8 wsec, csec;
78736 + char cur_tty[64] = { 0 };
78737 + char parent_tty[64] = { 0 };
78738 +
78739 + task = va_arg(ap, struct task_struct *);
78740 + wday = va_arg(ap, unsigned int);
78741 + cday = va_arg(ap, unsigned int);
78742 + whr = va_arg(ap, int);
78743 + chr = va_arg(ap, int);
78744 + wmin = va_arg(ap, int);
78745 + cmin = va_arg(ap, int);
78746 + wsec = va_arg(ap, int);
78747 + csec = va_arg(ap, int);
78748 + ulong1 = va_arg(ap, unsigned long);
78749 + cred = __task_cred(task);
78750 + pcred = __task_cred(task->real_parent);
78751 +
78752 + 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));
78753 + }
78754 + break;
78755 + default:
78756 + gr_log_middle(audit, msg, ap);
78757 + }
78758 + va_end(ap);
78759 + // these don't need DEFAULTSECARGS printed on the end
78760 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
78761 + gr_log_end(audit, 0);
78762 + else
78763 + gr_log_end(audit, 1);
78764 + END_LOCKS(audit);
78765 +}
78766 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
78767 new file mode 100644
78768 index 0000000..0e39d8c
78769 --- /dev/null
78770 +++ b/grsecurity/grsec_mem.c
78771 @@ -0,0 +1,48 @@
78772 +#include <linux/kernel.h>
78773 +#include <linux/sched.h>
78774 +#include <linux/mm.h>
78775 +#include <linux/mman.h>
78776 +#include <linux/module.h>
78777 +#include <linux/grinternal.h>
78778 +
78779 +void gr_handle_msr_write(void)
78780 +{
78781 + gr_log_noargs(GR_DONT_AUDIT, GR_MSRWRITE_MSG);
78782 + return;
78783 +}
78784 +EXPORT_SYMBOL_GPL(gr_handle_msr_write);
78785 +
78786 +void
78787 +gr_handle_ioperm(void)
78788 +{
78789 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
78790 + return;
78791 +}
78792 +
78793 +void
78794 +gr_handle_iopl(void)
78795 +{
78796 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
78797 + return;
78798 +}
78799 +
78800 +void
78801 +gr_handle_mem_readwrite(u64 from, u64 to)
78802 +{
78803 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
78804 + return;
78805 +}
78806 +
78807 +void
78808 +gr_handle_vm86(void)
78809 +{
78810 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
78811 + return;
78812 +}
78813 +
78814 +void
78815 +gr_log_badprocpid(const char *entry)
78816 +{
78817 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
78818 + return;
78819 +}
78820 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
78821 new file mode 100644
78822 index 0000000..cd9e124
78823 --- /dev/null
78824 +++ b/grsecurity/grsec_mount.c
78825 @@ -0,0 +1,65 @@
78826 +#include <linux/kernel.h>
78827 +#include <linux/sched.h>
78828 +#include <linux/mount.h>
78829 +#include <linux/major.h>
78830 +#include <linux/grsecurity.h>
78831 +#include <linux/grinternal.h>
78832 +
78833 +void
78834 +gr_log_remount(const char *devname, const int retval)
78835 +{
78836 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
78837 + if (grsec_enable_mount && (retval >= 0))
78838 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
78839 +#endif
78840 + return;
78841 +}
78842 +
78843 +void
78844 +gr_log_unmount(const char *devname, const int retval)
78845 +{
78846 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
78847 + if (grsec_enable_mount && (retval >= 0))
78848 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
78849 +#endif
78850 + return;
78851 +}
78852 +
78853 +void
78854 +gr_log_mount(const char *from, const char *to, const int retval)
78855 +{
78856 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
78857 + if (grsec_enable_mount && (retval >= 0))
78858 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
78859 +#endif
78860 + return;
78861 +}
78862 +
78863 +int
78864 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
78865 +{
78866 +#ifdef CONFIG_GRKERNSEC_ROFS
78867 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
78868 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
78869 + return -EPERM;
78870 + } else
78871 + return 0;
78872 +#endif
78873 + return 0;
78874 +}
78875 +
78876 +int
78877 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
78878 +{
78879 +#ifdef CONFIG_GRKERNSEC_ROFS
78880 + struct inode *inode = dentry->d_inode;
78881 +
78882 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
78883 + inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR))) {
78884 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
78885 + return -EPERM;
78886 + } else
78887 + return 0;
78888 +#endif
78889 + return 0;
78890 +}
78891 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
78892 new file mode 100644
78893 index 0000000..6ee9d50
78894 --- /dev/null
78895 +++ b/grsecurity/grsec_pax.c
78896 @@ -0,0 +1,45 @@
78897 +#include <linux/kernel.h>
78898 +#include <linux/sched.h>
78899 +#include <linux/mm.h>
78900 +#include <linux/file.h>
78901 +#include <linux/grinternal.h>
78902 +#include <linux/grsecurity.h>
78903 +
78904 +void
78905 +gr_log_textrel(struct vm_area_struct * vma)
78906 +{
78907 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78908 + if (grsec_enable_log_rwxmaps)
78909 + gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
78910 +#endif
78911 + return;
78912 +}
78913 +
78914 +void gr_log_ptgnustack(struct file *file)
78915 +{
78916 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78917 + if (grsec_enable_log_rwxmaps)
78918 + gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
78919 +#endif
78920 + return;
78921 +}
78922 +
78923 +void
78924 +gr_log_rwxmmap(struct file *file)
78925 +{
78926 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78927 + if (grsec_enable_log_rwxmaps)
78928 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
78929 +#endif
78930 + return;
78931 +}
78932 +
78933 +void
78934 +gr_log_rwxmprotect(struct vm_area_struct *vma)
78935 +{
78936 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78937 + if (grsec_enable_log_rwxmaps)
78938 + gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
78939 +#endif
78940 + return;
78941 +}
78942 diff --git a/grsecurity/grsec_proc.c b/grsecurity/grsec_proc.c
78943 new file mode 100644
78944 index 0000000..2005a3a
78945 --- /dev/null
78946 +++ b/grsecurity/grsec_proc.c
78947 @@ -0,0 +1,20 @@
78948 +#include <linux/kernel.h>
78949 +#include <linux/sched.h>
78950 +#include <linux/grsecurity.h>
78951 +#include <linux/grinternal.h>
78952 +
78953 +int gr_proc_is_restricted(void)
78954 +{
78955 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
78956 + const struct cred *cred = current_cred();
78957 +#endif
78958 +
78959 +#ifdef CONFIG_GRKERNSEC_PROC_USER
78960 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
78961 + return -EACCES;
78962 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
78963 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
78964 + return -EACCES;
78965 +#endif
78966 + return 0;
78967 +}
78968 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
78969 new file mode 100644
78970 index 0000000..f7f29aa
78971 --- /dev/null
78972 +++ b/grsecurity/grsec_ptrace.c
78973 @@ -0,0 +1,30 @@
78974 +#include <linux/kernel.h>
78975 +#include <linux/sched.h>
78976 +#include <linux/grinternal.h>
78977 +#include <linux/security.h>
78978 +
78979 +void
78980 +gr_audit_ptrace(struct task_struct *task)
78981 +{
78982 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
78983 + if (grsec_enable_audit_ptrace)
78984 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
78985 +#endif
78986 + return;
78987 +}
78988 +
78989 +int
78990 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
78991 +{
78992 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
78993 + const struct dentry *dentry = file->f_path.dentry;
78994 + const struct vfsmount *mnt = file->f_path.mnt;
78995 +
78996 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
78997 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
78998 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
78999 + return -EACCES;
79000 + }
79001 +#endif
79002 + return 0;
79003 +}
79004 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
79005 new file mode 100644
79006 index 0000000..3860c7e
79007 --- /dev/null
79008 +++ b/grsecurity/grsec_sig.c
79009 @@ -0,0 +1,236 @@
79010 +#include <linux/kernel.h>
79011 +#include <linux/sched.h>
79012 +#include <linux/fs.h>
79013 +#include <linux/delay.h>
79014 +#include <linux/grsecurity.h>
79015 +#include <linux/grinternal.h>
79016 +#include <linux/hardirq.h>
79017 +
79018 +char *signames[] = {
79019 + [SIGSEGV] = "Segmentation fault",
79020 + [SIGILL] = "Illegal instruction",
79021 + [SIGABRT] = "Abort",
79022 + [SIGBUS] = "Invalid alignment/Bus error"
79023 +};
79024 +
79025 +void
79026 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
79027 +{
79028 +#ifdef CONFIG_GRKERNSEC_SIGNAL
79029 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
79030 + (sig == SIGABRT) || (sig == SIGBUS))) {
79031 + if (task_pid_nr(t) == task_pid_nr(current)) {
79032 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
79033 + } else {
79034 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
79035 + }
79036 + }
79037 +#endif
79038 + return;
79039 +}
79040 +
79041 +int
79042 +gr_handle_signal(const struct task_struct *p, const int sig)
79043 +{
79044 +#ifdef CONFIG_GRKERNSEC
79045 + /* ignore the 0 signal for protected task checks */
79046 + if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
79047 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
79048 + return -EPERM;
79049 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
79050 + return -EPERM;
79051 + }
79052 +#endif
79053 + return 0;
79054 +}
79055 +
79056 +#ifdef CONFIG_GRKERNSEC
79057 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
79058 +
79059 +int gr_fake_force_sig(int sig, struct task_struct *t)
79060 +{
79061 + unsigned long int flags;
79062 + int ret, blocked, ignored;
79063 + struct k_sigaction *action;
79064 +
79065 + spin_lock_irqsave(&t->sighand->siglock, flags);
79066 + action = &t->sighand->action[sig-1];
79067 + ignored = action->sa.sa_handler == SIG_IGN;
79068 + blocked = sigismember(&t->blocked, sig);
79069 + if (blocked || ignored) {
79070 + action->sa.sa_handler = SIG_DFL;
79071 + if (blocked) {
79072 + sigdelset(&t->blocked, sig);
79073 + recalc_sigpending_and_wake(t);
79074 + }
79075 + }
79076 + if (action->sa.sa_handler == SIG_DFL)
79077 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
79078 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
79079 +
79080 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
79081 +
79082 + return ret;
79083 +}
79084 +#endif
79085 +
79086 +#define GR_USER_BAN_TIME (15 * 60)
79087 +#define GR_DAEMON_BRUTE_TIME (30 * 60)
79088 +
79089 +void gr_handle_brute_attach(int dumpable)
79090 +{
79091 +#ifdef CONFIG_GRKERNSEC_BRUTE
79092 + struct task_struct *p = current;
79093 + kuid_t uid = GLOBAL_ROOT_UID;
79094 + int daemon = 0;
79095 +
79096 + if (!grsec_enable_brute)
79097 + return;
79098 +
79099 + rcu_read_lock();
79100 + read_lock(&tasklist_lock);
79101 + read_lock(&grsec_exec_file_lock);
79102 + if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
79103 + p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
79104 + p->real_parent->brute = 1;
79105 + daemon = 1;
79106 + } else {
79107 + const struct cred *cred = __task_cred(p), *cred2;
79108 + struct task_struct *tsk, *tsk2;
79109 +
79110 + if (dumpable != SUID_DUMP_USER && gr_is_global_nonroot(cred->uid)) {
79111 + struct user_struct *user;
79112 +
79113 + uid = cred->uid;
79114 +
79115 + /* this is put upon execution past expiration */
79116 + user = find_user(uid);
79117 + if (user == NULL)
79118 + goto unlock;
79119 + user->suid_banned = 1;
79120 + user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
79121 + if (user->suid_ban_expires == ~0UL)
79122 + user->suid_ban_expires--;
79123 +
79124 + /* only kill other threads of the same binary, from the same user */
79125 + do_each_thread(tsk2, tsk) {
79126 + cred2 = __task_cred(tsk);
79127 + if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
79128 + gr_fake_force_sig(SIGKILL, tsk);
79129 + } while_each_thread(tsk2, tsk);
79130 + }
79131 + }
79132 +unlock:
79133 + read_unlock(&grsec_exec_file_lock);
79134 + read_unlock(&tasklist_lock);
79135 + rcu_read_unlock();
79136 +
79137 + if (gr_is_global_nonroot(uid))
79138 + 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);
79139 + else if (daemon)
79140 + gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
79141 +
79142 +#endif
79143 + return;
79144 +}
79145 +
79146 +void gr_handle_brute_check(void)
79147 +{
79148 +#ifdef CONFIG_GRKERNSEC_BRUTE
79149 + struct task_struct *p = current;
79150 +
79151 + if (unlikely(p->brute)) {
79152 + if (!grsec_enable_brute)
79153 + p->brute = 0;
79154 + else if (time_before(get_seconds(), p->brute_expires))
79155 + msleep(30 * 1000);
79156 + }
79157 +#endif
79158 + return;
79159 +}
79160 +
79161 +void gr_handle_kernel_exploit(void)
79162 +{
79163 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
79164 + const struct cred *cred;
79165 + struct task_struct *tsk, *tsk2;
79166 + struct user_struct *user;
79167 + kuid_t uid;
79168 +
79169 + if (in_irq() || in_serving_softirq() || in_nmi())
79170 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
79171 +
79172 + uid = current_uid();
79173 +
79174 + if (gr_is_global_root(uid))
79175 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
79176 + else {
79177 + /* kill all the processes of this user, hold a reference
79178 + to their creds struct, and prevent them from creating
79179 + another process until system reset
79180 + */
79181 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
79182 + GR_GLOBAL_UID(uid));
79183 + /* we intentionally leak this ref */
79184 + user = get_uid(current->cred->user);
79185 + if (user)
79186 + user->kernel_banned = 1;
79187 +
79188 + /* kill all processes of this user */
79189 + read_lock(&tasklist_lock);
79190 + do_each_thread(tsk2, tsk) {
79191 + cred = __task_cred(tsk);
79192 + if (uid_eq(cred->uid, uid))
79193 + gr_fake_force_sig(SIGKILL, tsk);
79194 + } while_each_thread(tsk2, tsk);
79195 + read_unlock(&tasklist_lock);
79196 + }
79197 +#endif
79198 +}
79199 +
79200 +#ifdef CONFIG_GRKERNSEC_BRUTE
79201 +static bool suid_ban_expired(struct user_struct *user)
79202 +{
79203 + if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
79204 + user->suid_banned = 0;
79205 + user->suid_ban_expires = 0;
79206 + free_uid(user);
79207 + return true;
79208 + }
79209 +
79210 + return false;
79211 +}
79212 +#endif
79213 +
79214 +int gr_process_kernel_exec_ban(void)
79215 +{
79216 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
79217 + if (unlikely(current->cred->user->kernel_banned))
79218 + return -EPERM;
79219 +#endif
79220 + return 0;
79221 +}
79222 +
79223 +int gr_process_kernel_setuid_ban(struct user_struct *user)
79224 +{
79225 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
79226 + if (unlikely(user->kernel_banned))
79227 + gr_fake_force_sig(SIGKILL, current);
79228 +#endif
79229 + return 0;
79230 +}
79231 +
79232 +int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
79233 +{
79234 +#ifdef CONFIG_GRKERNSEC_BRUTE
79235 + struct user_struct *user = current->cred->user;
79236 + if (unlikely(user->suid_banned)) {
79237 + if (suid_ban_expired(user))
79238 + return 0;
79239 + /* disallow execution of suid binaries only */
79240 + else if (!uid_eq(bprm->cred->euid, current->cred->uid))
79241 + return -EPERM;
79242 + }
79243 +#endif
79244 + return 0;
79245 +}
79246 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
79247 new file mode 100644
79248 index 0000000..c0aef3a
79249 --- /dev/null
79250 +++ b/grsecurity/grsec_sock.c
79251 @@ -0,0 +1,244 @@
79252 +#include <linux/kernel.h>
79253 +#include <linux/module.h>
79254 +#include <linux/sched.h>
79255 +#include <linux/file.h>
79256 +#include <linux/net.h>
79257 +#include <linux/in.h>
79258 +#include <linux/ip.h>
79259 +#include <net/sock.h>
79260 +#include <net/inet_sock.h>
79261 +#include <linux/grsecurity.h>
79262 +#include <linux/grinternal.h>
79263 +#include <linux/gracl.h>
79264 +
79265 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
79266 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
79267 +
79268 +EXPORT_SYMBOL_GPL(gr_search_udp_recvmsg);
79269 +EXPORT_SYMBOL_GPL(gr_search_udp_sendmsg);
79270 +
79271 +#ifdef CONFIG_UNIX_MODULE
79272 +EXPORT_SYMBOL_GPL(gr_acl_handle_unix);
79273 +EXPORT_SYMBOL_GPL(gr_acl_handle_mknod);
79274 +EXPORT_SYMBOL_GPL(gr_handle_chroot_unix);
79275 +EXPORT_SYMBOL_GPL(gr_handle_create);
79276 +#endif
79277 +
79278 +#ifdef CONFIG_GRKERNSEC
79279 +#define gr_conn_table_size 32749
79280 +struct conn_table_entry {
79281 + struct conn_table_entry *next;
79282 + struct signal_struct *sig;
79283 +};
79284 +
79285 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
79286 +DEFINE_SPINLOCK(gr_conn_table_lock);
79287 +
79288 +extern const char * gr_socktype_to_name(unsigned char type);
79289 +extern const char * gr_proto_to_name(unsigned char proto);
79290 +extern const char * gr_sockfamily_to_name(unsigned char family);
79291 +
79292 +static __inline__ int
79293 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
79294 +{
79295 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
79296 +}
79297 +
79298 +static __inline__ int
79299 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
79300 + __u16 sport, __u16 dport)
79301 +{
79302 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
79303 + sig->gr_sport == sport && sig->gr_dport == dport))
79304 + return 1;
79305 + else
79306 + return 0;
79307 +}
79308 +
79309 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
79310 +{
79311 + struct conn_table_entry **match;
79312 + unsigned int index;
79313 +
79314 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
79315 + sig->gr_sport, sig->gr_dport,
79316 + gr_conn_table_size);
79317 +
79318 + newent->sig = sig;
79319 +
79320 + match = &gr_conn_table[index];
79321 + newent->next = *match;
79322 + *match = newent;
79323 +
79324 + return;
79325 +}
79326 +
79327 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
79328 +{
79329 + struct conn_table_entry *match, *last = NULL;
79330 + unsigned int index;
79331 +
79332 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
79333 + sig->gr_sport, sig->gr_dport,
79334 + gr_conn_table_size);
79335 +
79336 + match = gr_conn_table[index];
79337 + while (match && !conn_match(match->sig,
79338 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
79339 + sig->gr_dport)) {
79340 + last = match;
79341 + match = match->next;
79342 + }
79343 +
79344 + if (match) {
79345 + if (last)
79346 + last->next = match->next;
79347 + else
79348 + gr_conn_table[index] = NULL;
79349 + kfree(match);
79350 + }
79351 +
79352 + return;
79353 +}
79354 +
79355 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
79356 + __u16 sport, __u16 dport)
79357 +{
79358 + struct conn_table_entry *match;
79359 + unsigned int index;
79360 +
79361 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
79362 +
79363 + match = gr_conn_table[index];
79364 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
79365 + match = match->next;
79366 +
79367 + if (match)
79368 + return match->sig;
79369 + else
79370 + return NULL;
79371 +}
79372 +
79373 +#endif
79374 +
79375 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
79376 +{
79377 +#ifdef CONFIG_GRKERNSEC
79378 + struct signal_struct *sig = task->signal;
79379 + struct conn_table_entry *newent;
79380 +
79381 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
79382 + if (newent == NULL)
79383 + return;
79384 + /* no bh lock needed since we are called with bh disabled */
79385 + spin_lock(&gr_conn_table_lock);
79386 + gr_del_task_from_ip_table_nolock(sig);
79387 + sig->gr_saddr = inet->inet_rcv_saddr;
79388 + sig->gr_daddr = inet->inet_daddr;
79389 + sig->gr_sport = inet->inet_sport;
79390 + sig->gr_dport = inet->inet_dport;
79391 + gr_add_to_task_ip_table_nolock(sig, newent);
79392 + spin_unlock(&gr_conn_table_lock);
79393 +#endif
79394 + return;
79395 +}
79396 +
79397 +void gr_del_task_from_ip_table(struct task_struct *task)
79398 +{
79399 +#ifdef CONFIG_GRKERNSEC
79400 + spin_lock_bh(&gr_conn_table_lock);
79401 + gr_del_task_from_ip_table_nolock(task->signal);
79402 + spin_unlock_bh(&gr_conn_table_lock);
79403 +#endif
79404 + return;
79405 +}
79406 +
79407 +void
79408 +gr_attach_curr_ip(const struct sock *sk)
79409 +{
79410 +#ifdef CONFIG_GRKERNSEC
79411 + struct signal_struct *p, *set;
79412 + const struct inet_sock *inet = inet_sk(sk);
79413 +
79414 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
79415 + return;
79416 +
79417 + set = current->signal;
79418 +
79419 + spin_lock_bh(&gr_conn_table_lock);
79420 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
79421 + inet->inet_dport, inet->inet_sport);
79422 + if (unlikely(p != NULL)) {
79423 + set->curr_ip = p->curr_ip;
79424 + set->used_accept = 1;
79425 + gr_del_task_from_ip_table_nolock(p);
79426 + spin_unlock_bh(&gr_conn_table_lock);
79427 + return;
79428 + }
79429 + spin_unlock_bh(&gr_conn_table_lock);
79430 +
79431 + set->curr_ip = inet->inet_daddr;
79432 + set->used_accept = 1;
79433 +#endif
79434 + return;
79435 +}
79436 +
79437 +int
79438 +gr_handle_sock_all(const int family, const int type, const int protocol)
79439 +{
79440 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
79441 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
79442 + (family != AF_UNIX)) {
79443 + if (family == AF_INET)
79444 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
79445 + else
79446 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
79447 + return -EACCES;
79448 + }
79449 +#endif
79450 + return 0;
79451 +}
79452 +
79453 +int
79454 +gr_handle_sock_server(const struct sockaddr *sck)
79455 +{
79456 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
79457 + if (grsec_enable_socket_server &&
79458 + in_group_p(grsec_socket_server_gid) &&
79459 + sck && (sck->sa_family != AF_UNIX) &&
79460 + (sck->sa_family != AF_LOCAL)) {
79461 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
79462 + return -EACCES;
79463 + }
79464 +#endif
79465 + return 0;
79466 +}
79467 +
79468 +int
79469 +gr_handle_sock_server_other(const struct sock *sck)
79470 +{
79471 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
79472 + if (grsec_enable_socket_server &&
79473 + in_group_p(grsec_socket_server_gid) &&
79474 + sck && (sck->sk_family != AF_UNIX) &&
79475 + (sck->sk_family != AF_LOCAL)) {
79476 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
79477 + return -EACCES;
79478 + }
79479 +#endif
79480 + return 0;
79481 +}
79482 +
79483 +int
79484 +gr_handle_sock_client(const struct sockaddr *sck)
79485 +{
79486 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
79487 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
79488 + sck && (sck->sa_family != AF_UNIX) &&
79489 + (sck->sa_family != AF_LOCAL)) {
79490 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
79491 + return -EACCES;
79492 + }
79493 +#endif
79494 + return 0;
79495 +}
79496 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
79497 new file mode 100644
79498 index 0000000..8159888
79499 --- /dev/null
79500 +++ b/grsecurity/grsec_sysctl.c
79501 @@ -0,0 +1,479 @@
79502 +#include <linux/kernel.h>
79503 +#include <linux/sched.h>
79504 +#include <linux/sysctl.h>
79505 +#include <linux/grsecurity.h>
79506 +#include <linux/grinternal.h>
79507 +
79508 +int
79509 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
79510 +{
79511 +#ifdef CONFIG_GRKERNSEC_SYSCTL
79512 + if (dirname == NULL || name == NULL)
79513 + return 0;
79514 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
79515 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
79516 + return -EACCES;
79517 + }
79518 +#endif
79519 + return 0;
79520 +}
79521 +
79522 +#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
79523 +static int __maybe_unused __read_only one = 1;
79524 +#endif
79525 +
79526 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
79527 + defined(CONFIG_GRKERNSEC_DENYUSB)
79528 +struct ctl_table grsecurity_table[] = {
79529 +#ifdef CONFIG_GRKERNSEC_SYSCTL
79530 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
79531 +#ifdef CONFIG_GRKERNSEC_IO
79532 + {
79533 + .procname = "disable_priv_io",
79534 + .data = &grsec_disable_privio,
79535 + .maxlen = sizeof(int),
79536 + .mode = 0600,
79537 + .proc_handler = &proc_dointvec,
79538 + },
79539 +#endif
79540 +#endif
79541 +#ifdef CONFIG_GRKERNSEC_LINK
79542 + {
79543 + .procname = "linking_restrictions",
79544 + .data = &grsec_enable_link,
79545 + .maxlen = sizeof(int),
79546 + .mode = 0600,
79547 + .proc_handler = &proc_dointvec,
79548 + },
79549 +#endif
79550 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
79551 + {
79552 + .procname = "enforce_symlinksifowner",
79553 + .data = &grsec_enable_symlinkown,
79554 + .maxlen = sizeof(int),
79555 + .mode = 0600,
79556 + .proc_handler = &proc_dointvec,
79557 + },
79558 + {
79559 + .procname = "symlinkown_gid",
79560 + .data = &grsec_symlinkown_gid,
79561 + .maxlen = sizeof(int),
79562 + .mode = 0600,
79563 + .proc_handler = &proc_dointvec,
79564 + },
79565 +#endif
79566 +#ifdef CONFIG_GRKERNSEC_BRUTE
79567 + {
79568 + .procname = "deter_bruteforce",
79569 + .data = &grsec_enable_brute,
79570 + .maxlen = sizeof(int),
79571 + .mode = 0600,
79572 + .proc_handler = &proc_dointvec,
79573 + },
79574 +#endif
79575 +#ifdef CONFIG_GRKERNSEC_FIFO
79576 + {
79577 + .procname = "fifo_restrictions",
79578 + .data = &grsec_enable_fifo,
79579 + .maxlen = sizeof(int),
79580 + .mode = 0600,
79581 + .proc_handler = &proc_dointvec,
79582 + },
79583 +#endif
79584 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
79585 + {
79586 + .procname = "ptrace_readexec",
79587 + .data = &grsec_enable_ptrace_readexec,
79588 + .maxlen = sizeof(int),
79589 + .mode = 0600,
79590 + .proc_handler = &proc_dointvec,
79591 + },
79592 +#endif
79593 +#ifdef CONFIG_GRKERNSEC_SETXID
79594 + {
79595 + .procname = "consistent_setxid",
79596 + .data = &grsec_enable_setxid,
79597 + .maxlen = sizeof(int),
79598 + .mode = 0600,
79599 + .proc_handler = &proc_dointvec,
79600 + },
79601 +#endif
79602 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79603 + {
79604 + .procname = "ip_blackhole",
79605 + .data = &grsec_enable_blackhole,
79606 + .maxlen = sizeof(int),
79607 + .mode = 0600,
79608 + .proc_handler = &proc_dointvec,
79609 + },
79610 + {
79611 + .procname = "lastack_retries",
79612 + .data = &grsec_lastack_retries,
79613 + .maxlen = sizeof(int),
79614 + .mode = 0600,
79615 + .proc_handler = &proc_dointvec,
79616 + },
79617 +#endif
79618 +#ifdef CONFIG_GRKERNSEC_EXECLOG
79619 + {
79620 + .procname = "exec_logging",
79621 + .data = &grsec_enable_execlog,
79622 + .maxlen = sizeof(int),
79623 + .mode = 0600,
79624 + .proc_handler = &proc_dointvec,
79625 + },
79626 +#endif
79627 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
79628 + {
79629 + .procname = "rwxmap_logging",
79630 + .data = &grsec_enable_log_rwxmaps,
79631 + .maxlen = sizeof(int),
79632 + .mode = 0600,
79633 + .proc_handler = &proc_dointvec,
79634 + },
79635 +#endif
79636 +#ifdef CONFIG_GRKERNSEC_SIGNAL
79637 + {
79638 + .procname = "signal_logging",
79639 + .data = &grsec_enable_signal,
79640 + .maxlen = sizeof(int),
79641 + .mode = 0600,
79642 + .proc_handler = &proc_dointvec,
79643 + },
79644 +#endif
79645 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
79646 + {
79647 + .procname = "forkfail_logging",
79648 + .data = &grsec_enable_forkfail,
79649 + .maxlen = sizeof(int),
79650 + .mode = 0600,
79651 + .proc_handler = &proc_dointvec,
79652 + },
79653 +#endif
79654 +#ifdef CONFIG_GRKERNSEC_TIME
79655 + {
79656 + .procname = "timechange_logging",
79657 + .data = &grsec_enable_time,
79658 + .maxlen = sizeof(int),
79659 + .mode = 0600,
79660 + .proc_handler = &proc_dointvec,
79661 + },
79662 +#endif
79663 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
79664 + {
79665 + .procname = "chroot_deny_shmat",
79666 + .data = &grsec_enable_chroot_shmat,
79667 + .maxlen = sizeof(int),
79668 + .mode = 0600,
79669 + .proc_handler = &proc_dointvec,
79670 + },
79671 +#endif
79672 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
79673 + {
79674 + .procname = "chroot_deny_unix",
79675 + .data = &grsec_enable_chroot_unix,
79676 + .maxlen = sizeof(int),
79677 + .mode = 0600,
79678 + .proc_handler = &proc_dointvec,
79679 + },
79680 +#endif
79681 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
79682 + {
79683 + .procname = "chroot_deny_mount",
79684 + .data = &grsec_enable_chroot_mount,
79685 + .maxlen = sizeof(int),
79686 + .mode = 0600,
79687 + .proc_handler = &proc_dointvec,
79688 + },
79689 +#endif
79690 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
79691 + {
79692 + .procname = "chroot_deny_fchdir",
79693 + .data = &grsec_enable_chroot_fchdir,
79694 + .maxlen = sizeof(int),
79695 + .mode = 0600,
79696 + .proc_handler = &proc_dointvec,
79697 + },
79698 +#endif
79699 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
79700 + {
79701 + .procname = "chroot_deny_chroot",
79702 + .data = &grsec_enable_chroot_double,
79703 + .maxlen = sizeof(int),
79704 + .mode = 0600,
79705 + .proc_handler = &proc_dointvec,
79706 + },
79707 +#endif
79708 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
79709 + {
79710 + .procname = "chroot_deny_pivot",
79711 + .data = &grsec_enable_chroot_pivot,
79712 + .maxlen = sizeof(int),
79713 + .mode = 0600,
79714 + .proc_handler = &proc_dointvec,
79715 + },
79716 +#endif
79717 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
79718 + {
79719 + .procname = "chroot_enforce_chdir",
79720 + .data = &grsec_enable_chroot_chdir,
79721 + .maxlen = sizeof(int),
79722 + .mode = 0600,
79723 + .proc_handler = &proc_dointvec,
79724 + },
79725 +#endif
79726 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
79727 + {
79728 + .procname = "chroot_deny_chmod",
79729 + .data = &grsec_enable_chroot_chmod,
79730 + .maxlen = sizeof(int),
79731 + .mode = 0600,
79732 + .proc_handler = &proc_dointvec,
79733 + },
79734 +#endif
79735 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
79736 + {
79737 + .procname = "chroot_deny_mknod",
79738 + .data = &grsec_enable_chroot_mknod,
79739 + .maxlen = sizeof(int),
79740 + .mode = 0600,
79741 + .proc_handler = &proc_dointvec,
79742 + },
79743 +#endif
79744 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
79745 + {
79746 + .procname = "chroot_restrict_nice",
79747 + .data = &grsec_enable_chroot_nice,
79748 + .maxlen = sizeof(int),
79749 + .mode = 0600,
79750 + .proc_handler = &proc_dointvec,
79751 + },
79752 +#endif
79753 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
79754 + {
79755 + .procname = "chroot_execlog",
79756 + .data = &grsec_enable_chroot_execlog,
79757 + .maxlen = sizeof(int),
79758 + .mode = 0600,
79759 + .proc_handler = &proc_dointvec,
79760 + },
79761 +#endif
79762 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
79763 + {
79764 + .procname = "chroot_caps",
79765 + .data = &grsec_enable_chroot_caps,
79766 + .maxlen = sizeof(int),
79767 + .mode = 0600,
79768 + .proc_handler = &proc_dointvec,
79769 + },
79770 +#endif
79771 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
79772 + {
79773 + .procname = "chroot_deny_sysctl",
79774 + .data = &grsec_enable_chroot_sysctl,
79775 + .maxlen = sizeof(int),
79776 + .mode = 0600,
79777 + .proc_handler = &proc_dointvec,
79778 + },
79779 +#endif
79780 +#ifdef CONFIG_GRKERNSEC_TPE
79781 + {
79782 + .procname = "tpe",
79783 + .data = &grsec_enable_tpe,
79784 + .maxlen = sizeof(int),
79785 + .mode = 0600,
79786 + .proc_handler = &proc_dointvec,
79787 + },
79788 + {
79789 + .procname = "tpe_gid",
79790 + .data = &grsec_tpe_gid,
79791 + .maxlen = sizeof(int),
79792 + .mode = 0600,
79793 + .proc_handler = &proc_dointvec,
79794 + },
79795 +#endif
79796 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
79797 + {
79798 + .procname = "tpe_invert",
79799 + .data = &grsec_enable_tpe_invert,
79800 + .maxlen = sizeof(int),
79801 + .mode = 0600,
79802 + .proc_handler = &proc_dointvec,
79803 + },
79804 +#endif
79805 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
79806 + {
79807 + .procname = "tpe_restrict_all",
79808 + .data = &grsec_enable_tpe_all,
79809 + .maxlen = sizeof(int),
79810 + .mode = 0600,
79811 + .proc_handler = &proc_dointvec,
79812 + },
79813 +#endif
79814 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
79815 + {
79816 + .procname = "socket_all",
79817 + .data = &grsec_enable_socket_all,
79818 + .maxlen = sizeof(int),
79819 + .mode = 0600,
79820 + .proc_handler = &proc_dointvec,
79821 + },
79822 + {
79823 + .procname = "socket_all_gid",
79824 + .data = &grsec_socket_all_gid,
79825 + .maxlen = sizeof(int),
79826 + .mode = 0600,
79827 + .proc_handler = &proc_dointvec,
79828 + },
79829 +#endif
79830 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
79831 + {
79832 + .procname = "socket_client",
79833 + .data = &grsec_enable_socket_client,
79834 + .maxlen = sizeof(int),
79835 + .mode = 0600,
79836 + .proc_handler = &proc_dointvec,
79837 + },
79838 + {
79839 + .procname = "socket_client_gid",
79840 + .data = &grsec_socket_client_gid,
79841 + .maxlen = sizeof(int),
79842 + .mode = 0600,
79843 + .proc_handler = &proc_dointvec,
79844 + },
79845 +#endif
79846 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
79847 + {
79848 + .procname = "socket_server",
79849 + .data = &grsec_enable_socket_server,
79850 + .maxlen = sizeof(int),
79851 + .mode = 0600,
79852 + .proc_handler = &proc_dointvec,
79853 + },
79854 + {
79855 + .procname = "socket_server_gid",
79856 + .data = &grsec_socket_server_gid,
79857 + .maxlen = sizeof(int),
79858 + .mode = 0600,
79859 + .proc_handler = &proc_dointvec,
79860 + },
79861 +#endif
79862 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
79863 + {
79864 + .procname = "audit_group",
79865 + .data = &grsec_enable_group,
79866 + .maxlen = sizeof(int),
79867 + .mode = 0600,
79868 + .proc_handler = &proc_dointvec,
79869 + },
79870 + {
79871 + .procname = "audit_gid",
79872 + .data = &grsec_audit_gid,
79873 + .maxlen = sizeof(int),
79874 + .mode = 0600,
79875 + .proc_handler = &proc_dointvec,
79876 + },
79877 +#endif
79878 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
79879 + {
79880 + .procname = "audit_chdir",
79881 + .data = &grsec_enable_chdir,
79882 + .maxlen = sizeof(int),
79883 + .mode = 0600,
79884 + .proc_handler = &proc_dointvec,
79885 + },
79886 +#endif
79887 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
79888 + {
79889 + .procname = "audit_mount",
79890 + .data = &grsec_enable_mount,
79891 + .maxlen = sizeof(int),
79892 + .mode = 0600,
79893 + .proc_handler = &proc_dointvec,
79894 + },
79895 +#endif
79896 +#ifdef CONFIG_GRKERNSEC_DMESG
79897 + {
79898 + .procname = "dmesg",
79899 + .data = &grsec_enable_dmesg,
79900 + .maxlen = sizeof(int),
79901 + .mode = 0600,
79902 + .proc_handler = &proc_dointvec,
79903 + },
79904 +#endif
79905 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
79906 + {
79907 + .procname = "chroot_findtask",
79908 + .data = &grsec_enable_chroot_findtask,
79909 + .maxlen = sizeof(int),
79910 + .mode = 0600,
79911 + .proc_handler = &proc_dointvec,
79912 + },
79913 +#endif
79914 +#ifdef CONFIG_GRKERNSEC_RESLOG
79915 + {
79916 + .procname = "resource_logging",
79917 + .data = &grsec_resource_logging,
79918 + .maxlen = sizeof(int),
79919 + .mode = 0600,
79920 + .proc_handler = &proc_dointvec,
79921 + },
79922 +#endif
79923 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
79924 + {
79925 + .procname = "audit_ptrace",
79926 + .data = &grsec_enable_audit_ptrace,
79927 + .maxlen = sizeof(int),
79928 + .mode = 0600,
79929 + .proc_handler = &proc_dointvec,
79930 + },
79931 +#endif
79932 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
79933 + {
79934 + .procname = "harden_ptrace",
79935 + .data = &grsec_enable_harden_ptrace,
79936 + .maxlen = sizeof(int),
79937 + .mode = 0600,
79938 + .proc_handler = &proc_dointvec,
79939 + },
79940 +#endif
79941 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
79942 + {
79943 + .procname = "harden_ipc",
79944 + .data = &grsec_enable_harden_ipc,
79945 + .maxlen = sizeof(int),
79946 + .mode = 0600,
79947 + .proc_handler = &proc_dointvec,
79948 + },
79949 +#endif
79950 + {
79951 + .procname = "grsec_lock",
79952 + .data = &grsec_lock,
79953 + .maxlen = sizeof(int),
79954 + .mode = 0600,
79955 + .proc_handler = &proc_dointvec,
79956 + },
79957 +#endif
79958 +#ifdef CONFIG_GRKERNSEC_ROFS
79959 + {
79960 + .procname = "romount_protect",
79961 + .data = &grsec_enable_rofs,
79962 + .maxlen = sizeof(int),
79963 + .mode = 0600,
79964 + .proc_handler = &proc_dointvec_minmax,
79965 + .extra1 = &one,
79966 + .extra2 = &one,
79967 + },
79968 +#endif
79969 +#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
79970 + {
79971 + .procname = "deny_new_usb",
79972 + .data = &grsec_deny_new_usb,
79973 + .maxlen = sizeof(int),
79974 + .mode = 0600,
79975 + .proc_handler = &proc_dointvec,
79976 + },
79977 +#endif
79978 + { }
79979 +};
79980 +#endif
79981 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
79982 new file mode 100644
79983 index 0000000..61b514e
79984 --- /dev/null
79985 +++ b/grsecurity/grsec_time.c
79986 @@ -0,0 +1,16 @@
79987 +#include <linux/kernel.h>
79988 +#include <linux/sched.h>
79989 +#include <linux/grinternal.h>
79990 +#include <linux/module.h>
79991 +
79992 +void
79993 +gr_log_timechange(void)
79994 +{
79995 +#ifdef CONFIG_GRKERNSEC_TIME
79996 + if (grsec_enable_time)
79997 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
79998 +#endif
79999 + return;
80000 +}
80001 +
80002 +EXPORT_SYMBOL_GPL(gr_log_timechange);
80003 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
80004 new file mode 100644
80005 index 0000000..d1953de
80006 --- /dev/null
80007 +++ b/grsecurity/grsec_tpe.c
80008 @@ -0,0 +1,78 @@
80009 +#include <linux/kernel.h>
80010 +#include <linux/sched.h>
80011 +#include <linux/file.h>
80012 +#include <linux/fs.h>
80013 +#include <linux/grinternal.h>
80014 +
80015 +extern int gr_acl_tpe_check(void);
80016 +
80017 +int
80018 +gr_tpe_allow(const struct file *file)
80019 +{
80020 +#ifdef CONFIG_GRKERNSEC
80021 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
80022 + struct inode *file_inode = file->f_path.dentry->d_inode;
80023 + const struct cred *cred = current_cred();
80024 + char *msg = NULL;
80025 + char *msg2 = NULL;
80026 +
80027 + // never restrict root
80028 + if (gr_is_global_root(cred->uid))
80029 + return 1;
80030 +
80031 + if (grsec_enable_tpe) {
80032 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
80033 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
80034 + msg = "not being in trusted group";
80035 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
80036 + msg = "being in untrusted group";
80037 +#else
80038 + if (in_group_p(grsec_tpe_gid))
80039 + msg = "being in untrusted group";
80040 +#endif
80041 + }
80042 + if (!msg && gr_acl_tpe_check())
80043 + msg = "being in untrusted role";
80044 +
80045 + // not in any affected group/role
80046 + if (!msg)
80047 + goto next_check;
80048 +
80049 + if (gr_is_global_nonroot(inode->i_uid))
80050 + msg2 = "file in non-root-owned directory";
80051 + else if (inode->i_mode & S_IWOTH)
80052 + msg2 = "file in world-writable directory";
80053 + else if (inode->i_mode & S_IWGRP)
80054 + msg2 = "file in group-writable directory";
80055 + else if (file_inode->i_mode & S_IWOTH)
80056 + msg2 = "file is world-writable";
80057 +
80058 + if (msg && msg2) {
80059 + char fullmsg[70] = {0};
80060 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
80061 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
80062 + return 0;
80063 + }
80064 + msg = NULL;
80065 +next_check:
80066 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
80067 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
80068 + return 1;
80069 +
80070 + if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
80071 + msg = "directory not owned by user";
80072 + else if (inode->i_mode & S_IWOTH)
80073 + msg = "file in world-writable directory";
80074 + else if (inode->i_mode & S_IWGRP)
80075 + msg = "file in group-writable directory";
80076 + else if (file_inode->i_mode & S_IWOTH)
80077 + msg = "file is world-writable";
80078 +
80079 + if (msg) {
80080 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
80081 + return 0;
80082 + }
80083 +#endif
80084 +#endif
80085 + return 1;
80086 +}
80087 diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
80088 new file mode 100644
80089 index 0000000..ae02d8e
80090 --- /dev/null
80091 +++ b/grsecurity/grsec_usb.c
80092 @@ -0,0 +1,15 @@
80093 +#include <linux/kernel.h>
80094 +#include <linux/grinternal.h>
80095 +#include <linux/module.h>
80096 +
80097 +int gr_handle_new_usb(void)
80098 +{
80099 +#ifdef CONFIG_GRKERNSEC_DENYUSB
80100 + if (grsec_deny_new_usb) {
80101 + printk(KERN_ALERT "grsec: denied insert of new USB device\n");
80102 + return 1;
80103 + }
80104 +#endif
80105 + return 0;
80106 +}
80107 +EXPORT_SYMBOL_GPL(gr_handle_new_usb);
80108 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
80109 new file mode 100644
80110 index 0000000..158b330
80111 --- /dev/null
80112 +++ b/grsecurity/grsum.c
80113 @@ -0,0 +1,64 @@
80114 +#include <linux/err.h>
80115 +#include <linux/kernel.h>
80116 +#include <linux/sched.h>
80117 +#include <linux/mm.h>
80118 +#include <linux/scatterlist.h>
80119 +#include <linux/crypto.h>
80120 +#include <linux/gracl.h>
80121 +
80122 +
80123 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
80124 +#error "crypto and sha256 must be built into the kernel"
80125 +#endif
80126 +
80127 +int
80128 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
80129 +{
80130 + struct crypto_hash *tfm;
80131 + struct hash_desc desc;
80132 + struct scatterlist sg[2];
80133 + unsigned char temp_sum[GR_SHA_LEN] __attribute__((aligned(__alignof__(unsigned long))));
80134 + unsigned long *tmpsumptr = (unsigned long *)temp_sum;
80135 + unsigned long *sumptr = (unsigned long *)sum;
80136 + int cryptres;
80137 + int retval = 1;
80138 + volatile int mismatched = 0;
80139 + volatile int dummy = 0;
80140 + unsigned int i;
80141 +
80142 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
80143 + if (IS_ERR(tfm)) {
80144 + /* should never happen, since sha256 should be built in */
80145 + memset(entry->pw, 0, GR_PW_LEN);
80146 + return 1;
80147 + }
80148 +
80149 + sg_init_table(sg, 2);
80150 + sg_set_buf(&sg[0], salt, GR_SALT_LEN);
80151 + sg_set_buf(&sg[1], entry->pw, strlen(entry->pw));
80152 +
80153 + desc.tfm = tfm;
80154 + desc.flags = 0;
80155 +
80156 + cryptres = crypto_hash_digest(&desc, sg, GR_SALT_LEN + strlen(entry->pw),
80157 + temp_sum);
80158 +
80159 + memset(entry->pw, 0, GR_PW_LEN);
80160 +
80161 + if (cryptres)
80162 + goto out;
80163 +
80164 + for (i = 0; i < GR_SHA_LEN/sizeof(tmpsumptr[0]); i++)
80165 + if (sumptr[i] != tmpsumptr[i])
80166 + mismatched = 1;
80167 + else
80168 + dummy = 1; // waste a cycle
80169 +
80170 + if (!mismatched)
80171 + retval = dummy - 1;
80172 +
80173 +out:
80174 + crypto_free_hash(tfm);
80175 +
80176 + return retval;
80177 +}
80178 diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
80179 index 77ff547..181834f 100644
80180 --- a/include/asm-generic/4level-fixup.h
80181 +++ b/include/asm-generic/4level-fixup.h
80182 @@ -13,8 +13,10 @@
80183 #define pmd_alloc(mm, pud, address) \
80184 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
80185 NULL: pmd_offset(pud, address))
80186 +#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
80187
80188 #define pud_alloc(mm, pgd, address) (pgd)
80189 +#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
80190 #define pud_offset(pgd, start) (pgd)
80191 #define pud_none(pud) 0
80192 #define pud_bad(pud) 0
80193 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
80194 index b7babf0..97f4c4f 100644
80195 --- a/include/asm-generic/atomic-long.h
80196 +++ b/include/asm-generic/atomic-long.h
80197 @@ -22,6 +22,12 @@
80198
80199 typedef atomic64_t atomic_long_t;
80200
80201 +#ifdef CONFIG_PAX_REFCOUNT
80202 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
80203 +#else
80204 +typedef atomic64_t atomic_long_unchecked_t;
80205 +#endif
80206 +
80207 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
80208
80209 static inline long atomic_long_read(atomic_long_t *l)
80210 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
80211 return (long)atomic64_read(v);
80212 }
80213
80214 +#ifdef CONFIG_PAX_REFCOUNT
80215 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
80216 +{
80217 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
80218 +
80219 + return (long)atomic64_read_unchecked(v);
80220 +}
80221 +#endif
80222 +
80223 static inline void atomic_long_set(atomic_long_t *l, long i)
80224 {
80225 atomic64_t *v = (atomic64_t *)l;
80226 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
80227 atomic64_set(v, i);
80228 }
80229
80230 +#ifdef CONFIG_PAX_REFCOUNT
80231 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
80232 +{
80233 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
80234 +
80235 + atomic64_set_unchecked(v, i);
80236 +}
80237 +#endif
80238 +
80239 static inline void atomic_long_inc(atomic_long_t *l)
80240 {
80241 atomic64_t *v = (atomic64_t *)l;
80242 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
80243 atomic64_inc(v);
80244 }
80245
80246 +#ifdef CONFIG_PAX_REFCOUNT
80247 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
80248 +{
80249 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
80250 +
80251 + atomic64_inc_unchecked(v);
80252 +}
80253 +#endif
80254 +
80255 static inline void atomic_long_dec(atomic_long_t *l)
80256 {
80257 atomic64_t *v = (atomic64_t *)l;
80258 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
80259 atomic64_dec(v);
80260 }
80261
80262 +#ifdef CONFIG_PAX_REFCOUNT
80263 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
80264 +{
80265 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
80266 +
80267 + atomic64_dec_unchecked(v);
80268 +}
80269 +#endif
80270 +
80271 static inline void atomic_long_add(long i, atomic_long_t *l)
80272 {
80273 atomic64_t *v = (atomic64_t *)l;
80274 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
80275 atomic64_add(i, v);
80276 }
80277
80278 +#ifdef CONFIG_PAX_REFCOUNT
80279 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
80280 +{
80281 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
80282 +
80283 + atomic64_add_unchecked(i, v);
80284 +}
80285 +#endif
80286 +
80287 static inline void atomic_long_sub(long i, atomic_long_t *l)
80288 {
80289 atomic64_t *v = (atomic64_t *)l;
80290 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
80291 atomic64_sub(i, v);
80292 }
80293
80294 +#ifdef CONFIG_PAX_REFCOUNT
80295 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
80296 +{
80297 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
80298 +
80299 + atomic64_sub_unchecked(i, v);
80300 +}
80301 +#endif
80302 +
80303 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
80304 {
80305 atomic64_t *v = (atomic64_t *)l;
80306 @@ -94,13 +154,22 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
80307 return atomic64_add_negative(i, v);
80308 }
80309
80310 -static inline long atomic_long_add_return(long i, atomic_long_t *l)
80311 +static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
80312 {
80313 atomic64_t *v = (atomic64_t *)l;
80314
80315 return (long)atomic64_add_return(i, v);
80316 }
80317
80318 +#ifdef CONFIG_PAX_REFCOUNT
80319 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
80320 +{
80321 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
80322 +
80323 + return (long)atomic64_add_return_unchecked(i, v);
80324 +}
80325 +#endif
80326 +
80327 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
80328 {
80329 atomic64_t *v = (atomic64_t *)l;
80330 @@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
80331 return (long)atomic64_inc_return(v);
80332 }
80333
80334 +#ifdef CONFIG_PAX_REFCOUNT
80335 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
80336 +{
80337 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
80338 +
80339 + return (long)atomic64_inc_return_unchecked(v);
80340 +}
80341 +#endif
80342 +
80343 static inline long atomic_long_dec_return(atomic_long_t *l)
80344 {
80345 atomic64_t *v = (atomic64_t *)l;
80346 @@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
80347
80348 typedef atomic_t atomic_long_t;
80349
80350 +#ifdef CONFIG_PAX_REFCOUNT
80351 +typedef atomic_unchecked_t atomic_long_unchecked_t;
80352 +#else
80353 +typedef atomic_t atomic_long_unchecked_t;
80354 +#endif
80355 +
80356 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
80357 static inline long atomic_long_read(atomic_long_t *l)
80358 {
80359 @@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
80360 return (long)atomic_read(v);
80361 }
80362
80363 +#ifdef CONFIG_PAX_REFCOUNT
80364 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
80365 +{
80366 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
80367 +
80368 + return (long)atomic_read_unchecked(v);
80369 +}
80370 +#endif
80371 +
80372 static inline void atomic_long_set(atomic_long_t *l, long i)
80373 {
80374 atomic_t *v = (atomic_t *)l;
80375 @@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
80376 atomic_set(v, i);
80377 }
80378
80379 +#ifdef CONFIG_PAX_REFCOUNT
80380 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
80381 +{
80382 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
80383 +
80384 + atomic_set_unchecked(v, i);
80385 +}
80386 +#endif
80387 +
80388 static inline void atomic_long_inc(atomic_long_t *l)
80389 {
80390 atomic_t *v = (atomic_t *)l;
80391 @@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
80392 atomic_inc(v);
80393 }
80394
80395 +#ifdef CONFIG_PAX_REFCOUNT
80396 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
80397 +{
80398 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
80399 +
80400 + atomic_inc_unchecked(v);
80401 +}
80402 +#endif
80403 +
80404 static inline void atomic_long_dec(atomic_long_t *l)
80405 {
80406 atomic_t *v = (atomic_t *)l;
80407 @@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
80408 atomic_dec(v);
80409 }
80410
80411 +#ifdef CONFIG_PAX_REFCOUNT
80412 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
80413 +{
80414 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
80415 +
80416 + atomic_dec_unchecked(v);
80417 +}
80418 +#endif
80419 +
80420 static inline void atomic_long_add(long i, atomic_long_t *l)
80421 {
80422 atomic_t *v = (atomic_t *)l;
80423 @@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
80424 atomic_add(i, v);
80425 }
80426
80427 +#ifdef CONFIG_PAX_REFCOUNT
80428 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
80429 +{
80430 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
80431 +
80432 + atomic_add_unchecked(i, v);
80433 +}
80434 +#endif
80435 +
80436 static inline void atomic_long_sub(long i, atomic_long_t *l)
80437 {
80438 atomic_t *v = (atomic_t *)l;
80439 @@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
80440 atomic_sub(i, v);
80441 }
80442
80443 +#ifdef CONFIG_PAX_REFCOUNT
80444 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
80445 +{
80446 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
80447 +
80448 + atomic_sub_unchecked(i, v);
80449 +}
80450 +#endif
80451 +
80452 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
80453 {
80454 atomic_t *v = (atomic_t *)l;
80455 @@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
80456 return (long)atomic_add_return(i, v);
80457 }
80458
80459 +#ifdef CONFIG_PAX_REFCOUNT
80460 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
80461 +{
80462 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
80463 +
80464 + return (long)atomic_add_return_unchecked(i, v);
80465 +}
80466 +
80467 +#endif
80468 +
80469 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
80470 {
80471 atomic_t *v = (atomic_t *)l;
80472 @@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
80473 return (long)atomic_inc_return(v);
80474 }
80475
80476 +#ifdef CONFIG_PAX_REFCOUNT
80477 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
80478 +{
80479 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
80480 +
80481 + return (long)atomic_inc_return_unchecked(v);
80482 +}
80483 +#endif
80484 +
80485 static inline long atomic_long_dec_return(atomic_long_t *l)
80486 {
80487 atomic_t *v = (atomic_t *)l;
80488 @@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
80489
80490 #endif /* BITS_PER_LONG == 64 */
80491
80492 +#ifdef CONFIG_PAX_REFCOUNT
80493 +static inline void pax_refcount_needs_these_functions(void)
80494 +{
80495 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
80496 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
80497 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
80498 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
80499 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
80500 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
80501 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
80502 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
80503 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
80504 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
80505 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
80506 +#ifdef CONFIG_X86
80507 + atomic_clear_mask_unchecked(0, NULL);
80508 + atomic_set_mask_unchecked(0, NULL);
80509 +#endif
80510 +
80511 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
80512 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
80513 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
80514 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
80515 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
80516 + atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
80517 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
80518 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
80519 +}
80520 +#else
80521 +#define atomic_read_unchecked(v) atomic_read(v)
80522 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
80523 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
80524 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
80525 +#define atomic_inc_unchecked(v) atomic_inc(v)
80526 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
80527 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
80528 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
80529 +#define atomic_dec_unchecked(v) atomic_dec(v)
80530 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
80531 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
80532 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
80533 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
80534 +
80535 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
80536 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
80537 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
80538 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
80539 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
80540 +#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
80541 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
80542 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
80543 +#endif
80544 +
80545 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
80546 diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
80547 index 9c79e76..9f7827d 100644
80548 --- a/include/asm-generic/atomic.h
80549 +++ b/include/asm-generic/atomic.h
80550 @@ -154,7 +154,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
80551 * Atomically clears the bits set in @mask from @v
80552 */
80553 #ifndef atomic_clear_mask
80554 -static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
80555 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
80556 {
80557 unsigned long flags;
80558
80559 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
80560 index b18ce4f..2ee2843 100644
80561 --- a/include/asm-generic/atomic64.h
80562 +++ b/include/asm-generic/atomic64.h
80563 @@ -16,6 +16,8 @@ typedef struct {
80564 long long counter;
80565 } atomic64_t;
80566
80567 +typedef atomic64_t atomic64_unchecked_t;
80568 +
80569 #define ATOMIC64_INIT(i) { (i) }
80570
80571 extern long long atomic64_read(const atomic64_t *v);
80572 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
80573 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
80574 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
80575
80576 +#define atomic64_read_unchecked(v) atomic64_read(v)
80577 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
80578 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
80579 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
80580 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
80581 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
80582 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
80583 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
80584 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
80585 +
80586 #endif /* _ASM_GENERIC_ATOMIC64_H */
80587 diff --git a/include/asm-generic/barrier.h b/include/asm-generic/barrier.h
80588 index 1402fa8..025a736 100644
80589 --- a/include/asm-generic/barrier.h
80590 +++ b/include/asm-generic/barrier.h
80591 @@ -74,7 +74,7 @@
80592 do { \
80593 compiletime_assert_atomic_type(*p); \
80594 smp_mb(); \
80595 - ACCESS_ONCE(*p) = (v); \
80596 + ACCESS_ONCE_RW(*p) = (v); \
80597 } while (0)
80598
80599 #define smp_load_acquire(p) \
80600 diff --git a/include/asm-generic/bitops/__fls.h b/include/asm-generic/bitops/__fls.h
80601 index a60a7cc..0fe12f2 100644
80602 --- a/include/asm-generic/bitops/__fls.h
80603 +++ b/include/asm-generic/bitops/__fls.h
80604 @@ -9,7 +9,7 @@
80605 *
80606 * Undefined if no set bit exists, so code should check against 0 first.
80607 */
80608 -static __always_inline unsigned long __fls(unsigned long word)
80609 +static __always_inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
80610 {
80611 int num = BITS_PER_LONG - 1;
80612
80613 diff --git a/include/asm-generic/bitops/fls.h b/include/asm-generic/bitops/fls.h
80614 index 0576d1f..dad6c71 100644
80615 --- a/include/asm-generic/bitops/fls.h
80616 +++ b/include/asm-generic/bitops/fls.h
80617 @@ -9,7 +9,7 @@
80618 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
80619 */
80620
80621 -static __always_inline int fls(int x)
80622 +static __always_inline int __intentional_overflow(-1) fls(int x)
80623 {
80624 int r = 32;
80625
80626 diff --git a/include/asm-generic/bitops/fls64.h b/include/asm-generic/bitops/fls64.h
80627 index b097cf8..3d40e14 100644
80628 --- a/include/asm-generic/bitops/fls64.h
80629 +++ b/include/asm-generic/bitops/fls64.h
80630 @@ -15,7 +15,7 @@
80631 * at position 64.
80632 */
80633 #if BITS_PER_LONG == 32
80634 -static __always_inline int fls64(__u64 x)
80635 +static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
80636 {
80637 __u32 h = x >> 32;
80638 if (h)
80639 @@ -23,7 +23,7 @@ static __always_inline int fls64(__u64 x)
80640 return fls(x);
80641 }
80642 #elif BITS_PER_LONG == 64
80643 -static __always_inline int fls64(__u64 x)
80644 +static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
80645 {
80646 if (x == 0)
80647 return 0;
80648 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
80649 index 1bfcfe5..e04c5c9 100644
80650 --- a/include/asm-generic/cache.h
80651 +++ b/include/asm-generic/cache.h
80652 @@ -6,7 +6,7 @@
80653 * cache lines need to provide their own cache.h.
80654 */
80655
80656 -#define L1_CACHE_SHIFT 5
80657 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
80658 +#define L1_CACHE_SHIFT 5UL
80659 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
80660
80661 #endif /* __ASM_GENERIC_CACHE_H */
80662 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
80663 index 0d68a1e..b74a761 100644
80664 --- a/include/asm-generic/emergency-restart.h
80665 +++ b/include/asm-generic/emergency-restart.h
80666 @@ -1,7 +1,7 @@
80667 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
80668 #define _ASM_GENERIC_EMERGENCY_RESTART_H
80669
80670 -static inline void machine_emergency_restart(void)
80671 +static inline __noreturn void machine_emergency_restart(void)
80672 {
80673 machine_restart(NULL);
80674 }
80675 diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h
80676 index 975e1cc..0b8a083 100644
80677 --- a/include/asm-generic/io.h
80678 +++ b/include/asm-generic/io.h
80679 @@ -289,7 +289,7 @@ static inline void pci_iounmap(struct pci_dev *dev, void __iomem *p)
80680 * These are pretty trivial
80681 */
80682 #ifndef virt_to_phys
80683 -static inline unsigned long virt_to_phys(volatile void *address)
80684 +static inline unsigned long __intentional_overflow(-1) virt_to_phys(volatile void *address)
80685 {
80686 return __pa((unsigned long)address);
80687 }
80688 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
80689 index 90f99c7..00ce236 100644
80690 --- a/include/asm-generic/kmap_types.h
80691 +++ b/include/asm-generic/kmap_types.h
80692 @@ -2,9 +2,9 @@
80693 #define _ASM_GENERIC_KMAP_TYPES_H
80694
80695 #ifdef __WITH_KM_FENCE
80696 -# define KM_TYPE_NR 41
80697 +# define KM_TYPE_NR 42
80698 #else
80699 -# define KM_TYPE_NR 20
80700 +# define KM_TYPE_NR 21
80701 #endif
80702
80703 #endif
80704 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
80705 index 9ceb03b..62b0b8f 100644
80706 --- a/include/asm-generic/local.h
80707 +++ b/include/asm-generic/local.h
80708 @@ -23,24 +23,37 @@ typedef struct
80709 atomic_long_t a;
80710 } local_t;
80711
80712 +typedef struct {
80713 + atomic_long_unchecked_t a;
80714 +} local_unchecked_t;
80715 +
80716 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
80717
80718 #define local_read(l) atomic_long_read(&(l)->a)
80719 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
80720 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
80721 +#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
80722 #define local_inc(l) atomic_long_inc(&(l)->a)
80723 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
80724 #define local_dec(l) atomic_long_dec(&(l)->a)
80725 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
80726 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
80727 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
80728 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
80729 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
80730
80731 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
80732 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
80733 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
80734 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
80735 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
80736 +#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
80737 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
80738 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
80739 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
80740
80741 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
80742 +#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
80743 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
80744 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
80745 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
80746 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
80747 index 725612b..9cc513a 100644
80748 --- a/include/asm-generic/pgtable-nopmd.h
80749 +++ b/include/asm-generic/pgtable-nopmd.h
80750 @@ -1,14 +1,19 @@
80751 #ifndef _PGTABLE_NOPMD_H
80752 #define _PGTABLE_NOPMD_H
80753
80754 -#ifndef __ASSEMBLY__
80755 -
80756 #include <asm-generic/pgtable-nopud.h>
80757
80758 -struct mm_struct;
80759 -
80760 #define __PAGETABLE_PMD_FOLDED
80761
80762 +#define PMD_SHIFT PUD_SHIFT
80763 +#define PTRS_PER_PMD 1
80764 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
80765 +#define PMD_MASK (~(PMD_SIZE-1))
80766 +
80767 +#ifndef __ASSEMBLY__
80768 +
80769 +struct mm_struct;
80770 +
80771 /*
80772 * Having the pmd type consist of a pud gets the size right, and allows
80773 * us to conceptually access the pud entry that this pmd is folded into
80774 @@ -16,11 +21,6 @@ struct mm_struct;
80775 */
80776 typedef struct { pud_t pud; } pmd_t;
80777
80778 -#define PMD_SHIFT PUD_SHIFT
80779 -#define PTRS_PER_PMD 1
80780 -#define PMD_SIZE (1UL << PMD_SHIFT)
80781 -#define PMD_MASK (~(PMD_SIZE-1))
80782 -
80783 /*
80784 * The "pud_xxx()" functions here are trivial for a folded two-level
80785 * setup: the pmd is never bad, and a pmd always exists (as it's folded
80786 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
80787 index 810431d..0ec4804f 100644
80788 --- a/include/asm-generic/pgtable-nopud.h
80789 +++ b/include/asm-generic/pgtable-nopud.h
80790 @@ -1,10 +1,15 @@
80791 #ifndef _PGTABLE_NOPUD_H
80792 #define _PGTABLE_NOPUD_H
80793
80794 -#ifndef __ASSEMBLY__
80795 -
80796 #define __PAGETABLE_PUD_FOLDED
80797
80798 +#define PUD_SHIFT PGDIR_SHIFT
80799 +#define PTRS_PER_PUD 1
80800 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
80801 +#define PUD_MASK (~(PUD_SIZE-1))
80802 +
80803 +#ifndef __ASSEMBLY__
80804 +
80805 /*
80806 * Having the pud type consist of a pgd gets the size right, and allows
80807 * us to conceptually access the pgd entry that this pud is folded into
80808 @@ -12,11 +17,6 @@
80809 */
80810 typedef struct { pgd_t pgd; } pud_t;
80811
80812 -#define PUD_SHIFT PGDIR_SHIFT
80813 -#define PTRS_PER_PUD 1
80814 -#define PUD_SIZE (1UL << PUD_SHIFT)
80815 -#define PUD_MASK (~(PUD_SIZE-1))
80816 -
80817 /*
80818 * The "pgd_xxx()" functions here are trivial for a folded two-level
80819 * setup: the pud is never bad, and a pud always exists (as it's folded
80820 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
80821 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
80822
80823 #define pgd_populate(mm, pgd, pud) do { } while (0)
80824 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
80825 /*
80826 * (puds are folded into pgds so this doesn't get actually called,
80827 * but the define is needed for a generic inline function.)
80828 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
80829 index 53b2acc..f4568e7 100644
80830 --- a/include/asm-generic/pgtable.h
80831 +++ b/include/asm-generic/pgtable.h
80832 @@ -819,6 +819,22 @@ static inline void pmdp_set_numa(struct mm_struct *mm, unsigned long addr,
80833 }
80834 #endif /* CONFIG_NUMA_BALANCING */
80835
80836 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
80837 +#ifdef CONFIG_PAX_KERNEXEC
80838 +#error KERNEXEC requires pax_open_kernel
80839 +#else
80840 +static inline unsigned long pax_open_kernel(void) { return 0; }
80841 +#endif
80842 +#endif
80843 +
80844 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
80845 +#ifdef CONFIG_PAX_KERNEXEC
80846 +#error KERNEXEC requires pax_close_kernel
80847 +#else
80848 +static inline unsigned long pax_close_kernel(void) { return 0; }
80849 +#endif
80850 +#endif
80851 +
80852 #endif /* CONFIG_MMU */
80853
80854 #endif /* !__ASSEMBLY__ */
80855 diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
80856 index 72d8803..cb9749c 100644
80857 --- a/include/asm-generic/uaccess.h
80858 +++ b/include/asm-generic/uaccess.h
80859 @@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
80860 return __clear_user(to, n);
80861 }
80862
80863 +#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
80864 +#ifdef CONFIG_PAX_MEMORY_UDEREF
80865 +#error UDEREF requires pax_open_userland
80866 +#else
80867 +static inline unsigned long pax_open_userland(void) { return 0; }
80868 +#endif
80869 +#endif
80870 +
80871 +#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
80872 +#ifdef CONFIG_PAX_MEMORY_UDEREF
80873 +#error UDEREF requires pax_close_userland
80874 +#else
80875 +static inline unsigned long pax_close_userland(void) { return 0; }
80876 +#endif
80877 +#endif
80878 +
80879 #endif /* __ASM_GENERIC_UACCESS_H */
80880 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
80881 index c1c0b0c..05c9588 100644
80882 --- a/include/asm-generic/vmlinux.lds.h
80883 +++ b/include/asm-generic/vmlinux.lds.h
80884 @@ -231,6 +231,7 @@
80885 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
80886 VMLINUX_SYMBOL(__start_rodata) = .; \
80887 *(.rodata) *(.rodata.*) \
80888 + *(.data..read_only) \
80889 *(__vermagic) /* Kernel version magic */ \
80890 . = ALIGN(8); \
80891 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
80892 @@ -719,17 +720,18 @@
80893 * section in the linker script will go there too. @phdr should have
80894 * a leading colon.
80895 *
80896 - * Note that this macros defines __per_cpu_load as an absolute symbol.
80897 + * Note that this macros defines per_cpu_load as an absolute symbol.
80898 * If there is no need to put the percpu section at a predetermined
80899 * address, use PERCPU_SECTION.
80900 */
80901 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
80902 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
80903 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
80904 + per_cpu_load = .; \
80905 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
80906 - LOAD_OFFSET) { \
80907 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
80908 PERCPU_INPUT(cacheline) \
80909 } phdr \
80910 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
80911 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
80912
80913 /**
80914 * PERCPU_SECTION - define output section for percpu area, simple version
80915 diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
80916 index 016c2f1..c4baa98 100644
80917 --- a/include/crypto/algapi.h
80918 +++ b/include/crypto/algapi.h
80919 @@ -34,7 +34,7 @@ struct crypto_type {
80920 unsigned int maskclear;
80921 unsigned int maskset;
80922 unsigned int tfmsize;
80923 -};
80924 +} __do_const;
80925
80926 struct crypto_instance {
80927 struct crypto_alg alg;
80928 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
80929 index 8af71a8..7fe6c19 100644
80930 --- a/include/drm/drmP.h
80931 +++ b/include/drm/drmP.h
80932 @@ -68,6 +68,7 @@
80933 #include <linux/workqueue.h>
80934 #include <linux/poll.h>
80935 #include <asm/pgalloc.h>
80936 +#include <asm/local.h>
80937 #include <drm/drm.h>
80938 #include <drm/drm_sarea.h>
80939 #include <drm/drm_vma_manager.h>
80940 @@ -261,10 +262,12 @@ do { \
80941 * \param cmd command.
80942 * \param arg argument.
80943 */
80944 -typedef int drm_ioctl_t(struct drm_device *dev, void *data,
80945 +typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
80946 + struct drm_file *file_priv);
80947 +typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
80948 struct drm_file *file_priv);
80949
80950 -typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
80951 +typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
80952 unsigned long arg);
80953
80954 #define DRM_IOCTL_NR(n) _IOC_NR(n)
80955 @@ -280,10 +283,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
80956 struct drm_ioctl_desc {
80957 unsigned int cmd;
80958 int flags;
80959 - drm_ioctl_t *func;
80960 + drm_ioctl_t func;
80961 unsigned int cmd_drv;
80962 const char *name;
80963 -};
80964 +} __do_const;
80965
80966 /**
80967 * Creates a driver or general drm_ioctl_desc array entry for the given
80968 @@ -983,7 +986,8 @@ struct drm_info_list {
80969 int (*show)(struct seq_file*, void*); /** show callback */
80970 u32 driver_features; /**< Required driver features for this entry */
80971 void *data;
80972 -};
80973 +} __do_const;
80974 +typedef struct drm_info_list __no_const drm_info_list_no_const;
80975
80976 /**
80977 * debugfs node structure. This structure represents a debugfs file.
80978 @@ -1067,7 +1071,7 @@ struct drm_device {
80979
80980 /** \name Usage Counters */
80981 /*@{ */
80982 - int open_count; /**< Outstanding files open, protected by drm_global_mutex. */
80983 + local_t open_count; /**< Outstanding files open, protected by drm_global_mutex. */
80984 spinlock_t buf_lock; /**< For drm_device::buf_use and a few other things. */
80985 int buf_use; /**< Buffers in use -- cannot alloc */
80986 atomic_t buf_alloc; /**< Buffer allocation in progress */
80987 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
80988 index a3d75fe..6802f9c 100644
80989 --- a/include/drm/drm_crtc_helper.h
80990 +++ b/include/drm/drm_crtc_helper.h
80991 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
80992 struct drm_connector *connector);
80993 /* disable encoder when not in use - more explicit than dpms off */
80994 void (*disable)(struct drm_encoder *encoder);
80995 -};
80996 +} __no_const;
80997
80998 /**
80999 * drm_connector_helper_funcs - helper operations for connectors
81000 diff --git a/include/drm/i915_pciids.h b/include/drm/i915_pciids.h
81001 index a70d456..6ea07cd 100644
81002 --- a/include/drm/i915_pciids.h
81003 +++ b/include/drm/i915_pciids.h
81004 @@ -37,7 +37,7 @@
81005 */
81006 #define INTEL_VGA_DEVICE(id, info) { \
81007 0x8086, id, \
81008 - ~0, ~0, \
81009 + PCI_ANY_ID, PCI_ANY_ID, \
81010 0x030000, 0xff0000, \
81011 (unsigned long) info }
81012
81013 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
81014 index 72dcbe8..8db58d7 100644
81015 --- a/include/drm/ttm/ttm_memory.h
81016 +++ b/include/drm/ttm/ttm_memory.h
81017 @@ -48,7 +48,7 @@
81018
81019 struct ttm_mem_shrink {
81020 int (*do_shrink) (struct ttm_mem_shrink *);
81021 -};
81022 +} __no_const;
81023
81024 /**
81025 * struct ttm_mem_global - Global memory accounting structure.
81026 diff --git a/include/drm/ttm/ttm_page_alloc.h b/include/drm/ttm/ttm_page_alloc.h
81027 index 49a8284..9643967 100644
81028 --- a/include/drm/ttm/ttm_page_alloc.h
81029 +++ b/include/drm/ttm/ttm_page_alloc.h
81030 @@ -80,6 +80,7 @@ void ttm_dma_page_alloc_fini(void);
81031 */
81032 extern int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data);
81033
81034 +struct device;
81035 extern int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev);
81036 extern void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev);
81037
81038 diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
81039 index 4b840e8..155d235 100644
81040 --- a/include/keys/asymmetric-subtype.h
81041 +++ b/include/keys/asymmetric-subtype.h
81042 @@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
81043 /* Verify the signature on a key of this subtype (optional) */
81044 int (*verify_signature)(const struct key *key,
81045 const struct public_key_signature *sig);
81046 -};
81047 +} __do_const;
81048
81049 /**
81050 * asymmetric_key_subtype - Get the subtype from an asymmetric key
81051 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
81052 index c1da539..1dcec55 100644
81053 --- a/include/linux/atmdev.h
81054 +++ b/include/linux/atmdev.h
81055 @@ -28,7 +28,7 @@ struct compat_atm_iobuf {
81056 #endif
81057
81058 struct k_atm_aal_stats {
81059 -#define __HANDLE_ITEM(i) atomic_t i
81060 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
81061 __AAL_STAT_ITEMS
81062 #undef __HANDLE_ITEM
81063 };
81064 @@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
81065 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
81066 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
81067 struct module *owner;
81068 -};
81069 +} __do_const ;
81070
81071 struct atmphy_ops {
81072 int (*start)(struct atm_dev *dev);
81073 diff --git a/include/linux/audit.h b/include/linux/audit.h
81074 index 22cfddb..ab759e8 100644
81075 --- a/include/linux/audit.h
81076 +++ b/include/linux/audit.h
81077 @@ -210,7 +210,7 @@ static inline void audit_ptrace(struct task_struct *t)
81078 extern unsigned int audit_serial(void);
81079 extern int auditsc_get_stamp(struct audit_context *ctx,
81080 struct timespec *t, unsigned int *serial);
81081 -extern int audit_set_loginuid(kuid_t loginuid);
81082 +extern int __intentional_overflow(-1) audit_set_loginuid(kuid_t loginuid);
81083
81084 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
81085 {
81086 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
81087 index 61f29e5..e67c658 100644
81088 --- a/include/linux/binfmts.h
81089 +++ b/include/linux/binfmts.h
81090 @@ -44,7 +44,7 @@ struct linux_binprm {
81091 unsigned interp_flags;
81092 unsigned interp_data;
81093 unsigned long loader, exec;
81094 -};
81095 +} __randomize_layout;
81096
81097 #define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0
81098 #define BINPRM_FLAGS_ENFORCE_NONDUMP (1 << BINPRM_FLAGS_ENFORCE_NONDUMP_BIT)
81099 @@ -73,8 +73,10 @@ struct linux_binfmt {
81100 int (*load_binary)(struct linux_binprm *);
81101 int (*load_shlib)(struct file *);
81102 int (*core_dump)(struct coredump_params *cprm);
81103 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
81104 + void (*handle_mmap)(struct file *);
81105 unsigned long min_coredump; /* minimal dump size */
81106 -};
81107 +} __do_const __randomize_layout;
81108
81109 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
81110
81111 diff --git a/include/linux/bitops.h b/include/linux/bitops.h
81112 index cbc5833..8123ebc 100644
81113 --- a/include/linux/bitops.h
81114 +++ b/include/linux/bitops.h
81115 @@ -122,7 +122,7 @@ static inline __u64 ror64(__u64 word, unsigned int shift)
81116 * @word: value to rotate
81117 * @shift: bits to roll
81118 */
81119 -static inline __u32 rol32(__u32 word, unsigned int shift)
81120 +static inline __u32 __intentional_overflow(-1) rol32(__u32 word, unsigned int shift)
81121 {
81122 return (word << shift) | (word >> (32 - shift));
81123 }
81124 @@ -132,7 +132,7 @@ static inline __u32 rol32(__u32 word, unsigned int shift)
81125 * @word: value to rotate
81126 * @shift: bits to roll
81127 */
81128 -static inline __u32 ror32(__u32 word, unsigned int shift)
81129 +static inline __u32 __intentional_overflow(-1) ror32(__u32 word, unsigned int shift)
81130 {
81131 return (word >> shift) | (word << (32 - shift));
81132 }
81133 @@ -188,7 +188,7 @@ static inline __s32 sign_extend32(__u32 value, int index)
81134 return (__s32)(value << shift) >> shift;
81135 }
81136
81137 -static inline unsigned fls_long(unsigned long l)
81138 +static inline unsigned __intentional_overflow(-1) fls_long(unsigned long l)
81139 {
81140 if (sizeof(l) == 4)
81141 return fls(l);
81142 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
81143 index 8699bcf..279485d 100644
81144 --- a/include/linux/blkdev.h
81145 +++ b/include/linux/blkdev.h
81146 @@ -1625,7 +1625,7 @@ struct block_device_operations {
81147 /* this callback is with swap_lock and sometimes page table lock held */
81148 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
81149 struct module *owner;
81150 -};
81151 +} __do_const;
81152
81153 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
81154 unsigned long);
81155 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
81156 index afc1343..9735539 100644
81157 --- a/include/linux/blktrace_api.h
81158 +++ b/include/linux/blktrace_api.h
81159 @@ -25,7 +25,7 @@ struct blk_trace {
81160 struct dentry *dropped_file;
81161 struct dentry *msg_file;
81162 struct list_head running_list;
81163 - atomic_t dropped;
81164 + atomic_unchecked_t dropped;
81165 };
81166
81167 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
81168 diff --git a/include/linux/cache.h b/include/linux/cache.h
81169 index 17e7e82..1d7da26 100644
81170 --- a/include/linux/cache.h
81171 +++ b/include/linux/cache.h
81172 @@ -16,6 +16,14 @@
81173 #define __read_mostly
81174 #endif
81175
81176 +#ifndef __read_only
81177 +#ifdef CONFIG_PAX_KERNEXEC
81178 +#error KERNEXEC requires __read_only
81179 +#else
81180 +#define __read_only __read_mostly
81181 +#endif
81182 +#endif
81183 +
81184 #ifndef ____cacheline_aligned
81185 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
81186 #endif
81187 diff --git a/include/linux/capability.h b/include/linux/capability.h
81188 index 84b13ad..172cdee 100644
81189 --- a/include/linux/capability.h
81190 +++ b/include/linux/capability.h
81191 @@ -211,9 +211,14 @@ extern bool has_ns_capability_noaudit(struct task_struct *t,
81192 extern bool capable(int cap);
81193 extern bool ns_capable(struct user_namespace *ns, int cap);
81194 extern bool capable_wrt_inode_uidgid(const struct inode *inode, int cap);
81195 +extern bool capable_wrt_inode_uidgid_nolog(const struct inode *inode, int cap);
81196 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
81197 +extern bool capable_nolog(int cap);
81198 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
81199
81200 /* audit system wants to get cap info from files as well */
81201 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
81202
81203 +extern int is_privileged_binary(const struct dentry *dentry);
81204 +
81205 #endif /* !_LINUX_CAPABILITY_H */
81206 diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
81207 index 8609d57..86e4d79 100644
81208 --- a/include/linux/cdrom.h
81209 +++ b/include/linux/cdrom.h
81210 @@ -87,7 +87,6 @@ struct cdrom_device_ops {
81211
81212 /* driver specifications */
81213 const int capability; /* capability flags */
81214 - int n_minors; /* number of active minor devices */
81215 /* handle uniform packets for scsi type devices (scsi,atapi) */
81216 int (*generic_packet) (struct cdrom_device_info *,
81217 struct packet_command *);
81218 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
81219 index 4ce9056..86caac6 100644
81220 --- a/include/linux/cleancache.h
81221 +++ b/include/linux/cleancache.h
81222 @@ -31,7 +31,7 @@ struct cleancache_ops {
81223 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
81224 void (*invalidate_inode)(int, struct cleancache_filekey);
81225 void (*invalidate_fs)(int);
81226 -};
81227 +} __no_const;
81228
81229 extern struct cleancache_ops *
81230 cleancache_register_ops(struct cleancache_ops *ops);
81231 diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
81232 index 0c287db..5efa775 100644
81233 --- a/include/linux/clk-provider.h
81234 +++ b/include/linux/clk-provider.h
81235 @@ -180,6 +180,7 @@ struct clk_ops {
81236 void (*init)(struct clk_hw *hw);
81237 int (*debug_init)(struct clk_hw *hw, struct dentry *dentry);
81238 };
81239 +typedef struct clk_ops __no_const clk_ops_no_const;
81240
81241 /**
81242 * struct clk_init_data - holds init data that's common to all clocks and is
81243 diff --git a/include/linux/compat.h b/include/linux/compat.h
81244 index e649426..a74047b 100644
81245 --- a/include/linux/compat.h
81246 +++ b/include/linux/compat.h
81247 @@ -316,7 +316,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
81248 compat_size_t __user *len_ptr);
81249
81250 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
81251 -asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
81252 +asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
81253 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
81254 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
81255 compat_ssize_t msgsz, int msgflg);
81256 @@ -436,7 +436,7 @@ extern int compat_ptrace_request(struct task_struct *child,
81257 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
81258 compat_ulong_t addr, compat_ulong_t data);
81259 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
81260 - compat_long_t addr, compat_long_t data);
81261 + compat_ulong_t addr, compat_ulong_t data);
81262
81263 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, compat_size_t);
81264 /*
81265 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
81266 index 2507fd2..55203f8 100644
81267 --- a/include/linux/compiler-gcc4.h
81268 +++ b/include/linux/compiler-gcc4.h
81269 @@ -39,9 +39,34 @@
81270 # define __compiletime_warning(message) __attribute__((warning(message)))
81271 # define __compiletime_error(message) __attribute__((error(message)))
81272 #endif /* __CHECKER__ */
81273 +
81274 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
81275 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
81276 +#define __bos0(ptr) __bos((ptr), 0)
81277 +#define __bos1(ptr) __bos((ptr), 1)
81278 #endif /* GCC_VERSION >= 40300 */
81279
81280 #if GCC_VERSION >= 40500
81281 +
81282 +#ifdef RANDSTRUCT_PLUGIN
81283 +#define __randomize_layout __attribute__((randomize_layout))
81284 +#define __no_randomize_layout __attribute__((no_randomize_layout))
81285 +#endif
81286 +
81287 +#ifdef CONSTIFY_PLUGIN
81288 +#define __no_const __attribute__((no_const))
81289 +#define __do_const __attribute__((do_const))
81290 +#endif
81291 +
81292 +#ifdef SIZE_OVERFLOW_PLUGIN
81293 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
81294 +#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
81295 +#endif
81296 +
81297 +#ifdef LATENT_ENTROPY_PLUGIN
81298 +#define __latent_entropy __attribute__((latent_entropy))
81299 +#endif
81300 +
81301 /*
81302 * Mark a position in code as unreachable. This can be used to
81303 * suppress control flow warnings after asm blocks that transfer
81304 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
81305 index d5ad7b1..3b74638 100644
81306 --- a/include/linux/compiler.h
81307 +++ b/include/linux/compiler.h
81308 @@ -5,11 +5,14 @@
81309
81310 #ifdef __CHECKER__
81311 # define __user __attribute__((noderef, address_space(1)))
81312 +# define __force_user __force __user
81313 # define __kernel __attribute__((address_space(0)))
81314 +# define __force_kernel __force __kernel
81315 # define __safe __attribute__((safe))
81316 # define __force __attribute__((force))
81317 # define __nocast __attribute__((nocast))
81318 # define __iomem __attribute__((noderef, address_space(2)))
81319 +# define __force_iomem __force __iomem
81320 # define __must_hold(x) __attribute__((context(x,1,1)))
81321 # define __acquires(x) __attribute__((context(x,0,1)))
81322 # define __releases(x) __attribute__((context(x,1,0)))
81323 @@ -17,20 +20,37 @@
81324 # define __release(x) __context__(x,-1)
81325 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
81326 # define __percpu __attribute__((noderef, address_space(3)))
81327 +# define __force_percpu __force __percpu
81328 #ifdef CONFIG_SPARSE_RCU_POINTER
81329 # define __rcu __attribute__((noderef, address_space(4)))
81330 +# define __force_rcu __force __rcu
81331 #else
81332 # define __rcu
81333 +# define __force_rcu
81334 #endif
81335 extern void __chk_user_ptr(const volatile void __user *);
81336 extern void __chk_io_ptr(const volatile void __iomem *);
81337 #else
81338 -# define __user
81339 -# define __kernel
81340 +# ifdef CHECKER_PLUGIN
81341 +//# define __user
81342 +//# define __force_user
81343 +//# define __kernel
81344 +//# define __force_kernel
81345 +# else
81346 +# ifdef STRUCTLEAK_PLUGIN
81347 +# define __user __attribute__((user))
81348 +# else
81349 +# define __user
81350 +# endif
81351 +# define __force_user
81352 +# define __kernel
81353 +# define __force_kernel
81354 +# endif
81355 # define __safe
81356 # define __force
81357 # define __nocast
81358 # define __iomem
81359 +# define __force_iomem
81360 # define __chk_user_ptr(x) (void)0
81361 # define __chk_io_ptr(x) (void)0
81362 # define __builtin_warning(x, y...) (1)
81363 @@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
81364 # define __release(x) (void)0
81365 # define __cond_lock(x,c) (c)
81366 # define __percpu
81367 +# define __force_percpu
81368 # define __rcu
81369 +# define __force_rcu
81370 #endif
81371
81372 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
81373 @@ -286,6 +308,34 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
81374 # define __attribute_const__ /* unimplemented */
81375 #endif
81376
81377 +#ifndef __randomize_layout
81378 +# define __randomize_layout
81379 +#endif
81380 +
81381 +#ifndef __no_randomize_layout
81382 +# define __no_randomize_layout
81383 +#endif
81384 +
81385 +#ifndef __no_const
81386 +# define __no_const
81387 +#endif
81388 +
81389 +#ifndef __do_const
81390 +# define __do_const
81391 +#endif
81392 +
81393 +#ifndef __size_overflow
81394 +# define __size_overflow(...)
81395 +#endif
81396 +
81397 +#ifndef __intentional_overflow
81398 +# define __intentional_overflow(...)
81399 +#endif
81400 +
81401 +#ifndef __latent_entropy
81402 +# define __latent_entropy
81403 +#endif
81404 +
81405 /*
81406 * Tell gcc if a function is cold. The compiler will assume any path
81407 * directly leading to the call is unlikely.
81408 @@ -295,6 +345,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
81409 #define __cold
81410 #endif
81411
81412 +#ifndef __alloc_size
81413 +#define __alloc_size(...)
81414 +#endif
81415 +
81416 +#ifndef __bos
81417 +#define __bos(ptr, arg)
81418 +#endif
81419 +
81420 +#ifndef __bos0
81421 +#define __bos0(ptr)
81422 +#endif
81423 +
81424 +#ifndef __bos1
81425 +#define __bos1(ptr)
81426 +#endif
81427 +
81428 /* Simple shorthand for a section definition */
81429 #ifndef __section
81430 # define __section(S) __attribute__ ((__section__(#S)))
81431 @@ -378,7 +444,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
81432 * use is to mediate communication between process-level code and irq/NMI
81433 * handlers, all running on the same CPU.
81434 */
81435 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
81436 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
81437 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
81438
81439 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
81440 #ifdef CONFIG_KPROBES
81441 diff --git a/include/linux/completion.h b/include/linux/completion.h
81442 index 5d5aaae..0ea9b84 100644
81443 --- a/include/linux/completion.h
81444 +++ b/include/linux/completion.h
81445 @@ -90,16 +90,16 @@ static inline void reinit_completion(struct completion *x)
81446
81447 extern void wait_for_completion(struct completion *);
81448 extern void wait_for_completion_io(struct completion *);
81449 -extern int wait_for_completion_interruptible(struct completion *x);
81450 -extern int wait_for_completion_killable(struct completion *x);
81451 +extern int wait_for_completion_interruptible(struct completion *x) __intentional_overflow(-1);
81452 +extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
81453 extern unsigned long wait_for_completion_timeout(struct completion *x,
81454 - unsigned long timeout);
81455 + unsigned long timeout) __intentional_overflow(-1);
81456 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
81457 - unsigned long timeout);
81458 + unsigned long timeout) __intentional_overflow(-1);
81459 extern long wait_for_completion_interruptible_timeout(
81460 - struct completion *x, unsigned long timeout);
81461 + struct completion *x, unsigned long timeout) __intentional_overflow(-1);
81462 extern long wait_for_completion_killable_timeout(
81463 - struct completion *x, unsigned long timeout);
81464 + struct completion *x, unsigned long timeout) __intentional_overflow(-1);
81465 extern bool try_wait_for_completion(struct completion *x);
81466 extern bool completion_done(struct completion *x);
81467
81468 diff --git a/include/linux/configfs.h b/include/linux/configfs.h
81469 index 34025df..d94bbbc 100644
81470 --- a/include/linux/configfs.h
81471 +++ b/include/linux/configfs.h
81472 @@ -125,7 +125,7 @@ struct configfs_attribute {
81473 const char *ca_name;
81474 struct module *ca_owner;
81475 umode_t ca_mode;
81476 -};
81477 +} __do_const;
81478
81479 /*
81480 * Users often need to create attribute structures for their configurable
81481 diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
81482 index 8f8ae95..b9b0e6d 100644
81483 --- a/include/linux/cpufreq.h
81484 +++ b/include/linux/cpufreq.h
81485 @@ -202,6 +202,7 @@ struct global_attr {
81486 ssize_t (*store)(struct kobject *a, struct attribute *b,
81487 const char *c, size_t count);
81488 };
81489 +typedef struct global_attr __no_const global_attr_no_const;
81490
81491 #define define_one_global_ro(_name) \
81492 static struct global_attr _name = \
81493 @@ -268,7 +269,7 @@ struct cpufreq_driver {
81494 bool boost_supported;
81495 bool boost_enabled;
81496 int (*set_boost) (int state);
81497 -};
81498 +} __do_const;
81499
81500 /* flags */
81501 #define CPUFREQ_STICKY (1 << 0) /* driver isn't removed even if
81502 diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
81503 index 25e0df6..952dffd 100644
81504 --- a/include/linux/cpuidle.h
81505 +++ b/include/linux/cpuidle.h
81506 @@ -50,7 +50,8 @@ struct cpuidle_state {
81507 int index);
81508
81509 int (*enter_dead) (struct cpuidle_device *dev, int index);
81510 -};
81511 +} __do_const;
81512 +typedef struct cpuidle_state __no_const cpuidle_state_no_const;
81513
81514 /* Idle State Flags */
81515 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
81516 @@ -209,7 +210,7 @@ struct cpuidle_governor {
81517 void (*reflect) (struct cpuidle_device *dev, int index);
81518
81519 struct module *owner;
81520 -};
81521 +} __do_const;
81522
81523 #ifdef CONFIG_CPU_IDLE
81524 extern int cpuidle_register_governor(struct cpuidle_governor *gov);
81525 diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
81526 index 2997af6..424ddc1 100644
81527 --- a/include/linux/cpumask.h
81528 +++ b/include/linux/cpumask.h
81529 @@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
81530 }
81531
81532 /* Valid inputs for n are -1 and 0. */
81533 -static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
81534 +static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
81535 {
81536 return n+1;
81537 }
81538
81539 -static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
81540 +static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
81541 {
81542 return n+1;
81543 }
81544
81545 -static inline unsigned int cpumask_next_and(int n,
81546 +static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
81547 const struct cpumask *srcp,
81548 const struct cpumask *andp)
81549 {
81550 @@ -174,7 +174,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
81551 *
81552 * Returns >= nr_cpu_ids if no further cpus set.
81553 */
81554 -static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
81555 +static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
81556 {
81557 /* -1 is a legal arg here. */
81558 if (n != -1)
81559 @@ -189,7 +189,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
81560 *
81561 * Returns >= nr_cpu_ids if no further cpus unset.
81562 */
81563 -static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
81564 +static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
81565 {
81566 /* -1 is a legal arg here. */
81567 if (n != -1)
81568 @@ -197,7 +197,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
81569 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
81570 }
81571
81572 -int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
81573 +int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
81574 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
81575 int cpumask_set_cpu_local_first(int i, int numa_node, cpumask_t *dstp);
81576
81577 diff --git a/include/linux/cred.h b/include/linux/cred.h
81578 index f61d6c8..d372d95 100644
81579 --- a/include/linux/cred.h
81580 +++ b/include/linux/cred.h
81581 @@ -35,7 +35,7 @@ struct group_info {
81582 int nblocks;
81583 kgid_t small_block[NGROUPS_SMALL];
81584 kgid_t *blocks[0];
81585 -};
81586 +} __randomize_layout;
81587
81588 /**
81589 * get_group_info - Get a reference to a group info structure
81590 @@ -136,7 +136,7 @@ struct cred {
81591 struct user_namespace *user_ns; /* user_ns the caps and keyrings are relative to. */
81592 struct group_info *group_info; /* supplementary groups for euid/fsgid */
81593 struct rcu_head rcu; /* RCU deletion hook */
81594 -};
81595 +} __randomize_layout;
81596
81597 extern void __put_cred(struct cred *);
81598 extern void exit_creds(struct task_struct *);
81599 @@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
81600 static inline void validate_process_creds(void)
81601 {
81602 }
81603 +static inline void validate_task_creds(struct task_struct *task)
81604 +{
81605 +}
81606 #endif
81607
81608 /**
81609 @@ -322,6 +325,7 @@ static inline void put_cred(const struct cred *_cred)
81610
81611 #define task_uid(task) (task_cred_xxx((task), uid))
81612 #define task_euid(task) (task_cred_xxx((task), euid))
81613 +#define task_securebits(task) (task_cred_xxx((task), securebits))
81614
81615 #define current_cred_xxx(xxx) \
81616 ({ \
81617 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
81618 index b92eadf..b4ecdc1 100644
81619 --- a/include/linux/crypto.h
81620 +++ b/include/linux/crypto.h
81621 @@ -373,7 +373,7 @@ struct cipher_tfm {
81622 const u8 *key, unsigned int keylen);
81623 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
81624 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
81625 -};
81626 +} __no_const;
81627
81628 struct hash_tfm {
81629 int (*init)(struct hash_desc *desc);
81630 @@ -394,13 +394,13 @@ struct compress_tfm {
81631 int (*cot_decompress)(struct crypto_tfm *tfm,
81632 const u8 *src, unsigned int slen,
81633 u8 *dst, unsigned int *dlen);
81634 -};
81635 +} __no_const;
81636
81637 struct rng_tfm {
81638 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
81639 unsigned int dlen);
81640 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
81641 -};
81642 +} __no_const;
81643
81644 #define crt_ablkcipher crt_u.ablkcipher
81645 #define crt_aead crt_u.aead
81646 diff --git a/include/linux/ctype.h b/include/linux/ctype.h
81647 index 653589e..4ef254a 100644
81648 --- a/include/linux/ctype.h
81649 +++ b/include/linux/ctype.h
81650 @@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
81651 * Fast implementation of tolower() for internal usage. Do not use in your
81652 * code.
81653 */
81654 -static inline char _tolower(const char c)
81655 +static inline unsigned char _tolower(const unsigned char c)
81656 {
81657 return c | 0x20;
81658 }
81659 diff --git a/include/linux/dcache.h b/include/linux/dcache.h
81660 index 3c7ec32..4ca97cc 100644
81661 --- a/include/linux/dcache.h
81662 +++ b/include/linux/dcache.h
81663 @@ -133,7 +133,7 @@ struct dentry {
81664 } d_u;
81665 struct list_head d_subdirs; /* our children */
81666 struct hlist_node d_alias; /* inode alias list */
81667 -};
81668 +} __randomize_layout;
81669
81670 /*
81671 * dentry->d_lock spinlock nesting subclasses:
81672 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
81673 index 7925bf0..d5143d2 100644
81674 --- a/include/linux/decompress/mm.h
81675 +++ b/include/linux/decompress/mm.h
81676 @@ -77,7 +77,7 @@ static void free(void *where)
81677 * warnings when not needed (indeed large_malloc / large_free are not
81678 * needed by inflate */
81679
81680 -#define malloc(a) kmalloc(a, GFP_KERNEL)
81681 +#define malloc(a) kmalloc((a), GFP_KERNEL)
81682 #define free(a) kfree(a)
81683
81684 #define large_malloc(a) vmalloc(a)
81685 diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
81686 index f1863dc..5c26074 100644
81687 --- a/include/linux/devfreq.h
81688 +++ b/include/linux/devfreq.h
81689 @@ -114,7 +114,7 @@ struct devfreq_governor {
81690 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
81691 int (*event_handler)(struct devfreq *devfreq,
81692 unsigned int event, void *data);
81693 -};
81694 +} __do_const;
81695
81696 /**
81697 * struct devfreq - Device devfreq structure
81698 diff --git a/include/linux/device.h b/include/linux/device.h
81699 index af424ac..fd46ddf 100644
81700 --- a/include/linux/device.h
81701 +++ b/include/linux/device.h
81702 @@ -310,7 +310,7 @@ struct subsys_interface {
81703 struct list_head node;
81704 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
81705 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
81706 -};
81707 +} __do_const;
81708
81709 int subsys_interface_register(struct subsys_interface *sif);
81710 void subsys_interface_unregister(struct subsys_interface *sif);
81711 @@ -506,7 +506,7 @@ struct device_type {
81712 void (*release)(struct device *dev);
81713
81714 const struct dev_pm_ops *pm;
81715 -};
81716 +} __do_const;
81717
81718 /* interface for exporting device attributes */
81719 struct device_attribute {
81720 @@ -516,11 +516,12 @@ struct device_attribute {
81721 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
81722 const char *buf, size_t count);
81723 };
81724 +typedef struct device_attribute __no_const device_attribute_no_const;
81725
81726 struct dev_ext_attribute {
81727 struct device_attribute attr;
81728 void *var;
81729 -};
81730 +} __do_const;
81731
81732 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
81733 char *buf);
81734 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
81735 index 931b709..89b2d89 100644
81736 --- a/include/linux/dma-mapping.h
81737 +++ b/include/linux/dma-mapping.h
81738 @@ -60,7 +60,7 @@ struct dma_map_ops {
81739 u64 (*get_required_mask)(struct device *dev);
81740 #endif
81741 int is_phys;
81742 -};
81743 +} __do_const;
81744
81745 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
81746
81747 diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
81748 index d2c5cc7..d193394 100644
81749 --- a/include/linux/dmaengine.h
81750 +++ b/include/linux/dmaengine.h
81751 @@ -1147,9 +1147,9 @@ struct dma_pinned_list {
81752 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
81753 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
81754
81755 -dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
81756 +dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
81757 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
81758 -dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
81759 +dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
81760 struct dma_pinned_list *pinned_list, struct page *page,
81761 unsigned int offset, size_t len);
81762
81763 diff --git a/include/linux/efi.h b/include/linux/efi.h
81764 index 41bbf8b..bd3a718 100644
81765 --- a/include/linux/efi.h
81766 +++ b/include/linux/efi.h
81767 @@ -1027,6 +1027,7 @@ struct efivar_operations {
81768 efi_set_variable_t *set_variable;
81769 efi_query_variable_store_t *query_variable_store;
81770 };
81771 +typedef struct efivar_operations __no_const efivar_operations_no_const;
81772
81773 struct efivars {
81774 /*
81775 diff --git a/include/linux/elf.h b/include/linux/elf.h
81776 index 67a5fa7..b817372 100644
81777 --- a/include/linux/elf.h
81778 +++ b/include/linux/elf.h
81779 @@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
81780 #define elf_note elf32_note
81781 #define elf_addr_t Elf32_Off
81782 #define Elf_Half Elf32_Half
81783 +#define elf_dyn Elf32_Dyn
81784
81785 #else
81786
81787 @@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
81788 #define elf_note elf64_note
81789 #define elf_addr_t Elf64_Off
81790 #define Elf_Half Elf64_Half
81791 +#define elf_dyn Elf64_Dyn
81792
81793 #endif
81794
81795 diff --git a/include/linux/err.h b/include/linux/err.h
81796 index a729120..6ede2c9 100644
81797 --- a/include/linux/err.h
81798 +++ b/include/linux/err.h
81799 @@ -20,12 +20,12 @@
81800
81801 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
81802
81803 -static inline void * __must_check ERR_PTR(long error)
81804 +static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
81805 {
81806 return (void *) error;
81807 }
81808
81809 -static inline long __must_check PTR_ERR(__force const void *ptr)
81810 +static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
81811 {
81812 return (long) ptr;
81813 }
81814 diff --git a/include/linux/extcon.h b/include/linux/extcon.h
81815 index 36f49c4..a2a1f4c 100644
81816 --- a/include/linux/extcon.h
81817 +++ b/include/linux/extcon.h
81818 @@ -135,7 +135,7 @@ struct extcon_dev {
81819 /* /sys/class/extcon/.../mutually_exclusive/... */
81820 struct attribute_group attr_g_muex;
81821 struct attribute **attrs_muex;
81822 - struct device_attribute *d_attrs_muex;
81823 + device_attribute_no_const *d_attrs_muex;
81824 };
81825
81826 /**
81827 diff --git a/include/linux/fb.h b/include/linux/fb.h
81828 index b6bfda9..1f13487 100644
81829 --- a/include/linux/fb.h
81830 +++ b/include/linux/fb.h
81831 @@ -305,7 +305,7 @@ struct fb_ops {
81832 /* called at KDB enter and leave time to prepare the console */
81833 int (*fb_debug_enter)(struct fb_info *info);
81834 int (*fb_debug_leave)(struct fb_info *info);
81835 -};
81836 +} __do_const;
81837
81838 #ifdef CONFIG_FB_TILEBLITTING
81839 #define FB_TILE_CURSOR_NONE 0
81840 diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
81841 index 230f87b..1fd0485 100644
81842 --- a/include/linux/fdtable.h
81843 +++ b/include/linux/fdtable.h
81844 @@ -100,7 +100,7 @@ struct files_struct *get_files_struct(struct task_struct *);
81845 void put_files_struct(struct files_struct *fs);
81846 void reset_files_struct(struct files_struct *);
81847 int unshare_files(struct files_struct **);
81848 -struct files_struct *dup_fd(struct files_struct *, int *);
81849 +struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
81850 void do_close_on_exec(struct files_struct *);
81851 int iterate_fd(struct files_struct *, unsigned,
81852 int (*)(const void *, struct file *, unsigned),
81853 diff --git a/include/linux/filter.h b/include/linux/filter.h
81854 index a7e3c48..e568c8e 100644
81855 --- a/include/linux/filter.h
81856 +++ b/include/linux/filter.h
81857 @@ -9,330 +9,28 @@
81858 #include <linux/workqueue.h>
81859 #include <uapi/linux/filter.h>
81860
81861 -/* Internally used and optimized filter representation with extended
81862 - * instruction set based on top of classic BPF.
81863 - */
81864 -
81865 -/* instruction classes */
81866 -#define BPF_ALU64 0x07 /* alu mode in double word width */
81867 -
81868 -/* ld/ldx fields */
81869 -#define BPF_DW 0x18 /* double word */
81870 -#define BPF_XADD 0xc0 /* exclusive add */
81871 -
81872 -/* alu/jmp fields */
81873 -#define BPF_MOV 0xb0 /* mov reg to reg */
81874 -#define BPF_ARSH 0xc0 /* sign extending arithmetic shift right */
81875 -
81876 -/* change endianness of a register */
81877 -#define BPF_END 0xd0 /* flags for endianness conversion: */
81878 -#define BPF_TO_LE 0x00 /* convert to little-endian */
81879 -#define BPF_TO_BE 0x08 /* convert to big-endian */
81880 -#define BPF_FROM_LE BPF_TO_LE
81881 -#define BPF_FROM_BE BPF_TO_BE
81882 -
81883 -#define BPF_JNE 0x50 /* jump != */
81884 -#define BPF_JSGT 0x60 /* SGT is signed '>', GT in x86 */
81885 -#define BPF_JSGE 0x70 /* SGE is signed '>=', GE in x86 */
81886 -#define BPF_CALL 0x80 /* function call */
81887 -#define BPF_EXIT 0x90 /* function return */
81888 -
81889 -/* Register numbers */
81890 -enum {
81891 - BPF_REG_0 = 0,
81892 - BPF_REG_1,
81893 - BPF_REG_2,
81894 - BPF_REG_3,
81895 - BPF_REG_4,
81896 - BPF_REG_5,
81897 - BPF_REG_6,
81898 - BPF_REG_7,
81899 - BPF_REG_8,
81900 - BPF_REG_9,
81901 - BPF_REG_10,
81902 - __MAX_BPF_REG,
81903 -};
81904 -
81905 -/* BPF has 10 general purpose 64-bit registers and stack frame. */
81906 -#define MAX_BPF_REG __MAX_BPF_REG
81907 -
81908 -/* ArgX, context and stack frame pointer register positions. Note,
81909 - * Arg1, Arg2, Arg3, etc are used as argument mappings of function
81910 - * calls in BPF_CALL instruction.
81911 - */
81912 -#define BPF_REG_ARG1 BPF_REG_1
81913 -#define BPF_REG_ARG2 BPF_REG_2
81914 -#define BPF_REG_ARG3 BPF_REG_3
81915 -#define BPF_REG_ARG4 BPF_REG_4
81916 -#define BPF_REG_ARG5 BPF_REG_5
81917 -#define BPF_REG_CTX BPF_REG_6
81918 -#define BPF_REG_FP BPF_REG_10
81919 -
81920 -/* Additional register mappings for converted user programs. */
81921 -#define BPF_REG_A BPF_REG_0
81922 -#define BPF_REG_X BPF_REG_7
81923 -#define BPF_REG_TMP BPF_REG_8
81924 -
81925 -/* BPF program can access up to 512 bytes of stack space. */
81926 -#define MAX_BPF_STACK 512
81927 -
81928 -/* Helper macros for filter block array initializers. */
81929 -
81930 -/* ALU ops on registers, bpf_add|sub|...: dst_reg += src_reg */
81931 -
81932 -#define BPF_ALU64_REG(OP, DST, SRC) \
81933 - ((struct sock_filter_int) { \
81934 - .code = BPF_ALU64 | BPF_OP(OP) | BPF_X, \
81935 - .dst_reg = DST, \
81936 - .src_reg = SRC, \
81937 - .off = 0, \
81938 - .imm = 0 })
81939 -
81940 -#define BPF_ALU32_REG(OP, DST, SRC) \
81941 - ((struct sock_filter_int) { \
81942 - .code = BPF_ALU | BPF_OP(OP) | BPF_X, \
81943 - .dst_reg = DST, \
81944 - .src_reg = SRC, \
81945 - .off = 0, \
81946 - .imm = 0 })
81947 -
81948 -/* ALU ops on immediates, bpf_add|sub|...: dst_reg += imm32 */
81949 -
81950 -#define BPF_ALU64_IMM(OP, DST, IMM) \
81951 - ((struct sock_filter_int) { \
81952 - .code = BPF_ALU64 | BPF_OP(OP) | BPF_K, \
81953 - .dst_reg = DST, \
81954 - .src_reg = 0, \
81955 - .off = 0, \
81956 - .imm = IMM })
81957 -
81958 -#define BPF_ALU32_IMM(OP, DST, IMM) \
81959 - ((struct sock_filter_int) { \
81960 - .code = BPF_ALU | BPF_OP(OP) | BPF_K, \
81961 - .dst_reg = DST, \
81962 - .src_reg = 0, \
81963 - .off = 0, \
81964 - .imm = IMM })
81965 -
81966 -/* Endianess conversion, cpu_to_{l,b}e(), {l,b}e_to_cpu() */
81967 -
81968 -#define BPF_ENDIAN(TYPE, DST, LEN) \
81969 - ((struct sock_filter_int) { \
81970 - .code = BPF_ALU | BPF_END | BPF_SRC(TYPE), \
81971 - .dst_reg = DST, \
81972 - .src_reg = 0, \
81973 - .off = 0, \
81974 - .imm = LEN })
81975 -
81976 -/* Short form of mov, dst_reg = src_reg */
81977 -
81978 -#define BPF_MOV64_REG(DST, SRC) \
81979 - ((struct sock_filter_int) { \
81980 - .code = BPF_ALU64 | BPF_MOV | BPF_X, \
81981 - .dst_reg = DST, \
81982 - .src_reg = SRC, \
81983 - .off = 0, \
81984 - .imm = 0 })
81985 -
81986 -#define BPF_MOV32_REG(DST, SRC) \
81987 - ((struct sock_filter_int) { \
81988 - .code = BPF_ALU | BPF_MOV | BPF_X, \
81989 - .dst_reg = DST, \
81990 - .src_reg = SRC, \
81991 - .off = 0, \
81992 - .imm = 0 })
81993 -
81994 -/* Short form of mov, dst_reg = imm32 */
81995 -
81996 -#define BPF_MOV64_IMM(DST, IMM) \
81997 - ((struct sock_filter_int) { \
81998 - .code = BPF_ALU64 | BPF_MOV | BPF_K, \
81999 - .dst_reg = DST, \
82000 - .src_reg = 0, \
82001 - .off = 0, \
82002 - .imm = IMM })
82003 -
82004 -#define BPF_MOV32_IMM(DST, IMM) \
82005 - ((struct sock_filter_int) { \
82006 - .code = BPF_ALU | BPF_MOV | BPF_K, \
82007 - .dst_reg = DST, \
82008 - .src_reg = 0, \
82009 - .off = 0, \
82010 - .imm = IMM })
82011 -
82012 -/* Short form of mov based on type, BPF_X: dst_reg = src_reg, BPF_K: dst_reg = imm32 */
82013 -
82014 -#define BPF_MOV64_RAW(TYPE, DST, SRC, IMM) \
82015 - ((struct sock_filter_int) { \
82016 - .code = BPF_ALU64 | BPF_MOV | BPF_SRC(TYPE), \
82017 - .dst_reg = DST, \
82018 - .src_reg = SRC, \
82019 - .off = 0, \
82020 - .imm = IMM })
82021 -
82022 -#define BPF_MOV32_RAW(TYPE, DST, SRC, IMM) \
82023 - ((struct sock_filter_int) { \
82024 - .code = BPF_ALU | BPF_MOV | BPF_SRC(TYPE), \
82025 - .dst_reg = DST, \
82026 - .src_reg = SRC, \
82027 - .off = 0, \
82028 - .imm = IMM })
82029 -
82030 -/* Direct packet access, R0 = *(uint *) (skb->data + imm32) */
82031 -
82032 -#define BPF_LD_ABS(SIZE, IMM) \
82033 - ((struct sock_filter_int) { \
82034 - .code = BPF_LD | BPF_SIZE(SIZE) | BPF_ABS, \
82035 - .dst_reg = 0, \
82036 - .src_reg = 0, \
82037 - .off = 0, \
82038 - .imm = IMM })
82039 -
82040 -/* Indirect packet access, R0 = *(uint *) (skb->data + src_reg + imm32) */
82041 -
82042 -#define BPF_LD_IND(SIZE, SRC, IMM) \
82043 - ((struct sock_filter_int) { \
82044 - .code = BPF_LD | BPF_SIZE(SIZE) | BPF_IND, \
82045 - .dst_reg = 0, \
82046 - .src_reg = SRC, \
82047 - .off = 0, \
82048 - .imm = IMM })
82049 -
82050 -/* Memory load, dst_reg = *(uint *) (src_reg + off16) */
82051 -
82052 -#define BPF_LDX_MEM(SIZE, DST, SRC, OFF) \
82053 - ((struct sock_filter_int) { \
82054 - .code = BPF_LDX | BPF_SIZE(SIZE) | BPF_MEM, \
82055 - .dst_reg = DST, \
82056 - .src_reg = SRC, \
82057 - .off = OFF, \
82058 - .imm = 0 })
82059 -
82060 -/* Memory store, *(uint *) (dst_reg + off16) = src_reg */
82061 -
82062 -#define BPF_STX_MEM(SIZE, DST, SRC, OFF) \
82063 - ((struct sock_filter_int) { \
82064 - .code = BPF_STX | BPF_SIZE(SIZE) | BPF_MEM, \
82065 - .dst_reg = DST, \
82066 - .src_reg = SRC, \
82067 - .off = OFF, \
82068 - .imm = 0 })
82069 -
82070 -/* Memory store, *(uint *) (dst_reg + off16) = imm32 */
82071 -
82072 -#define BPF_ST_MEM(SIZE, DST, OFF, IMM) \
82073 - ((struct sock_filter_int) { \
82074 - .code = BPF_ST | BPF_SIZE(SIZE) | BPF_MEM, \
82075 - .dst_reg = DST, \
82076 - .src_reg = 0, \
82077 - .off = OFF, \
82078 - .imm = IMM })
82079 -
82080 -/* Conditional jumps against registers, if (dst_reg 'op' src_reg) goto pc + off16 */
82081 -
82082 -#define BPF_JMP_REG(OP, DST, SRC, OFF) \
82083 - ((struct sock_filter_int) { \
82084 - .code = BPF_JMP | BPF_OP(OP) | BPF_X, \
82085 - .dst_reg = DST, \
82086 - .src_reg = SRC, \
82087 - .off = OFF, \
82088 - .imm = 0 })
82089 -
82090 -/* Conditional jumps against immediates, if (dst_reg 'op' imm32) goto pc + off16 */
82091 -
82092 -#define BPF_JMP_IMM(OP, DST, IMM, OFF) \
82093 - ((struct sock_filter_int) { \
82094 - .code = BPF_JMP | BPF_OP(OP) | BPF_K, \
82095 - .dst_reg = DST, \
82096 - .src_reg = 0, \
82097 - .off = OFF, \
82098 - .imm = IMM })
82099 -
82100 -/* Function call */
82101 -
82102 -#define BPF_EMIT_CALL(FUNC) \
82103 - ((struct sock_filter_int) { \
82104 - .code = BPF_JMP | BPF_CALL, \
82105 - .dst_reg = 0, \
82106 - .src_reg = 0, \
82107 - .off = 0, \
82108 - .imm = ((FUNC) - __bpf_call_base) })
82109 -
82110 -/* Raw code statement block */
82111 -
82112 -#define BPF_RAW_INSN(CODE, DST, SRC, OFF, IMM) \
82113 - ((struct sock_filter_int) { \
82114 - .code = CODE, \
82115 - .dst_reg = DST, \
82116 - .src_reg = SRC, \
82117 - .off = OFF, \
82118 - .imm = IMM })
82119 -
82120 -/* Program exit */
82121 -
82122 -#define BPF_EXIT_INSN() \
82123 - ((struct sock_filter_int) { \
82124 - .code = BPF_JMP | BPF_EXIT, \
82125 - .dst_reg = 0, \
82126 - .src_reg = 0, \
82127 - .off = 0, \
82128 - .imm = 0 })
82129 -
82130 -#define bytes_to_bpf_size(bytes) \
82131 -({ \
82132 - int bpf_size = -EINVAL; \
82133 - \
82134 - if (bytes == sizeof(u8)) \
82135 - bpf_size = BPF_B; \
82136 - else if (bytes == sizeof(u16)) \
82137 - bpf_size = BPF_H; \
82138 - else if (bytes == sizeof(u32)) \
82139 - bpf_size = BPF_W; \
82140 - else if (bytes == sizeof(u64)) \
82141 - bpf_size = BPF_DW; \
82142 - \
82143 - bpf_size; \
82144 -})
82145 -
82146 -/* Macro to invoke filter function. */
82147 -#define SK_RUN_FILTER(filter, ctx) (*filter->bpf_func)(ctx, filter->insnsi)
82148 -
82149 -struct sock_filter_int {
82150 - __u8 code; /* opcode */
82151 - __u8 dst_reg:4; /* dest register */
82152 - __u8 src_reg:4; /* source register */
82153 - __s16 off; /* signed offset */
82154 - __s32 imm; /* signed immediate constant */
82155 -};
82156 -
82157 #ifdef CONFIG_COMPAT
82158 -/* A struct sock_filter is architecture independent. */
82159 +/*
82160 + * A struct sock_filter is architecture independent.
82161 + */
82162 struct compat_sock_fprog {
82163 u16 len;
82164 - compat_uptr_t filter; /* struct sock_filter * */
82165 + compat_uptr_t filter; /* struct sock_filter * */
82166 };
82167 #endif
82168
82169 -struct sock_fprog_kern {
82170 - u16 len;
82171 - struct sock_filter *filter;
82172 -};
82173 -
82174 struct sk_buff;
82175 struct sock;
82176 -struct seccomp_data;
82177
82178 -struct sk_filter {
82179 +struct sk_filter
82180 +{
82181 atomic_t refcnt;
82182 - u32 jited:1, /* Is our filter JIT'ed? */
82183 - len:31; /* Number of filter blocks */
82184 - struct sock_fprog_kern *orig_prog; /* Original BPF program */
82185 + unsigned int len; /* Number of filter blocks */
82186 struct rcu_head rcu;
82187 unsigned int (*bpf_func)(const struct sk_buff *skb,
82188 - const struct sock_filter_int *filter);
82189 + const struct sock_filter *filter);
82190 union {
82191 - struct sock_filter insns[0];
82192 - struct sock_filter_int insnsi[0];
82193 + struct sock_filter insns[0];
82194 struct work_struct work;
82195 };
82196 };
82197 @@ -343,76 +41,25 @@ static inline unsigned int sk_filter_size(unsigned int proglen)
82198 offsetof(struct sk_filter, insns[proglen]));
82199 }
82200
82201 -#define sk_filter_proglen(fprog) \
82202 - (fprog->len * sizeof(fprog->filter[0]))
82203 -
82204 -int sk_filter(struct sock *sk, struct sk_buff *skb);
82205 -
82206 -void sk_filter_select_runtime(struct sk_filter *fp);
82207 -void sk_filter_free(struct sk_filter *fp);
82208 -
82209 -int sk_convert_filter(struct sock_filter *prog, int len,
82210 - struct sock_filter_int *new_prog, int *new_len);
82211 -
82212 -int sk_unattached_filter_create(struct sk_filter **pfp,
82213 - struct sock_fprog_kern *fprog);
82214 -void sk_unattached_filter_destroy(struct sk_filter *fp);
82215 -
82216 -int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk);
82217 -int sk_detach_filter(struct sock *sk);
82218 -
82219 -int sk_chk_filter(struct sock_filter *filter, unsigned int flen);
82220 -int sk_get_filter(struct sock *sk, struct sock_filter __user *filter,
82221 - unsigned int len);
82222 -
82223 -void sk_filter_charge(struct sock *sk, struct sk_filter *fp);
82224 -void sk_filter_uncharge(struct sock *sk, struct sk_filter *fp);
82225 -
82226 -u64 __bpf_call_base(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5);
82227 -void bpf_int_jit_compile(struct sk_filter *fp);
82228 -
82229 -#define BPF_ANC BIT(15)
82230 -
82231 -static inline u16 bpf_anc_helper(const struct sock_filter *ftest)
82232 -{
82233 - BUG_ON(ftest->code & BPF_ANC);
82234 -
82235 - switch (ftest->code) {
82236 - case BPF_LD | BPF_W | BPF_ABS:
82237 - case BPF_LD | BPF_H | BPF_ABS:
82238 - case BPF_LD | BPF_B | BPF_ABS:
82239 -#define BPF_ANCILLARY(CODE) case SKF_AD_OFF + SKF_AD_##CODE: \
82240 - return BPF_ANC | SKF_AD_##CODE
82241 - switch (ftest->k) {
82242 - BPF_ANCILLARY(PROTOCOL);
82243 - BPF_ANCILLARY(PKTTYPE);
82244 - BPF_ANCILLARY(IFINDEX);
82245 - BPF_ANCILLARY(NLATTR);
82246 - BPF_ANCILLARY(NLATTR_NEST);
82247 - BPF_ANCILLARY(MARK);
82248 - BPF_ANCILLARY(QUEUE);
82249 - BPF_ANCILLARY(HATYPE);
82250 - BPF_ANCILLARY(RXHASH);
82251 - BPF_ANCILLARY(CPU);
82252 - BPF_ANCILLARY(ALU_XOR_X);
82253 - BPF_ANCILLARY(VLAN_TAG);
82254 - BPF_ANCILLARY(VLAN_TAG_PRESENT);
82255 - BPF_ANCILLARY(PAY_OFFSET);
82256 - BPF_ANCILLARY(RANDOM);
82257 - }
82258 - /* Fallthrough. */
82259 - default:
82260 - return ftest->code;
82261 - }
82262 -}
82263 +extern int sk_filter(struct sock *sk, struct sk_buff *skb);
82264 +extern unsigned int sk_run_filter(const struct sk_buff *skb,
82265 + const struct sock_filter *filter);
82266 +extern int sk_unattached_filter_create(struct sk_filter **pfp,
82267 + struct sock_fprog *fprog);
82268 +extern void sk_unattached_filter_destroy(struct sk_filter *fp);
82269 +extern int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk);
82270 +extern int sk_detach_filter(struct sock *sk);
82271 +extern int sk_chk_filter(struct sock_filter *filter, unsigned int flen);
82272 +extern int sk_get_filter(struct sock *sk, struct sock_filter __user *filter, unsigned len);
82273 +extern void sk_decode_filter(struct sock_filter *filt, struct sock_filter *to);
82274
82275 #ifdef CONFIG_BPF_JIT
82276 #include <stdarg.h>
82277 #include <linux/linkage.h>
82278 #include <linux/printk.h>
82279
82280 -void bpf_jit_compile(struct sk_filter *fp);
82281 -void bpf_jit_free(struct sk_filter *fp);
82282 +extern void bpf_jit_compile(struct sk_filter *fp);
82283 +extern void bpf_jit_free(struct sk_filter *fp);
82284
82285 static inline void bpf_jit_dump(unsigned int flen, unsigned int proglen,
82286 u32 pass, void *image)
82287 @@ -423,22 +70,90 @@ static inline void bpf_jit_dump(unsigned int flen, unsigned int proglen,
82288 print_hex_dump(KERN_ERR, "JIT code: ", DUMP_PREFIX_OFFSET,
82289 16, 1, image, proglen, false);
82290 }
82291 +#define SK_RUN_FILTER(FILTER, SKB) (*FILTER->bpf_func)(SKB, FILTER->insns)
82292 #else
82293 #include <linux/slab.h>
82294 -
82295 static inline void bpf_jit_compile(struct sk_filter *fp)
82296 {
82297 }
82298 -
82299 static inline void bpf_jit_free(struct sk_filter *fp)
82300 {
82301 kfree(fp);
82302 }
82303 -#endif /* CONFIG_BPF_JIT */
82304 +#define SK_RUN_FILTER(FILTER, SKB) sk_run_filter(SKB, FILTER->insns)
82305 +#endif
82306
82307 static inline int bpf_tell_extensions(void)
82308 {
82309 return SKF_AD_MAX;
82310 }
82311
82312 +enum {
82313 + BPF_S_RET_K = 1,
82314 + BPF_S_RET_A,
82315 + BPF_S_ALU_ADD_K,
82316 + BPF_S_ALU_ADD_X,
82317 + BPF_S_ALU_SUB_K,
82318 + BPF_S_ALU_SUB_X,
82319 + BPF_S_ALU_MUL_K,
82320 + BPF_S_ALU_MUL_X,
82321 + BPF_S_ALU_DIV_X,
82322 + BPF_S_ALU_MOD_K,
82323 + BPF_S_ALU_MOD_X,
82324 + BPF_S_ALU_AND_K,
82325 + BPF_S_ALU_AND_X,
82326 + BPF_S_ALU_OR_K,
82327 + BPF_S_ALU_OR_X,
82328 + BPF_S_ALU_XOR_K,
82329 + BPF_S_ALU_XOR_X,
82330 + BPF_S_ALU_LSH_K,
82331 + BPF_S_ALU_LSH_X,
82332 + BPF_S_ALU_RSH_K,
82333 + BPF_S_ALU_RSH_X,
82334 + BPF_S_ALU_NEG,
82335 + BPF_S_LD_W_ABS,
82336 + BPF_S_LD_H_ABS,
82337 + BPF_S_LD_B_ABS,
82338 + BPF_S_LD_W_LEN,
82339 + BPF_S_LD_W_IND,
82340 + BPF_S_LD_H_IND,
82341 + BPF_S_LD_B_IND,
82342 + BPF_S_LD_IMM,
82343 + BPF_S_LDX_W_LEN,
82344 + BPF_S_LDX_B_MSH,
82345 + BPF_S_LDX_IMM,
82346 + BPF_S_MISC_TAX,
82347 + BPF_S_MISC_TXA,
82348 + BPF_S_ALU_DIV_K,
82349 + BPF_S_LD_MEM,
82350 + BPF_S_LDX_MEM,
82351 + BPF_S_ST,
82352 + BPF_S_STX,
82353 + BPF_S_JMP_JA,
82354 + BPF_S_JMP_JEQ_K,
82355 + BPF_S_JMP_JEQ_X,
82356 + BPF_S_JMP_JGE_K,
82357 + BPF_S_JMP_JGE_X,
82358 + BPF_S_JMP_JGT_K,
82359 + BPF_S_JMP_JGT_X,
82360 + BPF_S_JMP_JSET_K,
82361 + BPF_S_JMP_JSET_X,
82362 + /* Ancillary data */
82363 + BPF_S_ANC_PROTOCOL,
82364 + BPF_S_ANC_PKTTYPE,
82365 + BPF_S_ANC_IFINDEX,
82366 + BPF_S_ANC_NLATTR,
82367 + BPF_S_ANC_NLATTR_NEST,
82368 + BPF_S_ANC_MARK,
82369 + BPF_S_ANC_QUEUE,
82370 + BPF_S_ANC_HATYPE,
82371 + BPF_S_ANC_RXHASH,
82372 + BPF_S_ANC_CPU,
82373 + BPF_S_ANC_ALU_XOR_X,
82374 + BPF_S_ANC_SECCOMP_LD_W,
82375 + BPF_S_ANC_VLAN_TAG,
82376 + BPF_S_ANC_VLAN_TAG_PRESENT,
82377 + BPF_S_ANC_PAY_OFFSET,
82378 +};
82379 +
82380 #endif /* __LINUX_FILTER_H__ */
82381 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
82382 index 8293262..2b3b8bd 100644
82383 --- a/include/linux/frontswap.h
82384 +++ b/include/linux/frontswap.h
82385 @@ -11,7 +11,7 @@ struct frontswap_ops {
82386 int (*load)(unsigned, pgoff_t, struct page *);
82387 void (*invalidate_page)(unsigned, pgoff_t);
82388 void (*invalidate_area)(unsigned);
82389 -};
82390 +} __no_const;
82391
82392 extern bool frontswap_enabled;
82393 extern struct frontswap_ops *
82394 diff --git a/include/linux/fs.h b/include/linux/fs.h
82395 index e11d60c..901317a 100644
82396 --- a/include/linux/fs.h
82397 +++ b/include/linux/fs.h
82398 @@ -401,7 +401,7 @@ struct address_space {
82399 spinlock_t private_lock; /* for use by the address_space */
82400 struct list_head private_list; /* ditto */
82401 void *private_data; /* ditto */
82402 -} __attribute__((aligned(sizeof(long))));
82403 +} __attribute__((aligned(sizeof(long)))) __randomize_layout;
82404 /*
82405 * On most architectures that alignment is already the case; but
82406 * must be enforced here for CRIS, to let the least significant bit
82407 @@ -444,7 +444,7 @@ struct block_device {
82408 int bd_fsfreeze_count;
82409 /* Mutex for freeze */
82410 struct mutex bd_fsfreeze_mutex;
82411 -};
82412 +} __randomize_layout;
82413
82414 /*
82415 * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
82416 @@ -588,7 +588,7 @@ struct inode {
82417 #endif
82418
82419 void *i_private; /* fs or device private pointer */
82420 -};
82421 +} __randomize_layout;
82422
82423 static inline int inode_unhashed(struct inode *inode)
82424 {
82425 @@ -781,7 +781,7 @@ struct file {
82426 struct list_head f_tfile_llink;
82427 #endif /* #ifdef CONFIG_EPOLL */
82428 struct address_space *f_mapping;
82429 -} __attribute__((aligned(4))); /* lest something weird decides that 2 is OK */
82430 +} __attribute__((aligned(4))) __randomize_layout; /* lest something weird decides that 2 is OK */
82431
82432 struct file_handle {
82433 __u32 handle_bytes;
82434 @@ -909,7 +909,7 @@ struct file_lock {
82435 int state; /* state of grant or error if -ve */
82436 } afs;
82437 } fl_u;
82438 -};
82439 +} __randomize_layout;
82440
82441 /* The following constant reflects the upper bound of the file/locking space */
82442 #ifndef OFFSET_MAX
82443 @@ -1258,7 +1258,7 @@ struct super_block {
82444 struct list_lru s_dentry_lru ____cacheline_aligned_in_smp;
82445 struct list_lru s_inode_lru ____cacheline_aligned_in_smp;
82446 struct rcu_head rcu;
82447 -};
82448 +} __randomize_layout;
82449
82450 extern struct timespec current_fs_time(struct super_block *sb);
82451
82452 @@ -1484,7 +1484,8 @@ struct file_operations {
82453 long (*fallocate)(struct file *file, int mode, loff_t offset,
82454 loff_t len);
82455 int (*show_fdinfo)(struct seq_file *m, struct file *f);
82456 -};
82457 +} __do_const __randomize_layout;
82458 +typedef struct file_operations __no_const file_operations_no_const;
82459
82460 struct inode_operations {
82461 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
82462 @@ -2769,4 +2770,14 @@ static inline bool dir_relax(struct inode *inode)
82463 return !IS_DEADDIR(inode);
82464 }
82465
82466 +static inline bool is_sidechannel_device(const struct inode *inode)
82467 +{
82468 +#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
82469 + umode_t mode = inode->i_mode;
82470 + return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
82471 +#else
82472 + return false;
82473 +#endif
82474 +}
82475 +
82476 #endif /* _LINUX_FS_H */
82477 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
82478 index 0efc3e6..fd23610 100644
82479 --- a/include/linux/fs_struct.h
82480 +++ b/include/linux/fs_struct.h
82481 @@ -6,13 +6,13 @@
82482 #include <linux/seqlock.h>
82483
82484 struct fs_struct {
82485 - int users;
82486 + atomic_t users;
82487 spinlock_t lock;
82488 seqcount_t seq;
82489 int umask;
82490 int in_exec;
82491 struct path root, pwd;
82492 -};
82493 +} __randomize_layout;
82494
82495 extern struct kmem_cache *fs_cachep;
82496
82497 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
82498 index 7714849..a4a5c7a 100644
82499 --- a/include/linux/fscache-cache.h
82500 +++ b/include/linux/fscache-cache.h
82501 @@ -113,7 +113,7 @@ struct fscache_operation {
82502 fscache_operation_release_t release;
82503 };
82504
82505 -extern atomic_t fscache_op_debug_id;
82506 +extern atomic_unchecked_t fscache_op_debug_id;
82507 extern void fscache_op_work_func(struct work_struct *work);
82508
82509 extern void fscache_enqueue_operation(struct fscache_operation *);
82510 @@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
82511 INIT_WORK(&op->work, fscache_op_work_func);
82512 atomic_set(&op->usage, 1);
82513 op->state = FSCACHE_OP_ST_INITIALISED;
82514 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
82515 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
82516 op->processor = processor;
82517 op->release = release;
82518 INIT_LIST_HEAD(&op->pend_link);
82519 diff --git a/include/linux/fscache.h b/include/linux/fscache.h
82520 index 115bb81..e7b812b 100644
82521 --- a/include/linux/fscache.h
82522 +++ b/include/linux/fscache.h
82523 @@ -152,7 +152,7 @@ struct fscache_cookie_def {
82524 * - this is mandatory for any object that may have data
82525 */
82526 void (*now_uncached)(void *cookie_netfs_data);
82527 -};
82528 +} __do_const;
82529
82530 /*
82531 * fscache cached network filesystem type
82532 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
82533 index 1c804b0..1432c2b 100644
82534 --- a/include/linux/fsnotify.h
82535 +++ b/include/linux/fsnotify.h
82536 @@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
82537 struct inode *inode = file_inode(file);
82538 __u32 mask = FS_ACCESS;
82539
82540 + if (is_sidechannel_device(inode))
82541 + return;
82542 +
82543 if (S_ISDIR(inode->i_mode))
82544 mask |= FS_ISDIR;
82545
82546 @@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
82547 struct inode *inode = file_inode(file);
82548 __u32 mask = FS_MODIFY;
82549
82550 + if (is_sidechannel_device(inode))
82551 + return;
82552 +
82553 if (S_ISDIR(inode->i_mode))
82554 mask |= FS_ISDIR;
82555
82556 @@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
82557 */
82558 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
82559 {
82560 - return kstrdup(name, GFP_KERNEL);
82561 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
82562 }
82563
82564 /*
82565 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
82566 index ec274e0..e678159 100644
82567 --- a/include/linux/genhd.h
82568 +++ b/include/linux/genhd.h
82569 @@ -194,7 +194,7 @@ struct gendisk {
82570 struct kobject *slave_dir;
82571
82572 struct timer_rand_state *random;
82573 - atomic_t sync_io; /* RAID */
82574 + atomic_unchecked_t sync_io; /* RAID */
82575 struct disk_events *ev;
82576 #ifdef CONFIG_BLK_DEV_INTEGRITY
82577 struct blk_integrity *integrity;
82578 @@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
82579 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
82580
82581 /* drivers/char/random.c */
82582 -extern void add_disk_randomness(struct gendisk *disk);
82583 +extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
82584 extern void rand_initialize_disk(struct gendisk *disk);
82585
82586 static inline sector_t get_start_sect(struct block_device *bdev)
82587 diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
82588 index c0894dd..2fbf10c 100644
82589 --- a/include/linux/genl_magic_func.h
82590 +++ b/include/linux/genl_magic_func.h
82591 @@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
82592 },
82593
82594 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
82595 -static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
82596 +static struct genl_ops ZZZ_genl_ops[] = {
82597 #include GENL_MAGIC_INCLUDE_FILE
82598 };
82599
82600 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
82601 index 6eb1fb3..30fe7e4 100644
82602 --- a/include/linux/gfp.h
82603 +++ b/include/linux/gfp.h
82604 @@ -34,6 +34,13 @@ struct vm_area_struct;
82605 #define ___GFP_NO_KSWAPD 0x400000u
82606 #define ___GFP_OTHER_NODE 0x800000u
82607 #define ___GFP_WRITE 0x1000000u
82608 +
82609 +#ifdef CONFIG_PAX_USERCOPY_SLABS
82610 +#define ___GFP_USERCOPY 0x2000000u
82611 +#else
82612 +#define ___GFP_USERCOPY 0
82613 +#endif
82614 +
82615 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
82616
82617 /*
82618 @@ -90,6 +97,7 @@ struct vm_area_struct;
82619 #define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
82620 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
82621 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
82622 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
82623
82624 /*
82625 * This may seem redundant, but it's a way of annotating false positives vs.
82626 @@ -97,7 +105,7 @@ struct vm_area_struct;
82627 */
82628 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
82629
82630 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
82631 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
82632 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
82633
82634 /* This equals 0, but use constants in case they ever change */
82635 @@ -155,6 +163,8 @@ struct vm_area_struct;
82636 /* 4GB DMA on some platforms */
82637 #define GFP_DMA32 __GFP_DMA32
82638
82639 +#define GFP_USERCOPY __GFP_USERCOPY
82640 +
82641 /* Convert GFP flags to their corresponding migrate type */
82642 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
82643 {
82644 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
82645 new file mode 100644
82646 index 0000000..edb2cb6
82647 --- /dev/null
82648 +++ b/include/linux/gracl.h
82649 @@ -0,0 +1,340 @@
82650 +#ifndef GR_ACL_H
82651 +#define GR_ACL_H
82652 +
82653 +#include <linux/grdefs.h>
82654 +#include <linux/resource.h>
82655 +#include <linux/capability.h>
82656 +#include <linux/dcache.h>
82657 +#include <asm/resource.h>
82658 +
82659 +/* Major status information */
82660 +
82661 +#define GR_VERSION "grsecurity 3.0"
82662 +#define GRSECURITY_VERSION 0x3000
82663 +
82664 +enum {
82665 + GR_SHUTDOWN = 0,
82666 + GR_ENABLE = 1,
82667 + GR_SPROLE = 2,
82668 + GR_OLDRELOAD = 3,
82669 + GR_SEGVMOD = 4,
82670 + GR_STATUS = 5,
82671 + GR_UNSPROLE = 6,
82672 + GR_PASSSET = 7,
82673 + GR_SPROLEPAM = 8,
82674 + GR_RELOAD = 9,
82675 +};
82676 +
82677 +/* Password setup definitions
82678 + * kernel/grhash.c */
82679 +enum {
82680 + GR_PW_LEN = 128,
82681 + GR_SALT_LEN = 16,
82682 + GR_SHA_LEN = 32,
82683 +};
82684 +
82685 +enum {
82686 + GR_SPROLE_LEN = 64,
82687 +};
82688 +
82689 +enum {
82690 + GR_NO_GLOB = 0,
82691 + GR_REG_GLOB,
82692 + GR_CREATE_GLOB
82693 +};
82694 +
82695 +#define GR_NLIMITS 32
82696 +
82697 +/* Begin Data Structures */
82698 +
82699 +struct sprole_pw {
82700 + unsigned char *rolename;
82701 + unsigned char salt[GR_SALT_LEN];
82702 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
82703 +};
82704 +
82705 +struct name_entry {
82706 + __u32 key;
82707 + ino_t inode;
82708 + dev_t device;
82709 + char *name;
82710 + __u16 len;
82711 + __u8 deleted;
82712 + struct name_entry *prev;
82713 + struct name_entry *next;
82714 +};
82715 +
82716 +struct inodev_entry {
82717 + struct name_entry *nentry;
82718 + struct inodev_entry *prev;
82719 + struct inodev_entry *next;
82720 +};
82721 +
82722 +struct acl_role_db {
82723 + struct acl_role_label **r_hash;
82724 + __u32 r_size;
82725 +};
82726 +
82727 +struct inodev_db {
82728 + struct inodev_entry **i_hash;
82729 + __u32 i_size;
82730 +};
82731 +
82732 +struct name_db {
82733 + struct name_entry **n_hash;
82734 + __u32 n_size;
82735 +};
82736 +
82737 +struct crash_uid {
82738 + uid_t uid;
82739 + unsigned long expires;
82740 +};
82741 +
82742 +struct gr_hash_struct {
82743 + void **table;
82744 + void **nametable;
82745 + void *first;
82746 + __u32 table_size;
82747 + __u32 used_size;
82748 + int type;
82749 +};
82750 +
82751 +/* Userspace Grsecurity ACL data structures */
82752 +
82753 +struct acl_subject_label {
82754 + char *filename;
82755 + ino_t inode;
82756 + dev_t device;
82757 + __u32 mode;
82758 + kernel_cap_t cap_mask;
82759 + kernel_cap_t cap_lower;
82760 + kernel_cap_t cap_invert_audit;
82761 +
82762 + struct rlimit res[GR_NLIMITS];
82763 + __u32 resmask;
82764 +
82765 + __u8 user_trans_type;
82766 + __u8 group_trans_type;
82767 + uid_t *user_transitions;
82768 + gid_t *group_transitions;
82769 + __u16 user_trans_num;
82770 + __u16 group_trans_num;
82771 +
82772 + __u32 sock_families[2];
82773 + __u32 ip_proto[8];
82774 + __u32 ip_type;
82775 + struct acl_ip_label **ips;
82776 + __u32 ip_num;
82777 + __u32 inaddr_any_override;
82778 +
82779 + __u32 crashes;
82780 + unsigned long expires;
82781 +
82782 + struct acl_subject_label *parent_subject;
82783 + struct gr_hash_struct *hash;
82784 + struct acl_subject_label *prev;
82785 + struct acl_subject_label *next;
82786 +
82787 + struct acl_object_label **obj_hash;
82788 + __u32 obj_hash_size;
82789 + __u16 pax_flags;
82790 +};
82791 +
82792 +struct role_allowed_ip {
82793 + __u32 addr;
82794 + __u32 netmask;
82795 +
82796 + struct role_allowed_ip *prev;
82797 + struct role_allowed_ip *next;
82798 +};
82799 +
82800 +struct role_transition {
82801 + char *rolename;
82802 +
82803 + struct role_transition *prev;
82804 + struct role_transition *next;
82805 +};
82806 +
82807 +struct acl_role_label {
82808 + char *rolename;
82809 + uid_t uidgid;
82810 + __u16 roletype;
82811 +
82812 + __u16 auth_attempts;
82813 + unsigned long expires;
82814 +
82815 + struct acl_subject_label *root_label;
82816 + struct gr_hash_struct *hash;
82817 +
82818 + struct acl_role_label *prev;
82819 + struct acl_role_label *next;
82820 +
82821 + struct role_transition *transitions;
82822 + struct role_allowed_ip *allowed_ips;
82823 + uid_t *domain_children;
82824 + __u16 domain_child_num;
82825 +
82826 + umode_t umask;
82827 +
82828 + struct acl_subject_label **subj_hash;
82829 + __u32 subj_hash_size;
82830 +};
82831 +
82832 +struct user_acl_role_db {
82833 + struct acl_role_label **r_table;
82834 + __u32 num_pointers; /* Number of allocations to track */
82835 + __u32 num_roles; /* Number of roles */
82836 + __u32 num_domain_children; /* Number of domain children */
82837 + __u32 num_subjects; /* Number of subjects */
82838 + __u32 num_objects; /* Number of objects */
82839 +};
82840 +
82841 +struct acl_object_label {
82842 + char *filename;
82843 + ino_t inode;
82844 + dev_t device;
82845 + __u32 mode;
82846 +
82847 + struct acl_subject_label *nested;
82848 + struct acl_object_label *globbed;
82849 +
82850 + /* next two structures not used */
82851 +
82852 + struct acl_object_label *prev;
82853 + struct acl_object_label *next;
82854 +};
82855 +
82856 +struct acl_ip_label {
82857 + char *iface;
82858 + __u32 addr;
82859 + __u32 netmask;
82860 + __u16 low, high;
82861 + __u8 mode;
82862 + __u32 type;
82863 + __u32 proto[8];
82864 +
82865 + /* next two structures not used */
82866 +
82867 + struct acl_ip_label *prev;
82868 + struct acl_ip_label *next;
82869 +};
82870 +
82871 +struct gr_arg {
82872 + struct user_acl_role_db role_db;
82873 + unsigned char pw[GR_PW_LEN];
82874 + unsigned char salt[GR_SALT_LEN];
82875 + unsigned char sum[GR_SHA_LEN];
82876 + unsigned char sp_role[GR_SPROLE_LEN];
82877 + struct sprole_pw *sprole_pws;
82878 + dev_t segv_device;
82879 + ino_t segv_inode;
82880 + uid_t segv_uid;
82881 + __u16 num_sprole_pws;
82882 + __u16 mode;
82883 +};
82884 +
82885 +struct gr_arg_wrapper {
82886 + struct gr_arg *arg;
82887 + __u32 version;
82888 + __u32 size;
82889 +};
82890 +
82891 +struct subject_map {
82892 + struct acl_subject_label *user;
82893 + struct acl_subject_label *kernel;
82894 + struct subject_map *prev;
82895 + struct subject_map *next;
82896 +};
82897 +
82898 +struct acl_subj_map_db {
82899 + struct subject_map **s_hash;
82900 + __u32 s_size;
82901 +};
82902 +
82903 +struct gr_policy_state {
82904 + struct sprole_pw **acl_special_roles;
82905 + __u16 num_sprole_pws;
82906 + struct acl_role_label *kernel_role;
82907 + struct acl_role_label *role_list;
82908 + struct acl_role_label *default_role;
82909 + struct acl_role_db acl_role_set;
82910 + struct acl_subj_map_db subj_map_set;
82911 + struct name_db name_set;
82912 + struct inodev_db inodev_set;
82913 +};
82914 +
82915 +struct gr_alloc_state {
82916 + unsigned long alloc_stack_next;
82917 + unsigned long alloc_stack_size;
82918 + void **alloc_stack;
82919 +};
82920 +
82921 +struct gr_reload_state {
82922 + struct gr_policy_state oldpolicy;
82923 + struct gr_alloc_state oldalloc;
82924 + struct gr_policy_state newpolicy;
82925 + struct gr_alloc_state newalloc;
82926 + struct gr_policy_state *oldpolicy_ptr;
82927 + struct gr_alloc_state *oldalloc_ptr;
82928 + unsigned char oldmode;
82929 +};
82930 +
82931 +/* End Data Structures Section */
82932 +
82933 +/* Hash functions generated by empirical testing by Brad Spengler
82934 + Makes good use of the low bits of the inode. Generally 0-1 times
82935 + in loop for successful match. 0-3 for unsuccessful match.
82936 + Shift/add algorithm with modulus of table size and an XOR*/
82937 +
82938 +static __inline__ unsigned int
82939 +gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
82940 +{
82941 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
82942 +}
82943 +
82944 + static __inline__ unsigned int
82945 +gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
82946 +{
82947 + return ((const unsigned long)userp % sz);
82948 +}
82949 +
82950 +static __inline__ unsigned int
82951 +gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
82952 +{
82953 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
82954 +}
82955 +
82956 +static __inline__ unsigned int
82957 +gr_nhash(const char *name, const __u16 len, const unsigned int sz)
82958 +{
82959 + return full_name_hash((const unsigned char *)name, len) % sz;
82960 +}
82961 +
82962 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
82963 + subj = NULL; \
82964 + iter = 0; \
82965 + while (iter < role->subj_hash_size) { \
82966 + if (subj == NULL) \
82967 + subj = role->subj_hash[iter]; \
82968 + if (subj == NULL) { \
82969 + iter++; \
82970 + continue; \
82971 + }
82972 +
82973 +#define FOR_EACH_SUBJECT_END(subj,iter) \
82974 + subj = subj->next; \
82975 + if (subj == NULL) \
82976 + iter++; \
82977 + }
82978 +
82979 +
82980 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
82981 + subj = role->hash->first; \
82982 + while (subj != NULL) {
82983 +
82984 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
82985 + subj = subj->next; \
82986 + }
82987 +
82988 +#endif
82989 +
82990 diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
82991 new file mode 100644
82992 index 0000000..33ebd1f
82993 --- /dev/null
82994 +++ b/include/linux/gracl_compat.h
82995 @@ -0,0 +1,156 @@
82996 +#ifndef GR_ACL_COMPAT_H
82997 +#define GR_ACL_COMPAT_H
82998 +
82999 +#include <linux/resource.h>
83000 +#include <asm/resource.h>
83001 +
83002 +struct sprole_pw_compat {
83003 + compat_uptr_t rolename;
83004 + unsigned char salt[GR_SALT_LEN];
83005 + unsigned char sum[GR_SHA_LEN];
83006 +};
83007 +
83008 +struct gr_hash_struct_compat {
83009 + compat_uptr_t table;
83010 + compat_uptr_t nametable;
83011 + compat_uptr_t first;
83012 + __u32 table_size;
83013 + __u32 used_size;
83014 + int type;
83015 +};
83016 +
83017 +struct acl_subject_label_compat {
83018 + compat_uptr_t filename;
83019 + compat_ino_t inode;
83020 + __u32 device;
83021 + __u32 mode;
83022 + kernel_cap_t cap_mask;
83023 + kernel_cap_t cap_lower;
83024 + kernel_cap_t cap_invert_audit;
83025 +
83026 + struct compat_rlimit res[GR_NLIMITS];
83027 + __u32 resmask;
83028 +
83029 + __u8 user_trans_type;
83030 + __u8 group_trans_type;
83031 + compat_uptr_t user_transitions;
83032 + compat_uptr_t group_transitions;
83033 + __u16 user_trans_num;
83034 + __u16 group_trans_num;
83035 +
83036 + __u32 sock_families[2];
83037 + __u32 ip_proto[8];
83038 + __u32 ip_type;
83039 + compat_uptr_t ips;
83040 + __u32 ip_num;
83041 + __u32 inaddr_any_override;
83042 +
83043 + __u32 crashes;
83044 + compat_ulong_t expires;
83045 +
83046 + compat_uptr_t parent_subject;
83047 + compat_uptr_t hash;
83048 + compat_uptr_t prev;
83049 + compat_uptr_t next;
83050 +
83051 + compat_uptr_t obj_hash;
83052 + __u32 obj_hash_size;
83053 + __u16 pax_flags;
83054 +};
83055 +
83056 +struct role_allowed_ip_compat {
83057 + __u32 addr;
83058 + __u32 netmask;
83059 +
83060 + compat_uptr_t prev;
83061 + compat_uptr_t next;
83062 +};
83063 +
83064 +struct role_transition_compat {
83065 + compat_uptr_t rolename;
83066 +
83067 + compat_uptr_t prev;
83068 + compat_uptr_t next;
83069 +};
83070 +
83071 +struct acl_role_label_compat {
83072 + compat_uptr_t rolename;
83073 + uid_t uidgid;
83074 + __u16 roletype;
83075 +
83076 + __u16 auth_attempts;
83077 + compat_ulong_t expires;
83078 +
83079 + compat_uptr_t root_label;
83080 + compat_uptr_t hash;
83081 +
83082 + compat_uptr_t prev;
83083 + compat_uptr_t next;
83084 +
83085 + compat_uptr_t transitions;
83086 + compat_uptr_t allowed_ips;
83087 + compat_uptr_t domain_children;
83088 + __u16 domain_child_num;
83089 +
83090 + umode_t umask;
83091 +
83092 + compat_uptr_t subj_hash;
83093 + __u32 subj_hash_size;
83094 +};
83095 +
83096 +struct user_acl_role_db_compat {
83097 + compat_uptr_t r_table;
83098 + __u32 num_pointers;
83099 + __u32 num_roles;
83100 + __u32 num_domain_children;
83101 + __u32 num_subjects;
83102 + __u32 num_objects;
83103 +};
83104 +
83105 +struct acl_object_label_compat {
83106 + compat_uptr_t filename;
83107 + compat_ino_t inode;
83108 + __u32 device;
83109 + __u32 mode;
83110 +
83111 + compat_uptr_t nested;
83112 + compat_uptr_t globbed;
83113 +
83114 + compat_uptr_t prev;
83115 + compat_uptr_t next;
83116 +};
83117 +
83118 +struct acl_ip_label_compat {
83119 + compat_uptr_t iface;
83120 + __u32 addr;
83121 + __u32 netmask;
83122 + __u16 low, high;
83123 + __u8 mode;
83124 + __u32 type;
83125 + __u32 proto[8];
83126 +
83127 + compat_uptr_t prev;
83128 + compat_uptr_t next;
83129 +};
83130 +
83131 +struct gr_arg_compat {
83132 + struct user_acl_role_db_compat role_db;
83133 + unsigned char pw[GR_PW_LEN];
83134 + unsigned char salt[GR_SALT_LEN];
83135 + unsigned char sum[GR_SHA_LEN];
83136 + unsigned char sp_role[GR_SPROLE_LEN];
83137 + compat_uptr_t sprole_pws;
83138 + __u32 segv_device;
83139 + compat_ino_t segv_inode;
83140 + uid_t segv_uid;
83141 + __u16 num_sprole_pws;
83142 + __u16 mode;
83143 +};
83144 +
83145 +struct gr_arg_wrapper_compat {
83146 + compat_uptr_t arg;
83147 + __u32 version;
83148 + __u32 size;
83149 +};
83150 +
83151 +#endif
83152 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
83153 new file mode 100644
83154 index 0000000..323ecf2
83155 --- /dev/null
83156 +++ b/include/linux/gralloc.h
83157 @@ -0,0 +1,9 @@
83158 +#ifndef __GRALLOC_H
83159 +#define __GRALLOC_H
83160 +
83161 +void acl_free_all(void);
83162 +int acl_alloc_stack_init(unsigned long size);
83163 +void *acl_alloc(unsigned long len);
83164 +void *acl_alloc_num(unsigned long num, unsigned long len);
83165 +
83166 +#endif
83167 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
83168 new file mode 100644
83169 index 0000000..be66033
83170 --- /dev/null
83171 +++ b/include/linux/grdefs.h
83172 @@ -0,0 +1,140 @@
83173 +#ifndef GRDEFS_H
83174 +#define GRDEFS_H
83175 +
83176 +/* Begin grsecurity status declarations */
83177 +
83178 +enum {
83179 + GR_READY = 0x01,
83180 + GR_STATUS_INIT = 0x00 // disabled state
83181 +};
83182 +
83183 +/* Begin ACL declarations */
83184 +
83185 +/* Role flags */
83186 +
83187 +enum {
83188 + GR_ROLE_USER = 0x0001,
83189 + GR_ROLE_GROUP = 0x0002,
83190 + GR_ROLE_DEFAULT = 0x0004,
83191 + GR_ROLE_SPECIAL = 0x0008,
83192 + GR_ROLE_AUTH = 0x0010,
83193 + GR_ROLE_NOPW = 0x0020,
83194 + GR_ROLE_GOD = 0x0040,
83195 + GR_ROLE_LEARN = 0x0080,
83196 + GR_ROLE_TPE = 0x0100,
83197 + GR_ROLE_DOMAIN = 0x0200,
83198 + GR_ROLE_PAM = 0x0400,
83199 + GR_ROLE_PERSIST = 0x0800
83200 +};
83201 +
83202 +/* ACL Subject and Object mode flags */
83203 +enum {
83204 + GR_DELETED = 0x80000000
83205 +};
83206 +
83207 +/* ACL Object-only mode flags */
83208 +enum {
83209 + GR_READ = 0x00000001,
83210 + GR_APPEND = 0x00000002,
83211 + GR_WRITE = 0x00000004,
83212 + GR_EXEC = 0x00000008,
83213 + GR_FIND = 0x00000010,
83214 + GR_INHERIT = 0x00000020,
83215 + GR_SETID = 0x00000040,
83216 + GR_CREATE = 0x00000080,
83217 + GR_DELETE = 0x00000100,
83218 + GR_LINK = 0x00000200,
83219 + GR_AUDIT_READ = 0x00000400,
83220 + GR_AUDIT_APPEND = 0x00000800,
83221 + GR_AUDIT_WRITE = 0x00001000,
83222 + GR_AUDIT_EXEC = 0x00002000,
83223 + GR_AUDIT_FIND = 0x00004000,
83224 + GR_AUDIT_INHERIT= 0x00008000,
83225 + GR_AUDIT_SETID = 0x00010000,
83226 + GR_AUDIT_CREATE = 0x00020000,
83227 + GR_AUDIT_DELETE = 0x00040000,
83228 + GR_AUDIT_LINK = 0x00080000,
83229 + GR_PTRACERD = 0x00100000,
83230 + GR_NOPTRACE = 0x00200000,
83231 + GR_SUPPRESS = 0x00400000,
83232 + GR_NOLEARN = 0x00800000,
83233 + GR_INIT_TRANSFER= 0x01000000
83234 +};
83235 +
83236 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
83237 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
83238 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
83239 +
83240 +/* ACL subject-only mode flags */
83241 +enum {
83242 + GR_KILL = 0x00000001,
83243 + GR_VIEW = 0x00000002,
83244 + GR_PROTECTED = 0x00000004,
83245 + GR_LEARN = 0x00000008,
83246 + GR_OVERRIDE = 0x00000010,
83247 + /* just a placeholder, this mode is only used in userspace */
83248 + GR_DUMMY = 0x00000020,
83249 + GR_PROTSHM = 0x00000040,
83250 + GR_KILLPROC = 0x00000080,
83251 + GR_KILLIPPROC = 0x00000100,
83252 + /* just a placeholder, this mode is only used in userspace */
83253 + GR_NOTROJAN = 0x00000200,
83254 + GR_PROTPROCFD = 0x00000400,
83255 + GR_PROCACCT = 0x00000800,
83256 + GR_RELAXPTRACE = 0x00001000,
83257 + //GR_NESTED = 0x00002000,
83258 + GR_INHERITLEARN = 0x00004000,
83259 + GR_PROCFIND = 0x00008000,
83260 + GR_POVERRIDE = 0x00010000,
83261 + GR_KERNELAUTH = 0x00020000,
83262 + GR_ATSECURE = 0x00040000,
83263 + GR_SHMEXEC = 0x00080000
83264 +};
83265 +
83266 +enum {
83267 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
83268 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
83269 + GR_PAX_ENABLE_MPROTECT = 0x0004,
83270 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
83271 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
83272 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
83273 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
83274 + GR_PAX_DISABLE_MPROTECT = 0x0400,
83275 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
83276 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
83277 +};
83278 +
83279 +enum {
83280 + GR_ID_USER = 0x01,
83281 + GR_ID_GROUP = 0x02,
83282 +};
83283 +
83284 +enum {
83285 + GR_ID_ALLOW = 0x01,
83286 + GR_ID_DENY = 0x02,
83287 +};
83288 +
83289 +#define GR_CRASH_RES 31
83290 +#define GR_UIDTABLE_MAX 500
83291 +
83292 +/* begin resource learning section */
83293 +enum {
83294 + GR_RLIM_CPU_BUMP = 60,
83295 + GR_RLIM_FSIZE_BUMP = 50000,
83296 + GR_RLIM_DATA_BUMP = 10000,
83297 + GR_RLIM_STACK_BUMP = 1000,
83298 + GR_RLIM_CORE_BUMP = 10000,
83299 + GR_RLIM_RSS_BUMP = 500000,
83300 + GR_RLIM_NPROC_BUMP = 1,
83301 + GR_RLIM_NOFILE_BUMP = 5,
83302 + GR_RLIM_MEMLOCK_BUMP = 50000,
83303 + GR_RLIM_AS_BUMP = 500000,
83304 + GR_RLIM_LOCKS_BUMP = 2,
83305 + GR_RLIM_SIGPENDING_BUMP = 5,
83306 + GR_RLIM_MSGQUEUE_BUMP = 10000,
83307 + GR_RLIM_NICE_BUMP = 1,
83308 + GR_RLIM_RTPRIO_BUMP = 1,
83309 + GR_RLIM_RTTIME_BUMP = 1000000
83310 +};
83311 +
83312 +#endif
83313 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
83314 new file mode 100644
83315 index 0000000..d25522e
83316 --- /dev/null
83317 +++ b/include/linux/grinternal.h
83318 @@ -0,0 +1,229 @@
83319 +#ifndef __GRINTERNAL_H
83320 +#define __GRINTERNAL_H
83321 +
83322 +#ifdef CONFIG_GRKERNSEC
83323 +
83324 +#include <linux/fs.h>
83325 +#include <linux/mnt_namespace.h>
83326 +#include <linux/nsproxy.h>
83327 +#include <linux/gracl.h>
83328 +#include <linux/grdefs.h>
83329 +#include <linux/grmsg.h>
83330 +
83331 +void gr_add_learn_entry(const char *fmt, ...)
83332 + __attribute__ ((format (printf, 1, 2)));
83333 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
83334 + const struct vfsmount *mnt);
83335 +__u32 gr_check_create(const struct dentry *new_dentry,
83336 + const struct dentry *parent,
83337 + const struct vfsmount *mnt, const __u32 mode);
83338 +int gr_check_protected_task(const struct task_struct *task);
83339 +__u32 to_gr_audit(const __u32 reqmode);
83340 +int gr_set_acls(const int type);
83341 +int gr_acl_is_enabled(void);
83342 +char gr_roletype_to_char(void);
83343 +
83344 +void gr_handle_alertkill(struct task_struct *task);
83345 +char *gr_to_filename(const struct dentry *dentry,
83346 + const struct vfsmount *mnt);
83347 +char *gr_to_filename1(const struct dentry *dentry,
83348 + const struct vfsmount *mnt);
83349 +char *gr_to_filename2(const struct dentry *dentry,
83350 + const struct vfsmount *mnt);
83351 +char *gr_to_filename3(const struct dentry *dentry,
83352 + const struct vfsmount *mnt);
83353 +
83354 +extern int grsec_enable_ptrace_readexec;
83355 +extern int grsec_enable_harden_ptrace;
83356 +extern int grsec_enable_link;
83357 +extern int grsec_enable_fifo;
83358 +extern int grsec_enable_execve;
83359 +extern int grsec_enable_shm;
83360 +extern int grsec_enable_execlog;
83361 +extern int grsec_enable_signal;
83362 +extern int grsec_enable_audit_ptrace;
83363 +extern int grsec_enable_forkfail;
83364 +extern int grsec_enable_time;
83365 +extern int grsec_enable_rofs;
83366 +extern int grsec_deny_new_usb;
83367 +extern int grsec_enable_chroot_shmat;
83368 +extern int grsec_enable_chroot_mount;
83369 +extern int grsec_enable_chroot_double;
83370 +extern int grsec_enable_chroot_pivot;
83371 +extern int grsec_enable_chroot_chdir;
83372 +extern int grsec_enable_chroot_chmod;
83373 +extern int grsec_enable_chroot_mknod;
83374 +extern int grsec_enable_chroot_fchdir;
83375 +extern int grsec_enable_chroot_nice;
83376 +extern int grsec_enable_chroot_execlog;
83377 +extern int grsec_enable_chroot_caps;
83378 +extern int grsec_enable_chroot_sysctl;
83379 +extern int grsec_enable_chroot_unix;
83380 +extern int grsec_enable_symlinkown;
83381 +extern kgid_t grsec_symlinkown_gid;
83382 +extern int grsec_enable_tpe;
83383 +extern kgid_t grsec_tpe_gid;
83384 +extern int grsec_enable_tpe_all;
83385 +extern int grsec_enable_tpe_invert;
83386 +extern int grsec_enable_socket_all;
83387 +extern kgid_t grsec_socket_all_gid;
83388 +extern int grsec_enable_socket_client;
83389 +extern kgid_t grsec_socket_client_gid;
83390 +extern int grsec_enable_socket_server;
83391 +extern kgid_t grsec_socket_server_gid;
83392 +extern kgid_t grsec_audit_gid;
83393 +extern int grsec_enable_group;
83394 +extern int grsec_enable_log_rwxmaps;
83395 +extern int grsec_enable_mount;
83396 +extern int grsec_enable_chdir;
83397 +extern int grsec_resource_logging;
83398 +extern int grsec_enable_blackhole;
83399 +extern int grsec_lastack_retries;
83400 +extern int grsec_enable_brute;
83401 +extern int grsec_enable_harden_ipc;
83402 +extern int grsec_lock;
83403 +
83404 +extern spinlock_t grsec_alert_lock;
83405 +extern unsigned long grsec_alert_wtime;
83406 +extern unsigned long grsec_alert_fyet;
83407 +
83408 +extern spinlock_t grsec_audit_lock;
83409 +
83410 +extern rwlock_t grsec_exec_file_lock;
83411 +
83412 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
83413 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
83414 + (tsk)->exec_file->f_path.mnt) : "/")
83415 +
83416 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
83417 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
83418 + (tsk)->real_parent->exec_file->f_path.mnt) : "/")
83419 +
83420 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
83421 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
83422 + (tsk)->exec_file->f_path.mnt) : "/")
83423 +
83424 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
83425 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
83426 + (tsk)->real_parent->exec_file->f_path.mnt) : "/")
83427 +
83428 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
83429 +
83430 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
83431 +
83432 +static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
83433 +{
83434 + if (file1 && file2) {
83435 + const struct inode *inode1 = file1->f_path.dentry->d_inode;
83436 + const struct inode *inode2 = file2->f_path.dentry->d_inode;
83437 + if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
83438 + return true;
83439 + }
83440 +
83441 + return false;
83442 +}
83443 +
83444 +#define GR_CHROOT_CAPS {{ \
83445 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
83446 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
83447 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
83448 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
83449 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
83450 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
83451 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
83452 +
83453 +#define security_learn(normal_msg,args...) \
83454 +({ \
83455 + read_lock(&grsec_exec_file_lock); \
83456 + gr_add_learn_entry(normal_msg "\n", ## args); \
83457 + read_unlock(&grsec_exec_file_lock); \
83458 +})
83459 +
83460 +enum {
83461 + GR_DO_AUDIT,
83462 + GR_DONT_AUDIT,
83463 + /* used for non-audit messages that we shouldn't kill the task on */
83464 + GR_DONT_AUDIT_GOOD
83465 +};
83466 +
83467 +enum {
83468 + GR_TTYSNIFF,
83469 + GR_RBAC,
83470 + GR_RBAC_STR,
83471 + GR_STR_RBAC,
83472 + GR_RBAC_MODE2,
83473 + GR_RBAC_MODE3,
83474 + GR_FILENAME,
83475 + GR_SYSCTL_HIDDEN,
83476 + GR_NOARGS,
83477 + GR_ONE_INT,
83478 + GR_ONE_INT_TWO_STR,
83479 + GR_ONE_STR,
83480 + GR_STR_INT,
83481 + GR_TWO_STR_INT,
83482 + GR_TWO_INT,
83483 + GR_TWO_U64,
83484 + GR_THREE_INT,
83485 + GR_FIVE_INT_TWO_STR,
83486 + GR_TWO_STR,
83487 + GR_THREE_STR,
83488 + GR_FOUR_STR,
83489 + GR_STR_FILENAME,
83490 + GR_FILENAME_STR,
83491 + GR_FILENAME_TWO_INT,
83492 + GR_FILENAME_TWO_INT_STR,
83493 + GR_TEXTREL,
83494 + GR_PTRACE,
83495 + GR_RESOURCE,
83496 + GR_CAP,
83497 + GR_SIG,
83498 + GR_SIG2,
83499 + GR_CRASH1,
83500 + GR_CRASH2,
83501 + GR_PSACCT,
83502 + GR_RWXMAP,
83503 + GR_RWXMAPVMA
83504 +};
83505 +
83506 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
83507 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
83508 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
83509 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
83510 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
83511 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
83512 +#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)
83513 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
83514 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
83515 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
83516 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
83517 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
83518 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
83519 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
83520 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
83521 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
83522 +#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)
83523 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
83524 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
83525 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
83526 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
83527 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
83528 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
83529 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
83530 +#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)
83531 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
83532 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
83533 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
83534 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
83535 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
83536 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
83537 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
83538 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
83539 +#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)
83540 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
83541 +#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
83542 +
83543 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
83544 +
83545 +#endif
83546 +
83547 +#endif
83548 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
83549 new file mode 100644
83550 index 0000000..b02ba9d
83551 --- /dev/null
83552 +++ b/include/linux/grmsg.h
83553 @@ -0,0 +1,117 @@
83554 +#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"
83555 +#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"
83556 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
83557 +#define GR_STOPMOD_MSG "denied modification of module state by "
83558 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
83559 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
83560 +#define GR_IOPERM_MSG "denied use of ioperm() by "
83561 +#define GR_IOPL_MSG "denied use of iopl() by "
83562 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
83563 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
83564 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
83565 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
83566 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
83567 +#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"
83568 +#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"
83569 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
83570 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
83571 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
83572 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
83573 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
83574 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
83575 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
83576 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
83577 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
83578 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
83579 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
83580 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
83581 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
83582 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
83583 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
83584 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
83585 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
83586 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
83587 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
83588 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
83589 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
83590 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
83591 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
83592 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
83593 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
83594 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
83595 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
83596 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
83597 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
83598 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
83599 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
83600 +#define GR_CHROOT_FHANDLE_MSG "denied use of file handles inside chroot by "
83601 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
83602 +#define GR_SETXATTR_ACL_MSG "%s setting extended attribute of %.950s by "
83603 +#define GR_REMOVEXATTR_ACL_MSG "%s removing extended attribute of %.950s by "
83604 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
83605 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
83606 +#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"
83607 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
83608 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
83609 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
83610 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
83611 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
83612 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
83613 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
83614 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
83615 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
83616 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
83617 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
83618 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
83619 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
83620 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
83621 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
83622 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
83623 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
83624 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
83625 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
83626 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
83627 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
83628 +#define GR_NICE_CHROOT_MSG "denied priority change by "
83629 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
83630 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
83631 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
83632 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
83633 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
83634 +#define GR_TIME_MSG "time set by "
83635 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
83636 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
83637 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
83638 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
83639 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
83640 +#define GR_BIND_MSG "denied bind() by "
83641 +#define GR_CONNECT_MSG "denied connect() by "
83642 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
83643 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
83644 +#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"
83645 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
83646 +#define GR_CAP_ACL_MSG "use of %s denied for "
83647 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
83648 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
83649 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
83650 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
83651 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
83652 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
83653 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
83654 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
83655 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
83656 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
83657 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
83658 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
83659 +#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
83660 +#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
83661 +#define GR_VM86_MSG "denied use of vm86 by "
83662 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
83663 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
83664 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
83665 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
83666 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
83667 +#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 "
83668 +#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 "
83669 +#define GR_IPC_DENIED_MSG "denied %s of overly-permissive IPC object with creator uid %u by "
83670 +#define GR_MSRWRITE_MSG "denied write to CPU MSR by "
83671 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
83672 new file mode 100644
83673 index 0000000..10b9635
83674 --- /dev/null
83675 +++ b/include/linux/grsecurity.h
83676 @@ -0,0 +1,254 @@
83677 +#ifndef GR_SECURITY_H
83678 +#define GR_SECURITY_H
83679 +#include <linux/fs.h>
83680 +#include <linux/fs_struct.h>
83681 +#include <linux/binfmts.h>
83682 +#include <linux/gracl.h>
83683 +
83684 +/* notify of brain-dead configs */
83685 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
83686 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
83687 +#endif
83688 +#if defined(CONFIG_GRKERNSEC_PROC) && !defined(CONFIG_GRKERNSEC_PROC_USER) && !defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
83689 +#error "CONFIG_GRKERNSEC_PROC enabled, but neither CONFIG_GRKERNSEC_PROC_USER nor CONFIG_GRKERNSEC_PROC_USERGROUP enabled"
83690 +#endif
83691 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
83692 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
83693 +#endif
83694 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
83695 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
83696 +#endif
83697 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
83698 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
83699 +#endif
83700 +
83701 +int gr_handle_new_usb(void);
83702 +
83703 +void gr_handle_brute_attach(int dumpable);
83704 +void gr_handle_brute_check(void);
83705 +void gr_handle_kernel_exploit(void);
83706 +
83707 +char gr_roletype_to_char(void);
83708 +
83709 +int gr_proc_is_restricted(void);
83710 +
83711 +int gr_acl_enable_at_secure(void);
83712 +
83713 +int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
83714 +int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
83715 +
83716 +int gr_learn_cap(const struct task_struct *task, const struct cred *cred, const int cap);
83717 +
83718 +void gr_del_task_from_ip_table(struct task_struct *p);
83719 +
83720 +int gr_pid_is_chrooted(struct task_struct *p);
83721 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
83722 +int gr_handle_chroot_nice(void);
83723 +int gr_handle_chroot_sysctl(const int op);
83724 +int gr_handle_chroot_setpriority(struct task_struct *p,
83725 + const int niceval);
83726 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
83727 +int gr_chroot_fhandle(void);
83728 +int gr_handle_chroot_chroot(const struct dentry *dentry,
83729 + const struct vfsmount *mnt);
83730 +void gr_handle_chroot_chdir(const struct path *path);
83731 +int gr_handle_chroot_chmod(const struct dentry *dentry,
83732 + const struct vfsmount *mnt, const int mode);
83733 +int gr_handle_chroot_mknod(const struct dentry *dentry,
83734 + const struct vfsmount *mnt, const int mode);
83735 +int gr_handle_chroot_mount(const struct dentry *dentry,
83736 + const struct vfsmount *mnt,
83737 + const char *dev_name);
83738 +int gr_handle_chroot_pivot(void);
83739 +int gr_handle_chroot_unix(const pid_t pid);
83740 +
83741 +int gr_handle_rawio(const struct inode *inode);
83742 +
83743 +void gr_handle_ioperm(void);
83744 +void gr_handle_iopl(void);
83745 +void gr_handle_msr_write(void);
83746 +
83747 +umode_t gr_acl_umask(void);
83748 +
83749 +int gr_tpe_allow(const struct file *file);
83750 +
83751 +void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
83752 +void gr_clear_chroot_entries(struct task_struct *task);
83753 +
83754 +void gr_log_forkfail(const int retval);
83755 +void gr_log_timechange(void);
83756 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
83757 +void gr_log_chdir(const struct dentry *dentry,
83758 + const struct vfsmount *mnt);
83759 +void gr_log_chroot_exec(const struct dentry *dentry,
83760 + const struct vfsmount *mnt);
83761 +void gr_log_remount(const char *devname, const int retval);
83762 +void gr_log_unmount(const char *devname, const int retval);
83763 +void gr_log_mount(const char *from, const char *to, const int retval);
83764 +void gr_log_textrel(struct vm_area_struct *vma);
83765 +void gr_log_ptgnustack(struct file *file);
83766 +void gr_log_rwxmmap(struct file *file);
83767 +void gr_log_rwxmprotect(struct vm_area_struct *vma);
83768 +
83769 +int gr_handle_follow_link(const struct inode *parent,
83770 + const struct inode *inode,
83771 + const struct dentry *dentry,
83772 + const struct vfsmount *mnt);
83773 +int gr_handle_fifo(const struct dentry *dentry,
83774 + const struct vfsmount *mnt,
83775 + const struct dentry *dir, const int flag,
83776 + const int acc_mode);
83777 +int gr_handle_hardlink(const struct dentry *dentry,
83778 + const struct vfsmount *mnt,
83779 + struct inode *inode,
83780 + const int mode, const struct filename *to);
83781 +
83782 +int gr_is_capable(const int cap);
83783 +int gr_is_capable_nolog(const int cap);
83784 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
83785 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
83786 +
83787 +void gr_copy_label(struct task_struct *tsk);
83788 +void gr_handle_crash(struct task_struct *task, const int sig);
83789 +int gr_handle_signal(const struct task_struct *p, const int sig);
83790 +int gr_check_crash_uid(const kuid_t uid);
83791 +int gr_check_protected_task(const struct task_struct *task);
83792 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
83793 +int gr_acl_handle_mmap(const struct file *file,
83794 + const unsigned long prot);
83795 +int gr_acl_handle_mprotect(const struct file *file,
83796 + const unsigned long prot);
83797 +int gr_check_hidden_task(const struct task_struct *tsk);
83798 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
83799 + const struct vfsmount *mnt);
83800 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
83801 + const struct vfsmount *mnt);
83802 +__u32 gr_acl_handle_access(const struct dentry *dentry,
83803 + const struct vfsmount *mnt, const int fmode);
83804 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
83805 + const struct vfsmount *mnt, umode_t *mode);
83806 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
83807 + const struct vfsmount *mnt);
83808 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
83809 + const struct vfsmount *mnt);
83810 +__u32 gr_acl_handle_removexattr(const struct dentry *dentry,
83811 + const struct vfsmount *mnt);
83812 +int gr_handle_ptrace(struct task_struct *task, const long request);
83813 +int gr_handle_proc_ptrace(struct task_struct *task);
83814 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
83815 + const struct vfsmount *mnt);
83816 +int gr_check_crash_exec(const struct file *filp);
83817 +int gr_acl_is_enabled(void);
83818 +void gr_set_role_label(struct task_struct *task, const kuid_t uid,
83819 + const kgid_t gid);
83820 +int gr_set_proc_label(const struct dentry *dentry,
83821 + const struct vfsmount *mnt,
83822 + const int unsafe_flags);
83823 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
83824 + const struct vfsmount *mnt);
83825 +__u32 gr_acl_handle_open(const struct dentry *dentry,
83826 + const struct vfsmount *mnt, int acc_mode);
83827 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
83828 + const struct dentry *p_dentry,
83829 + const struct vfsmount *p_mnt,
83830 + int open_flags, int acc_mode, const int imode);
83831 +void gr_handle_create(const struct dentry *dentry,
83832 + const struct vfsmount *mnt);
83833 +void gr_handle_proc_create(const struct dentry *dentry,
83834 + const struct inode *inode);
83835 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
83836 + const struct dentry *parent_dentry,
83837 + const struct vfsmount *parent_mnt,
83838 + const int mode);
83839 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
83840 + const struct dentry *parent_dentry,
83841 + const struct vfsmount *parent_mnt);
83842 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
83843 + const struct vfsmount *mnt);
83844 +void gr_handle_delete(const ino_t ino, const dev_t dev);
83845 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
83846 + const struct vfsmount *mnt);
83847 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
83848 + const struct dentry *parent_dentry,
83849 + const struct vfsmount *parent_mnt,
83850 + const struct filename *from);
83851 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
83852 + const struct dentry *parent_dentry,
83853 + const struct vfsmount *parent_mnt,
83854 + const struct dentry *old_dentry,
83855 + const struct vfsmount *old_mnt, const struct filename *to);
83856 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
83857 +int gr_acl_handle_rename(struct dentry *new_dentry,
83858 + struct dentry *parent_dentry,
83859 + const struct vfsmount *parent_mnt,
83860 + struct dentry *old_dentry,
83861 + struct inode *old_parent_inode,
83862 + struct vfsmount *old_mnt, const struct filename *newname, unsigned int flags);
83863 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
83864 + struct dentry *old_dentry,
83865 + struct dentry *new_dentry,
83866 + struct vfsmount *mnt, const __u8 replace, unsigned int flags);
83867 +__u32 gr_check_link(const struct dentry *new_dentry,
83868 + const struct dentry *parent_dentry,
83869 + const struct vfsmount *parent_mnt,
83870 + const struct dentry *old_dentry,
83871 + const struct vfsmount *old_mnt);
83872 +int gr_acl_handle_filldir(const struct file *file, const char *name,
83873 + const unsigned int namelen, const ino_t ino);
83874 +
83875 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
83876 + const struct vfsmount *mnt);
83877 +void gr_acl_handle_exit(void);
83878 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
83879 +int gr_acl_handle_procpidmem(const struct task_struct *task);
83880 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
83881 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
83882 +void gr_audit_ptrace(struct task_struct *task);
83883 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
83884 +void gr_put_exec_file(struct task_struct *task);
83885 +
83886 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
83887 +
83888 +#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
83889 +extern void gr_learn_resource(const struct task_struct *task, const int res,
83890 + const unsigned long wanted, const int gt);
83891 +#else
83892 +static inline void gr_learn_resource(const struct task_struct *task, const int res,
83893 + const unsigned long wanted, const int gt)
83894 +{
83895 +}
83896 +#endif
83897 +
83898 +#ifdef CONFIG_GRKERNSEC_RESLOG
83899 +extern void gr_log_resource(const struct task_struct *task, const int res,
83900 + const unsigned long wanted, const int gt);
83901 +#else
83902 +static inline void gr_log_resource(const struct task_struct *task, const int res,
83903 + const unsigned long wanted, const int gt)
83904 +{
83905 +}
83906 +#endif
83907 +
83908 +#ifdef CONFIG_GRKERNSEC
83909 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
83910 +void gr_handle_vm86(void);
83911 +void gr_handle_mem_readwrite(u64 from, u64 to);
83912 +
83913 +void gr_log_badprocpid(const char *entry);
83914 +
83915 +extern int grsec_enable_dmesg;
83916 +extern int grsec_disable_privio;
83917 +
83918 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
83919 +extern kgid_t grsec_proc_gid;
83920 +#endif
83921 +
83922 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
83923 +extern int grsec_enable_chroot_findtask;
83924 +#endif
83925 +#ifdef CONFIG_GRKERNSEC_SETXID
83926 +extern int grsec_enable_setxid;
83927 +#endif
83928 +#endif
83929 +
83930 +#endif
83931 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
83932 new file mode 100644
83933 index 0000000..e7ffaaf
83934 --- /dev/null
83935 +++ b/include/linux/grsock.h
83936 @@ -0,0 +1,19 @@
83937 +#ifndef __GRSOCK_H
83938 +#define __GRSOCK_H
83939 +
83940 +extern void gr_attach_curr_ip(const struct sock *sk);
83941 +extern int gr_handle_sock_all(const int family, const int type,
83942 + const int protocol);
83943 +extern int gr_handle_sock_server(const struct sockaddr *sck);
83944 +extern int gr_handle_sock_server_other(const struct sock *sck);
83945 +extern int gr_handle_sock_client(const struct sockaddr *sck);
83946 +extern int gr_search_connect(struct socket * sock,
83947 + struct sockaddr_in * addr);
83948 +extern int gr_search_bind(struct socket * sock,
83949 + struct sockaddr_in * addr);
83950 +extern int gr_search_listen(struct socket * sock);
83951 +extern int gr_search_accept(struct socket * sock);
83952 +extern int gr_search_socket(const int domain, const int type,
83953 + const int protocol);
83954 +
83955 +#endif
83956 diff --git a/include/linux/hash.h b/include/linux/hash.h
83957 index bd1754c..8240892 100644
83958 --- a/include/linux/hash.h
83959 +++ b/include/linux/hash.h
83960 @@ -83,7 +83,7 @@ static inline u32 hash32_ptr(const void *ptr)
83961 struct fast_hash_ops {
83962 u32 (*hash)(const void *data, u32 len, u32 seed);
83963 u32 (*hash2)(const u32 *data, u32 len, u32 seed);
83964 -};
83965 +} __no_const;
83966
83967 /**
83968 * arch_fast_hash - Caclulates a hash over a given buffer that can have
83969 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
83970 index 7fb31da..08b5114 100644
83971 --- a/include/linux/highmem.h
83972 +++ b/include/linux/highmem.h
83973 @@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
83974 kunmap_atomic(kaddr);
83975 }
83976
83977 +static inline void sanitize_highpage(struct page *page)
83978 +{
83979 + void *kaddr;
83980 + unsigned long flags;
83981 +
83982 + local_irq_save(flags);
83983 + kaddr = kmap_atomic(page);
83984 + clear_page(kaddr);
83985 + kunmap_atomic(kaddr);
83986 + local_irq_restore(flags);
83987 +}
83988 +
83989 static inline void zero_user_segments(struct page *page,
83990 unsigned start1, unsigned end1,
83991 unsigned start2, unsigned end2)
83992 diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
83993 index 1c7b89a..7dda400 100644
83994 --- a/include/linux/hwmon-sysfs.h
83995 +++ b/include/linux/hwmon-sysfs.h
83996 @@ -25,7 +25,8 @@
83997 struct sensor_device_attribute{
83998 struct device_attribute dev_attr;
83999 int index;
84000 -};
84001 +} __do_const;
84002 +typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
84003 #define to_sensor_dev_attr(_dev_attr) \
84004 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
84005
84006 @@ -41,7 +42,8 @@ struct sensor_device_attribute_2 {
84007 struct device_attribute dev_attr;
84008 u8 index;
84009 u8 nr;
84010 -};
84011 +} __do_const;
84012 +typedef struct sensor_device_attribute_2 __no_const sensor_device_attribute_2_no_const;
84013 #define to_sensor_dev_attr_2(_dev_attr) \
84014 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
84015
84016 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
84017 index b556e0a..c10a515 100644
84018 --- a/include/linux/i2c.h
84019 +++ b/include/linux/i2c.h
84020 @@ -378,6 +378,7 @@ struct i2c_algorithm {
84021 /* To determine what the adapter supports */
84022 u32 (*functionality) (struct i2c_adapter *);
84023 };
84024 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
84025
84026 /**
84027 * struct i2c_bus_recovery_info - I2C bus recovery information
84028 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
84029 index d23c3c2..eb63c81 100644
84030 --- a/include/linux/i2o.h
84031 +++ b/include/linux/i2o.h
84032 @@ -565,7 +565,7 @@ struct i2o_controller {
84033 struct i2o_device *exec; /* Executive */
84034 #if BITS_PER_LONG == 64
84035 spinlock_t context_list_lock; /* lock for context_list */
84036 - atomic_t context_list_counter; /* needed for unique contexts */
84037 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
84038 struct list_head context_list; /* list of context id's
84039 and pointers */
84040 #endif
84041 diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
84042 index aff7ad8..3942bbd 100644
84043 --- a/include/linux/if_pppox.h
84044 +++ b/include/linux/if_pppox.h
84045 @@ -76,7 +76,7 @@ struct pppox_proto {
84046 int (*ioctl)(struct socket *sock, unsigned int cmd,
84047 unsigned long arg);
84048 struct module *owner;
84049 -};
84050 +} __do_const;
84051
84052 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
84053 extern void unregister_pppox_proto(int proto_num);
84054 diff --git a/include/linux/init.h b/include/linux/init.h
84055 index 2df8e8d..3e1280d 100644
84056 --- a/include/linux/init.h
84057 +++ b/include/linux/init.h
84058 @@ -37,9 +37,17 @@
84059 * section.
84060 */
84061
84062 +#define add_init_latent_entropy __latent_entropy
84063 +
84064 +#ifdef CONFIG_MEMORY_HOTPLUG
84065 +#define add_meminit_latent_entropy
84066 +#else
84067 +#define add_meminit_latent_entropy __latent_entropy
84068 +#endif
84069 +
84070 /* These are for everybody (although not all archs will actually
84071 discard it in modules) */
84072 -#define __init __section(.init.text) __cold notrace
84073 +#define __init __section(.init.text) __cold notrace add_init_latent_entropy
84074 #define __initdata __section(.init.data)
84075 #define __initconst __constsection(.init.rodata)
84076 #define __exitdata __section(.exit.data)
84077 @@ -100,7 +108,7 @@
84078 #define __cpuexitconst
84079
84080 /* Used for MEMORY_HOTPLUG */
84081 -#define __meminit __section(.meminit.text) __cold notrace
84082 +#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
84083 #define __meminitdata __section(.meminit.data)
84084 #define __meminitconst __constsection(.meminit.rodata)
84085 #define __memexit __section(.memexit.text) __exitused __cold notrace
84086 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
84087 index 6df7f9f..d0bf699 100644
84088 --- a/include/linux/init_task.h
84089 +++ b/include/linux/init_task.h
84090 @@ -156,6 +156,12 @@ extern struct task_group root_task_group;
84091
84092 #define INIT_TASK_COMM "swapper"
84093
84094 +#ifdef CONFIG_X86
84095 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
84096 +#else
84097 +#define INIT_TASK_THREAD_INFO
84098 +#endif
84099 +
84100 #ifdef CONFIG_RT_MUTEXES
84101 # define INIT_RT_MUTEXES(tsk) \
84102 .pi_waiters = RB_ROOT, \
84103 @@ -203,6 +209,7 @@ extern struct task_group root_task_group;
84104 RCU_POINTER_INITIALIZER(cred, &init_cred), \
84105 .comm = INIT_TASK_COMM, \
84106 .thread = INIT_THREAD, \
84107 + INIT_TASK_THREAD_INFO \
84108 .fs = &init_fs, \
84109 .files = &init_files, \
84110 .signal = &init_signals, \
84111 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
84112 index 698ad05..8601bb7 100644
84113 --- a/include/linux/interrupt.h
84114 +++ b/include/linux/interrupt.h
84115 @@ -418,8 +418,8 @@ extern const char * const softirq_to_name[NR_SOFTIRQS];
84116
84117 struct softirq_action
84118 {
84119 - void (*action)(struct softirq_action *);
84120 -};
84121 + void (*action)(void);
84122 +} __no_const;
84123
84124 asmlinkage void do_softirq(void);
84125 asmlinkage void __do_softirq(void);
84126 @@ -433,7 +433,7 @@ static inline void do_softirq_own_stack(void)
84127 }
84128 #endif
84129
84130 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
84131 +extern void open_softirq(int nr, void (*action)(void));
84132 extern void softirq_init(void);
84133 extern void __raise_softirq_irqoff(unsigned int nr);
84134
84135 diff --git a/include/linux/iommu.h b/include/linux/iommu.h
84136 index b96a5b2..2732d1c 100644
84137 --- a/include/linux/iommu.h
84138 +++ b/include/linux/iommu.h
84139 @@ -131,7 +131,7 @@ struct iommu_ops {
84140 u32 (*domain_get_windows)(struct iommu_domain *domain);
84141
84142 unsigned long pgsize_bitmap;
84143 -};
84144 +} __do_const;
84145
84146 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
84147 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
84148 diff --git a/include/linux/ioport.h b/include/linux/ioport.h
84149 index 5e3a906..3131d0f 100644
84150 --- a/include/linux/ioport.h
84151 +++ b/include/linux/ioport.h
84152 @@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
84153 int adjust_resource(struct resource *res, resource_size_t start,
84154 resource_size_t size);
84155 resource_size_t resource_alignment(struct resource *res);
84156 -static inline resource_size_t resource_size(const struct resource *res)
84157 +static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
84158 {
84159 return res->end - res->start + 1;
84160 }
84161 diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
84162 index 35e7eca..6afb7ad 100644
84163 --- a/include/linux/ipc_namespace.h
84164 +++ b/include/linux/ipc_namespace.h
84165 @@ -69,7 +69,7 @@ struct ipc_namespace {
84166 struct user_namespace *user_ns;
84167
84168 unsigned int proc_inum;
84169 -};
84170 +} __randomize_layout;
84171
84172 extern struct ipc_namespace init_ipc_ns;
84173 extern atomic_t nr_ipc_ns;
84174 diff --git a/include/linux/irq.h b/include/linux/irq.h
84175 index 0d998d8..3a1c782 100644
84176 --- a/include/linux/irq.h
84177 +++ b/include/linux/irq.h
84178 @@ -344,7 +344,8 @@ struct irq_chip {
84179 void (*irq_release_resources)(struct irq_data *data);
84180
84181 unsigned long flags;
84182 -};
84183 +} __do_const;
84184 +typedef struct irq_chip __no_const irq_chip_no_const;
84185
84186 /*
84187 * irq_chip specific flags
84188 diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
84189 index 45e2d8c..26d85da 100644
84190 --- a/include/linux/irqchip/arm-gic.h
84191 +++ b/include/linux/irqchip/arm-gic.h
84192 @@ -75,9 +75,11 @@
84193
84194 #ifndef __ASSEMBLY__
84195
84196 +#include <linux/irq.h>
84197 +
84198 struct device_node;
84199
84200 -extern struct irq_chip gic_arch_extn;
84201 +extern irq_chip_no_const gic_arch_extn;
84202
84203 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
84204 u32 offset, struct device_node *);
84205 diff --git a/include/linux/isdn_ppp.h b/include/linux/isdn_ppp.h
84206 index 8e10f57..d5f62bc 100644
84207 --- a/include/linux/isdn_ppp.h
84208 +++ b/include/linux/isdn_ppp.h
84209 @@ -180,8 +180,9 @@ struct ippp_struct {
84210 struct slcompress *slcomp;
84211 #endif
84212 #ifdef CONFIG_IPPP_FILTER
84213 - struct sk_filter *pass_filter; /* filter for packets to pass */
84214 - struct sk_filter *active_filter; /* filter for pkts to reset idle */
84215 + struct sock_filter *pass_filter; /* filter for packets to pass */
84216 + struct sock_filter *active_filter; /* filter for pkts to reset idle */
84217 + unsigned pass_len, active_len;
84218 #endif
84219 unsigned long debug;
84220 struct isdn_ppp_compressor *compressor,*decompressor;
84221 diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
84222 index 1f44466..b481806 100644
84223 --- a/include/linux/jiffies.h
84224 +++ b/include/linux/jiffies.h
84225 @@ -292,20 +292,20 @@ extern unsigned long preset_lpj;
84226 /*
84227 * Convert various time units to each other:
84228 */
84229 -extern unsigned int jiffies_to_msecs(const unsigned long j);
84230 -extern unsigned int jiffies_to_usecs(const unsigned long j);
84231 +extern unsigned int jiffies_to_msecs(const unsigned long j) __intentional_overflow(-1);
84232 +extern unsigned int jiffies_to_usecs(const unsigned long j) __intentional_overflow(-1);
84233
84234 -static inline u64 jiffies_to_nsecs(const unsigned long j)
84235 +static inline u64 __intentional_overflow(-1) jiffies_to_nsecs(const unsigned long j)
84236 {
84237 return (u64)jiffies_to_usecs(j) * NSEC_PER_USEC;
84238 }
84239
84240 -extern unsigned long msecs_to_jiffies(const unsigned int m);
84241 -extern unsigned long usecs_to_jiffies(const unsigned int u);
84242 +extern unsigned long msecs_to_jiffies(const unsigned int m) __intentional_overflow(-1);
84243 +extern unsigned long usecs_to_jiffies(const unsigned int u) __intentional_overflow(-1);
84244 extern unsigned long timespec_to_jiffies(const struct timespec *value);
84245 extern void jiffies_to_timespec(const unsigned long jiffies,
84246 - struct timespec *value);
84247 -extern unsigned long timeval_to_jiffies(const struct timeval *value);
84248 + struct timespec *value) __intentional_overflow(-1);
84249 +extern unsigned long timeval_to_jiffies(const struct timeval *value) __intentional_overflow(-1);
84250 extern void jiffies_to_timeval(const unsigned long jiffies,
84251 struct timeval *value);
84252
84253 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
84254 index 6883e19..e854fcb 100644
84255 --- a/include/linux/kallsyms.h
84256 +++ b/include/linux/kallsyms.h
84257 @@ -15,7 +15,8 @@
84258
84259 struct module;
84260
84261 -#ifdef CONFIG_KALLSYMS
84262 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
84263 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
84264 /* Lookup the address for a symbol. Returns 0 if not found. */
84265 unsigned long kallsyms_lookup_name(const char *name);
84266
84267 @@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
84268 /* Stupid that this does nothing, but I didn't create this mess. */
84269 #define __print_symbol(fmt, addr)
84270 #endif /*CONFIG_KALLSYMS*/
84271 +#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
84272 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
84273 +extern unsigned long kallsyms_lookup_name(const char *name);
84274 +extern void __print_symbol(const char *fmt, unsigned long address);
84275 +extern int sprint_backtrace(char *buffer, unsigned long address);
84276 +extern int sprint_symbol(char *buffer, unsigned long address);
84277 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
84278 +const char *kallsyms_lookup(unsigned long addr,
84279 + unsigned long *symbolsize,
84280 + unsigned long *offset,
84281 + char **modname, char *namebuf);
84282 +extern int kallsyms_lookup_size_offset(unsigned long addr,
84283 + unsigned long *symbolsize,
84284 + unsigned long *offset);
84285 +#endif
84286
84287 /* This macro allows us to keep printk typechecking */
84288 static __printf(1, 2)
84289 diff --git a/include/linux/key-type.h b/include/linux/key-type.h
84290 index a74c3a8..28d3f21 100644
84291 --- a/include/linux/key-type.h
84292 +++ b/include/linux/key-type.h
84293 @@ -131,7 +131,7 @@ struct key_type {
84294 /* internal fields */
84295 struct list_head link; /* link in types list */
84296 struct lock_class_key lock_class; /* key->sem lock class */
84297 -};
84298 +} __do_const;
84299
84300 extern struct key_type key_type_keyring;
84301
84302 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
84303 index 6b06d37..c134867 100644
84304 --- a/include/linux/kgdb.h
84305 +++ b/include/linux/kgdb.h
84306 @@ -52,7 +52,7 @@ extern int kgdb_connected;
84307 extern int kgdb_io_module_registered;
84308
84309 extern atomic_t kgdb_setting_breakpoint;
84310 -extern atomic_t kgdb_cpu_doing_single_step;
84311 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
84312
84313 extern struct task_struct *kgdb_usethread;
84314 extern struct task_struct *kgdb_contthread;
84315 @@ -254,7 +254,7 @@ struct kgdb_arch {
84316 void (*correct_hw_break)(void);
84317
84318 void (*enable_nmi)(bool on);
84319 -};
84320 +} __do_const;
84321
84322 /**
84323 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
84324 @@ -279,7 +279,7 @@ struct kgdb_io {
84325 void (*pre_exception) (void);
84326 void (*post_exception) (void);
84327 int is_console;
84328 -};
84329 +} __do_const;
84330
84331 extern struct kgdb_arch arch_kgdb_ops;
84332
84333 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
84334 index 0555cc6..40116ce 100644
84335 --- a/include/linux/kmod.h
84336 +++ b/include/linux/kmod.h
84337 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
84338 * usually useless though. */
84339 extern __printf(2, 3)
84340 int __request_module(bool wait, const char *name, ...);
84341 +extern __printf(3, 4)
84342 +int ___request_module(bool wait, char *param_name, const char *name, ...);
84343 #define request_module(mod...) __request_module(true, mod)
84344 #define request_module_nowait(mod...) __request_module(false, mod)
84345 #define try_then_request_module(x, mod...) \
84346 @@ -57,6 +59,9 @@ struct subprocess_info {
84347 struct work_struct work;
84348 struct completion *complete;
84349 char *path;
84350 +#ifdef CONFIG_GRKERNSEC
84351 + char *origpath;
84352 +#endif
84353 char **argv;
84354 char **envp;
84355 int wait;
84356 diff --git a/include/linux/kobject.h b/include/linux/kobject.h
84357 index 2d61b90..a1d0a13 100644
84358 --- a/include/linux/kobject.h
84359 +++ b/include/linux/kobject.h
84360 @@ -118,7 +118,7 @@ struct kobj_type {
84361 struct attribute **default_attrs;
84362 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
84363 const void *(*namespace)(struct kobject *kobj);
84364 -};
84365 +} __do_const;
84366
84367 struct kobj_uevent_env {
84368 char *argv[3];
84369 @@ -142,6 +142,7 @@ struct kobj_attribute {
84370 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
84371 const char *buf, size_t count);
84372 };
84373 +typedef struct kobj_attribute __no_const kobj_attribute_no_const;
84374
84375 extern const struct sysfs_ops kobj_sysfs_ops;
84376
84377 @@ -169,7 +170,7 @@ struct kset {
84378 spinlock_t list_lock;
84379 struct kobject kobj;
84380 const struct kset_uevent_ops *uevent_ops;
84381 -};
84382 +} __randomize_layout;
84383
84384 extern void kset_init(struct kset *kset);
84385 extern int __must_check kset_register(struct kset *kset);
84386 diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
84387 index df32d25..fb52e27 100644
84388 --- a/include/linux/kobject_ns.h
84389 +++ b/include/linux/kobject_ns.h
84390 @@ -44,7 +44,7 @@ struct kobj_ns_type_operations {
84391 const void *(*netlink_ns)(struct sock *sk);
84392 const void *(*initial_ns)(void);
84393 void (*drop_ns)(void *);
84394 -};
84395 +} __do_const;
84396
84397 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
84398 int kobj_ns_type_registered(enum kobj_ns_type type);
84399 diff --git a/include/linux/kref.h b/include/linux/kref.h
84400 index 484604d..0f6c5b6 100644
84401 --- a/include/linux/kref.h
84402 +++ b/include/linux/kref.h
84403 @@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
84404 static inline int kref_sub(struct kref *kref, unsigned int count,
84405 void (*release)(struct kref *kref))
84406 {
84407 - WARN_ON(release == NULL);
84408 + BUG_ON(release == NULL);
84409
84410 if (atomic_sub_and_test((int) count, &kref->refcount)) {
84411 release(kref);
84412 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
84413 index ec4e3bd..14db03a 100644
84414 --- a/include/linux/kvm_host.h
84415 +++ b/include/linux/kvm_host.h
84416 @@ -468,7 +468,7 @@ static inline void kvm_irqfd_exit(void)
84417 {
84418 }
84419 #endif
84420 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
84421 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
84422 struct module *module);
84423 void kvm_exit(void);
84424
84425 @@ -634,7 +634,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
84426 struct kvm_guest_debug *dbg);
84427 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
84428
84429 -int kvm_arch_init(void *opaque);
84430 +int kvm_arch_init(const void *opaque);
84431 void kvm_arch_exit(void);
84432
84433 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
84434 diff --git a/include/linux/libata.h b/include/linux/libata.h
84435 index 92abb49..e7fff2a 100644
84436 --- a/include/linux/libata.h
84437 +++ b/include/linux/libata.h
84438 @@ -976,7 +976,7 @@ struct ata_port_operations {
84439 * fields must be pointers.
84440 */
84441 const struct ata_port_operations *inherits;
84442 -};
84443 +} __do_const;
84444
84445 struct ata_port_info {
84446 unsigned long flags;
84447 diff --git a/include/linux/linkage.h b/include/linux/linkage.h
84448 index a6a42dd..6c5ebce 100644
84449 --- a/include/linux/linkage.h
84450 +++ b/include/linux/linkage.h
84451 @@ -36,6 +36,7 @@
84452 #endif
84453
84454 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
84455 +#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
84456 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
84457
84458 /*
84459 diff --git a/include/linux/list.h b/include/linux/list.h
84460 index ef95941..82db65a 100644
84461 --- a/include/linux/list.h
84462 +++ b/include/linux/list.h
84463 @@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
84464 extern void list_del(struct list_head *entry);
84465 #endif
84466
84467 +extern void __pax_list_add(struct list_head *new,
84468 + struct list_head *prev,
84469 + struct list_head *next);
84470 +static inline void pax_list_add(struct list_head *new, struct list_head *head)
84471 +{
84472 + __pax_list_add(new, head, head->next);
84473 +}
84474 +static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
84475 +{
84476 + __pax_list_add(new, head->prev, head);
84477 +}
84478 +extern void pax_list_del(struct list_head *entry);
84479 +
84480 /**
84481 * list_replace - replace old entry by new one
84482 * @old : the element to be replaced
84483 @@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
84484 INIT_LIST_HEAD(entry);
84485 }
84486
84487 +extern void pax_list_del_init(struct list_head *entry);
84488 +
84489 /**
84490 * list_move - delete from one list and add as another's head
84491 * @list: the entry to move
84492 diff --git a/include/linux/math64.h b/include/linux/math64.h
84493 index c45c089..298841c 100644
84494 --- a/include/linux/math64.h
84495 +++ b/include/linux/math64.h
84496 @@ -15,7 +15,7 @@
84497 * This is commonly provided by 32bit archs to provide an optimized 64bit
84498 * divide.
84499 */
84500 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
84501 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
84502 {
84503 *remainder = dividend % divisor;
84504 return dividend / divisor;
84505 @@ -42,7 +42,7 @@ static inline u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
84506 /**
84507 * div64_u64 - unsigned 64bit divide with 64bit divisor
84508 */
84509 -static inline u64 div64_u64(u64 dividend, u64 divisor)
84510 +static inline u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
84511 {
84512 return dividend / divisor;
84513 }
84514 @@ -61,7 +61,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
84515 #define div64_ul(x, y) div_u64((x), (y))
84516
84517 #ifndef div_u64_rem
84518 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
84519 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
84520 {
84521 *remainder = do_div(dividend, divisor);
84522 return dividend;
84523 @@ -77,7 +77,7 @@ extern u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder);
84524 #endif
84525
84526 #ifndef div64_u64
84527 -extern u64 div64_u64(u64 dividend, u64 divisor);
84528 +extern u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor);
84529 #endif
84530
84531 #ifndef div64_s64
84532 @@ -94,7 +94,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
84533 * divide.
84534 */
84535 #ifndef div_u64
84536 -static inline u64 div_u64(u64 dividend, u32 divisor)
84537 +static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
84538 {
84539 u32 remainder;
84540 return div_u64_rem(dividend, divisor, &remainder);
84541 diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
84542 index f230a97..714c006 100644
84543 --- a/include/linux/mempolicy.h
84544 +++ b/include/linux/mempolicy.h
84545 @@ -91,6 +91,10 @@ static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
84546 }
84547
84548 #define vma_policy(vma) ((vma)->vm_policy)
84549 +static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
84550 +{
84551 + vma->vm_policy = pol;
84552 +}
84553
84554 static inline void mpol_get(struct mempolicy *pol)
84555 {
84556 @@ -228,6 +232,9 @@ static inline void mpol_free_shared_policy(struct shared_policy *p)
84557 }
84558
84559 #define vma_policy(vma) NULL
84560 +static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
84561 +{
84562 +}
84563
84564 static inline int
84565 vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst)
84566 diff --git a/include/linux/mm.h b/include/linux/mm.h
84567 index e03dd29..eaf923c 100644
84568 --- a/include/linux/mm.h
84569 +++ b/include/linux/mm.h
84570 @@ -127,6 +127,11 @@ extern unsigned int kobjsize(const void *objp);
84571 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
84572 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
84573 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
84574 +
84575 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
84576 +#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
84577 +#endif
84578 +
84579 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
84580
84581 #ifdef CONFIG_MEM_SOFT_DIRTY
84582 @@ -237,8 +242,8 @@ struct vm_operations_struct {
84583 /* called by access_process_vm when get_user_pages() fails, typically
84584 * for use by special VMAs that can switch between memory and hardware
84585 */
84586 - int (*access)(struct vm_area_struct *vma, unsigned long addr,
84587 - void *buf, int len, int write);
84588 + ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
84589 + void *buf, size_t len, int write);
84590
84591 /* Called by the /proc/PID/maps code to ask the vma whether it
84592 * has a special name. Returning non-NULL will also cause this
84593 @@ -274,6 +279,7 @@ struct vm_operations_struct {
84594 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
84595 unsigned long size, pgoff_t pgoff);
84596 };
84597 +typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
84598
84599 struct mmu_gather;
84600 struct inode;
84601 @@ -1144,8 +1150,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
84602 unsigned long *pfn);
84603 int follow_phys(struct vm_area_struct *vma, unsigned long address,
84604 unsigned int flags, unsigned long *prot, resource_size_t *phys);
84605 -int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
84606 - void *buf, int len, int write);
84607 +ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
84608 + void *buf, size_t len, int write);
84609
84610 static inline void unmap_shared_mapping_range(struct address_space *mapping,
84611 loff_t const holebegin, loff_t const holelen)
84612 @@ -1184,9 +1190,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
84613 }
84614 #endif
84615
84616 -extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
84617 -extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
84618 - void *buf, int len, int write);
84619 +extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
84620 +extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
84621 + void *buf, size_t len, int write);
84622
84623 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
84624 unsigned long start, unsigned long nr_pages,
84625 @@ -1219,34 +1225,6 @@ int set_page_dirty_lock(struct page *page);
84626 int clear_page_dirty_for_io(struct page *page);
84627 int get_cmdline(struct task_struct *task, char *buffer, int buflen);
84628
84629 -/* Is the vma a continuation of the stack vma above it? */
84630 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
84631 -{
84632 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
84633 -}
84634 -
84635 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
84636 - unsigned long addr)
84637 -{
84638 - return (vma->vm_flags & VM_GROWSDOWN) &&
84639 - (vma->vm_start == addr) &&
84640 - !vma_growsdown(vma->vm_prev, addr);
84641 -}
84642 -
84643 -/* Is the vma a continuation of the stack vma below it? */
84644 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
84645 -{
84646 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
84647 -}
84648 -
84649 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
84650 - unsigned long addr)
84651 -{
84652 - return (vma->vm_flags & VM_GROWSUP) &&
84653 - (vma->vm_end == addr) &&
84654 - !vma_growsup(vma->vm_next, addr);
84655 -}
84656 -
84657 extern pid_t
84658 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
84659
84660 @@ -1346,6 +1324,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
84661 }
84662 #endif
84663
84664 +#ifdef CONFIG_MMU
84665 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
84666 +#else
84667 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
84668 +{
84669 + return __pgprot(0);
84670 +}
84671 +#endif
84672 +
84673 int vma_wants_writenotify(struct vm_area_struct *vma);
84674
84675 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
84676 @@ -1364,8 +1351,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
84677 {
84678 return 0;
84679 }
84680 +
84681 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
84682 + unsigned long address)
84683 +{
84684 + return 0;
84685 +}
84686 #else
84687 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
84688 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
84689 #endif
84690
84691 #ifdef __PAGETABLE_PMD_FOLDED
84692 @@ -1374,8 +1368,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
84693 {
84694 return 0;
84695 }
84696 +
84697 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
84698 + unsigned long address)
84699 +{
84700 + return 0;
84701 +}
84702 #else
84703 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
84704 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
84705 #endif
84706
84707 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
84708 @@ -1393,11 +1394,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
84709 NULL: pud_offset(pgd, address);
84710 }
84711
84712 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
84713 +{
84714 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
84715 + NULL: pud_offset(pgd, address);
84716 +}
84717 +
84718 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
84719 {
84720 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
84721 NULL: pmd_offset(pud, address);
84722 }
84723 +
84724 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
84725 +{
84726 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
84727 + NULL: pmd_offset(pud, address);
84728 +}
84729 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
84730
84731 #if USE_SPLIT_PTE_PTLOCKS
84732 @@ -1796,7 +1809,7 @@ extern int install_special_mapping(struct mm_struct *mm,
84733 unsigned long addr, unsigned long len,
84734 unsigned long flags, struct page **pages);
84735
84736 -extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
84737 +extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long) __intentional_overflow(-1);
84738
84739 extern unsigned long mmap_region(struct file *file, unsigned long addr,
84740 unsigned long len, vm_flags_t vm_flags, unsigned long pgoff);
84741 @@ -1804,6 +1817,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
84742 unsigned long len, unsigned long prot, unsigned long flags,
84743 unsigned long pgoff, unsigned long *populate);
84744 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
84745 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
84746
84747 #ifdef CONFIG_MMU
84748 extern int __mm_populate(unsigned long addr, unsigned long len,
84749 @@ -1832,10 +1846,11 @@ struct vm_unmapped_area_info {
84750 unsigned long high_limit;
84751 unsigned long align_mask;
84752 unsigned long align_offset;
84753 + unsigned long threadstack_offset;
84754 };
84755
84756 -extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
84757 -extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
84758 +extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
84759 +extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
84760
84761 /*
84762 * Search for an unmapped address range.
84763 @@ -1847,7 +1862,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
84764 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
84765 */
84766 static inline unsigned long
84767 -vm_unmapped_area(struct vm_unmapped_area_info *info)
84768 +vm_unmapped_area(const struct vm_unmapped_area_info *info)
84769 {
84770 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
84771 return unmapped_area(info);
84772 @@ -1909,6 +1924,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
84773 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
84774 struct vm_area_struct **pprev);
84775
84776 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
84777 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
84778 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
84779 +
84780 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
84781 NULL if none. Assume start_addr < end_addr. */
84782 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
84783 @@ -1937,15 +1956,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
84784 return vma;
84785 }
84786
84787 -#ifdef CONFIG_MMU
84788 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
84789 -#else
84790 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
84791 -{
84792 - return __pgprot(0);
84793 -}
84794 -#endif
84795 -
84796 #ifdef CONFIG_NUMA_BALANCING
84797 unsigned long change_prot_numa(struct vm_area_struct *vma,
84798 unsigned long start, unsigned long end);
84799 @@ -1997,6 +2007,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
84800 static inline void vm_stat_account(struct mm_struct *mm,
84801 unsigned long flags, struct file *file, long pages)
84802 {
84803 +
84804 +#ifdef CONFIG_PAX_RANDMMAP
84805 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
84806 +#endif
84807 +
84808 mm->total_vm += pages;
84809 }
84810 #endif /* CONFIG_PROC_FS */
84811 @@ -2078,7 +2093,7 @@ extern int unpoison_memory(unsigned long pfn);
84812 extern int sysctl_memory_failure_early_kill;
84813 extern int sysctl_memory_failure_recovery;
84814 extern void shake_page(struct page *p, int access);
84815 -extern atomic_long_t num_poisoned_pages;
84816 +extern atomic_long_unchecked_t num_poisoned_pages;
84817 extern int soft_offline_page(struct page *page, int flags);
84818
84819 #if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLBFS)
84820 @@ -2113,5 +2128,11 @@ void __init setup_nr_node_ids(void);
84821 static inline void setup_nr_node_ids(void) {}
84822 #endif
84823
84824 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
84825 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
84826 +#else
84827 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
84828 +#endif
84829 +
84830 #endif /* __KERNEL__ */
84831 #endif /* _LINUX_MM_H */
84832 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
84833 index 96c5750..15668ba 100644
84834 --- a/include/linux/mm_types.h
84835 +++ b/include/linux/mm_types.h
84836 @@ -308,7 +308,9 @@ struct vm_area_struct {
84837 #ifdef CONFIG_NUMA
84838 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
84839 #endif
84840 -};
84841 +
84842 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
84843 +} __randomize_layout;
84844
84845 struct core_thread {
84846 struct task_struct *task;
84847 @@ -454,7 +456,25 @@ struct mm_struct {
84848 bool tlb_flush_pending;
84849 #endif
84850 struct uprobes_state uprobes_state;
84851 -};
84852 +
84853 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
84854 + unsigned long pax_flags;
84855 +#endif
84856 +
84857 +#ifdef CONFIG_PAX_DLRESOLVE
84858 + unsigned long call_dl_resolve;
84859 +#endif
84860 +
84861 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
84862 + unsigned long call_syscall;
84863 +#endif
84864 +
84865 +#ifdef CONFIG_PAX_ASLR
84866 + unsigned long delta_mmap; /* randomized offset */
84867 + unsigned long delta_stack; /* randomized offset */
84868 +#endif
84869 +
84870 +} __randomize_layout;
84871
84872 static inline void mm_init_cpumask(struct mm_struct *mm)
84873 {
84874 diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
84875 index c5d5278..f0b68c8 100644
84876 --- a/include/linux/mmiotrace.h
84877 +++ b/include/linux/mmiotrace.h
84878 @@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
84879 /* Called from ioremap.c */
84880 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
84881 void __iomem *addr);
84882 -extern void mmiotrace_iounmap(volatile void __iomem *addr);
84883 +extern void mmiotrace_iounmap(const volatile void __iomem *addr);
84884
84885 /* For anyone to insert markers. Remember trailing newline. */
84886 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
84887 @@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
84888 {
84889 }
84890
84891 -static inline void mmiotrace_iounmap(volatile void __iomem *addr)
84892 +static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
84893 {
84894 }
84895
84896 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
84897 index 6cbd1b6..b1d2f99 100644
84898 --- a/include/linux/mmzone.h
84899 +++ b/include/linux/mmzone.h
84900 @@ -412,7 +412,7 @@ struct zone {
84901 unsigned long flags; /* zone flags, see below */
84902
84903 /* Zone statistics */
84904 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
84905 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
84906
84907 /*
84908 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
84909 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
84910 index 44eeef0..a92d3f9 100644
84911 --- a/include/linux/mod_devicetable.h
84912 +++ b/include/linux/mod_devicetable.h
84913 @@ -139,7 +139,7 @@ struct usb_device_id {
84914 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
84915 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
84916
84917 -#define HID_ANY_ID (~0)
84918 +#define HID_ANY_ID (~0U)
84919 #define HID_BUS_ANY 0xffff
84920 #define HID_GROUP_ANY 0x0000
84921
84922 @@ -475,7 +475,7 @@ struct dmi_system_id {
84923 const char *ident;
84924 struct dmi_strmatch matches[4];
84925 void *driver_data;
84926 -};
84927 +} __do_const;
84928 /*
84929 * struct dmi_device_id appears during expansion of
84930 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
84931 diff --git a/include/linux/module.h b/include/linux/module.h
84932 index f520a76..5f898ef 100644
84933 --- a/include/linux/module.h
84934 +++ b/include/linux/module.h
84935 @@ -17,9 +17,11 @@
84936 #include <linux/moduleparam.h>
84937 #include <linux/jump_label.h>
84938 #include <linux/export.h>
84939 +#include <linux/fs.h>
84940
84941 #include <linux/percpu.h>
84942 #include <asm/module.h>
84943 +#include <asm/pgtable.h>
84944
84945 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
84946 #define MODULE_SIG_STRING "~Module signature appended~\n"
84947 @@ -42,7 +44,7 @@ struct module_kobject {
84948 struct kobject *drivers_dir;
84949 struct module_param_attrs *mp;
84950 struct completion *kobj_completion;
84951 -};
84952 +} __randomize_layout;
84953
84954 struct module_attribute {
84955 struct attribute attr;
84956 @@ -54,12 +56,13 @@ struct module_attribute {
84957 int (*test)(struct module *);
84958 void (*free)(struct module *);
84959 };
84960 +typedef struct module_attribute __no_const module_attribute_no_const;
84961
84962 struct module_version_attribute {
84963 struct module_attribute mattr;
84964 const char *module_name;
84965 const char *version;
84966 -} __attribute__ ((__aligned__(sizeof(void *))));
84967 +} __do_const __attribute__ ((__aligned__(sizeof(void *))));
84968
84969 extern ssize_t __modver_version_show(struct module_attribute *,
84970 struct module_kobject *, char *);
84971 @@ -235,7 +238,7 @@ struct module {
84972
84973 /* Sysfs stuff. */
84974 struct module_kobject mkobj;
84975 - struct module_attribute *modinfo_attrs;
84976 + module_attribute_no_const *modinfo_attrs;
84977 const char *version;
84978 const char *srcversion;
84979 struct kobject *holders_dir;
84980 @@ -284,19 +287,16 @@ struct module {
84981 int (*init)(void);
84982
84983 /* If this is non-NULL, vfree after init() returns */
84984 - void *module_init;
84985 + void *module_init_rx, *module_init_rw;
84986
84987 /* Here is the actual code + data, vfree'd on unload. */
84988 - void *module_core;
84989 + void *module_core_rx, *module_core_rw;
84990
84991 /* Here are the sizes of the init and core sections */
84992 - unsigned int init_size, core_size;
84993 + unsigned int init_size_rw, core_size_rw;
84994
84995 /* The size of the executable code in each section. */
84996 - unsigned int init_text_size, core_text_size;
84997 -
84998 - /* Size of RO sections of the module (text+rodata) */
84999 - unsigned int init_ro_size, core_ro_size;
85000 + unsigned int init_size_rx, core_size_rx;
85001
85002 /* Arch-specific module values */
85003 struct mod_arch_specific arch;
85004 @@ -352,6 +352,10 @@ struct module {
85005 #ifdef CONFIG_EVENT_TRACING
85006 struct ftrace_event_call **trace_events;
85007 unsigned int num_trace_events;
85008 + struct file_operations trace_id;
85009 + struct file_operations trace_enable;
85010 + struct file_operations trace_format;
85011 + struct file_operations trace_filter;
85012 #endif
85013 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
85014 unsigned int num_ftrace_callsites;
85015 @@ -375,7 +379,7 @@ struct module {
85016 ctor_fn_t *ctors;
85017 unsigned int num_ctors;
85018 #endif
85019 -};
85020 +} __randomize_layout;
85021 #ifndef MODULE_ARCH_INIT
85022 #define MODULE_ARCH_INIT {}
85023 #endif
85024 @@ -396,16 +400,46 @@ bool is_module_address(unsigned long addr);
85025 bool is_module_percpu_address(unsigned long addr);
85026 bool is_module_text_address(unsigned long addr);
85027
85028 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
85029 +{
85030 +
85031 +#ifdef CONFIG_PAX_KERNEXEC
85032 + if (ktla_ktva(addr) >= (unsigned long)start &&
85033 + ktla_ktva(addr) < (unsigned long)start + size)
85034 + return 1;
85035 +#endif
85036 +
85037 + return ((void *)addr >= start && (void *)addr < start + size);
85038 +}
85039 +
85040 +static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
85041 +{
85042 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
85043 +}
85044 +
85045 +static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
85046 +{
85047 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
85048 +}
85049 +
85050 +static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
85051 +{
85052 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
85053 +}
85054 +
85055 +static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
85056 +{
85057 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
85058 +}
85059 +
85060 static inline int within_module_core(unsigned long addr, const struct module *mod)
85061 {
85062 - return (unsigned long)mod->module_core <= addr &&
85063 - addr < (unsigned long)mod->module_core + mod->core_size;
85064 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
85065 }
85066
85067 static inline int within_module_init(unsigned long addr, const struct module *mod)
85068 {
85069 - return (unsigned long)mod->module_init <= addr &&
85070 - addr < (unsigned long)mod->module_init + mod->init_size;
85071 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
85072 }
85073
85074 /* Search for module by name: must hold module_mutex. */
85075 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
85076 index 560ca53..ef621ef 100644
85077 --- a/include/linux/moduleloader.h
85078 +++ b/include/linux/moduleloader.h
85079 @@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
85080 sections. Returns NULL on failure. */
85081 void *module_alloc(unsigned long size);
85082
85083 +#ifdef CONFIG_PAX_KERNEXEC
85084 +void *module_alloc_exec(unsigned long size);
85085 +#else
85086 +#define module_alloc_exec(x) module_alloc(x)
85087 +#endif
85088 +
85089 /* Free memory returned from module_alloc. */
85090 void module_free(struct module *mod, void *module_region);
85091
85092 +#ifdef CONFIG_PAX_KERNEXEC
85093 +void module_free_exec(struct module *mod, void *module_region);
85094 +#else
85095 +#define module_free_exec(x, y) module_free((x), (y))
85096 +#endif
85097 +
85098 /*
85099 * Apply the given relocation to the (simplified) ELF. Return -error
85100 * or 0.
85101 @@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
85102 unsigned int relsec,
85103 struct module *me)
85104 {
85105 +#ifdef CONFIG_MODULES
85106 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
85107 +#endif
85108 return -ENOEXEC;
85109 }
85110 #endif
85111 @@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
85112 unsigned int relsec,
85113 struct module *me)
85114 {
85115 +#ifdef CONFIG_MODULES
85116 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
85117 +#endif
85118 return -ENOEXEC;
85119 }
85120 #endif
85121 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
85122 index b1990c5..2a6e611 100644
85123 --- a/include/linux/moduleparam.h
85124 +++ b/include/linux/moduleparam.h
85125 @@ -293,7 +293,7 @@ static inline void __kernel_param_unlock(void)
85126 * @len is usually just sizeof(string).
85127 */
85128 #define module_param_string(name, string, len, perm) \
85129 - static const struct kparam_string __param_string_##name \
85130 + static const struct kparam_string __param_string_##name __used \
85131 = { len, string }; \
85132 __module_param_call(MODULE_PARAM_PREFIX, name, \
85133 &param_ops_string, \
85134 @@ -432,7 +432,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
85135 */
85136 #define module_param_array_named(name, array, type, nump, perm) \
85137 param_check_##type(name, &(array)[0]); \
85138 - static const struct kparam_array __param_arr_##name \
85139 + static const struct kparam_array __param_arr_##name __used \
85140 = { .max = ARRAY_SIZE(array), .num = nump, \
85141 .ops = &param_ops_##type, \
85142 .elemsize = sizeof(array[0]), .elem = array }; \
85143 diff --git a/include/linux/mount.h b/include/linux/mount.h
85144 index 839bac2..a96b37c 100644
85145 --- a/include/linux/mount.h
85146 +++ b/include/linux/mount.h
85147 @@ -59,7 +59,7 @@ struct vfsmount {
85148 struct dentry *mnt_root; /* root of the mounted tree */
85149 struct super_block *mnt_sb; /* pointer to superblock */
85150 int mnt_flags;
85151 -};
85152 +} __randomize_layout;
85153
85154 struct file; /* forward dec */
85155
85156 diff --git a/include/linux/namei.h b/include/linux/namei.h
85157 index 492de72..1bddcd4 100644
85158 --- a/include/linux/namei.h
85159 +++ b/include/linux/namei.h
85160 @@ -19,7 +19,7 @@ struct nameidata {
85161 unsigned seq, m_seq;
85162 int last_type;
85163 unsigned depth;
85164 - char *saved_names[MAX_NESTED_LINKS + 1];
85165 + const char *saved_names[MAX_NESTED_LINKS + 1];
85166 };
85167
85168 /*
85169 @@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
85170
85171 extern void nd_jump_link(struct nameidata *nd, struct path *path);
85172
85173 -static inline void nd_set_link(struct nameidata *nd, char *path)
85174 +static inline void nd_set_link(struct nameidata *nd, const char *path)
85175 {
85176 nd->saved_names[nd->depth] = path;
85177 }
85178
85179 -static inline char *nd_get_link(struct nameidata *nd)
85180 +static inline const char *nd_get_link(const struct nameidata *nd)
85181 {
85182 return nd->saved_names[nd->depth];
85183 }
85184 diff --git a/include/linux/net.h b/include/linux/net.h
85185 index 17d8339..81656c0 100644
85186 --- a/include/linux/net.h
85187 +++ b/include/linux/net.h
85188 @@ -192,7 +192,7 @@ struct net_proto_family {
85189 int (*create)(struct net *net, struct socket *sock,
85190 int protocol, int kern);
85191 struct module *owner;
85192 -};
85193 +} __do_const;
85194
85195 struct iovec;
85196 struct kvec;
85197 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
85198 index 66f9a04..056078d 100644
85199 --- a/include/linux/netdevice.h
85200 +++ b/include/linux/netdevice.h
85201 @@ -1145,6 +1145,7 @@ struct net_device_ops {
85202 void *priv);
85203 int (*ndo_get_lock_subclass)(struct net_device *dev);
85204 };
85205 +typedef struct net_device_ops __no_const net_device_ops_no_const;
85206
85207 /**
85208 * enum net_device_priv_flags - &struct net_device priv_flags
85209 @@ -1312,11 +1313,11 @@ struct net_device {
85210 struct net_device_stats stats;
85211
85212 /* dropped packets by core network, Do not use this in drivers */
85213 - atomic_long_t rx_dropped;
85214 - atomic_long_t tx_dropped;
85215 + atomic_long_unchecked_t rx_dropped;
85216 + atomic_long_unchecked_t tx_dropped;
85217
85218 /* Stats to monitor carrier on<->off transitions */
85219 - atomic_t carrier_changes;
85220 + atomic_unchecked_t carrier_changes;
85221
85222 #ifdef CONFIG_WIRELESS_EXT
85223 /* List of functions to handle Wireless Extensions (instead of ioctl).
85224 diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
85225 index 2077489..a15e561 100644
85226 --- a/include/linux/netfilter.h
85227 +++ b/include/linux/netfilter.h
85228 @@ -84,7 +84,7 @@ struct nf_sockopt_ops {
85229 #endif
85230 /* Use the module struct to lock set/get code in place */
85231 struct module *owner;
85232 -};
85233 +} __do_const;
85234
85235 /* Function to register/unregister hook points. */
85236 int nf_register_hook(struct nf_hook_ops *reg);
85237 diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
85238 index e955d47..04a5338 100644
85239 --- a/include/linux/netfilter/nfnetlink.h
85240 +++ b/include/linux/netfilter/nfnetlink.h
85241 @@ -19,7 +19,7 @@ struct nfnl_callback {
85242 const struct nlattr * const cda[]);
85243 const struct nla_policy *policy; /* netlink attribute policy */
85244 const u_int16_t attr_count; /* number of nlattr's */
85245 -};
85246 +} __do_const;
85247
85248 struct nfnetlink_subsystem {
85249 const char *name;
85250 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
85251 new file mode 100644
85252 index 0000000..33f4af8
85253 --- /dev/null
85254 +++ b/include/linux/netfilter/xt_gradm.h
85255 @@ -0,0 +1,9 @@
85256 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
85257 +#define _LINUX_NETFILTER_XT_GRADM_H 1
85258 +
85259 +struct xt_gradm_mtinfo {
85260 + __u16 flags;
85261 + __u16 invflags;
85262 +};
85263 +
85264 +#endif
85265 diff --git a/include/linux/nls.h b/include/linux/nls.h
85266 index 520681b..2b7fabb 100644
85267 --- a/include/linux/nls.h
85268 +++ b/include/linux/nls.h
85269 @@ -31,7 +31,7 @@ struct nls_table {
85270 const unsigned char *charset2upper;
85271 struct module *owner;
85272 struct nls_table *next;
85273 -};
85274 +} __do_const;
85275
85276 /* this value hold the maximum octet of charset */
85277 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
85278 @@ -46,7 +46,7 @@ enum utf16_endian {
85279 /* nls_base.c */
85280 extern int __register_nls(struct nls_table *, struct module *);
85281 extern int unregister_nls(struct nls_table *);
85282 -extern struct nls_table *load_nls(char *);
85283 +extern struct nls_table *load_nls(const char *);
85284 extern void unload_nls(struct nls_table *);
85285 extern struct nls_table *load_nls_default(void);
85286 #define register_nls(nls) __register_nls((nls), THIS_MODULE)
85287 diff --git a/include/linux/notifier.h b/include/linux/notifier.h
85288 index d14a4c3..a078786 100644
85289 --- a/include/linux/notifier.h
85290 +++ b/include/linux/notifier.h
85291 @@ -54,7 +54,8 @@ struct notifier_block {
85292 notifier_fn_t notifier_call;
85293 struct notifier_block __rcu *next;
85294 int priority;
85295 -};
85296 +} __do_const;
85297 +typedef struct notifier_block __no_const notifier_block_no_const;
85298
85299 struct atomic_notifier_head {
85300 spinlock_t lock;
85301 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
85302 index b2a0f15..4d7da32 100644
85303 --- a/include/linux/oprofile.h
85304 +++ b/include/linux/oprofile.h
85305 @@ -138,9 +138,9 @@ int oprofilefs_create_ulong(struct dentry * root,
85306 int oprofilefs_create_ro_ulong(struct dentry * root,
85307 char const * name, ulong * val);
85308
85309 -/** Create a file for read-only access to an atomic_t. */
85310 +/** Create a file for read-only access to an atomic_unchecked_t. */
85311 int oprofilefs_create_ro_atomic(struct dentry * root,
85312 - char const * name, atomic_t * val);
85313 + char const * name, atomic_unchecked_t * val);
85314
85315 /** create a directory */
85316 struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name);
85317 diff --git a/include/linux/padata.h b/include/linux/padata.h
85318 index 4386946..f50c615 100644
85319 --- a/include/linux/padata.h
85320 +++ b/include/linux/padata.h
85321 @@ -129,7 +129,7 @@ struct parallel_data {
85322 struct padata_serial_queue __percpu *squeue;
85323 atomic_t reorder_objects;
85324 atomic_t refcnt;
85325 - atomic_t seq_nr;
85326 + atomic_unchecked_t seq_nr;
85327 struct padata_cpumask cpumask;
85328 spinlock_t lock ____cacheline_aligned;
85329 unsigned int processed;
85330 diff --git a/include/linux/path.h b/include/linux/path.h
85331 index d137218..be0c176 100644
85332 --- a/include/linux/path.h
85333 +++ b/include/linux/path.h
85334 @@ -1,13 +1,15 @@
85335 #ifndef _LINUX_PATH_H
85336 #define _LINUX_PATH_H
85337
85338 +#include <linux/compiler.h>
85339 +
85340 struct dentry;
85341 struct vfsmount;
85342
85343 struct path {
85344 struct vfsmount *mnt;
85345 struct dentry *dentry;
85346 -};
85347 +} __randomize_layout;
85348
85349 extern void path_get(const struct path *);
85350 extern void path_put(const struct path *);
85351 diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
85352 index 5f2e559..7d59314 100644
85353 --- a/include/linux/pci_hotplug.h
85354 +++ b/include/linux/pci_hotplug.h
85355 @@ -71,7 +71,8 @@ struct hotplug_slot_ops {
85356 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
85357 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
85358 int (*reset_slot) (struct hotplug_slot *slot, int probe);
85359 -};
85360 +} __do_const;
85361 +typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
85362
85363 /**
85364 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
85365 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
85366 index 707617a..28a2e7e 100644
85367 --- a/include/linux/perf_event.h
85368 +++ b/include/linux/perf_event.h
85369 @@ -339,8 +339,8 @@ struct perf_event {
85370
85371 enum perf_event_active_state state;
85372 unsigned int attach_state;
85373 - local64_t count;
85374 - atomic64_t child_count;
85375 + local64_t count; /* PaX: fix it one day */
85376 + atomic64_unchecked_t child_count;
85377
85378 /*
85379 * These are the total time in nanoseconds that the event
85380 @@ -391,8 +391,8 @@ struct perf_event {
85381 * These accumulate total time (in nanoseconds) that children
85382 * events have been enabled and running, respectively.
85383 */
85384 - atomic64_t child_total_time_enabled;
85385 - atomic64_t child_total_time_running;
85386 + atomic64_unchecked_t child_total_time_enabled;
85387 + atomic64_unchecked_t child_total_time_running;
85388
85389 /*
85390 * Protect attach/detach and child_list:
85391 @@ -722,7 +722,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
85392 entry->ip[entry->nr++] = ip;
85393 }
85394
85395 -extern int sysctl_perf_event_paranoid;
85396 +extern int sysctl_perf_event_legitimately_concerned;
85397 extern int sysctl_perf_event_mlock;
85398 extern int sysctl_perf_event_sample_rate;
85399 extern int sysctl_perf_cpu_time_max_percent;
85400 @@ -737,19 +737,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
85401 loff_t *ppos);
85402
85403
85404 +static inline bool perf_paranoid_any(void)
85405 +{
85406 + return sysctl_perf_event_legitimately_concerned > 2;
85407 +}
85408 +
85409 static inline bool perf_paranoid_tracepoint_raw(void)
85410 {
85411 - return sysctl_perf_event_paranoid > -1;
85412 + return sysctl_perf_event_legitimately_concerned > -1;
85413 }
85414
85415 static inline bool perf_paranoid_cpu(void)
85416 {
85417 - return sysctl_perf_event_paranoid > 0;
85418 + return sysctl_perf_event_legitimately_concerned > 0;
85419 }
85420
85421 static inline bool perf_paranoid_kernel(void)
85422 {
85423 - return sysctl_perf_event_paranoid > 1;
85424 + return sysctl_perf_event_legitimately_concerned > 1;
85425 }
85426
85427 extern void perf_event_init(void);
85428 @@ -880,7 +885,7 @@ struct perf_pmu_events_attr {
85429 struct device_attribute attr;
85430 u64 id;
85431 const char *event_str;
85432 -};
85433 +} __do_const;
85434
85435 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
85436 static struct perf_pmu_events_attr _var = { \
85437 diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
85438 index 7246ef3..1539ea4 100644
85439 --- a/include/linux/pid_namespace.h
85440 +++ b/include/linux/pid_namespace.h
85441 @@ -43,7 +43,7 @@ struct pid_namespace {
85442 int hide_pid;
85443 int reboot; /* group exit code if this pidns was rebooted */
85444 unsigned int proc_inum;
85445 -};
85446 +} __randomize_layout;
85447
85448 extern struct pid_namespace init_pid_ns;
85449
85450 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
85451 index eb8b8ac..62649e1 100644
85452 --- a/include/linux/pipe_fs_i.h
85453 +++ b/include/linux/pipe_fs_i.h
85454 @@ -47,10 +47,10 @@ struct pipe_inode_info {
85455 struct mutex mutex;
85456 wait_queue_head_t wait;
85457 unsigned int nrbufs, curbuf, buffers;
85458 - unsigned int readers;
85459 - unsigned int writers;
85460 - unsigned int files;
85461 - unsigned int waiting_writers;
85462 + atomic_t readers;
85463 + atomic_t writers;
85464 + atomic_t files;
85465 + atomic_t waiting_writers;
85466 unsigned int r_counter;
85467 unsigned int w_counter;
85468 struct page *tmp_page;
85469 diff --git a/include/linux/pm.h b/include/linux/pm.h
85470 index 72c0fe0..26918ed 100644
85471 --- a/include/linux/pm.h
85472 +++ b/include/linux/pm.h
85473 @@ -620,6 +620,7 @@ extern int dev_pm_put_subsys_data(struct device *dev);
85474 struct dev_pm_domain {
85475 struct dev_pm_ops ops;
85476 };
85477 +typedef struct dev_pm_domain __no_const dev_pm_domain_no_const;
85478
85479 /*
85480 * The PM_EVENT_ messages are also used by drivers implementing the legacy
85481 diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
85482 index 7c1d252..0e7061d 100644
85483 --- a/include/linux/pm_domain.h
85484 +++ b/include/linux/pm_domain.h
85485 @@ -44,11 +44,11 @@ struct gpd_dev_ops {
85486 int (*thaw_early)(struct device *dev);
85487 int (*thaw)(struct device *dev);
85488 bool (*active_wakeup)(struct device *dev);
85489 -};
85490 +} __no_const;
85491
85492 struct gpd_cpu_data {
85493 unsigned int saved_exit_latency;
85494 - struct cpuidle_state *idle_state;
85495 + cpuidle_state_no_const *idle_state;
85496 };
85497
85498 struct generic_pm_domain {
85499 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
85500 index 43fd671..08c96ee 100644
85501 --- a/include/linux/pm_runtime.h
85502 +++ b/include/linux/pm_runtime.h
85503 @@ -118,7 +118,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
85504
85505 static inline void pm_runtime_mark_last_busy(struct device *dev)
85506 {
85507 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
85508 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
85509 }
85510
85511 #else /* !CONFIG_PM_RUNTIME */
85512 diff --git a/include/linux/pnp.h b/include/linux/pnp.h
85513 index 195aafc..49a7bc2 100644
85514 --- a/include/linux/pnp.h
85515 +++ b/include/linux/pnp.h
85516 @@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
85517 struct pnp_fixup {
85518 char id[7];
85519 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
85520 -};
85521 +} __do_const;
85522
85523 /* config parameters */
85524 #define PNP_CONFIG_NORMAL 0x0001
85525 diff --git a/include/linux/poison.h b/include/linux/poison.h
85526 index 2110a81..13a11bb 100644
85527 --- a/include/linux/poison.h
85528 +++ b/include/linux/poison.h
85529 @@ -19,8 +19,8 @@
85530 * under normal circumstances, used to verify that nobody uses
85531 * non-initialized list entries.
85532 */
85533 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
85534 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
85535 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
85536 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
85537
85538 /********** include/linux/timer.h **********/
85539 /*
85540 diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
85541 index d8b187c3..9a9257a 100644
85542 --- a/include/linux/power/smartreflex.h
85543 +++ b/include/linux/power/smartreflex.h
85544 @@ -238,7 +238,7 @@ struct omap_sr_class_data {
85545 int (*notify)(struct omap_sr *sr, u32 status);
85546 u8 notify_flags;
85547 u8 class_type;
85548 -};
85549 +} __do_const;
85550
85551 /**
85552 * struct omap_sr_nvalue_table - Smartreflex n-target value info
85553 diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
85554 index 4ea1d37..80f4b33 100644
85555 --- a/include/linux/ppp-comp.h
85556 +++ b/include/linux/ppp-comp.h
85557 @@ -84,7 +84,7 @@ struct compressor {
85558 struct module *owner;
85559 /* Extra skb space needed by the compressor algorithm */
85560 unsigned int comp_extra;
85561 -};
85562 +} __do_const;
85563
85564 /*
85565 * The return value from decompress routine is the length of the
85566 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
85567 index de83b4e..c4b997d 100644
85568 --- a/include/linux/preempt.h
85569 +++ b/include/linux/preempt.h
85570 @@ -27,11 +27,16 @@ extern void preempt_count_sub(int val);
85571 #define preempt_count_dec_and_test() __preempt_count_dec_and_test()
85572 #endif
85573
85574 +#define raw_preempt_count_add(val) __preempt_count_add(val)
85575 +#define raw_preempt_count_sub(val) __preempt_count_sub(val)
85576 +
85577 #define __preempt_count_inc() __preempt_count_add(1)
85578 #define __preempt_count_dec() __preempt_count_sub(1)
85579
85580 #define preempt_count_inc() preempt_count_add(1)
85581 +#define raw_preempt_count_inc() raw_preempt_count_add(1)
85582 #define preempt_count_dec() preempt_count_sub(1)
85583 +#define raw_preempt_count_dec() raw_preempt_count_sub(1)
85584
85585 #ifdef CONFIG_PREEMPT_COUNT
85586
85587 @@ -41,6 +46,12 @@ do { \
85588 barrier(); \
85589 } while (0)
85590
85591 +#define raw_preempt_disable() \
85592 +do { \
85593 + raw_preempt_count_inc(); \
85594 + barrier(); \
85595 +} while (0)
85596 +
85597 #define sched_preempt_enable_no_resched() \
85598 do { \
85599 barrier(); \
85600 @@ -49,6 +60,12 @@ do { \
85601
85602 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
85603
85604 +#define raw_preempt_enable_no_resched() \
85605 +do { \
85606 + barrier(); \
85607 + raw_preempt_count_dec(); \
85608 +} while (0)
85609 +
85610 #ifdef CONFIG_PREEMPT
85611 #define preempt_enable() \
85612 do { \
85613 @@ -113,8 +130,10 @@ do { \
85614 * region.
85615 */
85616 #define preempt_disable() barrier()
85617 +#define raw_preempt_disable() barrier()
85618 #define sched_preempt_enable_no_resched() barrier()
85619 #define preempt_enable_no_resched() barrier()
85620 +#define raw_preempt_enable_no_resched() barrier()
85621 #define preempt_enable() barrier()
85622 #define preempt_check_resched() do { } while (0)
85623
85624 @@ -128,11 +147,13 @@ do { \
85625 /*
85626 * Modules have no business playing preemption tricks.
85627 */
85628 +#ifndef CONFIG_PAX_KERNEXEC
85629 #undef sched_preempt_enable_no_resched
85630 #undef preempt_enable_no_resched
85631 #undef preempt_enable_no_resched_notrace
85632 #undef preempt_check_resched
85633 #endif
85634 +#endif
85635
85636 #define preempt_set_need_resched() \
85637 do { \
85638 diff --git a/include/linux/printk.h b/include/linux/printk.h
85639 index 319ff7e..608849a 100644
85640 --- a/include/linux/printk.h
85641 +++ b/include/linux/printk.h
85642 @@ -121,6 +121,8 @@ static inline __printf(1, 2) __cold
85643 void early_printk(const char *s, ...) { }
85644 #endif
85645
85646 +extern int kptr_restrict;
85647 +
85648 #ifdef CONFIG_PRINTK
85649 asmlinkage __printf(5, 0)
85650 int vprintk_emit(int facility, int level,
85651 @@ -155,7 +157,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
85652
85653 extern int printk_delay_msec;
85654 extern int dmesg_restrict;
85655 -extern int kptr_restrict;
85656
85657 extern void wake_up_klogd(void);
85658
85659 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
85660 index 9d117f6..d832b31 100644
85661 --- a/include/linux/proc_fs.h
85662 +++ b/include/linux/proc_fs.h
85663 @@ -17,8 +17,11 @@ extern void proc_flush_task(struct task_struct *);
85664 extern struct proc_dir_entry *proc_symlink(const char *,
85665 struct proc_dir_entry *, const char *);
85666 extern struct proc_dir_entry *proc_mkdir(const char *, struct proc_dir_entry *);
85667 +extern struct proc_dir_entry *proc_mkdir_restrict(const char *, struct proc_dir_entry *);
85668 extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
85669 struct proc_dir_entry *, void *);
85670 +extern struct proc_dir_entry *proc_mkdir_data_restrict(const char *, umode_t,
85671 + struct proc_dir_entry *, void *);
85672 extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t,
85673 struct proc_dir_entry *);
85674
85675 @@ -34,6 +37,19 @@ static inline struct proc_dir_entry *proc_create(
85676 return proc_create_data(name, mode, parent, proc_fops, NULL);
85677 }
85678
85679 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
85680 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
85681 +{
85682 +#ifdef CONFIG_GRKERNSEC_PROC_USER
85683 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
85684 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
85685 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
85686 +#else
85687 + return proc_create_data(name, mode, parent, proc_fops, NULL);
85688 +#endif
85689 +}
85690 +
85691 +
85692 extern void proc_set_size(struct proc_dir_entry *, loff_t);
85693 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
85694 extern void *PDE_DATA(const struct inode *);
85695 @@ -56,8 +72,12 @@ static inline struct proc_dir_entry *proc_symlink(const char *name,
85696 struct proc_dir_entry *parent,const char *dest) { return NULL;}
85697 static inline struct proc_dir_entry *proc_mkdir(const char *name,
85698 struct proc_dir_entry *parent) {return NULL;}
85699 +static inline struct proc_dir_entry *proc_mkdir_restrict(const char *name,
85700 + struct proc_dir_entry *parent) { return NULL; }
85701 static inline struct proc_dir_entry *proc_mkdir_data(const char *name,
85702 umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
85703 +static inline struct proc_dir_entry *proc_mkdir_data_restrict(const char *name,
85704 + umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
85705 static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
85706 umode_t mode, struct proc_dir_entry *parent) { return NULL; }
85707 #define proc_create(name, mode, parent, proc_fops) ({NULL;})
85708 @@ -77,7 +97,7 @@ static inline int remove_proc_subtree(const char *name, struct proc_dir_entry *p
85709 static inline struct proc_dir_entry *proc_net_mkdir(
85710 struct net *net, const char *name, struct proc_dir_entry *parent)
85711 {
85712 - return proc_mkdir_data(name, 0, parent, net);
85713 + return proc_mkdir_data_restrict(name, 0, parent, net);
85714 }
85715
85716 #endif /* _LINUX_PROC_FS_H */
85717 diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
85718 index 34a1e10..70f6bde 100644
85719 --- a/include/linux/proc_ns.h
85720 +++ b/include/linux/proc_ns.h
85721 @@ -14,7 +14,7 @@ struct proc_ns_operations {
85722 void (*put)(void *ns);
85723 int (*install)(struct nsproxy *nsproxy, void *ns);
85724 unsigned int (*inum)(void *ns);
85725 -};
85726 +} __do_const __randomize_layout;
85727
85728 struct proc_ns {
85729 void *ns;
85730 diff --git a/include/linux/ptp_classify.h b/include/linux/ptp_classify.h
85731 index 7dfed71..1dc420b 100644
85732 --- a/include/linux/ptp_classify.h
85733 +++ b/include/linux/ptp_classify.h
85734 @@ -23,8 +23,15 @@
85735 #ifndef _PTP_CLASSIFY_H_
85736 #define _PTP_CLASSIFY_H_
85737
85738 +#include <linux/if_ether.h>
85739 +#include <linux/if_vlan.h>
85740 #include <linux/ip.h>
85741 -#include <linux/skbuff.h>
85742 +#include <linux/filter.h>
85743 +#ifdef __KERNEL__
85744 +#include <linux/in.h>
85745 +#else
85746 +#include <netinet/in.h>
85747 +#endif
85748
85749 #define PTP_CLASS_NONE 0x00 /* not a PTP event message */
85750 #define PTP_CLASS_V1 0x01 /* protocol version 1 */
85751 @@ -37,7 +44,7 @@
85752 #define PTP_CLASS_PMASK 0xf0 /* mask for the packet type field */
85753
85754 #define PTP_CLASS_V1_IPV4 (PTP_CLASS_V1 | PTP_CLASS_IPV4)
85755 -#define PTP_CLASS_V1_IPV6 (PTP_CLASS_V1 | PTP_CLASS_IPV6) /* probably DNE */
85756 +#define PTP_CLASS_V1_IPV6 (PTP_CLASS_V1 | PTP_CLASS_IPV6) /*probably DNE*/
85757 #define PTP_CLASS_V2_IPV4 (PTP_CLASS_V2 | PTP_CLASS_IPV4)
85758 #define PTP_CLASS_V2_IPV6 (PTP_CLASS_V2 | PTP_CLASS_IPV6)
85759 #define PTP_CLASS_V2_L2 (PTP_CLASS_V2 | PTP_CLASS_L2)
85760 @@ -46,34 +53,88 @@
85761 #define PTP_EV_PORT 319
85762 #define PTP_GEN_BIT 0x08 /* indicates general message, if set in message type */
85763
85764 +#define OFF_ETYPE 12
85765 +#define OFF_IHL 14
85766 +#define OFF_FRAG 20
85767 +#define OFF_PROTO4 23
85768 +#define OFF_NEXT 6
85769 +#define OFF_UDP_DST 2
85770 +
85771 #define OFF_PTP_SOURCE_UUID 22 /* PTPv1 only */
85772 #define OFF_PTP_SEQUENCE_ID 30
85773 #define OFF_PTP_CONTROL 32 /* PTPv1 only */
85774
85775 -/* Below defines should actually be removed at some point in time. */
85776 +#define IPV4_HLEN(data) (((struct iphdr *)(data + OFF_IHL))->ihl << 2)
85777 +
85778 #define IP6_HLEN 40
85779 #define UDP_HLEN 8
85780 -#define OFF_IHL 14
85781 +
85782 +#define RELOFF_DST4 (ETH_HLEN + OFF_UDP_DST)
85783 +#define OFF_DST6 (ETH_HLEN + IP6_HLEN + OFF_UDP_DST)
85784 #define OFF_PTP6 (ETH_HLEN + IP6_HLEN + UDP_HLEN)
85785 -#define IPV4_HLEN(data) (((struct iphdr *)(data + OFF_IHL))->ihl << 2)
85786
85787 -#if defined(CONFIG_NET_PTP_CLASSIFY)
85788 -/**
85789 - * ptp_classify_raw - classify a PTP packet
85790 - * @skb: buffer
85791 - *
85792 - * Runs a minimal BPF dissector to classify a network packet to
85793 - * determine the PTP class. In case the skb does not contain any
85794 - * PTP protocol data, PTP_CLASS_NONE will be returned, otherwise
85795 - * PTP_CLASS_V1_IPV{4,6}, PTP_CLASS_V2_IPV{4,6} or
85796 - * PTP_CLASS_V2_{L2,VLAN}, depending on the packet content.
85797 - */
85798 -unsigned int ptp_classify_raw(const struct sk_buff *skb);
85799 +#define OP_AND (BPF_ALU | BPF_AND | BPF_K)
85800 +#define OP_JEQ (BPF_JMP | BPF_JEQ | BPF_K)
85801 +#define OP_JSET (BPF_JMP | BPF_JSET | BPF_K)
85802 +#define OP_LDB (BPF_LD | BPF_B | BPF_ABS)
85803 +#define OP_LDH (BPF_LD | BPF_H | BPF_ABS)
85804 +#define OP_LDHI (BPF_LD | BPF_H | BPF_IND)
85805 +#define OP_LDX (BPF_LDX | BPF_B | BPF_MSH)
85806 +#define OP_OR (BPF_ALU | BPF_OR | BPF_K)
85807 +#define OP_RETA (BPF_RET | BPF_A)
85808 +#define OP_RETK (BPF_RET | BPF_K)
85809
85810 -void __init ptp_classifier_init(void);
85811 -#else
85812 -static inline void ptp_classifier_init(void)
85813 +static inline int ptp_filter_init(struct sock_filter *f, int len)
85814 {
85815 + if (OP_LDH == f[0].code)
85816 + return sk_chk_filter(f, len);
85817 + else
85818 + return 0;
85819 }
85820 +
85821 +#define PTP_FILTER \
85822 + {OP_LDH, 0, 0, OFF_ETYPE }, /* */ \
85823 + {OP_JEQ, 0, 12, ETH_P_IP }, /* f goto L20 */ \
85824 + {OP_LDB, 0, 0, OFF_PROTO4 }, /* */ \
85825 + {OP_JEQ, 0, 9, IPPROTO_UDP }, /* f goto L10 */ \
85826 + {OP_LDH, 0, 0, OFF_FRAG }, /* */ \
85827 + {OP_JSET, 7, 0, 0x1fff }, /* t goto L11 */ \
85828 + {OP_LDX, 0, 0, OFF_IHL }, /* */ \
85829 + {OP_LDHI, 0, 0, RELOFF_DST4 }, /* */ \
85830 + {OP_JEQ, 0, 4, PTP_EV_PORT }, /* f goto L12 */ \
85831 + {OP_LDHI, 0, 0, ETH_HLEN + UDP_HLEN }, /* */ \
85832 + {OP_AND, 0, 0, PTP_CLASS_VMASK }, /* */ \
85833 + {OP_OR, 0, 0, PTP_CLASS_IPV4 }, /* */ \
85834 + {OP_RETA, 0, 0, 0 }, /* */ \
85835 +/*L1x*/ {OP_RETK, 0, 0, PTP_CLASS_NONE }, /* */ \
85836 +/*L20*/ {OP_JEQ, 0, 9, ETH_P_IPV6 }, /* f goto L40 */ \
85837 + {OP_LDB, 0, 0, ETH_HLEN + OFF_NEXT }, /* */ \
85838 + {OP_JEQ, 0, 6, IPPROTO_UDP }, /* f goto L30 */ \
85839 + {OP_LDH, 0, 0, OFF_DST6 }, /* */ \
85840 + {OP_JEQ, 0, 4, PTP_EV_PORT }, /* f goto L31 */ \
85841 + {OP_LDH, 0, 0, OFF_PTP6 }, /* */ \
85842 + {OP_AND, 0, 0, PTP_CLASS_VMASK }, /* */ \
85843 + {OP_OR, 0, 0, PTP_CLASS_IPV6 }, /* */ \
85844 + {OP_RETA, 0, 0, 0 }, /* */ \
85845 +/*L3x*/ {OP_RETK, 0, 0, PTP_CLASS_NONE }, /* */ \
85846 +/*L40*/ {OP_JEQ, 0, 9, ETH_P_8021Q }, /* f goto L50 */ \
85847 + {OP_LDH, 0, 0, OFF_ETYPE + 4 }, /* */ \
85848 + {OP_JEQ, 0, 15, ETH_P_1588 }, /* f goto L60 */ \
85849 + {OP_LDB, 0, 0, ETH_HLEN + VLAN_HLEN }, /* */ \
85850 + {OP_AND, 0, 0, PTP_GEN_BIT }, /* */ \
85851 + {OP_JEQ, 0, 12, 0 }, /* f goto L6x */ \
85852 + {OP_LDH, 0, 0, ETH_HLEN + VLAN_HLEN }, /* */ \
85853 + {OP_AND, 0, 0, PTP_CLASS_VMASK }, /* */ \
85854 + {OP_OR, 0, 0, PTP_CLASS_VLAN }, /* */ \
85855 + {OP_RETA, 0, 0, 0 }, /* */ \
85856 +/*L50*/ {OP_JEQ, 0, 7, ETH_P_1588 }, /* f goto L61 */ \
85857 + {OP_LDB, 0, 0, ETH_HLEN }, /* */ \
85858 + {OP_AND, 0, 0, PTP_GEN_BIT }, /* */ \
85859 + {OP_JEQ, 0, 4, 0 }, /* f goto L6x */ \
85860 + {OP_LDH, 0, 0, ETH_HLEN }, /* */ \
85861 + {OP_AND, 0, 0, PTP_CLASS_VMASK }, /* */ \
85862 + {OP_OR, 0, 0, PTP_CLASS_L2 }, /* */ \
85863 + {OP_RETA, 0, 0, 0 }, /* */ \
85864 +/*L6x*/ {OP_RETK, 0, 0, PTP_CLASS_NONE },
85865 +
85866 #endif
85867 -#endif /* _PTP_CLASSIFY_H_ */
85868 diff --git a/include/linux/quota.h b/include/linux/quota.h
85869 index 0f3c5d3..bc559e3 100644
85870 --- a/include/linux/quota.h
85871 +++ b/include/linux/quota.h
85872 @@ -70,7 +70,7 @@ struct kqid { /* Type in which we store the quota identifier */
85873
85874 extern bool qid_eq(struct kqid left, struct kqid right);
85875 extern bool qid_lt(struct kqid left, struct kqid right);
85876 -extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
85877 +extern qid_t from_kqid(struct user_namespace *to, struct kqid qid) __intentional_overflow(-1);
85878 extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
85879 extern bool qid_valid(struct kqid qid);
85880
85881 diff --git a/include/linux/random.h b/include/linux/random.h
85882 index 57fbbff..2170304 100644
85883 --- a/include/linux/random.h
85884 +++ b/include/linux/random.h
85885 @@ -9,9 +9,19 @@
85886 #include <uapi/linux/random.h>
85887
85888 extern void add_device_randomness(const void *, unsigned int);
85889 +
85890 +static inline void add_latent_entropy(void)
85891 +{
85892 +
85893 +#ifdef LATENT_ENTROPY_PLUGIN
85894 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
85895 +#endif
85896 +
85897 +}
85898 +
85899 extern void add_input_randomness(unsigned int type, unsigned int code,
85900 - unsigned int value);
85901 -extern void add_interrupt_randomness(int irq, int irq_flags);
85902 + unsigned int value) __latent_entropy;
85903 +extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
85904
85905 extern void get_random_bytes(void *buf, int nbytes);
85906 extern void get_random_bytes_arch(void *buf, int nbytes);
85907 @@ -22,10 +32,10 @@ extern int random_int_secret_init(void);
85908 extern const struct file_operations random_fops, urandom_fops;
85909 #endif
85910
85911 -unsigned int get_random_int(void);
85912 +unsigned int __intentional_overflow(-1) get_random_int(void);
85913 unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
85914
85915 -u32 prandom_u32(void);
85916 +u32 prandom_u32(void) __intentional_overflow(-1);
85917 void prandom_bytes(void *buf, int nbytes);
85918 void prandom_seed(u32 seed);
85919 void prandom_reseed_late(void);
85920 @@ -37,6 +47,11 @@ struct rnd_state {
85921 u32 prandom_u32_state(struct rnd_state *state);
85922 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
85923
85924 +static inline unsigned long __intentional_overflow(-1) pax_get_random_long(void)
85925 +{
85926 + return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
85927 +}
85928 +
85929 /**
85930 * prandom_u32_max - returns a pseudo-random number in interval [0, ep_ro)
85931 * @ep_ro: right open interval endpoint
85932 @@ -49,7 +64,7 @@ void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
85933 *
85934 * Returns: pseudo-random number in interval [0, ep_ro)
85935 */
85936 -static inline u32 prandom_u32_max(u32 ep_ro)
85937 +static inline u32 __intentional_overflow(-1) prandom_u32_max(u32 ep_ro)
85938 {
85939 return (u32)(((u64) prandom_u32() * ep_ro) >> 32);
85940 }
85941 diff --git a/include/linux/rbtree_augmented.h b/include/linux/rbtree_augmented.h
85942 index fea49b5..2ac22bb 100644
85943 --- a/include/linux/rbtree_augmented.h
85944 +++ b/include/linux/rbtree_augmented.h
85945 @@ -80,7 +80,9 @@ rbname ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new) \
85946 old->rbaugmented = rbcompute(old); \
85947 } \
85948 rbstatic const struct rb_augment_callbacks rbname = { \
85949 - rbname ## _propagate, rbname ## _copy, rbname ## _rotate \
85950 + .propagate = rbname ## _propagate, \
85951 + .copy = rbname ## _copy, \
85952 + .rotate = rbname ## _rotate \
85953 };
85954
85955
85956 diff --git a/include/linux/rculist.h b/include/linux/rculist.h
85957 index 8183b46..a388711 100644
85958 --- a/include/linux/rculist.h
85959 +++ b/include/linux/rculist.h
85960 @@ -29,8 +29,8 @@
85961 */
85962 static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
85963 {
85964 - ACCESS_ONCE(list->next) = list;
85965 - ACCESS_ONCE(list->prev) = list;
85966 + ACCESS_ONCE_RW(list->next) = list;
85967 + ACCESS_ONCE_RW(list->prev) = list;
85968 }
85969
85970 /*
85971 @@ -59,6 +59,9 @@ void __list_add_rcu(struct list_head *new,
85972 struct list_head *prev, struct list_head *next);
85973 #endif
85974
85975 +void __pax_list_add_rcu(struct list_head *new,
85976 + struct list_head *prev, struct list_head *next);
85977 +
85978 /**
85979 * list_add_rcu - add a new entry to rcu-protected list
85980 * @new: new entry to be added
85981 @@ -80,6 +83,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
85982 __list_add_rcu(new, head, head->next);
85983 }
85984
85985 +static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
85986 +{
85987 + __pax_list_add_rcu(new, head, head->next);
85988 +}
85989 +
85990 /**
85991 * list_add_tail_rcu - add a new entry to rcu-protected list
85992 * @new: new entry to be added
85993 @@ -102,6 +110,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
85994 __list_add_rcu(new, head->prev, head);
85995 }
85996
85997 +static inline void pax_list_add_tail_rcu(struct list_head *new,
85998 + struct list_head *head)
85999 +{
86000 + __pax_list_add_rcu(new, head->prev, head);
86001 +}
86002 +
86003 /**
86004 * list_del_rcu - deletes entry from list without re-initialization
86005 * @entry: the element to delete from the list.
86006 @@ -132,6 +146,8 @@ static inline void list_del_rcu(struct list_head *entry)
86007 entry->prev = LIST_POISON2;
86008 }
86009
86010 +extern void pax_list_del_rcu(struct list_head *entry);
86011 +
86012 /**
86013 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
86014 * @n: the element to delete from the hash list.
86015 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
86016 index 48bf152..d38b785 100644
86017 --- a/include/linux/reboot.h
86018 +++ b/include/linux/reboot.h
86019 @@ -44,9 +44,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
86020 */
86021
86022 extern void migrate_to_reboot_cpu(void);
86023 -extern void machine_restart(char *cmd);
86024 -extern void machine_halt(void);
86025 -extern void machine_power_off(void);
86026 +extern void machine_restart(char *cmd) __noreturn;
86027 +extern void machine_halt(void) __noreturn;
86028 +extern void machine_power_off(void) __noreturn;
86029
86030 extern void machine_shutdown(void);
86031 struct pt_regs;
86032 @@ -57,9 +57,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
86033 */
86034
86035 extern void kernel_restart_prepare(char *cmd);
86036 -extern void kernel_restart(char *cmd);
86037 -extern void kernel_halt(void);
86038 -extern void kernel_power_off(void);
86039 +extern void kernel_restart(char *cmd) __noreturn;
86040 +extern void kernel_halt(void) __noreturn;
86041 +extern void kernel_power_off(void) __noreturn;
86042
86043 extern int C_A_D; /* for sysctl */
86044 void ctrl_alt_del(void);
86045 @@ -73,7 +73,7 @@ extern int orderly_poweroff(bool force);
86046 * Emergency restart, callable from an interrupt handler.
86047 */
86048
86049 -extern void emergency_restart(void);
86050 +extern void emergency_restart(void) __noreturn;
86051 #include <asm/emergency-restart.h>
86052
86053 #endif /* _LINUX_REBOOT_H */
86054 diff --git a/include/linux/regset.h b/include/linux/regset.h
86055 index 8e0c9fe..ac4d221 100644
86056 --- a/include/linux/regset.h
86057 +++ b/include/linux/regset.h
86058 @@ -161,7 +161,8 @@ struct user_regset {
86059 unsigned int align;
86060 unsigned int bias;
86061 unsigned int core_note_type;
86062 -};
86063 +} __do_const;
86064 +typedef struct user_regset __no_const user_regset_no_const;
86065
86066 /**
86067 * struct user_regset_view - available regsets
86068 diff --git a/include/linux/relay.h b/include/linux/relay.h
86069 index d7c8359..818daf5 100644
86070 --- a/include/linux/relay.h
86071 +++ b/include/linux/relay.h
86072 @@ -157,7 +157,7 @@ struct rchan_callbacks
86073 * The callback should return 0 if successful, negative if not.
86074 */
86075 int (*remove_buf_file)(struct dentry *dentry);
86076 -};
86077 +} __no_const;
86078
86079 /*
86080 * CONFIG_RELAY kernel API, kernel/relay.c
86081 diff --git a/include/linux/rio.h b/include/linux/rio.h
86082 index 6bda06f..bf39a9b 100644
86083 --- a/include/linux/rio.h
86084 +++ b/include/linux/rio.h
86085 @@ -358,7 +358,7 @@ struct rio_ops {
86086 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
86087 u64 rstart, u32 size, u32 flags);
86088 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
86089 -};
86090 +} __no_const;
86091
86092 #define RIO_RESOURCE_MEM 0x00000100
86093 #define RIO_RESOURCE_DOORBELL 0x00000200
86094 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
86095 index be57450..31cf65e 100644
86096 --- a/include/linux/rmap.h
86097 +++ b/include/linux/rmap.h
86098 @@ -144,8 +144,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
86099 void anon_vma_init(void); /* create anon_vma_cachep */
86100 int anon_vma_prepare(struct vm_area_struct *);
86101 void unlink_anon_vmas(struct vm_area_struct *);
86102 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
86103 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
86104 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
86105 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
86106
86107 static inline void anon_vma_merge(struct vm_area_struct *vma,
86108 struct vm_area_struct *next)
86109 diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h
86110 index a964f72..b475afb 100644
86111 --- a/include/linux/scatterlist.h
86112 +++ b/include/linux/scatterlist.h
86113 @@ -1,6 +1,7 @@
86114 #ifndef _LINUX_SCATTERLIST_H
86115 #define _LINUX_SCATTERLIST_H
86116
86117 +#include <linux/sched.h>
86118 #include <linux/string.h>
86119 #include <linux/bug.h>
86120 #include <linux/mm.h>
86121 @@ -114,6 +115,12 @@ static inline void sg_set_buf(struct scatterlist *sg, const void *buf,
86122 #ifdef CONFIG_DEBUG_SG
86123 BUG_ON(!virt_addr_valid(buf));
86124 #endif
86125 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
86126 + if (object_starts_on_stack(buf)) {
86127 + void *adjbuf = buf - current->stack + current->lowmem_stack;
86128 + sg_set_page(sg, virt_to_page(adjbuf), buflen, offset_in_page(adjbuf));
86129 + } else
86130 +#endif
86131 sg_set_page(sg, virt_to_page(buf), buflen, offset_in_page(buf));
86132 }
86133
86134 diff --git a/include/linux/sched.h b/include/linux/sched.h
86135 index 0376b05..82054c2 100644
86136 --- a/include/linux/sched.h
86137 +++ b/include/linux/sched.h
86138 @@ -131,6 +131,7 @@ struct fs_struct;
86139 struct perf_event_context;
86140 struct blk_plug;
86141 struct filename;
86142 +struct linux_binprm;
86143
86144 #define VMACACHE_BITS 2
86145 #define VMACACHE_SIZE (1U << VMACACHE_BITS)
86146 @@ -374,7 +375,7 @@ extern char __sched_text_start[], __sched_text_end[];
86147 extern int in_sched_functions(unsigned long addr);
86148
86149 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
86150 -extern signed long schedule_timeout(signed long timeout);
86151 +extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
86152 extern signed long schedule_timeout_interruptible(signed long timeout);
86153 extern signed long schedule_timeout_killable(signed long timeout);
86154 extern signed long schedule_timeout_uninterruptible(signed long timeout);
86155 @@ -385,6 +386,19 @@ struct nsproxy;
86156 struct user_namespace;
86157
86158 #ifdef CONFIG_MMU
86159 +
86160 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
86161 +extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
86162 +#else
86163 +static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
86164 +{
86165 + return 0;
86166 +}
86167 +#endif
86168 +
86169 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
86170 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
86171 +
86172 extern void arch_pick_mmap_layout(struct mm_struct *mm);
86173 extern unsigned long
86174 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
86175 @@ -682,6 +696,17 @@ struct signal_struct {
86176 #ifdef CONFIG_TASKSTATS
86177 struct taskstats *stats;
86178 #endif
86179 +
86180 +#ifdef CONFIG_GRKERNSEC
86181 + u32 curr_ip;
86182 + u32 saved_ip;
86183 + u32 gr_saddr;
86184 + u32 gr_daddr;
86185 + u16 gr_sport;
86186 + u16 gr_dport;
86187 + u8 used_accept:1;
86188 +#endif
86189 +
86190 #ifdef CONFIG_AUDIT
86191 unsigned audit_tty;
86192 unsigned audit_tty_log_passwd;
86193 @@ -708,7 +733,7 @@ struct signal_struct {
86194 struct mutex cred_guard_mutex; /* guard against foreign influences on
86195 * credential calculations
86196 * (notably. ptrace) */
86197 -};
86198 +} __randomize_layout;
86199
86200 /*
86201 * Bits in flags field of signal_struct.
86202 @@ -761,6 +786,14 @@ struct user_struct {
86203 struct key *session_keyring; /* UID's default session keyring */
86204 #endif
86205
86206 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
86207 + unsigned char kernel_banned;
86208 +#endif
86209 +#ifdef CONFIG_GRKERNSEC_BRUTE
86210 + unsigned char suid_banned;
86211 + unsigned long suid_ban_expires;
86212 +#endif
86213 +
86214 /* Hash table maintenance information */
86215 struct hlist_node uidhash_node;
86216 kuid_t uid;
86217 @@ -768,7 +801,7 @@ struct user_struct {
86218 #ifdef CONFIG_PERF_EVENTS
86219 atomic_long_t locked_vm;
86220 #endif
86221 -};
86222 +} __randomize_layout;
86223
86224 extern int uids_sysfs_init(void);
86225
86226 @@ -1224,6 +1257,9 @@ enum perf_event_task_context {
86227 struct task_struct {
86228 volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */
86229 void *stack;
86230 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
86231 + void *lowmem_stack;
86232 +#endif
86233 atomic_t usage;
86234 unsigned int flags; /* per process flags, defined below */
86235 unsigned int ptrace;
86236 @@ -1349,8 +1385,8 @@ struct task_struct {
86237 struct list_head thread_node;
86238
86239 struct completion *vfork_done; /* for vfork() */
86240 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
86241 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
86242 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
86243 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
86244
86245 cputime_t utime, stime, utimescaled, stimescaled;
86246 cputime_t gtime;
86247 @@ -1375,11 +1411,6 @@ struct task_struct {
86248 struct task_cputime cputime_expires;
86249 struct list_head cpu_timers[3];
86250
86251 -/* process credentials */
86252 - const struct cred __rcu *real_cred; /* objective and real subjective task
86253 - * credentials (COW) */
86254 - const struct cred __rcu *cred; /* effective (overridable) subjective task
86255 - * credentials (COW) */
86256 char comm[TASK_COMM_LEN]; /* executable name excluding path
86257 - access with [gs]et_task_comm (which lock
86258 it with task_lock())
86259 @@ -1396,6 +1427,10 @@ struct task_struct {
86260 #endif
86261 /* CPU-specific state of this task */
86262 struct thread_struct thread;
86263 +/* thread_info moved to task_struct */
86264 +#ifdef CONFIG_X86
86265 + struct thread_info tinfo;
86266 +#endif
86267 /* filesystem information */
86268 struct fs_struct *fs;
86269 /* open file information */
86270 @@ -1472,6 +1507,10 @@ struct task_struct {
86271 gfp_t lockdep_reclaim_gfp;
86272 #endif
86273
86274 +/* process credentials */
86275 + const struct cred __rcu *real_cred; /* objective and real subjective task
86276 + * credentials (COW) */
86277 +
86278 /* journalling filesystem info */
86279 void *journal_info;
86280
86281 @@ -1510,6 +1549,10 @@ struct task_struct {
86282 /* cg_list protected by css_set_lock and tsk->alloc_lock */
86283 struct list_head cg_list;
86284 #endif
86285 +
86286 + const struct cred __rcu *cred; /* effective (overridable) subjective task
86287 + * credentials (COW) */
86288 +
86289 #ifdef CONFIG_FUTEX
86290 struct robust_list_head __user *robust_list;
86291 #ifdef CONFIG_COMPAT
86292 @@ -1655,7 +1698,78 @@ struct task_struct {
86293 unsigned int sequential_io;
86294 unsigned int sequential_io_avg;
86295 #endif
86296 -};
86297 +
86298 +#ifdef CONFIG_GRKERNSEC
86299 + /* grsecurity */
86300 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
86301 + u64 exec_id;
86302 +#endif
86303 +#ifdef CONFIG_GRKERNSEC_SETXID
86304 + const struct cred *delayed_cred;
86305 +#endif
86306 + struct dentry *gr_chroot_dentry;
86307 + struct acl_subject_label *acl;
86308 + struct acl_subject_label *tmpacl;
86309 + struct acl_role_label *role;
86310 + struct file *exec_file;
86311 + unsigned long brute_expires;
86312 + u16 acl_role_id;
86313 + u8 inherited;
86314 + /* is this the task that authenticated to the special role */
86315 + u8 acl_sp_role;
86316 + u8 is_writable;
86317 + u8 brute;
86318 + u8 gr_is_chrooted;
86319 +#endif
86320 +
86321 +} __randomize_layout;
86322 +
86323 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
86324 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
86325 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
86326 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
86327 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
86328 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
86329 +
86330 +#ifdef CONFIG_PAX_SOFTMODE
86331 +extern int pax_softmode;
86332 +#endif
86333 +
86334 +extern int pax_check_flags(unsigned long *);
86335 +#define PAX_PARSE_FLAGS_FALLBACK (~0UL)
86336 +
86337 +/* if tsk != current then task_lock must be held on it */
86338 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
86339 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
86340 +{
86341 + if (likely(tsk->mm))
86342 + return tsk->mm->pax_flags;
86343 + else
86344 + return 0UL;
86345 +}
86346 +
86347 +/* if tsk != current then task_lock must be held on it */
86348 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
86349 +{
86350 + if (likely(tsk->mm)) {
86351 + tsk->mm->pax_flags = flags;
86352 + return 0;
86353 + }
86354 + return -EINVAL;
86355 +}
86356 +#endif
86357 +
86358 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
86359 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
86360 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
86361 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
86362 +#endif
86363 +
86364 +struct path;
86365 +extern char *pax_get_path(const struct path *path, char *buf, int buflen);
86366 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
86367 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
86368 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
86369
86370 /* Future-safe accessor for struct task_struct's cpus_allowed. */
86371 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
86372 @@ -1737,7 +1851,7 @@ struct pid_namespace;
86373 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
86374 struct pid_namespace *ns);
86375
86376 -static inline pid_t task_pid_nr(struct task_struct *tsk)
86377 +static inline pid_t task_pid_nr(const struct task_struct *tsk)
86378 {
86379 return tsk->pid;
86380 }
86381 @@ -2084,6 +2198,25 @@ extern u64 sched_clock_cpu(int cpu);
86382
86383 extern void sched_clock_init(void);
86384
86385 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
86386 +static inline void populate_stack(void)
86387 +{
86388 + struct task_struct *curtask = current;
86389 + int c;
86390 + int *ptr = curtask->stack;
86391 + int *end = curtask->stack + THREAD_SIZE;
86392 +
86393 + while (ptr < end) {
86394 + c = *(volatile int *)ptr;
86395 + ptr += PAGE_SIZE/sizeof(int);
86396 + }
86397 +}
86398 +#else
86399 +static inline void populate_stack(void)
86400 +{
86401 +}
86402 +#endif
86403 +
86404 #ifndef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
86405 static inline void sched_clock_tick(void)
86406 {
86407 @@ -2217,7 +2350,9 @@ void yield(void);
86408 extern struct exec_domain default_exec_domain;
86409
86410 union thread_union {
86411 +#ifndef CONFIG_X86
86412 struct thread_info thread_info;
86413 +#endif
86414 unsigned long stack[THREAD_SIZE/sizeof(long)];
86415 };
86416
86417 @@ -2250,6 +2385,7 @@ extern struct pid_namespace init_pid_ns;
86418 */
86419
86420 extern struct task_struct *find_task_by_vpid(pid_t nr);
86421 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
86422 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
86423 struct pid_namespace *ns);
86424
86425 @@ -2412,7 +2548,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
86426 extern void exit_itimers(struct signal_struct *);
86427 extern void flush_itimer_signals(void);
86428
86429 -extern void do_group_exit(int);
86430 +extern __noreturn void do_group_exit(int);
86431
86432 extern int do_execve(struct filename *,
86433 const char __user * const __user *,
86434 @@ -2614,9 +2750,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
86435
86436 #endif
86437
86438 -static inline int object_is_on_stack(void *obj)
86439 +static inline int object_starts_on_stack(const void *obj)
86440 {
86441 - void *stack = task_stack_page(current);
86442 + const void *stack = task_stack_page(current);
86443
86444 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
86445 }
86446 diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
86447 index 596a0e0..bea77ec 100644
86448 --- a/include/linux/sched/sysctl.h
86449 +++ b/include/linux/sched/sysctl.h
86450 @@ -34,6 +34,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
86451 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
86452
86453 extern int sysctl_max_map_count;
86454 +extern unsigned long sysctl_heap_stack_gap;
86455
86456 extern unsigned int sysctl_sched_latency;
86457 extern unsigned int sysctl_sched_min_granularity;
86458 diff --git a/include/linux/seccomp.h b/include/linux/seccomp.h
86459 index 4054b09..6f19cfd 100644
86460 --- a/include/linux/seccomp.h
86461 +++ b/include/linux/seccomp.h
86462 @@ -76,6 +76,7 @@ static inline int seccomp_mode(struct seccomp *s)
86463 #ifdef CONFIG_SECCOMP_FILTER
86464 extern void put_seccomp_filter(struct task_struct *tsk);
86465 extern void get_seccomp_filter(struct task_struct *tsk);
86466 +extern u32 seccomp_bpf_load(int off);
86467 #else /* CONFIG_SECCOMP_FILTER */
86468 static inline void put_seccomp_filter(struct task_struct *tsk)
86469 {
86470 diff --git a/include/linux/security.h b/include/linux/security.h
86471 index 9c6b972..7e7c704 100644
86472 --- a/include/linux/security.h
86473 +++ b/include/linux/security.h
86474 @@ -27,6 +27,7 @@
86475 #include <linux/slab.h>
86476 #include <linux/err.h>
86477 #include <linux/string.h>
86478 +#include <linux/grsecurity.h>
86479
86480 struct linux_binprm;
86481 struct cred;
86482 @@ -116,8 +117,6 @@ struct seq_file;
86483
86484 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
86485
86486 -void reset_security_ops(void);
86487 -
86488 #ifdef CONFIG_MMU
86489 extern unsigned long mmap_min_addr;
86490 extern unsigned long dac_mmap_min_addr;
86491 @@ -1719,7 +1718,7 @@ struct security_operations {
86492 struct audit_context *actx);
86493 void (*audit_rule_free) (void *lsmrule);
86494 #endif /* CONFIG_AUDIT */
86495 -};
86496 +} __randomize_layout;
86497
86498 /* prototypes */
86499 extern int security_init(void);
86500 diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
86501 index dc368b8..e895209 100644
86502 --- a/include/linux/semaphore.h
86503 +++ b/include/linux/semaphore.h
86504 @@ -37,7 +37,7 @@ static inline void sema_init(struct semaphore *sem, int val)
86505 }
86506
86507 extern void down(struct semaphore *sem);
86508 -extern int __must_check down_interruptible(struct semaphore *sem);
86509 +extern int __must_check down_interruptible(struct semaphore *sem) __intentional_overflow(-1);
86510 extern int __must_check down_killable(struct semaphore *sem);
86511 extern int __must_check down_trylock(struct semaphore *sem);
86512 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
86513 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
86514 index 52e0097..383f21d 100644
86515 --- a/include/linux/seq_file.h
86516 +++ b/include/linux/seq_file.h
86517 @@ -27,6 +27,9 @@ struct seq_file {
86518 struct mutex lock;
86519 const struct seq_operations *op;
86520 int poll_event;
86521 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
86522 + u64 exec_id;
86523 +#endif
86524 #ifdef CONFIG_USER_NS
86525 struct user_namespace *user_ns;
86526 #endif
86527 @@ -39,6 +42,7 @@ struct seq_operations {
86528 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
86529 int (*show) (struct seq_file *m, void *v);
86530 };
86531 +typedef struct seq_operations __no_const seq_operations_no_const;
86532
86533 #define SEQ_SKIP 1
86534
86535 @@ -96,6 +100,7 @@ void seq_pad(struct seq_file *m, char c);
86536
86537 char *mangle_path(char *s, const char *p, const char *esc);
86538 int seq_open(struct file *, const struct seq_operations *);
86539 +int seq_open_restrict(struct file *, const struct seq_operations *);
86540 ssize_t seq_read(struct file *, char __user *, size_t, loff_t *);
86541 loff_t seq_lseek(struct file *, loff_t, int);
86542 int seq_release(struct inode *, struct file *);
86543 @@ -138,6 +143,7 @@ static inline int seq_nodemask_list(struct seq_file *m, nodemask_t *mask)
86544 }
86545
86546 int single_open(struct file *, int (*)(struct seq_file *, void *), void *);
86547 +int single_open_restrict(struct file *, int (*)(struct seq_file *, void *), void *);
86548 int single_open_size(struct file *, int (*)(struct seq_file *, void *), void *, size_t);
86549 int single_release(struct inode *, struct file *);
86550 void *__seq_open_private(struct file *, const struct seq_operations *, int);
86551 diff --git a/include/linux/shm.h b/include/linux/shm.h
86552 index 57d7770..0936af6 100644
86553 --- a/include/linux/shm.h
86554 +++ b/include/linux/shm.h
86555 @@ -20,6 +20,10 @@ struct shmid_kernel /* private to the kernel */
86556
86557 /* The task created the shm object. NULL if the task is dead. */
86558 struct task_struct *shm_creator;
86559 +#ifdef CONFIG_GRKERNSEC
86560 + time_t shm_createtime;
86561 + pid_t shm_lapid;
86562 +#endif
86563 };
86564
86565 /* shm_mode upper byte flags */
86566 diff --git a/include/linux/signal.h b/include/linux/signal.h
86567 index c9e6536..923b302 100644
86568 --- a/include/linux/signal.h
86569 +++ b/include/linux/signal.h
86570 @@ -293,7 +293,7 @@ static inline void allow_signal(int sig)
86571 * know it'll be handled, so that they don't get converted to
86572 * SIGKILL or just silently dropped.
86573 */
86574 - kernel_sigaction(sig, (__force __sighandler_t)2);
86575 + kernel_sigaction(sig, (__force_user __sighandler_t)2);
86576 }
86577
86578 static inline void disallow_signal(int sig)
86579 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
86580 index ec89301..4fd29a6 100644
86581 --- a/include/linux/skbuff.h
86582 +++ b/include/linux/skbuff.h
86583 @@ -725,7 +725,7 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
86584 struct sk_buff *__alloc_skb(unsigned int size, gfp_t priority, int flags,
86585 int node);
86586 struct sk_buff *build_skb(void *data, unsigned int frag_size);
86587 -static inline struct sk_buff *alloc_skb(unsigned int size,
86588 +static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
86589 gfp_t priority)
86590 {
86591 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
86592 @@ -1839,7 +1839,7 @@ static inline u32 skb_inner_network_header_len(const struct sk_buff *skb)
86593 return skb->inner_transport_header - skb->inner_network_header;
86594 }
86595
86596 -static inline int skb_network_offset(const struct sk_buff *skb)
86597 +static inline int __intentional_overflow(0) skb_network_offset(const struct sk_buff *skb)
86598 {
86599 return skb_network_header(skb) - skb->data;
86600 }
86601 @@ -1911,7 +1911,7 @@ static inline void skb_pop_rcv_encapsulation(struct sk_buff *skb)
86602 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
86603 */
86604 #ifndef NET_SKB_PAD
86605 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
86606 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
86607 #endif
86608
86609 int ___pskb_trim(struct sk_buff *skb, unsigned int len);
86610 @@ -2518,7 +2518,7 @@ struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags, int noblock,
86611 int *err);
86612 unsigned int datagram_poll(struct file *file, struct socket *sock,
86613 struct poll_table_struct *wait);
86614 -int skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
86615 +int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
86616 struct iovec *to, int size);
86617 int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb, int hlen,
86618 struct iovec *iov);
86619 @@ -2664,6 +2664,8 @@ static inline ktime_t net_invalid_timestamp(void)
86620 return ktime_set(0, 0);
86621 }
86622
86623 +void skb_timestamping_init(void);
86624 +
86625 #ifdef CONFIG_NETWORK_PHY_TIMESTAMPING
86626
86627 void skb_clone_tx_timestamp(struct sk_buff *skb);
86628 @@ -2907,6 +2909,9 @@ static inline void nf_reset(struct sk_buff *skb)
86629 nf_bridge_put(skb->nf_bridge);
86630 skb->nf_bridge = NULL;
86631 #endif
86632 +#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
86633 + skb->nf_trace = 0;
86634 +#endif
86635 }
86636
86637 static inline void nf_reset_trace(struct sk_buff *skb)
86638 diff --git a/include/linux/slab.h b/include/linux/slab.h
86639 index 1d9abb7..b1e8b10 100644
86640 --- a/include/linux/slab.h
86641 +++ b/include/linux/slab.h
86642 @@ -14,15 +14,29 @@
86643 #include <linux/gfp.h>
86644 #include <linux/types.h>
86645 #include <linux/workqueue.h>
86646 -
86647 +#include <linux/err.h>
86648
86649 /*
86650 * Flags to pass to kmem_cache_create().
86651 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
86652 */
86653 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
86654 +
86655 +#ifdef CONFIG_PAX_USERCOPY_SLABS
86656 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
86657 +#else
86658 +#define SLAB_USERCOPY 0x00000000UL
86659 +#endif
86660 +
86661 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
86662 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
86663 +
86664 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
86665 +#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
86666 +#else
86667 +#define SLAB_NO_SANITIZE 0x00000000UL
86668 +#endif
86669 +
86670 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
86671 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
86672 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
86673 @@ -98,10 +112,13 @@
86674 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
86675 * Both make kfree a no-op.
86676 */
86677 -#define ZERO_SIZE_PTR ((void *)16)
86678 +#define ZERO_SIZE_PTR \
86679 +({ \
86680 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
86681 + (void *)(-MAX_ERRNO-1L); \
86682 +})
86683
86684 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
86685 - (unsigned long)ZERO_SIZE_PTR)
86686 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
86687
86688 #include <linux/kmemleak.h>
86689
86690 @@ -144,6 +161,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
86691 void kfree(const void *);
86692 void kzfree(const void *);
86693 size_t ksize(const void *);
86694 +const char *check_heap_object(const void *ptr, unsigned long n);
86695 +bool is_usercopy_object(const void *ptr);
86696
86697 /*
86698 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
86699 @@ -176,7 +195,7 @@ struct kmem_cache {
86700 unsigned int align; /* Alignment as calculated */
86701 unsigned long flags; /* Active flags on the slab */
86702 const char *name; /* Slab name for sysfs */
86703 - int refcount; /* Use counter */
86704 + atomic_t refcount; /* Use counter */
86705 void (*ctor)(void *); /* Called on object slot creation */
86706 struct list_head list; /* List of all slab caches on the system */
86707 };
86708 @@ -261,6 +280,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
86709 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
86710 #endif
86711
86712 +#ifdef CONFIG_PAX_USERCOPY_SLABS
86713 +extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
86714 +#endif
86715 +
86716 /*
86717 * Figure out which kmalloc slab an allocation of a certain size
86718 * belongs to.
86719 @@ -269,7 +292,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
86720 * 2 = 120 .. 192 bytes
86721 * n = 2^(n-1) .. 2^n -1
86722 */
86723 -static __always_inline int kmalloc_index(size_t size)
86724 +static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
86725 {
86726 if (!size)
86727 return 0;
86728 @@ -312,11 +335,11 @@ static __always_inline int kmalloc_index(size_t size)
86729 }
86730 #endif /* !CONFIG_SLOB */
86731
86732 -void *__kmalloc(size_t size, gfp_t flags);
86733 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
86734 void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags);
86735
86736 #ifdef CONFIG_NUMA
86737 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
86738 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __alloc_size(1);
86739 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
86740 #else
86741 static __always_inline void *__kmalloc_node(size_t size, gfp_t flags, int node)
86742 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
86743 index 8235dfb..47ce586 100644
86744 --- a/include/linux/slab_def.h
86745 +++ b/include/linux/slab_def.h
86746 @@ -38,7 +38,7 @@ struct kmem_cache {
86747 /* 4) cache creation/removal */
86748 const char *name;
86749 struct list_head list;
86750 - int refcount;
86751 + atomic_t refcount;
86752 int object_size;
86753 int align;
86754
86755 @@ -54,10 +54,14 @@ struct kmem_cache {
86756 unsigned long node_allocs;
86757 unsigned long node_frees;
86758 unsigned long node_overflow;
86759 - atomic_t allochit;
86760 - atomic_t allocmiss;
86761 - atomic_t freehit;
86762 - atomic_t freemiss;
86763 + atomic_unchecked_t allochit;
86764 + atomic_unchecked_t allocmiss;
86765 + atomic_unchecked_t freehit;
86766 + atomic_unchecked_t freemiss;
86767 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
86768 + atomic_unchecked_t sanitized;
86769 + atomic_unchecked_t not_sanitized;
86770 +#endif
86771
86772 /*
86773 * If debugging is enabled, then the allocator can add additional
86774 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
86775 index d82abd4..408c3a0 100644
86776 --- a/include/linux/slub_def.h
86777 +++ b/include/linux/slub_def.h
86778 @@ -74,7 +74,7 @@ struct kmem_cache {
86779 struct kmem_cache_order_objects max;
86780 struct kmem_cache_order_objects min;
86781 gfp_t allocflags; /* gfp flags to use on each alloc */
86782 - int refcount; /* Refcount for slab cache destroy */
86783 + atomic_t refcount; /* Refcount for slab cache destroy */
86784 void (*ctor)(void *);
86785 int inuse; /* Offset to metadata */
86786 int align; /* Alignment */
86787 diff --git a/include/linux/smp.h b/include/linux/smp.h
86788 index 34347f2..8739978 100644
86789 --- a/include/linux/smp.h
86790 +++ b/include/linux/smp.h
86791 @@ -174,7 +174,9 @@ static inline void kick_all_cpus_sync(void) { }
86792 #endif
86793
86794 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
86795 +#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
86796 #define put_cpu() preempt_enable()
86797 +#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
86798
86799 /*
86800 * Callback to arch code if there's nosmp or maxcpus=0 on the
86801 diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
86802 index 46cca4c..3323536 100644
86803 --- a/include/linux/sock_diag.h
86804 +++ b/include/linux/sock_diag.h
86805 @@ -11,7 +11,7 @@ struct sock;
86806 struct sock_diag_handler {
86807 __u8 family;
86808 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
86809 -};
86810 +} __do_const;
86811
86812 int sock_diag_register(const struct sock_diag_handler *h);
86813 void sock_diag_unregister(const struct sock_diag_handler *h);
86814 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
86815 index 680f9a3..f13aeb0 100644
86816 --- a/include/linux/sonet.h
86817 +++ b/include/linux/sonet.h
86818 @@ -7,7 +7,7 @@
86819 #include <uapi/linux/sonet.h>
86820
86821 struct k_sonet_stats {
86822 -#define __HANDLE_ITEM(i) atomic_t i
86823 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
86824 __SONET_ITEMS
86825 #undef __HANDLE_ITEM
86826 };
86827 diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
86828 index 07d8e53..dc934c9 100644
86829 --- a/include/linux/sunrpc/addr.h
86830 +++ b/include/linux/sunrpc/addr.h
86831 @@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
86832 {
86833 switch (sap->sa_family) {
86834 case AF_INET:
86835 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
86836 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
86837 case AF_INET6:
86838 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
86839 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
86840 }
86841 return 0;
86842 }
86843 @@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
86844 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
86845 const struct sockaddr *src)
86846 {
86847 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
86848 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
86849 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
86850
86851 dsin->sin_family = ssin->sin_family;
86852 @@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
86853 if (sa->sa_family != AF_INET6)
86854 return 0;
86855
86856 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
86857 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
86858 }
86859
86860 #endif /* _LINUX_SUNRPC_ADDR_H */
86861 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
86862 index 70736b9..37f33db 100644
86863 --- a/include/linux/sunrpc/clnt.h
86864 +++ b/include/linux/sunrpc/clnt.h
86865 @@ -97,7 +97,7 @@ struct rpc_procinfo {
86866 unsigned int p_timer; /* Which RTT timer to use */
86867 u32 p_statidx; /* Which procedure to account */
86868 const char * p_name; /* name of procedure */
86869 -};
86870 +} __do_const;
86871
86872 #ifdef __KERNEL__
86873
86874 diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
86875 index 1bc7cd0..7912dc2 100644
86876 --- a/include/linux/sunrpc/svc.h
86877 +++ b/include/linux/sunrpc/svc.h
86878 @@ -417,7 +417,7 @@ struct svc_procedure {
86879 unsigned int pc_count; /* call count */
86880 unsigned int pc_cachetype; /* cache info (NFS) */
86881 unsigned int pc_xdrressize; /* maximum size of XDR reply */
86882 -};
86883 +} __do_const;
86884
86885 /*
86886 * Function prototypes.
86887 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
86888 index 5cf99a0..c0a1b98 100644
86889 --- a/include/linux/sunrpc/svc_rdma.h
86890 +++ b/include/linux/sunrpc/svc_rdma.h
86891 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
86892 extern unsigned int svcrdma_max_requests;
86893 extern unsigned int svcrdma_max_req_size;
86894
86895 -extern atomic_t rdma_stat_recv;
86896 -extern atomic_t rdma_stat_read;
86897 -extern atomic_t rdma_stat_write;
86898 -extern atomic_t rdma_stat_sq_starve;
86899 -extern atomic_t rdma_stat_rq_starve;
86900 -extern atomic_t rdma_stat_rq_poll;
86901 -extern atomic_t rdma_stat_rq_prod;
86902 -extern atomic_t rdma_stat_sq_poll;
86903 -extern atomic_t rdma_stat_sq_prod;
86904 +extern atomic_unchecked_t rdma_stat_recv;
86905 +extern atomic_unchecked_t rdma_stat_read;
86906 +extern atomic_unchecked_t rdma_stat_write;
86907 +extern atomic_unchecked_t rdma_stat_sq_starve;
86908 +extern atomic_unchecked_t rdma_stat_rq_starve;
86909 +extern atomic_unchecked_t rdma_stat_rq_poll;
86910 +extern atomic_unchecked_t rdma_stat_rq_prod;
86911 +extern atomic_unchecked_t rdma_stat_sq_poll;
86912 +extern atomic_unchecked_t rdma_stat_sq_prod;
86913
86914 #define RPCRDMA_VERSION 1
86915
86916 diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
86917 index 8d71d65..f79586e 100644
86918 --- a/include/linux/sunrpc/svcauth.h
86919 +++ b/include/linux/sunrpc/svcauth.h
86920 @@ -120,7 +120,7 @@ struct auth_ops {
86921 int (*release)(struct svc_rqst *rq);
86922 void (*domain_release)(struct auth_domain *);
86923 int (*set_client)(struct svc_rqst *rq);
86924 -};
86925 +} __do_const;
86926
86927 #define SVC_GARBAGE 1
86928 #define SVC_SYSERR 2
86929 diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
86930 index e7a018e..49f8b17 100644
86931 --- a/include/linux/swiotlb.h
86932 +++ b/include/linux/swiotlb.h
86933 @@ -60,7 +60,8 @@ extern void
86934
86935 extern void
86936 swiotlb_free_coherent(struct device *hwdev, size_t size,
86937 - void *vaddr, dma_addr_t dma_handle);
86938 + void *vaddr, dma_addr_t dma_handle,
86939 + struct dma_attrs *attrs);
86940
86941 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
86942 unsigned long offset, size_t size,
86943 diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
86944 index b0881a0..559a440 100644
86945 --- a/include/linux/syscalls.h
86946 +++ b/include/linux/syscalls.h
86947 @@ -98,10 +98,16 @@ struct sigaltstack;
86948 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
86949
86950 #define __SC_DECL(t, a) t a
86951 +#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))
86952 #define __TYPE_IS_L(t) (__same_type((t)0, 0L))
86953 #define __TYPE_IS_UL(t) (__same_type((t)0, 0UL))
86954 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
86955 -#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
86956 +#define __SC_LONG(t, a) __typeof( \
86957 + __builtin_choose_expr( \
86958 + sizeof(t) > sizeof(int), \
86959 + (t) 0, \
86960 + __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
86961 + )) a
86962 #define __SC_CAST(t, a) (t) a
86963 #define __SC_ARGS(t, a) a
86964 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
86965 @@ -379,11 +385,11 @@ asmlinkage long sys_sync(void);
86966 asmlinkage long sys_fsync(unsigned int fd);
86967 asmlinkage long sys_fdatasync(unsigned int fd);
86968 asmlinkage long sys_bdflush(int func, long data);
86969 -asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
86970 - char __user *type, unsigned long flags,
86971 +asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
86972 + const char __user *type, unsigned long flags,
86973 void __user *data);
86974 -asmlinkage long sys_umount(char __user *name, int flags);
86975 -asmlinkage long sys_oldumount(char __user *name);
86976 +asmlinkage long sys_umount(const char __user *name, int flags);
86977 +asmlinkage long sys_oldumount(const char __user *name);
86978 asmlinkage long sys_truncate(const char __user *path, long length);
86979 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
86980 asmlinkage long sys_stat(const char __user *filename,
86981 @@ -595,7 +601,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
86982 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
86983 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
86984 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
86985 - struct sockaddr __user *, int);
86986 + struct sockaddr __user *, int) __intentional_overflow(0);
86987 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
86988 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
86989 unsigned int vlen, unsigned flags);
86990 diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
86991 index 27b3b0b..e093dd9 100644
86992 --- a/include/linux/syscore_ops.h
86993 +++ b/include/linux/syscore_ops.h
86994 @@ -16,7 +16,7 @@ struct syscore_ops {
86995 int (*suspend)(void);
86996 void (*resume)(void);
86997 void (*shutdown)(void);
86998 -};
86999 +} __do_const;
87000
87001 extern void register_syscore_ops(struct syscore_ops *ops);
87002 extern void unregister_syscore_ops(struct syscore_ops *ops);
87003 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
87004 index 14a8ff2..fa95f3a 100644
87005 --- a/include/linux/sysctl.h
87006 +++ b/include/linux/sysctl.h
87007 @@ -34,13 +34,13 @@ struct ctl_table_root;
87008 struct ctl_table_header;
87009 struct ctl_dir;
87010
87011 -typedef struct ctl_table ctl_table;
87012 -
87013 typedef int proc_handler (struct ctl_table *ctl, int write,
87014 void __user *buffer, size_t *lenp, loff_t *ppos);
87015
87016 extern int proc_dostring(struct ctl_table *, int,
87017 void __user *, size_t *, loff_t *);
87018 +extern int proc_dostring_modpriv(struct ctl_table *, int,
87019 + void __user *, size_t *, loff_t *);
87020 extern int proc_dointvec(struct ctl_table *, int,
87021 void __user *, size_t *, loff_t *);
87022 extern int proc_dointvec_minmax(struct ctl_table *, int,
87023 @@ -115,7 +115,9 @@ struct ctl_table
87024 struct ctl_table_poll *poll;
87025 void *extra1;
87026 void *extra2;
87027 -};
87028 +} __do_const __randomize_layout;
87029 +typedef struct ctl_table __no_const ctl_table_no_const;
87030 +typedef struct ctl_table ctl_table;
87031
87032 struct ctl_node {
87033 struct rb_node node;
87034 diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
87035 index f97d0db..c1187dc 100644
87036 --- a/include/linux/sysfs.h
87037 +++ b/include/linux/sysfs.h
87038 @@ -34,7 +34,8 @@ struct attribute {
87039 struct lock_class_key *key;
87040 struct lock_class_key skey;
87041 #endif
87042 -};
87043 +} __do_const;
87044 +typedef struct attribute __no_const attribute_no_const;
87045
87046 /**
87047 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
87048 @@ -63,7 +64,8 @@ struct attribute_group {
87049 struct attribute *, int);
87050 struct attribute **attrs;
87051 struct bin_attribute **bin_attrs;
87052 -};
87053 +} __do_const;
87054 +typedef struct attribute_group __no_const attribute_group_no_const;
87055
87056 /**
87057 * Use these macros to make defining attributes easier. See include/linux/device.h
87058 @@ -128,7 +130,8 @@ struct bin_attribute {
87059 char *, loff_t, size_t);
87060 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
87061 struct vm_area_struct *vma);
87062 -};
87063 +} __do_const;
87064 +typedef struct bin_attribute __no_const bin_attribute_no_const;
87065
87066 /**
87067 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
87068 diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
87069 index 387fa7d..3fcde6b 100644
87070 --- a/include/linux/sysrq.h
87071 +++ b/include/linux/sysrq.h
87072 @@ -16,6 +16,7 @@
87073
87074 #include <linux/errno.h>
87075 #include <linux/types.h>
87076 +#include <linux/compiler.h>
87077
87078 /* Possible values of bitmask for enabling sysrq functions */
87079 /* 0x0001 is reserved for enable everything */
87080 @@ -33,7 +34,7 @@ struct sysrq_key_op {
87081 char *help_msg;
87082 char *action_msg;
87083 int enable_mask;
87084 -};
87085 +} __do_const;
87086
87087 #ifdef CONFIG_MAGIC_SYSRQ
87088
87089 diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
87090 index ff307b5..f1a4468 100644
87091 --- a/include/linux/thread_info.h
87092 +++ b/include/linux/thread_info.h
87093 @@ -145,6 +145,13 @@ static inline bool test_and_clear_restore_sigmask(void)
87094 #error "no set_restore_sigmask() provided and default one won't work"
87095 #endif
87096
87097 +extern void __check_object_size(const void *ptr, unsigned long n, bool to_user, bool const_size);
87098 +
87099 +static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
87100 +{
87101 + __check_object_size(ptr, n, to_user, __builtin_constant_p(n));
87102 +}
87103 +
87104 #endif /* __KERNEL__ */
87105
87106 #endif /* _LINUX_THREAD_INFO_H */
87107 diff --git a/include/linux/tty.h b/include/linux/tty.h
87108 index 1c3316a..ae83b9f 100644
87109 --- a/include/linux/tty.h
87110 +++ b/include/linux/tty.h
87111 @@ -202,7 +202,7 @@ struct tty_port {
87112 const struct tty_port_operations *ops; /* Port operations */
87113 spinlock_t lock; /* Lock protecting tty field */
87114 int blocked_open; /* Waiting to open */
87115 - int count; /* Usage count */
87116 + atomic_t count; /* Usage count */
87117 wait_queue_head_t open_wait; /* Open waiters */
87118 wait_queue_head_t close_wait; /* Close waiters */
87119 wait_queue_head_t delta_msr_wait; /* Modem status change */
87120 @@ -284,7 +284,7 @@ struct tty_struct {
87121 /* If the tty has a pending do_SAK, queue it here - akpm */
87122 struct work_struct SAK_work;
87123 struct tty_port *port;
87124 -};
87125 +} __randomize_layout;
87126
87127 /* Each of a tty's open files has private_data pointing to tty_file_private */
87128 struct tty_file_private {
87129 @@ -550,7 +550,7 @@ extern int tty_port_open(struct tty_port *port,
87130 struct tty_struct *tty, struct file *filp);
87131 static inline int tty_port_users(struct tty_port *port)
87132 {
87133 - return port->count + port->blocked_open;
87134 + return atomic_read(&port->count) + port->blocked_open;
87135 }
87136
87137 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
87138 diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
87139 index 756a609..89db85e 100644
87140 --- a/include/linux/tty_driver.h
87141 +++ b/include/linux/tty_driver.h
87142 @@ -285,7 +285,7 @@ struct tty_operations {
87143 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
87144 #endif
87145 const struct file_operations *proc_fops;
87146 -};
87147 +} __do_const __randomize_layout;
87148
87149 struct tty_driver {
87150 int magic; /* magic number for this structure */
87151 @@ -319,7 +319,7 @@ struct tty_driver {
87152
87153 const struct tty_operations *ops;
87154 struct list_head tty_drivers;
87155 -};
87156 +} __randomize_layout;
87157
87158 extern struct list_head tty_drivers;
87159
87160 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
87161 index 00c9d68..bc0188b 100644
87162 --- a/include/linux/tty_ldisc.h
87163 +++ b/include/linux/tty_ldisc.h
87164 @@ -215,7 +215,7 @@ struct tty_ldisc_ops {
87165
87166 struct module *owner;
87167
87168 - int refcount;
87169 + atomic_t refcount;
87170 };
87171
87172 struct tty_ldisc {
87173 diff --git a/include/linux/types.h b/include/linux/types.h
87174 index a0bb704..f511c77 100644
87175 --- a/include/linux/types.h
87176 +++ b/include/linux/types.h
87177 @@ -177,10 +177,26 @@ typedef struct {
87178 int counter;
87179 } atomic_t;
87180
87181 +#ifdef CONFIG_PAX_REFCOUNT
87182 +typedef struct {
87183 + int counter;
87184 +} atomic_unchecked_t;
87185 +#else
87186 +typedef atomic_t atomic_unchecked_t;
87187 +#endif
87188 +
87189 #ifdef CONFIG_64BIT
87190 typedef struct {
87191 long counter;
87192 } atomic64_t;
87193 +
87194 +#ifdef CONFIG_PAX_REFCOUNT
87195 +typedef struct {
87196 + long counter;
87197 +} atomic64_unchecked_t;
87198 +#else
87199 +typedef atomic64_t atomic64_unchecked_t;
87200 +#endif
87201 #endif
87202
87203 struct list_head {
87204 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
87205 index ecd3319..8a36ded 100644
87206 --- a/include/linux/uaccess.h
87207 +++ b/include/linux/uaccess.h
87208 @@ -75,11 +75,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
87209 long ret; \
87210 mm_segment_t old_fs = get_fs(); \
87211 \
87212 - set_fs(KERNEL_DS); \
87213 pagefault_disable(); \
87214 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
87215 - pagefault_enable(); \
87216 + set_fs(KERNEL_DS); \
87217 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
87218 set_fs(old_fs); \
87219 + pagefault_enable(); \
87220 ret; \
87221 })
87222
87223 diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
87224 index 2d1f9b6..d7a9fce 100644
87225 --- a/include/linux/uidgid.h
87226 +++ b/include/linux/uidgid.h
87227 @@ -175,4 +175,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
87228
87229 #endif /* CONFIG_USER_NS */
87230
87231 +#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
87232 +#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
87233 +#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
87234 +#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
87235 +
87236 #endif /* _LINUX_UIDGID_H */
87237 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
87238 index 99c1b4d..562e6f3 100644
87239 --- a/include/linux/unaligned/access_ok.h
87240 +++ b/include/linux/unaligned/access_ok.h
87241 @@ -4,34 +4,34 @@
87242 #include <linux/kernel.h>
87243 #include <asm/byteorder.h>
87244
87245 -static inline u16 get_unaligned_le16(const void *p)
87246 +static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
87247 {
87248 - return le16_to_cpup((__le16 *)p);
87249 + return le16_to_cpup((const __le16 *)p);
87250 }
87251
87252 -static inline u32 get_unaligned_le32(const void *p)
87253 +static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
87254 {
87255 - return le32_to_cpup((__le32 *)p);
87256 + return le32_to_cpup((const __le32 *)p);
87257 }
87258
87259 -static inline u64 get_unaligned_le64(const void *p)
87260 +static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
87261 {
87262 - return le64_to_cpup((__le64 *)p);
87263 + return le64_to_cpup((const __le64 *)p);
87264 }
87265
87266 -static inline u16 get_unaligned_be16(const void *p)
87267 +static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
87268 {
87269 - return be16_to_cpup((__be16 *)p);
87270 + return be16_to_cpup((const __be16 *)p);
87271 }
87272
87273 -static inline u32 get_unaligned_be32(const void *p)
87274 +static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
87275 {
87276 - return be32_to_cpup((__be32 *)p);
87277 + return be32_to_cpup((const __be32 *)p);
87278 }
87279
87280 -static inline u64 get_unaligned_be64(const void *p)
87281 +static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
87282 {
87283 - return be64_to_cpup((__be64 *)p);
87284 + return be64_to_cpup((const __be64 *)p);
87285 }
87286
87287 static inline void put_unaligned_le16(u16 val, void *p)
87288 diff --git a/include/linux/usb.h b/include/linux/usb.h
87289 index d2465bc..5256de4 100644
87290 --- a/include/linux/usb.h
87291 +++ b/include/linux/usb.h
87292 @@ -571,7 +571,7 @@ struct usb_device {
87293 int maxchild;
87294
87295 u32 quirks;
87296 - atomic_t urbnum;
87297 + atomic_unchecked_t urbnum;
87298
87299 unsigned long active_duration;
87300
87301 @@ -1655,7 +1655,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
87302
87303 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
87304 __u8 request, __u8 requesttype, __u16 value, __u16 index,
87305 - void *data, __u16 size, int timeout);
87306 + void *data, __u16 size, int timeout) __intentional_overflow(-1);
87307 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
87308 void *data, int len, int *actual_length, int timeout);
87309 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
87310 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
87311 index e452ba6..78f8e80 100644
87312 --- a/include/linux/usb/renesas_usbhs.h
87313 +++ b/include/linux/usb/renesas_usbhs.h
87314 @@ -39,7 +39,7 @@ enum {
87315 */
87316 struct renesas_usbhs_driver_callback {
87317 int (*notify_hotplug)(struct platform_device *pdev);
87318 -};
87319 +} __no_const;
87320
87321 /*
87322 * callback functions for platform
87323 diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
87324 index 4836ba3..603f6ee 100644
87325 --- a/include/linux/user_namespace.h
87326 +++ b/include/linux/user_namespace.h
87327 @@ -33,7 +33,7 @@ struct user_namespace {
87328 struct key *persistent_keyring_register;
87329 struct rw_semaphore persistent_keyring_register_sem;
87330 #endif
87331 -};
87332 +} __randomize_layout;
87333
87334 extern struct user_namespace init_user_ns;
87335
87336 diff --git a/include/linux/utsname.h b/include/linux/utsname.h
87337 index 239e277..22a5cf5 100644
87338 --- a/include/linux/utsname.h
87339 +++ b/include/linux/utsname.h
87340 @@ -24,7 +24,7 @@ struct uts_namespace {
87341 struct new_utsname name;
87342 struct user_namespace *user_ns;
87343 unsigned int proc_inum;
87344 -};
87345 +} __randomize_layout;
87346 extern struct uts_namespace init_uts_ns;
87347
87348 #ifdef CONFIG_UTS_NS
87349 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
87350 index 6f8fbcf..4efc177 100644
87351 --- a/include/linux/vermagic.h
87352 +++ b/include/linux/vermagic.h
87353 @@ -25,9 +25,42 @@
87354 #define MODULE_ARCH_VERMAGIC ""
87355 #endif
87356
87357 +#ifdef CONFIG_PAX_REFCOUNT
87358 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
87359 +#else
87360 +#define MODULE_PAX_REFCOUNT ""
87361 +#endif
87362 +
87363 +#ifdef CONSTIFY_PLUGIN
87364 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
87365 +#else
87366 +#define MODULE_CONSTIFY_PLUGIN ""
87367 +#endif
87368 +
87369 +#ifdef STACKLEAK_PLUGIN
87370 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
87371 +#else
87372 +#define MODULE_STACKLEAK_PLUGIN ""
87373 +#endif
87374 +
87375 +#ifdef RANDSTRUCT_PLUGIN
87376 +#include <generated/randomize_layout_hash.h>
87377 +#define MODULE_RANDSTRUCT_PLUGIN "RANDSTRUCT_PLUGIN_" RANDSTRUCT_HASHED_SEED
87378 +#else
87379 +#define MODULE_RANDSTRUCT_PLUGIN
87380 +#endif
87381 +
87382 +#ifdef CONFIG_GRKERNSEC
87383 +#define MODULE_GRSEC "GRSEC "
87384 +#else
87385 +#define MODULE_GRSEC ""
87386 +#endif
87387 +
87388 #define VERMAGIC_STRING \
87389 UTS_RELEASE " " \
87390 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
87391 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
87392 - MODULE_ARCH_VERMAGIC
87393 + MODULE_ARCH_VERMAGIC \
87394 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
87395 + MODULE_GRSEC MODULE_RANDSTRUCT_PLUGIN
87396
87397 diff --git a/include/linux/vga_switcheroo.h b/include/linux/vga_switcheroo.h
87398 index 502073a..a7de024 100644
87399 --- a/include/linux/vga_switcheroo.h
87400 +++ b/include/linux/vga_switcheroo.h
87401 @@ -63,8 +63,8 @@ int vga_switcheroo_get_client_state(struct pci_dev *dev);
87402
87403 void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic);
87404
87405 -int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain);
87406 -int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain);
87407 +int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain);
87408 +int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain);
87409 #else
87410
87411 static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {}
87412 @@ -81,8 +81,8 @@ static inline int vga_switcheroo_get_client_state(struct pci_dev *dev) { return
87413
87414 static inline void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic) {}
87415
87416 -static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
87417 -static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
87418 +static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
87419 +static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
87420
87421 #endif
87422 #endif /* _LINUX_VGA_SWITCHEROO_H_ */
87423 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
87424 index 4b8a891..e9a2863 100644
87425 --- a/include/linux/vmalloc.h
87426 +++ b/include/linux/vmalloc.h
87427 @@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
87428 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
87429 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
87430 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
87431 +
87432 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
87433 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
87434 +#endif
87435 +
87436 /* bits [20..32] reserved for arch specific ioremap internals */
87437
87438 /*
87439 @@ -82,6 +87,10 @@ extern void *vmap(struct page **pages, unsigned int count,
87440 unsigned long flags, pgprot_t prot);
87441 extern void vunmap(const void *addr);
87442
87443 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
87444 +extern void unmap_process_stacks(struct task_struct *task);
87445 +#endif
87446 +
87447 extern int remap_vmalloc_range_partial(struct vm_area_struct *vma,
87448 unsigned long uaddr, void *kaddr,
87449 unsigned long size);
87450 @@ -142,7 +151,7 @@ extern void free_vm_area(struct vm_struct *area);
87451
87452 /* for /dev/kmem */
87453 extern long vread(char *buf, char *addr, unsigned long count);
87454 -extern long vwrite(char *buf, char *addr, unsigned long count);
87455 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
87456
87457 /*
87458 * Internals. Dont't use..
87459 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
87460 index 82e7db7..f8ce3d0 100644
87461 --- a/include/linux/vmstat.h
87462 +++ b/include/linux/vmstat.h
87463 @@ -108,18 +108,18 @@ static inline void vm_events_fold_cpu(int cpu)
87464 /*
87465 * Zone based page accounting with per cpu differentials.
87466 */
87467 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
87468 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
87469
87470 static inline void zone_page_state_add(long x, struct zone *zone,
87471 enum zone_stat_item item)
87472 {
87473 - atomic_long_add(x, &zone->vm_stat[item]);
87474 - atomic_long_add(x, &vm_stat[item]);
87475 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
87476 + atomic_long_add_unchecked(x, &vm_stat[item]);
87477 }
87478
87479 -static inline unsigned long global_page_state(enum zone_stat_item item)
87480 +static inline unsigned long __intentional_overflow(-1) global_page_state(enum zone_stat_item item)
87481 {
87482 - long x = atomic_long_read(&vm_stat[item]);
87483 + long x = atomic_long_read_unchecked(&vm_stat[item]);
87484 #ifdef CONFIG_SMP
87485 if (x < 0)
87486 x = 0;
87487 @@ -127,10 +127,10 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
87488 return x;
87489 }
87490
87491 -static inline unsigned long zone_page_state(struct zone *zone,
87492 +static inline unsigned long __intentional_overflow(-1) zone_page_state(struct zone *zone,
87493 enum zone_stat_item item)
87494 {
87495 - long x = atomic_long_read(&zone->vm_stat[item]);
87496 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
87497 #ifdef CONFIG_SMP
87498 if (x < 0)
87499 x = 0;
87500 @@ -147,7 +147,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
87501 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
87502 enum zone_stat_item item)
87503 {
87504 - long x = atomic_long_read(&zone->vm_stat[item]);
87505 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
87506
87507 #ifdef CONFIG_SMP
87508 int cpu;
87509 @@ -234,14 +234,14 @@ static inline void __mod_zone_page_state(struct zone *zone,
87510
87511 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
87512 {
87513 - atomic_long_inc(&zone->vm_stat[item]);
87514 - atomic_long_inc(&vm_stat[item]);
87515 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
87516 + atomic_long_inc_unchecked(&vm_stat[item]);
87517 }
87518
87519 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
87520 {
87521 - atomic_long_dec(&zone->vm_stat[item]);
87522 - atomic_long_dec(&vm_stat[item]);
87523 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
87524 + atomic_long_dec_unchecked(&vm_stat[item]);
87525 }
87526
87527 static inline void __inc_zone_page_state(struct page *page,
87528 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
87529 index 91b0a68..0e9adf6 100644
87530 --- a/include/linux/xattr.h
87531 +++ b/include/linux/xattr.h
87532 @@ -28,7 +28,7 @@ struct xattr_handler {
87533 size_t size, int handler_flags);
87534 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
87535 size_t size, int flags, int handler_flags);
87536 -};
87537 +} __do_const;
87538
87539 struct xattr {
87540 const char *name;
87541 @@ -37,6 +37,9 @@ struct xattr {
87542 };
87543
87544 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
87545 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
87546 +ssize_t pax_getxattr(struct dentry *, void *, size_t);
87547 +#endif
87548 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
87549 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
87550 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
87551 diff --git a/include/linux/zlib.h b/include/linux/zlib.h
87552 index 9c5a6b4..09c9438 100644
87553 --- a/include/linux/zlib.h
87554 +++ b/include/linux/zlib.h
87555 @@ -31,6 +31,7 @@
87556 #define _ZLIB_H
87557
87558 #include <linux/zconf.h>
87559 +#include <linux/compiler.h>
87560
87561 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
87562 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
87563 @@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
87564
87565 /* basic functions */
87566
87567 -extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
87568 +extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
87569 /*
87570 Returns the number of bytes that needs to be allocated for a per-
87571 stream workspace with the specified parameters. A pointer to this
87572 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
87573 index eec6e46..82d5641 100644
87574 --- a/include/media/v4l2-dev.h
87575 +++ b/include/media/v4l2-dev.h
87576 @@ -77,7 +77,7 @@ struct v4l2_file_operations {
87577 int (*mmap) (struct file *, struct vm_area_struct *);
87578 int (*open) (struct file *);
87579 int (*release) (struct file *);
87580 -};
87581 +} __do_const;
87582
87583 /*
87584 * Newer version of video_device, handled by videodev2.c
87585 diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
87586 index ffb69da..040393e 100644
87587 --- a/include/media/v4l2-device.h
87588 +++ b/include/media/v4l2-device.h
87589 @@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
87590 this function returns 0. If the name ends with a digit (e.g. cx18),
87591 then the name will be set to cx18-0 since cx180 looks really odd. */
87592 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
87593 - atomic_t *instance);
87594 + atomic_unchecked_t *instance);
87595
87596 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
87597 Since the parent disappears this ensures that v4l2_dev doesn't have an
87598 diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
87599 index d9fa68f..45c88d1 100644
87600 --- a/include/net/9p/transport.h
87601 +++ b/include/net/9p/transport.h
87602 @@ -63,7 +63,7 @@ struct p9_trans_module {
87603 int (*cancelled)(struct p9_client *, struct p9_req_t *req);
87604 int (*zc_request)(struct p9_client *, struct p9_req_t *,
87605 char *, char *, int , int, int, int);
87606 -};
87607 +} __do_const;
87608
87609 void v9fs_register_trans(struct p9_trans_module *m);
87610 void v9fs_unregister_trans(struct p9_trans_module *m);
87611 diff --git a/include/net/af_unix.h b/include/net/af_unix.h
87612 index a175ba4..196eb82 100644
87613 --- a/include/net/af_unix.h
87614 +++ b/include/net/af_unix.h
87615 @@ -36,7 +36,7 @@ struct unix_skb_parms {
87616 u32 secid; /* Security ID */
87617 #endif
87618 u32 consumed;
87619 -};
87620 +} __randomize_layout;
87621
87622 #define UNIXCB(skb) (*(struct unix_skb_parms *)&((skb)->cb))
87623 #define UNIXSID(skb) (&UNIXCB((skb)).secid)
87624 diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
87625 index 4abdcb2..945c5cc 100644
87626 --- a/include/net/bluetooth/l2cap.h
87627 +++ b/include/net/bluetooth/l2cap.h
87628 @@ -601,7 +601,7 @@ struct l2cap_ops {
87629 long (*get_sndtimeo) (struct l2cap_chan *chan);
87630 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
87631 unsigned long len, int nb);
87632 -};
87633 +} __do_const;
87634
87635 struct l2cap_conn {
87636 struct hci_conn *hcon;
87637 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
87638 index f2ae33d..c457cf0 100644
87639 --- a/include/net/caif/cfctrl.h
87640 +++ b/include/net/caif/cfctrl.h
87641 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
87642 void (*radioset_rsp)(void);
87643 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
87644 struct cflayer *client_layer);
87645 -};
87646 +} __no_const;
87647
87648 /* Link Setup Parameters for CAIF-Links. */
87649 struct cfctrl_link_param {
87650 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
87651 struct cfctrl {
87652 struct cfsrvl serv;
87653 struct cfctrl_rsp res;
87654 - atomic_t req_seq_no;
87655 - atomic_t rsp_seq_no;
87656 + atomic_unchecked_t req_seq_no;
87657 + atomic_unchecked_t rsp_seq_no;
87658 struct list_head list;
87659 /* Protects from simultaneous access to first_req list */
87660 spinlock_t info_list_lock;
87661 diff --git a/include/net/flow.h b/include/net/flow.h
87662 index 8109a15..504466d 100644
87663 --- a/include/net/flow.h
87664 +++ b/include/net/flow.h
87665 @@ -231,6 +231,6 @@ void flow_cache_fini(struct net *net);
87666
87667 void flow_cache_flush(struct net *net);
87668 void flow_cache_flush_deferred(struct net *net);
87669 -extern atomic_t flow_cache_genid;
87670 +extern atomic_unchecked_t flow_cache_genid;
87671
87672 #endif
87673 diff --git a/include/net/genetlink.h b/include/net/genetlink.h
87674 index 93695f0..766d71c 100644
87675 --- a/include/net/genetlink.h
87676 +++ b/include/net/genetlink.h
87677 @@ -120,7 +120,7 @@ struct genl_ops {
87678 u8 cmd;
87679 u8 internal_flags;
87680 u8 flags;
87681 -};
87682 +} __do_const;
87683
87684 int __genl_register_family(struct genl_family *family);
87685
87686 diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
87687 index 734d9b5..48a9a4b 100644
87688 --- a/include/net/gro_cells.h
87689 +++ b/include/net/gro_cells.h
87690 @@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
87691 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
87692
87693 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
87694 - atomic_long_inc(&dev->rx_dropped);
87695 + atomic_long_inc_unchecked(&dev->rx_dropped);
87696 kfree_skb(skb);
87697 return;
87698 }
87699 diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
87700 index 7a43138..bc76865 100644
87701 --- a/include/net/inet_connection_sock.h
87702 +++ b/include/net/inet_connection_sock.h
87703 @@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
87704 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
87705 int (*bind_conflict)(const struct sock *sk,
87706 const struct inet_bind_bucket *tb, bool relax);
87707 -};
87708 +} __do_const;
87709
87710 /** inet_connection_sock - INET connection oriented sock
87711 *
87712 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
87713 index 01d590e..f69c61d 100644
87714 --- a/include/net/inetpeer.h
87715 +++ b/include/net/inetpeer.h
87716 @@ -47,7 +47,7 @@ struct inet_peer {
87717 */
87718 union {
87719 struct {
87720 - atomic_t rid; /* Frag reception counter */
87721 + atomic_unchecked_t rid; /* Frag reception counter */
87722 };
87723 struct rcu_head rcu;
87724 struct inet_peer *gc_next;
87725 diff --git a/include/net/ip.h b/include/net/ip.h
87726 index 7596eb2..f7f5fad 100644
87727 --- a/include/net/ip.h
87728 +++ b/include/net/ip.h
87729 @@ -309,7 +309,7 @@ static inline unsigned int ip_skb_dst_mtu(const struct sk_buff *skb)
87730 }
87731 }
87732
87733 -u32 ip_idents_reserve(u32 hash, int segs);
87734 +u32 ip_idents_reserve(u32 hash, int segs) __intentional_overflow(-1);
87735 void __ip_select_ident(struct iphdr *iph, int segs);
87736
87737 static inline void ip_select_ident_segs(struct sk_buff *skb, struct sock *sk, int segs)
87738 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
87739 index 9922093..a1755d6 100644
87740 --- a/include/net/ip_fib.h
87741 +++ b/include/net/ip_fib.h
87742 @@ -169,7 +169,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
87743
87744 #define FIB_RES_SADDR(net, res) \
87745 ((FIB_RES_NH(res).nh_saddr_genid == \
87746 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
87747 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
87748 FIB_RES_NH(res).nh_saddr : \
87749 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
87750 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
87751 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
87752 index 624a8a5..b1e2a24 100644
87753 --- a/include/net/ip_vs.h
87754 +++ b/include/net/ip_vs.h
87755 @@ -558,7 +558,7 @@ struct ip_vs_conn {
87756 struct ip_vs_conn *control; /* Master control connection */
87757 atomic_t n_control; /* Number of controlled ones */
87758 struct ip_vs_dest *dest; /* real server */
87759 - atomic_t in_pkts; /* incoming packet counter */
87760 + atomic_unchecked_t in_pkts; /* incoming packet counter */
87761
87762 /* packet transmitter for different forwarding methods. If it
87763 mangles the packet, it must return NF_DROP or better NF_STOLEN,
87764 @@ -705,7 +705,7 @@ struct ip_vs_dest {
87765 __be16 port; /* port number of the server */
87766 union nf_inet_addr addr; /* IP address of the server */
87767 volatile unsigned int flags; /* dest status flags */
87768 - atomic_t conn_flags; /* flags to copy to conn */
87769 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
87770 atomic_t weight; /* server weight */
87771
87772 atomic_t refcnt; /* reference counter */
87773 @@ -960,11 +960,11 @@ struct netns_ipvs {
87774 /* ip_vs_lblc */
87775 int sysctl_lblc_expiration;
87776 struct ctl_table_header *lblc_ctl_header;
87777 - struct ctl_table *lblc_ctl_table;
87778 + ctl_table_no_const *lblc_ctl_table;
87779 /* ip_vs_lblcr */
87780 int sysctl_lblcr_expiration;
87781 struct ctl_table_header *lblcr_ctl_header;
87782 - struct ctl_table *lblcr_ctl_table;
87783 + ctl_table_no_const *lblcr_ctl_table;
87784 /* ip_vs_est */
87785 struct list_head est_list; /* estimator list */
87786 spinlock_t est_lock;
87787 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
87788 index 8d4f588..2e37ad2 100644
87789 --- a/include/net/irda/ircomm_tty.h
87790 +++ b/include/net/irda/ircomm_tty.h
87791 @@ -33,6 +33,7 @@
87792 #include <linux/termios.h>
87793 #include <linux/timer.h>
87794 #include <linux/tty.h> /* struct tty_struct */
87795 +#include <asm/local.h>
87796
87797 #include <net/irda/irias_object.h>
87798 #include <net/irda/ircomm_core.h>
87799 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
87800 index 714cc9a..ea05f3e 100644
87801 --- a/include/net/iucv/af_iucv.h
87802 +++ b/include/net/iucv/af_iucv.h
87803 @@ -149,7 +149,7 @@ struct iucv_skb_cb {
87804 struct iucv_sock_list {
87805 struct hlist_head head;
87806 rwlock_t lock;
87807 - atomic_t autobind_name;
87808 + atomic_unchecked_t autobind_name;
87809 };
87810
87811 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
87812 diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
87813 index f3be818..bf46196 100644
87814 --- a/include/net/llc_c_ac.h
87815 +++ b/include/net/llc_c_ac.h
87816 @@ -87,7 +87,7 @@
87817 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
87818 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
87819
87820 -typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
87821 +typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
87822
87823 int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
87824 int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
87825 diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
87826 index 3948cf1..83b28c4 100644
87827 --- a/include/net/llc_c_ev.h
87828 +++ b/include/net/llc_c_ev.h
87829 @@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
87830 return (struct llc_conn_state_ev *)skb->cb;
87831 }
87832
87833 -typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
87834 -typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
87835 +typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
87836 +typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
87837
87838 int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
87839 int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
87840 diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
87841 index 0e79cfb..f46db31 100644
87842 --- a/include/net/llc_c_st.h
87843 +++ b/include/net/llc_c_st.h
87844 @@ -37,7 +37,7 @@ struct llc_conn_state_trans {
87845 u8 next_state;
87846 llc_conn_ev_qfyr_t *ev_qualifiers;
87847 llc_conn_action_t *ev_actions;
87848 -};
87849 +} __do_const;
87850
87851 struct llc_conn_state {
87852 u8 current_state;
87853 diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
87854 index a61b98c..aade1eb 100644
87855 --- a/include/net/llc_s_ac.h
87856 +++ b/include/net/llc_s_ac.h
87857 @@ -23,7 +23,7 @@
87858 #define SAP_ACT_TEST_IND 9
87859
87860 /* All action functions must look like this */
87861 -typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
87862 +typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
87863
87864 int llc_sap_action_unitdata_ind(struct llc_sap *sap, struct sk_buff *skb);
87865 int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb);
87866 diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
87867 index 567c681..cd73ac02 100644
87868 --- a/include/net/llc_s_st.h
87869 +++ b/include/net/llc_s_st.h
87870 @@ -20,7 +20,7 @@ struct llc_sap_state_trans {
87871 llc_sap_ev_t ev;
87872 u8 next_state;
87873 llc_sap_action_t *ev_actions;
87874 -};
87875 +} __do_const;
87876
87877 struct llc_sap_state {
87878 u8 curr_state;
87879 diff --git a/include/net/mac80211.h b/include/net/mac80211.h
87880 index 421b6ec..5a03729 100644
87881 --- a/include/net/mac80211.h
87882 +++ b/include/net/mac80211.h
87883 @@ -4588,7 +4588,7 @@ struct rate_control_ops {
87884 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
87885
87886 u32 (*get_expected_throughput)(void *priv_sta);
87887 -};
87888 +} __do_const;
87889
87890 static inline int rate_supported(struct ieee80211_sta *sta,
87891 enum ieee80211_band band,
87892 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
87893 index 47f4254..fd095bc 100644
87894 --- a/include/net/neighbour.h
87895 +++ b/include/net/neighbour.h
87896 @@ -163,7 +163,7 @@ struct neigh_ops {
87897 void (*error_report)(struct neighbour *, struct sk_buff *);
87898 int (*output)(struct neighbour *, struct sk_buff *);
87899 int (*connected_output)(struct neighbour *, struct sk_buff *);
87900 -};
87901 +} __do_const;
87902
87903 struct pneigh_entry {
87904 struct pneigh_entry *next;
87905 @@ -217,7 +217,7 @@ struct neigh_table {
87906 struct neigh_statistics __percpu *stats;
87907 struct neigh_hash_table __rcu *nht;
87908 struct pneigh_entry **phash_buckets;
87909 -};
87910 +} __randomize_layout;
87911
87912 static inline int neigh_parms_family(struct neigh_parms *p)
87913 {
87914 diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
87915 index 361d260..903d15f 100644
87916 --- a/include/net/net_namespace.h
87917 +++ b/include/net/net_namespace.h
87918 @@ -129,8 +129,8 @@ struct net {
87919 struct netns_ipvs *ipvs;
87920 #endif
87921 struct sock *diag_nlsk;
87922 - atomic_t fnhe_genid;
87923 -};
87924 + atomic_unchecked_t fnhe_genid;
87925 +} __randomize_layout;
87926
87927 #include <linux/seq_file_net.h>
87928
87929 @@ -286,7 +286,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
87930 #define __net_init __init
87931 #define __net_exit __exit_refok
87932 #define __net_initdata __initdata
87933 +#ifdef CONSTIFY_PLUGIN
87934 #define __net_initconst __initconst
87935 +#else
87936 +#define __net_initconst __initdata
87937 +#endif
87938 #endif
87939
87940 struct pernet_operations {
87941 @@ -296,7 +300,7 @@ struct pernet_operations {
87942 void (*exit_batch)(struct list_head *net_exit_list);
87943 int *id;
87944 size_t size;
87945 -};
87946 +} __do_const;
87947
87948 /*
87949 * Use these carefully. If you implement a network device and it
87950 @@ -344,23 +348,23 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
87951
87952 static inline int rt_genid_ipv4(struct net *net)
87953 {
87954 - return atomic_read(&net->ipv4.rt_genid);
87955 + return atomic_read_unchecked(&net->ipv4.rt_genid);
87956 }
87957
87958 static inline void rt_genid_bump_ipv4(struct net *net)
87959 {
87960 - atomic_inc(&net->ipv4.rt_genid);
87961 + atomic_inc_unchecked(&net->ipv4.rt_genid);
87962 }
87963
87964 #if IS_ENABLED(CONFIG_IPV6)
87965 static inline int rt_genid_ipv6(struct net *net)
87966 {
87967 - return atomic_read(&net->ipv6.rt_genid);
87968 + return atomic_read_unchecked(&net->ipv6.rt_genid);
87969 }
87970
87971 static inline void rt_genid_bump_ipv6(struct net *net)
87972 {
87973 - atomic_inc(&net->ipv6.rt_genid);
87974 + atomic_inc_unchecked(&net->ipv6.rt_genid);
87975 }
87976 #else
87977 static inline int rt_genid_ipv6(struct net *net)
87978 @@ -390,12 +394,12 @@ static inline void rt_genid_bump_all(struct net *net)
87979
87980 static inline int fnhe_genid(struct net *net)
87981 {
87982 - return atomic_read(&net->fnhe_genid);
87983 + return atomic_read_unchecked(&net->fnhe_genid);
87984 }
87985
87986 static inline void fnhe_genid_bump(struct net *net)
87987 {
87988 - atomic_inc(&net->fnhe_genid);
87989 + atomic_inc_unchecked(&net->fnhe_genid);
87990 }
87991
87992 #endif /* __NET_NET_NAMESPACE_H */
87993 diff --git a/include/net/netdma.h b/include/net/netdma.h
87994 index 8ba8ce2..99b7fff 100644
87995 --- a/include/net/netdma.h
87996 +++ b/include/net/netdma.h
87997 @@ -24,7 +24,7 @@
87998 #include <linux/dmaengine.h>
87999 #include <linux/skbuff.h>
88000
88001 -int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
88002 +int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
88003 struct sk_buff *skb, int offset, struct iovec *to,
88004 size_t len, struct dma_pinned_list *pinned_list);
88005
88006 diff --git a/include/net/netlink.h b/include/net/netlink.h
88007 index 2b47eaa..6d5bcc2 100644
88008 --- a/include/net/netlink.h
88009 +++ b/include/net/netlink.h
88010 @@ -521,7 +521,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
88011 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
88012 {
88013 if (mark)
88014 - skb_trim(skb, (unsigned char *) mark - skb->data);
88015 + skb_trim(skb, (const unsigned char *) mark - skb->data);
88016 }
88017
88018 /**
88019 diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
88020 index 773cce3..6a11852 100644
88021 --- a/include/net/netns/conntrack.h
88022 +++ b/include/net/netns/conntrack.h
88023 @@ -13,10 +13,10 @@ struct nf_conntrack_ecache;
88024 struct nf_proto_net {
88025 #ifdef CONFIG_SYSCTL
88026 struct ctl_table_header *ctl_table_header;
88027 - struct ctl_table *ctl_table;
88028 + ctl_table_no_const *ctl_table;
88029 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
88030 struct ctl_table_header *ctl_compat_header;
88031 - struct ctl_table *ctl_compat_table;
88032 + ctl_table_no_const *ctl_compat_table;
88033 #endif
88034 #endif
88035 unsigned int users;
88036 @@ -59,7 +59,7 @@ struct nf_ip_net {
88037 struct nf_icmp_net icmpv6;
88038 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
88039 struct ctl_table_header *ctl_table_header;
88040 - struct ctl_table *ctl_table;
88041 + ctl_table_no_const *ctl_table;
88042 #endif
88043 };
88044
88045 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
88046 index aec5e12..807233f 100644
88047 --- a/include/net/netns/ipv4.h
88048 +++ b/include/net/netns/ipv4.h
88049 @@ -82,7 +82,7 @@ struct netns_ipv4 {
88050
88051 struct ping_group_range ping_group_range;
88052
88053 - atomic_t dev_addr_genid;
88054 + atomic_unchecked_t dev_addr_genid;
88055
88056 #ifdef CONFIG_SYSCTL
88057 unsigned long *sysctl_local_reserved_ports;
88058 @@ -96,6 +96,6 @@ struct netns_ipv4 {
88059 struct fib_rules_ops *mr_rules_ops;
88060 #endif
88061 #endif
88062 - atomic_t rt_genid;
88063 + atomic_unchecked_t rt_genid;
88064 };
88065 #endif
88066 diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
88067 index 19d3446..3c87195 100644
88068 --- a/include/net/netns/ipv6.h
88069 +++ b/include/net/netns/ipv6.h
88070 @@ -74,8 +74,8 @@ struct netns_ipv6 {
88071 struct fib_rules_ops *mr6_rules_ops;
88072 #endif
88073 #endif
88074 - atomic_t dev_addr_genid;
88075 - atomic_t rt_genid;
88076 + atomic_unchecked_t dev_addr_genid;
88077 + atomic_unchecked_t rt_genid;
88078 };
88079
88080 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
88081 diff --git a/include/net/netns/xfrm.h b/include/net/netns/xfrm.h
88082 index 3492434..209f58c 100644
88083 --- a/include/net/netns/xfrm.h
88084 +++ b/include/net/netns/xfrm.h
88085 @@ -64,7 +64,7 @@ struct netns_xfrm {
88086
88087 /* flow cache part */
88088 struct flow_cache flow_cache_global;
88089 - atomic_t flow_cache_genid;
88090 + atomic_unchecked_t flow_cache_genid;
88091 struct list_head flow_cache_gc_list;
88092 spinlock_t flow_cache_gc_lock;
88093 struct work_struct flow_cache_gc_work;
88094 diff --git a/include/net/ping.h b/include/net/ping.h
88095 index 026479b..d9b2829 100644
88096 --- a/include/net/ping.h
88097 +++ b/include/net/ping.h
88098 @@ -54,7 +54,7 @@ struct ping_iter_state {
88099
88100 extern struct proto ping_prot;
88101 #if IS_ENABLED(CONFIG_IPV6)
88102 -extern struct pingv6_ops pingv6_ops;
88103 +extern struct pingv6_ops *pingv6_ops;
88104 #endif
88105
88106 struct pingfakehdr {
88107 diff --git a/include/net/protocol.h b/include/net/protocol.h
88108 index d6fcc1f..ca277058 100644
88109 --- a/include/net/protocol.h
88110 +++ b/include/net/protocol.h
88111 @@ -49,7 +49,7 @@ struct net_protocol {
88112 * socket lookup?
88113 */
88114 icmp_strict_tag_validation:1;
88115 -};
88116 +} __do_const;
88117
88118 #if IS_ENABLED(CONFIG_IPV6)
88119 struct inet6_protocol {
88120 @@ -62,7 +62,7 @@ struct inet6_protocol {
88121 u8 type, u8 code, int offset,
88122 __be32 info);
88123 unsigned int flags; /* INET6_PROTO_xxx */
88124 -};
88125 +} __do_const;
88126
88127 #define INET6_PROTO_NOPOLICY 0x1
88128 #define INET6_PROTO_FINAL 0x2
88129 diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
88130 index 72240e5..8c14bef 100644
88131 --- a/include/net/rtnetlink.h
88132 +++ b/include/net/rtnetlink.h
88133 @@ -93,7 +93,7 @@ struct rtnl_link_ops {
88134 int (*fill_slave_info)(struct sk_buff *skb,
88135 const struct net_device *dev,
88136 const struct net_device *slave_dev);
88137 -};
88138 +} __do_const;
88139
88140 int __rtnl_link_register(struct rtnl_link_ops *ops);
88141 void __rtnl_link_unregister(struct rtnl_link_ops *ops);
88142 diff --git a/include/net/sctp/checksum.h b/include/net/sctp/checksum.h
88143 index 4a5b9a3..ca27d73 100644
88144 --- a/include/net/sctp/checksum.h
88145 +++ b/include/net/sctp/checksum.h
88146 @@ -61,8 +61,8 @@ static inline __le32 sctp_compute_cksum(const struct sk_buff *skb,
88147 unsigned int offset)
88148 {
88149 struct sctphdr *sh = sctp_hdr(skb);
88150 - __le32 ret, old = sh->checksum;
88151 - const struct skb_checksum_ops ops = {
88152 + __le32 ret, old = sh->checksum;
88153 + static const struct skb_checksum_ops ops = {
88154 .update = sctp_csum_update,
88155 .combine = sctp_csum_combine,
88156 };
88157 diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
88158 index 7f4eeb3..37e8fe1 100644
88159 --- a/include/net/sctp/sm.h
88160 +++ b/include/net/sctp/sm.h
88161 @@ -80,7 +80,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
88162 typedef struct {
88163 sctp_state_fn_t *fn;
88164 const char *name;
88165 -} sctp_sm_table_entry_t;
88166 +} __do_const sctp_sm_table_entry_t;
88167
88168 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
88169 * currently in use.
88170 @@ -292,7 +292,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
88171 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
88172
88173 /* Extern declarations for major data structures. */
88174 -extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
88175 +extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
88176
88177
88178 /* Get the size of a DATA chunk payload. */
88179 diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
88180 index f38588bf..94c1795 100644
88181 --- a/include/net/sctp/structs.h
88182 +++ b/include/net/sctp/structs.h
88183 @@ -507,7 +507,7 @@ struct sctp_pf {
88184 struct sctp_association *asoc);
88185 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
88186 struct sctp_af *af;
88187 -};
88188 +} __do_const;
88189
88190
88191 /* Structure to track chunk fragments that have been acked, but peer
88192 diff --git a/include/net/sock.h b/include/net/sock.h
88193 index 1563507..20d5d0e 100644
88194 --- a/include/net/sock.h
88195 +++ b/include/net/sock.h
88196 @@ -349,7 +349,7 @@ struct sock {
88197 unsigned int sk_napi_id;
88198 unsigned int sk_ll_usec;
88199 #endif
88200 - atomic_t sk_drops;
88201 + atomic_unchecked_t sk_drops;
88202 int sk_rcvbuf;
88203
88204 struct sk_filter __rcu *sk_filter;
88205 @@ -1038,7 +1038,7 @@ struct proto {
88206 void (*destroy_cgroup)(struct mem_cgroup *memcg);
88207 struct cg_proto *(*proto_cgroup)(struct mem_cgroup *memcg);
88208 #endif
88209 -};
88210 +} __randomize_layout;
88211
88212 /*
88213 * Bits in struct cg_proto.flags
88214 @@ -1225,7 +1225,7 @@ static inline u64 memcg_memory_allocated_read(struct cg_proto *prot)
88215 return ret >> PAGE_SHIFT;
88216 }
88217
88218 -static inline long
88219 +static inline long __intentional_overflow(-1)
88220 sk_memory_allocated(const struct sock *sk)
88221 {
88222 struct proto *prot = sk->sk_prot;
88223 @@ -1370,7 +1370,7 @@ struct sock_iocb {
88224 struct scm_cookie *scm;
88225 struct msghdr *msg, async_msg;
88226 struct kiocb *kiocb;
88227 -};
88228 +} __randomize_layout;
88229
88230 static inline struct sock_iocb *kiocb_to_siocb(struct kiocb *iocb)
88231 {
88232 @@ -1623,6 +1623,33 @@ void sk_common_release(struct sock *sk);
88233 /* Initialise core socket variables */
88234 void sock_init_data(struct socket *sock, struct sock *sk);
88235
88236 +void sk_filter_release_rcu(struct rcu_head *rcu);
88237 +
88238 +/**
88239 + * sk_filter_release - release a socket filter
88240 + * @fp: filter to remove
88241 + *
88242 + * Remove a filter from a socket and release its resources.
88243 + */
88244 +
88245 +static inline void sk_filter_release(struct sk_filter *fp)
88246 +{
88247 + if (atomic_dec_and_test(&fp->refcnt))
88248 + call_rcu(&fp->rcu, sk_filter_release_rcu);
88249 +}
88250 +
88251 +static inline void sk_filter_uncharge(struct sock *sk, struct sk_filter *fp)
88252 +{
88253 + atomic_sub(sk_filter_size(fp->len), &sk->sk_omem_alloc);
88254 + sk_filter_release(fp);
88255 +}
88256 +
88257 +static inline void sk_filter_charge(struct sock *sk, struct sk_filter *fp)
88258 +{
88259 + atomic_inc(&fp->refcnt);
88260 + atomic_add(sk_filter_size(fp->len), &sk->sk_omem_alloc);
88261 +}
88262 +
88263 /*
88264 * Socket reference counting postulates.
88265 *
88266 @@ -1805,7 +1832,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
88267 }
88268
88269 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
88270 - char __user *from, char *to,
88271 + char __user *from, unsigned char *to,
88272 int copy, int offset)
88273 {
88274 if (skb->ip_summed == CHECKSUM_NONE) {
88275 @@ -2067,7 +2094,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
88276 }
88277 }
88278
88279 -struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
88280 +struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
88281
88282 /**
88283 * sk_page_frag - return an appropriate page_frag
88284 diff --git a/include/net/tcp.h b/include/net/tcp.h
88285 index 7286db8..f1aa7dc 100644
88286 --- a/include/net/tcp.h
88287 +++ b/include/net/tcp.h
88288 @@ -535,7 +535,7 @@ void tcp_retransmit_timer(struct sock *sk);
88289 void tcp_xmit_retransmit_queue(struct sock *);
88290 void tcp_simple_retransmit(struct sock *);
88291 int tcp_trim_head(struct sock *, struct sk_buff *, u32);
88292 -int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int, gfp_t);
88293 +int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int, gfp_t);
88294
88295 void tcp_send_probe0(struct sock *);
88296 void tcp_send_partial(struct sock *);
88297 @@ -708,8 +708,8 @@ struct tcp_skb_cb {
88298 struct inet6_skb_parm h6;
88299 #endif
88300 } header; /* For incoming frames */
88301 - __u32 seq; /* Starting sequence number */
88302 - __u32 end_seq; /* SEQ + FIN + SYN + datalen */
88303 + __u32 seq __intentional_overflow(0); /* Starting sequence number */
88304 + __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
88305 __u32 when; /* used to compute rtt's */
88306 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
88307
88308 @@ -723,7 +723,7 @@ struct tcp_skb_cb {
88309
88310 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
88311 /* 1 byte hole */
88312 - __u32 ack_seq; /* Sequence number ACK'd */
88313 + __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
88314 };
88315
88316 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
88317 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
88318 index 721e9c3b..3c81bbf 100644
88319 --- a/include/net/xfrm.h
88320 +++ b/include/net/xfrm.h
88321 @@ -285,7 +285,6 @@ struct xfrm_dst;
88322 struct xfrm_policy_afinfo {
88323 unsigned short family;
88324 struct dst_ops *dst_ops;
88325 - void (*garbage_collect)(struct net *net);
88326 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
88327 const xfrm_address_t *saddr,
88328 const xfrm_address_t *daddr);
88329 @@ -303,7 +302,7 @@ struct xfrm_policy_afinfo {
88330 struct net_device *dev,
88331 const struct flowi *fl);
88332 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
88333 -};
88334 +} __do_const;
88335
88336 int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
88337 int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
88338 @@ -342,7 +341,7 @@ struct xfrm_state_afinfo {
88339 int (*transport_finish)(struct sk_buff *skb,
88340 int async);
88341 void (*local_error)(struct sk_buff *skb, u32 mtu);
88342 -};
88343 +} __do_const;
88344
88345 int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
88346 int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
88347 @@ -437,7 +436,7 @@ struct xfrm_mode {
88348 struct module *owner;
88349 unsigned int encap;
88350 int flags;
88351 -};
88352 +} __do_const;
88353
88354 /* Flags for xfrm_mode. */
88355 enum {
88356 @@ -534,7 +533,7 @@ struct xfrm_policy {
88357 struct timer_list timer;
88358
88359 struct flow_cache_object flo;
88360 - atomic_t genid;
88361 + atomic_unchecked_t genid;
88362 u32 priority;
88363 u32 index;
88364 struct xfrm_mark mark;
88365 @@ -1167,6 +1166,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
88366 }
88367
88368 void xfrm_garbage_collect(struct net *net);
88369 +void xfrm_garbage_collect_deferred(struct net *net);
88370
88371 #else
88372
88373 @@ -1205,6 +1205,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
88374 static inline void xfrm_garbage_collect(struct net *net)
88375 {
88376 }
88377 +static inline void xfrm_garbage_collect_deferred(struct net *net)
88378 +{
88379 +}
88380 #endif
88381
88382 static __inline__
88383 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
88384 index 1017e0b..227aa4d 100644
88385 --- a/include/rdma/iw_cm.h
88386 +++ b/include/rdma/iw_cm.h
88387 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
88388 int backlog);
88389
88390 int (*destroy_listen)(struct iw_cm_id *cm_id);
88391 -};
88392 +} __no_const;
88393
88394 /**
88395 * iw_create_cm_id - Create an IW CM identifier.
88396 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
88397 index 52beadf..598734c 100644
88398 --- a/include/scsi/libfc.h
88399 +++ b/include/scsi/libfc.h
88400 @@ -771,6 +771,7 @@ struct libfc_function_template {
88401 */
88402 void (*disc_stop_final) (struct fc_lport *);
88403 };
88404 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
88405
88406 /**
88407 * struct fc_disc - Discovery context
88408 @@ -875,7 +876,7 @@ struct fc_lport {
88409 struct fc_vport *vport;
88410
88411 /* Operational Information */
88412 - struct libfc_function_template tt;
88413 + libfc_function_template_no_const tt;
88414 u8 link_up;
88415 u8 qfull;
88416 enum fc_lport_state state;
88417 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
88418 index 27ab310..60dc245 100644
88419 --- a/include/scsi/scsi_device.h
88420 +++ b/include/scsi/scsi_device.h
88421 @@ -187,9 +187,9 @@ struct scsi_device {
88422 unsigned int max_device_blocked; /* what device_blocked counts down from */
88423 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
88424
88425 - atomic_t iorequest_cnt;
88426 - atomic_t iodone_cnt;
88427 - atomic_t ioerr_cnt;
88428 + atomic_unchecked_t iorequest_cnt;
88429 + atomic_unchecked_t iodone_cnt;
88430 + atomic_unchecked_t ioerr_cnt;
88431
88432 struct device sdev_gendev,
88433 sdev_dev;
88434 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
88435 index 8c79980..723f6f9 100644
88436 --- a/include/scsi/scsi_transport_fc.h
88437 +++ b/include/scsi/scsi_transport_fc.h
88438 @@ -752,7 +752,8 @@ struct fc_function_template {
88439 unsigned long show_host_system_hostname:1;
88440
88441 unsigned long disable_target_scan:1;
88442 -};
88443 +} __do_const;
88444 +typedef struct fc_function_template __no_const fc_function_template_no_const;
88445
88446
88447 /**
88448 diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
88449 index ae6c3b8..fd748ac 100644
88450 --- a/include/sound/compress_driver.h
88451 +++ b/include/sound/compress_driver.h
88452 @@ -128,7 +128,7 @@ struct snd_compr_ops {
88453 struct snd_compr_caps *caps);
88454 int (*get_codec_caps) (struct snd_compr_stream *stream,
88455 struct snd_compr_codec_caps *codec);
88456 -};
88457 +} __no_const;
88458
88459 /**
88460 * struct snd_compr: Compressed device
88461 diff --git a/include/sound/soc.h b/include/sound/soc.h
88462 index ed9e2d7..aad0887 100644
88463 --- a/include/sound/soc.h
88464 +++ b/include/sound/soc.h
88465 @@ -798,7 +798,7 @@ struct snd_soc_codec_driver {
88466 /* probe ordering - for components with runtime dependencies */
88467 int probe_order;
88468 int remove_order;
88469 -};
88470 +} __do_const;
88471
88472 /* SoC platform interface */
88473 struct snd_soc_platform_driver {
88474 @@ -845,7 +845,7 @@ struct snd_soc_platform_driver {
88475 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
88476 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
88477 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
88478 -};
88479 +} __do_const;
88480
88481 struct snd_soc_platform {
88482 const char *name;
88483 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
88484 index 9ec9864..e2ee1ee 100644
88485 --- a/include/target/target_core_base.h
88486 +++ b/include/target/target_core_base.h
88487 @@ -761,7 +761,7 @@ struct se_device {
88488 atomic_long_t write_bytes;
88489 /* Active commands on this virtual SE device */
88490 atomic_t simple_cmds;
88491 - atomic_t dev_ordered_id;
88492 + atomic_unchecked_t dev_ordered_id;
88493 atomic_t dev_ordered_sync;
88494 atomic_t dev_qf_count;
88495 int export_count;
88496 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
88497 new file mode 100644
88498 index 0000000..fb634b7
88499 --- /dev/null
88500 +++ b/include/trace/events/fs.h
88501 @@ -0,0 +1,53 @@
88502 +#undef TRACE_SYSTEM
88503 +#define TRACE_SYSTEM fs
88504 +
88505 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
88506 +#define _TRACE_FS_H
88507 +
88508 +#include <linux/fs.h>
88509 +#include <linux/tracepoint.h>
88510 +
88511 +TRACE_EVENT(do_sys_open,
88512 +
88513 + TP_PROTO(const char *filename, int flags, int mode),
88514 +
88515 + TP_ARGS(filename, flags, mode),
88516 +
88517 + TP_STRUCT__entry(
88518 + __string( filename, filename )
88519 + __field( int, flags )
88520 + __field( int, mode )
88521 + ),
88522 +
88523 + TP_fast_assign(
88524 + __assign_str(filename, filename);
88525 + __entry->flags = flags;
88526 + __entry->mode = mode;
88527 + ),
88528 +
88529 + TP_printk("\"%s\" %x %o",
88530 + __get_str(filename), __entry->flags, __entry->mode)
88531 +);
88532 +
88533 +TRACE_EVENT(open_exec,
88534 +
88535 + TP_PROTO(const char *filename),
88536 +
88537 + TP_ARGS(filename),
88538 +
88539 + TP_STRUCT__entry(
88540 + __string( filename, filename )
88541 + ),
88542 +
88543 + TP_fast_assign(
88544 + __assign_str(filename, filename);
88545 + ),
88546 +
88547 + TP_printk("\"%s\"",
88548 + __get_str(filename))
88549 +);
88550 +
88551 +#endif /* _TRACE_FS_H */
88552 +
88553 +/* This part must be outside protection */
88554 +#include <trace/define_trace.h>
88555 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
88556 index 1c09820..7f5ec79 100644
88557 --- a/include/trace/events/irq.h
88558 +++ b/include/trace/events/irq.h
88559 @@ -36,7 +36,7 @@ struct softirq_action;
88560 */
88561 TRACE_EVENT(irq_handler_entry,
88562
88563 - TP_PROTO(int irq, struct irqaction *action),
88564 + TP_PROTO(int irq, const struct irqaction *action),
88565
88566 TP_ARGS(irq, action),
88567
88568 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
88569 */
88570 TRACE_EVENT(irq_handler_exit,
88571
88572 - TP_PROTO(int irq, struct irqaction *action, int ret),
88573 + TP_PROTO(int irq, const struct irqaction *action, int ret),
88574
88575 TP_ARGS(irq, action, ret),
88576
88577 diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
88578 index 7caf44c..23c6f27 100644
88579 --- a/include/uapi/linux/a.out.h
88580 +++ b/include/uapi/linux/a.out.h
88581 @@ -39,6 +39,14 @@ enum machine_type {
88582 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
88583 };
88584
88585 +/* Constants for the N_FLAGS field */
88586 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
88587 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
88588 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
88589 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
88590 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
88591 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
88592 +
88593 #if !defined (N_MAGIC)
88594 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
88595 #endif
88596 diff --git a/include/uapi/linux/bcache.h b/include/uapi/linux/bcache.h
88597 index 22b6ad3..aeba37e 100644
88598 --- a/include/uapi/linux/bcache.h
88599 +++ b/include/uapi/linux/bcache.h
88600 @@ -5,6 +5,7 @@
88601 * Bcache on disk data structures
88602 */
88603
88604 +#include <linux/compiler.h>
88605 #include <asm/types.h>
88606
88607 #define BITMASK(name, type, field, offset, size) \
88608 @@ -20,8 +21,8 @@ static inline void SET_##name(type *k, __u64 v) \
88609 /* Btree keys - all units are in sectors */
88610
88611 struct bkey {
88612 - __u64 high;
88613 - __u64 low;
88614 + __u64 high __intentional_overflow(-1);
88615 + __u64 low __intentional_overflow(-1);
88616 __u64 ptr[];
88617 };
88618
88619 diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
88620 index d876736..ccce5c0 100644
88621 --- a/include/uapi/linux/byteorder/little_endian.h
88622 +++ b/include/uapi/linux/byteorder/little_endian.h
88623 @@ -42,51 +42,51 @@
88624
88625 static inline __le64 __cpu_to_le64p(const __u64 *p)
88626 {
88627 - return (__force __le64)*p;
88628 + return (__force const __le64)*p;
88629 }
88630 -static inline __u64 __le64_to_cpup(const __le64 *p)
88631 +static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
88632 {
88633 - return (__force __u64)*p;
88634 + return (__force const __u64)*p;
88635 }
88636 static inline __le32 __cpu_to_le32p(const __u32 *p)
88637 {
88638 - return (__force __le32)*p;
88639 + return (__force const __le32)*p;
88640 }
88641 static inline __u32 __le32_to_cpup(const __le32 *p)
88642 {
88643 - return (__force __u32)*p;
88644 + return (__force const __u32)*p;
88645 }
88646 static inline __le16 __cpu_to_le16p(const __u16 *p)
88647 {
88648 - return (__force __le16)*p;
88649 + return (__force const __le16)*p;
88650 }
88651 static inline __u16 __le16_to_cpup(const __le16 *p)
88652 {
88653 - return (__force __u16)*p;
88654 + return (__force const __u16)*p;
88655 }
88656 static inline __be64 __cpu_to_be64p(const __u64 *p)
88657 {
88658 - return (__force __be64)__swab64p(p);
88659 + return (__force const __be64)__swab64p(p);
88660 }
88661 static inline __u64 __be64_to_cpup(const __be64 *p)
88662 {
88663 - return __swab64p((__u64 *)p);
88664 + return __swab64p((const __u64 *)p);
88665 }
88666 static inline __be32 __cpu_to_be32p(const __u32 *p)
88667 {
88668 - return (__force __be32)__swab32p(p);
88669 + return (__force const __be32)__swab32p(p);
88670 }
88671 -static inline __u32 __be32_to_cpup(const __be32 *p)
88672 +static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
88673 {
88674 - return __swab32p((__u32 *)p);
88675 + return __swab32p((const __u32 *)p);
88676 }
88677 static inline __be16 __cpu_to_be16p(const __u16 *p)
88678 {
88679 - return (__force __be16)__swab16p(p);
88680 + return (__force const __be16)__swab16p(p);
88681 }
88682 static inline __u16 __be16_to_cpup(const __be16 *p)
88683 {
88684 - return __swab16p((__u16 *)p);
88685 + return __swab16p((const __u16 *)p);
88686 }
88687 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
88688 #define __le64_to_cpus(x) do { (void)(x); } while (0)
88689 diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
88690 index ef6103b..d4e65dd 100644
88691 --- a/include/uapi/linux/elf.h
88692 +++ b/include/uapi/linux/elf.h
88693 @@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
88694 #define PT_GNU_EH_FRAME 0x6474e550
88695
88696 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
88697 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
88698 +
88699 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
88700 +
88701 +/* Constants for the e_flags field */
88702 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
88703 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
88704 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
88705 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
88706 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
88707 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
88708
88709 /*
88710 * Extended Numbering
88711 @@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
88712 #define DT_DEBUG 21
88713 #define DT_TEXTREL 22
88714 #define DT_JMPREL 23
88715 +#define DT_FLAGS 30
88716 + #define DF_TEXTREL 0x00000004
88717 #define DT_ENCODING 32
88718 #define OLD_DT_LOOS 0x60000000
88719 #define DT_LOOS 0x6000000d
88720 @@ -240,6 +253,19 @@ typedef struct elf64_hdr {
88721 #define PF_W 0x2
88722 #define PF_X 0x1
88723
88724 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
88725 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
88726 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
88727 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
88728 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
88729 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
88730 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
88731 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
88732 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
88733 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
88734 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
88735 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
88736 +
88737 typedef struct elf32_phdr{
88738 Elf32_Word p_type;
88739 Elf32_Off p_offset;
88740 @@ -332,6 +358,8 @@ typedef struct elf64_shdr {
88741 #define EI_OSABI 7
88742 #define EI_PAD 8
88743
88744 +#define EI_PAX 14
88745 +
88746 #define ELFMAG0 0x7f /* EI_MAG */
88747 #define ELFMAG1 'E'
88748 #define ELFMAG2 'L'
88749 diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
88750 index aa169c4..6a2771d 100644
88751 --- a/include/uapi/linux/personality.h
88752 +++ b/include/uapi/linux/personality.h
88753 @@ -30,6 +30,7 @@ enum {
88754 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
88755 ADDR_NO_RANDOMIZE | \
88756 ADDR_COMPAT_LAYOUT | \
88757 + ADDR_LIMIT_3GB | \
88758 MMAP_PAGE_ZERO)
88759
88760 /*
88761 diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
88762 index 7530e74..e714828 100644
88763 --- a/include/uapi/linux/screen_info.h
88764 +++ b/include/uapi/linux/screen_info.h
88765 @@ -43,7 +43,8 @@ struct screen_info {
88766 __u16 pages; /* 0x32 */
88767 __u16 vesa_attributes; /* 0x34 */
88768 __u32 capabilities; /* 0x36 */
88769 - __u8 _reserved[6]; /* 0x3a */
88770 + __u16 vesapm_size; /* 0x3a */
88771 + __u8 _reserved[4]; /* 0x3c */
88772 } __attribute__((packed));
88773
88774 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
88775 diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
88776 index 0e011eb..82681b1 100644
88777 --- a/include/uapi/linux/swab.h
88778 +++ b/include/uapi/linux/swab.h
88779 @@ -43,7 +43,7 @@
88780 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
88781 */
88782
88783 -static inline __attribute_const__ __u16 __fswab16(__u16 val)
88784 +static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
88785 {
88786 #ifdef __HAVE_BUILTIN_BSWAP16__
88787 return __builtin_bswap16(val);
88788 @@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
88789 #endif
88790 }
88791
88792 -static inline __attribute_const__ __u32 __fswab32(__u32 val)
88793 +static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
88794 {
88795 #ifdef __HAVE_BUILTIN_BSWAP32__
88796 return __builtin_bswap32(val);
88797 @@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
88798 #endif
88799 }
88800
88801 -static inline __attribute_const__ __u64 __fswab64(__u64 val)
88802 +static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
88803 {
88804 #ifdef __HAVE_BUILTIN_BSWAP64__
88805 return __builtin_bswap64(val);
88806 diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
88807 index 6d67213..552fdd9 100644
88808 --- a/include/uapi/linux/sysctl.h
88809 +++ b/include/uapi/linux/sysctl.h
88810 @@ -155,8 +155,6 @@ enum
88811 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
88812 };
88813
88814 -
88815 -
88816 /* CTL_VM names: */
88817 enum
88818 {
88819 diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
88820 index 168ff50..a921df2 100644
88821 --- a/include/uapi/linux/videodev2.h
88822 +++ b/include/uapi/linux/videodev2.h
88823 @@ -1253,7 +1253,7 @@ struct v4l2_ext_control {
88824 union {
88825 __s32 value;
88826 __s64 value64;
88827 - char *string;
88828 + char __user *string;
88829 };
88830 } __attribute__ ((packed));
88831
88832 diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
88833 index c38355c..17a57bc 100644
88834 --- a/include/uapi/linux/xattr.h
88835 +++ b/include/uapi/linux/xattr.h
88836 @@ -73,5 +73,9 @@
88837 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
88838 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
88839
88840 +/* User namespace */
88841 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
88842 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
88843 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
88844
88845 #endif /* _UAPI_LINUX_XATTR_H */
88846 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
88847 index f9466fa..f4e2b81 100644
88848 --- a/include/video/udlfb.h
88849 +++ b/include/video/udlfb.h
88850 @@ -53,10 +53,10 @@ struct dlfb_data {
88851 u32 pseudo_palette[256];
88852 int blank_mode; /*one of FB_BLANK_ */
88853 /* blit-only rendering path metrics, exposed through sysfs */
88854 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
88855 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
88856 - atomic_t bytes_sent; /* to usb, after compression including overhead */
88857 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
88858 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
88859 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
88860 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
88861 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
88862 };
88863
88864 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
88865 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
88866 index 30f5362..8ed8ac9 100644
88867 --- a/include/video/uvesafb.h
88868 +++ b/include/video/uvesafb.h
88869 @@ -122,6 +122,7 @@ struct uvesafb_par {
88870 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
88871 u8 pmi_setpal; /* PMI for palette changes */
88872 u16 *pmi_base; /* protected mode interface location */
88873 + u8 *pmi_code; /* protected mode code location */
88874 void *pmi_start;
88875 void *pmi_pal;
88876 u8 *vbe_state_orig; /*
88877 diff --git a/init/Kconfig b/init/Kconfig
88878 index 9d76b99..d378b1e 100644
88879 --- a/init/Kconfig
88880 +++ b/init/Kconfig
88881 @@ -1105,6 +1105,7 @@ endif # CGROUPS
88882
88883 config CHECKPOINT_RESTORE
88884 bool "Checkpoint/restore support" if EXPERT
88885 + depends on !GRKERNSEC
88886 default n
88887 help
88888 Enables additional kernel features in a sake of checkpoint/restore.
88889 @@ -1589,7 +1590,7 @@ config SLUB_DEBUG
88890
88891 config COMPAT_BRK
88892 bool "Disable heap randomization"
88893 - default y
88894 + default n
88895 help
88896 Randomizing heap placement makes heap exploits harder, but it
88897 also breaks ancient binaries (including anything libc5 based).
88898 @@ -1877,7 +1878,7 @@ config INIT_ALL_POSSIBLE
88899 config STOP_MACHINE
88900 bool
88901 default y
88902 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
88903 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
88904 help
88905 Need stop_machine() primitive.
88906
88907 diff --git a/init/Makefile b/init/Makefile
88908 index 7bc47ee..6da2dc7 100644
88909 --- a/init/Makefile
88910 +++ b/init/Makefile
88911 @@ -2,6 +2,9 @@
88912 # Makefile for the linux kernel.
88913 #
88914
88915 +ccflags-y := $(GCC_PLUGINS_CFLAGS)
88916 +asflags-y := $(GCC_PLUGINS_AFLAGS)
88917 +
88918 obj-y := main.o version.o mounts.o
88919 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
88920 obj-y += noinitramfs.o
88921 diff --git a/init/do_mounts.c b/init/do_mounts.c
88922 index 82f2288..ea1430a 100644
88923 --- a/init/do_mounts.c
88924 +++ b/init/do_mounts.c
88925 @@ -359,11 +359,11 @@ static void __init get_fs_names(char *page)
88926 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
88927 {
88928 struct super_block *s;
88929 - int err = sys_mount(name, "/root", fs, flags, data);
88930 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
88931 if (err)
88932 return err;
88933
88934 - sys_chdir("/root");
88935 + sys_chdir((const char __force_user *)"/root");
88936 s = current->fs->pwd.dentry->d_sb;
88937 ROOT_DEV = s->s_dev;
88938 printk(KERN_INFO
88939 @@ -484,18 +484,18 @@ void __init change_floppy(char *fmt, ...)
88940 va_start(args, fmt);
88941 vsprintf(buf, fmt, args);
88942 va_end(args);
88943 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
88944 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
88945 if (fd >= 0) {
88946 sys_ioctl(fd, FDEJECT, 0);
88947 sys_close(fd);
88948 }
88949 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
88950 - fd = sys_open("/dev/console", O_RDWR, 0);
88951 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
88952 if (fd >= 0) {
88953 sys_ioctl(fd, TCGETS, (long)&termios);
88954 termios.c_lflag &= ~ICANON;
88955 sys_ioctl(fd, TCSETSF, (long)&termios);
88956 - sys_read(fd, &c, 1);
88957 + sys_read(fd, (char __user *)&c, 1);
88958 termios.c_lflag |= ICANON;
88959 sys_ioctl(fd, TCSETSF, (long)&termios);
88960 sys_close(fd);
88961 @@ -589,8 +589,8 @@ void __init prepare_namespace(void)
88962 mount_root();
88963 out:
88964 devtmpfs_mount("dev");
88965 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
88966 - sys_chroot(".");
88967 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
88968 + sys_chroot((const char __force_user *)".");
88969 }
88970
88971 static bool is_tmpfs;
88972 diff --git a/init/do_mounts.h b/init/do_mounts.h
88973 index f5b978a..69dbfe8 100644
88974 --- a/init/do_mounts.h
88975 +++ b/init/do_mounts.h
88976 @@ -15,15 +15,15 @@ extern int root_mountflags;
88977
88978 static inline int create_dev(char *name, dev_t dev)
88979 {
88980 - sys_unlink(name);
88981 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
88982 + sys_unlink((char __force_user *)name);
88983 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
88984 }
88985
88986 #if BITS_PER_LONG == 32
88987 static inline u32 bstat(char *name)
88988 {
88989 struct stat64 stat;
88990 - if (sys_stat64(name, &stat) != 0)
88991 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
88992 return 0;
88993 if (!S_ISBLK(stat.st_mode))
88994 return 0;
88995 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
88996 static inline u32 bstat(char *name)
88997 {
88998 struct stat stat;
88999 - if (sys_newstat(name, &stat) != 0)
89000 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
89001 return 0;
89002 if (!S_ISBLK(stat.st_mode))
89003 return 0;
89004 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
89005 index 3e0878e..8a9d7a0 100644
89006 --- a/init/do_mounts_initrd.c
89007 +++ b/init/do_mounts_initrd.c
89008 @@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
89009 {
89010 sys_unshare(CLONE_FS | CLONE_FILES);
89011 /* stdin/stdout/stderr for /linuxrc */
89012 - sys_open("/dev/console", O_RDWR, 0);
89013 + sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
89014 sys_dup(0);
89015 sys_dup(0);
89016 /* move initrd over / and chdir/chroot in initrd root */
89017 - sys_chdir("/root");
89018 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
89019 - sys_chroot(".");
89020 + sys_chdir((const char __force_user *)"/root");
89021 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
89022 + sys_chroot((const char __force_user *)".");
89023 sys_setsid();
89024 return 0;
89025 }
89026 @@ -59,8 +59,8 @@ static void __init handle_initrd(void)
89027 create_dev("/dev/root.old", Root_RAM0);
89028 /* mount initrd on rootfs' /root */
89029 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
89030 - sys_mkdir("/old", 0700);
89031 - sys_chdir("/old");
89032 + sys_mkdir((const char __force_user *)"/old", 0700);
89033 + sys_chdir((const char __force_user *)"/old");
89034
89035 /* try loading default modules from initrd */
89036 load_default_modules();
89037 @@ -80,31 +80,31 @@ static void __init handle_initrd(void)
89038 current->flags &= ~PF_FREEZER_SKIP;
89039
89040 /* move initrd to rootfs' /old */
89041 - sys_mount("..", ".", NULL, MS_MOVE, NULL);
89042 + sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
89043 /* switch root and cwd back to / of rootfs */
89044 - sys_chroot("..");
89045 + sys_chroot((const char __force_user *)"..");
89046
89047 if (new_decode_dev(real_root_dev) == Root_RAM0) {
89048 - sys_chdir("/old");
89049 + sys_chdir((const char __force_user *)"/old");
89050 return;
89051 }
89052
89053 - sys_chdir("/");
89054 + sys_chdir((const char __force_user *)"/");
89055 ROOT_DEV = new_decode_dev(real_root_dev);
89056 mount_root();
89057
89058 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
89059 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
89060 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
89061 if (!error)
89062 printk("okay\n");
89063 else {
89064 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
89065 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
89066 if (error == -ENOENT)
89067 printk("/initrd does not exist. Ignored.\n");
89068 else
89069 printk("failed\n");
89070 printk(KERN_NOTICE "Unmounting old root\n");
89071 - sys_umount("/old", MNT_DETACH);
89072 + sys_umount((char __force_user *)"/old", MNT_DETACH);
89073 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
89074 if (fd < 0) {
89075 error = fd;
89076 @@ -127,11 +127,11 @@ int __init initrd_load(void)
89077 * mounted in the normal path.
89078 */
89079 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
89080 - sys_unlink("/initrd.image");
89081 + sys_unlink((const char __force_user *)"/initrd.image");
89082 handle_initrd();
89083 return 1;
89084 }
89085 }
89086 - sys_unlink("/initrd.image");
89087 + sys_unlink((const char __force_user *)"/initrd.image");
89088 return 0;
89089 }
89090 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
89091 index 8cb6db5..d729f50 100644
89092 --- a/init/do_mounts_md.c
89093 +++ b/init/do_mounts_md.c
89094 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
89095 partitioned ? "_d" : "", minor,
89096 md_setup_args[ent].device_names);
89097
89098 - fd = sys_open(name, 0, 0);
89099 + fd = sys_open((char __force_user *)name, 0, 0);
89100 if (fd < 0) {
89101 printk(KERN_ERR "md: open failed - cannot start "
89102 "array %s\n", name);
89103 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
89104 * array without it
89105 */
89106 sys_close(fd);
89107 - fd = sys_open(name, 0, 0);
89108 + fd = sys_open((char __force_user *)name, 0, 0);
89109 sys_ioctl(fd, BLKRRPART, 0);
89110 }
89111 sys_close(fd);
89112 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
89113
89114 wait_for_device_probe();
89115
89116 - fd = sys_open("/dev/md0", 0, 0);
89117 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
89118 if (fd >= 0) {
89119 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
89120 sys_close(fd);
89121 diff --git a/init/init_task.c b/init/init_task.c
89122 index ba0a7f36..2bcf1d5 100644
89123 --- a/init/init_task.c
89124 +++ b/init/init_task.c
89125 @@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
89126 * Initial thread structure. Alignment of this is handled by a special
89127 * linker map entry.
89128 */
89129 +#ifdef CONFIG_X86
89130 +union thread_union init_thread_union __init_task_data;
89131 +#else
89132 union thread_union init_thread_union __init_task_data =
89133 { INIT_THREAD_INFO(init_task) };
89134 +#endif
89135 diff --git a/init/initramfs.c b/init/initramfs.c
89136 index a8497fa..35b3c90 100644
89137 --- a/init/initramfs.c
89138 +++ b/init/initramfs.c
89139 @@ -84,7 +84,7 @@ static void __init free_hash(void)
89140 }
89141 }
89142
89143 -static long __init do_utime(char *filename, time_t mtime)
89144 +static long __init do_utime(char __force_user *filename, time_t mtime)
89145 {
89146 struct timespec t[2];
89147
89148 @@ -119,7 +119,7 @@ static void __init dir_utime(void)
89149 struct dir_entry *de, *tmp;
89150 list_for_each_entry_safe(de, tmp, &dir_list, list) {
89151 list_del(&de->list);
89152 - do_utime(de->name, de->mtime);
89153 + do_utime((char __force_user *)de->name, de->mtime);
89154 kfree(de->name);
89155 kfree(de);
89156 }
89157 @@ -281,7 +281,7 @@ static int __init maybe_link(void)
89158 if (nlink >= 2) {
89159 char *old = find_link(major, minor, ino, mode, collected);
89160 if (old)
89161 - return (sys_link(old, collected) < 0) ? -1 : 1;
89162 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
89163 }
89164 return 0;
89165 }
89166 @@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
89167 {
89168 struct stat st;
89169
89170 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
89171 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
89172 if (S_ISDIR(st.st_mode))
89173 - sys_rmdir(path);
89174 + sys_rmdir((char __force_user *)path);
89175 else
89176 - sys_unlink(path);
89177 + sys_unlink((char __force_user *)path);
89178 }
89179 }
89180
89181 @@ -315,7 +315,7 @@ static int __init do_name(void)
89182 int openflags = O_WRONLY|O_CREAT;
89183 if (ml != 1)
89184 openflags |= O_TRUNC;
89185 - wfd = sys_open(collected, openflags, mode);
89186 + wfd = sys_open((char __force_user *)collected, openflags, mode);
89187
89188 if (wfd >= 0) {
89189 sys_fchown(wfd, uid, gid);
89190 @@ -327,17 +327,17 @@ static int __init do_name(void)
89191 }
89192 }
89193 } else if (S_ISDIR(mode)) {
89194 - sys_mkdir(collected, mode);
89195 - sys_chown(collected, uid, gid);
89196 - sys_chmod(collected, mode);
89197 + sys_mkdir((char __force_user *)collected, mode);
89198 + sys_chown((char __force_user *)collected, uid, gid);
89199 + sys_chmod((char __force_user *)collected, mode);
89200 dir_add(collected, mtime);
89201 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
89202 S_ISFIFO(mode) || S_ISSOCK(mode)) {
89203 if (maybe_link() == 0) {
89204 - sys_mknod(collected, mode, rdev);
89205 - sys_chown(collected, uid, gid);
89206 - sys_chmod(collected, mode);
89207 - do_utime(collected, mtime);
89208 + sys_mknod((char __force_user *)collected, mode, rdev);
89209 + sys_chown((char __force_user *)collected, uid, gid);
89210 + sys_chmod((char __force_user *)collected, mode);
89211 + do_utime((char __force_user *)collected, mtime);
89212 }
89213 }
89214 return 0;
89215 @@ -346,15 +346,15 @@ static int __init do_name(void)
89216 static int __init do_copy(void)
89217 {
89218 if (count >= body_len) {
89219 - sys_write(wfd, victim, body_len);
89220 + sys_write(wfd, (char __force_user *)victim, body_len);
89221 sys_close(wfd);
89222 - do_utime(vcollected, mtime);
89223 + do_utime((char __force_user *)vcollected, mtime);
89224 kfree(vcollected);
89225 eat(body_len);
89226 state = SkipIt;
89227 return 0;
89228 } else {
89229 - sys_write(wfd, victim, count);
89230 + sys_write(wfd, (char __force_user *)victim, count);
89231 body_len -= count;
89232 eat(count);
89233 return 1;
89234 @@ -365,9 +365,9 @@ static int __init do_symlink(void)
89235 {
89236 collected[N_ALIGN(name_len) + body_len] = '\0';
89237 clean_path(collected, 0);
89238 - sys_symlink(collected + N_ALIGN(name_len), collected);
89239 - sys_lchown(collected, uid, gid);
89240 - do_utime(collected, mtime);
89241 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
89242 + sys_lchown((char __force_user *)collected, uid, gid);
89243 + do_utime((char __force_user *)collected, mtime);
89244 state = SkipIt;
89245 next_state = Reset;
89246 return 0;
89247 diff --git a/init/main.c b/init/main.c
89248 index e8ae1fe..f60f98c 100644
89249 --- a/init/main.c
89250 +++ b/init/main.c
89251 @@ -98,6 +98,8 @@ extern void radix_tree_init(void);
89252 static inline void mark_rodata_ro(void) { }
89253 #endif
89254
89255 +extern void grsecurity_init(void);
89256 +
89257 /*
89258 * Debug helper: via this flag we know that we are in 'early bootup code'
89259 * where only the boot processor is running with IRQ disabled. This means
89260 @@ -159,6 +161,75 @@ static int __init set_reset_devices(char *str)
89261
89262 __setup("reset_devices", set_reset_devices);
89263
89264 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
89265 +kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
89266 +static int __init setup_grsec_proc_gid(char *str)
89267 +{
89268 + grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
89269 + return 1;
89270 +}
89271 +__setup("grsec_proc_gid=", setup_grsec_proc_gid);
89272 +#endif
89273 +
89274 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
89275 +unsigned long pax_user_shadow_base __read_only;
89276 +EXPORT_SYMBOL(pax_user_shadow_base);
89277 +extern char pax_enter_kernel_user[];
89278 +extern char pax_exit_kernel_user[];
89279 +#endif
89280 +
89281 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
89282 +static int __init setup_pax_nouderef(char *str)
89283 +{
89284 +#ifdef CONFIG_X86_32
89285 + unsigned int cpu;
89286 + struct desc_struct *gdt;
89287 +
89288 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
89289 + gdt = get_cpu_gdt_table(cpu);
89290 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
89291 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
89292 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
89293 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
89294 + }
89295 + loadsegment(ds, __KERNEL_DS);
89296 + loadsegment(es, __KERNEL_DS);
89297 + loadsegment(ss, __KERNEL_DS);
89298 +#else
89299 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
89300 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
89301 + clone_pgd_mask = ~(pgdval_t)0UL;
89302 + pax_user_shadow_base = 0UL;
89303 + setup_clear_cpu_cap(X86_FEATURE_PCID);
89304 + setup_clear_cpu_cap(X86_FEATURE_INVPCID);
89305 +#endif
89306 +
89307 + return 0;
89308 +}
89309 +early_param("pax_nouderef", setup_pax_nouderef);
89310 +
89311 +#ifdef CONFIG_X86_64
89312 +static int __init setup_pax_weakuderef(char *str)
89313 +{
89314 + if (clone_pgd_mask != ~(pgdval_t)0UL)
89315 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
89316 + return 1;
89317 +}
89318 +__setup("pax_weakuderef", setup_pax_weakuderef);
89319 +#endif
89320 +#endif
89321 +
89322 +#ifdef CONFIG_PAX_SOFTMODE
89323 +int pax_softmode;
89324 +
89325 +static int __init setup_pax_softmode(char *str)
89326 +{
89327 + get_option(&str, &pax_softmode);
89328 + return 1;
89329 +}
89330 +__setup("pax_softmode=", setup_pax_softmode);
89331 +#endif
89332 +
89333 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
89334 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
89335 static const char *panic_later, *panic_param;
89336 @@ -727,7 +798,7 @@ static bool __init_or_module initcall_blacklisted(initcall_t fn)
89337 struct blacklist_entry *entry;
89338 char *fn_name;
89339
89340 - fn_name = kasprintf(GFP_KERNEL, "%pf", fn);
89341 + fn_name = kasprintf(GFP_KERNEL, "%pX", fn);
89342 if (!fn_name)
89343 return false;
89344
89345 @@ -779,7 +850,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
89346 {
89347 int count = preempt_count();
89348 int ret;
89349 - char msgbuf[64];
89350 + const char *msg1 = "", *msg2 = "";
89351
89352 if (initcall_blacklisted(fn))
89353 return -EPERM;
89354 @@ -789,18 +860,17 @@ int __init_or_module do_one_initcall(initcall_t fn)
89355 else
89356 ret = fn();
89357
89358 - msgbuf[0] = 0;
89359 -
89360 if (preempt_count() != count) {
89361 - sprintf(msgbuf, "preemption imbalance ");
89362 + msg1 = " preemption imbalance";
89363 preempt_count_set(count);
89364 }
89365 if (irqs_disabled()) {
89366 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
89367 + msg2 = " disabled interrupts";
89368 local_irq_enable();
89369 }
89370 - WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
89371 + WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
89372
89373 + add_latent_entropy();
89374 return ret;
89375 }
89376
89377 @@ -907,8 +977,8 @@ static int run_init_process(const char *init_filename)
89378 {
89379 argv_init[0] = init_filename;
89380 return do_execve(getname_kernel(init_filename),
89381 - (const char __user *const __user *)argv_init,
89382 - (const char __user *const __user *)envp_init);
89383 + (const char __user *const __force_user *)argv_init,
89384 + (const char __user *const __force_user *)envp_init);
89385 }
89386
89387 static int try_to_run_init_process(const char *init_filename)
89388 @@ -925,6 +995,10 @@ static int try_to_run_init_process(const char *init_filename)
89389 return ret;
89390 }
89391
89392 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
89393 +extern int gr_init_ran;
89394 +#endif
89395 +
89396 static noinline void __init kernel_init_freeable(void);
89397
89398 static int __ref kernel_init(void *unused)
89399 @@ -949,6 +1023,11 @@ static int __ref kernel_init(void *unused)
89400 ramdisk_execute_command, ret);
89401 }
89402
89403 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
89404 + /* if no initrd was used, be extra sure we enforce chroot restrictions */
89405 + gr_init_ran = 1;
89406 +#endif
89407 +
89408 /*
89409 * We try each of these until one succeeds.
89410 *
89411 @@ -1004,7 +1083,7 @@ static noinline void __init kernel_init_freeable(void)
89412 do_basic_setup();
89413
89414 /* Open the /dev/console on the rootfs, this should never fail */
89415 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
89416 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
89417 pr_err("Warning: unable to open an initial console.\n");
89418
89419 (void) sys_dup(0);
89420 @@ -1017,11 +1096,13 @@ static noinline void __init kernel_init_freeable(void)
89421 if (!ramdisk_execute_command)
89422 ramdisk_execute_command = "/init";
89423
89424 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
89425 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
89426 ramdisk_execute_command = NULL;
89427 prepare_namespace();
89428 }
89429
89430 + grsecurity_init();
89431 +
89432 /*
89433 * Ok, we have completed the initial bootup, and
89434 * we're essentially up and running. Get rid of the
89435 diff --git a/ipc/compat.c b/ipc/compat.c
89436 index b5ef4f7..ff31d87 100644
89437 --- a/ipc/compat.c
89438 +++ b/ipc/compat.c
89439 @@ -396,7 +396,7 @@ COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second,
89440 COMPAT_SHMLBA);
89441 if (err < 0)
89442 return err;
89443 - return put_user(raddr, (compat_ulong_t *)compat_ptr(third));
89444 + return put_user(raddr, (compat_ulong_t __user *)compat_ptr(third));
89445 }
89446 case SHMDT:
89447 return sys_shmdt(compat_ptr(ptr));
89448 diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
89449 index c3f0326..d4e0579 100644
89450 --- a/ipc/ipc_sysctl.c
89451 +++ b/ipc/ipc_sysctl.c
89452 @@ -30,7 +30,7 @@ static void *get_ipc(struct ctl_table *table)
89453 static int proc_ipc_dointvec(struct ctl_table *table, int write,
89454 void __user *buffer, size_t *lenp, loff_t *ppos)
89455 {
89456 - struct ctl_table ipc_table;
89457 + ctl_table_no_const ipc_table;
89458
89459 memcpy(&ipc_table, table, sizeof(ipc_table));
89460 ipc_table.data = get_ipc(table);
89461 @@ -41,7 +41,7 @@ static int proc_ipc_dointvec(struct ctl_table *table, int write,
89462 static int proc_ipc_dointvec_minmax(struct ctl_table *table, int write,
89463 void __user *buffer, size_t *lenp, loff_t *ppos)
89464 {
89465 - struct ctl_table ipc_table;
89466 + ctl_table_no_const ipc_table;
89467
89468 memcpy(&ipc_table, table, sizeof(ipc_table));
89469 ipc_table.data = get_ipc(table);
89470 @@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(struct ctl_table *table, int write,
89471 static int proc_ipc_callback_dointvec_minmax(struct ctl_table *table, int write,
89472 void __user *buffer, size_t *lenp, loff_t *ppos)
89473 {
89474 - struct ctl_table ipc_table;
89475 + ctl_table_no_const ipc_table;
89476 size_t lenp_bef = *lenp;
89477 int rc;
89478
89479 @@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec_minmax(struct ctl_table *table, int write,
89480 static int proc_ipc_doulongvec_minmax(struct ctl_table *table, int write,
89481 void __user *buffer, size_t *lenp, loff_t *ppos)
89482 {
89483 - struct ctl_table ipc_table;
89484 + ctl_table_no_const ipc_table;
89485 memcpy(&ipc_table, table, sizeof(ipc_table));
89486 ipc_table.data = get_ipc(table);
89487
89488 @@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
89489 static int proc_ipcauto_dointvec_minmax(struct ctl_table *table, int write,
89490 void __user *buffer, size_t *lenp, loff_t *ppos)
89491 {
89492 - struct ctl_table ipc_table;
89493 + ctl_table_no_const ipc_table;
89494 size_t lenp_bef = *lenp;
89495 int oldval;
89496 int rc;
89497 diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
89498 index 68d4e95..1477ded 100644
89499 --- a/ipc/mq_sysctl.c
89500 +++ b/ipc/mq_sysctl.c
89501 @@ -25,7 +25,7 @@ static void *get_mq(struct ctl_table *table)
89502 static int proc_mq_dointvec(struct ctl_table *table, int write,
89503 void __user *buffer, size_t *lenp, loff_t *ppos)
89504 {
89505 - struct ctl_table mq_table;
89506 + ctl_table_no_const mq_table;
89507 memcpy(&mq_table, table, sizeof(mq_table));
89508 mq_table.data = get_mq(table);
89509
89510 @@ -35,7 +35,7 @@ static int proc_mq_dointvec(struct ctl_table *table, int write,
89511 static int proc_mq_dointvec_minmax(struct ctl_table *table, int write,
89512 void __user *buffer, size_t *lenp, loff_t *ppos)
89513 {
89514 - struct ctl_table mq_table;
89515 + ctl_table_no_const mq_table;
89516 memcpy(&mq_table, table, sizeof(mq_table));
89517 mq_table.data = get_mq(table);
89518
89519 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
89520 index 4fcf39a..d3cc2ec 100644
89521 --- a/ipc/mqueue.c
89522 +++ b/ipc/mqueue.c
89523 @@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
89524 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
89525 info->attr.mq_msgsize);
89526
89527 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
89528 spin_lock(&mq_lock);
89529 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
89530 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
89531 diff --git a/ipc/shm.c b/ipc/shm.c
89532 index 89fc354..cf56786 100644
89533 --- a/ipc/shm.c
89534 +++ b/ipc/shm.c
89535 @@ -72,6 +72,14 @@ static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp);
89536 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
89537 #endif
89538
89539 +#ifdef CONFIG_GRKERNSEC
89540 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
89541 + const time_t shm_createtime, const kuid_t cuid,
89542 + const int shmid);
89543 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
89544 + const time_t shm_createtime);
89545 +#endif
89546 +
89547 void shm_init_ns(struct ipc_namespace *ns)
89548 {
89549 ns->shm_ctlmax = SHMMAX;
89550 @@ -557,6 +565,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
89551 shp->shm_lprid = 0;
89552 shp->shm_atim = shp->shm_dtim = 0;
89553 shp->shm_ctim = get_seconds();
89554 +#ifdef CONFIG_GRKERNSEC
89555 + {
89556 + struct timespec timeval;
89557 + do_posix_clock_monotonic_gettime(&timeval);
89558 +
89559 + shp->shm_createtime = timeval.tv_sec;
89560 + }
89561 +#endif
89562 shp->shm_segsz = size;
89563 shp->shm_nattch = 0;
89564 shp->shm_file = file;
89565 @@ -1092,6 +1108,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
89566 f_mode = FMODE_READ | FMODE_WRITE;
89567 }
89568 if (shmflg & SHM_EXEC) {
89569 +
89570 +#ifdef CONFIG_PAX_MPROTECT
89571 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
89572 + goto out;
89573 +#endif
89574 +
89575 prot |= PROT_EXEC;
89576 acc_mode |= S_IXUGO;
89577 }
89578 @@ -1116,6 +1138,15 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
89579 if (err)
89580 goto out_unlock;
89581
89582 +#ifdef CONFIG_GRKERNSEC
89583 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
89584 + shp->shm_perm.cuid, shmid) ||
89585 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
89586 + err = -EACCES;
89587 + goto out_unlock;
89588 + }
89589 +#endif
89590 +
89591 ipc_lock_object(&shp->shm_perm);
89592
89593 /* check if shm_destroy() is tearing down shp */
89594 @@ -1128,6 +1159,9 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
89595 path = shp->shm_file->f_path;
89596 path_get(&path);
89597 shp->shm_nattch++;
89598 +#ifdef CONFIG_GRKERNSEC
89599 + shp->shm_lapid = current->pid;
89600 +#endif
89601 size = i_size_read(path.dentry->d_inode);
89602 ipc_unlock_object(&shp->shm_perm);
89603 rcu_read_unlock();
89604 diff --git a/ipc/util.c b/ipc/util.c
89605 index 27d74e6..8be0be2 100644
89606 --- a/ipc/util.c
89607 +++ b/ipc/util.c
89608 @@ -71,6 +71,8 @@ struct ipc_proc_iface {
89609 int (*show)(struct seq_file *, void *);
89610 };
89611
89612 +extern int gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode);
89613 +
89614 static void ipc_memory_notifier(struct work_struct *work)
89615 {
89616 ipcns_notify(IPCNS_MEMCHANGED);
89617 @@ -537,6 +539,10 @@ int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flag)
89618 granted_mode >>= 6;
89619 else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
89620 granted_mode >>= 3;
89621 +
89622 + if (!gr_ipc_permitted(ns, ipcp, requested_mode, granted_mode))
89623 + return -1;
89624 +
89625 /* is there some bit set in requested_mode but not in granted_mode? */
89626 if ((requested_mode & ~granted_mode & 0007) &&
89627 !ns_capable(ns->user_ns, CAP_IPC_OWNER))
89628 diff --git a/kernel/acct.c b/kernel/acct.c
89629 index 808a86f..da69695 100644
89630 --- a/kernel/acct.c
89631 +++ b/kernel/acct.c
89632 @@ -556,7 +556,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
89633 */
89634 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
89635 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
89636 - file->f_op->write(file, (char *)&ac,
89637 + file->f_op->write(file, (char __force_user *)&ac,
89638 sizeof(acct_t), &file->f_pos);
89639 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
89640 set_fs(fs);
89641 diff --git a/kernel/audit.c b/kernel/audit.c
89642 index 3ef2e0e..8873765 100644
89643 --- a/kernel/audit.c
89644 +++ b/kernel/audit.c
89645 @@ -122,7 +122,7 @@ u32 audit_sig_sid = 0;
89646 3) suppressed due to audit_rate_limit
89647 4) suppressed due to audit_backlog_limit
89648 */
89649 -static atomic_t audit_lost = ATOMIC_INIT(0);
89650 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
89651
89652 /* The netlink socket. */
89653 static struct sock *audit_sock;
89654 @@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
89655 unsigned long now;
89656 int print;
89657
89658 - atomic_inc(&audit_lost);
89659 + atomic_inc_unchecked(&audit_lost);
89660
89661 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
89662
89663 @@ -273,7 +273,7 @@ void audit_log_lost(const char *message)
89664 if (print) {
89665 if (printk_ratelimit())
89666 pr_warn("audit_lost=%u audit_rate_limit=%u audit_backlog_limit=%u\n",
89667 - atomic_read(&audit_lost),
89668 + atomic_read_unchecked(&audit_lost),
89669 audit_rate_limit,
89670 audit_backlog_limit);
89671 audit_panic(message);
89672 @@ -840,7 +840,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
89673 s.pid = audit_pid;
89674 s.rate_limit = audit_rate_limit;
89675 s.backlog_limit = audit_backlog_limit;
89676 - s.lost = atomic_read(&audit_lost);
89677 + s.lost = atomic_read_unchecked(&audit_lost);
89678 s.backlog = skb_queue_len(&audit_skb_queue);
89679 s.version = AUDIT_VERSION_LATEST;
89680 s.backlog_wait_time = audit_backlog_wait_time;
89681 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
89682 index 21eae3c..66db239 100644
89683 --- a/kernel/auditsc.c
89684 +++ b/kernel/auditsc.c
89685 @@ -2023,7 +2023,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
89686 }
89687
89688 /* global counter which is incremented every time something logs in */
89689 -static atomic_t session_id = ATOMIC_INIT(0);
89690 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
89691
89692 static int audit_set_loginuid_perm(kuid_t loginuid)
89693 {
89694 @@ -2090,7 +2090,7 @@ int audit_set_loginuid(kuid_t loginuid)
89695
89696 /* are we setting or clearing? */
89697 if (uid_valid(loginuid))
89698 - sessionid = (unsigned int)atomic_inc_return(&session_id);
89699 + sessionid = (unsigned int)atomic_inc_return_unchecked(&session_id);
89700
89701 task->sessionid = sessionid;
89702 task->loginuid = loginuid;
89703 diff --git a/kernel/capability.c b/kernel/capability.c
89704 index a5cf13c..07a2647 100644
89705 --- a/kernel/capability.c
89706 +++ b/kernel/capability.c
89707 @@ -192,6 +192,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
89708 * before modification is attempted and the application
89709 * fails.
89710 */
89711 + if (tocopy > ARRAY_SIZE(kdata))
89712 + return -EFAULT;
89713 +
89714 if (copy_to_user(dataptr, kdata, tocopy
89715 * sizeof(struct __user_cap_data_struct))) {
89716 return -EFAULT;
89717 @@ -293,10 +296,11 @@ bool has_ns_capability(struct task_struct *t,
89718 int ret;
89719
89720 rcu_read_lock();
89721 - ret = security_capable(__task_cred(t), ns, cap);
89722 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
89723 + gr_task_is_capable(t, __task_cred(t), cap);
89724 rcu_read_unlock();
89725
89726 - return (ret == 0);
89727 + return ret;
89728 }
89729
89730 /**
89731 @@ -333,10 +337,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
89732 int ret;
89733
89734 rcu_read_lock();
89735 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
89736 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
89737 rcu_read_unlock();
89738
89739 - return (ret == 0);
89740 + return ret;
89741 }
89742
89743 /**
89744 @@ -374,7 +378,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
89745 BUG();
89746 }
89747
89748 - if (security_capable(current_cred(), ns, cap) == 0) {
89749 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
89750 current->flags |= PF_SUPERPRIV;
89751 return true;
89752 }
89753 @@ -382,6 +386,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
89754 }
89755 EXPORT_SYMBOL(ns_capable);
89756
89757 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
89758 +{
89759 + if (unlikely(!cap_valid(cap))) {
89760 + printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
89761 + BUG();
89762 + }
89763 +
89764 + if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
89765 + current->flags |= PF_SUPERPRIV;
89766 + return true;
89767 + }
89768 + return false;
89769 +}
89770 +EXPORT_SYMBOL(ns_capable_nolog);
89771 +
89772 /**
89773 * file_ns_capable - Determine if the file's opener had a capability in effect
89774 * @file: The file we want to check
89775 @@ -423,6 +442,12 @@ bool capable(int cap)
89776 }
89777 EXPORT_SYMBOL(capable);
89778
89779 +bool capable_nolog(int cap)
89780 +{
89781 + return ns_capable_nolog(&init_user_ns, cap);
89782 +}
89783 +EXPORT_SYMBOL(capable_nolog);
89784 +
89785 /**
89786 * capable_wrt_inode_uidgid - Check nsown_capable and uid and gid mapped
89787 * @inode: The inode in question
89788 @@ -440,3 +465,12 @@ bool capable_wrt_inode_uidgid(const struct inode *inode, int cap)
89789 kgid_has_mapping(ns, inode->i_gid);
89790 }
89791 EXPORT_SYMBOL(capable_wrt_inode_uidgid);
89792 +
89793 +bool capable_wrt_inode_uidgid_nolog(const struct inode *inode, int cap)
89794 +{
89795 + struct user_namespace *ns = current_user_ns();
89796 +
89797 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid) &&
89798 + kgid_has_mapping(ns, inode->i_gid);
89799 +}
89800 +EXPORT_SYMBOL(capable_wrt_inode_uidgid_nolog);
89801 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
89802 index 70776ae..09c4988 100644
89803 --- a/kernel/cgroup.c
89804 +++ b/kernel/cgroup.c
89805 @@ -5146,6 +5146,14 @@ static void cgroup_release_agent(struct work_struct *work)
89806 release_list);
89807 list_del_init(&cgrp->release_list);
89808 raw_spin_unlock(&release_list_lock);
89809 +
89810 + /*
89811 + * don't bother calling call_usermodehelper if we haven't
89812 + * configured a binary to execute
89813 + */
89814 + if (cgrp->root->release_agent_path[0] == '\0')
89815 + goto continue_free;
89816 +
89817 pathbuf = kmalloc(PATH_MAX, GFP_KERNEL);
89818 if (!pathbuf)
89819 goto continue_free;
89820 @@ -5336,7 +5344,7 @@ static int cgroup_css_links_read(struct seq_file *seq, void *v)
89821 struct task_struct *task;
89822 int count = 0;
89823
89824 - seq_printf(seq, "css_set %p\n", cset);
89825 + seq_printf(seq, "css_set %pK\n", cset);
89826
89827 list_for_each_entry(task, &cset->tasks, cg_list) {
89828 if (count++ > MAX_TASKS_SHOWN_PER_CSS)
89829 diff --git a/kernel/compat.c b/kernel/compat.c
89830 index 633394f..bdfa969 100644
89831 --- a/kernel/compat.c
89832 +++ b/kernel/compat.c
89833 @@ -13,6 +13,7 @@
89834
89835 #include <linux/linkage.h>
89836 #include <linux/compat.h>
89837 +#include <linux/module.h>
89838 #include <linux/errno.h>
89839 #include <linux/time.h>
89840 #include <linux/signal.h>
89841 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
89842 mm_segment_t oldfs;
89843 long ret;
89844
89845 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
89846 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
89847 oldfs = get_fs();
89848 set_fs(KERNEL_DS);
89849 ret = hrtimer_nanosleep_restart(restart);
89850 @@ -252,7 +253,7 @@ COMPAT_SYSCALL_DEFINE2(nanosleep, struct compat_timespec __user *, rqtp,
89851 oldfs = get_fs();
89852 set_fs(KERNEL_DS);
89853 ret = hrtimer_nanosleep(&tu,
89854 - rmtp ? (struct timespec __user *)&rmt : NULL,
89855 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
89856 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
89857 set_fs(oldfs);
89858
89859 @@ -361,7 +362,7 @@ COMPAT_SYSCALL_DEFINE1(sigpending, compat_old_sigset_t __user *, set)
89860 mm_segment_t old_fs = get_fs();
89861
89862 set_fs(KERNEL_DS);
89863 - ret = sys_sigpending((old_sigset_t __user *) &s);
89864 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
89865 set_fs(old_fs);
89866 if (ret == 0)
89867 ret = put_user(s, set);
89868 @@ -451,7 +452,7 @@ COMPAT_SYSCALL_DEFINE2(old_getrlimit, unsigned int, resource,
89869 mm_segment_t old_fs = get_fs();
89870
89871 set_fs(KERNEL_DS);
89872 - ret = sys_old_getrlimit(resource, (struct rlimit __user *)&r);
89873 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
89874 set_fs(old_fs);
89875
89876 if (!ret) {
89877 @@ -533,8 +534,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
89878 set_fs (KERNEL_DS);
89879 ret = sys_wait4(pid,
89880 (stat_addr ?
89881 - (unsigned int __user *) &status : NULL),
89882 - options, (struct rusage __user *) &r);
89883 + (unsigned int __force_user *) &status : NULL),
89884 + options, (struct rusage __force_user *) &r);
89885 set_fs (old_fs);
89886
89887 if (ret > 0) {
89888 @@ -560,8 +561,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
89889 memset(&info, 0, sizeof(info));
89890
89891 set_fs(KERNEL_DS);
89892 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
89893 - uru ? (struct rusage __user *)&ru : NULL);
89894 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
89895 + uru ? (struct rusage __force_user *)&ru : NULL);
89896 set_fs(old_fs);
89897
89898 if ((ret < 0) || (info.si_signo == 0))
89899 @@ -695,8 +696,8 @@ COMPAT_SYSCALL_DEFINE4(timer_settime, timer_t, timer_id, int, flags,
89900 oldfs = get_fs();
89901 set_fs(KERNEL_DS);
89902 err = sys_timer_settime(timer_id, flags,
89903 - (struct itimerspec __user *) &newts,
89904 - (struct itimerspec __user *) &oldts);
89905 + (struct itimerspec __force_user *) &newts,
89906 + (struct itimerspec __force_user *) &oldts);
89907 set_fs(oldfs);
89908 if (!err && old && put_compat_itimerspec(old, &oldts))
89909 return -EFAULT;
89910 @@ -713,7 +714,7 @@ COMPAT_SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id,
89911 oldfs = get_fs();
89912 set_fs(KERNEL_DS);
89913 err = sys_timer_gettime(timer_id,
89914 - (struct itimerspec __user *) &ts);
89915 + (struct itimerspec __force_user *) &ts);
89916 set_fs(oldfs);
89917 if (!err && put_compat_itimerspec(setting, &ts))
89918 return -EFAULT;
89919 @@ -732,7 +733,7 @@ COMPAT_SYSCALL_DEFINE2(clock_settime, clockid_t, which_clock,
89920 oldfs = get_fs();
89921 set_fs(KERNEL_DS);
89922 err = sys_clock_settime(which_clock,
89923 - (struct timespec __user *) &ts);
89924 + (struct timespec __force_user *) &ts);
89925 set_fs(oldfs);
89926 return err;
89927 }
89928 @@ -747,7 +748,7 @@ COMPAT_SYSCALL_DEFINE2(clock_gettime, clockid_t, which_clock,
89929 oldfs = get_fs();
89930 set_fs(KERNEL_DS);
89931 err = sys_clock_gettime(which_clock,
89932 - (struct timespec __user *) &ts);
89933 + (struct timespec __force_user *) &ts);
89934 set_fs(oldfs);
89935 if (!err && compat_put_timespec(&ts, tp))
89936 return -EFAULT;
89937 @@ -767,7 +768,7 @@ COMPAT_SYSCALL_DEFINE2(clock_adjtime, clockid_t, which_clock,
89938
89939 oldfs = get_fs();
89940 set_fs(KERNEL_DS);
89941 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
89942 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
89943 set_fs(oldfs);
89944
89945 err = compat_put_timex(utp, &txc);
89946 @@ -787,7 +788,7 @@ COMPAT_SYSCALL_DEFINE2(clock_getres, clockid_t, which_clock,
89947 oldfs = get_fs();
89948 set_fs(KERNEL_DS);
89949 err = sys_clock_getres(which_clock,
89950 - (struct timespec __user *) &ts);
89951 + (struct timespec __force_user *) &ts);
89952 set_fs(oldfs);
89953 if (!err && tp && compat_put_timespec(&ts, tp))
89954 return -EFAULT;
89955 @@ -801,7 +802,7 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
89956 struct timespec tu;
89957 struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
89958
89959 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
89960 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
89961 oldfs = get_fs();
89962 set_fs(KERNEL_DS);
89963 err = clock_nanosleep_restart(restart);
89964 @@ -833,8 +834,8 @@ COMPAT_SYSCALL_DEFINE4(clock_nanosleep, clockid_t, which_clock, int, flags,
89965 oldfs = get_fs();
89966 set_fs(KERNEL_DS);
89967 err = sys_clock_nanosleep(which_clock, flags,
89968 - (struct timespec __user *) &in,
89969 - (struct timespec __user *) &out);
89970 + (struct timespec __force_user *) &in,
89971 + (struct timespec __force_user *) &out);
89972 set_fs(oldfs);
89973
89974 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
89975 @@ -1128,7 +1129,7 @@ COMPAT_SYSCALL_DEFINE2(sched_rr_get_interval,
89976 mm_segment_t old_fs = get_fs();
89977
89978 set_fs(KERNEL_DS);
89979 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
89980 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
89981 set_fs(old_fs);
89982 if (compat_put_timespec(&t, interval))
89983 return -EFAULT;
89984 diff --git a/kernel/configs.c b/kernel/configs.c
89985 index c18b1f1..b9a0132 100644
89986 --- a/kernel/configs.c
89987 +++ b/kernel/configs.c
89988 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
89989 struct proc_dir_entry *entry;
89990
89991 /* create the current config file */
89992 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
89993 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
89994 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
89995 + &ikconfig_file_ops);
89996 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
89997 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
89998 + &ikconfig_file_ops);
89999 +#endif
90000 +#else
90001 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
90002 &ikconfig_file_ops);
90003 +#endif
90004 +
90005 if (!entry)
90006 return -ENOMEM;
90007
90008 diff --git a/kernel/cred.c b/kernel/cred.c
90009 index e0573a4..26c0fd3 100644
90010 --- a/kernel/cred.c
90011 +++ b/kernel/cred.c
90012 @@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
90013 validate_creds(cred);
90014 alter_cred_subscribers(cred, -1);
90015 put_cred(cred);
90016 +
90017 +#ifdef CONFIG_GRKERNSEC_SETXID
90018 + cred = (struct cred *) tsk->delayed_cred;
90019 + if (cred != NULL) {
90020 + tsk->delayed_cred = NULL;
90021 + validate_creds(cred);
90022 + alter_cred_subscribers(cred, -1);
90023 + put_cred(cred);
90024 + }
90025 +#endif
90026 }
90027
90028 /**
90029 @@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
90030 * Always returns 0 thus allowing this function to be tail-called at the end
90031 * of, say, sys_setgid().
90032 */
90033 -int commit_creds(struct cred *new)
90034 +static int __commit_creds(struct cred *new)
90035 {
90036 struct task_struct *task = current;
90037 const struct cred *old = task->real_cred;
90038 @@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
90039
90040 get_cred(new); /* we will require a ref for the subj creds too */
90041
90042 + gr_set_role_label(task, new->uid, new->gid);
90043 +
90044 /* dumpability changes */
90045 if (!uid_eq(old->euid, new->euid) ||
90046 !gid_eq(old->egid, new->egid) ||
90047 @@ -479,6 +491,105 @@ int commit_creds(struct cred *new)
90048 put_cred(old);
90049 return 0;
90050 }
90051 +#ifdef CONFIG_GRKERNSEC_SETXID
90052 +extern int set_user(struct cred *new);
90053 +
90054 +void gr_delayed_cred_worker(void)
90055 +{
90056 + const struct cred *new = current->delayed_cred;
90057 + struct cred *ncred;
90058 +
90059 + current->delayed_cred = NULL;
90060 +
90061 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
90062 + // from doing get_cred on it when queueing this
90063 + put_cred(new);
90064 + return;
90065 + } else if (new == NULL)
90066 + return;
90067 +
90068 + ncred = prepare_creds();
90069 + if (!ncred)
90070 + goto die;
90071 + // uids
90072 + ncred->uid = new->uid;
90073 + ncred->euid = new->euid;
90074 + ncred->suid = new->suid;
90075 + ncred->fsuid = new->fsuid;
90076 + // gids
90077 + ncred->gid = new->gid;
90078 + ncred->egid = new->egid;
90079 + ncred->sgid = new->sgid;
90080 + ncred->fsgid = new->fsgid;
90081 + // groups
90082 + set_groups(ncred, new->group_info);
90083 + // caps
90084 + ncred->securebits = new->securebits;
90085 + ncred->cap_inheritable = new->cap_inheritable;
90086 + ncred->cap_permitted = new->cap_permitted;
90087 + ncred->cap_effective = new->cap_effective;
90088 + ncred->cap_bset = new->cap_bset;
90089 +
90090 + if (set_user(ncred)) {
90091 + abort_creds(ncred);
90092 + goto die;
90093 + }
90094 +
90095 + // from doing get_cred on it when queueing this
90096 + put_cred(new);
90097 +
90098 + __commit_creds(ncred);
90099 + return;
90100 +die:
90101 + // from doing get_cred on it when queueing this
90102 + put_cred(new);
90103 + do_group_exit(SIGKILL);
90104 +}
90105 +#endif
90106 +
90107 +int commit_creds(struct cred *new)
90108 +{
90109 +#ifdef CONFIG_GRKERNSEC_SETXID
90110 + int ret;
90111 + int schedule_it = 0;
90112 + struct task_struct *t;
90113 + unsigned oldsecurebits = current_cred()->securebits;
90114 +
90115 + /* we won't get called with tasklist_lock held for writing
90116 + and interrupts disabled as the cred struct in that case is
90117 + init_cred
90118 + */
90119 + if (grsec_enable_setxid && !current_is_single_threaded() &&
90120 + uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
90121 + !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
90122 + schedule_it = 1;
90123 + }
90124 + ret = __commit_creds(new);
90125 + if (schedule_it) {
90126 + rcu_read_lock();
90127 + read_lock(&tasklist_lock);
90128 + for (t = next_thread(current); t != current;
90129 + t = next_thread(t)) {
90130 + /* we'll check if the thread has uid 0 in
90131 + * the delayed worker routine
90132 + */
90133 + if (task_securebits(t) == oldsecurebits &&
90134 + t->delayed_cred == NULL) {
90135 + t->delayed_cred = get_cred(new);
90136 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
90137 + set_tsk_need_resched(t);
90138 + }
90139 + }
90140 + read_unlock(&tasklist_lock);
90141 + rcu_read_unlock();
90142 + }
90143 +
90144 + return ret;
90145 +#else
90146 + return __commit_creds(new);
90147 +#endif
90148 +}
90149 +
90150 EXPORT_SYMBOL(commit_creds);
90151
90152 /**
90153 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
90154 index 1adf62b..7736e06 100644
90155 --- a/kernel/debug/debug_core.c
90156 +++ b/kernel/debug/debug_core.c
90157 @@ -124,7 +124,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
90158 */
90159 static atomic_t masters_in_kgdb;
90160 static atomic_t slaves_in_kgdb;
90161 -static atomic_t kgdb_break_tasklet_var;
90162 +static atomic_unchecked_t kgdb_break_tasklet_var;
90163 atomic_t kgdb_setting_breakpoint;
90164
90165 struct task_struct *kgdb_usethread;
90166 @@ -134,7 +134,7 @@ int kgdb_single_step;
90167 static pid_t kgdb_sstep_pid;
90168
90169 /* to keep track of the CPU which is doing the single stepping*/
90170 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
90171 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
90172
90173 /*
90174 * If you are debugging a problem where roundup (the collection of
90175 @@ -549,7 +549,7 @@ return_normal:
90176 * kernel will only try for the value of sstep_tries before
90177 * giving up and continuing on.
90178 */
90179 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
90180 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
90181 (kgdb_info[cpu].task &&
90182 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
90183 atomic_set(&kgdb_active, -1);
90184 @@ -647,8 +647,8 @@ cpu_master_loop:
90185 }
90186
90187 kgdb_restore:
90188 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
90189 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
90190 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
90191 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
90192 if (kgdb_info[sstep_cpu].task)
90193 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
90194 else
90195 @@ -925,18 +925,18 @@ static void kgdb_unregister_callbacks(void)
90196 static void kgdb_tasklet_bpt(unsigned long ing)
90197 {
90198 kgdb_breakpoint();
90199 - atomic_set(&kgdb_break_tasklet_var, 0);
90200 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
90201 }
90202
90203 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
90204
90205 void kgdb_schedule_breakpoint(void)
90206 {
90207 - if (atomic_read(&kgdb_break_tasklet_var) ||
90208 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
90209 atomic_read(&kgdb_active) != -1 ||
90210 atomic_read(&kgdb_setting_breakpoint))
90211 return;
90212 - atomic_inc(&kgdb_break_tasklet_var);
90213 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
90214 tasklet_schedule(&kgdb_tasklet_breakpoint);
90215 }
90216 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
90217 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
90218 index 2f7c760..95b6a66 100644
90219 --- a/kernel/debug/kdb/kdb_main.c
90220 +++ b/kernel/debug/kdb/kdb_main.c
90221 @@ -1977,7 +1977,7 @@ static int kdb_lsmod(int argc, const char **argv)
90222 continue;
90223
90224 kdb_printf("%-20s%8u 0x%p ", mod->name,
90225 - mod->core_size, (void *)mod);
90226 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
90227 #ifdef CONFIG_MODULE_UNLOAD
90228 kdb_printf("%4ld ", module_refcount(mod));
90229 #endif
90230 @@ -1987,7 +1987,7 @@ static int kdb_lsmod(int argc, const char **argv)
90231 kdb_printf(" (Loading)");
90232 else
90233 kdb_printf(" (Live)");
90234 - kdb_printf(" 0x%p", mod->module_core);
90235 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
90236
90237 #ifdef CONFIG_MODULE_UNLOAD
90238 {
90239 diff --git a/kernel/events/core.c b/kernel/events/core.c
90240 index 6b17ac1..00fd505 100644
90241 --- a/kernel/events/core.c
90242 +++ b/kernel/events/core.c
90243 @@ -160,8 +160,15 @@ static struct srcu_struct pmus_srcu;
90244 * 0 - disallow raw tracepoint access for unpriv
90245 * 1 - disallow cpu events for unpriv
90246 * 2 - disallow kernel profiling for unpriv
90247 + * 3 - disallow all unpriv perf event use
90248 */
90249 -int sysctl_perf_event_paranoid __read_mostly = 1;
90250 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
90251 +int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
90252 +#elif defined(CONFIG_GRKERNSEC_HIDESYM)
90253 +int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
90254 +#else
90255 +int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
90256 +#endif
90257
90258 /* Minimum for 512 kiB + 1 user control page */
90259 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
90260 @@ -187,7 +194,7 @@ void update_perf_cpu_limits(void)
90261
90262 tmp *= sysctl_perf_cpu_time_max_percent;
90263 do_div(tmp, 100);
90264 - ACCESS_ONCE(perf_sample_allowed_ns) = tmp;
90265 + ACCESS_ONCE_RW(perf_sample_allowed_ns) = tmp;
90266 }
90267
90268 static int perf_rotate_context(struct perf_cpu_context *cpuctx);
90269 @@ -293,7 +300,7 @@ void perf_sample_event_took(u64 sample_len_ns)
90270 }
90271 }
90272
90273 -static atomic64_t perf_event_id;
90274 +static atomic64_unchecked_t perf_event_id;
90275
90276 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
90277 enum event_type_t event_type);
90278 @@ -3023,7 +3030,7 @@ static void __perf_event_read(void *info)
90279
90280 static inline u64 perf_event_count(struct perf_event *event)
90281 {
90282 - return local64_read(&event->count) + atomic64_read(&event->child_count);
90283 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
90284 }
90285
90286 static u64 perf_event_read(struct perf_event *event)
90287 @@ -3399,9 +3406,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
90288 mutex_lock(&event->child_mutex);
90289 total += perf_event_read(event);
90290 *enabled += event->total_time_enabled +
90291 - atomic64_read(&event->child_total_time_enabled);
90292 + atomic64_read_unchecked(&event->child_total_time_enabled);
90293 *running += event->total_time_running +
90294 - atomic64_read(&event->child_total_time_running);
90295 + atomic64_read_unchecked(&event->child_total_time_running);
90296
90297 list_for_each_entry(child, &event->child_list, child_list) {
90298 total += perf_event_read(child);
90299 @@ -3830,10 +3837,10 @@ void perf_event_update_userpage(struct perf_event *event)
90300 userpg->offset -= local64_read(&event->hw.prev_count);
90301
90302 userpg->time_enabled = enabled +
90303 - atomic64_read(&event->child_total_time_enabled);
90304 + atomic64_read_unchecked(&event->child_total_time_enabled);
90305
90306 userpg->time_running = running +
90307 - atomic64_read(&event->child_total_time_running);
90308 + atomic64_read_unchecked(&event->child_total_time_running);
90309
90310 arch_perf_update_userpage(userpg, now);
90311
90312 @@ -4397,7 +4404,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
90313
90314 /* Data. */
90315 sp = perf_user_stack_pointer(regs);
90316 - rem = __output_copy_user(handle, (void *) sp, dump_size);
90317 + rem = __output_copy_user(handle, (void __user *) sp, dump_size);
90318 dyn_size = dump_size - rem;
90319
90320 perf_output_skip(handle, rem);
90321 @@ -4488,11 +4495,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
90322 values[n++] = perf_event_count(event);
90323 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
90324 values[n++] = enabled +
90325 - atomic64_read(&event->child_total_time_enabled);
90326 + atomic64_read_unchecked(&event->child_total_time_enabled);
90327 }
90328 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
90329 values[n++] = running +
90330 - atomic64_read(&event->child_total_time_running);
90331 + atomic64_read_unchecked(&event->child_total_time_running);
90332 }
90333 if (read_format & PERF_FORMAT_ID)
90334 values[n++] = primary_event_id(event);
90335 @@ -6801,7 +6808,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
90336 event->parent = parent_event;
90337
90338 event->ns = get_pid_ns(task_active_pid_ns(current));
90339 - event->id = atomic64_inc_return(&perf_event_id);
90340 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
90341
90342 event->state = PERF_EVENT_STATE_INACTIVE;
90343
90344 @@ -7080,6 +7087,11 @@ SYSCALL_DEFINE5(perf_event_open,
90345 if (flags & ~PERF_FLAG_ALL)
90346 return -EINVAL;
90347
90348 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
90349 + if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
90350 + return -EACCES;
90351 +#endif
90352 +
90353 err = perf_copy_attr(attr_uptr, &attr);
90354 if (err)
90355 return err;
90356 @@ -7432,10 +7444,10 @@ static void sync_child_event(struct perf_event *child_event,
90357 /*
90358 * Add back the child's count to the parent's count:
90359 */
90360 - atomic64_add(child_val, &parent_event->child_count);
90361 - atomic64_add(child_event->total_time_enabled,
90362 + atomic64_add_unchecked(child_val, &parent_event->child_count);
90363 + atomic64_add_unchecked(child_event->total_time_enabled,
90364 &parent_event->child_total_time_enabled);
90365 - atomic64_add(child_event->total_time_running,
90366 + atomic64_add_unchecked(child_event->total_time_running,
90367 &parent_event->child_total_time_running);
90368
90369 /*
90370 diff --git a/kernel/events/internal.h b/kernel/events/internal.h
90371 index 569b2187..19940d9 100644
90372 --- a/kernel/events/internal.h
90373 +++ b/kernel/events/internal.h
90374 @@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
90375 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
90376 }
90377
90378 -#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
90379 +#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
90380 static inline unsigned long \
90381 func_name(struct perf_output_handle *handle, \
90382 - const void *buf, unsigned long len) \
90383 + const void user *buf, unsigned long len) \
90384 { \
90385 unsigned long size, written; \
90386 \
90387 @@ -117,7 +117,7 @@ memcpy_common(void *dst, const void *src, unsigned long n)
90388 return 0;
90389 }
90390
90391 -DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
90392 +DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
90393
90394 static inline unsigned long
90395 memcpy_skip(void *dst, const void *src, unsigned long n)
90396 @@ -125,7 +125,7 @@ memcpy_skip(void *dst, const void *src, unsigned long n)
90397 return 0;
90398 }
90399
90400 -DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip)
90401 +DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip, )
90402
90403 #ifndef arch_perf_out_copy_user
90404 #define arch_perf_out_copy_user arch_perf_out_copy_user
90405 @@ -143,7 +143,7 @@ arch_perf_out_copy_user(void *dst, const void *src, unsigned long n)
90406 }
90407 #endif
90408
90409 -DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
90410 +DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
90411
90412 /* Callchain handling */
90413 extern struct perf_callchain_entry *
90414 diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
90415 index 6f3254e..e4c1fe4 100644
90416 --- a/kernel/events/uprobes.c
90417 +++ b/kernel/events/uprobes.c
90418 @@ -1670,7 +1670,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
90419 {
90420 struct page *page;
90421 uprobe_opcode_t opcode;
90422 - int result;
90423 + long result;
90424
90425 pagefault_disable();
90426 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
90427 diff --git a/kernel/exit.c b/kernel/exit.c
90428 index e5c4668..592d2e5 100644
90429 --- a/kernel/exit.c
90430 +++ b/kernel/exit.c
90431 @@ -173,6 +173,10 @@ void release_task(struct task_struct * p)
90432 struct task_struct *leader;
90433 int zap_leader;
90434 repeat:
90435 +#ifdef CONFIG_NET
90436 + gr_del_task_from_ip_table(p);
90437 +#endif
90438 +
90439 /* don't need to get the RCU readlock here - the process is dead and
90440 * can't be modifying its own credentials. But shut RCU-lockdep up */
90441 rcu_read_lock();
90442 @@ -664,6 +668,8 @@ void do_exit(long code)
90443 struct task_struct *tsk = current;
90444 int group_dead;
90445
90446 + set_fs(USER_DS);
90447 +
90448 profile_task_exit(tsk);
90449
90450 WARN_ON(blk_needs_flush_plug(tsk));
90451 @@ -680,7 +686,6 @@ void do_exit(long code)
90452 * mm_release()->clear_child_tid() from writing to a user-controlled
90453 * kernel address.
90454 */
90455 - set_fs(USER_DS);
90456
90457 ptrace_event(PTRACE_EVENT_EXIT, code);
90458
90459 @@ -739,6 +744,9 @@ void do_exit(long code)
90460 tsk->exit_code = code;
90461 taskstats_exit(tsk, group_dead);
90462
90463 + gr_acl_handle_psacct(tsk, code);
90464 + gr_acl_handle_exit();
90465 +
90466 exit_mm(tsk);
90467
90468 if (group_dead)
90469 @@ -858,7 +866,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
90470 * Take down every thread in the group. This is called by fatal signals
90471 * as well as by sys_exit_group (below).
90472 */
90473 -void
90474 +__noreturn void
90475 do_group_exit(int exit_code)
90476 {
90477 struct signal_struct *sig = current->signal;
90478 diff --git a/kernel/fork.c b/kernel/fork.c
90479 index 6a13c46..a623c8e 100644
90480 --- a/kernel/fork.c
90481 +++ b/kernel/fork.c
90482 @@ -183,6 +183,48 @@ void thread_info_cache_init(void)
90483 # endif
90484 #endif
90485
90486 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
90487 +static inline struct thread_info *gr_alloc_thread_info_node(struct task_struct *tsk,
90488 + int node, void **lowmem_stack)
90489 +{
90490 + struct page *pages[THREAD_SIZE / PAGE_SIZE];
90491 + void *ret = NULL;
90492 + unsigned int i;
90493 +
90494 + *lowmem_stack = alloc_thread_info_node(tsk, node);
90495 + if (*lowmem_stack == NULL)
90496 + goto out;
90497 +
90498 + for (i = 0; i < THREAD_SIZE / PAGE_SIZE; i++)
90499 + pages[i] = virt_to_page(*lowmem_stack + (i * PAGE_SIZE));
90500 +
90501 + /* use VM_IOREMAP to gain THREAD_SIZE alignment */
90502 + ret = vmap(pages, THREAD_SIZE / PAGE_SIZE, VM_IOREMAP, PAGE_KERNEL);
90503 + if (ret == NULL) {
90504 + free_thread_info(*lowmem_stack);
90505 + *lowmem_stack = NULL;
90506 + }
90507 +
90508 +out:
90509 + return ret;
90510 +}
90511 +
90512 +static inline void gr_free_thread_info(struct task_struct *tsk, struct thread_info *ti)
90513 +{
90514 + unmap_process_stacks(tsk);
90515 +}
90516 +#else
90517 +static inline struct thread_info *gr_alloc_thread_info_node(struct task_struct *tsk,
90518 + int node, void **lowmem_stack)
90519 +{
90520 + return alloc_thread_info_node(tsk, node);
90521 +}
90522 +static inline void gr_free_thread_info(struct task_struct *tsk, struct thread_info *ti)
90523 +{
90524 + free_thread_info(ti);
90525 +}
90526 +#endif
90527 +
90528 /* SLAB cache for signal_struct structures (tsk->signal) */
90529 static struct kmem_cache *signal_cachep;
90530
90531 @@ -201,18 +243,22 @@ struct kmem_cache *vm_area_cachep;
90532 /* SLAB cache for mm_struct structures (tsk->mm) */
90533 static struct kmem_cache *mm_cachep;
90534
90535 -static void account_kernel_stack(struct thread_info *ti, int account)
90536 +static void account_kernel_stack(struct task_struct *tsk, struct thread_info *ti, int account)
90537 {
90538 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
90539 + struct zone *zone = page_zone(virt_to_page(tsk->lowmem_stack));
90540 +#else
90541 struct zone *zone = page_zone(virt_to_page(ti));
90542 +#endif
90543
90544 mod_zone_page_state(zone, NR_KERNEL_STACK, account);
90545 }
90546
90547 void free_task(struct task_struct *tsk)
90548 {
90549 - account_kernel_stack(tsk->stack, -1);
90550 + account_kernel_stack(tsk, tsk->stack, -1);
90551 arch_release_thread_info(tsk->stack);
90552 - free_thread_info(tsk->stack);
90553 + gr_free_thread_info(tsk, tsk->stack);
90554 rt_mutex_debug_task_free(tsk);
90555 ftrace_graph_exit_task(tsk);
90556 put_seccomp_filter(tsk);
90557 @@ -299,6 +345,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
90558 struct task_struct *tsk;
90559 struct thread_info *ti;
90560 unsigned long *stackend;
90561 + void *lowmem_stack;
90562 int node = tsk_fork_get_node(orig);
90563 int err;
90564
90565 @@ -306,7 +353,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
90566 if (!tsk)
90567 return NULL;
90568
90569 - ti = alloc_thread_info_node(tsk, node);
90570 + ti = gr_alloc_thread_info_node(tsk, node, &lowmem_stack);
90571 if (!ti)
90572 goto free_tsk;
90573
90574 @@ -315,6 +362,9 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
90575 goto free_ti;
90576
90577 tsk->stack = ti;
90578 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
90579 + tsk->lowmem_stack = lowmem_stack;
90580 +#endif
90581
90582 setup_thread_stack(tsk, orig);
90583 clear_user_return_notifier(tsk);
90584 @@ -323,7 +373,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
90585 *stackend = STACK_END_MAGIC; /* for overflow detection */
90586
90587 #ifdef CONFIG_CC_STACKPROTECTOR
90588 - tsk->stack_canary = get_random_int();
90589 + tsk->stack_canary = pax_get_random_long();
90590 #endif
90591
90592 /*
90593 @@ -337,24 +387,92 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
90594 tsk->splice_pipe = NULL;
90595 tsk->task_frag.page = NULL;
90596
90597 - account_kernel_stack(ti, 1);
90598 + account_kernel_stack(tsk, ti, 1);
90599
90600 return tsk;
90601
90602 free_ti:
90603 - free_thread_info(ti);
90604 + gr_free_thread_info(tsk, ti);
90605 free_tsk:
90606 free_task_struct(tsk);
90607 return NULL;
90608 }
90609
90610 #ifdef CONFIG_MMU
90611 -static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
90612 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
90613 +{
90614 + struct vm_area_struct *tmp;
90615 + unsigned long charge;
90616 + struct file *file;
90617 + int retval;
90618 +
90619 + charge = 0;
90620 + if (mpnt->vm_flags & VM_ACCOUNT) {
90621 + unsigned long len = vma_pages(mpnt);
90622 +
90623 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
90624 + goto fail_nomem;
90625 + charge = len;
90626 + }
90627 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
90628 + if (!tmp)
90629 + goto fail_nomem;
90630 + *tmp = *mpnt;
90631 + tmp->vm_mm = mm;
90632 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
90633 + retval = vma_dup_policy(mpnt, tmp);
90634 + if (retval)
90635 + goto fail_nomem_policy;
90636 + if (anon_vma_fork(tmp, mpnt))
90637 + goto fail_nomem_anon_vma_fork;
90638 + tmp->vm_flags &= ~VM_LOCKED;
90639 + tmp->vm_next = tmp->vm_prev = NULL;
90640 + tmp->vm_mirror = NULL;
90641 + file = tmp->vm_file;
90642 + if (file) {
90643 + struct inode *inode = file_inode(file);
90644 + struct address_space *mapping = file->f_mapping;
90645 +
90646 + get_file(file);
90647 + if (tmp->vm_flags & VM_DENYWRITE)
90648 + atomic_dec(&inode->i_writecount);
90649 + mutex_lock(&mapping->i_mmap_mutex);
90650 + if (tmp->vm_flags & VM_SHARED)
90651 + mapping->i_mmap_writable++;
90652 + flush_dcache_mmap_lock(mapping);
90653 + /* insert tmp into the share list, just after mpnt */
90654 + if (unlikely(tmp->vm_flags & VM_NONLINEAR))
90655 + vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
90656 + else
90657 + vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
90658 + flush_dcache_mmap_unlock(mapping);
90659 + mutex_unlock(&mapping->i_mmap_mutex);
90660 + }
90661 +
90662 + /*
90663 + * Clear hugetlb-related page reserves for children. This only
90664 + * affects MAP_PRIVATE mappings. Faults generated by the child
90665 + * are not guaranteed to succeed, even if read-only
90666 + */
90667 + if (is_vm_hugetlb_page(tmp))
90668 + reset_vma_resv_huge_pages(tmp);
90669 +
90670 + return tmp;
90671 +
90672 +fail_nomem_anon_vma_fork:
90673 + mpol_put(vma_policy(tmp));
90674 +fail_nomem_policy:
90675 + kmem_cache_free(vm_area_cachep, tmp);
90676 +fail_nomem:
90677 + vm_unacct_memory(charge);
90678 + return NULL;
90679 +}
90680 +
90681 +static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
90682 {
90683 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
90684 struct rb_node **rb_link, *rb_parent;
90685 int retval;
90686 - unsigned long charge;
90687
90688 uprobe_start_dup_mmap();
90689 down_write(&oldmm->mmap_sem);
90690 @@ -383,55 +501,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
90691
90692 prev = NULL;
90693 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
90694 - struct file *file;
90695 -
90696 if (mpnt->vm_flags & VM_DONTCOPY) {
90697 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
90698 -vma_pages(mpnt));
90699 continue;
90700 }
90701 - charge = 0;
90702 - if (mpnt->vm_flags & VM_ACCOUNT) {
90703 - unsigned long len = vma_pages(mpnt);
90704 -
90705 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
90706 - goto fail_nomem;
90707 - charge = len;
90708 - }
90709 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
90710 - if (!tmp)
90711 - goto fail_nomem;
90712 - *tmp = *mpnt;
90713 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
90714 - retval = vma_dup_policy(mpnt, tmp);
90715 - if (retval)
90716 - goto fail_nomem_policy;
90717 - tmp->vm_mm = mm;
90718 - if (anon_vma_fork(tmp, mpnt))
90719 - goto fail_nomem_anon_vma_fork;
90720 - tmp->vm_flags &= ~VM_LOCKED;
90721 - tmp->vm_next = tmp->vm_prev = NULL;
90722 - file = tmp->vm_file;
90723 - if (file) {
90724 - struct inode *inode = file_inode(file);
90725 - struct address_space *mapping = file->f_mapping;
90726 -
90727 - get_file(file);
90728 - if (tmp->vm_flags & VM_DENYWRITE)
90729 - atomic_dec(&inode->i_writecount);
90730 - mutex_lock(&mapping->i_mmap_mutex);
90731 - if (tmp->vm_flags & VM_SHARED)
90732 - mapping->i_mmap_writable++;
90733 - flush_dcache_mmap_lock(mapping);
90734 - /* insert tmp into the share list, just after mpnt */
90735 - if (unlikely(tmp->vm_flags & VM_NONLINEAR))
90736 - vma_nonlinear_insert(tmp,
90737 - &mapping->i_mmap_nonlinear);
90738 - else
90739 - vma_interval_tree_insert_after(tmp, mpnt,
90740 - &mapping->i_mmap);
90741 - flush_dcache_mmap_unlock(mapping);
90742 - mutex_unlock(&mapping->i_mmap_mutex);
90743 + tmp = dup_vma(mm, oldmm, mpnt);
90744 + if (!tmp) {
90745 + retval = -ENOMEM;
90746 + goto out;
90747 }
90748
90749 /*
90750 @@ -463,6 +541,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
90751 if (retval)
90752 goto out;
90753 }
90754 +
90755 +#ifdef CONFIG_PAX_SEGMEXEC
90756 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
90757 + struct vm_area_struct *mpnt_m;
90758 +
90759 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
90760 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
90761 +
90762 + if (!mpnt->vm_mirror)
90763 + continue;
90764 +
90765 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
90766 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
90767 + mpnt->vm_mirror = mpnt_m;
90768 + } else {
90769 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
90770 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
90771 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
90772 + mpnt->vm_mirror->vm_mirror = mpnt;
90773 + }
90774 + }
90775 + BUG_ON(mpnt_m);
90776 + }
90777 +#endif
90778 +
90779 /* a new mm has just been created */
90780 arch_dup_mmap(oldmm, mm);
90781 retval = 0;
90782 @@ -472,14 +575,6 @@ out:
90783 up_write(&oldmm->mmap_sem);
90784 uprobe_end_dup_mmap();
90785 return retval;
90786 -fail_nomem_anon_vma_fork:
90787 - mpol_put(vma_policy(tmp));
90788 -fail_nomem_policy:
90789 - kmem_cache_free(vm_area_cachep, tmp);
90790 -fail_nomem:
90791 - retval = -ENOMEM;
90792 - vm_unacct_memory(charge);
90793 - goto out;
90794 }
90795
90796 static inline int mm_alloc_pgd(struct mm_struct *mm)
90797 @@ -698,8 +793,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
90798 return ERR_PTR(err);
90799
90800 mm = get_task_mm(task);
90801 - if (mm && mm != current->mm &&
90802 - !ptrace_may_access(task, mode)) {
90803 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
90804 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
90805 mmput(mm);
90806 mm = ERR_PTR(-EACCES);
90807 }
90808 @@ -918,13 +1013,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
90809 spin_unlock(&fs->lock);
90810 return -EAGAIN;
90811 }
90812 - fs->users++;
90813 + atomic_inc(&fs->users);
90814 spin_unlock(&fs->lock);
90815 return 0;
90816 }
90817 tsk->fs = copy_fs_struct(fs);
90818 if (!tsk->fs)
90819 return -ENOMEM;
90820 + /* Carry through gr_chroot_dentry and is_chrooted instead
90821 + of recomputing it here. Already copied when the task struct
90822 + is duplicated. This allows pivot_root to not be treated as
90823 + a chroot
90824 + */
90825 + //gr_set_chroot_entries(tsk, &tsk->fs->root);
90826 +
90827 return 0;
90828 }
90829
90830 @@ -1133,7 +1235,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
90831 * parts of the process environment (as per the clone
90832 * flags). The actual kick-off is left to the caller.
90833 */
90834 -static struct task_struct *copy_process(unsigned long clone_flags,
90835 +static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
90836 unsigned long stack_start,
90837 unsigned long stack_size,
90838 int __user *child_tidptr,
90839 @@ -1205,6 +1307,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
90840 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
90841 #endif
90842 retval = -EAGAIN;
90843 +
90844 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
90845 +
90846 if (atomic_read(&p->real_cred->user->processes) >=
90847 task_rlimit(p, RLIMIT_NPROC)) {
90848 if (p->real_cred->user != INIT_USER &&
90849 @@ -1452,6 +1557,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
90850 goto bad_fork_free_pid;
90851 }
90852
90853 + /* synchronizes with gr_set_acls()
90854 + we need to call this past the point of no return for fork()
90855 + */
90856 + gr_copy_label(p);
90857 +
90858 if (likely(p->pid)) {
90859 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
90860
90861 @@ -1541,6 +1651,8 @@ bad_fork_cleanup_count:
90862 bad_fork_free:
90863 free_task(p);
90864 fork_out:
90865 + gr_log_forkfail(retval);
90866 +
90867 return ERR_PTR(retval);
90868 }
90869
90870 @@ -1602,6 +1714,7 @@ long do_fork(unsigned long clone_flags,
90871
90872 p = copy_process(clone_flags, stack_start, stack_size,
90873 child_tidptr, NULL, trace);
90874 + add_latent_entropy();
90875 /*
90876 * Do this prior waking up the new thread - the thread pointer
90877 * might get invalid after that point, if the thread exits quickly.
90878 @@ -1618,6 +1731,8 @@ long do_fork(unsigned long clone_flags,
90879 if (clone_flags & CLONE_PARENT_SETTID)
90880 put_user(nr, parent_tidptr);
90881
90882 + gr_handle_brute_check();
90883 +
90884 if (clone_flags & CLONE_VFORK) {
90885 p->vfork_done = &vfork;
90886 init_completion(&vfork);
90887 @@ -1736,7 +1851,7 @@ void __init proc_caches_init(void)
90888 mm_cachep = kmem_cache_create("mm_struct",
90889 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
90890 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
90891 - vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
90892 + vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
90893 mmap_init();
90894 nsproxy_cache_init();
90895 }
90896 @@ -1776,7 +1891,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
90897 return 0;
90898
90899 /* don't need lock here; in the worst case we'll do useless copy */
90900 - if (fs->users == 1)
90901 + if (atomic_read(&fs->users) == 1)
90902 return 0;
90903
90904 *new_fsp = copy_fs_struct(fs);
90905 @@ -1883,7 +1998,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
90906 fs = current->fs;
90907 spin_lock(&fs->lock);
90908 current->fs = new_fs;
90909 - if (--fs->users)
90910 + gr_set_chroot_entries(current, &current->fs->root);
90911 + if (atomic_dec_return(&fs->users))
90912 new_fs = NULL;
90913 else
90914 new_fs = fs;
90915 diff --git a/kernel/futex.c b/kernel/futex.c
90916 index b632b5f..ca00da9 100644
90917 --- a/kernel/futex.c
90918 +++ b/kernel/futex.c
90919 @@ -202,7 +202,7 @@ struct futex_pi_state {
90920 atomic_t refcount;
90921
90922 union futex_key key;
90923 -};
90924 +} __randomize_layout;
90925
90926 /**
90927 * struct futex_q - The hashed futex queue entry, one per waiting task
90928 @@ -236,7 +236,7 @@ struct futex_q {
90929 struct rt_mutex_waiter *rt_waiter;
90930 union futex_key *requeue_pi_key;
90931 u32 bitset;
90932 -};
90933 +} __randomize_layout;
90934
90935 static const struct futex_q futex_q_init = {
90936 /* list gets initialized in queue_me()*/
90937 @@ -394,6 +394,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
90938 struct page *page, *page_head;
90939 int err, ro = 0;
90940
90941 +#ifdef CONFIG_PAX_SEGMEXEC
90942 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
90943 + return -EFAULT;
90944 +#endif
90945 +
90946 /*
90947 * The futex address must be "naturally" aligned.
90948 */
90949 @@ -593,7 +598,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
90950
90951 static int get_futex_value_locked(u32 *dest, u32 __user *from)
90952 {
90953 - int ret;
90954 + unsigned long ret;
90955
90956 pagefault_disable();
90957 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
90958 @@ -3033,6 +3038,7 @@ static void __init futex_detect_cmpxchg(void)
90959 {
90960 #ifndef CONFIG_HAVE_FUTEX_CMPXCHG
90961 u32 curval;
90962 + mm_segment_t oldfs;
90963
90964 /*
90965 * This will fail and we want it. Some arch implementations do
90966 @@ -3044,8 +3050,11 @@ static void __init futex_detect_cmpxchg(void)
90967 * implementation, the non-functional ones will return
90968 * -ENOSYS.
90969 */
90970 + oldfs = get_fs();
90971 + set_fs(USER_DS);
90972 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
90973 futex_cmpxchg_enabled = 1;
90974 + set_fs(oldfs);
90975 #endif
90976 }
90977
90978 diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
90979 index 55c8c93..9ba7ad6 100644
90980 --- a/kernel/futex_compat.c
90981 +++ b/kernel/futex_compat.c
90982 @@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
90983 return 0;
90984 }
90985
90986 -static void __user *futex_uaddr(struct robust_list __user *entry,
90987 +static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
90988 compat_long_t futex_offset)
90989 {
90990 compat_uptr_t base = ptr_to_compat(entry);
90991 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
90992 index b358a80..fc25240 100644
90993 --- a/kernel/gcov/base.c
90994 +++ b/kernel/gcov/base.c
90995 @@ -114,11 +114,6 @@ void gcov_enable_events(void)
90996 }
90997
90998 #ifdef CONFIG_MODULES
90999 -static inline int within(void *addr, void *start, unsigned long size)
91000 -{
91001 - return ((addr >= start) && (addr < start + size));
91002 -}
91003 -
91004 /* Update list and generate events when modules are unloaded. */
91005 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
91006 void *data)
91007 @@ -133,7 +128,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
91008
91009 /* Remove entries located in module from linked list. */
91010 while ((info = gcov_info_next(info))) {
91011 - if (within(info, mod->module_core, mod->core_size)) {
91012 + if (within_module_core_rw((unsigned long)info, mod)) {
91013 gcov_info_unlink(prev, info);
91014 if (gcov_events_enabled)
91015 gcov_event(GCOV_REMOVE, info);
91016 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
91017 index 3ab2899..c6ad010 100644
91018 --- a/kernel/hrtimer.c
91019 +++ b/kernel/hrtimer.c
91020 @@ -1449,7 +1449,7 @@ void hrtimer_peek_ahead_timers(void)
91021 local_irq_restore(flags);
91022 }
91023
91024 -static void run_hrtimer_softirq(struct softirq_action *h)
91025 +static __latent_entropy void run_hrtimer_softirq(void)
91026 {
91027 hrtimer_peek_ahead_timers();
91028 }
91029 diff --git a/kernel/irq_work.c b/kernel/irq_work.c
91030 index a82170e..5b01e7f 100644
91031 --- a/kernel/irq_work.c
91032 +++ b/kernel/irq_work.c
91033 @@ -191,12 +191,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
91034 return NOTIFY_OK;
91035 }
91036
91037 -static struct notifier_block cpu_notify;
91038 +static struct notifier_block cpu_notify = {
91039 + .notifier_call = irq_work_cpu_notify,
91040 + .priority = 0,
91041 +};
91042
91043 static __init int irq_work_init_cpu_notifier(void)
91044 {
91045 - cpu_notify.notifier_call = irq_work_cpu_notify;
91046 - cpu_notify.priority = 0;
91047 register_cpu_notifier(&cpu_notify);
91048 return 0;
91049 }
91050 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
91051 index 9019f15..9a3c42e 100644
91052 --- a/kernel/jump_label.c
91053 +++ b/kernel/jump_label.c
91054 @@ -14,6 +14,7 @@
91055 #include <linux/err.h>
91056 #include <linux/static_key.h>
91057 #include <linux/jump_label_ratelimit.h>
91058 +#include <linux/mm.h>
91059
91060 #ifdef HAVE_JUMP_LABEL
91061
91062 @@ -51,7 +52,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
91063
91064 size = (((unsigned long)stop - (unsigned long)start)
91065 / sizeof(struct jump_entry));
91066 + pax_open_kernel();
91067 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
91068 + pax_close_kernel();
91069 }
91070
91071 static void jump_label_update(struct static_key *key, int enable);
91072 @@ -363,10 +366,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
91073 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
91074 struct jump_entry *iter;
91075
91076 + pax_open_kernel();
91077 for (iter = iter_start; iter < iter_stop; iter++) {
91078 if (within_module_init(iter->code, mod))
91079 iter->code = 0;
91080 }
91081 + pax_close_kernel();
91082 }
91083
91084 static int
91085 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
91086 index cb0cf37..b69e161 100644
91087 --- a/kernel/kallsyms.c
91088 +++ b/kernel/kallsyms.c
91089 @@ -11,6 +11,9 @@
91090 * Changed the compression method from stem compression to "table lookup"
91091 * compression (see scripts/kallsyms.c for a more complete description)
91092 */
91093 +#ifdef CONFIG_GRKERNSEC_HIDESYM
91094 +#define __INCLUDED_BY_HIDESYM 1
91095 +#endif
91096 #include <linux/kallsyms.h>
91097 #include <linux/module.h>
91098 #include <linux/init.h>
91099 @@ -54,12 +57,33 @@ extern const unsigned long kallsyms_markers[] __weak;
91100
91101 static inline int is_kernel_inittext(unsigned long addr)
91102 {
91103 + if (system_state != SYSTEM_BOOTING)
91104 + return 0;
91105 +
91106 if (addr >= (unsigned long)_sinittext
91107 && addr <= (unsigned long)_einittext)
91108 return 1;
91109 return 0;
91110 }
91111
91112 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
91113 +#ifdef CONFIG_MODULES
91114 +static inline int is_module_text(unsigned long addr)
91115 +{
91116 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
91117 + return 1;
91118 +
91119 + addr = ktla_ktva(addr);
91120 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
91121 +}
91122 +#else
91123 +static inline int is_module_text(unsigned long addr)
91124 +{
91125 + return 0;
91126 +}
91127 +#endif
91128 +#endif
91129 +
91130 static inline int is_kernel_text(unsigned long addr)
91131 {
91132 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
91133 @@ -70,13 +94,28 @@ static inline int is_kernel_text(unsigned long addr)
91134
91135 static inline int is_kernel(unsigned long addr)
91136 {
91137 +
91138 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
91139 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
91140 + return 1;
91141 +
91142 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
91143 +#else
91144 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
91145 +#endif
91146 +
91147 return 1;
91148 return in_gate_area_no_mm(addr);
91149 }
91150
91151 static int is_ksym_addr(unsigned long addr)
91152 {
91153 +
91154 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
91155 + if (is_module_text(addr))
91156 + return 0;
91157 +#endif
91158 +
91159 if (all_var)
91160 return is_kernel(addr);
91161
91162 @@ -481,7 +520,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
91163
91164 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
91165 {
91166 - iter->name[0] = '\0';
91167 iter->nameoff = get_symbol_offset(new_pos);
91168 iter->pos = new_pos;
91169 }
91170 @@ -529,6 +567,11 @@ static int s_show(struct seq_file *m, void *p)
91171 {
91172 struct kallsym_iter *iter = m->private;
91173
91174 +#ifdef CONFIG_GRKERNSEC_HIDESYM
91175 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
91176 + return 0;
91177 +#endif
91178 +
91179 /* Some debugging symbols have no name. Ignore them. */
91180 if (!iter->name[0])
91181 return 0;
91182 @@ -542,6 +585,7 @@ static int s_show(struct seq_file *m, void *p)
91183 */
91184 type = iter->exported ? toupper(iter->type) :
91185 tolower(iter->type);
91186 +
91187 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
91188 type, iter->name, iter->module_name);
91189 } else
91190 @@ -567,7 +611,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
91191 struct kallsym_iter *iter;
91192 int ret;
91193
91194 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
91195 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
91196 if (!iter)
91197 return -ENOMEM;
91198 reset_iter(iter, 0);
91199 diff --git a/kernel/kcmp.c b/kernel/kcmp.c
91200 index e30ac0f..3528cac 100644
91201 --- a/kernel/kcmp.c
91202 +++ b/kernel/kcmp.c
91203 @@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
91204 struct task_struct *task1, *task2;
91205 int ret;
91206
91207 +#ifdef CONFIG_GRKERNSEC
91208 + return -ENOSYS;
91209 +#endif
91210 +
91211 rcu_read_lock();
91212
91213 /*
91214 diff --git a/kernel/kexec.c b/kernel/kexec.c
91215 index 4b8f0c9..fffd0df 100644
91216 --- a/kernel/kexec.c
91217 +++ b/kernel/kexec.c
91218 @@ -1045,7 +1045,8 @@ COMPAT_SYSCALL_DEFINE4(kexec_load, compat_ulong_t, entry,
91219 compat_ulong_t, flags)
91220 {
91221 struct compat_kexec_segment in;
91222 - struct kexec_segment out, __user *ksegments;
91223 + struct kexec_segment out;
91224 + struct kexec_segment __user *ksegments;
91225 unsigned long i, result;
91226
91227 /* Don't allow clients that don't understand the native
91228 diff --git a/kernel/kmod.c b/kernel/kmod.c
91229 index 8637e04..8b1d0d8 100644
91230 --- a/kernel/kmod.c
91231 +++ b/kernel/kmod.c
91232 @@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
91233 kfree(info->argv);
91234 }
91235
91236 -static int call_modprobe(char *module_name, int wait)
91237 +static int call_modprobe(char *module_name, char *module_param, int wait)
91238 {
91239 struct subprocess_info *info;
91240 static char *envp[] = {
91241 @@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
91242 NULL
91243 };
91244
91245 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
91246 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
91247 if (!argv)
91248 goto out;
91249
91250 @@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
91251 argv[1] = "-q";
91252 argv[2] = "--";
91253 argv[3] = module_name; /* check free_modprobe_argv() */
91254 - argv[4] = NULL;
91255 + argv[4] = module_param;
91256 + argv[5] = NULL;
91257
91258 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
91259 NULL, free_modprobe_argv, NULL);
91260 @@ -129,9 +130,8 @@ out:
91261 * If module auto-loading support is disabled then this function
91262 * becomes a no-operation.
91263 */
91264 -int __request_module(bool wait, const char *fmt, ...)
91265 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
91266 {
91267 - va_list args;
91268 char module_name[MODULE_NAME_LEN];
91269 unsigned int max_modprobes;
91270 int ret;
91271 @@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
91272 if (!modprobe_path[0])
91273 return 0;
91274
91275 - va_start(args, fmt);
91276 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
91277 - va_end(args);
91278 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
91279 if (ret >= MODULE_NAME_LEN)
91280 return -ENAMETOOLONG;
91281
91282 @@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
91283 if (ret)
91284 return ret;
91285
91286 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
91287 + if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
91288 + /* hack to workaround consolekit/udisks stupidity */
91289 + read_lock(&tasklist_lock);
91290 + if (!strcmp(current->comm, "mount") &&
91291 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
91292 + read_unlock(&tasklist_lock);
91293 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
91294 + return -EPERM;
91295 + }
91296 + read_unlock(&tasklist_lock);
91297 + }
91298 +#endif
91299 +
91300 /* If modprobe needs a service that is in a module, we get a recursive
91301 * loop. Limit the number of running kmod threads to max_threads/2 or
91302 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
91303 @@ -188,11 +200,52 @@ int __request_module(bool wait, const char *fmt, ...)
91304
91305 trace_module_request(module_name, wait, _RET_IP_);
91306
91307 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
91308 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
91309
91310 atomic_dec(&kmod_concurrent);
91311 return ret;
91312 }
91313 +
91314 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
91315 +{
91316 + va_list args;
91317 + int ret;
91318 +
91319 + va_start(args, fmt);
91320 + ret = ____request_module(wait, module_param, fmt, args);
91321 + va_end(args);
91322 +
91323 + return ret;
91324 +}
91325 +
91326 +int __request_module(bool wait, const char *fmt, ...)
91327 +{
91328 + va_list args;
91329 + int ret;
91330 +
91331 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
91332 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
91333 + char module_param[MODULE_NAME_LEN];
91334 +
91335 + memset(module_param, 0, sizeof(module_param));
91336 +
91337 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
91338 +
91339 + va_start(args, fmt);
91340 + ret = ____request_module(wait, module_param, fmt, args);
91341 + va_end(args);
91342 +
91343 + return ret;
91344 + }
91345 +#endif
91346 +
91347 + va_start(args, fmt);
91348 + ret = ____request_module(wait, NULL, fmt, args);
91349 + va_end(args);
91350 +
91351 + return ret;
91352 +}
91353 +
91354 EXPORT_SYMBOL(__request_module);
91355 #endif /* CONFIG_MODULES */
91356
91357 @@ -218,6 +271,20 @@ static int ____call_usermodehelper(void *data)
91358 */
91359 set_user_nice(current, 0);
91360
91361 +#ifdef CONFIG_GRKERNSEC
91362 + /* this is race-free as far as userland is concerned as we copied
91363 + out the path to be used prior to this point and are now operating
91364 + on that copy
91365 + */
91366 + if ((strncmp(sub_info->path, "/sbin/", 6) && strncmp(sub_info->path, "/usr/lib/", 9) &&
91367 + strncmp(sub_info->path, "/lib/", 5) && strncmp(sub_info->path, "/lib64/", 7) &&
91368 + strcmp(sub_info->path, "/usr/share/apport/apport")) || strstr(sub_info->path, "..")) {
91369 + printk(KERN_ALERT "grsec: denied exec of usermode helper binary %.950s located outside of /sbin and system library paths\n", sub_info->path);
91370 + retval = -EPERM;
91371 + goto fail;
91372 + }
91373 +#endif
91374 +
91375 retval = -ENOMEM;
91376 new = prepare_kernel_cred(current);
91377 if (!new)
91378 @@ -240,8 +307,8 @@ static int ____call_usermodehelper(void *data)
91379 commit_creds(new);
91380
91381 retval = do_execve(getname_kernel(sub_info->path),
91382 - (const char __user *const __user *)sub_info->argv,
91383 - (const char __user *const __user *)sub_info->envp);
91384 + (const char __user *const __force_user *)sub_info->argv,
91385 + (const char __user *const __force_user *)sub_info->envp);
91386 if (!retval)
91387 return 0;
91388
91389 @@ -260,6 +327,10 @@ static int call_helper(void *data)
91390
91391 static void call_usermodehelper_freeinfo(struct subprocess_info *info)
91392 {
91393 +#ifdef CONFIG_GRKERNSEC
91394 + kfree(info->path);
91395 + info->path = info->origpath;
91396 +#endif
91397 if (info->cleanup)
91398 (*info->cleanup)(info);
91399 kfree(info);
91400 @@ -300,7 +371,7 @@ static int wait_for_helper(void *data)
91401 *
91402 * Thus the __user pointer cast is valid here.
91403 */
91404 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
91405 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
91406
91407 /*
91408 * If ret is 0, either ____call_usermodehelper failed and the
91409 @@ -539,7 +610,12 @@ struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
91410 goto out;
91411
91412 INIT_WORK(&sub_info->work, __call_usermodehelper);
91413 +#ifdef CONFIG_GRKERNSEC
91414 + sub_info->origpath = path;
91415 + sub_info->path = kstrdup(path, gfp_mask);
91416 +#else
91417 sub_info->path = path;
91418 +#endif
91419 sub_info->argv = argv;
91420 sub_info->envp = envp;
91421
91422 @@ -647,7 +723,7 @@ EXPORT_SYMBOL(call_usermodehelper);
91423 static int proc_cap_handler(struct ctl_table *table, int write,
91424 void __user *buffer, size_t *lenp, loff_t *ppos)
91425 {
91426 - struct ctl_table t;
91427 + ctl_table_no_const t;
91428 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
91429 kernel_cap_t new_cap;
91430 int err, i;
91431 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
91432 index 734e9a7..0a313b8 100644
91433 --- a/kernel/kprobes.c
91434 +++ b/kernel/kprobes.c
91435 @@ -31,6 +31,9 @@
91436 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
91437 * <prasanna@in.ibm.com> added function-return probes.
91438 */
91439 +#ifdef CONFIG_GRKERNSEC_HIDESYM
91440 +#define __INCLUDED_BY_HIDESYM 1
91441 +#endif
91442 #include <linux/kprobes.h>
91443 #include <linux/hash.h>
91444 #include <linux/init.h>
91445 @@ -122,12 +125,12 @@ enum kprobe_slot_state {
91446
91447 static void *alloc_insn_page(void)
91448 {
91449 - return module_alloc(PAGE_SIZE);
91450 + return module_alloc_exec(PAGE_SIZE);
91451 }
91452
91453 static void free_insn_page(void *page)
91454 {
91455 - module_free(NULL, page);
91456 + module_free_exec(NULL, page);
91457 }
91458
91459 struct kprobe_insn_cache kprobe_insn_slots = {
91460 @@ -2176,11 +2179,11 @@ static void report_probe(struct seq_file *pi, struct kprobe *p,
91461 kprobe_type = "k";
91462
91463 if (sym)
91464 - seq_printf(pi, "%p %s %s+0x%x %s ",
91465 + seq_printf(pi, "%pK %s %s+0x%x %s ",
91466 p->addr, kprobe_type, sym, offset,
91467 (modname ? modname : " "));
91468 else
91469 - seq_printf(pi, "%p %s %p ",
91470 + seq_printf(pi, "%pK %s %pK ",
91471 p->addr, kprobe_type, p->addr);
91472
91473 if (!pp)
91474 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
91475 index 6683cce..daf8999 100644
91476 --- a/kernel/ksysfs.c
91477 +++ b/kernel/ksysfs.c
91478 @@ -50,6 +50,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
91479 {
91480 if (count+1 > UEVENT_HELPER_PATH_LEN)
91481 return -ENOENT;
91482 + if (!capable(CAP_SYS_ADMIN))
91483 + return -EPERM;
91484 memcpy(uevent_helper, buf, count);
91485 uevent_helper[count] = '\0';
91486 if (count && uevent_helper[count-1] == '\n')
91487 @@ -176,7 +178,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
91488 return count;
91489 }
91490
91491 -static struct bin_attribute notes_attr = {
91492 +static bin_attribute_no_const notes_attr __read_only = {
91493 .attr = {
91494 .name = "notes",
91495 .mode = S_IRUGO,
91496 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
91497 index d24e433..fa04fb8 100644
91498 --- a/kernel/locking/lockdep.c
91499 +++ b/kernel/locking/lockdep.c
91500 @@ -597,6 +597,10 @@ static int static_obj(void *obj)
91501 end = (unsigned long) &_end,
91502 addr = (unsigned long) obj;
91503
91504 +#ifdef CONFIG_PAX_KERNEXEC
91505 + start = ktla_ktva(start);
91506 +#endif
91507 +
91508 /*
91509 * static variable?
91510 */
91511 @@ -738,6 +742,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
91512 if (!static_obj(lock->key)) {
91513 debug_locks_off();
91514 printk("INFO: trying to register non-static key.\n");
91515 + printk("lock:%pS key:%pS.\n", lock, lock->key);
91516 printk("the code is fine but needs lockdep annotation.\n");
91517 printk("turning off the locking correctness validator.\n");
91518 dump_stack();
91519 @@ -3079,7 +3084,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
91520 if (!class)
91521 return 0;
91522 }
91523 - atomic_inc((atomic_t *)&class->ops);
91524 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)&class->ops);
91525 if (very_verbose(class)) {
91526 printk("\nacquire class [%p] %s", class->key, class->name);
91527 if (class->name_version > 1)
91528 diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
91529 index ef43ac4..2720dfa 100644
91530 --- a/kernel/locking/lockdep_proc.c
91531 +++ b/kernel/locking/lockdep_proc.c
91532 @@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
91533 return 0;
91534 }
91535
91536 - seq_printf(m, "%p", class->key);
91537 + seq_printf(m, "%pK", class->key);
91538 #ifdef CONFIG_DEBUG_LOCKDEP
91539 seq_printf(m, " OPS:%8ld", class->ops);
91540 #endif
91541 @@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
91542
91543 list_for_each_entry(entry, &class->locks_after, entry) {
91544 if (entry->distance == 1) {
91545 - seq_printf(m, " -> [%p] ", entry->class->key);
91546 + seq_printf(m, " -> [%pK] ", entry->class->key);
91547 print_name(m, entry->class);
91548 seq_puts(m, "\n");
91549 }
91550 @@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
91551 if (!class->key)
91552 continue;
91553
91554 - seq_printf(m, "[%p] ", class->key);
91555 + seq_printf(m, "[%pK] ", class->key);
91556 print_name(m, class);
91557 seq_puts(m, "\n");
91558 }
91559 @@ -496,7 +496,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
91560 if (!i)
91561 seq_line(m, '-', 40-namelen, namelen);
91562
91563 - snprintf(ip, sizeof(ip), "[<%p>]",
91564 + snprintf(ip, sizeof(ip), "[<%pK>]",
91565 (void *)class->contention_point[i]);
91566 seq_printf(m, "%40s %14lu %29s %pS\n",
91567 name, stats->contention_point[i],
91568 @@ -511,7 +511,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
91569 if (!i)
91570 seq_line(m, '-', 40-namelen, namelen);
91571
91572 - snprintf(ip, sizeof(ip), "[<%p>]",
91573 + snprintf(ip, sizeof(ip), "[<%pK>]",
91574 (void *)class->contending_point[i]);
91575 seq_printf(m, "%40s %14lu %29s %pS\n",
91576 name, stats->contending_point[i],
91577 diff --git a/kernel/locking/mcs_spinlock.c b/kernel/locking/mcs_spinlock.c
91578 index be9ee15..39d6233 100644
91579 --- a/kernel/locking/mcs_spinlock.c
91580 +++ b/kernel/locking/mcs_spinlock.c
91581 @@ -102,7 +102,7 @@ bool osq_lock(struct optimistic_spin_queue *lock)
91582
91583 prev = decode_cpu(old);
91584 node->prev = prev;
91585 - ACCESS_ONCE(prev->next) = node;
91586 + ACCESS_ONCE_RW(prev->next) = node;
91587
91588 /*
91589 * Normally @prev is untouchable after the above store; because at that
91590 @@ -174,8 +174,8 @@ unqueue:
91591 * it will wait in Step-A.
91592 */
91593
91594 - ACCESS_ONCE(next->prev) = prev;
91595 - ACCESS_ONCE(prev->next) = next;
91596 + ACCESS_ONCE_RW(next->prev) = prev;
91597 + ACCESS_ONCE_RW(prev->next) = next;
91598
91599 return false;
91600 }
91601 @@ -197,13 +197,13 @@ void osq_unlock(struct optimistic_spin_queue *lock)
91602 node = this_cpu_ptr(&osq_node);
91603 next = xchg(&node->next, NULL);
91604 if (next) {
91605 - ACCESS_ONCE(next->locked) = 1;
91606 + ACCESS_ONCE_RW(next->locked) = 1;
91607 return;
91608 }
91609
91610 next = osq_wait_next(lock, node, NULL);
91611 if (next)
91612 - ACCESS_ONCE(next->locked) = 1;
91613 + ACCESS_ONCE_RW(next->locked) = 1;
91614 }
91615
91616 #endif
91617 diff --git a/kernel/locking/mcs_spinlock.h b/kernel/locking/mcs_spinlock.h
91618 index 74356dc..48dd5e1 100644
91619 --- a/kernel/locking/mcs_spinlock.h
91620 +++ b/kernel/locking/mcs_spinlock.h
91621 @@ -81,7 +81,7 @@ void mcs_spin_lock(struct mcs_spinlock **lock, struct mcs_spinlock *node)
91622 */
91623 return;
91624 }
91625 - ACCESS_ONCE(prev->next) = node;
91626 + ACCESS_ONCE_RW(prev->next) = node;
91627
91628 /* Wait until the lock holder passes the lock down. */
91629 arch_mcs_spin_lock_contended(&node->locked);
91630 diff --git a/kernel/locking/mutex-debug.c b/kernel/locking/mutex-debug.c
91631 index 5cf6731..ce3bc5a 100644
91632 --- a/kernel/locking/mutex-debug.c
91633 +++ b/kernel/locking/mutex-debug.c
91634 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
91635 }
91636
91637 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
91638 - struct thread_info *ti)
91639 + struct task_struct *task)
91640 {
91641 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
91642
91643 /* Mark the current thread as blocked on the lock: */
91644 - ti->task->blocked_on = waiter;
91645 + task->blocked_on = waiter;
91646 }
91647
91648 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
91649 - struct thread_info *ti)
91650 + struct task_struct *task)
91651 {
91652 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
91653 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
91654 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
91655 - ti->task->blocked_on = NULL;
91656 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
91657 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
91658 + task->blocked_on = NULL;
91659
91660 list_del_init(&waiter->list);
91661 waiter->task = NULL;
91662 diff --git a/kernel/locking/mutex-debug.h b/kernel/locking/mutex-debug.h
91663 index 0799fd3..d06ae3b 100644
91664 --- a/kernel/locking/mutex-debug.h
91665 +++ b/kernel/locking/mutex-debug.h
91666 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
91667 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
91668 extern void debug_mutex_add_waiter(struct mutex *lock,
91669 struct mutex_waiter *waiter,
91670 - struct thread_info *ti);
91671 + struct task_struct *task);
91672 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
91673 - struct thread_info *ti);
91674 + struct task_struct *task);
91675 extern void debug_mutex_unlock(struct mutex *lock);
91676 extern void debug_mutex_init(struct mutex *lock, const char *name,
91677 struct lock_class_key *key);
91678 diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
91679 index acca2c1..ddeaea8 100644
91680 --- a/kernel/locking/mutex.c
91681 +++ b/kernel/locking/mutex.c
91682 @@ -490,7 +490,7 @@ slowpath:
91683 goto skip_wait;
91684
91685 debug_mutex_lock_common(lock, &waiter);
91686 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
91687 + debug_mutex_add_waiter(lock, &waiter, task);
91688
91689 /* add waiting tasks to the end of the waitqueue (FIFO): */
91690 list_add_tail(&waiter.list, &lock->wait_list);
91691 @@ -534,7 +534,7 @@ slowpath:
91692 schedule_preempt_disabled();
91693 spin_lock_mutex(&lock->wait_lock, flags);
91694 }
91695 - mutex_remove_waiter(lock, &waiter, current_thread_info());
91696 + mutex_remove_waiter(lock, &waiter, task);
91697 /* set it to 0 if there are no waiters left: */
91698 if (likely(list_empty(&lock->wait_list)))
91699 atomic_set(&lock->count, 0);
91700 @@ -571,7 +571,7 @@ skip_wait:
91701 return 0;
91702
91703 err:
91704 - mutex_remove_waiter(lock, &waiter, task_thread_info(task));
91705 + mutex_remove_waiter(lock, &waiter, task);
91706 spin_unlock_mutex(&lock->wait_lock, flags);
91707 debug_mutex_free_waiter(&waiter);
91708 mutex_release(&lock->dep_map, 1, ip);
91709 diff --git a/kernel/locking/rtmutex-tester.c b/kernel/locking/rtmutex-tester.c
91710 index 1d96dd0..994ff19 100644
91711 --- a/kernel/locking/rtmutex-tester.c
91712 +++ b/kernel/locking/rtmutex-tester.c
91713 @@ -22,7 +22,7 @@
91714 #define MAX_RT_TEST_MUTEXES 8
91715
91716 static spinlock_t rttest_lock;
91717 -static atomic_t rttest_event;
91718 +static atomic_unchecked_t rttest_event;
91719
91720 struct test_thread_data {
91721 int opcode;
91722 @@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
91723
91724 case RTTEST_LOCKCONT:
91725 td->mutexes[td->opdata] = 1;
91726 - td->event = atomic_add_return(1, &rttest_event);
91727 + td->event = atomic_add_return_unchecked(1, &rttest_event);
91728 return 0;
91729
91730 case RTTEST_RESET:
91731 @@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
91732 return 0;
91733
91734 case RTTEST_RESETEVENT:
91735 - atomic_set(&rttest_event, 0);
91736 + atomic_set_unchecked(&rttest_event, 0);
91737 return 0;
91738
91739 default:
91740 @@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
91741 return ret;
91742
91743 td->mutexes[id] = 1;
91744 - td->event = atomic_add_return(1, &rttest_event);
91745 + td->event = atomic_add_return_unchecked(1, &rttest_event);
91746 rt_mutex_lock(&mutexes[id]);
91747 - td->event = atomic_add_return(1, &rttest_event);
91748 + td->event = atomic_add_return_unchecked(1, &rttest_event);
91749 td->mutexes[id] = 4;
91750 return 0;
91751
91752 @@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
91753 return ret;
91754
91755 td->mutexes[id] = 1;
91756 - td->event = atomic_add_return(1, &rttest_event);
91757 + td->event = atomic_add_return_unchecked(1, &rttest_event);
91758 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
91759 - td->event = atomic_add_return(1, &rttest_event);
91760 + td->event = atomic_add_return_unchecked(1, &rttest_event);
91761 td->mutexes[id] = ret ? 0 : 4;
91762 return ret ? -EINTR : 0;
91763
91764 @@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
91765 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
91766 return ret;
91767
91768 - td->event = atomic_add_return(1, &rttest_event);
91769 + td->event = atomic_add_return_unchecked(1, &rttest_event);
91770 rt_mutex_unlock(&mutexes[id]);
91771 - td->event = atomic_add_return(1, &rttest_event);
91772 + td->event = atomic_add_return_unchecked(1, &rttest_event);
91773 td->mutexes[id] = 0;
91774 return 0;
91775
91776 @@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
91777 break;
91778
91779 td->mutexes[dat] = 2;
91780 - td->event = atomic_add_return(1, &rttest_event);
91781 + td->event = atomic_add_return_unchecked(1, &rttest_event);
91782 break;
91783
91784 default:
91785 @@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
91786 return;
91787
91788 td->mutexes[dat] = 3;
91789 - td->event = atomic_add_return(1, &rttest_event);
91790 + td->event = atomic_add_return_unchecked(1, &rttest_event);
91791 break;
91792
91793 case RTTEST_LOCKNOWAIT:
91794 @@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
91795 return;
91796
91797 td->mutexes[dat] = 1;
91798 - td->event = atomic_add_return(1, &rttest_event);
91799 + td->event = atomic_add_return_unchecked(1, &rttest_event);
91800 return;
91801
91802 default:
91803 diff --git a/kernel/module.c b/kernel/module.c
91804 index 81e727c..a8ea6f9 100644
91805 --- a/kernel/module.c
91806 +++ b/kernel/module.c
91807 @@ -61,6 +61,7 @@
91808 #include <linux/pfn.h>
91809 #include <linux/bsearch.h>
91810 #include <linux/fips.h>
91811 +#include <linux/grsecurity.h>
91812 #include <uapi/linux/module.h>
91813 #include "module-internal.h"
91814
91815 @@ -157,7 +158,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
91816
91817 /* Bounds of module allocation, for speeding __module_address.
91818 * Protected by module_mutex. */
91819 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
91820 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
91821 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
91822
91823 int register_module_notifier(struct notifier_block * nb)
91824 {
91825 @@ -324,7 +326,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
91826 return true;
91827
91828 list_for_each_entry_rcu(mod, &modules, list) {
91829 - struct symsearch arr[] = {
91830 + struct symsearch modarr[] = {
91831 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
91832 NOT_GPL_ONLY, false },
91833 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
91834 @@ -349,7 +351,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
91835 if (mod->state == MODULE_STATE_UNFORMED)
91836 continue;
91837
91838 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
91839 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
91840 return true;
91841 }
91842 return false;
91843 @@ -489,7 +491,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
91844 if (!pcpusec->sh_size)
91845 return 0;
91846
91847 - if (align > PAGE_SIZE) {
91848 + if (align-1 >= PAGE_SIZE) {
91849 pr_warn("%s: per-cpu alignment %li > %li\n",
91850 mod->name, align, PAGE_SIZE);
91851 align = PAGE_SIZE;
91852 @@ -1061,7 +1063,7 @@ struct module_attribute module_uevent =
91853 static ssize_t show_coresize(struct module_attribute *mattr,
91854 struct module_kobject *mk, char *buffer)
91855 {
91856 - return sprintf(buffer, "%u\n", mk->mod->core_size);
91857 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
91858 }
91859
91860 static struct module_attribute modinfo_coresize =
91861 @@ -1070,7 +1072,7 @@ static struct module_attribute modinfo_coresize =
91862 static ssize_t show_initsize(struct module_attribute *mattr,
91863 struct module_kobject *mk, char *buffer)
91864 {
91865 - return sprintf(buffer, "%u\n", mk->mod->init_size);
91866 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
91867 }
91868
91869 static struct module_attribute modinfo_initsize =
91870 @@ -1162,12 +1164,29 @@ static int check_version(Elf_Shdr *sechdrs,
91871 goto bad_version;
91872 }
91873
91874 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
91875 + /*
91876 + * avoid potentially printing jibberish on attempted load
91877 + * of a module randomized with a different seed
91878 + */
91879 + pr_warn("no symbol version for %s\n", symname);
91880 +#else
91881 pr_warn("%s: no symbol version for %s\n", mod->name, symname);
91882 +#endif
91883 return 0;
91884
91885 bad_version:
91886 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
91887 + /*
91888 + * avoid potentially printing jibberish on attempted load
91889 + * of a module randomized with a different seed
91890 + */
91891 + printk("attempted module disagrees about version of symbol %s\n",
91892 + symname);
91893 +#else
91894 printk("%s: disagrees about version of symbol %s\n",
91895 mod->name, symname);
91896 +#endif
91897 return 0;
91898 }
91899
91900 @@ -1283,7 +1302,7 @@ resolve_symbol_wait(struct module *mod,
91901 */
91902 #ifdef CONFIG_SYSFS
91903
91904 -#ifdef CONFIG_KALLSYMS
91905 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
91906 static inline bool sect_empty(const Elf_Shdr *sect)
91907 {
91908 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
91909 @@ -1423,7 +1442,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
91910 {
91911 unsigned int notes, loaded, i;
91912 struct module_notes_attrs *notes_attrs;
91913 - struct bin_attribute *nattr;
91914 + bin_attribute_no_const *nattr;
91915
91916 /* failed to create section attributes, so can't create notes */
91917 if (!mod->sect_attrs)
91918 @@ -1535,7 +1554,7 @@ static void del_usage_links(struct module *mod)
91919 static int module_add_modinfo_attrs(struct module *mod)
91920 {
91921 struct module_attribute *attr;
91922 - struct module_attribute *temp_attr;
91923 + module_attribute_no_const *temp_attr;
91924 int error = 0;
91925 int i;
91926
91927 @@ -1756,21 +1775,21 @@ static void set_section_ro_nx(void *base,
91928
91929 static void unset_module_core_ro_nx(struct module *mod)
91930 {
91931 - set_page_attributes(mod->module_core + mod->core_text_size,
91932 - mod->module_core + mod->core_size,
91933 + set_page_attributes(mod->module_core_rw,
91934 + mod->module_core_rw + mod->core_size_rw,
91935 set_memory_x);
91936 - set_page_attributes(mod->module_core,
91937 - mod->module_core + mod->core_ro_size,
91938 + set_page_attributes(mod->module_core_rx,
91939 + mod->module_core_rx + mod->core_size_rx,
91940 set_memory_rw);
91941 }
91942
91943 static void unset_module_init_ro_nx(struct module *mod)
91944 {
91945 - set_page_attributes(mod->module_init + mod->init_text_size,
91946 - mod->module_init + mod->init_size,
91947 + set_page_attributes(mod->module_init_rw,
91948 + mod->module_init_rw + mod->init_size_rw,
91949 set_memory_x);
91950 - set_page_attributes(mod->module_init,
91951 - mod->module_init + mod->init_ro_size,
91952 + set_page_attributes(mod->module_init_rx,
91953 + mod->module_init_rx + mod->init_size_rx,
91954 set_memory_rw);
91955 }
91956
91957 @@ -1783,14 +1802,14 @@ void set_all_modules_text_rw(void)
91958 list_for_each_entry_rcu(mod, &modules, list) {
91959 if (mod->state == MODULE_STATE_UNFORMED)
91960 continue;
91961 - if ((mod->module_core) && (mod->core_text_size)) {
91962 - set_page_attributes(mod->module_core,
91963 - mod->module_core + mod->core_text_size,
91964 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
91965 + set_page_attributes(mod->module_core_rx,
91966 + mod->module_core_rx + mod->core_size_rx,
91967 set_memory_rw);
91968 }
91969 - if ((mod->module_init) && (mod->init_text_size)) {
91970 - set_page_attributes(mod->module_init,
91971 - mod->module_init + mod->init_text_size,
91972 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
91973 + set_page_attributes(mod->module_init_rx,
91974 + mod->module_init_rx + mod->init_size_rx,
91975 set_memory_rw);
91976 }
91977 }
91978 @@ -1806,14 +1825,14 @@ void set_all_modules_text_ro(void)
91979 list_for_each_entry_rcu(mod, &modules, list) {
91980 if (mod->state == MODULE_STATE_UNFORMED)
91981 continue;
91982 - if ((mod->module_core) && (mod->core_text_size)) {
91983 - set_page_attributes(mod->module_core,
91984 - mod->module_core + mod->core_text_size,
91985 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
91986 + set_page_attributes(mod->module_core_rx,
91987 + mod->module_core_rx + mod->core_size_rx,
91988 set_memory_ro);
91989 }
91990 - if ((mod->module_init) && (mod->init_text_size)) {
91991 - set_page_attributes(mod->module_init,
91992 - mod->module_init + mod->init_text_size,
91993 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
91994 + set_page_attributes(mod->module_init_rx,
91995 + mod->module_init_rx + mod->init_size_rx,
91996 set_memory_ro);
91997 }
91998 }
91999 @@ -1864,16 +1883,19 @@ static void free_module(struct module *mod)
92000
92001 /* This may be NULL, but that's OK */
92002 unset_module_init_ro_nx(mod);
92003 - module_free(mod, mod->module_init);
92004 + module_free(mod, mod->module_init_rw);
92005 + module_free_exec(mod, mod->module_init_rx);
92006 kfree(mod->args);
92007 percpu_modfree(mod);
92008
92009 /* Free lock-classes: */
92010 - lockdep_free_key_range(mod->module_core, mod->core_size);
92011 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
92012 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
92013
92014 /* Finally, free the core (containing the module structure) */
92015 unset_module_core_ro_nx(mod);
92016 - module_free(mod, mod->module_core);
92017 + module_free_exec(mod, mod->module_core_rx);
92018 + module_free(mod, mod->module_core_rw);
92019
92020 #ifdef CONFIG_MPU
92021 update_protections(current->mm);
92022 @@ -1942,9 +1964,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
92023 int ret = 0;
92024 const struct kernel_symbol *ksym;
92025
92026 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
92027 + int is_fs_load = 0;
92028 + int register_filesystem_found = 0;
92029 + char *p;
92030 +
92031 + p = strstr(mod->args, "grsec_modharden_fs");
92032 + if (p) {
92033 + char *endptr = p + sizeof("grsec_modharden_fs") - 1;
92034 + /* copy \0 as well */
92035 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
92036 + is_fs_load = 1;
92037 + }
92038 +#endif
92039 +
92040 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
92041 const char *name = info->strtab + sym[i].st_name;
92042
92043 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
92044 + /* it's a real shame this will never get ripped and copied
92045 + upstream! ;(
92046 + */
92047 + if (is_fs_load && !strcmp(name, "register_filesystem"))
92048 + register_filesystem_found = 1;
92049 +#endif
92050 +
92051 switch (sym[i].st_shndx) {
92052 case SHN_COMMON:
92053 /* Ignore common symbols */
92054 @@ -1969,7 +2013,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
92055 ksym = resolve_symbol_wait(mod, info, name);
92056 /* Ok if resolved. */
92057 if (ksym && !IS_ERR(ksym)) {
92058 + pax_open_kernel();
92059 sym[i].st_value = ksym->value;
92060 + pax_close_kernel();
92061 break;
92062 }
92063
92064 @@ -1988,11 +2034,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
92065 secbase = (unsigned long)mod_percpu(mod);
92066 else
92067 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
92068 + pax_open_kernel();
92069 sym[i].st_value += secbase;
92070 + pax_close_kernel();
92071 break;
92072 }
92073 }
92074
92075 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
92076 + if (is_fs_load && !register_filesystem_found) {
92077 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
92078 + ret = -EPERM;
92079 + }
92080 +#endif
92081 +
92082 return ret;
92083 }
92084
92085 @@ -2076,22 +2131,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
92086 || s->sh_entsize != ~0UL
92087 || strstarts(sname, ".init"))
92088 continue;
92089 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
92090 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
92091 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
92092 + else
92093 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
92094 pr_debug("\t%s\n", sname);
92095 }
92096 - switch (m) {
92097 - case 0: /* executable */
92098 - mod->core_size = debug_align(mod->core_size);
92099 - mod->core_text_size = mod->core_size;
92100 - break;
92101 - case 1: /* RO: text and ro-data */
92102 - mod->core_size = debug_align(mod->core_size);
92103 - mod->core_ro_size = mod->core_size;
92104 - break;
92105 - case 3: /* whole core */
92106 - mod->core_size = debug_align(mod->core_size);
92107 - break;
92108 - }
92109 }
92110
92111 pr_debug("Init section allocation order:\n");
92112 @@ -2105,23 +2150,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
92113 || s->sh_entsize != ~0UL
92114 || !strstarts(sname, ".init"))
92115 continue;
92116 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
92117 - | INIT_OFFSET_MASK);
92118 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
92119 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
92120 + else
92121 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
92122 + s->sh_entsize |= INIT_OFFSET_MASK;
92123 pr_debug("\t%s\n", sname);
92124 }
92125 - switch (m) {
92126 - case 0: /* executable */
92127 - mod->init_size = debug_align(mod->init_size);
92128 - mod->init_text_size = mod->init_size;
92129 - break;
92130 - case 1: /* RO: text and ro-data */
92131 - mod->init_size = debug_align(mod->init_size);
92132 - mod->init_ro_size = mod->init_size;
92133 - break;
92134 - case 3: /* whole init */
92135 - mod->init_size = debug_align(mod->init_size);
92136 - break;
92137 - }
92138 }
92139 }
92140
92141 @@ -2294,7 +2329,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
92142
92143 /* Put symbol section at end of init part of module. */
92144 symsect->sh_flags |= SHF_ALLOC;
92145 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
92146 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
92147 info->index.sym) | INIT_OFFSET_MASK;
92148 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
92149
92150 @@ -2311,13 +2346,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
92151 }
92152
92153 /* Append room for core symbols at end of core part. */
92154 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
92155 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
92156 - mod->core_size += strtab_size;
92157 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
92158 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
92159 + mod->core_size_rx += strtab_size;
92160
92161 /* Put string table section at end of init part of module. */
92162 strsect->sh_flags |= SHF_ALLOC;
92163 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
92164 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
92165 info->index.str) | INIT_OFFSET_MASK;
92166 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
92167 }
92168 @@ -2335,12 +2370,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
92169 /* Make sure we get permanent strtab: don't use info->strtab. */
92170 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
92171
92172 + pax_open_kernel();
92173 +
92174 /* Set types up while we still have access to sections. */
92175 for (i = 0; i < mod->num_symtab; i++)
92176 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
92177
92178 - mod->core_symtab = dst = mod->module_core + info->symoffs;
92179 - mod->core_strtab = s = mod->module_core + info->stroffs;
92180 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
92181 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
92182 src = mod->symtab;
92183 for (ndst = i = 0; i < mod->num_symtab; i++) {
92184 if (i == 0 ||
92185 @@ -2352,6 +2389,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
92186 }
92187 }
92188 mod->core_num_syms = ndst;
92189 +
92190 + pax_close_kernel();
92191 }
92192 #else
92193 static inline void layout_symtab(struct module *mod, struct load_info *info)
92194 @@ -2385,17 +2424,33 @@ void * __weak module_alloc(unsigned long size)
92195 return vmalloc_exec(size);
92196 }
92197
92198 -static void *module_alloc_update_bounds(unsigned long size)
92199 +static void *module_alloc_update_bounds_rw(unsigned long size)
92200 {
92201 void *ret = module_alloc(size);
92202
92203 if (ret) {
92204 mutex_lock(&module_mutex);
92205 /* Update module bounds. */
92206 - if ((unsigned long)ret < module_addr_min)
92207 - module_addr_min = (unsigned long)ret;
92208 - if ((unsigned long)ret + size > module_addr_max)
92209 - module_addr_max = (unsigned long)ret + size;
92210 + if ((unsigned long)ret < module_addr_min_rw)
92211 + module_addr_min_rw = (unsigned long)ret;
92212 + if ((unsigned long)ret + size > module_addr_max_rw)
92213 + module_addr_max_rw = (unsigned long)ret + size;
92214 + mutex_unlock(&module_mutex);
92215 + }
92216 + return ret;
92217 +}
92218 +
92219 +static void *module_alloc_update_bounds_rx(unsigned long size)
92220 +{
92221 + void *ret = module_alloc_exec(size);
92222 +
92223 + if (ret) {
92224 + mutex_lock(&module_mutex);
92225 + /* Update module bounds. */
92226 + if ((unsigned long)ret < module_addr_min_rx)
92227 + module_addr_min_rx = (unsigned long)ret;
92228 + if ((unsigned long)ret + size > module_addr_max_rx)
92229 + module_addr_max_rx = (unsigned long)ret + size;
92230 mutex_unlock(&module_mutex);
92231 }
92232 return ret;
92233 @@ -2652,7 +2707,15 @@ static struct module *setup_load_info(struct load_info *info, int flags)
92234 mod = (void *)info->sechdrs[info->index.mod].sh_addr;
92235
92236 if (info->index.sym == 0) {
92237 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
92238 + /*
92239 + * avoid potentially printing jibberish on attempted load
92240 + * of a module randomized with a different seed
92241 + */
92242 + pr_warn("module has no symbols (stripped?)\n");
92243 +#else
92244 pr_warn("%s: module has no symbols (stripped?)\n", mod->name);
92245 +#endif
92246 return ERR_PTR(-ENOEXEC);
92247 }
92248
92249 @@ -2668,8 +2731,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
92250 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
92251 {
92252 const char *modmagic = get_modinfo(info, "vermagic");
92253 + const char *license = get_modinfo(info, "license");
92254 int err;
92255
92256 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
92257 + if (!license || !license_is_gpl_compatible(license))
92258 + return -ENOEXEC;
92259 +#endif
92260 +
92261 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
92262 modmagic = NULL;
92263
92264 @@ -2694,7 +2763,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
92265 }
92266
92267 /* Set up license info based on the info section */
92268 - set_license(mod, get_modinfo(info, "license"));
92269 + set_license(mod, license);
92270
92271 return 0;
92272 }
92273 @@ -2788,7 +2857,7 @@ static int move_module(struct module *mod, struct load_info *info)
92274 void *ptr;
92275
92276 /* Do the allocs. */
92277 - ptr = module_alloc_update_bounds(mod->core_size);
92278 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
92279 /*
92280 * The pointer to this block is stored in the module structure
92281 * which is inside the block. Just mark it as not being a
92282 @@ -2798,11 +2867,11 @@ static int move_module(struct module *mod, struct load_info *info)
92283 if (!ptr)
92284 return -ENOMEM;
92285
92286 - memset(ptr, 0, mod->core_size);
92287 - mod->module_core = ptr;
92288 + memset(ptr, 0, mod->core_size_rw);
92289 + mod->module_core_rw = ptr;
92290
92291 - if (mod->init_size) {
92292 - ptr = module_alloc_update_bounds(mod->init_size);
92293 + if (mod->init_size_rw) {
92294 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
92295 /*
92296 * The pointer to this block is stored in the module structure
92297 * which is inside the block. This block doesn't need to be
92298 @@ -2811,13 +2880,45 @@ static int move_module(struct module *mod, struct load_info *info)
92299 */
92300 kmemleak_ignore(ptr);
92301 if (!ptr) {
92302 - module_free(mod, mod->module_core);
92303 + module_free(mod, mod->module_core_rw);
92304 return -ENOMEM;
92305 }
92306 - memset(ptr, 0, mod->init_size);
92307 - mod->module_init = ptr;
92308 + memset(ptr, 0, mod->init_size_rw);
92309 + mod->module_init_rw = ptr;
92310 } else
92311 - mod->module_init = NULL;
92312 + mod->module_init_rw = NULL;
92313 +
92314 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
92315 + kmemleak_not_leak(ptr);
92316 + if (!ptr) {
92317 + if (mod->module_init_rw)
92318 + module_free(mod, mod->module_init_rw);
92319 + module_free(mod, mod->module_core_rw);
92320 + return -ENOMEM;
92321 + }
92322 +
92323 + pax_open_kernel();
92324 + memset(ptr, 0, mod->core_size_rx);
92325 + pax_close_kernel();
92326 + mod->module_core_rx = ptr;
92327 +
92328 + if (mod->init_size_rx) {
92329 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
92330 + kmemleak_ignore(ptr);
92331 + if (!ptr && mod->init_size_rx) {
92332 + module_free_exec(mod, mod->module_core_rx);
92333 + if (mod->module_init_rw)
92334 + module_free(mod, mod->module_init_rw);
92335 + module_free(mod, mod->module_core_rw);
92336 + return -ENOMEM;
92337 + }
92338 +
92339 + pax_open_kernel();
92340 + memset(ptr, 0, mod->init_size_rx);
92341 + pax_close_kernel();
92342 + mod->module_init_rx = ptr;
92343 + } else
92344 + mod->module_init_rx = NULL;
92345
92346 /* Transfer each section which specifies SHF_ALLOC */
92347 pr_debug("final section addresses:\n");
92348 @@ -2828,16 +2929,45 @@ static int move_module(struct module *mod, struct load_info *info)
92349 if (!(shdr->sh_flags & SHF_ALLOC))
92350 continue;
92351
92352 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
92353 - dest = mod->module_init
92354 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
92355 - else
92356 - dest = mod->module_core + shdr->sh_entsize;
92357 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
92358 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
92359 + dest = mod->module_init_rw
92360 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
92361 + else
92362 + dest = mod->module_init_rx
92363 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
92364 + } else {
92365 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
92366 + dest = mod->module_core_rw + shdr->sh_entsize;
92367 + else
92368 + dest = mod->module_core_rx + shdr->sh_entsize;
92369 + }
92370 +
92371 + if (shdr->sh_type != SHT_NOBITS) {
92372 +
92373 +#ifdef CONFIG_PAX_KERNEXEC
92374 +#ifdef CONFIG_X86_64
92375 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
92376 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
92377 +#endif
92378 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
92379 + pax_open_kernel();
92380 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
92381 + pax_close_kernel();
92382 + } else
92383 +#endif
92384
92385 - if (shdr->sh_type != SHT_NOBITS)
92386 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
92387 + }
92388 /* Update sh_addr to point to copy in image. */
92389 - shdr->sh_addr = (unsigned long)dest;
92390 +
92391 +#ifdef CONFIG_PAX_KERNEXEC
92392 + if (shdr->sh_flags & SHF_EXECINSTR)
92393 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
92394 + else
92395 +#endif
92396 +
92397 + shdr->sh_addr = (unsigned long)dest;
92398 pr_debug("\t0x%lx %s\n",
92399 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
92400 }
92401 @@ -2894,12 +3024,12 @@ static void flush_module_icache(const struct module *mod)
92402 * Do it before processing of module parameters, so the module
92403 * can provide parameter accessor functions of its own.
92404 */
92405 - if (mod->module_init)
92406 - flush_icache_range((unsigned long)mod->module_init,
92407 - (unsigned long)mod->module_init
92408 - + mod->init_size);
92409 - flush_icache_range((unsigned long)mod->module_core,
92410 - (unsigned long)mod->module_core + mod->core_size);
92411 + if (mod->module_init_rx)
92412 + flush_icache_range((unsigned long)mod->module_init_rx,
92413 + (unsigned long)mod->module_init_rx
92414 + + mod->init_size_rx);
92415 + flush_icache_range((unsigned long)mod->module_core_rx,
92416 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
92417
92418 set_fs(old_fs);
92419 }
92420 @@ -2956,8 +3086,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
92421 static void module_deallocate(struct module *mod, struct load_info *info)
92422 {
92423 percpu_modfree(mod);
92424 - module_free(mod, mod->module_init);
92425 - module_free(mod, mod->module_core);
92426 + module_free_exec(mod, mod->module_init_rx);
92427 + module_free_exec(mod, mod->module_core_rx);
92428 + module_free(mod, mod->module_init_rw);
92429 + module_free(mod, mod->module_core_rw);
92430 }
92431
92432 int __weak module_finalize(const Elf_Ehdr *hdr,
92433 @@ -2970,7 +3102,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
92434 static int post_relocation(struct module *mod, const struct load_info *info)
92435 {
92436 /* Sort exception table now relocations are done. */
92437 + pax_open_kernel();
92438 sort_extable(mod->extable, mod->extable + mod->num_exentries);
92439 + pax_close_kernel();
92440
92441 /* Copy relocated percpu area over. */
92442 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
92443 @@ -3079,11 +3213,12 @@ static int do_init_module(struct module *mod)
92444 mod->strtab = mod->core_strtab;
92445 #endif
92446 unset_module_init_ro_nx(mod);
92447 - module_free(mod, mod->module_init);
92448 - mod->module_init = NULL;
92449 - mod->init_size = 0;
92450 - mod->init_ro_size = 0;
92451 - mod->init_text_size = 0;
92452 + module_free(mod, mod->module_init_rw);
92453 + module_free_exec(mod, mod->module_init_rx);
92454 + mod->module_init_rw = NULL;
92455 + mod->module_init_rx = NULL;
92456 + mod->init_size_rw = 0;
92457 + mod->init_size_rx = 0;
92458 mutex_unlock(&module_mutex);
92459 wake_up_all(&module_wq);
92460
92461 @@ -3151,16 +3286,16 @@ static int complete_formation(struct module *mod, struct load_info *info)
92462 module_bug_finalize(info->hdr, info->sechdrs, mod);
92463
92464 /* Set RO and NX regions for core */
92465 - set_section_ro_nx(mod->module_core,
92466 - mod->core_text_size,
92467 - mod->core_ro_size,
92468 - mod->core_size);
92469 + set_section_ro_nx(mod->module_core_rx,
92470 + mod->core_size_rx,
92471 + mod->core_size_rx,
92472 + mod->core_size_rx);
92473
92474 /* Set RO and NX regions for init */
92475 - set_section_ro_nx(mod->module_init,
92476 - mod->init_text_size,
92477 - mod->init_ro_size,
92478 - mod->init_size);
92479 + set_section_ro_nx(mod->module_init_rx,
92480 + mod->init_size_rx,
92481 + mod->init_size_rx,
92482 + mod->init_size_rx);
92483
92484 /* Mark state as coming so strong_try_module_get() ignores us,
92485 * but kallsyms etc. can see us. */
92486 @@ -3244,9 +3379,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
92487 if (err)
92488 goto free_unload;
92489
92490 + /* Now copy in args */
92491 + mod->args = strndup_user(uargs, ~0UL >> 1);
92492 + if (IS_ERR(mod->args)) {
92493 + err = PTR_ERR(mod->args);
92494 + goto free_unload;
92495 + }
92496 +
92497 /* Set up MODINFO_ATTR fields */
92498 setup_modinfo(mod, info);
92499
92500 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
92501 + {
92502 + char *p, *p2;
92503 +
92504 + if (strstr(mod->args, "grsec_modharden_netdev")) {
92505 + 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);
92506 + err = -EPERM;
92507 + goto free_modinfo;
92508 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
92509 + p += sizeof("grsec_modharden_normal") - 1;
92510 + p2 = strstr(p, "_");
92511 + if (p2) {
92512 + *p2 = '\0';
92513 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
92514 + *p2 = '_';
92515 + }
92516 + err = -EPERM;
92517 + goto free_modinfo;
92518 + }
92519 + }
92520 +#endif
92521 +
92522 /* Fix up syms, so that st_value is a pointer to location. */
92523 err = simplify_symbols(mod, info);
92524 if (err < 0)
92525 @@ -3262,13 +3426,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
92526
92527 flush_module_icache(mod);
92528
92529 - /* Now copy in args */
92530 - mod->args = strndup_user(uargs, ~0UL >> 1);
92531 - if (IS_ERR(mod->args)) {
92532 - err = PTR_ERR(mod->args);
92533 - goto free_arch_cleanup;
92534 - }
92535 -
92536 dynamic_debug_setup(info->debug, info->num_debug);
92537
92538 /* Ftrace init must be called in the MODULE_STATE_UNFORMED state */
92539 @@ -3311,11 +3468,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
92540 ddebug_cleanup:
92541 dynamic_debug_remove(info->debug);
92542 synchronize_sched();
92543 - kfree(mod->args);
92544 - free_arch_cleanup:
92545 module_arch_cleanup(mod);
92546 free_modinfo:
92547 free_modinfo(mod);
92548 + kfree(mod->args);
92549 free_unload:
92550 module_unload_free(mod);
92551 unlink_mod:
92552 @@ -3398,10 +3554,16 @@ static const char *get_ksymbol(struct module *mod,
92553 unsigned long nextval;
92554
92555 /* At worse, next value is at end of module */
92556 - if (within_module_init(addr, mod))
92557 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
92558 + if (within_module_init_rx(addr, mod))
92559 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
92560 + else if (within_module_init_rw(addr, mod))
92561 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
92562 + else if (within_module_core_rx(addr, mod))
92563 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
92564 + else if (within_module_core_rw(addr, mod))
92565 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
92566 else
92567 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
92568 + return NULL;
92569
92570 /* Scan for closest preceding symbol, and next symbol. (ELF
92571 starts real symbols at 1). */
92572 @@ -3652,7 +3814,7 @@ static int m_show(struct seq_file *m, void *p)
92573 return 0;
92574
92575 seq_printf(m, "%s %u",
92576 - mod->name, mod->init_size + mod->core_size);
92577 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
92578 print_unload_info(m, mod);
92579
92580 /* Informative for users. */
92581 @@ -3661,7 +3823,7 @@ static int m_show(struct seq_file *m, void *p)
92582 mod->state == MODULE_STATE_COMING ? "Loading":
92583 "Live");
92584 /* Used by oprofile and other similar tools. */
92585 - seq_printf(m, " 0x%pK", mod->module_core);
92586 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
92587
92588 /* Taints info */
92589 if (mod->taints)
92590 @@ -3697,7 +3859,17 @@ static const struct file_operations proc_modules_operations = {
92591
92592 static int __init proc_modules_init(void)
92593 {
92594 +#ifndef CONFIG_GRKERNSEC_HIDESYM
92595 +#ifdef CONFIG_GRKERNSEC_PROC_USER
92596 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
92597 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
92598 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
92599 +#else
92600 proc_create("modules", 0, NULL, &proc_modules_operations);
92601 +#endif
92602 +#else
92603 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
92604 +#endif
92605 return 0;
92606 }
92607 module_init(proc_modules_init);
92608 @@ -3758,14 +3930,14 @@ struct module *__module_address(unsigned long addr)
92609 {
92610 struct module *mod;
92611
92612 - if (addr < module_addr_min || addr > module_addr_max)
92613 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
92614 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
92615 return NULL;
92616
92617 list_for_each_entry_rcu(mod, &modules, list) {
92618 if (mod->state == MODULE_STATE_UNFORMED)
92619 continue;
92620 - if (within_module_core(addr, mod)
92621 - || within_module_init(addr, mod))
92622 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
92623 return mod;
92624 }
92625 return NULL;
92626 @@ -3800,11 +3972,20 @@ bool is_module_text_address(unsigned long addr)
92627 */
92628 struct module *__module_text_address(unsigned long addr)
92629 {
92630 - struct module *mod = __module_address(addr);
92631 + struct module *mod;
92632 +
92633 +#ifdef CONFIG_X86_32
92634 + addr = ktla_ktva(addr);
92635 +#endif
92636 +
92637 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
92638 + return NULL;
92639 +
92640 + mod = __module_address(addr);
92641 +
92642 if (mod) {
92643 /* Make sure it's within the text section. */
92644 - if (!within(addr, mod->module_init, mod->init_text_size)
92645 - && !within(addr, mod->module_core, mod->core_text_size))
92646 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
92647 mod = NULL;
92648 }
92649 return mod;
92650 diff --git a/kernel/notifier.c b/kernel/notifier.c
92651 index 4803da6..1c5eea6 100644
92652 --- a/kernel/notifier.c
92653 +++ b/kernel/notifier.c
92654 @@ -5,6 +5,7 @@
92655 #include <linux/rcupdate.h>
92656 #include <linux/vmalloc.h>
92657 #include <linux/reboot.h>
92658 +#include <linux/mm.h>
92659
92660 /*
92661 * Notifier list for kernel code which wants to be called
92662 @@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
92663 while ((*nl) != NULL) {
92664 if (n->priority > (*nl)->priority)
92665 break;
92666 - nl = &((*nl)->next);
92667 + nl = (struct notifier_block **)&((*nl)->next);
92668 }
92669 - n->next = *nl;
92670 + pax_open_kernel();
92671 + *(const void **)&n->next = *nl;
92672 rcu_assign_pointer(*nl, n);
92673 + pax_close_kernel();
92674 return 0;
92675 }
92676
92677 @@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
92678 return 0;
92679 if (n->priority > (*nl)->priority)
92680 break;
92681 - nl = &((*nl)->next);
92682 + nl = (struct notifier_block **)&((*nl)->next);
92683 }
92684 - n->next = *nl;
92685 + pax_open_kernel();
92686 + *(const void **)&n->next = *nl;
92687 rcu_assign_pointer(*nl, n);
92688 + pax_close_kernel();
92689 return 0;
92690 }
92691
92692 @@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
92693 {
92694 while ((*nl) != NULL) {
92695 if ((*nl) == n) {
92696 + pax_open_kernel();
92697 rcu_assign_pointer(*nl, n->next);
92698 + pax_close_kernel();
92699 return 0;
92700 }
92701 - nl = &((*nl)->next);
92702 + nl = (struct notifier_block **)&((*nl)->next);
92703 }
92704 return -ENOENT;
92705 }
92706 diff --git a/kernel/padata.c b/kernel/padata.c
92707 index 161402f..598814c 100644
92708 --- a/kernel/padata.c
92709 +++ b/kernel/padata.c
92710 @@ -54,7 +54,7 @@ static int padata_cpu_hash(struct parallel_data *pd)
92711 * seq_nr mod. number of cpus in use.
92712 */
92713
92714 - seq_nr = atomic_inc_return(&pd->seq_nr);
92715 + seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
92716 cpu_index = seq_nr % cpumask_weight(pd->cpumask.pcpu);
92717
92718 return padata_index_to_cpu(pd, cpu_index);
92719 @@ -428,7 +428,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
92720 padata_init_pqueues(pd);
92721 padata_init_squeues(pd);
92722 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
92723 - atomic_set(&pd->seq_nr, -1);
92724 + atomic_set_unchecked(&pd->seq_nr, -1);
92725 atomic_set(&pd->reorder_objects, 0);
92726 atomic_set(&pd->refcnt, 0);
92727 pd->pinst = pinst;
92728 diff --git a/kernel/panic.c b/kernel/panic.c
92729 index 62e16ce..9db5047b 100644
92730 --- a/kernel/panic.c
92731 +++ b/kernel/panic.c
92732 @@ -53,7 +53,7 @@ EXPORT_SYMBOL(panic_blink);
92733 /*
92734 * Stop ourself in panic -- architecture code may override this
92735 */
92736 -void __weak panic_smp_self_stop(void)
92737 +void __weak __noreturn panic_smp_self_stop(void)
92738 {
92739 while (1)
92740 cpu_relax();
92741 @@ -420,7 +420,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
92742 disable_trace_on_warning();
92743
92744 pr_warn("------------[ cut here ]------------\n");
92745 - pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
92746 + pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
92747 raw_smp_processor_id(), current->pid, file, line, caller);
92748
92749 if (args)
92750 @@ -474,7 +474,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
92751 */
92752 __visible void __stack_chk_fail(void)
92753 {
92754 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
92755 + dump_stack();
92756 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
92757 __builtin_return_address(0));
92758 }
92759 EXPORT_SYMBOL(__stack_chk_fail);
92760 diff --git a/kernel/pid.c b/kernel/pid.c
92761 index 9b9a266..c20ef80 100644
92762 --- a/kernel/pid.c
92763 +++ b/kernel/pid.c
92764 @@ -33,6 +33,7 @@
92765 #include <linux/rculist.h>
92766 #include <linux/bootmem.h>
92767 #include <linux/hash.h>
92768 +#include <linux/security.h>
92769 #include <linux/pid_namespace.h>
92770 #include <linux/init_task.h>
92771 #include <linux/syscalls.h>
92772 @@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
92773
92774 int pid_max = PID_MAX_DEFAULT;
92775
92776 -#define RESERVED_PIDS 300
92777 +#define RESERVED_PIDS 500
92778
92779 int pid_max_min = RESERVED_PIDS + 1;
92780 int pid_max_max = PID_MAX_LIMIT;
92781 @@ -445,10 +446,18 @@ EXPORT_SYMBOL(pid_task);
92782 */
92783 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
92784 {
92785 + struct task_struct *task;
92786 +
92787 rcu_lockdep_assert(rcu_read_lock_held(),
92788 "find_task_by_pid_ns() needs rcu_read_lock()"
92789 " protection");
92790 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
92791 +
92792 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
92793 +
92794 + if (gr_pid_is_chrooted(task))
92795 + return NULL;
92796 +
92797 + return task;
92798 }
92799
92800 struct task_struct *find_task_by_vpid(pid_t vnr)
92801 @@ -456,6 +465,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
92802 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
92803 }
92804
92805 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
92806 +{
92807 + rcu_lockdep_assert(rcu_read_lock_held(),
92808 + "find_task_by_pid_ns() needs rcu_read_lock()"
92809 + " protection");
92810 + return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
92811 +}
92812 +
92813 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
92814 {
92815 struct pid *pid;
92816 diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
92817 index db95d8e..a0ca23f 100644
92818 --- a/kernel/pid_namespace.c
92819 +++ b/kernel/pid_namespace.c
92820 @@ -253,7 +253,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
92821 void __user *buffer, size_t *lenp, loff_t *ppos)
92822 {
92823 struct pid_namespace *pid_ns = task_active_pid_ns(current);
92824 - struct ctl_table tmp = *table;
92825 + ctl_table_no_const tmp = *table;
92826
92827 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
92828 return -EPERM;
92829 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
92830 index 3b89464..5e38379 100644
92831 --- a/kernel/posix-cpu-timers.c
92832 +++ b/kernel/posix-cpu-timers.c
92833 @@ -1464,14 +1464,14 @@ struct k_clock clock_posix_cpu = {
92834
92835 static __init int init_posix_cpu_timers(void)
92836 {
92837 - struct k_clock process = {
92838 + static struct k_clock process = {
92839 .clock_getres = process_cpu_clock_getres,
92840 .clock_get = process_cpu_clock_get,
92841 .timer_create = process_cpu_timer_create,
92842 .nsleep = process_cpu_nsleep,
92843 .nsleep_restart = process_cpu_nsleep_restart,
92844 };
92845 - struct k_clock thread = {
92846 + static struct k_clock thread = {
92847 .clock_getres = thread_cpu_clock_getres,
92848 .clock_get = thread_cpu_clock_get,
92849 .timer_create = thread_cpu_timer_create,
92850 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
92851 index 424c2d4..679242f 100644
92852 --- a/kernel/posix-timers.c
92853 +++ b/kernel/posix-timers.c
92854 @@ -43,6 +43,7 @@
92855 #include <linux/hash.h>
92856 #include <linux/posix-clock.h>
92857 #include <linux/posix-timers.h>
92858 +#include <linux/grsecurity.h>
92859 #include <linux/syscalls.h>
92860 #include <linux/wait.h>
92861 #include <linux/workqueue.h>
92862 @@ -122,7 +123,7 @@ static DEFINE_SPINLOCK(hash_lock);
92863 * which we beg off on and pass to do_sys_settimeofday().
92864 */
92865
92866 -static struct k_clock posix_clocks[MAX_CLOCKS];
92867 +static struct k_clock *posix_clocks[MAX_CLOCKS];
92868
92869 /*
92870 * These ones are defined below.
92871 @@ -275,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
92872 */
92873 static __init int init_posix_timers(void)
92874 {
92875 - struct k_clock clock_realtime = {
92876 + static struct k_clock clock_realtime = {
92877 .clock_getres = hrtimer_get_res,
92878 .clock_get = posix_clock_realtime_get,
92879 .clock_set = posix_clock_realtime_set,
92880 @@ -287,7 +288,7 @@ static __init int init_posix_timers(void)
92881 .timer_get = common_timer_get,
92882 .timer_del = common_timer_del,
92883 };
92884 - struct k_clock clock_monotonic = {
92885 + static struct k_clock clock_monotonic = {
92886 .clock_getres = hrtimer_get_res,
92887 .clock_get = posix_ktime_get_ts,
92888 .nsleep = common_nsleep,
92889 @@ -297,19 +298,19 @@ static __init int init_posix_timers(void)
92890 .timer_get = common_timer_get,
92891 .timer_del = common_timer_del,
92892 };
92893 - struct k_clock clock_monotonic_raw = {
92894 + static struct k_clock clock_monotonic_raw = {
92895 .clock_getres = hrtimer_get_res,
92896 .clock_get = posix_get_monotonic_raw,
92897 };
92898 - struct k_clock clock_realtime_coarse = {
92899 + static struct k_clock clock_realtime_coarse = {
92900 .clock_getres = posix_get_coarse_res,
92901 .clock_get = posix_get_realtime_coarse,
92902 };
92903 - struct k_clock clock_monotonic_coarse = {
92904 + static struct k_clock clock_monotonic_coarse = {
92905 .clock_getres = posix_get_coarse_res,
92906 .clock_get = posix_get_monotonic_coarse,
92907 };
92908 - struct k_clock clock_tai = {
92909 + static struct k_clock clock_tai = {
92910 .clock_getres = hrtimer_get_res,
92911 .clock_get = posix_get_tai,
92912 .nsleep = common_nsleep,
92913 @@ -319,7 +320,7 @@ static __init int init_posix_timers(void)
92914 .timer_get = common_timer_get,
92915 .timer_del = common_timer_del,
92916 };
92917 - struct k_clock clock_boottime = {
92918 + static struct k_clock clock_boottime = {
92919 .clock_getres = hrtimer_get_res,
92920 .clock_get = posix_get_boottime,
92921 .nsleep = common_nsleep,
92922 @@ -531,7 +532,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
92923 return;
92924 }
92925
92926 - posix_clocks[clock_id] = *new_clock;
92927 + posix_clocks[clock_id] = new_clock;
92928 }
92929 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
92930
92931 @@ -577,9 +578,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
92932 return (id & CLOCKFD_MASK) == CLOCKFD ?
92933 &clock_posix_dynamic : &clock_posix_cpu;
92934
92935 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
92936 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
92937 return NULL;
92938 - return &posix_clocks[id];
92939 + return posix_clocks[id];
92940 }
92941
92942 static int common_timer_create(struct k_itimer *new_timer)
92943 @@ -597,7 +598,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
92944 struct k_clock *kc = clockid_to_kclock(which_clock);
92945 struct k_itimer *new_timer;
92946 int error, new_timer_id;
92947 - sigevent_t event;
92948 + sigevent_t event = { };
92949 int it_id_set = IT_ID_NOT_SET;
92950
92951 if (!kc)
92952 @@ -1011,6 +1012,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
92953 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
92954 return -EFAULT;
92955
92956 + /* only the CLOCK_REALTIME clock can be set, all other clocks
92957 + have their clock_set fptr set to a nosettime dummy function
92958 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
92959 + call common_clock_set, which calls do_sys_settimeofday, which
92960 + we hook
92961 + */
92962 +
92963 return kc->clock_set(which_clock, &new_tp);
92964 }
92965
92966 diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
92967 index 9a83d78..128bfc0 100644
92968 --- a/kernel/power/Kconfig
92969 +++ b/kernel/power/Kconfig
92970 @@ -24,6 +24,8 @@ config HIBERNATE_CALLBACKS
92971 config HIBERNATION
92972 bool "Hibernation (aka 'suspend to disk')"
92973 depends on SWAP && ARCH_HIBERNATION_POSSIBLE
92974 + depends on !GRKERNSEC_KMEM
92975 + depends on !PAX_MEMORY_SANITIZE
92976 select HIBERNATE_CALLBACKS
92977 select LZO_COMPRESS
92978 select LZO_DECOMPRESS
92979 diff --git a/kernel/power/process.c b/kernel/power/process.c
92980 index 4ee194e..925778f 100644
92981 --- a/kernel/power/process.c
92982 +++ b/kernel/power/process.c
92983 @@ -35,6 +35,7 @@ static int try_to_freeze_tasks(bool user_only)
92984 unsigned int elapsed_msecs;
92985 bool wakeup = false;
92986 int sleep_usecs = USEC_PER_MSEC;
92987 + bool timedout = false;
92988
92989 do_gettimeofday(&start);
92990
92991 @@ -45,13 +46,20 @@ static int try_to_freeze_tasks(bool user_only)
92992
92993 while (true) {
92994 todo = 0;
92995 + if (time_after(jiffies, end_time))
92996 + timedout = true;
92997 read_lock(&tasklist_lock);
92998 do_each_thread(g, p) {
92999 if (p == current || !freeze_task(p))
93000 continue;
93001
93002 - if (!freezer_should_skip(p))
93003 + if (!freezer_should_skip(p)) {
93004 todo++;
93005 + if (timedout) {
93006 + printk(KERN_ERR "Task refusing to freeze:\n");
93007 + sched_show_task(p);
93008 + }
93009 + }
93010 } while_each_thread(g, p);
93011 read_unlock(&tasklist_lock);
93012
93013 @@ -60,7 +68,7 @@ static int try_to_freeze_tasks(bool user_only)
93014 todo += wq_busy;
93015 }
93016
93017 - if (!todo || time_after(jiffies, end_time))
93018 + if (!todo || timedout)
93019 break;
93020
93021 if (pm_wakeup_pending()) {
93022 diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
93023 index 13e839d..8a71f12 100644
93024 --- a/kernel/printk/printk.c
93025 +++ b/kernel/printk/printk.c
93026 @@ -480,6 +480,11 @@ static int check_syslog_permissions(int type, bool from_file)
93027 if (from_file && type != SYSLOG_ACTION_OPEN)
93028 return 0;
93029
93030 +#ifdef CONFIG_GRKERNSEC_DMESG
93031 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
93032 + return -EPERM;
93033 +#endif
93034 +
93035 if (syslog_action_restricted(type)) {
93036 if (capable(CAP_SYSLOG))
93037 return 0;
93038 diff --git a/kernel/profile.c b/kernel/profile.c
93039 index 54bf5ba..df6e0a2 100644
93040 --- a/kernel/profile.c
93041 +++ b/kernel/profile.c
93042 @@ -37,7 +37,7 @@ struct profile_hit {
93043 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
93044 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
93045
93046 -static atomic_t *prof_buffer;
93047 +static atomic_unchecked_t *prof_buffer;
93048 static unsigned long prof_len, prof_shift;
93049
93050 int prof_on __read_mostly;
93051 @@ -256,7 +256,7 @@ static void profile_flip_buffers(void)
93052 hits[i].pc = 0;
93053 continue;
93054 }
93055 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
93056 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
93057 hits[i].hits = hits[i].pc = 0;
93058 }
93059 }
93060 @@ -317,9 +317,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
93061 * Add the current hit(s) and flush the write-queue out
93062 * to the global buffer:
93063 */
93064 - atomic_add(nr_hits, &prof_buffer[pc]);
93065 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
93066 for (i = 0; i < NR_PROFILE_HIT; ++i) {
93067 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
93068 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
93069 hits[i].pc = hits[i].hits = 0;
93070 }
93071 out:
93072 @@ -394,7 +394,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
93073 {
93074 unsigned long pc;
93075 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
93076 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
93077 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
93078 }
93079 #endif /* !CONFIG_SMP */
93080
93081 @@ -490,7 +490,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
93082 return -EFAULT;
93083 buf++; p++; count--; read++;
93084 }
93085 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
93086 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
93087 if (copy_to_user(buf, (void *)pnt, count))
93088 return -EFAULT;
93089 read += count;
93090 @@ -521,7 +521,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
93091 }
93092 #endif
93093 profile_discard_flip_buffers();
93094 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
93095 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
93096 return count;
93097 }
93098
93099 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
93100 index adf9862..9d86345 100644
93101 --- a/kernel/ptrace.c
93102 +++ b/kernel/ptrace.c
93103 @@ -327,7 +327,7 @@ static int ptrace_attach(struct task_struct *task, long request,
93104 if (seize)
93105 flags |= PT_SEIZED;
93106 rcu_read_lock();
93107 - if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
93108 + if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
93109 flags |= PT_PTRACE_CAP;
93110 rcu_read_unlock();
93111 task->ptrace = flags;
93112 @@ -538,7 +538,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
93113 break;
93114 return -EIO;
93115 }
93116 - if (copy_to_user(dst, buf, retval))
93117 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
93118 return -EFAULT;
93119 copied += retval;
93120 src += retval;
93121 @@ -806,7 +806,7 @@ int ptrace_request(struct task_struct *child, long request,
93122 bool seized = child->ptrace & PT_SEIZED;
93123 int ret = -EIO;
93124 siginfo_t siginfo, *si;
93125 - void __user *datavp = (void __user *) data;
93126 + void __user *datavp = (__force void __user *) data;
93127 unsigned long __user *datalp = datavp;
93128 unsigned long flags;
93129
93130 @@ -1052,14 +1052,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
93131 goto out;
93132 }
93133
93134 + if (gr_handle_ptrace(child, request)) {
93135 + ret = -EPERM;
93136 + goto out_put_task_struct;
93137 + }
93138 +
93139 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
93140 ret = ptrace_attach(child, request, addr, data);
93141 /*
93142 * Some architectures need to do book-keeping after
93143 * a ptrace attach.
93144 */
93145 - if (!ret)
93146 + if (!ret) {
93147 arch_ptrace_attach(child);
93148 + gr_audit_ptrace(child);
93149 + }
93150 goto out_put_task_struct;
93151 }
93152
93153 @@ -1087,7 +1094,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
93154 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
93155 if (copied != sizeof(tmp))
93156 return -EIO;
93157 - return put_user(tmp, (unsigned long __user *)data);
93158 + return put_user(tmp, (__force unsigned long __user *)data);
93159 }
93160
93161 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
93162 @@ -1181,7 +1188,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
93163 }
93164
93165 COMPAT_SYSCALL_DEFINE4(ptrace, compat_long_t, request, compat_long_t, pid,
93166 - compat_long_t, addr, compat_long_t, data)
93167 + compat_ulong_t, addr, compat_ulong_t, data)
93168 {
93169 struct task_struct *child;
93170 long ret;
93171 @@ -1197,14 +1204,21 @@ COMPAT_SYSCALL_DEFINE4(ptrace, compat_long_t, request, compat_long_t, pid,
93172 goto out;
93173 }
93174
93175 + if (gr_handle_ptrace(child, request)) {
93176 + ret = -EPERM;
93177 + goto out_put_task_struct;
93178 + }
93179 +
93180 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
93181 ret = ptrace_attach(child, request, addr, data);
93182 /*
93183 * Some architectures need to do book-keeping after
93184 * a ptrace attach.
93185 */
93186 - if (!ret)
93187 + if (!ret) {
93188 arch_ptrace_attach(child);
93189 + gr_audit_ptrace(child);
93190 + }
93191 goto out_put_task_struct;
93192 }
93193
93194 diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
93195 index 948a769..5ca842b 100644
93196 --- a/kernel/rcu/rcutorture.c
93197 +++ b/kernel/rcu/rcutorture.c
93198 @@ -124,12 +124,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
93199 rcu_torture_count) = { 0 };
93200 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
93201 rcu_torture_batch) = { 0 };
93202 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
93203 -static atomic_t n_rcu_torture_alloc;
93204 -static atomic_t n_rcu_torture_alloc_fail;
93205 -static atomic_t n_rcu_torture_free;
93206 -static atomic_t n_rcu_torture_mberror;
93207 -static atomic_t n_rcu_torture_error;
93208 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
93209 +static atomic_unchecked_t n_rcu_torture_alloc;
93210 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
93211 +static atomic_unchecked_t n_rcu_torture_free;
93212 +static atomic_unchecked_t n_rcu_torture_mberror;
93213 +static atomic_unchecked_t n_rcu_torture_error;
93214 static long n_rcu_torture_barrier_error;
93215 static long n_rcu_torture_boost_ktrerror;
93216 static long n_rcu_torture_boost_rterror;
93217 @@ -200,11 +200,11 @@ rcu_torture_alloc(void)
93218
93219 spin_lock_bh(&rcu_torture_lock);
93220 if (list_empty(&rcu_torture_freelist)) {
93221 - atomic_inc(&n_rcu_torture_alloc_fail);
93222 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
93223 spin_unlock_bh(&rcu_torture_lock);
93224 return NULL;
93225 }
93226 - atomic_inc(&n_rcu_torture_alloc);
93227 + atomic_inc_unchecked(&n_rcu_torture_alloc);
93228 p = rcu_torture_freelist.next;
93229 list_del_init(p);
93230 spin_unlock_bh(&rcu_torture_lock);
93231 @@ -217,7 +217,7 @@ rcu_torture_alloc(void)
93232 static void
93233 rcu_torture_free(struct rcu_torture *p)
93234 {
93235 - atomic_inc(&n_rcu_torture_free);
93236 + atomic_inc_unchecked(&n_rcu_torture_free);
93237 spin_lock_bh(&rcu_torture_lock);
93238 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
93239 spin_unlock_bh(&rcu_torture_lock);
93240 @@ -301,7 +301,7 @@ rcu_torture_pipe_update_one(struct rcu_torture *rp)
93241 i = rp->rtort_pipe_count;
93242 if (i > RCU_TORTURE_PIPE_LEN)
93243 i = RCU_TORTURE_PIPE_LEN;
93244 - atomic_inc(&rcu_torture_wcount[i]);
93245 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
93246 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
93247 rp->rtort_mbtest = 0;
93248 return true;
93249 @@ -808,7 +808,7 @@ rcu_torture_writer(void *arg)
93250 i = old_rp->rtort_pipe_count;
93251 if (i > RCU_TORTURE_PIPE_LEN)
93252 i = RCU_TORTURE_PIPE_LEN;
93253 - atomic_inc(&rcu_torture_wcount[i]);
93254 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
93255 old_rp->rtort_pipe_count++;
93256 switch (synctype[torture_random(&rand) % nsynctypes]) {
93257 case RTWS_DEF_FREE:
93258 @@ -926,7 +926,7 @@ static void rcu_torture_timer(unsigned long unused)
93259 return;
93260 }
93261 if (p->rtort_mbtest == 0)
93262 - atomic_inc(&n_rcu_torture_mberror);
93263 + atomic_inc_unchecked(&n_rcu_torture_mberror);
93264 spin_lock(&rand_lock);
93265 cur_ops->read_delay(&rand);
93266 n_rcu_torture_timers++;
93267 @@ -996,7 +996,7 @@ rcu_torture_reader(void *arg)
93268 continue;
93269 }
93270 if (p->rtort_mbtest == 0)
93271 - atomic_inc(&n_rcu_torture_mberror);
93272 + atomic_inc_unchecked(&n_rcu_torture_mberror);
93273 cur_ops->read_delay(&rand);
93274 preempt_disable();
93275 pipe_count = p->rtort_pipe_count;
93276 @@ -1054,15 +1054,15 @@ rcu_torture_printk(char *page)
93277 }
93278 page += sprintf(page, "%s%s ", torture_type, TORTURE_FLAG);
93279 page += sprintf(page,
93280 - "rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
93281 + "rtc: %pP ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
93282 rcu_torture_current,
93283 rcu_torture_current_version,
93284 list_empty(&rcu_torture_freelist),
93285 - atomic_read(&n_rcu_torture_alloc),
93286 - atomic_read(&n_rcu_torture_alloc_fail),
93287 - atomic_read(&n_rcu_torture_free));
93288 + atomic_read_unchecked(&n_rcu_torture_alloc),
93289 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
93290 + atomic_read_unchecked(&n_rcu_torture_free));
93291 page += sprintf(page, "rtmbe: %d rtbke: %ld rtbre: %ld ",
93292 - atomic_read(&n_rcu_torture_mberror),
93293 + atomic_read_unchecked(&n_rcu_torture_mberror),
93294 n_rcu_torture_boost_ktrerror,
93295 n_rcu_torture_boost_rterror);
93296 page += sprintf(page, "rtbf: %ld rtb: %ld nt: %ld ",
93297 @@ -1075,14 +1075,14 @@ rcu_torture_printk(char *page)
93298 n_barrier_attempts,
93299 n_rcu_torture_barrier_error);
93300 page += sprintf(page, "\n%s%s ", torture_type, TORTURE_FLAG);
93301 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
93302 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
93303 n_rcu_torture_barrier_error != 0 ||
93304 n_rcu_torture_boost_ktrerror != 0 ||
93305 n_rcu_torture_boost_rterror != 0 ||
93306 n_rcu_torture_boost_failure != 0 ||
93307 i > 1) {
93308 page += sprintf(page, "!!! ");
93309 - atomic_inc(&n_rcu_torture_error);
93310 + atomic_inc_unchecked(&n_rcu_torture_error);
93311 WARN_ON_ONCE(1);
93312 }
93313 page += sprintf(page, "Reader Pipe: ");
93314 @@ -1096,7 +1096,7 @@ rcu_torture_printk(char *page)
93315 page += sprintf(page, "Free-Block Circulation: ");
93316 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
93317 page += sprintf(page, " %d",
93318 - atomic_read(&rcu_torture_wcount[i]));
93319 + atomic_read_unchecked(&rcu_torture_wcount[i]));
93320 }
93321 page += sprintf(page, "\n");
93322 if (cur_ops->stats)
93323 @@ -1461,7 +1461,7 @@ rcu_torture_cleanup(void)
93324
93325 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
93326
93327 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
93328 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
93329 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
93330 else if (torture_onoff_failures())
93331 rcu_torture_print_module_parms(cur_ops,
93332 @@ -1584,18 +1584,18 @@ rcu_torture_init(void)
93333
93334 rcu_torture_current = NULL;
93335 rcu_torture_current_version = 0;
93336 - atomic_set(&n_rcu_torture_alloc, 0);
93337 - atomic_set(&n_rcu_torture_alloc_fail, 0);
93338 - atomic_set(&n_rcu_torture_free, 0);
93339 - atomic_set(&n_rcu_torture_mberror, 0);
93340 - atomic_set(&n_rcu_torture_error, 0);
93341 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
93342 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
93343 + atomic_set_unchecked(&n_rcu_torture_free, 0);
93344 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
93345 + atomic_set_unchecked(&n_rcu_torture_error, 0);
93346 n_rcu_torture_barrier_error = 0;
93347 n_rcu_torture_boost_ktrerror = 0;
93348 n_rcu_torture_boost_rterror = 0;
93349 n_rcu_torture_boost_failure = 0;
93350 n_rcu_torture_boosts = 0;
93351 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
93352 - atomic_set(&rcu_torture_wcount[i], 0);
93353 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
93354 for_each_possible_cpu(cpu) {
93355 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
93356 per_cpu(rcu_torture_count, cpu)[i] = 0;
93357 diff --git a/kernel/rcu/srcu.c b/kernel/rcu/srcu.c
93358 index c639556..cf0a0d5 100644
93359 --- a/kernel/rcu/srcu.c
93360 +++ b/kernel/rcu/srcu.c
93361 @@ -298,9 +298,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
93362
93363 idx = ACCESS_ONCE(sp->completed) & 0x1;
93364 preempt_disable();
93365 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
93366 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
93367 smp_mb(); /* B */ /* Avoid leaking the critical section. */
93368 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
93369 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
93370 preempt_enable();
93371 return idx;
93372 }
93373 diff --git a/kernel/rcu/tiny.c b/kernel/rcu/tiny.c
93374 index d9efcc1..ea543e9 100644
93375 --- a/kernel/rcu/tiny.c
93376 +++ b/kernel/rcu/tiny.c
93377 @@ -42,7 +42,7 @@
93378 /* Forward declarations for tiny_plugin.h. */
93379 struct rcu_ctrlblk;
93380 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
93381 -static void rcu_process_callbacks(struct softirq_action *unused);
93382 +static void rcu_process_callbacks(void);
93383 static void __call_rcu(struct rcu_head *head,
93384 void (*func)(struct rcu_head *rcu),
93385 struct rcu_ctrlblk *rcp);
93386 @@ -308,7 +308,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
93387 false));
93388 }
93389
93390 -static void rcu_process_callbacks(struct softirq_action *unused)
93391 +static __latent_entropy void rcu_process_callbacks(void)
93392 {
93393 __rcu_process_callbacks(&rcu_sched_ctrlblk);
93394 __rcu_process_callbacks(&rcu_bh_ctrlblk);
93395 diff --git a/kernel/rcu/tiny_plugin.h b/kernel/rcu/tiny_plugin.h
93396 index 858c565..7efd915 100644
93397 --- a/kernel/rcu/tiny_plugin.h
93398 +++ b/kernel/rcu/tiny_plugin.h
93399 @@ -152,17 +152,17 @@ static void check_cpu_stall(struct rcu_ctrlblk *rcp)
93400 dump_stack();
93401 }
93402 if (*rcp->curtail && ULONG_CMP_GE(j, js))
93403 - ACCESS_ONCE(rcp->jiffies_stall) = jiffies +
93404 + ACCESS_ONCE_RW(rcp->jiffies_stall) = jiffies +
93405 3 * rcu_jiffies_till_stall_check() + 3;
93406 else if (ULONG_CMP_GE(j, js))
93407 - ACCESS_ONCE(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
93408 + ACCESS_ONCE_RW(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
93409 }
93410
93411 static void reset_cpu_stall_ticks(struct rcu_ctrlblk *rcp)
93412 {
93413 rcp->ticks_this_gp = 0;
93414 rcp->gp_start = jiffies;
93415 - ACCESS_ONCE(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
93416 + ACCESS_ONCE_RW(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
93417 }
93418
93419 static void check_cpu_stalls(void)
93420 diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
93421 index 625d0b0..0bce4d6 100644
93422 --- a/kernel/rcu/tree.c
93423 +++ b/kernel/rcu/tree.c
93424 @@ -263,7 +263,7 @@ static void rcu_momentary_dyntick_idle(void)
93425 */
93426 rdtp = this_cpu_ptr(&rcu_dynticks);
93427 smp_mb__before_atomic(); /* Earlier stuff before QS. */
93428 - atomic_add(2, &rdtp->dynticks); /* QS. */
93429 + atomic_add_unchecked(2, &rdtp->dynticks); /* QS. */
93430 smp_mb__after_atomic(); /* Later stuff after QS. */
93431 break;
93432 }
93433 @@ -523,9 +523,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
93434 rcu_prepare_for_idle(smp_processor_id());
93435 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
93436 smp_mb__before_atomic(); /* See above. */
93437 - atomic_inc(&rdtp->dynticks);
93438 + atomic_inc_unchecked(&rdtp->dynticks);
93439 smp_mb__after_atomic(); /* Force ordering with next sojourn. */
93440 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
93441 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
93442
93443 /*
93444 * It is illegal to enter an extended quiescent state while
93445 @@ -643,10 +643,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
93446 int user)
93447 {
93448 smp_mb__before_atomic(); /* Force ordering w/previous sojourn. */
93449 - atomic_inc(&rdtp->dynticks);
93450 + atomic_inc_unchecked(&rdtp->dynticks);
93451 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
93452 smp_mb__after_atomic(); /* See above. */
93453 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
93454 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
93455 rcu_cleanup_after_idle(smp_processor_id());
93456 trace_rcu_dyntick(TPS("End"), oldval, rdtp->dynticks_nesting);
93457 if (!user && !is_idle_task(current)) {
93458 @@ -767,14 +767,14 @@ void rcu_nmi_enter(void)
93459 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
93460
93461 if (rdtp->dynticks_nmi_nesting == 0 &&
93462 - (atomic_read(&rdtp->dynticks) & 0x1))
93463 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
93464 return;
93465 rdtp->dynticks_nmi_nesting++;
93466 smp_mb__before_atomic(); /* Force delay from prior write. */
93467 - atomic_inc(&rdtp->dynticks);
93468 + atomic_inc_unchecked(&rdtp->dynticks);
93469 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
93470 smp_mb__after_atomic(); /* See above. */
93471 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
93472 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
93473 }
93474
93475 /**
93476 @@ -793,9 +793,9 @@ void rcu_nmi_exit(void)
93477 return;
93478 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
93479 smp_mb__before_atomic(); /* See above. */
93480 - atomic_inc(&rdtp->dynticks);
93481 + atomic_inc_unchecked(&rdtp->dynticks);
93482 smp_mb__after_atomic(); /* Force delay to next write. */
93483 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
93484 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
93485 }
93486
93487 /**
93488 @@ -808,7 +808,7 @@ void rcu_nmi_exit(void)
93489 */
93490 bool notrace __rcu_is_watching(void)
93491 {
93492 - return atomic_read(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
93493 + return atomic_read_unchecked(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
93494 }
93495
93496 /**
93497 @@ -891,7 +891,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
93498 static int dyntick_save_progress_counter(struct rcu_data *rdp,
93499 bool *isidle, unsigned long *maxj)
93500 {
93501 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
93502 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
93503 rcu_sysidle_check_cpu(rdp, isidle, maxj);
93504 if ((rdp->dynticks_snap & 0x1) == 0) {
93505 trace_rcu_fqs(rdp->rsp->name, rdp->gpnum, rdp->cpu, TPS("dti"));
93506 @@ -920,7 +920,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
93507 int *rcrmp;
93508 unsigned int snap;
93509
93510 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
93511 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
93512 snap = (unsigned int)rdp->dynticks_snap;
93513
93514 /*
93515 @@ -983,10 +983,10 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
93516 rdp->rsp->gp_start + jiffies_till_sched_qs) ||
93517 ULONG_CMP_GE(jiffies, rdp->rsp->jiffies_resched)) {
93518 if (!(ACCESS_ONCE(*rcrmp) & rdp->rsp->flavor_mask)) {
93519 - ACCESS_ONCE(rdp->cond_resched_completed) =
93520 + ACCESS_ONCE_RW(rdp->cond_resched_completed) =
93521 ACCESS_ONCE(rdp->mynode->completed);
93522 smp_mb(); /* ->cond_resched_completed before *rcrmp. */
93523 - ACCESS_ONCE(*rcrmp) =
93524 + ACCESS_ONCE_RW(*rcrmp) =
93525 ACCESS_ONCE(*rcrmp) + rdp->rsp->flavor_mask;
93526 resched_cpu(rdp->cpu); /* Force CPU into scheduler. */
93527 rdp->rsp->jiffies_resched += 5; /* Enable beating. */
93528 @@ -1008,7 +1008,7 @@ static void record_gp_stall_check_time(struct rcu_state *rsp)
93529 rsp->gp_start = j;
93530 smp_wmb(); /* Record start time before stall time. */
93531 j1 = rcu_jiffies_till_stall_check();
93532 - ACCESS_ONCE(rsp->jiffies_stall) = j + j1;
93533 + ACCESS_ONCE_RW(rsp->jiffies_stall) = j + j1;
93534 rsp->jiffies_resched = j + j1 / 2;
93535 }
93536
93537 @@ -1052,7 +1052,7 @@ static void print_other_cpu_stall(struct rcu_state *rsp)
93538 raw_spin_unlock_irqrestore(&rnp->lock, flags);
93539 return;
93540 }
93541 - ACCESS_ONCE(rsp->jiffies_stall) = jiffies + 3 * rcu_jiffies_till_stall_check() + 3;
93542 + ACCESS_ONCE_RW(rsp->jiffies_stall) = jiffies + 3 * rcu_jiffies_till_stall_check() + 3;
93543 raw_spin_unlock_irqrestore(&rnp->lock, flags);
93544
93545 /*
93546 @@ -1130,7 +1130,7 @@ static void print_cpu_stall(struct rcu_state *rsp)
93547
93548 raw_spin_lock_irqsave(&rnp->lock, flags);
93549 if (ULONG_CMP_GE(jiffies, ACCESS_ONCE(rsp->jiffies_stall)))
93550 - ACCESS_ONCE(rsp->jiffies_stall) = jiffies +
93551 + ACCESS_ONCE_RW(rsp->jiffies_stall) = jiffies +
93552 3 * rcu_jiffies_till_stall_check() + 3;
93553 raw_spin_unlock_irqrestore(&rnp->lock, flags);
93554
93555 @@ -1214,7 +1214,7 @@ void rcu_cpu_stall_reset(void)
93556 struct rcu_state *rsp;
93557
93558 for_each_rcu_flavor(rsp)
93559 - ACCESS_ONCE(rsp->jiffies_stall) = jiffies + ULONG_MAX / 2;
93560 + ACCESS_ONCE_RW(rsp->jiffies_stall) = jiffies + ULONG_MAX / 2;
93561 }
93562
93563 /*
93564 @@ -1594,7 +1594,7 @@ static int rcu_gp_init(struct rcu_state *rsp)
93565 raw_spin_unlock_irq(&rnp->lock);
93566 return 0;
93567 }
93568 - ACCESS_ONCE(rsp->gp_flags) = 0; /* Clear all flags: New grace period. */
93569 + ACCESS_ONCE_RW(rsp->gp_flags) = 0; /* Clear all flags: New grace period. */
93570
93571 if (WARN_ON_ONCE(rcu_gp_in_progress(rsp))) {
93572 /*
93573 @@ -1635,9 +1635,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
93574 rdp = this_cpu_ptr(rsp->rda);
93575 rcu_preempt_check_blocked_tasks(rnp);
93576 rnp->qsmask = rnp->qsmaskinit;
93577 - ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
93578 + ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
93579 WARN_ON_ONCE(rnp->completed != rsp->completed);
93580 - ACCESS_ONCE(rnp->completed) = rsp->completed;
93581 + ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
93582 if (rnp == rdp->mynode)
93583 (void)__note_gp_changes(rsp, rnp, rdp);
93584 rcu_preempt_boost_start_gp(rnp);
93585 @@ -1687,7 +1687,7 @@ static int rcu_gp_fqs(struct rcu_state *rsp, int fqs_state_in)
93586 if (ACCESS_ONCE(rsp->gp_flags) & RCU_GP_FLAG_FQS) {
93587 raw_spin_lock_irq(&rnp->lock);
93588 smp_mb__after_unlock_lock();
93589 - ACCESS_ONCE(rsp->gp_flags) &= ~RCU_GP_FLAG_FQS;
93590 + ACCESS_ONCE_RW(rsp->gp_flags) &= ~RCU_GP_FLAG_FQS;
93591 raw_spin_unlock_irq(&rnp->lock);
93592 }
93593 return fqs_state;
93594 @@ -1732,7 +1732,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
93595 rcu_for_each_node_breadth_first(rsp, rnp) {
93596 raw_spin_lock_irq(&rnp->lock);
93597 smp_mb__after_unlock_lock();
93598 - ACCESS_ONCE(rnp->completed) = rsp->gpnum;
93599 + ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
93600 rdp = this_cpu_ptr(rsp->rda);
93601 if (rnp == rdp->mynode)
93602 needgp = __note_gp_changes(rsp, rnp, rdp) || needgp;
93603 @@ -1747,14 +1747,14 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
93604 rcu_nocb_gp_set(rnp, nocb);
93605
93606 /* Declare grace period done. */
93607 - ACCESS_ONCE(rsp->completed) = rsp->gpnum;
93608 + ACCESS_ONCE_RW(rsp->completed) = rsp->gpnum;
93609 trace_rcu_grace_period(rsp->name, rsp->completed, TPS("end"));
93610 rsp->fqs_state = RCU_GP_IDLE;
93611 rdp = this_cpu_ptr(rsp->rda);
93612 /* Advance CBs to reduce false positives below. */
93613 needgp = rcu_advance_cbs(rsp, rnp, rdp) || needgp;
93614 if (needgp || cpu_needs_another_gp(rsp, rdp)) {
93615 - ACCESS_ONCE(rsp->gp_flags) = RCU_GP_FLAG_INIT;
93616 + ACCESS_ONCE_RW(rsp->gp_flags) = RCU_GP_FLAG_INIT;
93617 trace_rcu_grace_period(rsp->name,
93618 ACCESS_ONCE(rsp->gpnum),
93619 TPS("newreq"));
93620 @@ -1879,7 +1879,7 @@ rcu_start_gp_advanced(struct rcu_state *rsp, struct rcu_node *rnp,
93621 */
93622 return false;
93623 }
93624 - ACCESS_ONCE(rsp->gp_flags) = RCU_GP_FLAG_INIT;
93625 + ACCESS_ONCE_RW(rsp->gp_flags) = RCU_GP_FLAG_INIT;
93626 trace_rcu_grace_period(rsp->name, ACCESS_ONCE(rsp->gpnum),
93627 TPS("newreq"));
93628
93629 @@ -2100,7 +2100,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
93630 rsp->qlen += rdp->qlen;
93631 rdp->n_cbs_orphaned += rdp->qlen;
93632 rdp->qlen_lazy = 0;
93633 - ACCESS_ONCE(rdp->qlen) = 0;
93634 + ACCESS_ONCE_RW(rdp->qlen) = 0;
93635 }
93636
93637 /*
93638 @@ -2347,7 +2347,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
93639 }
93640 smp_mb(); /* List handling before counting for rcu_barrier(). */
93641 rdp->qlen_lazy -= count_lazy;
93642 - ACCESS_ONCE(rdp->qlen) -= count;
93643 + ACCESS_ONCE_RW(rdp->qlen) -= count;
93644 rdp->n_cbs_invoked += count;
93645
93646 /* Reinstate batch limit if we have worked down the excess. */
93647 @@ -2492,7 +2492,7 @@ static void force_quiescent_state(struct rcu_state *rsp)
93648 if (rnp_old != NULL)
93649 raw_spin_unlock(&rnp_old->fqslock);
93650 if (ret) {
93651 - ACCESS_ONCE(rsp->n_force_qs_lh)++;
93652 + ACCESS_ONCE_RW(rsp->n_force_qs_lh)++;
93653 return;
93654 }
93655 rnp_old = rnp;
93656 @@ -2504,11 +2504,11 @@ static void force_quiescent_state(struct rcu_state *rsp)
93657 smp_mb__after_unlock_lock();
93658 raw_spin_unlock(&rnp_old->fqslock);
93659 if (ACCESS_ONCE(rsp->gp_flags) & RCU_GP_FLAG_FQS) {
93660 - ACCESS_ONCE(rsp->n_force_qs_lh)++;
93661 + ACCESS_ONCE_RW(rsp->n_force_qs_lh)++;
93662 raw_spin_unlock_irqrestore(&rnp_old->lock, flags);
93663 return; /* Someone beat us to it. */
93664 }
93665 - ACCESS_ONCE(rsp->gp_flags) |= RCU_GP_FLAG_FQS;
93666 + ACCESS_ONCE_RW(rsp->gp_flags) |= RCU_GP_FLAG_FQS;
93667 raw_spin_unlock_irqrestore(&rnp_old->lock, flags);
93668 wake_up(&rsp->gp_wq); /* Memory barrier implied by wake_up() path. */
93669 }
93670 @@ -2553,7 +2553,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
93671 /*
93672 * Do RCU core processing for the current CPU.
93673 */
93674 -static void rcu_process_callbacks(struct softirq_action *unused)
93675 +static void rcu_process_callbacks(void)
93676 {
93677 struct rcu_state *rsp;
93678
93679 @@ -2665,7 +2665,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
93680 WARN_ON_ONCE((unsigned long)head & 0x3); /* Misaligned rcu_head! */
93681 if (debug_rcu_head_queue(head)) {
93682 /* Probable double call_rcu(), so leak the callback. */
93683 - ACCESS_ONCE(head->func) = rcu_leak_callback;
93684 + ACCESS_ONCE_RW(head->func) = rcu_leak_callback;
93685 WARN_ONCE(1, "__call_rcu(): Leaked duplicate callback\n");
93686 return;
93687 }
93688 @@ -2693,7 +2693,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
93689 local_irq_restore(flags);
93690 return;
93691 }
93692 - ACCESS_ONCE(rdp->qlen)++;
93693 + ACCESS_ONCE_RW(rdp->qlen)++;
93694 if (lazy)
93695 rdp->qlen_lazy++;
93696 else
93697 @@ -2968,11 +2968,11 @@ void synchronize_sched_expedited(void)
93698 * counter wrap on a 32-bit system. Quite a few more CPUs would of
93699 * course be required on a 64-bit system.
93700 */
93701 - if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
93702 + if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
93703 (ulong)atomic_long_read(&rsp->expedited_done) +
93704 ULONG_MAX / 8)) {
93705 synchronize_sched();
93706 - atomic_long_inc(&rsp->expedited_wrap);
93707 + atomic_long_inc_unchecked(&rsp->expedited_wrap);
93708 return;
93709 }
93710
93711 @@ -2980,7 +2980,7 @@ void synchronize_sched_expedited(void)
93712 * Take a ticket. Note that atomic_inc_return() implies a
93713 * full memory barrier.
93714 */
93715 - snap = atomic_long_inc_return(&rsp->expedited_start);
93716 + snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
93717 firstsnap = snap;
93718 get_online_cpus();
93719 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
93720 @@ -2993,14 +2993,14 @@ void synchronize_sched_expedited(void)
93721 synchronize_sched_expedited_cpu_stop,
93722 NULL) == -EAGAIN) {
93723 put_online_cpus();
93724 - atomic_long_inc(&rsp->expedited_tryfail);
93725 + atomic_long_inc_unchecked(&rsp->expedited_tryfail);
93726
93727 /* Check to see if someone else did our work for us. */
93728 s = atomic_long_read(&rsp->expedited_done);
93729 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
93730 /* ensure test happens before caller kfree */
93731 smp_mb__before_atomic(); /* ^^^ */
93732 - atomic_long_inc(&rsp->expedited_workdone1);
93733 + atomic_long_inc_unchecked(&rsp->expedited_workdone1);
93734 return;
93735 }
93736
93737 @@ -3009,7 +3009,7 @@ void synchronize_sched_expedited(void)
93738 udelay(trycount * num_online_cpus());
93739 } else {
93740 wait_rcu_gp(call_rcu_sched);
93741 - atomic_long_inc(&rsp->expedited_normal);
93742 + atomic_long_inc_unchecked(&rsp->expedited_normal);
93743 return;
93744 }
93745
93746 @@ -3018,7 +3018,7 @@ void synchronize_sched_expedited(void)
93747 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
93748 /* ensure test happens before caller kfree */
93749 smp_mb__before_atomic(); /* ^^^ */
93750 - atomic_long_inc(&rsp->expedited_workdone2);
93751 + atomic_long_inc_unchecked(&rsp->expedited_workdone2);
93752 return;
93753 }
93754
93755 @@ -3030,10 +3030,10 @@ void synchronize_sched_expedited(void)
93756 * period works for us.
93757 */
93758 get_online_cpus();
93759 - snap = atomic_long_read(&rsp->expedited_start);
93760 + snap = atomic_long_read_unchecked(&rsp->expedited_start);
93761 smp_mb(); /* ensure read is before try_stop_cpus(). */
93762 }
93763 - atomic_long_inc(&rsp->expedited_stoppedcpus);
93764 + atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
93765
93766 /*
93767 * Everyone up to our most recent fetch is covered by our grace
93768 @@ -3042,16 +3042,16 @@ void synchronize_sched_expedited(void)
93769 * than we did already did their update.
93770 */
93771 do {
93772 - atomic_long_inc(&rsp->expedited_done_tries);
93773 + atomic_long_inc_unchecked(&rsp->expedited_done_tries);
93774 s = atomic_long_read(&rsp->expedited_done);
93775 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
93776 /* ensure test happens before caller kfree */
93777 smp_mb__before_atomic(); /* ^^^ */
93778 - atomic_long_inc(&rsp->expedited_done_lost);
93779 + atomic_long_inc_unchecked(&rsp->expedited_done_lost);
93780 break;
93781 }
93782 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
93783 - atomic_long_inc(&rsp->expedited_done_exit);
93784 + atomic_long_inc_unchecked(&rsp->expedited_done_exit);
93785
93786 put_online_cpus();
93787 }
93788 @@ -3257,7 +3257,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
93789 * ACCESS_ONCE() to prevent the compiler from speculating
93790 * the increment to precede the early-exit check.
93791 */
93792 - ACCESS_ONCE(rsp->n_barrier_done)++;
93793 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
93794 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
93795 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
93796 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
93797 @@ -3307,7 +3307,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
93798
93799 /* Increment ->n_barrier_done to prevent duplicate work. */
93800 smp_mb(); /* Keep increment after above mechanism. */
93801 - ACCESS_ONCE(rsp->n_barrier_done)++;
93802 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
93803 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
93804 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
93805 smp_mb(); /* Keep increment before caller's subsequent code. */
93806 @@ -3352,10 +3352,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
93807 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
93808 init_callback_list(rdp);
93809 rdp->qlen_lazy = 0;
93810 - ACCESS_ONCE(rdp->qlen) = 0;
93811 + ACCESS_ONCE_RW(rdp->qlen) = 0;
93812 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
93813 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
93814 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
93815 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
93816 rdp->cpu = cpu;
93817 rdp->rsp = rsp;
93818 rcu_boot_init_nocb_percpu_data(rdp);
93819 @@ -3388,8 +3388,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp)
93820 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
93821 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
93822 rcu_sysidle_init_percpu_data(rdp->dynticks);
93823 - atomic_set(&rdp->dynticks->dynticks,
93824 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
93825 + atomic_set_unchecked(&rdp->dynticks->dynticks,
93826 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
93827 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
93828
93829 /* Add CPU to rcu_node bitmasks. */
93830 diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
93831 index 0f69a79..c85c2dc 100644
93832 --- a/kernel/rcu/tree.h
93833 +++ b/kernel/rcu/tree.h
93834 @@ -87,11 +87,11 @@ struct rcu_dynticks {
93835 long long dynticks_nesting; /* Track irq/process nesting level. */
93836 /* Process level is worth LLONG_MAX/2. */
93837 int dynticks_nmi_nesting; /* Track NMI nesting level. */
93838 - atomic_t dynticks; /* Even value for idle, else odd. */
93839 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
93840 #ifdef CONFIG_NO_HZ_FULL_SYSIDLE
93841 long long dynticks_idle_nesting;
93842 /* irq/process nesting level from idle. */
93843 - atomic_t dynticks_idle; /* Even value for idle, else odd. */
93844 + atomic_unchecked_t dynticks_idle;/* Even value for idle, else odd. */
93845 /* "Idle" excludes userspace execution. */
93846 unsigned long dynticks_idle_jiffies;
93847 /* End of last non-NMI non-idle period. */
93848 @@ -435,17 +435,17 @@ struct rcu_state {
93849 /* _rcu_barrier(). */
93850 /* End of fields guarded by barrier_mutex. */
93851
93852 - atomic_long_t expedited_start; /* Starting ticket. */
93853 - atomic_long_t expedited_done; /* Done ticket. */
93854 - atomic_long_t expedited_wrap; /* # near-wrap incidents. */
93855 - atomic_long_t expedited_tryfail; /* # acquisition failures. */
93856 - atomic_long_t expedited_workdone1; /* # done by others #1. */
93857 - atomic_long_t expedited_workdone2; /* # done by others #2. */
93858 - atomic_long_t expedited_normal; /* # fallbacks to normal. */
93859 - atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
93860 - atomic_long_t expedited_done_tries; /* # tries to update _done. */
93861 - atomic_long_t expedited_done_lost; /* # times beaten to _done. */
93862 - atomic_long_t expedited_done_exit; /* # times exited _done loop. */
93863 + atomic_long_unchecked_t expedited_start; /* Starting ticket. */
93864 + atomic_long_t expedited_done; /* Done ticket. */
93865 + atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
93866 + atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
93867 + atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
93868 + atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
93869 + atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
93870 + atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
93871 + atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
93872 + atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
93873 + atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
93874
93875 unsigned long jiffies_force_qs; /* Time at which to invoke */
93876 /* force_quiescent_state(). */
93877 diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
93878 index 02ac0fb..4aa4a36 100644
93879 --- a/kernel/rcu/tree_plugin.h
93880 +++ b/kernel/rcu/tree_plugin.h
93881 @@ -735,7 +735,7 @@ static int rcu_preempted_readers_exp(struct rcu_node *rnp)
93882 static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
93883 {
93884 return !rcu_preempted_readers_exp(rnp) &&
93885 - ACCESS_ONCE(rnp->expmask) == 0;
93886 + ACCESS_ONCE_RW(rnp->expmask) == 0;
93887 }
93888
93889 /*
93890 @@ -897,7 +897,7 @@ void synchronize_rcu_expedited(void)
93891
93892 /* Clean up and exit. */
93893 smp_mb(); /* ensure expedited GP seen before counter increment. */
93894 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
93895 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
93896 unlock_mb_ret:
93897 mutex_unlock(&sync_rcu_preempt_exp_mutex);
93898 mb_ret:
93899 @@ -1447,7 +1447,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
93900 free_cpumask_var(cm);
93901 }
93902
93903 -static struct smp_hotplug_thread rcu_cpu_thread_spec = {
93904 +static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
93905 .store = &rcu_cpu_kthread_task,
93906 .thread_should_run = rcu_cpu_kthread_should_run,
93907 .thread_fn = rcu_cpu_kthread,
93908 @@ -1926,7 +1926,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
93909 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
93910 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
93911 cpu, ticks_value, ticks_title,
93912 - atomic_read(&rdtp->dynticks) & 0xfff,
93913 + atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
93914 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
93915 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
93916 fast_no_hz);
93917 @@ -2079,7 +2079,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
93918
93919 /* Enqueue the callback on the nocb list and update counts. */
93920 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
93921 - ACCESS_ONCE(*old_rhpp) = rhp;
93922 + ACCESS_ONCE_RW(*old_rhpp) = rhp;
93923 atomic_long_add(rhcount, &rdp->nocb_q_count);
93924 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
93925
93926 @@ -2255,12 +2255,12 @@ static int rcu_nocb_kthread(void *arg)
93927 * Extract queued callbacks, update counts, and wait
93928 * for a grace period to elapse.
93929 */
93930 - ACCESS_ONCE(rdp->nocb_head) = NULL;
93931 + ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
93932 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
93933 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
93934 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
93935 - ACCESS_ONCE(rdp->nocb_p_count) += c;
93936 - ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
93937 + ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
93938 + ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
93939 rcu_nocb_wait_gp(rdp);
93940
93941 /* Each pass through the following loop invokes a callback. */
93942 @@ -2286,8 +2286,8 @@ static int rcu_nocb_kthread(void *arg)
93943 list = next;
93944 }
93945 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
93946 - ACCESS_ONCE(rdp->nocb_p_count) -= c;
93947 - ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
93948 + ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
93949 + ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
93950 rdp->n_nocbs_invoked += c;
93951 }
93952 return 0;
93953 @@ -2304,7 +2304,7 @@ static void do_nocb_deferred_wakeup(struct rcu_data *rdp)
93954 {
93955 if (!rcu_nocb_need_deferred_wakeup(rdp))
93956 return;
93957 - ACCESS_ONCE(rdp->nocb_defer_wakeup) = false;
93958 + ACCESS_ONCE_RW(rdp->nocb_defer_wakeup) = false;
93959 wake_up(&rdp->nocb_wq);
93960 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, TPS("DeferredWakeEmpty"));
93961 }
93962 @@ -2330,7 +2330,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
93963 t = kthread_run(rcu_nocb_kthread, rdp,
93964 "rcuo%c/%d", rsp->abbr, cpu);
93965 BUG_ON(IS_ERR(t));
93966 - ACCESS_ONCE(rdp->nocb_kthread) = t;
93967 + ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
93968 }
93969 }
93970
93971 @@ -2461,11 +2461,11 @@ static void rcu_sysidle_enter(struct rcu_dynticks *rdtp, int irq)
93972
93973 /* Record start of fully idle period. */
93974 j = jiffies;
93975 - ACCESS_ONCE(rdtp->dynticks_idle_jiffies) = j;
93976 + ACCESS_ONCE_RW(rdtp->dynticks_idle_jiffies) = j;
93977 smp_mb__before_atomic();
93978 - atomic_inc(&rdtp->dynticks_idle);
93979 + atomic_inc_unchecked(&rdtp->dynticks_idle);
93980 smp_mb__after_atomic();
93981 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks_idle) & 0x1);
93982 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1);
93983 }
93984
93985 /*
93986 @@ -2530,9 +2530,9 @@ static void rcu_sysidle_exit(struct rcu_dynticks *rdtp, int irq)
93987
93988 /* Record end of idle period. */
93989 smp_mb__before_atomic();
93990 - atomic_inc(&rdtp->dynticks_idle);
93991 + atomic_inc_unchecked(&rdtp->dynticks_idle);
93992 smp_mb__after_atomic();
93993 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks_idle) & 0x1));
93994 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1));
93995
93996 /*
93997 * If we are the timekeeping CPU, we are permitted to be non-idle
93998 @@ -2573,7 +2573,7 @@ static void rcu_sysidle_check_cpu(struct rcu_data *rdp, bool *isidle,
93999 WARN_ON_ONCE(smp_processor_id() != tick_do_timer_cpu);
94000
94001 /* Pick up current idle and NMI-nesting counter and check. */
94002 - cur = atomic_read(&rdtp->dynticks_idle);
94003 + cur = atomic_read_unchecked(&rdtp->dynticks_idle);
94004 if (cur & 0x1) {
94005 *isidle = false; /* We are not idle! */
94006 return;
94007 @@ -2622,7 +2622,7 @@ static void rcu_sysidle(unsigned long j)
94008 case RCU_SYSIDLE_NOT:
94009
94010 /* First time all are idle, so note a short idle period. */
94011 - ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_SHORT;
94012 + ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_SHORT;
94013 break;
94014
94015 case RCU_SYSIDLE_SHORT:
94016 @@ -2660,7 +2660,7 @@ static void rcu_sysidle_cancel(void)
94017 {
94018 smp_mb();
94019 if (full_sysidle_state > RCU_SYSIDLE_SHORT)
94020 - ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_NOT;
94021 + ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_NOT;
94022 }
94023
94024 /*
94025 @@ -2708,7 +2708,7 @@ static void rcu_sysidle_cb(struct rcu_head *rhp)
94026 smp_mb(); /* grace period precedes setting inuse. */
94027
94028 rshp = container_of(rhp, struct rcu_sysidle_head, rh);
94029 - ACCESS_ONCE(rshp->inuse) = 0;
94030 + ACCESS_ONCE_RW(rshp->inuse) = 0;
94031 }
94032
94033 /*
94034 diff --git a/kernel/rcu/tree_trace.c b/kernel/rcu/tree_trace.c
94035 index 5cdc62e..cc52e88 100644
94036 --- a/kernel/rcu/tree_trace.c
94037 +++ b/kernel/rcu/tree_trace.c
94038 @@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
94039 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
94040 rdp->passed_quiesce, rdp->qs_pending);
94041 seq_printf(m, " dt=%d/%llx/%d df=%lu",
94042 - atomic_read(&rdp->dynticks->dynticks),
94043 + atomic_read_unchecked(&rdp->dynticks->dynticks),
94044 rdp->dynticks->dynticks_nesting,
94045 rdp->dynticks->dynticks_nmi_nesting,
94046 rdp->dynticks_fqs);
94047 @@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
94048 struct rcu_state *rsp = (struct rcu_state *)m->private;
94049
94050 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",
94051 - atomic_long_read(&rsp->expedited_start),
94052 + atomic_long_read_unchecked(&rsp->expedited_start),
94053 atomic_long_read(&rsp->expedited_done),
94054 - atomic_long_read(&rsp->expedited_wrap),
94055 - atomic_long_read(&rsp->expedited_tryfail),
94056 - atomic_long_read(&rsp->expedited_workdone1),
94057 - atomic_long_read(&rsp->expedited_workdone2),
94058 - atomic_long_read(&rsp->expedited_normal),
94059 - atomic_long_read(&rsp->expedited_stoppedcpus),
94060 - atomic_long_read(&rsp->expedited_done_tries),
94061 - atomic_long_read(&rsp->expedited_done_lost),
94062 - atomic_long_read(&rsp->expedited_done_exit));
94063 + atomic_long_read_unchecked(&rsp->expedited_wrap),
94064 + atomic_long_read_unchecked(&rsp->expedited_tryfail),
94065 + atomic_long_read_unchecked(&rsp->expedited_workdone1),
94066 + atomic_long_read_unchecked(&rsp->expedited_workdone2),
94067 + atomic_long_read_unchecked(&rsp->expedited_normal),
94068 + atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
94069 + atomic_long_read_unchecked(&rsp->expedited_done_tries),
94070 + atomic_long_read_unchecked(&rsp->expedited_done_lost),
94071 + atomic_long_read_unchecked(&rsp->expedited_done_exit));
94072 return 0;
94073 }
94074
94075 diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c
94076 index bc78835..7691a45 100644
94077 --- a/kernel/rcu/update.c
94078 +++ b/kernel/rcu/update.c
94079 @@ -311,10 +311,10 @@ int rcu_jiffies_till_stall_check(void)
94080 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
94081 */
94082 if (till_stall_check < 3) {
94083 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
94084 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
94085 till_stall_check = 3;
94086 } else if (till_stall_check > 300) {
94087 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
94088 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
94089 till_stall_check = 300;
94090 }
94091 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
94092 diff --git a/kernel/resource.c b/kernel/resource.c
94093 index 3c2237a..4568d96 100644
94094 --- a/kernel/resource.c
94095 +++ b/kernel/resource.c
94096 @@ -152,8 +152,18 @@ static const struct file_operations proc_iomem_operations = {
94097
94098 static int __init ioresources_init(void)
94099 {
94100 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
94101 +#ifdef CONFIG_GRKERNSEC_PROC_USER
94102 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
94103 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
94104 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
94105 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
94106 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
94107 +#endif
94108 +#else
94109 proc_create("ioports", 0, NULL, &proc_ioports_operations);
94110 proc_create("iomem", 0, NULL, &proc_iomem_operations);
94111 +#endif
94112 return 0;
94113 }
94114 __initcall(ioresources_init);
94115 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
94116 index e73efba..c9bfbd4 100644
94117 --- a/kernel/sched/auto_group.c
94118 +++ b/kernel/sched/auto_group.c
94119 @@ -11,7 +11,7 @@
94120
94121 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
94122 static struct autogroup autogroup_default;
94123 -static atomic_t autogroup_seq_nr;
94124 +static atomic_unchecked_t autogroup_seq_nr;
94125
94126 void __init autogroup_init(struct task_struct *init_task)
94127 {
94128 @@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
94129
94130 kref_init(&ag->kref);
94131 init_rwsem(&ag->lock);
94132 - ag->id = atomic_inc_return(&autogroup_seq_nr);
94133 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
94134 ag->tg = tg;
94135 #ifdef CONFIG_RT_GROUP_SCHED
94136 /*
94137 diff --git a/kernel/sched/completion.c b/kernel/sched/completion.c
94138 index a63f4dc..349bbb0 100644
94139 --- a/kernel/sched/completion.c
94140 +++ b/kernel/sched/completion.c
94141 @@ -204,7 +204,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
94142 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
94143 * or number of jiffies left till timeout) if completed.
94144 */
94145 -long __sched
94146 +long __sched __intentional_overflow(-1)
94147 wait_for_completion_interruptible_timeout(struct completion *x,
94148 unsigned long timeout)
94149 {
94150 @@ -221,7 +221,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
94151 *
94152 * Return: -ERESTARTSYS if interrupted, 0 if completed.
94153 */
94154 -int __sched wait_for_completion_killable(struct completion *x)
94155 +int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
94156 {
94157 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
94158 if (t == -ERESTARTSYS)
94159 @@ -242,7 +242,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
94160 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
94161 * or number of jiffies left till timeout) if completed.
94162 */
94163 -long __sched
94164 +long __sched __intentional_overflow(-1)
94165 wait_for_completion_killable_timeout(struct completion *x,
94166 unsigned long timeout)
94167 {
94168 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
94169 index bc1638b..a7638fc 100644
94170 --- a/kernel/sched/core.c
94171 +++ b/kernel/sched/core.c
94172 @@ -1849,7 +1849,7 @@ void set_numabalancing_state(bool enabled)
94173 int sysctl_numa_balancing(struct ctl_table *table, int write,
94174 void __user *buffer, size_t *lenp, loff_t *ppos)
94175 {
94176 - struct ctl_table t;
94177 + ctl_table_no_const t;
94178 int err;
94179 int state = numabalancing_enabled;
94180
94181 @@ -2312,8 +2312,10 @@ context_switch(struct rq *rq, struct task_struct *prev,
94182 next->active_mm = oldmm;
94183 atomic_inc(&oldmm->mm_count);
94184 enter_lazy_tlb(oldmm, next);
94185 - } else
94186 + } else {
94187 switch_mm(oldmm, mm, next);
94188 + populate_stack();
94189 + }
94190
94191 if (!prev->mm) {
94192 prev->active_mm = NULL;
94193 @@ -3081,6 +3083,8 @@ int can_nice(const struct task_struct *p, const int nice)
94194 /* convert nice value [19,-20] to rlimit style value [1,40] */
94195 int nice_rlim = nice_to_rlimit(nice);
94196
94197 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
94198 +
94199 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
94200 capable(CAP_SYS_NICE));
94201 }
94202 @@ -3107,7 +3111,8 @@ SYSCALL_DEFINE1(nice, int, increment)
94203 nice = task_nice(current) + increment;
94204
94205 nice = clamp_val(nice, MIN_NICE, MAX_NICE);
94206 - if (increment < 0 && !can_nice(current, nice))
94207 + if (increment < 0 && (!can_nice(current, nice) ||
94208 + gr_handle_chroot_nice()))
94209 return -EPERM;
94210
94211 retval = security_task_setnice(current, nice);
94212 @@ -3380,6 +3385,7 @@ recheck:
94213 if (policy != p->policy && !rlim_rtprio)
94214 return -EPERM;
94215
94216 + gr_learn_resource(p, RLIMIT_RTPRIO, attr->sched_priority, 1);
94217 /* can't increase priority */
94218 if (attr->sched_priority > p->rt_priority &&
94219 attr->sched_priority > rlim_rtprio)
94220 @@ -4771,6 +4777,7 @@ void idle_task_exit(void)
94221
94222 if (mm != &init_mm) {
94223 switch_mm(mm, &init_mm, current);
94224 + populate_stack();
94225 finish_arch_post_lock_switch();
94226 }
94227 mmdrop(mm);
94228 @@ -4866,7 +4873,7 @@ static void migrate_tasks(unsigned int dead_cpu)
94229
94230 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
94231
94232 -static struct ctl_table sd_ctl_dir[] = {
94233 +static ctl_table_no_const sd_ctl_dir[] __read_only = {
94234 {
94235 .procname = "sched_domain",
94236 .mode = 0555,
94237 @@ -4883,17 +4890,17 @@ static struct ctl_table sd_ctl_root[] = {
94238 {}
94239 };
94240
94241 -static struct ctl_table *sd_alloc_ctl_entry(int n)
94242 +static ctl_table_no_const *sd_alloc_ctl_entry(int n)
94243 {
94244 - struct ctl_table *entry =
94245 + ctl_table_no_const *entry =
94246 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
94247
94248 return entry;
94249 }
94250
94251 -static void sd_free_ctl_entry(struct ctl_table **tablep)
94252 +static void sd_free_ctl_entry(ctl_table_no_const *tablep)
94253 {
94254 - struct ctl_table *entry;
94255 + ctl_table_no_const *entry;
94256
94257 /*
94258 * In the intermediate directories, both the child directory and
94259 @@ -4901,22 +4908,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
94260 * will always be set. In the lowest directory the names are
94261 * static strings and all have proc handlers.
94262 */
94263 - for (entry = *tablep; entry->mode; entry++) {
94264 - if (entry->child)
94265 - sd_free_ctl_entry(&entry->child);
94266 + for (entry = tablep; entry->mode; entry++) {
94267 + if (entry->child) {
94268 + sd_free_ctl_entry(entry->child);
94269 + pax_open_kernel();
94270 + entry->child = NULL;
94271 + pax_close_kernel();
94272 + }
94273 if (entry->proc_handler == NULL)
94274 kfree(entry->procname);
94275 }
94276
94277 - kfree(*tablep);
94278 - *tablep = NULL;
94279 + kfree(tablep);
94280 }
94281
94282 static int min_load_idx = 0;
94283 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
94284
94285 static void
94286 -set_table_entry(struct ctl_table *entry,
94287 +set_table_entry(ctl_table_no_const *entry,
94288 const char *procname, void *data, int maxlen,
94289 umode_t mode, proc_handler *proc_handler,
94290 bool load_idx)
94291 @@ -4936,7 +4946,7 @@ set_table_entry(struct ctl_table *entry,
94292 static struct ctl_table *
94293 sd_alloc_ctl_domain_table(struct sched_domain *sd)
94294 {
94295 - struct ctl_table *table = sd_alloc_ctl_entry(14);
94296 + ctl_table_no_const *table = sd_alloc_ctl_entry(14);
94297
94298 if (table == NULL)
94299 return NULL;
94300 @@ -4974,9 +4984,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
94301 return table;
94302 }
94303
94304 -static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
94305 +static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
94306 {
94307 - struct ctl_table *entry, *table;
94308 + ctl_table_no_const *entry, *table;
94309 struct sched_domain *sd;
94310 int domain_num = 0, i;
94311 char buf[32];
94312 @@ -5003,11 +5013,13 @@ static struct ctl_table_header *sd_sysctl_header;
94313 static void register_sched_domain_sysctl(void)
94314 {
94315 int i, cpu_num = num_possible_cpus();
94316 - struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
94317 + ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
94318 char buf[32];
94319
94320 WARN_ON(sd_ctl_dir[0].child);
94321 + pax_open_kernel();
94322 sd_ctl_dir[0].child = entry;
94323 + pax_close_kernel();
94324
94325 if (entry == NULL)
94326 return;
94327 @@ -5030,8 +5042,12 @@ static void unregister_sched_domain_sysctl(void)
94328 if (sd_sysctl_header)
94329 unregister_sysctl_table(sd_sysctl_header);
94330 sd_sysctl_header = NULL;
94331 - if (sd_ctl_dir[0].child)
94332 - sd_free_ctl_entry(&sd_ctl_dir[0].child);
94333 + if (sd_ctl_dir[0].child) {
94334 + sd_free_ctl_entry(sd_ctl_dir[0].child);
94335 + pax_open_kernel();
94336 + sd_ctl_dir[0].child = NULL;
94337 + pax_close_kernel();
94338 + }
94339 }
94340 #else
94341 static void register_sched_domain_sysctl(void)
94342 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
94343 index fea7d33..84faa94 100644
94344 --- a/kernel/sched/fair.c
94345 +++ b/kernel/sched/fair.c
94346 @@ -1857,7 +1857,7 @@ void task_numa_fault(int last_cpupid, int mem_node, int pages, int flags)
94347
94348 static void reset_ptenuma_scan(struct task_struct *p)
94349 {
94350 - ACCESS_ONCE(p->mm->numa_scan_seq)++;
94351 + ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
94352 p->mm->numa_scan_offset = 0;
94353 }
94354
94355 @@ -7289,7 +7289,7 @@ static void nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle) { }
94356 * run_rebalance_domains is triggered when needed from the scheduler tick.
94357 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
94358 */
94359 -static void run_rebalance_domains(struct softirq_action *h)
94360 +static __latent_entropy void run_rebalance_domains(void)
94361 {
94362 struct rq *this_rq = this_rq();
94363 enum cpu_idle_type idle = this_rq->idle_balance ?
94364 diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
94365 index 31cc02e..734fb85 100644
94366 --- a/kernel/sched/sched.h
94367 +++ b/kernel/sched/sched.h
94368 @@ -1153,7 +1153,7 @@ struct sched_class {
94369 #ifdef CONFIG_FAIR_GROUP_SCHED
94370 void (*task_move_group) (struct task_struct *p, int on_rq);
94371 #endif
94372 -};
94373 +} __do_const;
94374
94375 static inline void put_prev_task(struct rq *rq, struct task_struct *prev)
94376 {
94377 diff --git a/kernel/seccomp.c b/kernel/seccomp.c
94378 index 301bbc2..eda2da3 100644
94379 --- a/kernel/seccomp.c
94380 +++ b/kernel/seccomp.c
94381 @@ -39,7 +39,7 @@
94382 * is only needed for handling filters shared across tasks.
94383 * @prev: points to a previously installed, or inherited, filter
94384 * @len: the number of instructions in the program
94385 - * @insnsi: the BPF program instructions to evaluate
94386 + * @insns: the BPF program instructions to evaluate
94387 *
94388 * seccomp_filter objects are organized in a tree linked via the @prev
94389 * pointer. For any task, it appears to be a singly-linked list starting
94390 @@ -54,32 +54,61 @@
94391 struct seccomp_filter {
94392 atomic_t usage;
94393 struct seccomp_filter *prev;
94394 - struct sk_filter *prog;
94395 + unsigned short len; /* Instruction count */
94396 + struct sock_filter insns[];
94397 };
94398
94399 /* Limit any path through the tree to 256KB worth of instructions. */
94400 #define MAX_INSNS_PER_PATH ((1 << 18) / sizeof(struct sock_filter))
94401
94402 -/*
94403 +/**
94404 + * get_u32 - returns a u32 offset into data
94405 + * @data: a unsigned 64 bit value
94406 + * @index: 0 or 1 to return the first or second 32-bits
94407 + *
94408 + * This inline exists to hide the length of unsigned long. If a 32-bit
94409 + * unsigned long is passed in, it will be extended and the top 32-bits will be
94410 + * 0. If it is a 64-bit unsigned long, then whatever data is resident will be
94411 + * properly returned.
94412 + *
94413 * Endianness is explicitly ignored and left for BPF program authors to manage
94414 * as per the specific architecture.
94415 */
94416 -static void populate_seccomp_data(struct seccomp_data *sd)
94417 +static inline u32 get_u32(u64 data, int index)
94418 {
94419 - struct task_struct *task = current;
94420 - struct pt_regs *regs = task_pt_regs(task);
94421 - unsigned long args[6];
94422 + return ((u32 *)&data)[index];
94423 +}
94424
94425 - sd->nr = syscall_get_nr(task, regs);
94426 - sd->arch = syscall_get_arch();
94427 - syscall_get_arguments(task, regs, 0, 6, args);
94428 - sd->args[0] = args[0];
94429 - sd->args[1] = args[1];
94430 - sd->args[2] = args[2];
94431 - sd->args[3] = args[3];
94432 - sd->args[4] = args[4];
94433 - sd->args[5] = args[5];
94434 - sd->instruction_pointer = KSTK_EIP(task);
94435 +/* Helper for bpf_load below. */
94436 +#define BPF_DATA(_name) offsetof(struct seccomp_data, _name)
94437 +/**
94438 + * bpf_load: checks and returns a pointer to the requested offset
94439 + * @off: offset into struct seccomp_data to load from
94440 + *
94441 + * Returns the requested 32-bits of data.
94442 + * seccomp_check_filter() should assure that @off is 32-bit aligned
94443 + * and not out of bounds. Failure to do so is a BUG.
94444 + */
94445 +u32 seccomp_bpf_load(int off)
94446 +{
94447 + struct pt_regs *regs = task_pt_regs(current);
94448 + if (off == BPF_DATA(nr))
94449 + return syscall_get_nr(current, regs);
94450 + if (off == BPF_DATA(arch))
94451 + return syscall_get_arch();
94452 + if (off >= BPF_DATA(args[0]) && off < BPF_DATA(args[6])) {
94453 + unsigned long value;
94454 + int arg = (off - BPF_DATA(args[0])) / sizeof(u64);
94455 + int index = !!(off % sizeof(u64));
94456 + syscall_get_arguments(current, regs, arg, 1, &value);
94457 + return get_u32(value, index);
94458 + }
94459 + if (off == BPF_DATA(instruction_pointer))
94460 + return get_u32(KSTK_EIP(current), 0);
94461 + if (off == BPF_DATA(instruction_pointer) + sizeof(u32))
94462 + return get_u32(KSTK_EIP(current), 1);
94463 + /* seccomp_check_filter should make this impossible. */
94464 + BUG();
94465 }
94466
94467 /**
94468 @@ -103,59 +132,59 @@ static int seccomp_check_filter(struct sock_filter *filter, unsigned int flen)
94469 u32 k = ftest->k;
94470
94471 switch (code) {
94472 - case BPF_LD | BPF_W | BPF_ABS:
94473 - ftest->code = BPF_LDX | BPF_W | BPF_ABS;
94474 + case BPF_S_LD_W_ABS:
94475 + ftest->code = BPF_S_ANC_SECCOMP_LD_W;
94476 /* 32-bit aligned and not out of bounds. */
94477 if (k >= sizeof(struct seccomp_data) || k & 3)
94478 return -EINVAL;
94479 continue;
94480 - case BPF_LD | BPF_W | BPF_LEN:
94481 - ftest->code = BPF_LD | BPF_IMM;
94482 + case BPF_S_LD_W_LEN:
94483 + ftest->code = BPF_S_LD_IMM;
94484 ftest->k = sizeof(struct seccomp_data);
94485 continue;
94486 - case BPF_LDX | BPF_W | BPF_LEN:
94487 - ftest->code = BPF_LDX | BPF_IMM;
94488 + case BPF_S_LDX_W_LEN:
94489 + ftest->code = BPF_S_LDX_IMM;
94490 ftest->k = sizeof(struct seccomp_data);
94491 continue;
94492 /* Explicitly include allowed calls. */
94493 - case BPF_RET | BPF_K:
94494 - case BPF_RET | BPF_A:
94495 - case BPF_ALU | BPF_ADD | BPF_K:
94496 - case BPF_ALU | BPF_ADD | BPF_X:
94497 - case BPF_ALU | BPF_SUB | BPF_K:
94498 - case BPF_ALU | BPF_SUB | BPF_X:
94499 - case BPF_ALU | BPF_MUL | BPF_K:
94500 - case BPF_ALU | BPF_MUL | BPF_X:
94501 - case BPF_ALU | BPF_DIV | BPF_K:
94502 - case BPF_ALU | BPF_DIV | BPF_X:
94503 - case BPF_ALU | BPF_AND | BPF_K:
94504 - case BPF_ALU | BPF_AND | BPF_X:
94505 - case BPF_ALU | BPF_OR | BPF_K:
94506 - case BPF_ALU | BPF_OR | BPF_X:
94507 - case BPF_ALU | BPF_XOR | BPF_K:
94508 - case BPF_ALU | BPF_XOR | BPF_X:
94509 - case BPF_ALU | BPF_LSH | BPF_K:
94510 - case BPF_ALU | BPF_LSH | BPF_X:
94511 - case BPF_ALU | BPF_RSH | BPF_K:
94512 - case BPF_ALU | BPF_RSH | BPF_X:
94513 - case BPF_ALU | BPF_NEG:
94514 - case BPF_LD | BPF_IMM:
94515 - case BPF_LDX | BPF_IMM:
94516 - case BPF_MISC | BPF_TAX:
94517 - case BPF_MISC | BPF_TXA:
94518 - case BPF_LD | BPF_MEM:
94519 - case BPF_LDX | BPF_MEM:
94520 - case BPF_ST:
94521 - case BPF_STX:
94522 - case BPF_JMP | BPF_JA:
94523 - case BPF_JMP | BPF_JEQ | BPF_K:
94524 - case BPF_JMP | BPF_JEQ | BPF_X:
94525 - case BPF_JMP | BPF_JGE | BPF_K:
94526 - case BPF_JMP | BPF_JGE | BPF_X:
94527 - case BPF_JMP | BPF_JGT | BPF_K:
94528 - case BPF_JMP | BPF_JGT | BPF_X:
94529 - case BPF_JMP | BPF_JSET | BPF_K:
94530 - case BPF_JMP | BPF_JSET | BPF_X:
94531 + case BPF_S_RET_K:
94532 + case BPF_S_RET_A:
94533 + case BPF_S_ALU_ADD_K:
94534 + case BPF_S_ALU_ADD_X:
94535 + case BPF_S_ALU_SUB_K:
94536 + case BPF_S_ALU_SUB_X:
94537 + case BPF_S_ALU_MUL_K:
94538 + case BPF_S_ALU_MUL_X:
94539 + case BPF_S_ALU_DIV_X:
94540 + case BPF_S_ALU_AND_K:
94541 + case BPF_S_ALU_AND_X:
94542 + case BPF_S_ALU_OR_K:
94543 + case BPF_S_ALU_OR_X:
94544 + case BPF_S_ALU_XOR_K:
94545 + case BPF_S_ALU_XOR_X:
94546 + case BPF_S_ALU_LSH_K:
94547 + case BPF_S_ALU_LSH_X:
94548 + case BPF_S_ALU_RSH_K:
94549 + case BPF_S_ALU_RSH_X:
94550 + case BPF_S_ALU_NEG:
94551 + case BPF_S_LD_IMM:
94552 + case BPF_S_LDX_IMM:
94553 + case BPF_S_MISC_TAX:
94554 + case BPF_S_MISC_TXA:
94555 + case BPF_S_ALU_DIV_K:
94556 + case BPF_S_LD_MEM:
94557 + case BPF_S_LDX_MEM:
94558 + case BPF_S_ST:
94559 + case BPF_S_STX:
94560 + case BPF_S_JMP_JA:
94561 + case BPF_S_JMP_JEQ_K:
94562 + case BPF_S_JMP_JEQ_X:
94563 + case BPF_S_JMP_JGE_K:
94564 + case BPF_S_JMP_JGE_X:
94565 + case BPF_S_JMP_JGT_K:
94566 + case BPF_S_JMP_JGT_X:
94567 + case BPF_S_JMP_JSET_K:
94568 + case BPF_S_JMP_JSET_X:
94569 continue;
94570 default:
94571 return -EINVAL;
94572 @@ -173,22 +202,18 @@ static int seccomp_check_filter(struct sock_filter *filter, unsigned int flen)
94573 static u32 seccomp_run_filters(int syscall)
94574 {
94575 struct seccomp_filter *f;
94576 - struct seccomp_data sd;
94577 u32 ret = SECCOMP_RET_ALLOW;
94578
94579 /* Ensure unexpected behavior doesn't result in failing open. */
94580 if (WARN_ON(current->seccomp.filter == NULL))
94581 return SECCOMP_RET_KILL;
94582
94583 - populate_seccomp_data(&sd);
94584 -
94585 /*
94586 * All filters in the list are evaluated and the lowest BPF return
94587 * value always takes priority (ignoring the DATA).
94588 */
94589 for (f = current->seccomp.filter; f; f = f->prev) {
94590 - u32 cur_ret = SK_RUN_FILTER(f->prog, (void *)&sd);
94591 -
94592 + u32 cur_ret = sk_run_filter(NULL, f->insns);
94593 if ((cur_ret & SECCOMP_RET_ACTION) < (ret & SECCOMP_RET_ACTION))
94594 ret = cur_ret;
94595 }
94596 @@ -206,20 +231,18 @@ static long seccomp_attach_filter(struct sock_fprog *fprog)
94597 struct seccomp_filter *filter;
94598 unsigned long fp_size = fprog->len * sizeof(struct sock_filter);
94599 unsigned long total_insns = fprog->len;
94600 - struct sock_filter *fp;
94601 - int new_len;
94602 long ret;
94603
94604 if (fprog->len == 0 || fprog->len > BPF_MAXINSNS)
94605 return -EINVAL;
94606
94607 for (filter = current->seccomp.filter; filter; filter = filter->prev)
94608 - total_insns += filter->prog->len + 4; /* include a 4 instr penalty */
94609 + total_insns += filter->len + 4; /* include a 4 instr penalty */
94610 if (total_insns > MAX_INSNS_PER_PATH)
94611 return -ENOMEM;
94612
94613 /*
94614 - * Installing a seccomp filter requires that the task has
94615 + * Installing a seccomp filter requires that the task have
94616 * CAP_SYS_ADMIN in its namespace or be running with no_new_privs.
94617 * This avoids scenarios where unprivileged tasks can affect the
94618 * behavior of privileged children.
94619 @@ -229,51 +252,28 @@ static long seccomp_attach_filter(struct sock_fprog *fprog)
94620 CAP_SYS_ADMIN) != 0)
94621 return -EACCES;
94622
94623 - fp = kzalloc(fp_size, GFP_KERNEL|__GFP_NOWARN);
94624 - if (!fp)
94625 - return -ENOMEM;
94626 -
94627 - /* Copy the instructions from fprog. */
94628 - ret = -EFAULT;
94629 - if (copy_from_user(fp, fprog->filter, fp_size))
94630 - goto free_prog;
94631 -
94632 - /* Check and rewrite the fprog via the skb checker */
94633 - ret = sk_chk_filter(fp, fprog->len);
94634 - if (ret)
94635 - goto free_prog;
94636 -
94637 - /* Check and rewrite the fprog for seccomp use */
94638 - ret = seccomp_check_filter(fp, fprog->len);
94639 - if (ret)
94640 - goto free_prog;
94641 -
94642 - /* Convert 'sock_filter' insns to 'sock_filter_int' insns */
94643 - ret = sk_convert_filter(fp, fprog->len, NULL, &new_len);
94644 - if (ret)
94645 - goto free_prog;
94646 -
94647 /* Allocate a new seccomp_filter */
94648 - ret = -ENOMEM;
94649 - filter = kzalloc(sizeof(struct seccomp_filter),
94650 + filter = kzalloc(sizeof(struct seccomp_filter) + fp_size,
94651 GFP_KERNEL|__GFP_NOWARN);
94652 if (!filter)
94653 - goto free_prog;
94654 -
94655 - filter->prog = kzalloc(sk_filter_size(new_len),
94656 - GFP_KERNEL|__GFP_NOWARN);
94657 - if (!filter->prog)
94658 - goto free_filter;
94659 -
94660 - ret = sk_convert_filter(fp, fprog->len, filter->prog->insnsi, &new_len);
94661 - if (ret)
94662 - goto free_filter_prog;
94663 - kfree(fp);
94664 -
94665 + return -ENOMEM;
94666 atomic_set(&filter->usage, 1);
94667 - filter->prog->len = new_len;
94668 + filter->len = fprog->len;
94669
94670 - sk_filter_select_runtime(filter->prog);
94671 + /* Copy the instructions from fprog. */
94672 + ret = -EFAULT;
94673 + if (copy_from_user(filter->insns, fprog->filter, fp_size))
94674 + goto fail;
94675 +
94676 + /* Check and rewrite the fprog via the skb checker */
94677 + ret = sk_chk_filter(filter->insns, filter->len);
94678 + if (ret)
94679 + goto fail;
94680 +
94681 + /* Check and rewrite the fprog for seccomp use */
94682 + ret = seccomp_check_filter(filter->insns, filter->len);
94683 + if (ret)
94684 + goto fail;
94685
94686 /*
94687 * If there is an existing filter, make it the prev and don't drop its
94688 @@ -282,13 +282,8 @@ static long seccomp_attach_filter(struct sock_fprog *fprog)
94689 filter->prev = current->seccomp.filter;
94690 current->seccomp.filter = filter;
94691 return 0;
94692 -
94693 -free_filter_prog:
94694 - kfree(filter->prog);
94695 -free_filter:
94696 +fail:
94697 kfree(filter);
94698 -free_prog:
94699 - kfree(fp);
94700 return ret;
94701 }
94702
94703 @@ -298,7 +293,7 @@ free_prog:
94704 *
94705 * Returns 0 on success and non-zero otherwise.
94706 */
94707 -static long seccomp_attach_user_filter(char __user *user_filter)
94708 +long seccomp_attach_user_filter(char __user *user_filter)
94709 {
94710 struct sock_fprog fprog;
94711 long ret = -EFAULT;
94712 @@ -337,7 +332,6 @@ void put_seccomp_filter(struct task_struct *tsk)
94713 while (orig && atomic_dec_and_test(&orig->usage)) {
94714 struct seccomp_filter *freeme = orig;
94715 orig = orig->prev;
94716 - sk_filter_free(freeme->prog);
94717 kfree(freeme);
94718 }
94719 }
94720 diff --git a/kernel/signal.c b/kernel/signal.c
94721 index a4077e9..f0d4e5c 100644
94722 --- a/kernel/signal.c
94723 +++ b/kernel/signal.c
94724 @@ -53,12 +53,12 @@ static struct kmem_cache *sigqueue_cachep;
94725
94726 int print_fatal_signals __read_mostly;
94727
94728 -static void __user *sig_handler(struct task_struct *t, int sig)
94729 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
94730 {
94731 return t->sighand->action[sig - 1].sa.sa_handler;
94732 }
94733
94734 -static int sig_handler_ignored(void __user *handler, int sig)
94735 +static int sig_handler_ignored(__sighandler_t handler, int sig)
94736 {
94737 /* Is it explicitly or implicitly ignored? */
94738 return handler == SIG_IGN ||
94739 @@ -67,7 +67,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
94740
94741 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
94742 {
94743 - void __user *handler;
94744 + __sighandler_t handler;
94745
94746 handler = sig_handler(t, sig);
94747
94748 @@ -372,6 +372,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
94749 atomic_inc(&user->sigpending);
94750 rcu_read_unlock();
94751
94752 + if (!override_rlimit)
94753 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
94754 +
94755 if (override_rlimit ||
94756 atomic_read(&user->sigpending) <=
94757 task_rlimit(t, RLIMIT_SIGPENDING)) {
94758 @@ -499,7 +502,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
94759
94760 int unhandled_signal(struct task_struct *tsk, int sig)
94761 {
94762 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
94763 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
94764 if (is_global_init(tsk))
94765 return 1;
94766 if (handler != SIG_IGN && handler != SIG_DFL)
94767 @@ -793,6 +796,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
94768 }
94769 }
94770
94771 + /* allow glibc communication via tgkill to other threads in our
94772 + thread group */
94773 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
94774 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
94775 + && gr_handle_signal(t, sig))
94776 + return -EPERM;
94777 +
94778 return security_task_kill(t, info, sig, 0);
94779 }
94780
94781 @@ -1176,7 +1186,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
94782 return send_signal(sig, info, p, 1);
94783 }
94784
94785 -static int
94786 +int
94787 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
94788 {
94789 return send_signal(sig, info, t, 0);
94790 @@ -1213,6 +1223,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
94791 unsigned long int flags;
94792 int ret, blocked, ignored;
94793 struct k_sigaction *action;
94794 + int is_unhandled = 0;
94795
94796 spin_lock_irqsave(&t->sighand->siglock, flags);
94797 action = &t->sighand->action[sig-1];
94798 @@ -1227,9 +1238,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
94799 }
94800 if (action->sa.sa_handler == SIG_DFL)
94801 t->signal->flags &= ~SIGNAL_UNKILLABLE;
94802 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
94803 + is_unhandled = 1;
94804 ret = specific_send_sig_info(sig, info, t);
94805 spin_unlock_irqrestore(&t->sighand->siglock, flags);
94806
94807 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
94808 + normal operation */
94809 + if (is_unhandled) {
94810 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
94811 + gr_handle_crash(t, sig);
94812 + }
94813 +
94814 return ret;
94815 }
94816
94817 @@ -1296,8 +1316,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
94818 ret = check_kill_permission(sig, info, p);
94819 rcu_read_unlock();
94820
94821 - if (!ret && sig)
94822 + if (!ret && sig) {
94823 ret = do_send_sig_info(sig, info, p, true);
94824 + if (!ret)
94825 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
94826 + }
94827
94828 return ret;
94829 }
94830 @@ -2903,7 +2926,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
94831 int error = -ESRCH;
94832
94833 rcu_read_lock();
94834 - p = find_task_by_vpid(pid);
94835 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
94836 + /* allow glibc communication via tgkill to other threads in our
94837 + thread group */
94838 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
94839 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
94840 + p = find_task_by_vpid_unrestricted(pid);
94841 + else
94842 +#endif
94843 + p = find_task_by_vpid(pid);
94844 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
94845 error = check_kill_permission(sig, info, p);
94846 /*
94847 @@ -3236,8 +3267,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
94848 }
94849 seg = get_fs();
94850 set_fs(KERNEL_DS);
94851 - ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
94852 - (stack_t __force __user *) &uoss,
94853 + ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
94854 + (stack_t __force_user *) &uoss,
94855 compat_user_stack_pointer());
94856 set_fs(seg);
94857 if (ret >= 0 && uoss_ptr) {
94858 diff --git a/kernel/smpboot.c b/kernel/smpboot.c
94859 index eb89e18..a4e6792 100644
94860 --- a/kernel/smpboot.c
94861 +++ b/kernel/smpboot.c
94862 @@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
94863 }
94864 smpboot_unpark_thread(plug_thread, cpu);
94865 }
94866 - list_add(&plug_thread->list, &hotplug_threads);
94867 + pax_list_add(&plug_thread->list, &hotplug_threads);
94868 out:
94869 mutex_unlock(&smpboot_threads_lock);
94870 return ret;
94871 @@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
94872 {
94873 get_online_cpus();
94874 mutex_lock(&smpboot_threads_lock);
94875 - list_del(&plug_thread->list);
94876 + pax_list_del(&plug_thread->list);
94877 smpboot_destroy_threads(plug_thread);
94878 mutex_unlock(&smpboot_threads_lock);
94879 put_online_cpus();
94880 diff --git a/kernel/softirq.c b/kernel/softirq.c
94881 index 5918d22..e95d1926 100644
94882 --- a/kernel/softirq.c
94883 +++ b/kernel/softirq.c
94884 @@ -53,7 +53,7 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
94885 EXPORT_SYMBOL(irq_stat);
94886 #endif
94887
94888 -static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
94889 +static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
94890
94891 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
94892
94893 @@ -266,7 +266,7 @@ restart:
94894 kstat_incr_softirqs_this_cpu(vec_nr);
94895
94896 trace_softirq_entry(vec_nr);
94897 - h->action(h);
94898 + h->action();
94899 trace_softirq_exit(vec_nr);
94900 if (unlikely(prev_count != preempt_count())) {
94901 pr_err("huh, entered softirq %u %s %p with preempt_count %08x, exited with %08x?\n",
94902 @@ -426,7 +426,7 @@ void __raise_softirq_irqoff(unsigned int nr)
94903 or_softirq_pending(1UL << nr);
94904 }
94905
94906 -void open_softirq(int nr, void (*action)(struct softirq_action *))
94907 +void __init open_softirq(int nr, void (*action)(void))
94908 {
94909 softirq_vec[nr].action = action;
94910 }
94911 @@ -478,7 +478,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
94912 }
94913 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
94914
94915 -static void tasklet_action(struct softirq_action *a)
94916 +static void tasklet_action(void)
94917 {
94918 struct tasklet_struct *list;
94919
94920 @@ -514,7 +514,7 @@ static void tasklet_action(struct softirq_action *a)
94921 }
94922 }
94923
94924 -static void tasklet_hi_action(struct softirq_action *a)
94925 +static __latent_entropy void tasklet_hi_action(void)
94926 {
94927 struct tasklet_struct *list;
94928
94929 @@ -741,7 +741,7 @@ static struct notifier_block cpu_nfb = {
94930 .notifier_call = cpu_callback
94931 };
94932
94933 -static struct smp_hotplug_thread softirq_threads = {
94934 +static struct smp_hotplug_thread softirq_threads __read_only = {
94935 .store = &ksoftirqd,
94936 .thread_should_run = ksoftirqd_should_run,
94937 .thread_fn = run_ksoftirqd,
94938 diff --git a/kernel/sys.c b/kernel/sys.c
94939 index 66a751e..a42497e 100644
94940 --- a/kernel/sys.c
94941 +++ b/kernel/sys.c
94942 @@ -148,6 +148,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
94943 error = -EACCES;
94944 goto out;
94945 }
94946 +
94947 + if (gr_handle_chroot_setpriority(p, niceval)) {
94948 + error = -EACCES;
94949 + goto out;
94950 + }
94951 +
94952 no_nice = security_task_setnice(p, niceval);
94953 if (no_nice) {
94954 error = no_nice;
94955 @@ -351,6 +357,20 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
94956 goto error;
94957 }
94958
94959 + if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
94960 + goto error;
94961 +
94962 + if (!gid_eq(new->gid, old->gid)) {
94963 + /* make sure we generate a learn log for what will
94964 + end up being a role transition after a full-learning
94965 + policy is generated
94966 + CAP_SETGID is required to perform a transition
94967 + we may not log a CAP_SETGID check above, e.g.
94968 + in the case where new rgid = old egid
94969 + */
94970 + gr_learn_cap(current, new, CAP_SETGID);
94971 + }
94972 +
94973 if (rgid != (gid_t) -1 ||
94974 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
94975 new->sgid = new->egid;
94976 @@ -386,6 +406,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
94977 old = current_cred();
94978
94979 retval = -EPERM;
94980 +
94981 + if (gr_check_group_change(kgid, kgid, kgid))
94982 + goto error;
94983 +
94984 if (ns_capable(old->user_ns, CAP_SETGID))
94985 new->gid = new->egid = new->sgid = new->fsgid = kgid;
94986 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
94987 @@ -403,7 +427,7 @@ error:
94988 /*
94989 * change the user struct in a credentials set to match the new UID
94990 */
94991 -static int set_user(struct cred *new)
94992 +int set_user(struct cred *new)
94993 {
94994 struct user_struct *new_user;
94995
94996 @@ -483,7 +507,18 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
94997 goto error;
94998 }
94999
95000 + if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
95001 + goto error;
95002 +
95003 if (!uid_eq(new->uid, old->uid)) {
95004 + /* make sure we generate a learn log for what will
95005 + end up being a role transition after a full-learning
95006 + policy is generated
95007 + CAP_SETUID is required to perform a transition
95008 + we may not log a CAP_SETUID check above, e.g.
95009 + in the case where new ruid = old euid
95010 + */
95011 + gr_learn_cap(current, new, CAP_SETUID);
95012 retval = set_user(new);
95013 if (retval < 0)
95014 goto error;
95015 @@ -533,6 +568,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
95016 old = current_cred();
95017
95018 retval = -EPERM;
95019 +
95020 + if (gr_check_crash_uid(kuid))
95021 + goto error;
95022 + if (gr_check_user_change(kuid, kuid, kuid))
95023 + goto error;
95024 +
95025 if (ns_capable(old->user_ns, CAP_SETUID)) {
95026 new->suid = new->uid = kuid;
95027 if (!uid_eq(kuid, old->uid)) {
95028 @@ -602,6 +643,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
95029 goto error;
95030 }
95031
95032 + if (gr_check_user_change(kruid, keuid, INVALID_UID))
95033 + goto error;
95034 +
95035 if (ruid != (uid_t) -1) {
95036 new->uid = kruid;
95037 if (!uid_eq(kruid, old->uid)) {
95038 @@ -684,6 +728,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
95039 goto error;
95040 }
95041
95042 + if (gr_check_group_change(krgid, kegid, INVALID_GID))
95043 + goto error;
95044 +
95045 if (rgid != (gid_t) -1)
95046 new->gid = krgid;
95047 if (egid != (gid_t) -1)
95048 @@ -745,12 +792,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
95049 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
95050 ns_capable(old->user_ns, CAP_SETUID)) {
95051 if (!uid_eq(kuid, old->fsuid)) {
95052 + if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
95053 + goto error;
95054 +
95055 new->fsuid = kuid;
95056 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
95057 goto change_okay;
95058 }
95059 }
95060
95061 +error:
95062 abort_creds(new);
95063 return old_fsuid;
95064
95065 @@ -783,12 +834,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
95066 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
95067 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
95068 ns_capable(old->user_ns, CAP_SETGID)) {
95069 + if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
95070 + goto error;
95071 +
95072 if (!gid_eq(kgid, old->fsgid)) {
95073 new->fsgid = kgid;
95074 goto change_okay;
95075 }
95076 }
95077
95078 +error:
95079 abort_creds(new);
95080 return old_fsgid;
95081
95082 @@ -1167,19 +1222,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
95083 return -EFAULT;
95084
95085 down_read(&uts_sem);
95086 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
95087 + error = __copy_to_user(name->sysname, &utsname()->sysname,
95088 __OLD_UTS_LEN);
95089 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
95090 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
95091 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
95092 __OLD_UTS_LEN);
95093 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
95094 - error |= __copy_to_user(&name->release, &utsname()->release,
95095 + error |= __copy_to_user(name->release, &utsname()->release,
95096 __OLD_UTS_LEN);
95097 error |= __put_user(0, name->release + __OLD_UTS_LEN);
95098 - error |= __copy_to_user(&name->version, &utsname()->version,
95099 + error |= __copy_to_user(name->version, &utsname()->version,
95100 __OLD_UTS_LEN);
95101 error |= __put_user(0, name->version + __OLD_UTS_LEN);
95102 - error |= __copy_to_user(&name->machine, &utsname()->machine,
95103 + error |= __copy_to_user(name->machine, &utsname()->machine,
95104 __OLD_UTS_LEN);
95105 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
95106 up_read(&uts_sem);
95107 @@ -1381,6 +1436,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
95108 */
95109 new_rlim->rlim_cur = 1;
95110 }
95111 + /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
95112 + is changed to a lower value. Since tasks can be created by the same
95113 + user in between this limit change and an execve by this task, force
95114 + a recheck only for this task by setting PF_NPROC_EXCEEDED
95115 + */
95116 + if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
95117 + tsk->flags |= PF_NPROC_EXCEEDED;
95118 }
95119 if (!retval) {
95120 if (old_rlim)
95121 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
95122 index 75b22e2..65c0ac8 100644
95123 --- a/kernel/sysctl.c
95124 +++ b/kernel/sysctl.c
95125 @@ -94,7 +94,6 @@
95126
95127
95128 #if defined(CONFIG_SYSCTL)
95129 -
95130 /* External variables not in a header file. */
95131 extern int max_threads;
95132 extern int suid_dumpable;
95133 @@ -115,19 +114,20 @@ extern int sysctl_nr_trim_pages;
95134
95135 /* Constants used for minimum and maximum */
95136 #ifdef CONFIG_LOCKUP_DETECTOR
95137 -static int sixty = 60;
95138 +static int sixty __read_only = 60;
95139 #endif
95140
95141 -static int __maybe_unused neg_one = -1;
95142 +static int __maybe_unused neg_one __read_only = -1;
95143
95144 -static int zero;
95145 -static int __maybe_unused one = 1;
95146 -static int __maybe_unused two = 2;
95147 -static int __maybe_unused four = 4;
95148 -static unsigned long one_ul = 1;
95149 -static int one_hundred = 100;
95150 +static int zero __read_only = 0;
95151 +static int __maybe_unused one __read_only = 1;
95152 +static int __maybe_unused two __read_only = 2;
95153 +static int __maybe_unused three __read_only = 3;
95154 +static int __maybe_unused four __read_only = 4;
95155 +static unsigned long one_ul __read_only = 1;
95156 +static int one_hundred __read_only = 100;
95157 #ifdef CONFIG_PRINTK
95158 -static int ten_thousand = 10000;
95159 +static int ten_thousand __read_only = 10000;
95160 #endif
95161
95162 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
95163 @@ -181,10 +181,8 @@ static int proc_taint(struct ctl_table *table, int write,
95164 void __user *buffer, size_t *lenp, loff_t *ppos);
95165 #endif
95166
95167 -#ifdef CONFIG_PRINTK
95168 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
95169 void __user *buffer, size_t *lenp, loff_t *ppos);
95170 -#endif
95171
95172 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
95173 void __user *buffer, size_t *lenp, loff_t *ppos);
95174 @@ -215,6 +213,8 @@ static int sysrq_sysctl_handler(struct ctl_table *table, int write,
95175
95176 #endif
95177
95178 +extern struct ctl_table grsecurity_table[];
95179 +
95180 static struct ctl_table kern_table[];
95181 static struct ctl_table vm_table[];
95182 static struct ctl_table fs_table[];
95183 @@ -229,6 +229,20 @@ extern struct ctl_table epoll_table[];
95184 int sysctl_legacy_va_layout;
95185 #endif
95186
95187 +#ifdef CONFIG_PAX_SOFTMODE
95188 +static ctl_table pax_table[] = {
95189 + {
95190 + .procname = "softmode",
95191 + .data = &pax_softmode,
95192 + .maxlen = sizeof(unsigned int),
95193 + .mode = 0600,
95194 + .proc_handler = &proc_dointvec,
95195 + },
95196 +
95197 + { }
95198 +};
95199 +#endif
95200 +
95201 /* The default sysctl tables: */
95202
95203 static struct ctl_table sysctl_base_table[] = {
95204 @@ -277,6 +291,22 @@ static int max_extfrag_threshold = 1000;
95205 #endif
95206
95207 static struct ctl_table kern_table[] = {
95208 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
95209 + {
95210 + .procname = "grsecurity",
95211 + .mode = 0500,
95212 + .child = grsecurity_table,
95213 + },
95214 +#endif
95215 +
95216 +#ifdef CONFIG_PAX_SOFTMODE
95217 + {
95218 + .procname = "pax",
95219 + .mode = 0500,
95220 + .child = pax_table,
95221 + },
95222 +#endif
95223 +
95224 {
95225 .procname = "sched_child_runs_first",
95226 .data = &sysctl_sched_child_runs_first,
95227 @@ -641,7 +671,7 @@ static struct ctl_table kern_table[] = {
95228 .data = &modprobe_path,
95229 .maxlen = KMOD_PATH_LEN,
95230 .mode = 0644,
95231 - .proc_handler = proc_dostring,
95232 + .proc_handler = proc_dostring_modpriv,
95233 },
95234 {
95235 .procname = "modules_disabled",
95236 @@ -808,16 +838,20 @@ static struct ctl_table kern_table[] = {
95237 .extra1 = &zero,
95238 .extra2 = &one,
95239 },
95240 +#endif
95241 {
95242 .procname = "kptr_restrict",
95243 .data = &kptr_restrict,
95244 .maxlen = sizeof(int),
95245 .mode = 0644,
95246 .proc_handler = proc_dointvec_minmax_sysadmin,
95247 +#ifdef CONFIG_GRKERNSEC_HIDESYM
95248 + .extra1 = &two,
95249 +#else
95250 .extra1 = &zero,
95251 +#endif
95252 .extra2 = &two,
95253 },
95254 -#endif
95255 {
95256 .procname = "ngroups_max",
95257 .data = &ngroups_max,
95258 @@ -1073,10 +1107,17 @@ static struct ctl_table kern_table[] = {
95259 */
95260 {
95261 .procname = "perf_event_paranoid",
95262 - .data = &sysctl_perf_event_paranoid,
95263 - .maxlen = sizeof(sysctl_perf_event_paranoid),
95264 + .data = &sysctl_perf_event_legitimately_concerned,
95265 + .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
95266 .mode = 0644,
95267 - .proc_handler = proc_dointvec,
95268 + /* go ahead, be a hero */
95269 + .proc_handler = proc_dointvec_minmax_sysadmin,
95270 + .extra1 = &neg_one,
95271 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
95272 + .extra2 = &three,
95273 +#else
95274 + .extra2 = &two,
95275 +#endif
95276 },
95277 {
95278 .procname = "perf_event_mlock_kb",
95279 @@ -1338,6 +1379,13 @@ static struct ctl_table vm_table[] = {
95280 .proc_handler = proc_dointvec_minmax,
95281 .extra1 = &zero,
95282 },
95283 + {
95284 + .procname = "heap_stack_gap",
95285 + .data = &sysctl_heap_stack_gap,
95286 + .maxlen = sizeof(sysctl_heap_stack_gap),
95287 + .mode = 0644,
95288 + .proc_handler = proc_doulongvec_minmax,
95289 + },
95290 #else
95291 {
95292 .procname = "nr_trim_pages",
95293 @@ -1827,6 +1875,16 @@ int proc_dostring(struct ctl_table *table, int write,
95294 (char __user *)buffer, lenp, ppos);
95295 }
95296
95297 +int proc_dostring_modpriv(struct ctl_table *table, int write,
95298 + void __user *buffer, size_t *lenp, loff_t *ppos)
95299 +{
95300 + if (write && !capable(CAP_SYS_MODULE))
95301 + return -EPERM;
95302 +
95303 + return _proc_do_string(table->data, table->maxlen, write,
95304 + buffer, lenp, ppos);
95305 +}
95306 +
95307 static size_t proc_skip_spaces(char **buf)
95308 {
95309 size_t ret;
95310 @@ -1932,6 +1990,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
95311 len = strlen(tmp);
95312 if (len > *size)
95313 len = *size;
95314 + if (len > sizeof(tmp))
95315 + len = sizeof(tmp);
95316 if (copy_to_user(*buf, tmp, len))
95317 return -EFAULT;
95318 *size -= len;
95319 @@ -2109,7 +2169,7 @@ int proc_dointvec(struct ctl_table *table, int write,
95320 static int proc_taint(struct ctl_table *table, int write,
95321 void __user *buffer, size_t *lenp, loff_t *ppos)
95322 {
95323 - struct ctl_table t;
95324 + ctl_table_no_const t;
95325 unsigned long tmptaint = get_taint();
95326 int err;
95327
95328 @@ -2137,7 +2197,6 @@ static int proc_taint(struct ctl_table *table, int write,
95329 return err;
95330 }
95331
95332 -#ifdef CONFIG_PRINTK
95333 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
95334 void __user *buffer, size_t *lenp, loff_t *ppos)
95335 {
95336 @@ -2146,7 +2205,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
95337
95338 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
95339 }
95340 -#endif
95341
95342 struct do_proc_dointvec_minmax_conv_param {
95343 int *min;
95344 @@ -2706,6 +2764,12 @@ int proc_dostring(struct ctl_table *table, int write,
95345 return -ENOSYS;
95346 }
95347
95348 +int proc_dostring_modpriv(struct ctl_table *table, int write,
95349 + void __user *buffer, size_t *lenp, loff_t *ppos)
95350 +{
95351 + return -ENOSYS;
95352 +}
95353 +
95354 int proc_dointvec(struct ctl_table *table, int write,
95355 void __user *buffer, size_t *lenp, loff_t *ppos)
95356 {
95357 @@ -2762,5 +2826,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
95358 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
95359 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
95360 EXPORT_SYMBOL(proc_dostring);
95361 +EXPORT_SYMBOL(proc_dostring_modpriv);
95362 EXPORT_SYMBOL(proc_doulongvec_minmax);
95363 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
95364 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
95365 index 13d2f7c..c93d0b0 100644
95366 --- a/kernel/taskstats.c
95367 +++ b/kernel/taskstats.c
95368 @@ -28,9 +28,12 @@
95369 #include <linux/fs.h>
95370 #include <linux/file.h>
95371 #include <linux/pid_namespace.h>
95372 +#include <linux/grsecurity.h>
95373 #include <net/genetlink.h>
95374 #include <linux/atomic.h>
95375
95376 +extern int gr_is_taskstats_denied(int pid);
95377 +
95378 /*
95379 * Maximum length of a cpumask that can be specified in
95380 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
95381 @@ -576,6 +579,9 @@ err:
95382
95383 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
95384 {
95385 + if (gr_is_taskstats_denied(current->pid))
95386 + return -EACCES;
95387 +
95388 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
95389 return cmd_attr_register_cpumask(info);
95390 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
95391 diff --git a/kernel/time.c b/kernel/time.c
95392 index 7c7964c..2a0d412 100644
95393 --- a/kernel/time.c
95394 +++ b/kernel/time.c
95395 @@ -172,6 +172,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
95396 return error;
95397
95398 if (tz) {
95399 + /* we log in do_settimeofday called below, so don't log twice
95400 + */
95401 + if (!tv)
95402 + gr_log_timechange();
95403 +
95404 sys_tz = *tz;
95405 update_vsyscall_tz();
95406 if (firsttime) {
95407 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
95408 index fe75444..190c528 100644
95409 --- a/kernel/time/alarmtimer.c
95410 +++ b/kernel/time/alarmtimer.c
95411 @@ -811,7 +811,7 @@ static int __init alarmtimer_init(void)
95412 struct platform_device *pdev;
95413 int error = 0;
95414 int i;
95415 - struct k_clock alarm_clock = {
95416 + static struct k_clock alarm_clock = {
95417 .clock_getres = alarm_clock_getres,
95418 .clock_get = alarm_clock_get,
95419 .timer_create = alarm_timer_create,
95420 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
95421 index 32d8d6a..11486af 100644
95422 --- a/kernel/time/timekeeping.c
95423 +++ b/kernel/time/timekeeping.c
95424 @@ -15,6 +15,7 @@
95425 #include <linux/init.h>
95426 #include <linux/mm.h>
95427 #include <linux/sched.h>
95428 +#include <linux/grsecurity.h>
95429 #include <linux/syscore_ops.h>
95430 #include <linux/clocksource.h>
95431 #include <linux/jiffies.h>
95432 @@ -502,6 +503,8 @@ int do_settimeofday(const struct timespec *tv)
95433 if (!timespec_valid_strict(tv))
95434 return -EINVAL;
95435
95436 + gr_log_timechange();
95437 +
95438 raw_spin_lock_irqsave(&timekeeper_lock, flags);
95439 write_seqcount_begin(&timekeeper_seq);
95440
95441 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
95442 index 61ed862..3b52c65 100644
95443 --- a/kernel/time/timer_list.c
95444 +++ b/kernel/time/timer_list.c
95445 @@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
95446
95447 static void print_name_offset(struct seq_file *m, void *sym)
95448 {
95449 +#ifdef CONFIG_GRKERNSEC_HIDESYM
95450 + SEQ_printf(m, "<%p>", NULL);
95451 +#else
95452 char symname[KSYM_NAME_LEN];
95453
95454 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
95455 SEQ_printf(m, "<%pK>", sym);
95456 else
95457 SEQ_printf(m, "%s", symname);
95458 +#endif
95459 }
95460
95461 static void
95462 @@ -119,7 +123,11 @@ next_one:
95463 static void
95464 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
95465 {
95466 +#ifdef CONFIG_GRKERNSEC_HIDESYM
95467 + SEQ_printf(m, " .base: %p\n", NULL);
95468 +#else
95469 SEQ_printf(m, " .base: %pK\n", base);
95470 +#endif
95471 SEQ_printf(m, " .index: %d\n",
95472 base->index);
95473 SEQ_printf(m, " .resolution: %Lu nsecs\n",
95474 @@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
95475 {
95476 struct proc_dir_entry *pe;
95477
95478 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
95479 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
95480 +#else
95481 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
95482 +#endif
95483 if (!pe)
95484 return -ENOMEM;
95485 return 0;
95486 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
95487 index 1fb08f2..ca4bb1e 100644
95488 --- a/kernel/time/timer_stats.c
95489 +++ b/kernel/time/timer_stats.c
95490 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
95491 static unsigned long nr_entries;
95492 static struct entry entries[MAX_ENTRIES];
95493
95494 -static atomic_t overflow_count;
95495 +static atomic_unchecked_t overflow_count;
95496
95497 /*
95498 * The entries are in a hash-table, for fast lookup:
95499 @@ -140,7 +140,7 @@ static void reset_entries(void)
95500 nr_entries = 0;
95501 memset(entries, 0, sizeof(entries));
95502 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
95503 - atomic_set(&overflow_count, 0);
95504 + atomic_set_unchecked(&overflow_count, 0);
95505 }
95506
95507 static struct entry *alloc_entry(void)
95508 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
95509 if (likely(entry))
95510 entry->count++;
95511 else
95512 - atomic_inc(&overflow_count);
95513 + atomic_inc_unchecked(&overflow_count);
95514
95515 out_unlock:
95516 raw_spin_unlock_irqrestore(lock, flags);
95517 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
95518
95519 static void print_name_offset(struct seq_file *m, unsigned long addr)
95520 {
95521 +#ifdef CONFIG_GRKERNSEC_HIDESYM
95522 + seq_printf(m, "<%p>", NULL);
95523 +#else
95524 char symname[KSYM_NAME_LEN];
95525
95526 if (lookup_symbol_name(addr, symname) < 0)
95527 - seq_printf(m, "<%p>", (void *)addr);
95528 + seq_printf(m, "<%pK>", (void *)addr);
95529 else
95530 seq_printf(m, "%s", symname);
95531 +#endif
95532 }
95533
95534 static int tstats_show(struct seq_file *m, void *v)
95535 @@ -300,8 +304,8 @@ static int tstats_show(struct seq_file *m, void *v)
95536
95537 seq_puts(m, "Timer Stats Version: v0.3\n");
95538 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
95539 - if (atomic_read(&overflow_count))
95540 - seq_printf(m, "Overflow: %d entries\n", atomic_read(&overflow_count));
95541 + if (atomic_read_unchecked(&overflow_count))
95542 + seq_printf(m, "Overflow: %d entries\n", atomic_read_unchecked(&overflow_count));
95543 seq_printf(m, "Collection: %s\n", timer_stats_active ? "active" : "inactive");
95544
95545 for (i = 0; i < nr_entries; i++) {
95546 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
95547 {
95548 struct proc_dir_entry *pe;
95549
95550 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
95551 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
95552 +#else
95553 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
95554 +#endif
95555 if (!pe)
95556 return -ENOMEM;
95557 return 0;
95558 diff --git a/kernel/timer.c b/kernel/timer.c
95559 index 3bb01a3..0e7760e 100644
95560 --- a/kernel/timer.c
95561 +++ b/kernel/timer.c
95562 @@ -1393,7 +1393,7 @@ void update_process_times(int user_tick)
95563 /*
95564 * This function runs timers and the timer-tq in bottom half context.
95565 */
95566 -static void run_timer_softirq(struct softirq_action *h)
95567 +static __latent_entropy void run_timer_softirq(void)
95568 {
95569 struct tvec_base *base = __this_cpu_read(tvec_bases);
95570
95571 @@ -1456,7 +1456,7 @@ static void process_timeout(unsigned long __data)
95572 *
95573 * In all cases the return value is guaranteed to be non-negative.
95574 */
95575 -signed long __sched schedule_timeout(signed long timeout)
95576 +signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
95577 {
95578 struct timer_list timer;
95579 unsigned long expire;
95580 diff --git a/kernel/torture.c b/kernel/torture.c
95581 index 40bb511..91190b9 100644
95582 --- a/kernel/torture.c
95583 +++ b/kernel/torture.c
95584 @@ -484,7 +484,7 @@ static int torture_shutdown_notify(struct notifier_block *unused1,
95585 mutex_lock(&fullstop_mutex);
95586 if (ACCESS_ONCE(fullstop) == FULLSTOP_DONTSTOP) {
95587 VERBOSE_TOROUT_STRING("Unscheduled system shutdown detected");
95588 - ACCESS_ONCE(fullstop) = FULLSTOP_SHUTDOWN;
95589 + ACCESS_ONCE_RW(fullstop) = FULLSTOP_SHUTDOWN;
95590 } else {
95591 pr_warn("Concurrent rmmod and shutdown illegal!\n");
95592 }
95593 @@ -551,14 +551,14 @@ static int torture_stutter(void *arg)
95594 if (!torture_must_stop()) {
95595 if (stutter > 1) {
95596 schedule_timeout_interruptible(stutter - 1);
95597 - ACCESS_ONCE(stutter_pause_test) = 2;
95598 + ACCESS_ONCE_RW(stutter_pause_test) = 2;
95599 }
95600 schedule_timeout_interruptible(1);
95601 - ACCESS_ONCE(stutter_pause_test) = 1;
95602 + ACCESS_ONCE_RW(stutter_pause_test) = 1;
95603 }
95604 if (!torture_must_stop())
95605 schedule_timeout_interruptible(stutter);
95606 - ACCESS_ONCE(stutter_pause_test) = 0;
95607 + ACCESS_ONCE_RW(stutter_pause_test) = 0;
95608 torture_shutdown_absorb("torture_stutter");
95609 } while (!torture_must_stop());
95610 torture_kthread_stopping("torture_stutter");
95611 @@ -645,7 +645,7 @@ bool torture_cleanup(void)
95612 schedule_timeout_uninterruptible(10);
95613 return true;
95614 }
95615 - ACCESS_ONCE(fullstop) = FULLSTOP_RMMOD;
95616 + ACCESS_ONCE_RW(fullstop) = FULLSTOP_RMMOD;
95617 mutex_unlock(&fullstop_mutex);
95618 torture_shutdown_cleanup();
95619 torture_shuffle_cleanup();
95620 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
95621 index c1bd4ad..4b861dc 100644
95622 --- a/kernel/trace/blktrace.c
95623 +++ b/kernel/trace/blktrace.c
95624 @@ -328,7 +328,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
95625 struct blk_trace *bt = filp->private_data;
95626 char buf[16];
95627
95628 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
95629 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
95630
95631 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
95632 }
95633 @@ -386,7 +386,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
95634 return 1;
95635
95636 bt = buf->chan->private_data;
95637 - atomic_inc(&bt->dropped);
95638 + atomic_inc_unchecked(&bt->dropped);
95639 return 0;
95640 }
95641
95642 @@ -487,7 +487,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
95643
95644 bt->dir = dir;
95645 bt->dev = dev;
95646 - atomic_set(&bt->dropped, 0);
95647 + atomic_set_unchecked(&bt->dropped, 0);
95648 INIT_LIST_HEAD(&bt->running_list);
95649
95650 ret = -EIO;
95651 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
95652 index ac9d1da..ce98b35 100644
95653 --- a/kernel/trace/ftrace.c
95654 +++ b/kernel/trace/ftrace.c
95655 @@ -1920,12 +1920,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
95656 if (unlikely(ftrace_disabled))
95657 return 0;
95658
95659 + ret = ftrace_arch_code_modify_prepare();
95660 + FTRACE_WARN_ON(ret);
95661 + if (ret)
95662 + return 0;
95663 +
95664 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
95665 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
95666 if (ret) {
95667 ftrace_bug(ret, ip);
95668 - return 0;
95669 }
95670 - return 1;
95671 + return ret ? 0 : 1;
95672 }
95673
95674 /*
95675 @@ -4126,8 +4131,10 @@ static int ftrace_process_locs(struct module *mod,
95676 if (!count)
95677 return 0;
95678
95679 + pax_open_kernel();
95680 sort(start, count, sizeof(*start),
95681 ftrace_cmp_ips, ftrace_swap_ips);
95682 + pax_close_kernel();
95683
95684 start_pg = ftrace_allocate_pages(count);
95685 if (!start_pg)
95686 diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
95687 index ff70271..4242e69 100644
95688 --- a/kernel/trace/ring_buffer.c
95689 +++ b/kernel/trace/ring_buffer.c
95690 @@ -352,9 +352,9 @@ struct buffer_data_page {
95691 */
95692 struct buffer_page {
95693 struct list_head list; /* list of buffer pages */
95694 - local_t write; /* index for next write */
95695 + local_unchecked_t write; /* index for next write */
95696 unsigned read; /* index for next read */
95697 - local_t entries; /* entries on this page */
95698 + local_unchecked_t entries; /* entries on this page */
95699 unsigned long real_end; /* real end of data */
95700 struct buffer_data_page *page; /* Actual data page */
95701 };
95702 @@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
95703 unsigned long last_overrun;
95704 local_t entries_bytes;
95705 local_t entries;
95706 - local_t overrun;
95707 - local_t commit_overrun;
95708 + local_unchecked_t overrun;
95709 + local_unchecked_t commit_overrun;
95710 local_t dropped_events;
95711 local_t committing;
95712 local_t commits;
95713 @@ -626,8 +626,22 @@ int ring_buffer_poll_wait(struct ring_buffer *buffer, int cpu,
95714 work = &cpu_buffer->irq_work;
95715 }
95716
95717 - work->waiters_pending = true;
95718 poll_wait(filp, &work->waiters, poll_table);
95719 + work->waiters_pending = true;
95720 + /*
95721 + * There's a tight race between setting the waiters_pending and
95722 + * checking if the ring buffer is empty. Once the waiters_pending bit
95723 + * is set, the next event will wake the task up, but we can get stuck
95724 + * if there's only a single event in.
95725 + *
95726 + * FIXME: Ideally, we need a memory barrier on the writer side as well,
95727 + * but adding a memory barrier to all events will cause too much of a
95728 + * performance hit in the fast path. We only need a memory barrier when
95729 + * the buffer goes from empty to having content. But as this race is
95730 + * extremely small, and it's not a problem if another event comes in, we
95731 + * will fix it later.
95732 + */
95733 + smp_mb();
95734
95735 if ((cpu == RING_BUFFER_ALL_CPUS && !ring_buffer_empty(buffer)) ||
95736 (cpu != RING_BUFFER_ALL_CPUS && !ring_buffer_empty_cpu(buffer, cpu)))
95737 @@ -991,8 +1005,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
95738 *
95739 * We add a counter to the write field to denote this.
95740 */
95741 - old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
95742 - old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
95743 + old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
95744 + old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
95745
95746 /*
95747 * Just make sure we have seen our old_write and synchronize
95748 @@ -1020,8 +1034,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
95749 * cmpxchg to only update if an interrupt did not already
95750 * do it for us. If the cmpxchg fails, we don't care.
95751 */
95752 - (void)local_cmpxchg(&next_page->write, old_write, val);
95753 - (void)local_cmpxchg(&next_page->entries, old_entries, eval);
95754 + (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
95755 + (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
95756
95757 /*
95758 * No need to worry about races with clearing out the commit.
95759 @@ -1388,12 +1402,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
95760
95761 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
95762 {
95763 - return local_read(&bpage->entries) & RB_WRITE_MASK;
95764 + return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
95765 }
95766
95767 static inline unsigned long rb_page_write(struct buffer_page *bpage)
95768 {
95769 - return local_read(&bpage->write) & RB_WRITE_MASK;
95770 + return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
95771 }
95772
95773 static int
95774 @@ -1488,7 +1502,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
95775 * bytes consumed in ring buffer from here.
95776 * Increment overrun to account for the lost events.
95777 */
95778 - local_add(page_entries, &cpu_buffer->overrun);
95779 + local_add_unchecked(page_entries, &cpu_buffer->overrun);
95780 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
95781 }
95782
95783 @@ -2066,7 +2080,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
95784 * it is our responsibility to update
95785 * the counters.
95786 */
95787 - local_add(entries, &cpu_buffer->overrun);
95788 + local_add_unchecked(entries, &cpu_buffer->overrun);
95789 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
95790
95791 /*
95792 @@ -2216,7 +2230,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
95793 if (tail == BUF_PAGE_SIZE)
95794 tail_page->real_end = 0;
95795
95796 - local_sub(length, &tail_page->write);
95797 + local_sub_unchecked(length, &tail_page->write);
95798 return;
95799 }
95800
95801 @@ -2251,7 +2265,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
95802 rb_event_set_padding(event);
95803
95804 /* Set the write back to the previous setting */
95805 - local_sub(length, &tail_page->write);
95806 + local_sub_unchecked(length, &tail_page->write);
95807 return;
95808 }
95809
95810 @@ -2263,7 +2277,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
95811
95812 /* Set write to end of buffer */
95813 length = (tail + length) - BUF_PAGE_SIZE;
95814 - local_sub(length, &tail_page->write);
95815 + local_sub_unchecked(length, &tail_page->write);
95816 }
95817
95818 /*
95819 @@ -2289,7 +2303,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
95820 * about it.
95821 */
95822 if (unlikely(next_page == commit_page)) {
95823 - local_inc(&cpu_buffer->commit_overrun);
95824 + local_inc_unchecked(&cpu_buffer->commit_overrun);
95825 goto out_reset;
95826 }
95827
95828 @@ -2345,7 +2359,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
95829 cpu_buffer->tail_page) &&
95830 (cpu_buffer->commit_page ==
95831 cpu_buffer->reader_page))) {
95832 - local_inc(&cpu_buffer->commit_overrun);
95833 + local_inc_unchecked(&cpu_buffer->commit_overrun);
95834 goto out_reset;
95835 }
95836 }
95837 @@ -2393,7 +2407,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
95838 length += RB_LEN_TIME_EXTEND;
95839
95840 tail_page = cpu_buffer->tail_page;
95841 - write = local_add_return(length, &tail_page->write);
95842 + write = local_add_return_unchecked(length, &tail_page->write);
95843
95844 /* set write to only the index of the write */
95845 write &= RB_WRITE_MASK;
95846 @@ -2417,7 +2431,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
95847 kmemcheck_annotate_bitfield(event, bitfield);
95848 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
95849
95850 - local_inc(&tail_page->entries);
95851 + local_inc_unchecked(&tail_page->entries);
95852
95853 /*
95854 * If this is the first commit on the page, then update
95855 @@ -2450,7 +2464,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
95856
95857 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
95858 unsigned long write_mask =
95859 - local_read(&bpage->write) & ~RB_WRITE_MASK;
95860 + local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
95861 unsigned long event_length = rb_event_length(event);
95862 /*
95863 * This is on the tail page. It is possible that
95864 @@ -2460,7 +2474,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
95865 */
95866 old_index += write_mask;
95867 new_index += write_mask;
95868 - index = local_cmpxchg(&bpage->write, old_index, new_index);
95869 + index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
95870 if (index == old_index) {
95871 /* update counters */
95872 local_sub(event_length, &cpu_buffer->entries_bytes);
95873 @@ -2852,7 +2866,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
95874
95875 /* Do the likely case first */
95876 if (likely(bpage->page == (void *)addr)) {
95877 - local_dec(&bpage->entries);
95878 + local_dec_unchecked(&bpage->entries);
95879 return;
95880 }
95881
95882 @@ -2864,7 +2878,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
95883 start = bpage;
95884 do {
95885 if (bpage->page == (void *)addr) {
95886 - local_dec(&bpage->entries);
95887 + local_dec_unchecked(&bpage->entries);
95888 return;
95889 }
95890 rb_inc_page(cpu_buffer, &bpage);
95891 @@ -3148,7 +3162,7 @@ static inline unsigned long
95892 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
95893 {
95894 return local_read(&cpu_buffer->entries) -
95895 - (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
95896 + (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
95897 }
95898
95899 /**
95900 @@ -3237,7 +3251,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
95901 return 0;
95902
95903 cpu_buffer = buffer->buffers[cpu];
95904 - ret = local_read(&cpu_buffer->overrun);
95905 + ret = local_read_unchecked(&cpu_buffer->overrun);
95906
95907 return ret;
95908 }
95909 @@ -3260,7 +3274,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
95910 return 0;
95911
95912 cpu_buffer = buffer->buffers[cpu];
95913 - ret = local_read(&cpu_buffer->commit_overrun);
95914 + ret = local_read_unchecked(&cpu_buffer->commit_overrun);
95915
95916 return ret;
95917 }
95918 @@ -3345,7 +3359,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
95919 /* if you care about this being correct, lock the buffer */
95920 for_each_buffer_cpu(buffer, cpu) {
95921 cpu_buffer = buffer->buffers[cpu];
95922 - overruns += local_read(&cpu_buffer->overrun);
95923 + overruns += local_read_unchecked(&cpu_buffer->overrun);
95924 }
95925
95926 return overruns;
95927 @@ -3521,8 +3535,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
95928 /*
95929 * Reset the reader page to size zero.
95930 */
95931 - local_set(&cpu_buffer->reader_page->write, 0);
95932 - local_set(&cpu_buffer->reader_page->entries, 0);
95933 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
95934 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
95935 local_set(&cpu_buffer->reader_page->page->commit, 0);
95936 cpu_buffer->reader_page->real_end = 0;
95937
95938 @@ -3556,7 +3570,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
95939 * want to compare with the last_overrun.
95940 */
95941 smp_mb();
95942 - overwrite = local_read(&(cpu_buffer->overrun));
95943 + overwrite = local_read_unchecked(&(cpu_buffer->overrun));
95944
95945 /*
95946 * Here's the tricky part.
95947 @@ -4126,8 +4140,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
95948
95949 cpu_buffer->head_page
95950 = list_entry(cpu_buffer->pages, struct buffer_page, list);
95951 - local_set(&cpu_buffer->head_page->write, 0);
95952 - local_set(&cpu_buffer->head_page->entries, 0);
95953 + local_set_unchecked(&cpu_buffer->head_page->write, 0);
95954 + local_set_unchecked(&cpu_buffer->head_page->entries, 0);
95955 local_set(&cpu_buffer->head_page->page->commit, 0);
95956
95957 cpu_buffer->head_page->read = 0;
95958 @@ -4137,14 +4151,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
95959
95960 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
95961 INIT_LIST_HEAD(&cpu_buffer->new_pages);
95962 - local_set(&cpu_buffer->reader_page->write, 0);
95963 - local_set(&cpu_buffer->reader_page->entries, 0);
95964 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
95965 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
95966 local_set(&cpu_buffer->reader_page->page->commit, 0);
95967 cpu_buffer->reader_page->read = 0;
95968
95969 local_set(&cpu_buffer->entries_bytes, 0);
95970 - local_set(&cpu_buffer->overrun, 0);
95971 - local_set(&cpu_buffer->commit_overrun, 0);
95972 + local_set_unchecked(&cpu_buffer->overrun, 0);
95973 + local_set_unchecked(&cpu_buffer->commit_overrun, 0);
95974 local_set(&cpu_buffer->dropped_events, 0);
95975 local_set(&cpu_buffer->entries, 0);
95976 local_set(&cpu_buffer->committing, 0);
95977 @@ -4549,8 +4563,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
95978 rb_init_page(bpage);
95979 bpage = reader->page;
95980 reader->page = *data_page;
95981 - local_set(&reader->write, 0);
95982 - local_set(&reader->entries, 0);
95983 + local_set_unchecked(&reader->write, 0);
95984 + local_set_unchecked(&reader->entries, 0);
95985 reader->read = 0;
95986 *data_page = bpage;
95987
95988 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
95989 index 291397e..db3836d 100644
95990 --- a/kernel/trace/trace.c
95991 +++ b/kernel/trace/trace.c
95992 @@ -3510,7 +3510,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
95993 return 0;
95994 }
95995
95996 -int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
95997 +int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
95998 {
95999 /* do nothing if flag is already set */
96000 if (!!(trace_flags & mask) == !!enabled)
96001 diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
96002 index 9258f5a..9b1e41e 100644
96003 --- a/kernel/trace/trace.h
96004 +++ b/kernel/trace/trace.h
96005 @@ -1278,7 +1278,7 @@ extern const char *__stop___tracepoint_str[];
96006 void trace_printk_init_buffers(void);
96007 void trace_printk_start_comm(void);
96008 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
96009 -int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
96010 +int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
96011
96012 /*
96013 * Normal trace_printk() and friends allocates special buffers
96014 diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
96015 index 57b67b1..66082a9 100644
96016 --- a/kernel/trace/trace_clock.c
96017 +++ b/kernel/trace/trace_clock.c
96018 @@ -124,7 +124,7 @@ u64 notrace trace_clock_global(void)
96019 return now;
96020 }
96021
96022 -static atomic64_t trace_counter;
96023 +static atomic64_unchecked_t trace_counter;
96024
96025 /*
96026 * trace_clock_counter(): simply an atomic counter.
96027 @@ -133,5 +133,5 @@ static atomic64_t trace_counter;
96028 */
96029 u64 notrace trace_clock_counter(void)
96030 {
96031 - return atomic64_add_return(1, &trace_counter);
96032 + return atomic64_inc_return_unchecked(&trace_counter);
96033 }
96034 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
96035 index 2de5362..c4c7003 100644
96036 --- a/kernel/trace/trace_events.c
96037 +++ b/kernel/trace/trace_events.c
96038 @@ -1722,7 +1722,6 @@ __trace_early_add_new_event(struct ftrace_event_call *call,
96039 return 0;
96040 }
96041
96042 -struct ftrace_module_file_ops;
96043 static void __add_event_to_tracers(struct ftrace_event_call *call);
96044
96045 /* Add an additional event_call dynamically */
96046 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
96047 index 0abd9b8..6a663a2 100644
96048 --- a/kernel/trace/trace_mmiotrace.c
96049 +++ b/kernel/trace/trace_mmiotrace.c
96050 @@ -24,7 +24,7 @@ struct header_iter {
96051 static struct trace_array *mmio_trace_array;
96052 static bool overrun_detected;
96053 static unsigned long prev_overruns;
96054 -static atomic_t dropped_count;
96055 +static atomic_unchecked_t dropped_count;
96056
96057 static void mmio_reset_data(struct trace_array *tr)
96058 {
96059 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
96060
96061 static unsigned long count_overruns(struct trace_iterator *iter)
96062 {
96063 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
96064 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
96065 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
96066
96067 if (over > prev_overruns)
96068 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
96069 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
96070 sizeof(*entry), 0, pc);
96071 if (!event) {
96072 - atomic_inc(&dropped_count);
96073 + atomic_inc_unchecked(&dropped_count);
96074 return;
96075 }
96076 entry = ring_buffer_event_data(event);
96077 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
96078 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
96079 sizeof(*entry), 0, pc);
96080 if (!event) {
96081 - atomic_inc(&dropped_count);
96082 + atomic_inc_unchecked(&dropped_count);
96083 return;
96084 }
96085 entry = ring_buffer_event_data(event);
96086 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
96087 index f3dad80..d291d61 100644
96088 --- a/kernel/trace/trace_output.c
96089 +++ b/kernel/trace/trace_output.c
96090 @@ -322,7 +322,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
96091
96092 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
96093 if (!IS_ERR(p)) {
96094 - p = mangle_path(s->buffer + s->len, p, "\n");
96095 + p = mangle_path(s->buffer + s->len, p, "\n\\");
96096 if (p) {
96097 s->len = p - s->buffer;
96098 return 1;
96099 @@ -980,14 +980,16 @@ int register_ftrace_event(struct trace_event *event)
96100 goto out;
96101 }
96102
96103 + pax_open_kernel();
96104 if (event->funcs->trace == NULL)
96105 - event->funcs->trace = trace_nop_print;
96106 + *(void **)&event->funcs->trace = trace_nop_print;
96107 if (event->funcs->raw == NULL)
96108 - event->funcs->raw = trace_nop_print;
96109 + *(void **)&event->funcs->raw = trace_nop_print;
96110 if (event->funcs->hex == NULL)
96111 - event->funcs->hex = trace_nop_print;
96112 + *(void **)&event->funcs->hex = trace_nop_print;
96113 if (event->funcs->binary == NULL)
96114 - event->funcs->binary = trace_nop_print;
96115 + *(void **)&event->funcs->binary = trace_nop_print;
96116 + pax_close_kernel();
96117
96118 key = event->type & (EVENT_HASHSIZE - 1);
96119
96120 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
96121 index 8a4e5cb..64f270d 100644
96122 --- a/kernel/trace/trace_stack.c
96123 +++ b/kernel/trace/trace_stack.c
96124 @@ -91,7 +91,7 @@ check_stack(unsigned long ip, unsigned long *stack)
96125 return;
96126
96127 /* we do not handle interrupt stacks yet */
96128 - if (!object_is_on_stack(stack))
96129 + if (!object_starts_on_stack(stack))
96130 return;
96131
96132 local_irq_save(flags);
96133 diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
96134 index fcc0256..aee880f 100644
96135 --- a/kernel/user_namespace.c
96136 +++ b/kernel/user_namespace.c
96137 @@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
96138 !kgid_has_mapping(parent_ns, group))
96139 return -EPERM;
96140
96141 +#ifdef CONFIG_GRKERNSEC
96142 + /*
96143 + * This doesn't really inspire confidence:
96144 + * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
96145 + * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
96146 + * Increases kernel attack surface in areas developers
96147 + * previously cared little about ("low importance due
96148 + * to requiring "root" capability")
96149 + * To be removed when this code receives *proper* review
96150 + */
96151 + if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
96152 + !capable(CAP_SETGID))
96153 + return -EPERM;
96154 +#endif
96155 +
96156 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
96157 if (!ns)
96158 return -ENOMEM;
96159 @@ -872,7 +887,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
96160 if (atomic_read(&current->mm->mm_users) > 1)
96161 return -EINVAL;
96162
96163 - if (current->fs->users != 1)
96164 + if (atomic_read(&current->fs->users) != 1)
96165 return -EINVAL;
96166
96167 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
96168 diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
96169 index c8eac43..4b5f08f 100644
96170 --- a/kernel/utsname_sysctl.c
96171 +++ b/kernel/utsname_sysctl.c
96172 @@ -47,7 +47,7 @@ static void put_uts(struct ctl_table *table, int write, void *which)
96173 static int proc_do_uts_string(struct ctl_table *table, int write,
96174 void __user *buffer, size_t *lenp, loff_t *ppos)
96175 {
96176 - struct ctl_table uts_table;
96177 + ctl_table_no_const uts_table;
96178 int r;
96179 memcpy(&uts_table, table, sizeof(uts_table));
96180 uts_table.data = get_uts(table, write);
96181 diff --git a/kernel/watchdog.c b/kernel/watchdog.c
96182 index c3319bd..67efc3c 100644
96183 --- a/kernel/watchdog.c
96184 +++ b/kernel/watchdog.c
96185 @@ -518,7 +518,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
96186 static void watchdog_nmi_disable(unsigned int cpu) { return; }
96187 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
96188
96189 -static struct smp_hotplug_thread watchdog_threads = {
96190 +static struct smp_hotplug_thread watchdog_threads __read_only = {
96191 .store = &softlockup_watchdog,
96192 .thread_should_run = watchdog_should_run,
96193 .thread_fn = watchdog,
96194 diff --git a/kernel/workqueue.c b/kernel/workqueue.c
96195 index 35974ac..43c9e87 100644
96196 --- a/kernel/workqueue.c
96197 +++ b/kernel/workqueue.c
96198 @@ -4576,7 +4576,7 @@ static void rebind_workers(struct worker_pool *pool)
96199 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
96200 worker_flags |= WORKER_REBOUND;
96201 worker_flags &= ~WORKER_UNBOUND;
96202 - ACCESS_ONCE(worker->flags) = worker_flags;
96203 + ACCESS_ONCE_RW(worker->flags) = worker_flags;
96204 }
96205
96206 spin_unlock_irq(&pool->lock);
96207 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
96208 index 7a638aa..20db901 100644
96209 --- a/lib/Kconfig.debug
96210 +++ b/lib/Kconfig.debug
96211 @@ -858,7 +858,7 @@ config DEBUG_MUTEXES
96212
96213 config DEBUG_WW_MUTEX_SLOWPATH
96214 bool "Wait/wound mutex debugging: Slowpath testing"
96215 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
96216 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
96217 select DEBUG_LOCK_ALLOC
96218 select DEBUG_SPINLOCK
96219 select DEBUG_MUTEXES
96220 @@ -871,7 +871,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
96221
96222 config DEBUG_LOCK_ALLOC
96223 bool "Lock debugging: detect incorrect freeing of live locks"
96224 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
96225 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
96226 select DEBUG_SPINLOCK
96227 select DEBUG_MUTEXES
96228 select LOCKDEP
96229 @@ -885,7 +885,7 @@ config DEBUG_LOCK_ALLOC
96230
96231 config PROVE_LOCKING
96232 bool "Lock debugging: prove locking correctness"
96233 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
96234 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
96235 select LOCKDEP
96236 select DEBUG_SPINLOCK
96237 select DEBUG_MUTEXES
96238 @@ -936,7 +936,7 @@ config LOCKDEP
96239
96240 config LOCK_STAT
96241 bool "Lock usage statistics"
96242 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
96243 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
96244 select LOCKDEP
96245 select DEBUG_SPINLOCK
96246 select DEBUG_MUTEXES
96247 @@ -1418,6 +1418,7 @@ config LATENCYTOP
96248 depends on DEBUG_KERNEL
96249 depends on STACKTRACE_SUPPORT
96250 depends on PROC_FS
96251 + depends on !GRKERNSEC_HIDESYM
96252 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !ARC
96253 select KALLSYMS
96254 select KALLSYMS_ALL
96255 @@ -1434,7 +1435,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
96256 config DEBUG_STRICT_USER_COPY_CHECKS
96257 bool "Strict user copy size checks"
96258 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
96259 - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
96260 + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
96261 help
96262 Enabling this option turns a certain set of sanity checks for user
96263 copy operations into compile time failures.
96264 @@ -1554,7 +1555,7 @@ endmenu # runtime tests
96265
96266 config PROVIDE_OHCI1394_DMA_INIT
96267 bool "Remote debugging over FireWire early on boot"
96268 - depends on PCI && X86
96269 + depends on PCI && X86 && !GRKERNSEC
96270 help
96271 If you want to debug problems which hang or crash the kernel early
96272 on boot and the crashing machine has a FireWire port, you can use
96273 diff --git a/lib/Makefile b/lib/Makefile
96274 index ba967a1..2cc869a 100644
96275 --- a/lib/Makefile
96276 +++ b/lib/Makefile
96277 @@ -33,7 +33,6 @@ obj-y += kstrtox.o
96278 obj-$(CONFIG_TEST_KSTRTOX) += test-kstrtox.o
96279 obj-$(CONFIG_TEST_MODULE) += test_module.o
96280 obj-$(CONFIG_TEST_USER_COPY) += test_user_copy.o
96281 -obj-$(CONFIG_TEST_BPF) += test_bpf.o
96282
96283 ifeq ($(CONFIG_DEBUG_KOBJECT),y)
96284 CFLAGS_kobject.o += -DDEBUG
96285 @@ -54,7 +53,7 @@ obj-$(CONFIG_BTREE) += btree.o
96286 obj-$(CONFIG_INTERVAL_TREE) += interval_tree.o
96287 obj-$(CONFIG_ASSOCIATIVE_ARRAY) += assoc_array.o
96288 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
96289 -obj-$(CONFIG_DEBUG_LIST) += list_debug.o
96290 +obj-y += list_debug.o
96291 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
96292
96293 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
96294 diff --git a/lib/average.c b/lib/average.c
96295 index 114d1be..ab0350c 100644
96296 --- a/lib/average.c
96297 +++ b/lib/average.c
96298 @@ -55,7 +55,7 @@ struct ewma *ewma_add(struct ewma *avg, unsigned long val)
96299 {
96300 unsigned long internal = ACCESS_ONCE(avg->internal);
96301
96302 - ACCESS_ONCE(avg->internal) = internal ?
96303 + ACCESS_ONCE_RW(avg->internal) = internal ?
96304 (((internal << avg->weight) - internal) +
96305 (val << avg->factor)) >> avg->weight :
96306 (val << avg->factor);
96307 diff --git a/lib/bitmap.c b/lib/bitmap.c
96308 index 06f7e4f..f3cf2b0 100644
96309 --- a/lib/bitmap.c
96310 +++ b/lib/bitmap.c
96311 @@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
96312 {
96313 int c, old_c, totaldigits, ndigits, nchunks, nbits;
96314 u32 chunk;
96315 - const char __user __force *ubuf = (const char __user __force *)buf;
96316 + const char __user *ubuf = (const char __force_user *)buf;
96317
96318 bitmap_zero(maskp, nmaskbits);
96319
96320 @@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
96321 {
96322 if (!access_ok(VERIFY_READ, ubuf, ulen))
96323 return -EFAULT;
96324 - return __bitmap_parse((const char __force *)ubuf,
96325 + return __bitmap_parse((const char __force_kernel *)ubuf,
96326 ulen, 1, maskp, nmaskbits);
96327
96328 }
96329 @@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
96330 {
96331 unsigned a, b;
96332 int c, old_c, totaldigits;
96333 - const char __user __force *ubuf = (const char __user __force *)buf;
96334 + const char __user *ubuf = (const char __force_user *)buf;
96335 int exp_digit, in_range;
96336
96337 totaldigits = c = 0;
96338 @@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
96339 {
96340 if (!access_ok(VERIFY_READ, ubuf, ulen))
96341 return -EFAULT;
96342 - return __bitmap_parselist((const char __force *)ubuf,
96343 + return __bitmap_parselist((const char __force_kernel *)ubuf,
96344 ulen, 1, maskp, nmaskbits);
96345 }
96346 EXPORT_SYMBOL(bitmap_parselist_user);
96347 diff --git a/lib/bug.c b/lib/bug.c
96348 index d1d7c78..b354235 100644
96349 --- a/lib/bug.c
96350 +++ b/lib/bug.c
96351 @@ -137,6 +137,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
96352 return BUG_TRAP_TYPE_NONE;
96353
96354 bug = find_bug(bugaddr);
96355 + if (!bug)
96356 + return BUG_TRAP_TYPE_NONE;
96357
96358 file = NULL;
96359 line = 0;
96360 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
96361 index 547f7f9..a6d4ba0 100644
96362 --- a/lib/debugobjects.c
96363 +++ b/lib/debugobjects.c
96364 @@ -289,7 +289,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
96365 if (limit > 4)
96366 return;
96367
96368 - is_on_stack = object_is_on_stack(addr);
96369 + is_on_stack = object_starts_on_stack(addr);
96370 if (is_on_stack == onstack)
96371 return;
96372
96373 diff --git a/lib/div64.c b/lib/div64.c
96374 index 4382ad7..08aa558 100644
96375 --- a/lib/div64.c
96376 +++ b/lib/div64.c
96377 @@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
96378 EXPORT_SYMBOL(__div64_32);
96379
96380 #ifndef div_s64_rem
96381 -s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
96382 +s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
96383 {
96384 u64 quotient;
96385
96386 @@ -130,7 +130,7 @@ EXPORT_SYMBOL(div64_u64_rem);
96387 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
96388 */
96389 #ifndef div64_u64
96390 -u64 div64_u64(u64 dividend, u64 divisor)
96391 +u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
96392 {
96393 u32 high = divisor >> 32;
96394 u64 quot;
96395 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
96396 index 98f2d7e..899da5c 100644
96397 --- a/lib/dma-debug.c
96398 +++ b/lib/dma-debug.c
96399 @@ -971,7 +971,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
96400
96401 void dma_debug_add_bus(struct bus_type *bus)
96402 {
96403 - struct notifier_block *nb;
96404 + notifier_block_no_const *nb;
96405
96406 if (global_disable)
96407 return;
96408 @@ -1148,7 +1148,7 @@ static void check_unmap(struct dma_debug_entry *ref)
96409
96410 static void check_for_stack(struct device *dev, void *addr)
96411 {
96412 - if (object_is_on_stack(addr))
96413 + if (object_starts_on_stack(addr))
96414 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
96415 "stack [addr=%p]\n", addr);
96416 }
96417 diff --git a/lib/hash.c b/lib/hash.c
96418 index fea973f..386626f 100644
96419 --- a/lib/hash.c
96420 +++ b/lib/hash.c
96421 @@ -14,7 +14,7 @@
96422 #include <linux/hash.h>
96423 #include <linux/cache.h>
96424
96425 -static struct fast_hash_ops arch_hash_ops __read_mostly = {
96426 +static struct fast_hash_ops arch_hash_ops __read_only = {
96427 .hash = jhash,
96428 .hash2 = jhash2,
96429 };
96430 diff --git a/lib/inflate.c b/lib/inflate.c
96431 index 013a761..c28f3fc 100644
96432 --- a/lib/inflate.c
96433 +++ b/lib/inflate.c
96434 @@ -269,7 +269,7 @@ static void free(void *where)
96435 malloc_ptr = free_mem_ptr;
96436 }
96437 #else
96438 -#define malloc(a) kmalloc(a, GFP_KERNEL)
96439 +#define malloc(a) kmalloc((a), GFP_KERNEL)
96440 #define free(a) kfree(a)
96441 #endif
96442
96443 diff --git a/lib/ioremap.c b/lib/ioremap.c
96444 index 0c9216c..863bd89 100644
96445 --- a/lib/ioremap.c
96446 +++ b/lib/ioremap.c
96447 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
96448 unsigned long next;
96449
96450 phys_addr -= addr;
96451 - pmd = pmd_alloc(&init_mm, pud, addr);
96452 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
96453 if (!pmd)
96454 return -ENOMEM;
96455 do {
96456 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
96457 unsigned long next;
96458
96459 phys_addr -= addr;
96460 - pud = pud_alloc(&init_mm, pgd, addr);
96461 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
96462 if (!pud)
96463 return -ENOMEM;
96464 do {
96465 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
96466 index bd2bea9..6b3c95e 100644
96467 --- a/lib/is_single_threaded.c
96468 +++ b/lib/is_single_threaded.c
96469 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
96470 struct task_struct *p, *t;
96471 bool ret;
96472
96473 + if (!mm)
96474 + return true;
96475 +
96476 if (atomic_read(&task->signal->live) != 1)
96477 return false;
96478
96479 diff --git a/lib/kobject.c b/lib/kobject.c
96480 index 58751bb..93a1853 100644
96481 --- a/lib/kobject.c
96482 +++ b/lib/kobject.c
96483 @@ -931,9 +931,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
96484
96485
96486 static DEFINE_SPINLOCK(kobj_ns_type_lock);
96487 -static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
96488 +static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
96489
96490 -int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
96491 +int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
96492 {
96493 enum kobj_ns_type type = ops->type;
96494 int error;
96495 diff --git a/lib/list_debug.c b/lib/list_debug.c
96496 index c24c2f7..f0296f4 100644
96497 --- a/lib/list_debug.c
96498 +++ b/lib/list_debug.c
96499 @@ -11,7 +11,9 @@
96500 #include <linux/bug.h>
96501 #include <linux/kernel.h>
96502 #include <linux/rculist.h>
96503 +#include <linux/mm.h>
96504
96505 +#ifdef CONFIG_DEBUG_LIST
96506 /*
96507 * Insert a new entry between two known consecutive entries.
96508 *
96509 @@ -19,21 +21,40 @@
96510 * the prev/next entries already!
96511 */
96512
96513 +static bool __list_add_debug(struct list_head *new,
96514 + struct list_head *prev,
96515 + struct list_head *next)
96516 +{
96517 + if (unlikely(next->prev != prev)) {
96518 + printk(KERN_ERR "list_add corruption. next->prev should be "
96519 + "prev (%p), but was %p. (next=%p).\n",
96520 + prev, next->prev, next);
96521 + BUG();
96522 + return false;
96523 + }
96524 + if (unlikely(prev->next != next)) {
96525 + printk(KERN_ERR "list_add corruption. prev->next should be "
96526 + "next (%p), but was %p. (prev=%p).\n",
96527 + next, prev->next, prev);
96528 + BUG();
96529 + return false;
96530 + }
96531 + if (unlikely(new == prev || new == next)) {
96532 + printk(KERN_ERR "list_add double add: new=%p, prev=%p, next=%p.\n",
96533 + new, prev, next);
96534 + BUG();
96535 + return false;
96536 + }
96537 + return true;
96538 +}
96539 +
96540 void __list_add(struct list_head *new,
96541 - struct list_head *prev,
96542 - struct list_head *next)
96543 + struct list_head *prev,
96544 + struct list_head *next)
96545 {
96546 - WARN(next->prev != prev,
96547 - "list_add corruption. next->prev should be "
96548 - "prev (%p), but was %p. (next=%p).\n",
96549 - prev, next->prev, next);
96550 - WARN(prev->next != next,
96551 - "list_add corruption. prev->next should be "
96552 - "next (%p), but was %p. (prev=%p).\n",
96553 - next, prev->next, prev);
96554 - WARN(new == prev || new == next,
96555 - "list_add double add: new=%p, prev=%p, next=%p.\n",
96556 - new, prev, next);
96557 + if (!__list_add_debug(new, prev, next))
96558 + return;
96559 +
96560 next->prev = new;
96561 new->next = next;
96562 new->prev = prev;
96563 @@ -41,28 +62,46 @@ void __list_add(struct list_head *new,
96564 }
96565 EXPORT_SYMBOL(__list_add);
96566
96567 -void __list_del_entry(struct list_head *entry)
96568 +static bool __list_del_entry_debug(struct list_head *entry)
96569 {
96570 struct list_head *prev, *next;
96571
96572 prev = entry->prev;
96573 next = entry->next;
96574
96575 - if (WARN(next == LIST_POISON1,
96576 - "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
96577 - entry, LIST_POISON1) ||
96578 - WARN(prev == LIST_POISON2,
96579 - "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
96580 - entry, LIST_POISON2) ||
96581 - WARN(prev->next != entry,
96582 - "list_del corruption. prev->next should be %p, "
96583 - "but was %p\n", entry, prev->next) ||
96584 - WARN(next->prev != entry,
96585 - "list_del corruption. next->prev should be %p, "
96586 - "but was %p\n", entry, next->prev))
96587 + if (unlikely(next == LIST_POISON1)) {
96588 + printk(KERN_ERR "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
96589 + entry, LIST_POISON1);
96590 + BUG();
96591 + return false;
96592 + }
96593 + if (unlikely(prev == LIST_POISON2)) {
96594 + printk(KERN_ERR "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
96595 + entry, LIST_POISON2);
96596 + BUG();
96597 + return false;
96598 + }
96599 + if (unlikely(entry->prev->next != entry)) {
96600 + printk(KERN_ERR "list_del corruption. prev->next should be %p, "
96601 + "but was %p\n", entry, prev->next);
96602 + BUG();
96603 + return false;
96604 + }
96605 + if (unlikely(entry->next->prev != entry)) {
96606 + printk(KERN_ERR "list_del corruption. next->prev should be %p, "
96607 + "but was %p\n", entry, next->prev);
96608 + BUG();
96609 + return false;
96610 + }
96611 + return true;
96612 +}
96613 +
96614 +void __list_del_entry(struct list_head *entry)
96615 +{
96616 + if (!__list_del_entry_debug(entry))
96617 return;
96618
96619 - __list_del(prev, next);
96620 + __list_del(entry->prev, entry->next);
96621 }
96622 EXPORT_SYMBOL(__list_del_entry);
96623
96624 @@ -86,15 +125,85 @@ EXPORT_SYMBOL(list_del);
96625 void __list_add_rcu(struct list_head *new,
96626 struct list_head *prev, struct list_head *next)
96627 {
96628 - WARN(next->prev != prev,
96629 - "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
96630 - prev, next->prev, next);
96631 - WARN(prev->next != next,
96632 - "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
96633 - next, prev->next, prev);
96634 + if (!__list_add_debug(new, prev, next))
96635 + return;
96636 +
96637 new->next = next;
96638 new->prev = prev;
96639 rcu_assign_pointer(list_next_rcu(prev), new);
96640 next->prev = new;
96641 }
96642 EXPORT_SYMBOL(__list_add_rcu);
96643 +#endif
96644 +
96645 +void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
96646 +{
96647 +#ifdef CONFIG_DEBUG_LIST
96648 + if (!__list_add_debug(new, prev, next))
96649 + return;
96650 +#endif
96651 +
96652 + pax_open_kernel();
96653 + next->prev = new;
96654 + new->next = next;
96655 + new->prev = prev;
96656 + prev->next = new;
96657 + pax_close_kernel();
96658 +}
96659 +EXPORT_SYMBOL(__pax_list_add);
96660 +
96661 +void pax_list_del(struct list_head *entry)
96662 +{
96663 +#ifdef CONFIG_DEBUG_LIST
96664 + if (!__list_del_entry_debug(entry))
96665 + return;
96666 +#endif
96667 +
96668 + pax_open_kernel();
96669 + __list_del(entry->prev, entry->next);
96670 + entry->next = LIST_POISON1;
96671 + entry->prev = LIST_POISON2;
96672 + pax_close_kernel();
96673 +}
96674 +EXPORT_SYMBOL(pax_list_del);
96675 +
96676 +void pax_list_del_init(struct list_head *entry)
96677 +{
96678 + pax_open_kernel();
96679 + __list_del(entry->prev, entry->next);
96680 + INIT_LIST_HEAD(entry);
96681 + pax_close_kernel();
96682 +}
96683 +EXPORT_SYMBOL(pax_list_del_init);
96684 +
96685 +void __pax_list_add_rcu(struct list_head *new,
96686 + struct list_head *prev, struct list_head *next)
96687 +{
96688 +#ifdef CONFIG_DEBUG_LIST
96689 + if (!__list_add_debug(new, prev, next))
96690 + return;
96691 +#endif
96692 +
96693 + pax_open_kernel();
96694 + new->next = next;
96695 + new->prev = prev;
96696 + rcu_assign_pointer(list_next_rcu(prev), new);
96697 + next->prev = new;
96698 + pax_close_kernel();
96699 +}
96700 +EXPORT_SYMBOL(__pax_list_add_rcu);
96701 +
96702 +void pax_list_del_rcu(struct list_head *entry)
96703 +{
96704 +#ifdef CONFIG_DEBUG_LIST
96705 + if (!__list_del_entry_debug(entry))
96706 + return;
96707 +#endif
96708 +
96709 + pax_open_kernel();
96710 + __list_del(entry->prev, entry->next);
96711 + entry->next = LIST_POISON1;
96712 + entry->prev = LIST_POISON2;
96713 + pax_close_kernel();
96714 +}
96715 +EXPORT_SYMBOL(pax_list_del_rcu);
96716 diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
96717 index 963b703..438bc51 100644
96718 --- a/lib/percpu-refcount.c
96719 +++ b/lib/percpu-refcount.c
96720 @@ -29,7 +29,7 @@
96721 * can't hit 0 before we've added up all the percpu refs.
96722 */
96723
96724 -#define PCPU_COUNT_BIAS (1U << 31)
96725 +#define PCPU_COUNT_BIAS (1U << 30)
96726
96727 /**
96728 * percpu_ref_init - initialize a percpu refcount
96729 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
96730 index 3291a8e..346a91e 100644
96731 --- a/lib/radix-tree.c
96732 +++ b/lib/radix-tree.c
96733 @@ -67,7 +67,7 @@ struct radix_tree_preload {
96734 int nr;
96735 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
96736 };
96737 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
96738 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
96739
96740 static inline void *ptr_to_indirect(void *ptr)
96741 {
96742 diff --git a/lib/random32.c b/lib/random32.c
96743 index fa5da61..35fe9af 100644
96744 --- a/lib/random32.c
96745 +++ b/lib/random32.c
96746 @@ -42,7 +42,7 @@
96747 static void __init prandom_state_selftest(void);
96748 #endif
96749
96750 -static DEFINE_PER_CPU(struct rnd_state, net_rand_state);
96751 +static DEFINE_PER_CPU(struct rnd_state, net_rand_state) __latent_entropy;
96752
96753 /**
96754 * prandom_u32_state - seeded pseudo-random number generator.
96755 diff --git a/lib/rbtree.c b/lib/rbtree.c
96756 index 65f4eff..2cfa167 100644
96757 --- a/lib/rbtree.c
96758 +++ b/lib/rbtree.c
96759 @@ -380,7 +380,9 @@ static inline void dummy_copy(struct rb_node *old, struct rb_node *new) {}
96760 static inline void dummy_rotate(struct rb_node *old, struct rb_node *new) {}
96761
96762 static const struct rb_augment_callbacks dummy_callbacks = {
96763 - dummy_propagate, dummy_copy, dummy_rotate
96764 + .propagate = dummy_propagate,
96765 + .copy = dummy_copy,
96766 + .rotate = dummy_rotate
96767 };
96768
96769 void rb_insert_color(struct rb_node *node, struct rb_root *root)
96770 diff --git a/lib/show_mem.c b/lib/show_mem.c
96771 index 0922579..9d7adb9 100644
96772 --- a/lib/show_mem.c
96773 +++ b/lib/show_mem.c
96774 @@ -44,6 +44,6 @@ void show_mem(unsigned int filter)
96775 quicklist_total_size());
96776 #endif
96777 #ifdef CONFIG_MEMORY_FAILURE
96778 - printk("%lu pages hwpoisoned\n", atomic_long_read(&num_poisoned_pages));
96779 + printk("%lu pages hwpoisoned\n", atomic_long_read_unchecked(&num_poisoned_pages));
96780 #endif
96781 }
96782 diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
96783 index bb2b201..46abaf9 100644
96784 --- a/lib/strncpy_from_user.c
96785 +++ b/lib/strncpy_from_user.c
96786 @@ -21,7 +21,7 @@
96787 */
96788 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
96789 {
96790 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
96791 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
96792 long res = 0;
96793
96794 /*
96795 diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
96796 index a28df52..3d55877 100644
96797 --- a/lib/strnlen_user.c
96798 +++ b/lib/strnlen_user.c
96799 @@ -26,7 +26,7 @@
96800 */
96801 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
96802 {
96803 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
96804 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
96805 long align, res = 0;
96806 unsigned long c;
96807
96808 diff --git a/lib/swiotlb.c b/lib/swiotlb.c
96809 index 4abda07..b9d3765 100644
96810 --- a/lib/swiotlb.c
96811 +++ b/lib/swiotlb.c
96812 @@ -682,7 +682,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
96813
96814 void
96815 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
96816 - dma_addr_t dev_addr)
96817 + dma_addr_t dev_addr, struct dma_attrs *attrs)
96818 {
96819 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
96820
96821 diff --git a/lib/test_bpf.c b/lib/test_bpf.c
96822 deleted file mode 100644
96823 index c579e0f..0000000
96824 --- a/lib/test_bpf.c
96825 +++ /dev/null
96826 @@ -1,1929 +0,0 @@
96827 -/*
96828 - * Testsuite for BPF interpreter and BPF JIT compiler
96829 - *
96830 - * Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com
96831 - *
96832 - * This program is free software; you can redistribute it and/or
96833 - * modify it under the terms of version 2 of the GNU General Public
96834 - * License as published by the Free Software Foundation.
96835 - *
96836 - * This program is distributed in the hope that it will be useful, but
96837 - * WITHOUT ANY WARRANTY; without even the implied warranty of
96838 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
96839 - * General Public License for more details.
96840 - */
96841 -
96842 -#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
96843 -
96844 -#include <linux/init.h>
96845 -#include <linux/module.h>
96846 -#include <linux/filter.h>
96847 -#include <linux/skbuff.h>
96848 -#include <linux/netdevice.h>
96849 -#include <linux/if_vlan.h>
96850 -
96851 -/* General test specific settings */
96852 -#define MAX_SUBTESTS 3
96853 -#define MAX_TESTRUNS 10000
96854 -#define MAX_DATA 128
96855 -#define MAX_INSNS 512
96856 -#define MAX_K 0xffffFFFF
96857 -
96858 -/* Few constants used to init test 'skb' */
96859 -#define SKB_TYPE 3
96860 -#define SKB_MARK 0x1234aaaa
96861 -#define SKB_HASH 0x1234aaab
96862 -#define SKB_QUEUE_MAP 123
96863 -#define SKB_VLAN_TCI 0xffff
96864 -#define SKB_DEV_IFINDEX 577
96865 -#define SKB_DEV_TYPE 588
96866 -
96867 -/* Redefine REGs to make tests less verbose */
96868 -#define R0 BPF_REG_0
96869 -#define R1 BPF_REG_1
96870 -#define R2 BPF_REG_2
96871 -#define R3 BPF_REG_3
96872 -#define R4 BPF_REG_4
96873 -#define R5 BPF_REG_5
96874 -#define R6 BPF_REG_6
96875 -#define R7 BPF_REG_7
96876 -#define R8 BPF_REG_8
96877 -#define R9 BPF_REG_9
96878 -#define R10 BPF_REG_10
96879 -
96880 -/* Flags that can be passed to test cases */
96881 -#define FLAG_NO_DATA BIT(0)
96882 -#define FLAG_EXPECTED_FAIL BIT(1)
96883 -
96884 -enum {
96885 - CLASSIC = BIT(6), /* Old BPF instructions only. */
96886 - INTERNAL = BIT(7), /* Extended instruction set. */
96887 -};
96888 -
96889 -#define TEST_TYPE_MASK (CLASSIC | INTERNAL)
96890 -
96891 -struct bpf_test {
96892 - const char *descr;
96893 - union {
96894 - struct sock_filter insns[MAX_INSNS];
96895 - struct sock_filter_int insns_int[MAX_INSNS];
96896 - } u;
96897 - __u8 aux;
96898 - __u8 data[MAX_DATA];
96899 - struct {
96900 - int data_size;
96901 - __u32 result;
96902 - } test[MAX_SUBTESTS];
96903 -};
96904 -
96905 -static struct bpf_test tests[] = {
96906 - {
96907 - "TAX",
96908 - .u.insns = {
96909 - BPF_STMT(BPF_LD | BPF_IMM, 1),
96910 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
96911 - BPF_STMT(BPF_LD | BPF_IMM, 2),
96912 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
96913 - BPF_STMT(BPF_ALU | BPF_NEG, 0), /* A == -3 */
96914 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
96915 - BPF_STMT(BPF_LD | BPF_LEN, 0),
96916 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
96917 - BPF_STMT(BPF_MISC | BPF_TAX, 0), /* X == len - 3 */
96918 - BPF_STMT(BPF_LD | BPF_B | BPF_IND, 1),
96919 - BPF_STMT(BPF_RET | BPF_A, 0)
96920 - },
96921 - CLASSIC,
96922 - { 10, 20, 30, 40, 50 },
96923 - { { 2, 10 }, { 3, 20 }, { 4, 30 } },
96924 - },
96925 - {
96926 - "TXA",
96927 - .u.insns = {
96928 - BPF_STMT(BPF_LDX | BPF_LEN, 0),
96929 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
96930 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
96931 - BPF_STMT(BPF_RET | BPF_A, 0) /* A == len * 2 */
96932 - },
96933 - CLASSIC,
96934 - { 10, 20, 30, 40, 50 },
96935 - { { 1, 2 }, { 3, 6 }, { 4, 8 } },
96936 - },
96937 - {
96938 - "ADD_SUB_MUL_K",
96939 - .u.insns = {
96940 - BPF_STMT(BPF_LD | BPF_IMM, 1),
96941 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 2),
96942 - BPF_STMT(BPF_LDX | BPF_IMM, 3),
96943 - BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
96944 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 0xffffffff),
96945 - BPF_STMT(BPF_ALU | BPF_MUL | BPF_K, 3),
96946 - BPF_STMT(BPF_RET | BPF_A, 0)
96947 - },
96948 - CLASSIC | FLAG_NO_DATA,
96949 - { },
96950 - { { 0, 0xfffffffd } }
96951 - },
96952 - {
96953 - "DIV_KX",
96954 - .u.insns = {
96955 - BPF_STMT(BPF_LD | BPF_IMM, 8),
96956 - BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 2),
96957 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
96958 - BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
96959 - BPF_STMT(BPF_ALU | BPF_DIV | BPF_X, 0),
96960 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
96961 - BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
96962 - BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0x70000000),
96963 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
96964 - BPF_STMT(BPF_RET | BPF_A, 0)
96965 - },
96966 - CLASSIC | FLAG_NO_DATA,
96967 - { },
96968 - { { 0, 0x40000001 } }
96969 - },
96970 - {
96971 - "AND_OR_LSH_K",
96972 - .u.insns = {
96973 - BPF_STMT(BPF_LD | BPF_IMM, 0xff),
96974 - BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf0),
96975 - BPF_STMT(BPF_ALU | BPF_LSH | BPF_K, 27),
96976 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
96977 - BPF_STMT(BPF_LD | BPF_IMM, 0xf),
96978 - BPF_STMT(BPF_ALU | BPF_OR | BPF_K, 0xf0),
96979 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
96980 - BPF_STMT(BPF_RET | BPF_A, 0)
96981 - },
96982 - CLASSIC | FLAG_NO_DATA,
96983 - { },
96984 - { { 0, 0x800000ff }, { 1, 0x800000ff } },
96985 - },
96986 - {
96987 - "LD_IMM_0",
96988 - .u.insns = {
96989 - BPF_STMT(BPF_LD | BPF_IMM, 0), /* ld #0 */
96990 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0, 1, 0),
96991 - BPF_STMT(BPF_RET | BPF_K, 0),
96992 - BPF_STMT(BPF_RET | BPF_K, 1),
96993 - },
96994 - CLASSIC,
96995 - { },
96996 - { { 1, 1 } },
96997 - },
96998 - {
96999 - "LD_IND",
97000 - .u.insns = {
97001 - BPF_STMT(BPF_LDX | BPF_LEN, 0),
97002 - BPF_STMT(BPF_LD | BPF_H | BPF_IND, MAX_K),
97003 - BPF_STMT(BPF_RET | BPF_K, 1)
97004 - },
97005 - CLASSIC,
97006 - { },
97007 - { { 1, 0 }, { 10, 0 }, { 60, 0 } },
97008 - },
97009 - {
97010 - "LD_ABS",
97011 - .u.insns = {
97012 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 1000),
97013 - BPF_STMT(BPF_RET | BPF_K, 1)
97014 - },
97015 - CLASSIC,
97016 - { },
97017 - { { 1, 0 }, { 10, 0 }, { 60, 0 } },
97018 - },
97019 - {
97020 - "LD_ABS_LL",
97021 - .u.insns = {
97022 - BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_LL_OFF),
97023 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
97024 - BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_LL_OFF + 1),
97025 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
97026 - BPF_STMT(BPF_RET | BPF_A, 0)
97027 - },
97028 - CLASSIC,
97029 - { 1, 2, 3 },
97030 - { { 1, 0 }, { 2, 3 } },
97031 - },
97032 - {
97033 - "LD_IND_LL",
97034 - .u.insns = {
97035 - BPF_STMT(BPF_LD | BPF_IMM, SKF_LL_OFF - 1),
97036 - BPF_STMT(BPF_LDX | BPF_LEN, 0),
97037 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
97038 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
97039 - BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0),
97040 - BPF_STMT(BPF_RET | BPF_A, 0)
97041 - },
97042 - CLASSIC,
97043 - { 1, 2, 3, 0xff },
97044 - { { 1, 1 }, { 3, 3 }, { 4, 0xff } },
97045 - },
97046 - {
97047 - "LD_ABS_NET",
97048 - .u.insns = {
97049 - BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_NET_OFF),
97050 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
97051 - BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_NET_OFF + 1),
97052 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
97053 - BPF_STMT(BPF_RET | BPF_A, 0)
97054 - },
97055 - CLASSIC,
97056 - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 },
97057 - { { 15, 0 }, { 16, 3 } },
97058 - },
97059 - {
97060 - "LD_IND_NET",
97061 - .u.insns = {
97062 - BPF_STMT(BPF_LD | BPF_IMM, SKF_NET_OFF - 15),
97063 - BPF_STMT(BPF_LDX | BPF_LEN, 0),
97064 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
97065 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
97066 - BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0),
97067 - BPF_STMT(BPF_RET | BPF_A, 0)
97068 - },
97069 - CLASSIC,
97070 - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 },
97071 - { { 14, 0 }, { 15, 1 }, { 17, 3 } },
97072 - },
97073 - {
97074 - "LD_PKTTYPE",
97075 - .u.insns = {
97076 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
97077 - SKF_AD_OFF + SKF_AD_PKTTYPE),
97078 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
97079 - BPF_STMT(BPF_RET | BPF_K, 1),
97080 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
97081 - SKF_AD_OFF + SKF_AD_PKTTYPE),
97082 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
97083 - BPF_STMT(BPF_RET | BPF_K, 1),
97084 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
97085 - SKF_AD_OFF + SKF_AD_PKTTYPE),
97086 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
97087 - BPF_STMT(BPF_RET | BPF_K, 1),
97088 - BPF_STMT(BPF_RET | BPF_A, 0)
97089 - },
97090 - CLASSIC,
97091 - { },
97092 - { { 1, 3 }, { 10, 3 } },
97093 - },
97094 - {
97095 - "LD_MARK",
97096 - .u.insns = {
97097 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
97098 - SKF_AD_OFF + SKF_AD_MARK),
97099 - BPF_STMT(BPF_RET | BPF_A, 0)
97100 - },
97101 - CLASSIC,
97102 - { },
97103 - { { 1, SKB_MARK}, { 10, SKB_MARK} },
97104 - },
97105 - {
97106 - "LD_RXHASH",
97107 - .u.insns = {
97108 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
97109 - SKF_AD_OFF + SKF_AD_RXHASH),
97110 - BPF_STMT(BPF_RET | BPF_A, 0)
97111 - },
97112 - CLASSIC,
97113 - { },
97114 - { { 1, SKB_HASH}, { 10, SKB_HASH} },
97115 - },
97116 - {
97117 - "LD_QUEUE",
97118 - .u.insns = {
97119 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
97120 - SKF_AD_OFF + SKF_AD_QUEUE),
97121 - BPF_STMT(BPF_RET | BPF_A, 0)
97122 - },
97123 - CLASSIC,
97124 - { },
97125 - { { 1, SKB_QUEUE_MAP }, { 10, SKB_QUEUE_MAP } },
97126 - },
97127 - {
97128 - "LD_PROTOCOL",
97129 - .u.insns = {
97130 - BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 1),
97131 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 20, 1, 0),
97132 - BPF_STMT(BPF_RET | BPF_K, 0),
97133 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
97134 - SKF_AD_OFF + SKF_AD_PROTOCOL),
97135 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
97136 - BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
97137 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 30, 1, 0),
97138 - BPF_STMT(BPF_RET | BPF_K, 0),
97139 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
97140 - BPF_STMT(BPF_RET | BPF_A, 0)
97141 - },
97142 - CLASSIC,
97143 - { 10, 20, 30 },
97144 - { { 10, ETH_P_IP }, { 100, ETH_P_IP } },
97145 - },
97146 - {
97147 - "LD_VLAN_TAG",
97148 - .u.insns = {
97149 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
97150 - SKF_AD_OFF + SKF_AD_VLAN_TAG),
97151 - BPF_STMT(BPF_RET | BPF_A, 0)
97152 - },
97153 - CLASSIC,
97154 - { },
97155 - {
97156 - { 1, SKB_VLAN_TCI & ~VLAN_TAG_PRESENT },
97157 - { 10, SKB_VLAN_TCI & ~VLAN_TAG_PRESENT }
97158 - },
97159 - },
97160 - {
97161 - "LD_VLAN_TAG_PRESENT",
97162 - .u.insns = {
97163 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
97164 - SKF_AD_OFF + SKF_AD_VLAN_TAG_PRESENT),
97165 - BPF_STMT(BPF_RET | BPF_A, 0)
97166 - },
97167 - CLASSIC,
97168 - { },
97169 - {
97170 - { 1, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) },
97171 - { 10, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) }
97172 - },
97173 - },
97174 - {
97175 - "LD_IFINDEX",
97176 - .u.insns = {
97177 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
97178 - SKF_AD_OFF + SKF_AD_IFINDEX),
97179 - BPF_STMT(BPF_RET | BPF_A, 0)
97180 - },
97181 - CLASSIC,
97182 - { },
97183 - { { 1, SKB_DEV_IFINDEX }, { 10, SKB_DEV_IFINDEX } },
97184 - },
97185 - {
97186 - "LD_HATYPE",
97187 - .u.insns = {
97188 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
97189 - SKF_AD_OFF + SKF_AD_HATYPE),
97190 - BPF_STMT(BPF_RET | BPF_A, 0)
97191 - },
97192 - CLASSIC,
97193 - { },
97194 - { { 1, SKB_DEV_TYPE }, { 10, SKB_DEV_TYPE } },
97195 - },
97196 - {
97197 - "LD_CPU",
97198 - .u.insns = {
97199 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
97200 - SKF_AD_OFF + SKF_AD_CPU),
97201 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
97202 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
97203 - SKF_AD_OFF + SKF_AD_CPU),
97204 - BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
97205 - BPF_STMT(BPF_RET | BPF_A, 0)
97206 - },
97207 - CLASSIC,
97208 - { },
97209 - { { 1, 0 }, { 10, 0 } },
97210 - },
97211 - {
97212 - "LD_NLATTR",
97213 - .u.insns = {
97214 - BPF_STMT(BPF_LDX | BPF_IMM, 2),
97215 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
97216 - BPF_STMT(BPF_LDX | BPF_IMM, 3),
97217 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
97218 - SKF_AD_OFF + SKF_AD_NLATTR),
97219 - BPF_STMT(BPF_RET | BPF_A, 0)
97220 - },
97221 - CLASSIC,
97222 -#ifdef __BIG_ENDIAN
97223 - { 0xff, 0xff, 0, 4, 0, 2, 0, 4, 0, 3 },
97224 -#else
97225 - { 0xff, 0xff, 4, 0, 2, 0, 4, 0, 3, 0 },
97226 -#endif
97227 - { { 4, 0 }, { 20, 6 } },
97228 - },
97229 - {
97230 - "LD_NLATTR_NEST",
97231 - .u.insns = {
97232 - BPF_STMT(BPF_LD | BPF_IMM, 2),
97233 - BPF_STMT(BPF_LDX | BPF_IMM, 3),
97234 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
97235 - SKF_AD_OFF + SKF_AD_NLATTR_NEST),
97236 - BPF_STMT(BPF_LD | BPF_IMM, 2),
97237 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
97238 - SKF_AD_OFF + SKF_AD_NLATTR_NEST),
97239 - BPF_STMT(BPF_LD | BPF_IMM, 2),
97240 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
97241 - SKF_AD_OFF + SKF_AD_NLATTR_NEST),
97242 - BPF_STMT(BPF_LD | BPF_IMM, 2),
97243 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
97244 - SKF_AD_OFF + SKF_AD_NLATTR_NEST),
97245 - BPF_STMT(BPF_LD | BPF_IMM, 2),
97246 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
97247 - SKF_AD_OFF + SKF_AD_NLATTR_NEST),
97248 - BPF_STMT(BPF_LD | BPF_IMM, 2),
97249 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
97250 - SKF_AD_OFF + SKF_AD_NLATTR_NEST),
97251 - BPF_STMT(BPF_LD | BPF_IMM, 2),
97252 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
97253 - SKF_AD_OFF + SKF_AD_NLATTR_NEST),
97254 - BPF_STMT(BPF_LD | BPF_IMM, 2),
97255 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
97256 - SKF_AD_OFF + SKF_AD_NLATTR_NEST),
97257 - BPF_STMT(BPF_RET | BPF_A, 0)
97258 - },
97259 - CLASSIC,
97260 -#ifdef __BIG_ENDIAN
97261 - { 0xff, 0xff, 0, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3 },
97262 -#else
97263 - { 0xff, 0xff, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3, 0 },
97264 -#endif
97265 - { { 4, 0 }, { 20, 10 } },
97266 - },
97267 - {
97268 - "LD_PAYLOAD_OFF",
97269 - .u.insns = {
97270 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
97271 - SKF_AD_OFF + SKF_AD_PAY_OFFSET),
97272 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
97273 - SKF_AD_OFF + SKF_AD_PAY_OFFSET),
97274 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
97275 - SKF_AD_OFF + SKF_AD_PAY_OFFSET),
97276 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
97277 - SKF_AD_OFF + SKF_AD_PAY_OFFSET),
97278 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
97279 - SKF_AD_OFF + SKF_AD_PAY_OFFSET),
97280 - BPF_STMT(BPF_RET | BPF_A, 0)
97281 - },
97282 - CLASSIC,
97283 - /* 00:00:00:00:00:00 > 00:00:00:00:00:00, ethtype IPv4 (0x0800),
97284 - * length 98: 127.0.0.1 > 127.0.0.1: ICMP echo request,
97285 - * id 9737, seq 1, length 64
97286 - */
97287 - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
97288 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
97289 - 0x08, 0x00,
97290 - 0x45, 0x00, 0x00, 0x54, 0xac, 0x8b, 0x40, 0x00, 0x40,
97291 - 0x01, 0x90, 0x1b, 0x7f, 0x00, 0x00, 0x01 },
97292 - { { 30, 0 }, { 100, 42 } },
97293 - },
97294 - {
97295 - "LD_ANC_XOR",
97296 - .u.insns = {
97297 - BPF_STMT(BPF_LD | BPF_IMM, 10),
97298 - BPF_STMT(BPF_LDX | BPF_IMM, 300),
97299 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
97300 - SKF_AD_OFF + SKF_AD_ALU_XOR_X),
97301 - BPF_STMT(BPF_RET | BPF_A, 0)
97302 - },
97303 - CLASSIC,
97304 - { },
97305 - { { 4, 10 ^ 300 }, { 20, 10 ^ 300 } },
97306 - },
97307 - {
97308 - "SPILL_FILL",
97309 - .u.insns = {
97310 - BPF_STMT(BPF_LDX | BPF_LEN, 0),
97311 - BPF_STMT(BPF_LD | BPF_IMM, 2),
97312 - BPF_STMT(BPF_ALU | BPF_RSH, 1),
97313 - BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
97314 - BPF_STMT(BPF_ST, 1), /* M1 = 1 ^ len */
97315 - BPF_STMT(BPF_ALU | BPF_XOR | BPF_K, 0x80000000),
97316 - BPF_STMT(BPF_ST, 2), /* M2 = 1 ^ len ^ 0x80000000 */
97317 - BPF_STMT(BPF_STX, 15), /* M3 = len */
97318 - BPF_STMT(BPF_LDX | BPF_MEM, 1),
97319 - BPF_STMT(BPF_LD | BPF_MEM, 2),
97320 - BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
97321 - BPF_STMT(BPF_LDX | BPF_MEM, 15),
97322 - BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
97323 - BPF_STMT(BPF_RET | BPF_A, 0)
97324 - },
97325 - CLASSIC,
97326 - { },
97327 - { { 1, 0x80000001 }, { 2, 0x80000002 }, { 60, 0x80000000 ^ 60 } }
97328 - },
97329 - {
97330 - "JEQ",
97331 - .u.insns = {
97332 - BPF_STMT(BPF_LDX | BPF_LEN, 0),
97333 - BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
97334 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, 0, 1),
97335 - BPF_STMT(BPF_RET | BPF_K, 1),
97336 - BPF_STMT(BPF_RET | BPF_K, MAX_K)
97337 - },
97338 - CLASSIC,
97339 - { 3, 3, 3, 3, 3 },
97340 - { { 1, 0 }, { 3, 1 }, { 4, MAX_K } },
97341 - },
97342 - {
97343 - "JGT",
97344 - .u.insns = {
97345 - BPF_STMT(BPF_LDX | BPF_LEN, 0),
97346 - BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
97347 - BPF_JUMP(BPF_JMP | BPF_JGT | BPF_X, 0, 0, 1),
97348 - BPF_STMT(BPF_RET | BPF_K, 1),
97349 - BPF_STMT(BPF_RET | BPF_K, MAX_K)
97350 - },
97351 - CLASSIC,
97352 - { 4, 4, 4, 3, 3 },
97353 - { { 2, 0 }, { 3, 1 }, { 4, MAX_K } },
97354 - },
97355 - {
97356 - "JGE",
97357 - .u.insns = {
97358 - BPF_STMT(BPF_LDX | BPF_LEN, 0),
97359 - BPF_STMT(BPF_LD | BPF_B | BPF_IND, MAX_K),
97360 - BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 1, 1, 0),
97361 - BPF_STMT(BPF_RET | BPF_K, 10),
97362 - BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 2, 1, 0),
97363 - BPF_STMT(BPF_RET | BPF_K, 20),
97364 - BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 3, 1, 0),
97365 - BPF_STMT(BPF_RET | BPF_K, 30),
97366 - BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 4, 1, 0),
97367 - BPF_STMT(BPF_RET | BPF_K, 40),
97368 - BPF_STMT(BPF_RET | BPF_K, MAX_K)
97369 - },
97370 - CLASSIC,
97371 - { 1, 2, 3, 4, 5 },
97372 - { { 1, 20 }, { 3, 40 }, { 5, MAX_K } },
97373 - },
97374 - {
97375 - "JSET",
97376 - .u.insns = {
97377 - BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
97378 - BPF_JUMP(BPF_JMP | BPF_JA, 1, 1, 1),
97379 - BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
97380 - BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
97381 - BPF_STMT(BPF_LDX | BPF_LEN, 0),
97382 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
97383 - BPF_STMT(BPF_ALU | BPF_SUB | BPF_K, 4),
97384 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
97385 - BPF_STMT(BPF_LD | BPF_W | BPF_IND, 0),
97386 - BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 1, 0, 1),
97387 - BPF_STMT(BPF_RET | BPF_K, 10),
97388 - BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x80000000, 0, 1),
97389 - BPF_STMT(BPF_RET | BPF_K, 20),
97390 - BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
97391 - BPF_STMT(BPF_RET | BPF_K, 30),
97392 - BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
97393 - BPF_STMT(BPF_RET | BPF_K, 30),
97394 - BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
97395 - BPF_STMT(BPF_RET | BPF_K, 30),
97396 - BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
97397 - BPF_STMT(BPF_RET | BPF_K, 30),
97398 - BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
97399 - BPF_STMT(BPF_RET | BPF_K, 30),
97400 - BPF_STMT(BPF_RET | BPF_K, MAX_K)
97401 - },
97402 - CLASSIC,
97403 - { 0, 0xAA, 0x55, 1 },
97404 - { { 4, 10 }, { 5, 20 }, { 6, MAX_K } },
97405 - },
97406 - {
97407 - "tcpdump port 22",
97408 - .u.insns = {
97409 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 12),
97410 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x86dd, 0, 8), /* IPv6 */
97411 - BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 20),
97412 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x84, 2, 0),
97413 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 1, 0),
97414 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x11, 0, 17),
97415 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 54),
97416 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 14, 0),
97417 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 56),
97418 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 12, 13),
97419 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x0800, 0, 12), /* IPv4 */
97420 - BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 23),
97421 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x84, 2, 0),
97422 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 1, 0),
97423 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x11, 0, 8),
97424 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 20),
97425 - BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x1fff, 6, 0),
97426 - BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
97427 - BPF_STMT(BPF_LD | BPF_H | BPF_IND, 14),
97428 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 2, 0),
97429 - BPF_STMT(BPF_LD | BPF_H | BPF_IND, 16),
97430 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 0, 1),
97431 - BPF_STMT(BPF_RET | BPF_K, 0xffff),
97432 - BPF_STMT(BPF_RET | BPF_K, 0),
97433 - },
97434 - CLASSIC,
97435 - /* 3c:07:54:43:e5:76 > 10:bf:48:d6:43:d6, ethertype IPv4(0x0800)
97436 - * length 114: 10.1.1.149.49700 > 10.1.2.10.22: Flags [P.],
97437 - * seq 1305692979:1305693027, ack 3650467037, win 65535,
97438 - * options [nop,nop,TS val 2502645400 ecr 3971138], length 48
97439 - */
97440 - { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6,
97441 - 0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76,
97442 - 0x08, 0x00,
97443 - 0x45, 0x10, 0x00, 0x64, 0x75, 0xb5,
97444 - 0x40, 0x00, 0x40, 0x06, 0xad, 0x2e, /* IP header */
97445 - 0x0a, 0x01, 0x01, 0x95, /* ip src */
97446 - 0x0a, 0x01, 0x02, 0x0a, /* ip dst */
97447 - 0xc2, 0x24,
97448 - 0x00, 0x16 /* dst port */ },
97449 - { { 10, 0 }, { 30, 0 }, { 100, 65535 } },
97450 - },
97451 - {
97452 - "tcpdump complex",
97453 - .u.insns = {
97454 - /* tcpdump -nei eth0 'tcp port 22 and (((ip[2:2] -
97455 - * ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0) and
97456 - * (len > 115 or len < 30000000000)' -d
97457 - */
97458 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 12),
97459 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x86dd, 30, 0),
97460 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x800, 0, 29),
97461 - BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 23),
97462 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 0, 27),
97463 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 20),
97464 - BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x1fff, 25, 0),
97465 - BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
97466 - BPF_STMT(BPF_LD | BPF_H | BPF_IND, 14),
97467 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 2, 0),
97468 - BPF_STMT(BPF_LD | BPF_H | BPF_IND, 16),
97469 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 0, 20),
97470 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 16),
97471 - BPF_STMT(BPF_ST, 1),
97472 - BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 14),
97473 - BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf),
97474 - BPF_STMT(BPF_ALU | BPF_LSH | BPF_K, 2),
97475 - BPF_STMT(BPF_MISC | BPF_TAX, 0x5), /* libpcap emits K on TAX */
97476 - BPF_STMT(BPF_LD | BPF_MEM, 1),
97477 - BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
97478 - BPF_STMT(BPF_ST, 5),
97479 - BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
97480 - BPF_STMT(BPF_LD | BPF_B | BPF_IND, 26),
97481 - BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf0),
97482 - BPF_STMT(BPF_ALU | BPF_RSH | BPF_K, 2),
97483 - BPF_STMT(BPF_MISC | BPF_TAX, 0x9), /* libpcap emits K on TAX */
97484 - BPF_STMT(BPF_LD | BPF_MEM, 5),
97485 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, 4, 0),
97486 - BPF_STMT(BPF_LD | BPF_LEN, 0),
97487 - BPF_JUMP(BPF_JMP | BPF_JGT | BPF_K, 0x73, 1, 0),
97488 - BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 0xfc23ac00, 1, 0),
97489 - BPF_STMT(BPF_RET | BPF_K, 0xffff),
97490 - BPF_STMT(BPF_RET | BPF_K, 0),
97491 - },
97492 - CLASSIC,
97493 - { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6,
97494 - 0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76,
97495 - 0x08, 0x00,
97496 - 0x45, 0x10, 0x00, 0x64, 0x75, 0xb5,
97497 - 0x40, 0x00, 0x40, 0x06, 0xad, 0x2e, /* IP header */
97498 - 0x0a, 0x01, 0x01, 0x95, /* ip src */
97499 - 0x0a, 0x01, 0x02, 0x0a, /* ip dst */
97500 - 0xc2, 0x24,
97501 - 0x00, 0x16 /* dst port */ },
97502 - { { 10, 0 }, { 30, 0 }, { 100, 65535 } },
97503 - },
97504 - {
97505 - "RET_A",
97506 - .u.insns = {
97507 - /* check that unitialized X and A contain zeros */
97508 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
97509 - BPF_STMT(BPF_RET | BPF_A, 0)
97510 - },
97511 - CLASSIC,
97512 - { },
97513 - { {1, 0}, {2, 0} },
97514 - },
97515 - {
97516 - "INT: ADD trivial",
97517 - .u.insns_int = {
97518 - BPF_ALU64_IMM(BPF_MOV, R1, 1),
97519 - BPF_ALU64_IMM(BPF_ADD, R1, 2),
97520 - BPF_ALU64_IMM(BPF_MOV, R2, 3),
97521 - BPF_ALU64_REG(BPF_SUB, R1, R2),
97522 - BPF_ALU64_IMM(BPF_ADD, R1, -1),
97523 - BPF_ALU64_IMM(BPF_MUL, R1, 3),
97524 - BPF_ALU64_REG(BPF_MOV, R0, R1),
97525 - BPF_EXIT_INSN(),
97526 - },
97527 - INTERNAL,
97528 - { },
97529 - { { 0, 0xfffffffd } }
97530 - },
97531 - {
97532 - "INT: MUL_X",
97533 - .u.insns_int = {
97534 - BPF_ALU64_IMM(BPF_MOV, R0, -1),
97535 - BPF_ALU64_IMM(BPF_MOV, R1, -1),
97536 - BPF_ALU64_IMM(BPF_MOV, R2, 3),
97537 - BPF_ALU64_REG(BPF_MUL, R1, R2),
97538 - BPF_JMP_IMM(BPF_JEQ, R1, 0xfffffffd, 1),
97539 - BPF_EXIT_INSN(),
97540 - BPF_ALU64_IMM(BPF_MOV, R0, 1),
97541 - BPF_EXIT_INSN(),
97542 - },
97543 - INTERNAL,
97544 - { },
97545 - { { 0, 1 } }
97546 - },
97547 - {
97548 - "INT: MUL_X2",
97549 - .u.insns_int = {
97550 - BPF_ALU32_IMM(BPF_MOV, R0, -1),
97551 - BPF_ALU32_IMM(BPF_MOV, R1, -1),
97552 - BPF_ALU32_IMM(BPF_MOV, R2, 3),
97553 - BPF_ALU64_REG(BPF_MUL, R1, R2),
97554 - BPF_ALU64_IMM(BPF_RSH, R1, 8),
97555 - BPF_JMP_IMM(BPF_JEQ, R1, 0x2ffffff, 1),
97556 - BPF_EXIT_INSN(),
97557 - BPF_ALU32_IMM(BPF_MOV, R0, 1),
97558 - BPF_EXIT_INSN(),
97559 - },
97560 - INTERNAL,
97561 - { },
97562 - { { 0, 1 } }
97563 - },
97564 - {
97565 - "INT: MUL32_X",
97566 - .u.insns_int = {
97567 - BPF_ALU32_IMM(BPF_MOV, R0, -1),
97568 - BPF_ALU64_IMM(BPF_MOV, R1, -1),
97569 - BPF_ALU32_IMM(BPF_MOV, R2, 3),
97570 - BPF_ALU32_REG(BPF_MUL, R1, R2),
97571 - BPF_ALU64_IMM(BPF_RSH, R1, 8),
97572 - BPF_JMP_IMM(BPF_JEQ, R1, 0xffffff, 1),
97573 - BPF_EXIT_INSN(),
97574 - BPF_ALU32_IMM(BPF_MOV, R0, 1),
97575 - BPF_EXIT_INSN(),
97576 - },
97577 - INTERNAL,
97578 - { },
97579 - { { 0, 1 } }
97580 - },
97581 - {
97582 - /* Have to test all register combinations, since
97583 - * JITing of different registers will produce
97584 - * different asm code.
97585 - */
97586 - "INT: ADD 64-bit",
97587 - .u.insns_int = {
97588 - BPF_ALU64_IMM(BPF_MOV, R0, 0),
97589 - BPF_ALU64_IMM(BPF_MOV, R1, 1),
97590 - BPF_ALU64_IMM(BPF_MOV, R2, 2),
97591 - BPF_ALU64_IMM(BPF_MOV, R3, 3),
97592 - BPF_ALU64_IMM(BPF_MOV, R4, 4),
97593 - BPF_ALU64_IMM(BPF_MOV, R5, 5),
97594 - BPF_ALU64_IMM(BPF_MOV, R6, 6),
97595 - BPF_ALU64_IMM(BPF_MOV, R7, 7),
97596 - BPF_ALU64_IMM(BPF_MOV, R8, 8),
97597 - BPF_ALU64_IMM(BPF_MOV, R9, 9),
97598 - BPF_ALU64_IMM(BPF_ADD, R0, 20),
97599 - BPF_ALU64_IMM(BPF_ADD, R1, 20),
97600 - BPF_ALU64_IMM(BPF_ADD, R2, 20),
97601 - BPF_ALU64_IMM(BPF_ADD, R3, 20),
97602 - BPF_ALU64_IMM(BPF_ADD, R4, 20),
97603 - BPF_ALU64_IMM(BPF_ADD, R5, 20),
97604 - BPF_ALU64_IMM(BPF_ADD, R6, 20),
97605 - BPF_ALU64_IMM(BPF_ADD, R7, 20),
97606 - BPF_ALU64_IMM(BPF_ADD, R8, 20),
97607 - BPF_ALU64_IMM(BPF_ADD, R9, 20),
97608 - BPF_ALU64_IMM(BPF_SUB, R0, 10),
97609 - BPF_ALU64_IMM(BPF_SUB, R1, 10),
97610 - BPF_ALU64_IMM(BPF_SUB, R2, 10),
97611 - BPF_ALU64_IMM(BPF_SUB, R3, 10),
97612 - BPF_ALU64_IMM(BPF_SUB, R4, 10),
97613 - BPF_ALU64_IMM(BPF_SUB, R5, 10),
97614 - BPF_ALU64_IMM(BPF_SUB, R6, 10),
97615 - BPF_ALU64_IMM(BPF_SUB, R7, 10),
97616 - BPF_ALU64_IMM(BPF_SUB, R8, 10),
97617 - BPF_ALU64_IMM(BPF_SUB, R9, 10),
97618 - BPF_ALU64_REG(BPF_ADD, R0, R0),
97619 - BPF_ALU64_REG(BPF_ADD, R0, R1),
97620 - BPF_ALU64_REG(BPF_ADD, R0, R2),
97621 - BPF_ALU64_REG(BPF_ADD, R0, R3),
97622 - BPF_ALU64_REG(BPF_ADD, R0, R4),
97623 - BPF_ALU64_REG(BPF_ADD, R0, R5),
97624 - BPF_ALU64_REG(BPF_ADD, R0, R6),
97625 - BPF_ALU64_REG(BPF_ADD, R0, R7),
97626 - BPF_ALU64_REG(BPF_ADD, R0, R8),
97627 - BPF_ALU64_REG(BPF_ADD, R0, R9), /* R0 == 155 */
97628 - BPF_JMP_IMM(BPF_JEQ, R0, 155, 1),
97629 - BPF_EXIT_INSN(),
97630 - BPF_ALU64_REG(BPF_ADD, R1, R0),
97631 - BPF_ALU64_REG(BPF_ADD, R1, R1),
97632 - BPF_ALU64_REG(BPF_ADD, R1, R2),
97633 - BPF_ALU64_REG(BPF_ADD, R1, R3),
97634 - BPF_ALU64_REG(BPF_ADD, R1, R4),
97635 - BPF_ALU64_REG(BPF_ADD, R1, R5),
97636 - BPF_ALU64_REG(BPF_ADD, R1, R6),
97637 - BPF_ALU64_REG(BPF_ADD, R1, R7),
97638 - BPF_ALU64_REG(BPF_ADD, R1, R8),
97639 - BPF_ALU64_REG(BPF_ADD, R1, R9), /* R1 == 456 */
97640 - BPF_JMP_IMM(BPF_JEQ, R1, 456, 1),
97641 - BPF_EXIT_INSN(),
97642 - BPF_ALU64_REG(BPF_ADD, R2, R0),
97643 - BPF_ALU64_REG(BPF_ADD, R2, R1),
97644 - BPF_ALU64_REG(BPF_ADD, R2, R2),
97645 - BPF_ALU64_REG(BPF_ADD, R2, R3),
97646 - BPF_ALU64_REG(BPF_ADD, R2, R4),
97647 - BPF_ALU64_REG(BPF_ADD, R2, R5),
97648 - BPF_ALU64_REG(BPF_ADD, R2, R6),
97649 - BPF_ALU64_REG(BPF_ADD, R2, R7),
97650 - BPF_ALU64_REG(BPF_ADD, R2, R8),
97651 - BPF_ALU64_REG(BPF_ADD, R2, R9), /* R2 == 1358 */
97652 - BPF_JMP_IMM(BPF_JEQ, R2, 1358, 1),
97653 - BPF_EXIT_INSN(),
97654 - BPF_ALU64_REG(BPF_ADD, R3, R0),
97655 - BPF_ALU64_REG(BPF_ADD, R3, R1),
97656 - BPF_ALU64_REG(BPF_ADD, R3, R2),
97657 - BPF_ALU64_REG(BPF_ADD, R3, R3),
97658 - BPF_ALU64_REG(BPF_ADD, R3, R4),
97659 - BPF_ALU64_REG(BPF_ADD, R3, R5),
97660 - BPF_ALU64_REG(BPF_ADD, R3, R6),
97661 - BPF_ALU64_REG(BPF_ADD, R3, R7),
97662 - BPF_ALU64_REG(BPF_ADD, R3, R8),
97663 - BPF_ALU64_REG(BPF_ADD, R3, R9), /* R3 == 4063 */
97664 - BPF_JMP_IMM(BPF_JEQ, R3, 4063, 1),
97665 - BPF_EXIT_INSN(),
97666 - BPF_ALU64_REG(BPF_ADD, R4, R0),
97667 - BPF_ALU64_REG(BPF_ADD, R4, R1),
97668 - BPF_ALU64_REG(BPF_ADD, R4, R2),
97669 - BPF_ALU64_REG(BPF_ADD, R4, R3),
97670 - BPF_ALU64_REG(BPF_ADD, R4, R4),
97671 - BPF_ALU64_REG(BPF_ADD, R4, R5),
97672 - BPF_ALU64_REG(BPF_ADD, R4, R6),
97673 - BPF_ALU64_REG(BPF_ADD, R4, R7),
97674 - BPF_ALU64_REG(BPF_ADD, R4, R8),
97675 - BPF_ALU64_REG(BPF_ADD, R4, R9), /* R4 == 12177 */
97676 - BPF_JMP_IMM(BPF_JEQ, R4, 12177, 1),
97677 - BPF_EXIT_INSN(),
97678 - BPF_ALU64_REG(BPF_ADD, R5, R0),
97679 - BPF_ALU64_REG(BPF_ADD, R5, R1),
97680 - BPF_ALU64_REG(BPF_ADD, R5, R2),
97681 - BPF_ALU64_REG(BPF_ADD, R5, R3),
97682 - BPF_ALU64_REG(BPF_ADD, R5, R4),
97683 - BPF_ALU64_REG(BPF_ADD, R5, R5),
97684 - BPF_ALU64_REG(BPF_ADD, R5, R6),
97685 - BPF_ALU64_REG(BPF_ADD, R5, R7),
97686 - BPF_ALU64_REG(BPF_ADD, R5, R8),
97687 - BPF_ALU64_REG(BPF_ADD, R5, R9), /* R5 == 36518 */
97688 - BPF_JMP_IMM(BPF_JEQ, R5, 36518, 1),
97689 - BPF_EXIT_INSN(),
97690 - BPF_ALU64_REG(BPF_ADD, R6, R0),
97691 - BPF_ALU64_REG(BPF_ADD, R6, R1),
97692 - BPF_ALU64_REG(BPF_ADD, R6, R2),
97693 - BPF_ALU64_REG(BPF_ADD, R6, R3),
97694 - BPF_ALU64_REG(BPF_ADD, R6, R4),
97695 - BPF_ALU64_REG(BPF_ADD, R6, R5),
97696 - BPF_ALU64_REG(BPF_ADD, R6, R6),
97697 - BPF_ALU64_REG(BPF_ADD, R6, R7),
97698 - BPF_ALU64_REG(BPF_ADD, R6, R8),
97699 - BPF_ALU64_REG(BPF_ADD, R6, R9), /* R6 == 109540 */
97700 - BPF_JMP_IMM(BPF_JEQ, R6, 109540, 1),
97701 - BPF_EXIT_INSN(),
97702 - BPF_ALU64_REG(BPF_ADD, R7, R0),
97703 - BPF_ALU64_REG(BPF_ADD, R7, R1),
97704 - BPF_ALU64_REG(BPF_ADD, R7, R2),
97705 - BPF_ALU64_REG(BPF_ADD, R7, R3),
97706 - BPF_ALU64_REG(BPF_ADD, R7, R4),
97707 - BPF_ALU64_REG(BPF_ADD, R7, R5),
97708 - BPF_ALU64_REG(BPF_ADD, R7, R6),
97709 - BPF_ALU64_REG(BPF_ADD, R7, R7),
97710 - BPF_ALU64_REG(BPF_ADD, R7, R8),
97711 - BPF_ALU64_REG(BPF_ADD, R7, R9), /* R7 == 328605 */
97712 - BPF_JMP_IMM(BPF_JEQ, R7, 328605, 1),
97713 - BPF_EXIT_INSN(),
97714 - BPF_ALU64_REG(BPF_ADD, R8, R0),
97715 - BPF_ALU64_REG(BPF_ADD, R8, R1),
97716 - BPF_ALU64_REG(BPF_ADD, R8, R2),
97717 - BPF_ALU64_REG(BPF_ADD, R8, R3),
97718 - BPF_ALU64_REG(BPF_ADD, R8, R4),
97719 - BPF_ALU64_REG(BPF_ADD, R8, R5),
97720 - BPF_ALU64_REG(BPF_ADD, R8, R6),
97721 - BPF_ALU64_REG(BPF_ADD, R8, R7),
97722 - BPF_ALU64_REG(BPF_ADD, R8, R8),
97723 - BPF_ALU64_REG(BPF_ADD, R8, R9), /* R8 == 985799 */
97724 - BPF_JMP_IMM(BPF_JEQ, R8, 985799, 1),
97725 - BPF_EXIT_INSN(),
97726 - BPF_ALU64_REG(BPF_ADD, R9, R0),
97727 - BPF_ALU64_REG(BPF_ADD, R9, R1),
97728 - BPF_ALU64_REG(BPF_ADD, R9, R2),
97729 - BPF_ALU64_REG(BPF_ADD, R9, R3),
97730 - BPF_ALU64_REG(BPF_ADD, R9, R4),
97731 - BPF_ALU64_REG(BPF_ADD, R9, R5),
97732 - BPF_ALU64_REG(BPF_ADD, R9, R6),
97733 - BPF_ALU64_REG(BPF_ADD, R9, R7),
97734 - BPF_ALU64_REG(BPF_ADD, R9, R8),
97735 - BPF_ALU64_REG(BPF_ADD, R9, R9), /* R9 == 2957380 */
97736 - BPF_ALU64_REG(BPF_MOV, R0, R9),
97737 - BPF_EXIT_INSN(),
97738 - },
97739 - INTERNAL,
97740 - { },
97741 - { { 0, 2957380 } }
97742 - },
97743 - {
97744 - "INT: ADD 32-bit",
97745 - .u.insns_int = {
97746 - BPF_ALU32_IMM(BPF_MOV, R0, 20),
97747 - BPF_ALU32_IMM(BPF_MOV, R1, 1),
97748 - BPF_ALU32_IMM(BPF_MOV, R2, 2),
97749 - BPF_ALU32_IMM(BPF_MOV, R3, 3),
97750 - BPF_ALU32_IMM(BPF_MOV, R4, 4),
97751 - BPF_ALU32_IMM(BPF_MOV, R5, 5),
97752 - BPF_ALU32_IMM(BPF_MOV, R6, 6),
97753 - BPF_ALU32_IMM(BPF_MOV, R7, 7),
97754 - BPF_ALU32_IMM(BPF_MOV, R8, 8),
97755 - BPF_ALU32_IMM(BPF_MOV, R9, 9),
97756 - BPF_ALU64_IMM(BPF_ADD, R1, 10),
97757 - BPF_ALU64_IMM(BPF_ADD, R2, 10),
97758 - BPF_ALU64_IMM(BPF_ADD, R3, 10),
97759 - BPF_ALU64_IMM(BPF_ADD, R4, 10),
97760 - BPF_ALU64_IMM(BPF_ADD, R5, 10),
97761 - BPF_ALU64_IMM(BPF_ADD, R6, 10),
97762 - BPF_ALU64_IMM(BPF_ADD, R7, 10),
97763 - BPF_ALU64_IMM(BPF_ADD, R8, 10),
97764 - BPF_ALU64_IMM(BPF_ADD, R9, 10),
97765 - BPF_ALU32_REG(BPF_ADD, R0, R1),
97766 - BPF_ALU32_REG(BPF_ADD, R0, R2),
97767 - BPF_ALU32_REG(BPF_ADD, R0, R3),
97768 - BPF_ALU32_REG(BPF_ADD, R0, R4),
97769 - BPF_ALU32_REG(BPF_ADD, R0, R5),
97770 - BPF_ALU32_REG(BPF_ADD, R0, R6),
97771 - BPF_ALU32_REG(BPF_ADD, R0, R7),
97772 - BPF_ALU32_REG(BPF_ADD, R0, R8),
97773 - BPF_ALU32_REG(BPF_ADD, R0, R9), /* R0 == 155 */
97774 - BPF_JMP_IMM(BPF_JEQ, R0, 155, 1),
97775 - BPF_EXIT_INSN(),
97776 - BPF_ALU32_REG(BPF_ADD, R1, R0),
97777 - BPF_ALU32_REG(BPF_ADD, R1, R1),
97778 - BPF_ALU32_REG(BPF_ADD, R1, R2),
97779 - BPF_ALU32_REG(BPF_ADD, R1, R3),
97780 - BPF_ALU32_REG(BPF_ADD, R1, R4),
97781 - BPF_ALU32_REG(BPF_ADD, R1, R5),
97782 - BPF_ALU32_REG(BPF_ADD, R1, R6),
97783 - BPF_ALU32_REG(BPF_ADD, R1, R7),
97784 - BPF_ALU32_REG(BPF_ADD, R1, R8),
97785 - BPF_ALU32_REG(BPF_ADD, R1, R9), /* R1 == 456 */
97786 - BPF_JMP_IMM(BPF_JEQ, R1, 456, 1),
97787 - BPF_EXIT_INSN(),
97788 - BPF_ALU32_REG(BPF_ADD, R2, R0),
97789 - BPF_ALU32_REG(BPF_ADD, R2, R1),
97790 - BPF_ALU32_REG(BPF_ADD, R2, R2),
97791 - BPF_ALU32_REG(BPF_ADD, R2, R3),
97792 - BPF_ALU32_REG(BPF_ADD, R2, R4),
97793 - BPF_ALU32_REG(BPF_ADD, R2, R5),
97794 - BPF_ALU32_REG(BPF_ADD, R2, R6),
97795 - BPF_ALU32_REG(BPF_ADD, R2, R7),
97796 - BPF_ALU32_REG(BPF_ADD, R2, R8),
97797 - BPF_ALU32_REG(BPF_ADD, R2, R9), /* R2 == 1358 */
97798 - BPF_JMP_IMM(BPF_JEQ, R2, 1358, 1),
97799 - BPF_EXIT_INSN(),
97800 - BPF_ALU32_REG(BPF_ADD, R3, R0),
97801 - BPF_ALU32_REG(BPF_ADD, R3, R1),
97802 - BPF_ALU32_REG(BPF_ADD, R3, R2),
97803 - BPF_ALU32_REG(BPF_ADD, R3, R3),
97804 - BPF_ALU32_REG(BPF_ADD, R3, R4),
97805 - BPF_ALU32_REG(BPF_ADD, R3, R5),
97806 - BPF_ALU32_REG(BPF_ADD, R3, R6),
97807 - BPF_ALU32_REG(BPF_ADD, R3, R7),
97808 - BPF_ALU32_REG(BPF_ADD, R3, R8),
97809 - BPF_ALU32_REG(BPF_ADD, R3, R9), /* R3 == 4063 */
97810 - BPF_JMP_IMM(BPF_JEQ, R3, 4063, 1),
97811 - BPF_EXIT_INSN(),
97812 - BPF_ALU32_REG(BPF_ADD, R4, R0),
97813 - BPF_ALU32_REG(BPF_ADD, R4, R1),
97814 - BPF_ALU32_REG(BPF_ADD, R4, R2),
97815 - BPF_ALU32_REG(BPF_ADD, R4, R3),
97816 - BPF_ALU32_REG(BPF_ADD, R4, R4),
97817 - BPF_ALU32_REG(BPF_ADD, R4, R5),
97818 - BPF_ALU32_REG(BPF_ADD, R4, R6),
97819 - BPF_ALU32_REG(BPF_ADD, R4, R7),
97820 - BPF_ALU32_REG(BPF_ADD, R4, R8),
97821 - BPF_ALU32_REG(BPF_ADD, R4, R9), /* R4 == 12177 */
97822 - BPF_JMP_IMM(BPF_JEQ, R4, 12177, 1),
97823 - BPF_EXIT_INSN(),
97824 - BPF_ALU32_REG(BPF_ADD, R5, R0),
97825 - BPF_ALU32_REG(BPF_ADD, R5, R1),
97826 - BPF_ALU32_REG(BPF_ADD, R5, R2),
97827 - BPF_ALU32_REG(BPF_ADD, R5, R3),
97828 - BPF_ALU32_REG(BPF_ADD, R5, R4),
97829 - BPF_ALU32_REG(BPF_ADD, R5, R5),
97830 - BPF_ALU32_REG(BPF_ADD, R5, R6),
97831 - BPF_ALU32_REG(BPF_ADD, R5, R7),
97832 - BPF_ALU32_REG(BPF_ADD, R5, R8),
97833 - BPF_ALU32_REG(BPF_ADD, R5, R9), /* R5 == 36518 */
97834 - BPF_JMP_IMM(BPF_JEQ, R5, 36518, 1),
97835 - BPF_EXIT_INSN(),
97836 - BPF_ALU32_REG(BPF_ADD, R6, R0),
97837 - BPF_ALU32_REG(BPF_ADD, R6, R1),
97838 - BPF_ALU32_REG(BPF_ADD, R6, R2),
97839 - BPF_ALU32_REG(BPF_ADD, R6, R3),
97840 - BPF_ALU32_REG(BPF_ADD, R6, R4),
97841 - BPF_ALU32_REG(BPF_ADD, R6, R5),
97842 - BPF_ALU32_REG(BPF_ADD, R6, R6),
97843 - BPF_ALU32_REG(BPF_ADD, R6, R7),
97844 - BPF_ALU32_REG(BPF_ADD, R6, R8),
97845 - BPF_ALU32_REG(BPF_ADD, R6, R9), /* R6 == 109540 */
97846 - BPF_JMP_IMM(BPF_JEQ, R6, 109540, 1),
97847 - BPF_EXIT_INSN(),
97848 - BPF_ALU32_REG(BPF_ADD, R7, R0),
97849 - BPF_ALU32_REG(BPF_ADD, R7, R1),
97850 - BPF_ALU32_REG(BPF_ADD, R7, R2),
97851 - BPF_ALU32_REG(BPF_ADD, R7, R3),
97852 - BPF_ALU32_REG(BPF_ADD, R7, R4),
97853 - BPF_ALU32_REG(BPF_ADD, R7, R5),
97854 - BPF_ALU32_REG(BPF_ADD, R7, R6),
97855 - BPF_ALU32_REG(BPF_ADD, R7, R7),
97856 - BPF_ALU32_REG(BPF_ADD, R7, R8),
97857 - BPF_ALU32_REG(BPF_ADD, R7, R9), /* R7 == 328605 */
97858 - BPF_JMP_IMM(BPF_JEQ, R7, 328605, 1),
97859 - BPF_EXIT_INSN(),
97860 - BPF_ALU32_REG(BPF_ADD, R8, R0),
97861 - BPF_ALU32_REG(BPF_ADD, R8, R1),
97862 - BPF_ALU32_REG(BPF_ADD, R8, R2),
97863 - BPF_ALU32_REG(BPF_ADD, R8, R3),
97864 - BPF_ALU32_REG(BPF_ADD, R8, R4),
97865 - BPF_ALU32_REG(BPF_ADD, R8, R5),
97866 - BPF_ALU32_REG(BPF_ADD, R8, R6),
97867 - BPF_ALU32_REG(BPF_ADD, R8, R7),
97868 - BPF_ALU32_REG(BPF_ADD, R8, R8),
97869 - BPF_ALU32_REG(BPF_ADD, R8, R9), /* R8 == 985799 */
97870 - BPF_JMP_IMM(BPF_JEQ, R8, 985799, 1),
97871 - BPF_EXIT_INSN(),
97872 - BPF_ALU32_REG(BPF_ADD, R9, R0),
97873 - BPF_ALU32_REG(BPF_ADD, R9, R1),
97874 - BPF_ALU32_REG(BPF_ADD, R9, R2),
97875 - BPF_ALU32_REG(BPF_ADD, R9, R3),
97876 - BPF_ALU32_REG(BPF_ADD, R9, R4),
97877 - BPF_ALU32_REG(BPF_ADD, R9, R5),
97878 - BPF_ALU32_REG(BPF_ADD, R9, R6),
97879 - BPF_ALU32_REG(BPF_ADD, R9, R7),
97880 - BPF_ALU32_REG(BPF_ADD, R9, R8),
97881 - BPF_ALU32_REG(BPF_ADD, R9, R9), /* R9 == 2957380 */
97882 - BPF_ALU32_REG(BPF_MOV, R0, R9),
97883 - BPF_EXIT_INSN(),
97884 - },
97885 - INTERNAL,
97886 - { },
97887 - { { 0, 2957380 } }
97888 - },
97889 - { /* Mainly checking JIT here. */
97890 - "INT: SUB",
97891 - .u.insns_int = {
97892 - BPF_ALU64_IMM(BPF_MOV, R0, 0),
97893 - BPF_ALU64_IMM(BPF_MOV, R1, 1),
97894 - BPF_ALU64_IMM(BPF_MOV, R2, 2),
97895 - BPF_ALU64_IMM(BPF_MOV, R3, 3),
97896 - BPF_ALU64_IMM(BPF_MOV, R4, 4),
97897 - BPF_ALU64_IMM(BPF_MOV, R5, 5),
97898 - BPF_ALU64_IMM(BPF_MOV, R6, 6),
97899 - BPF_ALU64_IMM(BPF_MOV, R7, 7),
97900 - BPF_ALU64_IMM(BPF_MOV, R8, 8),
97901 - BPF_ALU64_IMM(BPF_MOV, R9, 9),
97902 - BPF_ALU64_REG(BPF_SUB, R0, R0),
97903 - BPF_ALU64_REG(BPF_SUB, R0, R1),
97904 - BPF_ALU64_REG(BPF_SUB, R0, R2),
97905 - BPF_ALU64_REG(BPF_SUB, R0, R3),
97906 - BPF_ALU64_REG(BPF_SUB, R0, R4),
97907 - BPF_ALU64_REG(BPF_SUB, R0, R5),
97908 - BPF_ALU64_REG(BPF_SUB, R0, R6),
97909 - BPF_ALU64_REG(BPF_SUB, R0, R7),
97910 - BPF_ALU64_REG(BPF_SUB, R0, R8),
97911 - BPF_ALU64_REG(BPF_SUB, R0, R9),
97912 - BPF_ALU64_IMM(BPF_SUB, R0, 10),
97913 - BPF_JMP_IMM(BPF_JEQ, R0, -55, 1),
97914 - BPF_EXIT_INSN(),
97915 - BPF_ALU64_REG(BPF_SUB, R1, R0),
97916 - BPF_ALU64_REG(BPF_SUB, R1, R2),
97917 - BPF_ALU64_REG(BPF_SUB, R1, R3),
97918 - BPF_ALU64_REG(BPF_SUB, R1, R4),
97919 - BPF_ALU64_REG(BPF_SUB, R1, R5),
97920 - BPF_ALU64_REG(BPF_SUB, R1, R6),
97921 - BPF_ALU64_REG(BPF_SUB, R1, R7),
97922 - BPF_ALU64_REG(BPF_SUB, R1, R8),
97923 - BPF_ALU64_REG(BPF_SUB, R1, R9),
97924 - BPF_ALU64_IMM(BPF_SUB, R1, 10),
97925 - BPF_ALU64_REG(BPF_SUB, R2, R0),
97926 - BPF_ALU64_REG(BPF_SUB, R2, R1),
97927 - BPF_ALU64_REG(BPF_SUB, R2, R3),
97928 - BPF_ALU64_REG(BPF_SUB, R2, R4),
97929 - BPF_ALU64_REG(BPF_SUB, R2, R5),
97930 - BPF_ALU64_REG(BPF_SUB, R2, R6),
97931 - BPF_ALU64_REG(BPF_SUB, R2, R7),
97932 - BPF_ALU64_REG(BPF_SUB, R2, R8),
97933 - BPF_ALU64_REG(BPF_SUB, R2, R9),
97934 - BPF_ALU64_IMM(BPF_SUB, R2, 10),
97935 - BPF_ALU64_REG(BPF_SUB, R3, R0),
97936 - BPF_ALU64_REG(BPF_SUB, R3, R1),
97937 - BPF_ALU64_REG(BPF_SUB, R3, R2),
97938 - BPF_ALU64_REG(BPF_SUB, R3, R4),
97939 - BPF_ALU64_REG(BPF_SUB, R3, R5),
97940 - BPF_ALU64_REG(BPF_SUB, R3, R6),
97941 - BPF_ALU64_REG(BPF_SUB, R3, R7),
97942 - BPF_ALU64_REG(BPF_SUB, R3, R8),
97943 - BPF_ALU64_REG(BPF_SUB, R3, R9),
97944 - BPF_ALU64_IMM(BPF_SUB, R3, 10),
97945 - BPF_ALU64_REG(BPF_SUB, R4, R0),
97946 - BPF_ALU64_REG(BPF_SUB, R4, R1),
97947 - BPF_ALU64_REG(BPF_SUB, R4, R2),
97948 - BPF_ALU64_REG(BPF_SUB, R4, R3),
97949 - BPF_ALU64_REG(BPF_SUB, R4, R5),
97950 - BPF_ALU64_REG(BPF_SUB, R4, R6),
97951 - BPF_ALU64_REG(BPF_SUB, R4, R7),
97952 - BPF_ALU64_REG(BPF_SUB, R4, R8),
97953 - BPF_ALU64_REG(BPF_SUB, R4, R9),
97954 - BPF_ALU64_IMM(BPF_SUB, R4, 10),
97955 - BPF_ALU64_REG(BPF_SUB, R5, R0),
97956 - BPF_ALU64_REG(BPF_SUB, R5, R1),
97957 - BPF_ALU64_REG(BPF_SUB, R5, R2),
97958 - BPF_ALU64_REG(BPF_SUB, R5, R3),
97959 - BPF_ALU64_REG(BPF_SUB, R5, R4),
97960 - BPF_ALU64_REG(BPF_SUB, R5, R6),
97961 - BPF_ALU64_REG(BPF_SUB, R5, R7),
97962 - BPF_ALU64_REG(BPF_SUB, R5, R8),
97963 - BPF_ALU64_REG(BPF_SUB, R5, R9),
97964 - BPF_ALU64_IMM(BPF_SUB, R5, 10),
97965 - BPF_ALU64_REG(BPF_SUB, R6, R0),
97966 - BPF_ALU64_REG(BPF_SUB, R6, R1),
97967 - BPF_ALU64_REG(BPF_SUB, R6, R2),
97968 - BPF_ALU64_REG(BPF_SUB, R6, R3),
97969 - BPF_ALU64_REG(BPF_SUB, R6, R4),
97970 - BPF_ALU64_REG(BPF_SUB, R6, R5),
97971 - BPF_ALU64_REG(BPF_SUB, R6, R7),
97972 - BPF_ALU64_REG(BPF_SUB, R6, R8),
97973 - BPF_ALU64_REG(BPF_SUB, R6, R9),
97974 - BPF_ALU64_IMM(BPF_SUB, R6, 10),
97975 - BPF_ALU64_REG(BPF_SUB, R7, R0),
97976 - BPF_ALU64_REG(BPF_SUB, R7, R1),
97977 - BPF_ALU64_REG(BPF_SUB, R7, R2),
97978 - BPF_ALU64_REG(BPF_SUB, R7, R3),
97979 - BPF_ALU64_REG(BPF_SUB, R7, R4),
97980 - BPF_ALU64_REG(BPF_SUB, R7, R5),
97981 - BPF_ALU64_REG(BPF_SUB, R7, R6),
97982 - BPF_ALU64_REG(BPF_SUB, R7, R8),
97983 - BPF_ALU64_REG(BPF_SUB, R7, R9),
97984 - BPF_ALU64_IMM(BPF_SUB, R7, 10),
97985 - BPF_ALU64_REG(BPF_SUB, R8, R0),
97986 - BPF_ALU64_REG(BPF_SUB, R8, R1),
97987 - BPF_ALU64_REG(BPF_SUB, R8, R2),
97988 - BPF_ALU64_REG(BPF_SUB, R8, R3),
97989 - BPF_ALU64_REG(BPF_SUB, R8, R4),
97990 - BPF_ALU64_REG(BPF_SUB, R8, R5),
97991 - BPF_ALU64_REG(BPF_SUB, R8, R6),
97992 - BPF_ALU64_REG(BPF_SUB, R8, R7),
97993 - BPF_ALU64_REG(BPF_SUB, R8, R9),
97994 - BPF_ALU64_IMM(BPF_SUB, R8, 10),
97995 - BPF_ALU64_REG(BPF_SUB, R9, R0),
97996 - BPF_ALU64_REG(BPF_SUB, R9, R1),
97997 - BPF_ALU64_REG(BPF_SUB, R9, R2),
97998 - BPF_ALU64_REG(BPF_SUB, R9, R3),
97999 - BPF_ALU64_REG(BPF_SUB, R9, R4),
98000 - BPF_ALU64_REG(BPF_SUB, R9, R5),
98001 - BPF_ALU64_REG(BPF_SUB, R9, R6),
98002 - BPF_ALU64_REG(BPF_SUB, R9, R7),
98003 - BPF_ALU64_REG(BPF_SUB, R9, R8),
98004 - BPF_ALU64_IMM(BPF_SUB, R9, 10),
98005 - BPF_ALU64_IMM(BPF_SUB, R0, 10),
98006 - BPF_ALU64_IMM(BPF_NEG, R0, 0),
98007 - BPF_ALU64_REG(BPF_SUB, R0, R1),
98008 - BPF_ALU64_REG(BPF_SUB, R0, R2),
98009 - BPF_ALU64_REG(BPF_SUB, R0, R3),
98010 - BPF_ALU64_REG(BPF_SUB, R0, R4),
98011 - BPF_ALU64_REG(BPF_SUB, R0, R5),
98012 - BPF_ALU64_REG(BPF_SUB, R0, R6),
98013 - BPF_ALU64_REG(BPF_SUB, R0, R7),
98014 - BPF_ALU64_REG(BPF_SUB, R0, R8),
98015 - BPF_ALU64_REG(BPF_SUB, R0, R9),
98016 - BPF_EXIT_INSN(),
98017 - },
98018 - INTERNAL,
98019 - { },
98020 - { { 0, 11 } }
98021 - },
98022 - { /* Mainly checking JIT here. */
98023 - "INT: XOR",
98024 - .u.insns_int = {
98025 - BPF_ALU64_REG(BPF_SUB, R0, R0),
98026 - BPF_ALU64_REG(BPF_XOR, R1, R1),
98027 - BPF_JMP_REG(BPF_JEQ, R0, R1, 1),
98028 - BPF_EXIT_INSN(),
98029 - BPF_ALU64_IMM(BPF_MOV, R0, 10),
98030 - BPF_ALU64_IMM(BPF_MOV, R1, -1),
98031 - BPF_ALU64_REG(BPF_SUB, R1, R1),
98032 - BPF_ALU64_REG(BPF_XOR, R2, R2),
98033 - BPF_JMP_REG(BPF_JEQ, R1, R2, 1),
98034 - BPF_EXIT_INSN(),
98035 - BPF_ALU64_REG(BPF_SUB, R2, R2),
98036 - BPF_ALU64_REG(BPF_XOR, R3, R3),
98037 - BPF_ALU64_IMM(BPF_MOV, R0, 10),
98038 - BPF_ALU64_IMM(BPF_MOV, R1, -1),
98039 - BPF_JMP_REG(BPF_JEQ, R2, R3, 1),
98040 - BPF_EXIT_INSN(),
98041 - BPF_ALU64_REG(BPF_SUB, R3, R3),
98042 - BPF_ALU64_REG(BPF_XOR, R4, R4),
98043 - BPF_ALU64_IMM(BPF_MOV, R2, 1),
98044 - BPF_ALU64_IMM(BPF_MOV, R5, -1),
98045 - BPF_JMP_REG(BPF_JEQ, R3, R4, 1),
98046 - BPF_EXIT_INSN(),
98047 - BPF_ALU64_REG(BPF_SUB, R4, R4),
98048 - BPF_ALU64_REG(BPF_XOR, R5, R5),
98049 - BPF_ALU64_IMM(BPF_MOV, R3, 1),
98050 - BPF_ALU64_IMM(BPF_MOV, R7, -1),
98051 - BPF_JMP_REG(BPF_JEQ, R5, R4, 1),
98052 - BPF_EXIT_INSN(),
98053 - BPF_ALU64_IMM(BPF_MOV, R5, 1),
98054 - BPF_ALU64_REG(BPF_SUB, R5, R5),
98055 - BPF_ALU64_REG(BPF_XOR, R6, R6),
98056 - BPF_ALU64_IMM(BPF_MOV, R1, 1),
98057 - BPF_ALU64_IMM(BPF_MOV, R8, -1),
98058 - BPF_JMP_REG(BPF_JEQ, R5, R6, 1),
98059 - BPF_EXIT_INSN(),
98060 - BPF_ALU64_REG(BPF_SUB, R6, R6),
98061 - BPF_ALU64_REG(BPF_XOR, R7, R7),
98062 - BPF_JMP_REG(BPF_JEQ, R7, R6, 1),
98063 - BPF_EXIT_INSN(),
98064 - BPF_ALU64_REG(BPF_SUB, R7, R7),
98065 - BPF_ALU64_REG(BPF_XOR, R8, R8),
98066 - BPF_JMP_REG(BPF_JEQ, R7, R8, 1),
98067 - BPF_EXIT_INSN(),
98068 - BPF_ALU64_REG(BPF_SUB, R8, R8),
98069 - BPF_ALU64_REG(BPF_XOR, R9, R9),
98070 - BPF_JMP_REG(BPF_JEQ, R9, R8, 1),
98071 - BPF_EXIT_INSN(),
98072 - BPF_ALU64_REG(BPF_SUB, R9, R9),
98073 - BPF_ALU64_REG(BPF_XOR, R0, R0),
98074 - BPF_JMP_REG(BPF_JEQ, R9, R0, 1),
98075 - BPF_EXIT_INSN(),
98076 - BPF_ALU64_REG(BPF_SUB, R1, R1),
98077 - BPF_ALU64_REG(BPF_XOR, R0, R0),
98078 - BPF_JMP_REG(BPF_JEQ, R9, R0, 2),
98079 - BPF_ALU64_IMM(BPF_MOV, R0, 0),
98080 - BPF_EXIT_INSN(),
98081 - BPF_ALU64_IMM(BPF_MOV, R0, 1),
98082 - BPF_EXIT_INSN(),
98083 - },
98084 - INTERNAL,
98085 - { },
98086 - { { 0, 1 } }
98087 - },
98088 - { /* Mainly checking JIT here. */
98089 - "INT: MUL",
98090 - .u.insns_int = {
98091 - BPF_ALU64_IMM(BPF_MOV, R0, 11),
98092 - BPF_ALU64_IMM(BPF_MOV, R1, 1),
98093 - BPF_ALU64_IMM(BPF_MOV, R2, 2),
98094 - BPF_ALU64_IMM(BPF_MOV, R3, 3),
98095 - BPF_ALU64_IMM(BPF_MOV, R4, 4),
98096 - BPF_ALU64_IMM(BPF_MOV, R5, 5),
98097 - BPF_ALU64_IMM(BPF_MOV, R6, 6),
98098 - BPF_ALU64_IMM(BPF_MOV, R7, 7),
98099 - BPF_ALU64_IMM(BPF_MOV, R8, 8),
98100 - BPF_ALU64_IMM(BPF_MOV, R9, 9),
98101 - BPF_ALU64_REG(BPF_MUL, R0, R0),
98102 - BPF_ALU64_REG(BPF_MUL, R0, R1),
98103 - BPF_ALU64_REG(BPF_MUL, R0, R2),
98104 - BPF_ALU64_REG(BPF_MUL, R0, R3),
98105 - BPF_ALU64_REG(BPF_MUL, R0, R4),
98106 - BPF_ALU64_REG(BPF_MUL, R0, R5),
98107 - BPF_ALU64_REG(BPF_MUL, R0, R6),
98108 - BPF_ALU64_REG(BPF_MUL, R0, R7),
98109 - BPF_ALU64_REG(BPF_MUL, R0, R8),
98110 - BPF_ALU64_REG(BPF_MUL, R0, R9),
98111 - BPF_ALU64_IMM(BPF_MUL, R0, 10),
98112 - BPF_JMP_IMM(BPF_JEQ, R0, 439084800, 1),
98113 - BPF_EXIT_INSN(),
98114 - BPF_ALU64_REG(BPF_MUL, R1, R0),
98115 - BPF_ALU64_REG(BPF_MUL, R1, R2),
98116 - BPF_ALU64_REG(BPF_MUL, R1, R3),
98117 - BPF_ALU64_REG(BPF_MUL, R1, R4),
98118 - BPF_ALU64_REG(BPF_MUL, R1, R5),
98119 - BPF_ALU64_REG(BPF_MUL, R1, R6),
98120 - BPF_ALU64_REG(BPF_MUL, R1, R7),
98121 - BPF_ALU64_REG(BPF_MUL, R1, R8),
98122 - BPF_ALU64_REG(BPF_MUL, R1, R9),
98123 - BPF_ALU64_IMM(BPF_MUL, R1, 10),
98124 - BPF_ALU64_REG(BPF_MOV, R2, R1),
98125 - BPF_ALU64_IMM(BPF_RSH, R2, 32),
98126 - BPF_JMP_IMM(BPF_JEQ, R2, 0x5a924, 1),
98127 - BPF_EXIT_INSN(),
98128 - BPF_ALU64_IMM(BPF_LSH, R1, 32),
98129 - BPF_ALU64_IMM(BPF_ARSH, R1, 32),
98130 - BPF_JMP_IMM(BPF_JEQ, R1, 0xebb90000, 1),
98131 - BPF_EXIT_INSN(),
98132 - BPF_ALU64_REG(BPF_MUL, R2, R0),
98133 - BPF_ALU64_REG(BPF_MUL, R2, R1),
98134 - BPF_ALU64_REG(BPF_MUL, R2, R3),
98135 - BPF_ALU64_REG(BPF_MUL, R2, R4),
98136 - BPF_ALU64_REG(BPF_MUL, R2, R5),
98137 - BPF_ALU64_REG(BPF_MUL, R2, R6),
98138 - BPF_ALU64_REG(BPF_MUL, R2, R7),
98139 - BPF_ALU64_REG(BPF_MUL, R2, R8),
98140 - BPF_ALU64_REG(BPF_MUL, R2, R9),
98141 - BPF_ALU64_IMM(BPF_MUL, R2, 10),
98142 - BPF_ALU64_IMM(BPF_RSH, R2, 32),
98143 - BPF_ALU64_REG(BPF_MOV, R0, R2),
98144 - BPF_EXIT_INSN(),
98145 - },
98146 - INTERNAL,
98147 - { },
98148 - { { 0, 0x35d97ef2 } }
98149 - },
98150 - {
98151 - "INT: ALU MIX",
98152 - .u.insns_int = {
98153 - BPF_ALU64_IMM(BPF_MOV, R0, 11),
98154 - BPF_ALU64_IMM(BPF_ADD, R0, -1),
98155 - BPF_ALU64_IMM(BPF_MOV, R2, 2),
98156 - BPF_ALU64_IMM(BPF_XOR, R2, 3),
98157 - BPF_ALU64_REG(BPF_DIV, R0, R2),
98158 - BPF_JMP_IMM(BPF_JEQ, R0, 10, 1),
98159 - BPF_EXIT_INSN(),
98160 - BPF_ALU64_IMM(BPF_MOD, R0, 3),
98161 - BPF_JMP_IMM(BPF_JEQ, R0, 1, 1),
98162 - BPF_EXIT_INSN(),
98163 - BPF_ALU64_IMM(BPF_MOV, R0, -1),
98164 - BPF_EXIT_INSN(),
98165 - },
98166 - INTERNAL,
98167 - { },
98168 - { { 0, -1 } }
98169 - },
98170 - {
98171 - "INT: DIV + ABS",
98172 - .u.insns_int = {
98173 - BPF_ALU64_REG(BPF_MOV, R6, R1),
98174 - BPF_LD_ABS(BPF_B, 3),
98175 - BPF_ALU64_IMM(BPF_MOV, R2, 2),
98176 - BPF_ALU32_REG(BPF_DIV, R0, R2),
98177 - BPF_ALU64_REG(BPF_MOV, R8, R0),
98178 - BPF_LD_ABS(BPF_B, 4),
98179 - BPF_ALU64_REG(BPF_ADD, R8, R0),
98180 - BPF_LD_IND(BPF_B, R8, -70),
98181 - BPF_EXIT_INSN(),
98182 - },
98183 - INTERNAL,
98184 - { 10, 20, 30, 40, 50 },
98185 - { { 4, 0 }, { 5, 10 } }
98186 - },
98187 - {
98188 - "INT: DIV by zero",
98189 - .u.insns_int = {
98190 - BPF_ALU64_REG(BPF_MOV, R6, R1),
98191 - BPF_ALU64_IMM(BPF_MOV, R7, 0),
98192 - BPF_LD_ABS(BPF_B, 3),
98193 - BPF_ALU32_REG(BPF_DIV, R0, R7),
98194 - BPF_EXIT_INSN(),
98195 - },
98196 - INTERNAL,
98197 - { 10, 20, 30, 40, 50 },
98198 - { { 3, 0 }, { 4, 0 } }
98199 - },
98200 - {
98201 - "check: missing ret",
98202 - .u.insns = {
98203 - BPF_STMT(BPF_LD | BPF_IMM, 1),
98204 - },
98205 - CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
98206 - { },
98207 - { }
98208 - },
98209 - {
98210 - "check: div_k_0",
98211 - .u.insns = {
98212 - BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0),
98213 - BPF_STMT(BPF_RET | BPF_K, 0)
98214 - },
98215 - CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
98216 - { },
98217 - { }
98218 - },
98219 - {
98220 - "check: unknown insn",
98221 - .u.insns = {
98222 - /* seccomp insn, rejected in socket filter */
98223 - BPF_STMT(BPF_LDX | BPF_W | BPF_ABS, 0),
98224 - BPF_STMT(BPF_RET | BPF_K, 0)
98225 - },
98226 - CLASSIC | FLAG_EXPECTED_FAIL,
98227 - { },
98228 - { }
98229 - },
98230 - {
98231 - "check: out of range spill/fill",
98232 - .u.insns = {
98233 - BPF_STMT(BPF_STX, 16),
98234 - BPF_STMT(BPF_RET | BPF_K, 0)
98235 - },
98236 - CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
98237 - { },
98238 - { }
98239 - },
98240 - {
98241 - "JUMPS + HOLES",
98242 - .u.insns = {
98243 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98244 - BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 15),
98245 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98246 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98247 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98248 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98249 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98250 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98251 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98252 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98253 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98254 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98255 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98256 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98257 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98258 - BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90c2894d, 3, 4),
98259 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98260 - BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90c2894d, 1, 2),
98261 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98262 - BPF_JUMP(BPF_JMP | BPF_JGE, 0, 14, 15),
98263 - BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 14),
98264 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98265 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98266 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98267 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98268 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98269 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98270 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98271 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98272 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98273 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98274 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98275 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98276 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98277 - BPF_JUMP(BPF_JMP | BPF_JEQ, 0x2ac28349, 2, 3),
98278 - BPF_JUMP(BPF_JMP | BPF_JEQ, 0x2ac28349, 1, 2),
98279 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98280 - BPF_JUMP(BPF_JMP | BPF_JGE, 0, 14, 15),
98281 - BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 14),
98282 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98283 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98284 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98285 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98286 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98287 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98288 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98289 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98290 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98291 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98292 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98293 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98294 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98295 - BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90d2ff41, 2, 3),
98296 - BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90d2ff41, 1, 2),
98297 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
98298 - BPF_STMT(BPF_RET | BPF_A, 0),
98299 - BPF_STMT(BPF_RET | BPF_A, 0),
98300 - },
98301 - CLASSIC,
98302 - { 0x00, 0x1b, 0x21, 0x3c, 0x9d, 0xf8,
98303 - 0x90, 0xe2, 0xba, 0x0a, 0x56, 0xb4,
98304 - 0x08, 0x00,
98305 - 0x45, 0x00, 0x00, 0x28, 0x00, 0x00,
98306 - 0x20, 0x00, 0x40, 0x11, 0x00, 0x00, /* IP header */
98307 - 0xc0, 0xa8, 0x33, 0x01,
98308 - 0xc0, 0xa8, 0x33, 0x02,
98309 - 0xbb, 0xb6,
98310 - 0xa9, 0xfa,
98311 - 0x00, 0x14, 0x00, 0x00,
98312 - 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
98313 - 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
98314 - 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
98315 - 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
98316 - 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
98317 - 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
98318 - 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
98319 - 0xcc, 0xcc, 0xcc, 0xcc },
98320 - { { 88, 0x001b } }
98321 - },
98322 - {
98323 - "check: RET X",
98324 - .u.insns = {
98325 - BPF_STMT(BPF_RET | BPF_X, 0),
98326 - },
98327 - CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
98328 - { },
98329 - { },
98330 - },
98331 - {
98332 - "check: LDX + RET X",
98333 - .u.insns = {
98334 - BPF_STMT(BPF_LDX | BPF_IMM, 42),
98335 - BPF_STMT(BPF_RET | BPF_X, 0),
98336 - },
98337 - CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
98338 - { },
98339 - { },
98340 - },
98341 - { /* Mainly checking JIT here. */
98342 - "M[]: alt STX + LDX",
98343 - .u.insns = {
98344 - BPF_STMT(BPF_LDX | BPF_IMM, 100),
98345 - BPF_STMT(BPF_STX, 0),
98346 - BPF_STMT(BPF_LDX | BPF_MEM, 0),
98347 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
98348 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
98349 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
98350 - BPF_STMT(BPF_STX, 1),
98351 - BPF_STMT(BPF_LDX | BPF_MEM, 1),
98352 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
98353 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
98354 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
98355 - BPF_STMT(BPF_STX, 2),
98356 - BPF_STMT(BPF_LDX | BPF_MEM, 2),
98357 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
98358 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
98359 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
98360 - BPF_STMT(BPF_STX, 3),
98361 - BPF_STMT(BPF_LDX | BPF_MEM, 3),
98362 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
98363 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
98364 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
98365 - BPF_STMT(BPF_STX, 4),
98366 - BPF_STMT(BPF_LDX | BPF_MEM, 4),
98367 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
98368 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
98369 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
98370 - BPF_STMT(BPF_STX, 5),
98371 - BPF_STMT(BPF_LDX | BPF_MEM, 5),
98372 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
98373 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
98374 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
98375 - BPF_STMT(BPF_STX, 6),
98376 - BPF_STMT(BPF_LDX | BPF_MEM, 6),
98377 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
98378 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
98379 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
98380 - BPF_STMT(BPF_STX, 7),
98381 - BPF_STMT(BPF_LDX | BPF_MEM, 7),
98382 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
98383 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
98384 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
98385 - BPF_STMT(BPF_STX, 8),
98386 - BPF_STMT(BPF_LDX | BPF_MEM, 8),
98387 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
98388 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
98389 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
98390 - BPF_STMT(BPF_STX, 9),
98391 - BPF_STMT(BPF_LDX | BPF_MEM, 9),
98392 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
98393 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
98394 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
98395 - BPF_STMT(BPF_STX, 10),
98396 - BPF_STMT(BPF_LDX | BPF_MEM, 10),
98397 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
98398 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
98399 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
98400 - BPF_STMT(BPF_STX, 11),
98401 - BPF_STMT(BPF_LDX | BPF_MEM, 11),
98402 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
98403 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
98404 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
98405 - BPF_STMT(BPF_STX, 12),
98406 - BPF_STMT(BPF_LDX | BPF_MEM, 12),
98407 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
98408 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
98409 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
98410 - BPF_STMT(BPF_STX, 13),
98411 - BPF_STMT(BPF_LDX | BPF_MEM, 13),
98412 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
98413 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
98414 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
98415 - BPF_STMT(BPF_STX, 14),
98416 - BPF_STMT(BPF_LDX | BPF_MEM, 14),
98417 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
98418 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
98419 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
98420 - BPF_STMT(BPF_STX, 15),
98421 - BPF_STMT(BPF_LDX | BPF_MEM, 15),
98422 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
98423 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
98424 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
98425 - BPF_STMT(BPF_RET | BPF_A, 0),
98426 - },
98427 - CLASSIC | FLAG_NO_DATA,
98428 - { },
98429 - { { 0, 116 } },
98430 - },
98431 - { /* Mainly checking JIT here. */
98432 - "M[]: full STX + full LDX",
98433 - .u.insns = {
98434 - BPF_STMT(BPF_LDX | BPF_IMM, 0xbadfeedb),
98435 - BPF_STMT(BPF_STX, 0),
98436 - BPF_STMT(BPF_LDX | BPF_IMM, 0xecabedae),
98437 - BPF_STMT(BPF_STX, 1),
98438 - BPF_STMT(BPF_LDX | BPF_IMM, 0xafccfeaf),
98439 - BPF_STMT(BPF_STX, 2),
98440 - BPF_STMT(BPF_LDX | BPF_IMM, 0xbffdcedc),
98441 - BPF_STMT(BPF_STX, 3),
98442 - BPF_STMT(BPF_LDX | BPF_IMM, 0xfbbbdccb),
98443 - BPF_STMT(BPF_STX, 4),
98444 - BPF_STMT(BPF_LDX | BPF_IMM, 0xfbabcbda),
98445 - BPF_STMT(BPF_STX, 5),
98446 - BPF_STMT(BPF_LDX | BPF_IMM, 0xaedecbdb),
98447 - BPF_STMT(BPF_STX, 6),
98448 - BPF_STMT(BPF_LDX | BPF_IMM, 0xadebbade),
98449 - BPF_STMT(BPF_STX, 7),
98450 - BPF_STMT(BPF_LDX | BPF_IMM, 0xfcfcfaec),
98451 - BPF_STMT(BPF_STX, 8),
98452 - BPF_STMT(BPF_LDX | BPF_IMM, 0xbcdddbdc),
98453 - BPF_STMT(BPF_STX, 9),
98454 - BPF_STMT(BPF_LDX | BPF_IMM, 0xfeefdfac),
98455 - BPF_STMT(BPF_STX, 10),
98456 - BPF_STMT(BPF_LDX | BPF_IMM, 0xcddcdeea),
98457 - BPF_STMT(BPF_STX, 11),
98458 - BPF_STMT(BPF_LDX | BPF_IMM, 0xaccfaebb),
98459 - BPF_STMT(BPF_STX, 12),
98460 - BPF_STMT(BPF_LDX | BPF_IMM, 0xbdcccdcf),
98461 - BPF_STMT(BPF_STX, 13),
98462 - BPF_STMT(BPF_LDX | BPF_IMM, 0xaaedecde),
98463 - BPF_STMT(BPF_STX, 14),
98464 - BPF_STMT(BPF_LDX | BPF_IMM, 0xfaeacdad),
98465 - BPF_STMT(BPF_STX, 15),
98466 - BPF_STMT(BPF_LDX | BPF_MEM, 0),
98467 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
98468 - BPF_STMT(BPF_LDX | BPF_MEM, 1),
98469 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
98470 - BPF_STMT(BPF_LDX | BPF_MEM, 2),
98471 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
98472 - BPF_STMT(BPF_LDX | BPF_MEM, 3),
98473 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
98474 - BPF_STMT(BPF_LDX | BPF_MEM, 4),
98475 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
98476 - BPF_STMT(BPF_LDX | BPF_MEM, 5),
98477 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
98478 - BPF_STMT(BPF_LDX | BPF_MEM, 6),
98479 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
98480 - BPF_STMT(BPF_LDX | BPF_MEM, 7),
98481 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
98482 - BPF_STMT(BPF_LDX | BPF_MEM, 8),
98483 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
98484 - BPF_STMT(BPF_LDX | BPF_MEM, 9),
98485 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
98486 - BPF_STMT(BPF_LDX | BPF_MEM, 10),
98487 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
98488 - BPF_STMT(BPF_LDX | BPF_MEM, 11),
98489 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
98490 - BPF_STMT(BPF_LDX | BPF_MEM, 12),
98491 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
98492 - BPF_STMT(BPF_LDX | BPF_MEM, 13),
98493 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
98494 - BPF_STMT(BPF_LDX | BPF_MEM, 14),
98495 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
98496 - BPF_STMT(BPF_LDX | BPF_MEM, 15),
98497 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
98498 - BPF_STMT(BPF_RET | BPF_A, 0),
98499 - },
98500 - CLASSIC | FLAG_NO_DATA,
98501 - { },
98502 - { { 0, 0x2a5a5e5 } },
98503 - },
98504 - {
98505 - "check: SKF_AD_MAX",
98506 - .u.insns = {
98507 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
98508 - SKF_AD_OFF + SKF_AD_MAX),
98509 - BPF_STMT(BPF_RET | BPF_A, 0),
98510 - },
98511 - CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
98512 - { },
98513 - { },
98514 - },
98515 - { /* Passes checker but fails during runtime. */
98516 - "LD [SKF_AD_OFF-1]",
98517 - .u.insns = {
98518 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
98519 - SKF_AD_OFF - 1),
98520 - BPF_STMT(BPF_RET | BPF_K, 1),
98521 - },
98522 - CLASSIC,
98523 - { },
98524 - { { 1, 0 } },
98525 - },
98526 -};
98527 -
98528 -static struct net_device dev;
98529 -
98530 -static struct sk_buff *populate_skb(char *buf, int size)
98531 -{
98532 - struct sk_buff *skb;
98533 -
98534 - if (size >= MAX_DATA)
98535 - return NULL;
98536 -
98537 - skb = alloc_skb(MAX_DATA, GFP_KERNEL);
98538 - if (!skb)
98539 - return NULL;
98540 -
98541 - memcpy(__skb_put(skb, size), buf, size);
98542 -
98543 - /* Initialize a fake skb with test pattern. */
98544 - skb_reset_mac_header(skb);
98545 - skb->protocol = htons(ETH_P_IP);
98546 - skb->pkt_type = SKB_TYPE;
98547 - skb->mark = SKB_MARK;
98548 - skb->hash = SKB_HASH;
98549 - skb->queue_mapping = SKB_QUEUE_MAP;
98550 - skb->vlan_tci = SKB_VLAN_TCI;
98551 - skb->dev = &dev;
98552 - skb->dev->ifindex = SKB_DEV_IFINDEX;
98553 - skb->dev->type = SKB_DEV_TYPE;
98554 - skb_set_network_header(skb, min(size, ETH_HLEN));
98555 -
98556 - return skb;
98557 -}
98558 -
98559 -static void *generate_test_data(struct bpf_test *test, int sub)
98560 -{
98561 - if (test->aux & FLAG_NO_DATA)
98562 - return NULL;
98563 -
98564 - /* Test case expects an skb, so populate one. Various
98565 - * subtests generate skbs of different sizes based on
98566 - * the same data.
98567 - */
98568 - return populate_skb(test->data, test->test[sub].data_size);
98569 -}
98570 -
98571 -static void release_test_data(const struct bpf_test *test, void *data)
98572 -{
98573 - if (test->aux & FLAG_NO_DATA)
98574 - return;
98575 -
98576 - kfree_skb(data);
98577 -}
98578 -
98579 -static int probe_filter_length(struct sock_filter *fp)
98580 -{
98581 - int len = 0;
98582 -
98583 - for (len = MAX_INSNS - 1; len > 0; --len)
98584 - if (fp[len].code != 0 || fp[len].k != 0)
98585 - break;
98586 -
98587 - return len + 1;
98588 -}
98589 -
98590 -static struct sk_filter *generate_filter(int which, int *err)
98591 -{
98592 - struct sk_filter *fp;
98593 - struct sock_fprog_kern fprog;
98594 - unsigned int flen = probe_filter_length(tests[which].u.insns);
98595 - __u8 test_type = tests[which].aux & TEST_TYPE_MASK;
98596 -
98597 - switch (test_type) {
98598 - case CLASSIC:
98599 - fprog.filter = tests[which].u.insns;
98600 - fprog.len = flen;
98601 -
98602 - *err = sk_unattached_filter_create(&fp, &fprog);
98603 - if (tests[which].aux & FLAG_EXPECTED_FAIL) {
98604 - if (*err == -EINVAL) {
98605 - pr_cont("PASS\n");
98606 - /* Verifier rejected filter as expected. */
98607 - *err = 0;
98608 - return NULL;
98609 - } else {
98610 - pr_cont("UNEXPECTED_PASS\n");
98611 - /* Verifier didn't reject the test that's
98612 - * bad enough, just return!
98613 - */
98614 - *err = -EINVAL;
98615 - return NULL;
98616 - }
98617 - }
98618 - /* We don't expect to fail. */
98619 - if (*err) {
98620 - pr_cont("FAIL to attach err=%d len=%d\n",
98621 - *err, fprog.len);
98622 - return NULL;
98623 - }
98624 - break;
98625 -
98626 - case INTERNAL:
98627 - fp = kzalloc(sk_filter_size(flen), GFP_KERNEL);
98628 - if (fp == NULL) {
98629 - pr_cont("UNEXPECTED_FAIL no memory left\n");
98630 - *err = -ENOMEM;
98631 - return NULL;
98632 - }
98633 -
98634 - fp->len = flen;
98635 - memcpy(fp->insnsi, tests[which].u.insns_int,
98636 - fp->len * sizeof(struct sock_filter_int));
98637 -
98638 - sk_filter_select_runtime(fp);
98639 - break;
98640 - }
98641 -
98642 - *err = 0;
98643 - return fp;
98644 -}
98645 -
98646 -static void release_filter(struct sk_filter *fp, int which)
98647 -{
98648 - __u8 test_type = tests[which].aux & TEST_TYPE_MASK;
98649 -
98650 - switch (test_type) {
98651 - case CLASSIC:
98652 - sk_unattached_filter_destroy(fp);
98653 - break;
98654 - case INTERNAL:
98655 - sk_filter_free(fp);
98656 - break;
98657 - }
98658 -}
98659 -
98660 -static int __run_one(const struct sk_filter *fp, const void *data,
98661 - int runs, u64 *duration)
98662 -{
98663 - u64 start, finish;
98664 - int ret, i;
98665 -
98666 - start = ktime_to_us(ktime_get());
98667 -
98668 - for (i = 0; i < runs; i++)
98669 - ret = SK_RUN_FILTER(fp, data);
98670 -
98671 - finish = ktime_to_us(ktime_get());
98672 -
98673 - *duration = (finish - start) * 1000ULL;
98674 - do_div(*duration, runs);
98675 -
98676 - return ret;
98677 -}
98678 -
98679 -static int run_one(const struct sk_filter *fp, struct bpf_test *test)
98680 -{
98681 - int err_cnt = 0, i, runs = MAX_TESTRUNS;
98682 -
98683 - for (i = 0; i < MAX_SUBTESTS; i++) {
98684 - void *data;
98685 - u64 duration;
98686 - u32 ret;
98687 -
98688 - if (test->test[i].data_size == 0 &&
98689 - test->test[i].result == 0)
98690 - break;
98691 -
98692 - data = generate_test_data(test, i);
98693 - ret = __run_one(fp, data, runs, &duration);
98694 - release_test_data(test, data);
98695 -
98696 - if (ret == test->test[i].result) {
98697 - pr_cont("%lld ", duration);
98698 - } else {
98699 - pr_cont("ret %d != %d ", ret,
98700 - test->test[i].result);
98701 - err_cnt++;
98702 - }
98703 - }
98704 -
98705 - return err_cnt;
98706 -}
98707 -
98708 -static __init int test_bpf(void)
98709 -{
98710 - int i, err_cnt = 0, pass_cnt = 0;
98711 -
98712 - for (i = 0; i < ARRAY_SIZE(tests); i++) {
98713 - struct sk_filter *fp;
98714 - int err;
98715 -
98716 - pr_info("#%d %s ", i, tests[i].descr);
98717 -
98718 - fp = generate_filter(i, &err);
98719 - if (fp == NULL) {
98720 - if (err == 0) {
98721 - pass_cnt++;
98722 - continue;
98723 - }
98724 -
98725 - return err;
98726 - }
98727 - err = run_one(fp, &tests[i]);
98728 - release_filter(fp, i);
98729 -
98730 - if (err) {
98731 - pr_cont("FAIL (%d times)\n", err);
98732 - err_cnt++;
98733 - } else {
98734 - pr_cont("PASS\n");
98735 - pass_cnt++;
98736 - }
98737 - }
98738 -
98739 - pr_info("Summary: %d PASSED, %d FAILED\n", pass_cnt, err_cnt);
98740 - return err_cnt ? -EINVAL : 0;
98741 -}
98742 -
98743 -static int __init test_bpf_init(void)
98744 -{
98745 - return test_bpf();
98746 -}
98747 -
98748 -static void __exit test_bpf_exit(void)
98749 -{
98750 -}
98751 -
98752 -module_init(test_bpf_init);
98753 -module_exit(test_bpf_exit);
98754 -
98755 -MODULE_LICENSE("GPL");
98756 diff --git a/lib/usercopy.c b/lib/usercopy.c
98757 index 4f5b1dd..7cab418 100644
98758 --- a/lib/usercopy.c
98759 +++ b/lib/usercopy.c
98760 @@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
98761 WARN(1, "Buffer overflow detected!\n");
98762 }
98763 EXPORT_SYMBOL(copy_from_user_overflow);
98764 +
98765 +void copy_to_user_overflow(void)
98766 +{
98767 + WARN(1, "Buffer overflow detected!\n");
98768 +}
98769 +EXPORT_SYMBOL(copy_to_user_overflow);
98770 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
98771 index 6fe2c84..2fe5ec6 100644
98772 --- a/lib/vsprintf.c
98773 +++ b/lib/vsprintf.c
98774 @@ -16,6 +16,9 @@
98775 * - scnprintf and vscnprintf
98776 */
98777
98778 +#ifdef CONFIG_GRKERNSEC_HIDESYM
98779 +#define __INCLUDED_BY_HIDESYM 1
98780 +#endif
98781 #include <stdarg.h>
98782 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
98783 #include <linux/types.h>
98784 @@ -624,7 +627,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
98785 #ifdef CONFIG_KALLSYMS
98786 if (*fmt == 'B')
98787 sprint_backtrace(sym, value);
98788 - else if (*fmt != 'f' && *fmt != 's')
98789 + else if (*fmt != 'f' && *fmt != 's' && *fmt != 'X')
98790 sprint_symbol(sym, value);
98791 else
98792 sprint_symbol_no_offset(sym, value);
98793 @@ -1183,7 +1186,11 @@ char *address_val(char *buf, char *end, const void *addr,
98794 return number(buf, end, num, spec);
98795 }
98796
98797 +#ifdef CONFIG_GRKERNSEC_HIDESYM
98798 +int kptr_restrict __read_mostly = 2;
98799 +#else
98800 int kptr_restrict __read_mostly;
98801 +#endif
98802
98803 /*
98804 * Show a '%p' thing. A kernel extension is that the '%p' is followed
98805 @@ -1194,8 +1201,10 @@ int kptr_restrict __read_mostly;
98806 *
98807 * - 'F' For symbolic function descriptor pointers with offset
98808 * - 'f' For simple symbolic function names without offset
98809 + * - 'X' For simple symbolic function names without offset approved for use with GRKERNSEC_HIDESYM
98810 * - 'S' For symbolic direct pointers with offset
98811 * - 's' For symbolic direct pointers without offset
98812 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
98813 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
98814 * - 'B' For backtraced symbolic direct pointers with offset
98815 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
98816 @@ -1263,12 +1272,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
98817
98818 if (!ptr && *fmt != 'K') {
98819 /*
98820 - * Print (null) with the same width as a pointer so it makes
98821 + * Print (nil) with the same width as a pointer so it makes
98822 * tabular output look nice.
98823 */
98824 if (spec.field_width == -1)
98825 spec.field_width = default_width;
98826 - return string(buf, end, "(null)", spec);
98827 + return string(buf, end, "(nil)", spec);
98828 }
98829
98830 switch (*fmt) {
98831 @@ -1278,6 +1287,14 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
98832 /* Fallthrough */
98833 case 'S':
98834 case 's':
98835 +#ifdef CONFIG_GRKERNSEC_HIDESYM
98836 + break;
98837 +#else
98838 + return symbol_string(buf, end, ptr, spec, fmt);
98839 +#endif
98840 + case 'X':
98841 + ptr = dereference_function_descriptor(ptr);
98842 + case 'A':
98843 case 'B':
98844 return symbol_string(buf, end, ptr, spec, fmt);
98845 case 'R':
98846 @@ -1333,6 +1350,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
98847 va_end(va);
98848 return buf;
98849 }
98850 + case 'P':
98851 + break;
98852 case 'K':
98853 /*
98854 * %pK cannot be used in IRQ context because its test
98855 @@ -1390,6 +1409,22 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
98856 ((const struct file *)ptr)->f_path.dentry,
98857 spec, fmt);
98858 }
98859 +
98860 +#ifdef CONFIG_GRKERNSEC_HIDESYM
98861 + /* 'P' = approved pointers to copy to userland,
98862 + as in the /proc/kallsyms case, as we make it display nothing
98863 + for non-root users, and the real contents for root users
98864 + 'X' = approved simple symbols
98865 + Also ignore 'K' pointers, since we force their NULLing for non-root users
98866 + above
98867 + */
98868 + if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'X' && *fmt != 'K' && is_usercopy_object(buf)) {
98869 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
98870 + dump_stack();
98871 + ptr = NULL;
98872 + }
98873 +#endif
98874 +
98875 spec.flags |= SMALL;
98876 if (spec.field_width == -1) {
98877 spec.field_width = default_width;
98878 @@ -2089,11 +2124,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
98879 typeof(type) value; \
98880 if (sizeof(type) == 8) { \
98881 args = PTR_ALIGN(args, sizeof(u32)); \
98882 - *(u32 *)&value = *(u32 *)args; \
98883 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
98884 + *(u32 *)&value = *(const u32 *)args; \
98885 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
98886 } else { \
98887 args = PTR_ALIGN(args, sizeof(type)); \
98888 - value = *(typeof(type) *)args; \
98889 + value = *(const typeof(type) *)args; \
98890 } \
98891 args += sizeof(type); \
98892 value; \
98893 @@ -2156,7 +2191,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
98894 case FORMAT_TYPE_STR: {
98895 const char *str_arg = args;
98896 args += strlen(str_arg) + 1;
98897 - str = string(str, end, (char *)str_arg, spec);
98898 + str = string(str, end, str_arg, spec);
98899 break;
98900 }
98901
98902 diff --git a/localversion-grsec b/localversion-grsec
98903 new file mode 100644
98904 index 0000000..7cd6065
98905 --- /dev/null
98906 +++ b/localversion-grsec
98907 @@ -0,0 +1 @@
98908 +-grsec
98909 diff --git a/mm/Kconfig b/mm/Kconfig
98910 index 3e9977a..205074f 100644
98911 --- a/mm/Kconfig
98912 +++ b/mm/Kconfig
98913 @@ -333,10 +333,11 @@ config KSM
98914 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
98915
98916 config DEFAULT_MMAP_MIN_ADDR
98917 - int "Low address space to protect from user allocation"
98918 + int "Low address space to protect from user allocation"
98919 depends on MMU
98920 - default 4096
98921 - help
98922 + default 32768 if ALPHA || ARM || PARISC || SPARC32
98923 + default 65536
98924 + help
98925 This is the portion of low virtual memory which should be protected
98926 from userspace allocation. Keeping a user from writing to low pages
98927 can help reduce the impact of kernel NULL pointer bugs.
98928 @@ -367,7 +368,7 @@ config MEMORY_FAILURE
98929
98930 config HWPOISON_INJECT
98931 tristate "HWPoison pages injector"
98932 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
98933 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
98934 select PROC_PAGE_MONITOR
98935
98936 config NOMMU_INITIAL_TRIM_EXCESS
98937 diff --git a/mm/backing-dev.c b/mm/backing-dev.c
98938 index 1706cbb..f89dbca 100644
98939 --- a/mm/backing-dev.c
98940 +++ b/mm/backing-dev.c
98941 @@ -12,7 +12,7 @@
98942 #include <linux/device.h>
98943 #include <trace/events/writeback.h>
98944
98945 -static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
98946 +static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
98947
98948 struct backing_dev_info default_backing_dev_info = {
98949 .name = "default",
98950 @@ -533,7 +533,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
98951 return err;
98952
98953 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
98954 - atomic_long_inc_return(&bdi_seq));
98955 + atomic_long_inc_return_unchecked(&bdi_seq));
98956 if (err) {
98957 bdi_destroy(bdi);
98958 return err;
98959 diff --git a/mm/filemap.c b/mm/filemap.c
98960 index 900edfa..ff056b1 100644
98961 --- a/mm/filemap.c
98962 +++ b/mm/filemap.c
98963 @@ -2074,7 +2074,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
98964 struct address_space *mapping = file->f_mapping;
98965
98966 if (!mapping->a_ops->readpage)
98967 - return -ENOEXEC;
98968 + return -ENODEV;
98969 file_accessed(file);
98970 vma->vm_ops = &generic_file_vm_ops;
98971 return 0;
98972 @@ -2252,6 +2252,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
98973 *pos = i_size_read(inode);
98974
98975 if (limit != RLIM_INFINITY) {
98976 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
98977 if (*pos >= limit) {
98978 send_sig(SIGXFSZ, current, 0);
98979 return -EFBIG;
98980 diff --git a/mm/fremap.c b/mm/fremap.c
98981 index 72b8fa3..c5b39f1 100644
98982 --- a/mm/fremap.c
98983 +++ b/mm/fremap.c
98984 @@ -180,6 +180,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
98985 retry:
98986 vma = find_vma(mm, start);
98987
98988 +#ifdef CONFIG_PAX_SEGMEXEC
98989 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
98990 + goto out;
98991 +#endif
98992 +
98993 /*
98994 * Make sure the vma is shared, that it supports prefaulting,
98995 * and that the remapped range is valid and fully within
98996 diff --git a/mm/gup.c b/mm/gup.c
98997 index cc5a9e7..d496acf 100644
98998 --- a/mm/gup.c
98999 +++ b/mm/gup.c
99000 @@ -265,11 +265,6 @@ static int faultin_page(struct task_struct *tsk, struct vm_area_struct *vma,
99001 unsigned int fault_flags = 0;
99002 int ret;
99003
99004 - /* For mlock, just skip the stack guard page. */
99005 - if ((*flags & FOLL_MLOCK) &&
99006 - (stack_guard_page_start(vma, address) ||
99007 - stack_guard_page_end(vma, address + PAGE_SIZE)))
99008 - return -ENOENT;
99009 if (*flags & FOLL_WRITE)
99010 fault_flags |= FAULT_FLAG_WRITE;
99011 if (nonblocking)
99012 @@ -424,14 +419,14 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
99013 if (!(gup_flags & FOLL_FORCE))
99014 gup_flags |= FOLL_NUMA;
99015
99016 - do {
99017 + while (nr_pages) {
99018 struct page *page;
99019 unsigned int foll_flags = gup_flags;
99020 unsigned int page_increm;
99021
99022 /* first iteration or cross vma bound */
99023 if (!vma || start >= vma->vm_end) {
99024 - vma = find_extend_vma(mm, start);
99025 + vma = find_vma(mm, start);
99026 if (!vma && in_gate_area(mm, start)) {
99027 int ret;
99028 ret = get_gate_page(mm, start & PAGE_MASK,
99029 @@ -443,7 +438,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
99030 goto next_page;
99031 }
99032
99033 - if (!vma || check_vma_flags(vma, gup_flags))
99034 + if (!vma || start < vma->vm_start || check_vma_flags(vma, gup_flags))
99035 return i ? : -EFAULT;
99036 if (is_vm_hugetlb_page(vma)) {
99037 i = follow_hugetlb_page(mm, vma, pages, vmas,
99038 @@ -498,7 +493,7 @@ next_page:
99039 i += page_increm;
99040 start += page_increm * PAGE_SIZE;
99041 nr_pages -= page_increm;
99042 - } while (nr_pages);
99043 + }
99044 return i;
99045 }
99046 EXPORT_SYMBOL(__get_user_pages);
99047 diff --git a/mm/highmem.c b/mm/highmem.c
99048 index b32b70c..e512eb0 100644
99049 --- a/mm/highmem.c
99050 +++ b/mm/highmem.c
99051 @@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
99052 * So no dangers, even with speculative execution.
99053 */
99054 page = pte_page(pkmap_page_table[i]);
99055 + pax_open_kernel();
99056 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
99057 -
99058 + pax_close_kernel();
99059 set_page_address(page, NULL);
99060 need_flush = 1;
99061 }
99062 @@ -198,9 +199,11 @@ start:
99063 }
99064 }
99065 vaddr = PKMAP_ADDR(last_pkmap_nr);
99066 +
99067 + pax_open_kernel();
99068 set_pte_at(&init_mm, vaddr,
99069 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
99070 -
99071 + pax_close_kernel();
99072 pkmap_count[last_pkmap_nr] = 1;
99073 set_page_address(page, (void *)vaddr);
99074
99075 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
99076 index 7a0a73d..d583cca 100644
99077 --- a/mm/hugetlb.c
99078 +++ b/mm/hugetlb.c
99079 @@ -2250,6 +2250,7 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
99080 struct hstate *h = &default_hstate;
99081 unsigned long tmp;
99082 int ret;
99083 + ctl_table_no_const hugetlb_table;
99084
99085 if (!hugepages_supported())
99086 return -ENOTSUPP;
99087 @@ -2259,9 +2260,10 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
99088 if (write && hstate_is_gigantic(h) && !gigantic_page_supported())
99089 return -EINVAL;
99090
99091 - table->data = &tmp;
99092 - table->maxlen = sizeof(unsigned long);
99093 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
99094 + hugetlb_table = *table;
99095 + hugetlb_table.data = &tmp;
99096 + hugetlb_table.maxlen = sizeof(unsigned long);
99097 + ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
99098 if (ret)
99099 goto out;
99100
99101 @@ -2306,6 +2308,7 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
99102 struct hstate *h = &default_hstate;
99103 unsigned long tmp;
99104 int ret;
99105 + ctl_table_no_const hugetlb_table;
99106
99107 if (!hugepages_supported())
99108 return -ENOTSUPP;
99109 @@ -2315,9 +2318,10 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
99110 if (write && hstate_is_gigantic(h))
99111 return -EINVAL;
99112
99113 - table->data = &tmp;
99114 - table->maxlen = sizeof(unsigned long);
99115 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
99116 + hugetlb_table = *table;
99117 + hugetlb_table.data = &tmp;
99118 + hugetlb_table.maxlen = sizeof(unsigned long);
99119 + ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
99120 if (ret)
99121 goto out;
99122
99123 @@ -2798,6 +2802,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
99124 return 1;
99125 }
99126
99127 +#ifdef CONFIG_PAX_SEGMEXEC
99128 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
99129 +{
99130 + struct mm_struct *mm = vma->vm_mm;
99131 + struct vm_area_struct *vma_m;
99132 + unsigned long address_m;
99133 + pte_t *ptep_m;
99134 +
99135 + vma_m = pax_find_mirror_vma(vma);
99136 + if (!vma_m)
99137 + return;
99138 +
99139 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
99140 + address_m = address + SEGMEXEC_TASK_SIZE;
99141 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
99142 + get_page(page_m);
99143 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
99144 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
99145 +}
99146 +#endif
99147 +
99148 /*
99149 * Hugetlb_cow() should be called with page lock of the original hugepage held.
99150 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
99151 @@ -2915,6 +2940,11 @@ retry_avoidcopy:
99152 make_huge_pte(vma, new_page, 1));
99153 page_remove_rmap(old_page);
99154 hugepage_add_new_anon_rmap(new_page, vma, address);
99155 +
99156 +#ifdef CONFIG_PAX_SEGMEXEC
99157 + pax_mirror_huge_pte(vma, address, new_page);
99158 +#endif
99159 +
99160 /* Make the old page be freed below */
99161 new_page = old_page;
99162 }
99163 @@ -3074,6 +3104,10 @@ retry:
99164 && (vma->vm_flags & VM_SHARED)));
99165 set_huge_pte_at(mm, address, ptep, new_pte);
99166
99167 +#ifdef CONFIG_PAX_SEGMEXEC
99168 + pax_mirror_huge_pte(vma, address, page);
99169 +#endif
99170 +
99171 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
99172 /* Optimization, do the COW without a second fault */
99173 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page, ptl);
99174 @@ -3140,6 +3174,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
99175 struct hstate *h = hstate_vma(vma);
99176 struct address_space *mapping;
99177
99178 +#ifdef CONFIG_PAX_SEGMEXEC
99179 + struct vm_area_struct *vma_m;
99180 +#endif
99181 +
99182 address &= huge_page_mask(h);
99183
99184 ptep = huge_pte_offset(mm, address);
99185 @@ -3153,6 +3191,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
99186 VM_FAULT_SET_HINDEX(hstate_index(h));
99187 }
99188
99189 +#ifdef CONFIG_PAX_SEGMEXEC
99190 + vma_m = pax_find_mirror_vma(vma);
99191 + if (vma_m) {
99192 + unsigned long address_m;
99193 +
99194 + if (vma->vm_start > vma_m->vm_start) {
99195 + address_m = address;
99196 + address -= SEGMEXEC_TASK_SIZE;
99197 + vma = vma_m;
99198 + h = hstate_vma(vma);
99199 + } else
99200 + address_m = address + SEGMEXEC_TASK_SIZE;
99201 +
99202 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
99203 + return VM_FAULT_OOM;
99204 + address_m &= HPAGE_MASK;
99205 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
99206 + }
99207 +#endif
99208 +
99209 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
99210 if (!ptep)
99211 return VM_FAULT_OOM;
99212 diff --git a/mm/internal.h b/mm/internal.h
99213 index 7f22a11f..f3c207f 100644
99214 --- a/mm/internal.h
99215 +++ b/mm/internal.h
99216 @@ -109,6 +109,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
99217 * in mm/page_alloc.c
99218 */
99219 extern void __free_pages_bootmem(struct page *page, unsigned int order);
99220 +extern void free_compound_page(struct page *page);
99221 extern void prep_compound_page(struct page *page, unsigned long order);
99222 #ifdef CONFIG_MEMORY_FAILURE
99223 extern bool is_free_buddy_page(struct page *page);
99224 @@ -351,7 +352,7 @@ extern u32 hwpoison_filter_enable;
99225
99226 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
99227 unsigned long, unsigned long,
99228 - unsigned long, unsigned long);
99229 + unsigned long, unsigned long) __intentional_overflow(-1);
99230
99231 extern void set_pageblock_order(void);
99232 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
99233 diff --git a/mm/iov_iter.c b/mm/iov_iter.c
99234 index 7b5dbd1..af0e329 100644
99235 --- a/mm/iov_iter.c
99236 +++ b/mm/iov_iter.c
99237 @@ -173,7 +173,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
99238
99239 while (bytes) {
99240 char __user *buf = iov->iov_base + base;
99241 - int copy = min(bytes, iov->iov_len - base);
99242 + size_t copy = min(bytes, iov->iov_len - base);
99243
99244 base = 0;
99245 left = __copy_from_user_inatomic(vaddr, buf, copy);
99246 @@ -201,7 +201,7 @@ static size_t copy_from_user_atomic_iovec(struct page *page,
99247
99248 kaddr = kmap_atomic(page);
99249 if (likely(i->nr_segs == 1)) {
99250 - int left;
99251 + size_t left;
99252 char __user *buf = i->iov->iov_base + i->iov_offset;
99253 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
99254 copied = bytes - left;
99255 @@ -231,7 +231,7 @@ static void advance_iovec(struct iov_iter *i, size_t bytes)
99256 * zero-length segments (without overruning the iovec).
99257 */
99258 while (bytes || unlikely(i->count && !iov->iov_len)) {
99259 - int copy;
99260 + size_t copy;
99261
99262 copy = min(bytes, iov->iov_len - base);
99263 BUG_ON(!i->count || i->count < copy);
99264 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
99265 index 3cda50c..032ba634 100644
99266 --- a/mm/kmemleak.c
99267 +++ b/mm/kmemleak.c
99268 @@ -364,7 +364,7 @@ static void print_unreferenced(struct seq_file *seq,
99269
99270 for (i = 0; i < object->trace_len; i++) {
99271 void *ptr = (void *)object->trace[i];
99272 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
99273 + seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
99274 }
99275 }
99276
99277 @@ -1905,7 +1905,7 @@ static int __init kmemleak_late_init(void)
99278 return -ENOMEM;
99279 }
99280
99281 - dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
99282 + dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
99283 &kmemleak_fops);
99284 if (!dentry)
99285 pr_warning("Failed to create the debugfs kmemleak file\n");
99286 diff --git a/mm/maccess.c b/mm/maccess.c
99287 index d53adf9..03a24bf 100644
99288 --- a/mm/maccess.c
99289 +++ b/mm/maccess.c
99290 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
99291 set_fs(KERNEL_DS);
99292 pagefault_disable();
99293 ret = __copy_from_user_inatomic(dst,
99294 - (__force const void __user *)src, size);
99295 + (const void __force_user *)src, size);
99296 pagefault_enable();
99297 set_fs(old_fs);
99298
99299 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
99300
99301 set_fs(KERNEL_DS);
99302 pagefault_disable();
99303 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
99304 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
99305 pagefault_enable();
99306 set_fs(old_fs);
99307
99308 diff --git a/mm/madvise.c b/mm/madvise.c
99309 index a402f8f..f5e5daa 100644
99310 --- a/mm/madvise.c
99311 +++ b/mm/madvise.c
99312 @@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct *vma,
99313 pgoff_t pgoff;
99314 unsigned long new_flags = vma->vm_flags;
99315
99316 +#ifdef CONFIG_PAX_SEGMEXEC
99317 + struct vm_area_struct *vma_m;
99318 +#endif
99319 +
99320 switch (behavior) {
99321 case MADV_NORMAL:
99322 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
99323 @@ -126,6 +130,13 @@ success:
99324 /*
99325 * vm_flags is protected by the mmap_sem held in write mode.
99326 */
99327 +
99328 +#ifdef CONFIG_PAX_SEGMEXEC
99329 + vma_m = pax_find_mirror_vma(vma);
99330 + if (vma_m)
99331 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
99332 +#endif
99333 +
99334 vma->vm_flags = new_flags;
99335
99336 out:
99337 @@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct *vma,
99338 struct vm_area_struct **prev,
99339 unsigned long start, unsigned long end)
99340 {
99341 +
99342 +#ifdef CONFIG_PAX_SEGMEXEC
99343 + struct vm_area_struct *vma_m;
99344 +#endif
99345 +
99346 *prev = vma;
99347 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
99348 return -EINVAL;
99349 @@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct *vma,
99350 zap_page_range(vma, start, end - start, &details);
99351 } else
99352 zap_page_range(vma, start, end - start, NULL);
99353 +
99354 +#ifdef CONFIG_PAX_SEGMEXEC
99355 + vma_m = pax_find_mirror_vma(vma);
99356 + if (vma_m) {
99357 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
99358 + struct zap_details details = {
99359 + .nonlinear_vma = vma_m,
99360 + .last_index = ULONG_MAX,
99361 + };
99362 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
99363 + } else
99364 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
99365 + }
99366 +#endif
99367 +
99368 return 0;
99369 }
99370
99371 @@ -491,6 +522,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
99372 if (end < start)
99373 return error;
99374
99375 +#ifdef CONFIG_PAX_SEGMEXEC
99376 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
99377 + if (end > SEGMEXEC_TASK_SIZE)
99378 + return error;
99379 + } else
99380 +#endif
99381 +
99382 + if (end > TASK_SIZE)
99383 + return error;
99384 +
99385 error = 0;
99386 if (end == start)
99387 return error;
99388 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
99389 index a013bc9..a897a14 100644
99390 --- a/mm/memory-failure.c
99391 +++ b/mm/memory-failure.c
99392 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
99393
99394 int sysctl_memory_failure_recovery __read_mostly = 1;
99395
99396 -atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
99397 +atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
99398
99399 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
99400
99401 @@ -198,7 +198,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
99402 pfn, t->comm, t->pid);
99403 si.si_signo = SIGBUS;
99404 si.si_errno = 0;
99405 - si.si_addr = (void *)addr;
99406 + si.si_addr = (void __user *)addr;
99407 #ifdef __ARCH_SI_TRAPNO
99408 si.si_trapno = trapno;
99409 #endif
99410 @@ -791,7 +791,7 @@ static struct page_state {
99411 unsigned long res;
99412 char *msg;
99413 int (*action)(struct page *p, unsigned long pfn);
99414 -} error_states[] = {
99415 +} __do_const error_states[] = {
99416 { reserved, reserved, "reserved kernel", me_kernel },
99417 /*
99418 * free pages are specially detected outside this table:
99419 @@ -1099,7 +1099,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
99420 nr_pages = 1 << compound_order(hpage);
99421 else /* normal page or thp */
99422 nr_pages = 1;
99423 - atomic_long_add(nr_pages, &num_poisoned_pages);
99424 + atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
99425
99426 /*
99427 * We need/can do nothing about count=0 pages.
99428 @@ -1128,7 +1128,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
99429 if (PageHWPoison(hpage)) {
99430 if ((hwpoison_filter(p) && TestClearPageHWPoison(p))
99431 || (p != hpage && TestSetPageHWPoison(hpage))) {
99432 - atomic_long_sub(nr_pages, &num_poisoned_pages);
99433 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
99434 unlock_page(hpage);
99435 return 0;
99436 }
99437 @@ -1186,14 +1186,14 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
99438 */
99439 if (!PageHWPoison(p)) {
99440 printk(KERN_ERR "MCE %#lx: just unpoisoned\n", pfn);
99441 - atomic_long_sub(nr_pages, &num_poisoned_pages);
99442 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
99443 put_page(hpage);
99444 res = 0;
99445 goto out;
99446 }
99447 if (hwpoison_filter(p)) {
99448 if (TestClearPageHWPoison(p))
99449 - atomic_long_sub(nr_pages, &num_poisoned_pages);
99450 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
99451 unlock_page(hpage);
99452 put_page(hpage);
99453 return 0;
99454 @@ -1423,7 +1423,7 @@ int unpoison_memory(unsigned long pfn)
99455 return 0;
99456 }
99457 if (TestClearPageHWPoison(p))
99458 - atomic_long_dec(&num_poisoned_pages);
99459 + atomic_long_dec_unchecked(&num_poisoned_pages);
99460 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
99461 return 0;
99462 }
99463 @@ -1437,7 +1437,7 @@ int unpoison_memory(unsigned long pfn)
99464 */
99465 if (TestClearPageHWPoison(page)) {
99466 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
99467 - atomic_long_sub(nr_pages, &num_poisoned_pages);
99468 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
99469 freeit = 1;
99470 if (PageHuge(page))
99471 clear_page_hwpoison_huge_page(page);
99472 @@ -1562,11 +1562,11 @@ static int soft_offline_huge_page(struct page *page, int flags)
99473 if (PageHuge(page)) {
99474 set_page_hwpoison_huge_page(hpage);
99475 dequeue_hwpoisoned_huge_page(hpage);
99476 - atomic_long_add(1 << compound_order(hpage),
99477 + atomic_long_add_unchecked(1 << compound_order(hpage),
99478 &num_poisoned_pages);
99479 } else {
99480 SetPageHWPoison(page);
99481 - atomic_long_inc(&num_poisoned_pages);
99482 + atomic_long_inc_unchecked(&num_poisoned_pages);
99483 }
99484 }
99485 return ret;
99486 @@ -1605,7 +1605,7 @@ static int __soft_offline_page(struct page *page, int flags)
99487 put_page(page);
99488 pr_info("soft_offline: %#lx: invalidated\n", pfn);
99489 SetPageHWPoison(page);
99490 - atomic_long_inc(&num_poisoned_pages);
99491 + atomic_long_inc_unchecked(&num_poisoned_pages);
99492 return 0;
99493 }
99494
99495 @@ -1656,7 +1656,7 @@ static int __soft_offline_page(struct page *page, int flags)
99496 if (!is_free_buddy_page(page))
99497 pr_info("soft offline: %#lx: page leaked\n",
99498 pfn);
99499 - atomic_long_inc(&num_poisoned_pages);
99500 + atomic_long_inc_unchecked(&num_poisoned_pages);
99501 }
99502 } else {
99503 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
99504 @@ -1726,11 +1726,11 @@ int soft_offline_page(struct page *page, int flags)
99505 if (PageHuge(page)) {
99506 set_page_hwpoison_huge_page(hpage);
99507 dequeue_hwpoisoned_huge_page(hpage);
99508 - atomic_long_add(1 << compound_order(hpage),
99509 + atomic_long_add_unchecked(1 << compound_order(hpage),
99510 &num_poisoned_pages);
99511 } else {
99512 SetPageHWPoison(page);
99513 - atomic_long_inc(&num_poisoned_pages);
99514 + atomic_long_inc_unchecked(&num_poisoned_pages);
99515 }
99516 }
99517 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
99518 diff --git a/mm/memory.c b/mm/memory.c
99519 index 8b44f76..babeaec 100644
99520 --- a/mm/memory.c
99521 +++ b/mm/memory.c
99522 @@ -413,6 +413,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
99523 free_pte_range(tlb, pmd, addr);
99524 } while (pmd++, addr = next, addr != end);
99525
99526 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
99527 start &= PUD_MASK;
99528 if (start < floor)
99529 return;
99530 @@ -427,6 +428,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
99531 pmd = pmd_offset(pud, start);
99532 pud_clear(pud);
99533 pmd_free_tlb(tlb, pmd, start);
99534 +#endif
99535 +
99536 }
99537
99538 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
99539 @@ -446,6 +449,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
99540 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
99541 } while (pud++, addr = next, addr != end);
99542
99543 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
99544 start &= PGDIR_MASK;
99545 if (start < floor)
99546 return;
99547 @@ -460,6 +464,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
99548 pud = pud_offset(pgd, start);
99549 pgd_clear(pgd);
99550 pud_free_tlb(tlb, pud, start);
99551 +#endif
99552 +
99553 }
99554
99555 /*
99556 @@ -751,7 +757,7 @@ struct page *vm_normal_page(struct vm_area_struct *vma, unsigned long addr,
99557 unsigned long pfn = pte_pfn(pte);
99558
99559 if (HAVE_PTE_SPECIAL) {
99560 - if (likely(!pte_special(pte) || pte_numa(pte)))
99561 + if (likely(!pte_special(pte)))
99562 goto check_pfn;
99563 if (vma->vm_flags & (VM_PFNMAP | VM_MIXEDMAP))
99564 return NULL;
99565 @@ -777,15 +783,14 @@ struct page *vm_normal_page(struct vm_area_struct *vma, unsigned long addr,
99566 }
99567 }
99568
99569 + if (is_zero_pfn(pfn))
99570 + return NULL;
99571 check_pfn:
99572 if (unlikely(pfn > highest_memmap_pfn)) {
99573 print_bad_pte(vma, addr, pte, NULL);
99574 return NULL;
99575 }
99576
99577 - if (is_zero_pfn(pfn))
99578 - return NULL;
99579 -
99580 /*
99581 * NOTE! We still have PageReserved() pages in the page tables.
99582 * eg. VDSO mappings can cause them to exist.
99583 @@ -1501,6 +1506,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
99584 page_add_file_rmap(page);
99585 set_pte_at(mm, addr, pte, mk_pte(page, prot));
99586
99587 +#ifdef CONFIG_PAX_SEGMEXEC
99588 + pax_mirror_file_pte(vma, addr, page, ptl);
99589 +#endif
99590 +
99591 retval = 0;
99592 pte_unmap_unlock(pte, ptl);
99593 return retval;
99594 @@ -1545,9 +1554,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
99595 if (!page_count(page))
99596 return -EINVAL;
99597 if (!(vma->vm_flags & VM_MIXEDMAP)) {
99598 +
99599 +#ifdef CONFIG_PAX_SEGMEXEC
99600 + struct vm_area_struct *vma_m;
99601 +#endif
99602 +
99603 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
99604 BUG_ON(vma->vm_flags & VM_PFNMAP);
99605 vma->vm_flags |= VM_MIXEDMAP;
99606 +
99607 +#ifdef CONFIG_PAX_SEGMEXEC
99608 + vma_m = pax_find_mirror_vma(vma);
99609 + if (vma_m)
99610 + vma_m->vm_flags |= VM_MIXEDMAP;
99611 +#endif
99612 +
99613 }
99614 return insert_page(vma, addr, page, vma->vm_page_prot);
99615 }
99616 @@ -1630,6 +1651,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
99617 unsigned long pfn)
99618 {
99619 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
99620 + BUG_ON(vma->vm_mirror);
99621
99622 if (addr < vma->vm_start || addr >= vma->vm_end)
99623 return -EFAULT;
99624 @@ -1877,7 +1899,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
99625
99626 BUG_ON(pud_huge(*pud));
99627
99628 - pmd = pmd_alloc(mm, pud, addr);
99629 + pmd = (mm == &init_mm) ?
99630 + pmd_alloc_kernel(mm, pud, addr) :
99631 + pmd_alloc(mm, pud, addr);
99632 if (!pmd)
99633 return -ENOMEM;
99634 do {
99635 @@ -1897,7 +1921,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
99636 unsigned long next;
99637 int err;
99638
99639 - pud = pud_alloc(mm, pgd, addr);
99640 + pud = (mm == &init_mm) ?
99641 + pud_alloc_kernel(mm, pgd, addr) :
99642 + pud_alloc(mm, pgd, addr);
99643 if (!pud)
99644 return -ENOMEM;
99645 do {
99646 @@ -2019,6 +2045,186 @@ static int do_page_mkwrite(struct vm_area_struct *vma, struct page *page,
99647 return ret;
99648 }
99649
99650 +#ifdef CONFIG_PAX_SEGMEXEC
99651 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
99652 +{
99653 + struct mm_struct *mm = vma->vm_mm;
99654 + spinlock_t *ptl;
99655 + pte_t *pte, entry;
99656 +
99657 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
99658 + entry = *pte;
99659 + if (!pte_present(entry)) {
99660 + if (!pte_none(entry)) {
99661 + BUG_ON(pte_file(entry));
99662 + free_swap_and_cache(pte_to_swp_entry(entry));
99663 + pte_clear_not_present_full(mm, address, pte, 0);
99664 + }
99665 + } else {
99666 + struct page *page;
99667 +
99668 + flush_cache_page(vma, address, pte_pfn(entry));
99669 + entry = ptep_clear_flush(vma, address, pte);
99670 + BUG_ON(pte_dirty(entry));
99671 + page = vm_normal_page(vma, address, entry);
99672 + if (page) {
99673 + update_hiwater_rss(mm);
99674 + if (PageAnon(page))
99675 + dec_mm_counter_fast(mm, MM_ANONPAGES);
99676 + else
99677 + dec_mm_counter_fast(mm, MM_FILEPAGES);
99678 + page_remove_rmap(page);
99679 + page_cache_release(page);
99680 + }
99681 + }
99682 + pte_unmap_unlock(pte, ptl);
99683 +}
99684 +
99685 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
99686 + *
99687 + * the ptl of the lower mapped page is held on entry and is not released on exit
99688 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
99689 + */
99690 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
99691 +{
99692 + struct mm_struct *mm = vma->vm_mm;
99693 + unsigned long address_m;
99694 + spinlock_t *ptl_m;
99695 + struct vm_area_struct *vma_m;
99696 + pmd_t *pmd_m;
99697 + pte_t *pte_m, entry_m;
99698 +
99699 + BUG_ON(!page_m || !PageAnon(page_m));
99700 +
99701 + vma_m = pax_find_mirror_vma(vma);
99702 + if (!vma_m)
99703 + return;
99704 +
99705 + BUG_ON(!PageLocked(page_m));
99706 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
99707 + address_m = address + SEGMEXEC_TASK_SIZE;
99708 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
99709 + pte_m = pte_offset_map(pmd_m, address_m);
99710 + ptl_m = pte_lockptr(mm, pmd_m);
99711 + if (ptl != ptl_m) {
99712 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
99713 + if (!pte_none(*pte_m))
99714 + goto out;
99715 + }
99716 +
99717 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
99718 + page_cache_get(page_m);
99719 + page_add_anon_rmap(page_m, vma_m, address_m);
99720 + inc_mm_counter_fast(mm, MM_ANONPAGES);
99721 + set_pte_at(mm, address_m, pte_m, entry_m);
99722 + update_mmu_cache(vma_m, address_m, pte_m);
99723 +out:
99724 + if (ptl != ptl_m)
99725 + spin_unlock(ptl_m);
99726 + pte_unmap(pte_m);
99727 + unlock_page(page_m);
99728 +}
99729 +
99730 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
99731 +{
99732 + struct mm_struct *mm = vma->vm_mm;
99733 + unsigned long address_m;
99734 + spinlock_t *ptl_m;
99735 + struct vm_area_struct *vma_m;
99736 + pmd_t *pmd_m;
99737 + pte_t *pte_m, entry_m;
99738 +
99739 + BUG_ON(!page_m || PageAnon(page_m));
99740 +
99741 + vma_m = pax_find_mirror_vma(vma);
99742 + if (!vma_m)
99743 + return;
99744 +
99745 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
99746 + address_m = address + SEGMEXEC_TASK_SIZE;
99747 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
99748 + pte_m = pte_offset_map(pmd_m, address_m);
99749 + ptl_m = pte_lockptr(mm, pmd_m);
99750 + if (ptl != ptl_m) {
99751 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
99752 + if (!pte_none(*pte_m))
99753 + goto out;
99754 + }
99755 +
99756 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
99757 + page_cache_get(page_m);
99758 + page_add_file_rmap(page_m);
99759 + inc_mm_counter_fast(mm, MM_FILEPAGES);
99760 + set_pte_at(mm, address_m, pte_m, entry_m);
99761 + update_mmu_cache(vma_m, address_m, pte_m);
99762 +out:
99763 + if (ptl != ptl_m)
99764 + spin_unlock(ptl_m);
99765 + pte_unmap(pte_m);
99766 +}
99767 +
99768 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
99769 +{
99770 + struct mm_struct *mm = vma->vm_mm;
99771 + unsigned long address_m;
99772 + spinlock_t *ptl_m;
99773 + struct vm_area_struct *vma_m;
99774 + pmd_t *pmd_m;
99775 + pte_t *pte_m, entry_m;
99776 +
99777 + vma_m = pax_find_mirror_vma(vma);
99778 + if (!vma_m)
99779 + return;
99780 +
99781 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
99782 + address_m = address + SEGMEXEC_TASK_SIZE;
99783 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
99784 + pte_m = pte_offset_map(pmd_m, address_m);
99785 + ptl_m = pte_lockptr(mm, pmd_m);
99786 + if (ptl != ptl_m) {
99787 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
99788 + if (!pte_none(*pte_m))
99789 + goto out;
99790 + }
99791 +
99792 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
99793 + set_pte_at(mm, address_m, pte_m, entry_m);
99794 +out:
99795 + if (ptl != ptl_m)
99796 + spin_unlock(ptl_m);
99797 + pte_unmap(pte_m);
99798 +}
99799 +
99800 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
99801 +{
99802 + struct page *page_m;
99803 + pte_t entry;
99804 +
99805 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
99806 + goto out;
99807 +
99808 + entry = *pte;
99809 + page_m = vm_normal_page(vma, address, entry);
99810 + if (!page_m)
99811 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
99812 + else if (PageAnon(page_m)) {
99813 + if (pax_find_mirror_vma(vma)) {
99814 + pte_unmap_unlock(pte, ptl);
99815 + lock_page(page_m);
99816 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
99817 + if (pte_same(entry, *pte))
99818 + pax_mirror_anon_pte(vma, address, page_m, ptl);
99819 + else
99820 + unlock_page(page_m);
99821 + }
99822 + } else
99823 + pax_mirror_file_pte(vma, address, page_m, ptl);
99824 +
99825 +out:
99826 + pte_unmap_unlock(pte, ptl);
99827 +}
99828 +#endif
99829 +
99830 /*
99831 * This routine handles present pages, when users try to write
99832 * to a shared page. It is done by copying the page to a new address
99833 @@ -2216,6 +2422,12 @@ gotten:
99834 */
99835 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
99836 if (likely(pte_same(*page_table, orig_pte))) {
99837 +
99838 +#ifdef CONFIG_PAX_SEGMEXEC
99839 + if (pax_find_mirror_vma(vma))
99840 + BUG_ON(!trylock_page(new_page));
99841 +#endif
99842 +
99843 if (old_page) {
99844 if (!PageAnon(old_page)) {
99845 dec_mm_counter_fast(mm, MM_FILEPAGES);
99846 @@ -2267,6 +2479,10 @@ gotten:
99847 page_remove_rmap(old_page);
99848 }
99849
99850 +#ifdef CONFIG_PAX_SEGMEXEC
99851 + pax_mirror_anon_pte(vma, address, new_page, ptl);
99852 +#endif
99853 +
99854 /* Free the old page.. */
99855 new_page = old_page;
99856 ret |= VM_FAULT_WRITE;
99857 @@ -2540,6 +2756,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
99858 swap_free(entry);
99859 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
99860 try_to_free_swap(page);
99861 +
99862 +#ifdef CONFIG_PAX_SEGMEXEC
99863 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
99864 +#endif
99865 +
99866 unlock_page(page);
99867 if (page != swapcache) {
99868 /*
99869 @@ -2563,6 +2784,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
99870
99871 /* No need to invalidate - it was non-present before */
99872 update_mmu_cache(vma, address, page_table);
99873 +
99874 +#ifdef CONFIG_PAX_SEGMEXEC
99875 + pax_mirror_anon_pte(vma, address, page, ptl);
99876 +#endif
99877 +
99878 unlock:
99879 pte_unmap_unlock(page_table, ptl);
99880 out:
99881 @@ -2582,40 +2808,6 @@ out_release:
99882 }
99883
99884 /*
99885 - * This is like a special single-page "expand_{down|up}wards()",
99886 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
99887 - * doesn't hit another vma.
99888 - */
99889 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
99890 -{
99891 - address &= PAGE_MASK;
99892 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
99893 - struct vm_area_struct *prev = vma->vm_prev;
99894 -
99895 - /*
99896 - * Is there a mapping abutting this one below?
99897 - *
99898 - * That's only ok if it's the same stack mapping
99899 - * that has gotten split..
99900 - */
99901 - if (prev && prev->vm_end == address)
99902 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
99903 -
99904 - expand_downwards(vma, address - PAGE_SIZE);
99905 - }
99906 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
99907 - struct vm_area_struct *next = vma->vm_next;
99908 -
99909 - /* As VM_GROWSDOWN but s/below/above/ */
99910 - if (next && next->vm_start == address + PAGE_SIZE)
99911 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
99912 -
99913 - expand_upwards(vma, address + PAGE_SIZE);
99914 - }
99915 - return 0;
99916 -}
99917 -
99918 -/*
99919 * We enter with non-exclusive mmap_sem (to exclude vma changes,
99920 * but allow concurrent faults), and pte mapped but not yet locked.
99921 * We return with mmap_sem still held, but pte unmapped and unlocked.
99922 @@ -2624,27 +2816,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
99923 unsigned long address, pte_t *page_table, pmd_t *pmd,
99924 unsigned int flags)
99925 {
99926 - struct page *page;
99927 + struct page *page = NULL;
99928 spinlock_t *ptl;
99929 pte_t entry;
99930
99931 - pte_unmap(page_table);
99932 -
99933 - /* Check if we need to add a guard page to the stack */
99934 - if (check_stack_guard_page(vma, address) < 0)
99935 - return VM_FAULT_SIGBUS;
99936 -
99937 - /* Use the zero-page for reads */
99938 if (!(flags & FAULT_FLAG_WRITE)) {
99939 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
99940 vma->vm_page_prot));
99941 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
99942 + ptl = pte_lockptr(mm, pmd);
99943 + spin_lock(ptl);
99944 if (!pte_none(*page_table))
99945 goto unlock;
99946 goto setpte;
99947 }
99948
99949 /* Allocate our own private page. */
99950 + pte_unmap(page_table);
99951 +
99952 if (unlikely(anon_vma_prepare(vma)))
99953 goto oom;
99954 page = alloc_zeroed_user_highpage_movable(vma, address);
99955 @@ -2668,6 +2856,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
99956 if (!pte_none(*page_table))
99957 goto release;
99958
99959 +#ifdef CONFIG_PAX_SEGMEXEC
99960 + if (pax_find_mirror_vma(vma))
99961 + BUG_ON(!trylock_page(page));
99962 +#endif
99963 +
99964 inc_mm_counter_fast(mm, MM_ANONPAGES);
99965 page_add_new_anon_rmap(page, vma, address);
99966 setpte:
99967 @@ -2675,6 +2868,12 @@ setpte:
99968
99969 /* No need to invalidate - it was non-present before */
99970 update_mmu_cache(vma, address, page_table);
99971 +
99972 +#ifdef CONFIG_PAX_SEGMEXEC
99973 + if (page)
99974 + pax_mirror_anon_pte(vma, address, page, ptl);
99975 +#endif
99976 +
99977 unlock:
99978 pte_unmap_unlock(page_table, ptl);
99979 return 0;
99980 @@ -2906,6 +3105,11 @@ static int do_read_fault(struct mm_struct *mm, struct vm_area_struct *vma,
99981 return ret;
99982 }
99983 do_set_pte(vma, address, fault_page, pte, false, false);
99984 +
99985 +#ifdef CONFIG_PAX_SEGMEXEC
99986 + pax_mirror_file_pte(vma, address, fault_page, ptl);
99987 +#endif
99988 +
99989 unlock_page(fault_page);
99990 unlock_out:
99991 pte_unmap_unlock(pte, ptl);
99992 @@ -2947,7 +3151,18 @@ static int do_cow_fault(struct mm_struct *mm, struct vm_area_struct *vma,
99993 page_cache_release(fault_page);
99994 goto uncharge_out;
99995 }
99996 +
99997 +#ifdef CONFIG_PAX_SEGMEXEC
99998 + if (pax_find_mirror_vma(vma))
99999 + BUG_ON(!trylock_page(new_page));
100000 +#endif
100001 +
100002 do_set_pte(vma, address, new_page, pte, true, true);
100003 +
100004 +#ifdef CONFIG_PAX_SEGMEXEC
100005 + pax_mirror_anon_pte(vma, address, new_page, ptl);
100006 +#endif
100007 +
100008 pte_unmap_unlock(pte, ptl);
100009 unlock_page(fault_page);
100010 page_cache_release(fault_page);
100011 @@ -2995,6 +3210,11 @@ static int do_shared_fault(struct mm_struct *mm, struct vm_area_struct *vma,
100012 return ret;
100013 }
100014 do_set_pte(vma, address, fault_page, pte, true, false);
100015 +
100016 +#ifdef CONFIG_PAX_SEGMEXEC
100017 + pax_mirror_file_pte(vma, address, fault_page, ptl);
100018 +#endif
100019 +
100020 pte_unmap_unlock(pte, ptl);
100021
100022 if (set_page_dirty(fault_page))
100023 @@ -3225,6 +3445,12 @@ static int handle_pte_fault(struct mm_struct *mm,
100024 if (flags & FAULT_FLAG_WRITE)
100025 flush_tlb_fix_spurious_fault(vma, address);
100026 }
100027 +
100028 +#ifdef CONFIG_PAX_SEGMEXEC
100029 + pax_mirror_pte(vma, address, pte, pmd, ptl);
100030 + return 0;
100031 +#endif
100032 +
100033 unlock:
100034 pte_unmap_unlock(pte, ptl);
100035 return 0;
100036 @@ -3241,9 +3467,41 @@ static int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
100037 pmd_t *pmd;
100038 pte_t *pte;
100039
100040 +#ifdef CONFIG_PAX_SEGMEXEC
100041 + struct vm_area_struct *vma_m;
100042 +#endif
100043 +
100044 if (unlikely(is_vm_hugetlb_page(vma)))
100045 return hugetlb_fault(mm, vma, address, flags);
100046
100047 +#ifdef CONFIG_PAX_SEGMEXEC
100048 + vma_m = pax_find_mirror_vma(vma);
100049 + if (vma_m) {
100050 + unsigned long address_m;
100051 + pgd_t *pgd_m;
100052 + pud_t *pud_m;
100053 + pmd_t *pmd_m;
100054 +
100055 + if (vma->vm_start > vma_m->vm_start) {
100056 + address_m = address;
100057 + address -= SEGMEXEC_TASK_SIZE;
100058 + vma = vma_m;
100059 + } else
100060 + address_m = address + SEGMEXEC_TASK_SIZE;
100061 +
100062 + pgd_m = pgd_offset(mm, address_m);
100063 + pud_m = pud_alloc(mm, pgd_m, address_m);
100064 + if (!pud_m)
100065 + return VM_FAULT_OOM;
100066 + pmd_m = pmd_alloc(mm, pud_m, address_m);
100067 + if (!pmd_m)
100068 + return VM_FAULT_OOM;
100069 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
100070 + return VM_FAULT_OOM;
100071 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
100072 + }
100073 +#endif
100074 +
100075 pgd = pgd_offset(mm, address);
100076 pud = pud_alloc(mm, pgd, address);
100077 if (!pud)
100078 @@ -3371,6 +3629,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
100079 spin_unlock(&mm->page_table_lock);
100080 return 0;
100081 }
100082 +
100083 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
100084 +{
100085 + pud_t *new = pud_alloc_one(mm, address);
100086 + if (!new)
100087 + return -ENOMEM;
100088 +
100089 + smp_wmb(); /* See comment in __pte_alloc */
100090 +
100091 + spin_lock(&mm->page_table_lock);
100092 + if (pgd_present(*pgd)) /* Another has populated it */
100093 + pud_free(mm, new);
100094 + else
100095 + pgd_populate_kernel(mm, pgd, new);
100096 + spin_unlock(&mm->page_table_lock);
100097 + return 0;
100098 +}
100099 #endif /* __PAGETABLE_PUD_FOLDED */
100100
100101 #ifndef __PAGETABLE_PMD_FOLDED
100102 @@ -3401,6 +3676,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
100103 spin_unlock(&mm->page_table_lock);
100104 return 0;
100105 }
100106 +
100107 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
100108 +{
100109 + pmd_t *new = pmd_alloc_one(mm, address);
100110 + if (!new)
100111 + return -ENOMEM;
100112 +
100113 + smp_wmb(); /* See comment in __pte_alloc */
100114 +
100115 + spin_lock(&mm->page_table_lock);
100116 +#ifndef __ARCH_HAS_4LEVEL_HACK
100117 + if (pud_present(*pud)) /* Another has populated it */
100118 + pmd_free(mm, new);
100119 + else
100120 + pud_populate_kernel(mm, pud, new);
100121 +#else
100122 + if (pgd_present(*pud)) /* Another has populated it */
100123 + pmd_free(mm, new);
100124 + else
100125 + pgd_populate_kernel(mm, pud, new);
100126 +#endif /* __ARCH_HAS_4LEVEL_HACK */
100127 + spin_unlock(&mm->page_table_lock);
100128 + return 0;
100129 +}
100130 #endif /* __PAGETABLE_PMD_FOLDED */
100131
100132 #if !defined(__HAVE_ARCH_GATE_AREA)
100133 @@ -3414,7 +3713,7 @@ static int __init gate_vma_init(void)
100134 gate_vma.vm_start = FIXADDR_USER_START;
100135 gate_vma.vm_end = FIXADDR_USER_END;
100136 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
100137 - gate_vma.vm_page_prot = __P101;
100138 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
100139
100140 return 0;
100141 }
100142 @@ -3548,8 +3847,8 @@ out:
100143 return ret;
100144 }
100145
100146 -int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
100147 - void *buf, int len, int write)
100148 +ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
100149 + void *buf, size_t len, int write)
100150 {
100151 resource_size_t phys_addr;
100152 unsigned long prot = 0;
100153 @@ -3575,8 +3874,8 @@ EXPORT_SYMBOL_GPL(generic_access_phys);
100154 * Access another process' address space as given in mm. If non-NULL, use the
100155 * given task for page fault accounting.
100156 */
100157 -static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
100158 - unsigned long addr, void *buf, int len, int write)
100159 +static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
100160 + unsigned long addr, void *buf, size_t len, int write)
100161 {
100162 struct vm_area_struct *vma;
100163 void *old_buf = buf;
100164 @@ -3584,7 +3883,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
100165 down_read(&mm->mmap_sem);
100166 /* ignore errors, just check how much was successfully transferred */
100167 while (len) {
100168 - int bytes, ret, offset;
100169 + ssize_t bytes, ret, offset;
100170 void *maddr;
100171 struct page *page = NULL;
100172
100173 @@ -3643,8 +3942,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
100174 *
100175 * The caller must hold a reference on @mm.
100176 */
100177 -int access_remote_vm(struct mm_struct *mm, unsigned long addr,
100178 - void *buf, int len, int write)
100179 +ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
100180 + void *buf, size_t len, int write)
100181 {
100182 return __access_remote_vm(NULL, mm, addr, buf, len, write);
100183 }
100184 @@ -3654,11 +3953,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
100185 * Source/target buffer must be kernel space,
100186 * Do not walk the page table directly, use get_user_pages
100187 */
100188 -int access_process_vm(struct task_struct *tsk, unsigned long addr,
100189 - void *buf, int len, int write)
100190 +ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
100191 + void *buf, size_t len, int write)
100192 {
100193 struct mm_struct *mm;
100194 - int ret;
100195 + ssize_t ret;
100196
100197 mm = get_task_mm(tsk);
100198 if (!mm)
100199 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
100200 index 8f5330d..b41914b 100644
100201 --- a/mm/mempolicy.c
100202 +++ b/mm/mempolicy.c
100203 @@ -750,6 +750,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
100204 unsigned long vmstart;
100205 unsigned long vmend;
100206
100207 +#ifdef CONFIG_PAX_SEGMEXEC
100208 + struct vm_area_struct *vma_m;
100209 +#endif
100210 +
100211 vma = find_vma(mm, start);
100212 if (!vma || vma->vm_start > start)
100213 return -EFAULT;
100214 @@ -793,6 +797,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
100215 err = vma_replace_policy(vma, new_pol);
100216 if (err)
100217 goto out;
100218 +
100219 +#ifdef CONFIG_PAX_SEGMEXEC
100220 + vma_m = pax_find_mirror_vma(vma);
100221 + if (vma_m) {
100222 + err = vma_replace_policy(vma_m, new_pol);
100223 + if (err)
100224 + goto out;
100225 + }
100226 +#endif
100227 +
100228 }
100229
100230 out:
100231 @@ -1225,6 +1239,17 @@ static long do_mbind(unsigned long start, unsigned long len,
100232
100233 if (end < start)
100234 return -EINVAL;
100235 +
100236 +#ifdef CONFIG_PAX_SEGMEXEC
100237 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
100238 + if (end > SEGMEXEC_TASK_SIZE)
100239 + return -EINVAL;
100240 + } else
100241 +#endif
100242 +
100243 + if (end > TASK_SIZE)
100244 + return -EINVAL;
100245 +
100246 if (end == start)
100247 return 0;
100248
100249 @@ -1450,8 +1475,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
100250 */
100251 tcred = __task_cred(task);
100252 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
100253 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
100254 - !capable(CAP_SYS_NICE)) {
100255 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
100256 rcu_read_unlock();
100257 err = -EPERM;
100258 goto out_put;
100259 @@ -1482,6 +1506,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
100260 goto out;
100261 }
100262
100263 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
100264 + if (mm != current->mm &&
100265 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
100266 + mmput(mm);
100267 + err = -EPERM;
100268 + goto out;
100269 + }
100270 +#endif
100271 +
100272 err = do_migrate_pages(mm, old, new,
100273 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
100274
100275 diff --git a/mm/migrate.c b/mm/migrate.c
100276 index be6dbf9..febb8ec 100644
100277 --- a/mm/migrate.c
100278 +++ b/mm/migrate.c
100279 @@ -1506,8 +1506,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
100280 */
100281 tcred = __task_cred(task);
100282 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
100283 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
100284 - !capable(CAP_SYS_NICE)) {
100285 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
100286 rcu_read_unlock();
100287 err = -EPERM;
100288 goto out;
100289 diff --git a/mm/mlock.c b/mm/mlock.c
100290 index b1eb536..091d154 100644
100291 --- a/mm/mlock.c
100292 +++ b/mm/mlock.c
100293 @@ -14,6 +14,7 @@
100294 #include <linux/pagevec.h>
100295 #include <linux/mempolicy.h>
100296 #include <linux/syscalls.h>
100297 +#include <linux/security.h>
100298 #include <linux/sched.h>
100299 #include <linux/export.h>
100300 #include <linux/rmap.h>
100301 @@ -606,7 +607,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
100302 {
100303 unsigned long nstart, end, tmp;
100304 struct vm_area_struct * vma, * prev;
100305 - int error;
100306 + int error = 0;
100307
100308 VM_BUG_ON(start & ~PAGE_MASK);
100309 VM_BUG_ON(len != PAGE_ALIGN(len));
100310 @@ -615,6 +616,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
100311 return -EINVAL;
100312 if (end == start)
100313 return 0;
100314 + if (end > TASK_SIZE)
100315 + return -EINVAL;
100316 +
100317 vma = find_vma(current->mm, start);
100318 if (!vma || vma->vm_start > start)
100319 return -ENOMEM;
100320 @@ -626,6 +630,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
100321 for (nstart = start ; ; ) {
100322 vm_flags_t newflags;
100323
100324 +#ifdef CONFIG_PAX_SEGMEXEC
100325 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
100326 + break;
100327 +#endif
100328 +
100329 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
100330
100331 newflags = vma->vm_flags & ~VM_LOCKED;
100332 @@ -739,6 +748,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
100333 locked += current->mm->locked_vm;
100334
100335 /* check against resource limits */
100336 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
100337 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
100338 error = do_mlock(start, len, 1);
100339
100340 @@ -776,6 +786,11 @@ static int do_mlockall(int flags)
100341 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
100342 vm_flags_t newflags;
100343
100344 +#ifdef CONFIG_PAX_SEGMEXEC
100345 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
100346 + break;
100347 +#endif
100348 +
100349 newflags = vma->vm_flags & ~VM_LOCKED;
100350 if (flags & MCL_CURRENT)
100351 newflags |= VM_LOCKED;
100352 @@ -807,8 +822,10 @@ SYSCALL_DEFINE1(mlockall, int, flags)
100353 lock_limit >>= PAGE_SHIFT;
100354
100355 ret = -ENOMEM;
100356 +
100357 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
100358 +
100359 down_write(&current->mm->mmap_sem);
100360 -
100361 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
100362 capable(CAP_IPC_LOCK))
100363 ret = do_mlockall(flags);
100364 diff --git a/mm/mmap.c b/mm/mmap.c
100365 index 129b847..fbed804 100644
100366 --- a/mm/mmap.c
100367 +++ b/mm/mmap.c
100368 @@ -40,6 +40,7 @@
100369 #include <linux/notifier.h>
100370 #include <linux/memory.h>
100371 #include <linux/printk.h>
100372 +#include <linux/random.h>
100373
100374 #include <asm/uaccess.h>
100375 #include <asm/cacheflush.h>
100376 @@ -56,6 +57,16 @@
100377 #define arch_rebalance_pgtables(addr, len) (addr)
100378 #endif
100379
100380 +static inline void verify_mm_writelocked(struct mm_struct *mm)
100381 +{
100382 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
100383 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
100384 + up_read(&mm->mmap_sem);
100385 + BUG();
100386 + }
100387 +#endif
100388 +}
100389 +
100390 static void unmap_region(struct mm_struct *mm,
100391 struct vm_area_struct *vma, struct vm_area_struct *prev,
100392 unsigned long start, unsigned long end);
100393 @@ -75,16 +86,25 @@ static void unmap_region(struct mm_struct *mm,
100394 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
100395 *
100396 */
100397 -pgprot_t protection_map[16] = {
100398 +pgprot_t protection_map[16] __read_only = {
100399 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
100400 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
100401 };
100402
100403 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
100404 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
100405 {
100406 - return __pgprot(pgprot_val(protection_map[vm_flags &
100407 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
100408 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
100409 pgprot_val(arch_vm_get_page_prot(vm_flags)));
100410 +
100411 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
100412 + if (!(__supported_pte_mask & _PAGE_NX) &&
100413 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
100414 + (vm_flags & (VM_READ | VM_WRITE)))
100415 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
100416 +#endif
100417 +
100418 + return prot;
100419 }
100420 EXPORT_SYMBOL(vm_get_page_prot);
100421
100422 @@ -94,6 +114,7 @@ unsigned long sysctl_overcommit_kbytes __read_mostly;
100423 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
100424 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
100425 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
100426 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
100427 /*
100428 * Make sure vm_committed_as in one cacheline and not cacheline shared with
100429 * other variables. It can be updated by several CPUs frequently.
100430 @@ -250,6 +271,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
100431 struct vm_area_struct *next = vma->vm_next;
100432
100433 might_sleep();
100434 + BUG_ON(vma->vm_mirror);
100435 if (vma->vm_ops && vma->vm_ops->close)
100436 vma->vm_ops->close(vma);
100437 if (vma->vm_file)
100438 @@ -294,6 +316,12 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
100439 * not page aligned -Ram Gupta
100440 */
100441 rlim = rlimit(RLIMIT_DATA);
100442 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
100443 + /* force a minimum 16MB brk heap on setuid/setgid binaries */
100444 + if (rlim < PAGE_SIZE && (get_dumpable(mm) != SUID_DUMP_USER) && gr_is_global_nonroot(current_uid()))
100445 + rlim = 4096 * PAGE_SIZE;
100446 +#endif
100447 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
100448 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
100449 (mm->end_data - mm->start_data) > rlim)
100450 goto out;
100451 @@ -944,6 +972,12 @@ static int
100452 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
100453 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
100454 {
100455 +
100456 +#ifdef CONFIG_PAX_SEGMEXEC
100457 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
100458 + return 0;
100459 +#endif
100460 +
100461 if (is_mergeable_vma(vma, file, vm_flags) &&
100462 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
100463 if (vma->vm_pgoff == vm_pgoff)
100464 @@ -963,6 +997,12 @@ static int
100465 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
100466 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
100467 {
100468 +
100469 +#ifdef CONFIG_PAX_SEGMEXEC
100470 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
100471 + return 0;
100472 +#endif
100473 +
100474 if (is_mergeable_vma(vma, file, vm_flags) &&
100475 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
100476 pgoff_t vm_pglen;
100477 @@ -1005,13 +1045,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
100478 struct vm_area_struct *vma_merge(struct mm_struct *mm,
100479 struct vm_area_struct *prev, unsigned long addr,
100480 unsigned long end, unsigned long vm_flags,
100481 - struct anon_vma *anon_vma, struct file *file,
100482 + struct anon_vma *anon_vma, struct file *file,
100483 pgoff_t pgoff, struct mempolicy *policy)
100484 {
100485 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
100486 struct vm_area_struct *area, *next;
100487 int err;
100488
100489 +#ifdef CONFIG_PAX_SEGMEXEC
100490 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
100491 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
100492 +
100493 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
100494 +#endif
100495 +
100496 /*
100497 * We later require that vma->vm_flags == vm_flags,
100498 * so this tests vma->vm_flags & VM_SPECIAL, too.
100499 @@ -1027,6 +1074,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
100500 if (next && next->vm_end == end) /* cases 6, 7, 8 */
100501 next = next->vm_next;
100502
100503 +#ifdef CONFIG_PAX_SEGMEXEC
100504 + if (prev)
100505 + prev_m = pax_find_mirror_vma(prev);
100506 + if (area)
100507 + area_m = pax_find_mirror_vma(area);
100508 + if (next)
100509 + next_m = pax_find_mirror_vma(next);
100510 +#endif
100511 +
100512 /*
100513 * Can it merge with the predecessor?
100514 */
100515 @@ -1046,9 +1102,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
100516 /* cases 1, 6 */
100517 err = vma_adjust(prev, prev->vm_start,
100518 next->vm_end, prev->vm_pgoff, NULL);
100519 - } else /* cases 2, 5, 7 */
100520 +
100521 +#ifdef CONFIG_PAX_SEGMEXEC
100522 + if (!err && prev_m)
100523 + err = vma_adjust(prev_m, prev_m->vm_start,
100524 + next_m->vm_end, prev_m->vm_pgoff, NULL);
100525 +#endif
100526 +
100527 + } else { /* cases 2, 5, 7 */
100528 err = vma_adjust(prev, prev->vm_start,
100529 end, prev->vm_pgoff, NULL);
100530 +
100531 +#ifdef CONFIG_PAX_SEGMEXEC
100532 + if (!err && prev_m)
100533 + err = vma_adjust(prev_m, prev_m->vm_start,
100534 + end_m, prev_m->vm_pgoff, NULL);
100535 +#endif
100536 +
100537 + }
100538 if (err)
100539 return NULL;
100540 khugepaged_enter_vma_merge(prev);
100541 @@ -1062,12 +1133,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
100542 mpol_equal(policy, vma_policy(next)) &&
100543 can_vma_merge_before(next, vm_flags,
100544 anon_vma, file, pgoff+pglen)) {
100545 - if (prev && addr < prev->vm_end) /* case 4 */
100546 + if (prev && addr < prev->vm_end) { /* case 4 */
100547 err = vma_adjust(prev, prev->vm_start,
100548 addr, prev->vm_pgoff, NULL);
100549 - else /* cases 3, 8 */
100550 +
100551 +#ifdef CONFIG_PAX_SEGMEXEC
100552 + if (!err && prev_m)
100553 + err = vma_adjust(prev_m, prev_m->vm_start,
100554 + addr_m, prev_m->vm_pgoff, NULL);
100555 +#endif
100556 +
100557 + } else { /* cases 3, 8 */
100558 err = vma_adjust(area, addr, next->vm_end,
100559 next->vm_pgoff - pglen, NULL);
100560 +
100561 +#ifdef CONFIG_PAX_SEGMEXEC
100562 + if (!err && area_m)
100563 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
100564 + next_m->vm_pgoff - pglen, NULL);
100565 +#endif
100566 +
100567 + }
100568 if (err)
100569 return NULL;
100570 khugepaged_enter_vma_merge(area);
100571 @@ -1176,8 +1262,10 @@ none:
100572 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
100573 struct file *file, long pages)
100574 {
100575 - const unsigned long stack_flags
100576 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
100577 +
100578 +#ifdef CONFIG_PAX_RANDMMAP
100579 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
100580 +#endif
100581
100582 mm->total_vm += pages;
100583
100584 @@ -1185,7 +1273,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
100585 mm->shared_vm += pages;
100586 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
100587 mm->exec_vm += pages;
100588 - } else if (flags & stack_flags)
100589 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
100590 mm->stack_vm += pages;
100591 }
100592 #endif /* CONFIG_PROC_FS */
100593 @@ -1215,6 +1303,7 @@ static inline int mlock_future_check(struct mm_struct *mm,
100594 locked += mm->locked_vm;
100595 lock_limit = rlimit(RLIMIT_MEMLOCK);
100596 lock_limit >>= PAGE_SHIFT;
100597 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
100598 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
100599 return -EAGAIN;
100600 }
100601 @@ -1241,7 +1330,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
100602 * (the exception is when the underlying filesystem is noexec
100603 * mounted, in which case we dont add PROT_EXEC.)
100604 */
100605 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
100606 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
100607 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
100608 prot |= PROT_EXEC;
100609
100610 @@ -1267,7 +1356,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
100611 /* Obtain the address to map to. we verify (or select) it and ensure
100612 * that it represents a valid section of the address space.
100613 */
100614 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
100615 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
100616 if (addr & ~PAGE_MASK)
100617 return addr;
100618
100619 @@ -1278,6 +1367,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
100620 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
100621 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
100622
100623 +#ifdef CONFIG_PAX_MPROTECT
100624 + if (mm->pax_flags & MF_PAX_MPROTECT) {
100625 +
100626 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
100627 + if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
100628 + mm->binfmt->handle_mmap)
100629 + mm->binfmt->handle_mmap(file);
100630 +#endif
100631 +
100632 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
100633 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
100634 + gr_log_rwxmmap(file);
100635 +
100636 +#ifdef CONFIG_PAX_EMUPLT
100637 + vm_flags &= ~VM_EXEC;
100638 +#else
100639 + return -EPERM;
100640 +#endif
100641 +
100642 + }
100643 +
100644 + if (!(vm_flags & VM_EXEC))
100645 + vm_flags &= ~VM_MAYEXEC;
100646 +#else
100647 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
100648 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
100649 +#endif
100650 + else
100651 + vm_flags &= ~VM_MAYWRITE;
100652 + }
100653 +#endif
100654 +
100655 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
100656 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
100657 + vm_flags &= ~VM_PAGEEXEC;
100658 +#endif
100659 +
100660 if (flags & MAP_LOCKED)
100661 if (!can_do_mlock())
100662 return -EPERM;
100663 @@ -1365,6 +1491,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
100664 vm_flags |= VM_NORESERVE;
100665 }
100666
100667 + if (!gr_acl_handle_mmap(file, prot))
100668 + return -EACCES;
100669 +
100670 addr = mmap_region(file, addr, len, vm_flags, pgoff);
100671 if (!IS_ERR_VALUE(addr) &&
100672 ((vm_flags & VM_LOCKED) ||
100673 @@ -1458,7 +1587,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
100674 vm_flags_t vm_flags = vma->vm_flags;
100675
100676 /* If it was private or non-writable, the write bit is already clear */
100677 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
100678 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
100679 return 0;
100680
100681 /* The backer wishes to know when pages are first written to? */
100682 @@ -1504,7 +1633,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
100683 struct rb_node **rb_link, *rb_parent;
100684 unsigned long charged = 0;
100685
100686 +#ifdef CONFIG_PAX_SEGMEXEC
100687 + struct vm_area_struct *vma_m = NULL;
100688 +#endif
100689 +
100690 + /*
100691 + * mm->mmap_sem is required to protect against another thread
100692 + * changing the mappings in case we sleep.
100693 + */
100694 + verify_mm_writelocked(mm);
100695 +
100696 /* Check against address space limit. */
100697 +
100698 +#ifdef CONFIG_PAX_RANDMMAP
100699 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
100700 +#endif
100701 +
100702 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
100703 unsigned long nr_pages;
100704
100705 @@ -1523,11 +1667,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
100706
100707 /* Clear old maps */
100708 error = -ENOMEM;
100709 -munmap_back:
100710 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
100711 if (do_munmap(mm, addr, len))
100712 return -ENOMEM;
100713 - goto munmap_back;
100714 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
100715 }
100716
100717 /*
100718 @@ -1558,6 +1701,16 @@ munmap_back:
100719 goto unacct_error;
100720 }
100721
100722 +#ifdef CONFIG_PAX_SEGMEXEC
100723 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
100724 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
100725 + if (!vma_m) {
100726 + error = -ENOMEM;
100727 + goto free_vma;
100728 + }
100729 + }
100730 +#endif
100731 +
100732 vma->vm_mm = mm;
100733 vma->vm_start = addr;
100734 vma->vm_end = addr + len;
100735 @@ -1577,6 +1730,13 @@ munmap_back:
100736 if (error)
100737 goto unmap_and_free_vma;
100738
100739 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
100740 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
100741 + vma->vm_flags |= VM_PAGEEXEC;
100742 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
100743 + }
100744 +#endif
100745 +
100746 /* Can addr have changed??
100747 *
100748 * Answer: Yes, several device drivers can do it in their
100749 @@ -1610,6 +1770,12 @@ munmap_back:
100750 }
100751
100752 vma_link(mm, vma, prev, rb_link, rb_parent);
100753 +
100754 +#ifdef CONFIG_PAX_SEGMEXEC
100755 + if (vma_m)
100756 + BUG_ON(pax_mirror_vma(vma_m, vma));
100757 +#endif
100758 +
100759 /* Once vma denies write, undo our temporary denial count */
100760 if (vm_flags & VM_DENYWRITE)
100761 allow_write_access(file);
100762 @@ -1618,6 +1784,7 @@ out:
100763 perf_event_mmap(vma);
100764
100765 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
100766 + track_exec_limit(mm, addr, addr + len, vm_flags);
100767 if (vm_flags & VM_LOCKED) {
100768 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
100769 vma == get_gate_vma(current->mm)))
100770 @@ -1650,6 +1817,12 @@ unmap_and_free_vma:
100771 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
100772 charged = 0;
100773 free_vma:
100774 +
100775 +#ifdef CONFIG_PAX_SEGMEXEC
100776 + if (vma_m)
100777 + kmem_cache_free(vm_area_cachep, vma_m);
100778 +#endif
100779 +
100780 kmem_cache_free(vm_area_cachep, vma);
100781 unacct_error:
100782 if (charged)
100783 @@ -1657,7 +1830,63 @@ unacct_error:
100784 return error;
100785 }
100786
100787 -unsigned long unmapped_area(struct vm_unmapped_area_info *info)
100788 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
100789 +unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
100790 +{
100791 + if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
100792 + return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
100793 +
100794 + return 0;
100795 +}
100796 +#endif
100797 +
100798 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
100799 +{
100800 + if (!vma) {
100801 +#ifdef CONFIG_STACK_GROWSUP
100802 + if (addr > sysctl_heap_stack_gap)
100803 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
100804 + else
100805 + vma = find_vma(current->mm, 0);
100806 + if (vma && (vma->vm_flags & VM_GROWSUP))
100807 + return false;
100808 +#endif
100809 + return true;
100810 + }
100811 +
100812 + if (addr + len > vma->vm_start)
100813 + return false;
100814 +
100815 + if (vma->vm_flags & VM_GROWSDOWN)
100816 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
100817 +#ifdef CONFIG_STACK_GROWSUP
100818 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
100819 + return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
100820 +#endif
100821 + else if (offset)
100822 + return offset <= vma->vm_start - addr - len;
100823 +
100824 + return true;
100825 +}
100826 +
100827 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
100828 +{
100829 + if (vma->vm_start < len)
100830 + return -ENOMEM;
100831 +
100832 + if (!(vma->vm_flags & VM_GROWSDOWN)) {
100833 + if (offset <= vma->vm_start - len)
100834 + return vma->vm_start - len - offset;
100835 + else
100836 + return -ENOMEM;
100837 + }
100838 +
100839 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
100840 + return vma->vm_start - len - sysctl_heap_stack_gap;
100841 + return -ENOMEM;
100842 +}
100843 +
100844 +unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
100845 {
100846 /*
100847 * We implement the search by looking for an rbtree node that
100848 @@ -1705,11 +1934,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
100849 }
100850 }
100851
100852 - gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
100853 + gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
100854 check_current:
100855 /* Check if current node has a suitable gap */
100856 if (gap_start > high_limit)
100857 return -ENOMEM;
100858 +
100859 + if (gap_end - gap_start > info->threadstack_offset)
100860 + gap_start += info->threadstack_offset;
100861 + else
100862 + gap_start = gap_end;
100863 +
100864 + if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
100865 + if (gap_end - gap_start > sysctl_heap_stack_gap)
100866 + gap_start += sysctl_heap_stack_gap;
100867 + else
100868 + gap_start = gap_end;
100869 + }
100870 + if (vma->vm_flags & VM_GROWSDOWN) {
100871 + if (gap_end - gap_start > sysctl_heap_stack_gap)
100872 + gap_end -= sysctl_heap_stack_gap;
100873 + else
100874 + gap_end = gap_start;
100875 + }
100876 if (gap_end >= low_limit && gap_end - gap_start >= length)
100877 goto found;
100878
100879 @@ -1759,7 +2006,7 @@ found:
100880 return gap_start;
100881 }
100882
100883 -unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
100884 +unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
100885 {
100886 struct mm_struct *mm = current->mm;
100887 struct vm_area_struct *vma;
100888 @@ -1813,6 +2060,24 @@ check_current:
100889 gap_end = vma->vm_start;
100890 if (gap_end < low_limit)
100891 return -ENOMEM;
100892 +
100893 + if (gap_end - gap_start > info->threadstack_offset)
100894 + gap_end -= info->threadstack_offset;
100895 + else
100896 + gap_end = gap_start;
100897 +
100898 + if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
100899 + if (gap_end - gap_start > sysctl_heap_stack_gap)
100900 + gap_start += sysctl_heap_stack_gap;
100901 + else
100902 + gap_start = gap_end;
100903 + }
100904 + if (vma->vm_flags & VM_GROWSDOWN) {
100905 + if (gap_end - gap_start > sysctl_heap_stack_gap)
100906 + gap_end -= sysctl_heap_stack_gap;
100907 + else
100908 + gap_end = gap_start;
100909 + }
100910 if (gap_start <= high_limit && gap_end - gap_start >= length)
100911 goto found;
100912
100913 @@ -1876,6 +2141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
100914 struct mm_struct *mm = current->mm;
100915 struct vm_area_struct *vma;
100916 struct vm_unmapped_area_info info;
100917 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
100918
100919 if (len > TASK_SIZE - mmap_min_addr)
100920 return -ENOMEM;
100921 @@ -1883,11 +2149,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
100922 if (flags & MAP_FIXED)
100923 return addr;
100924
100925 +#ifdef CONFIG_PAX_RANDMMAP
100926 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
100927 +#endif
100928 +
100929 if (addr) {
100930 addr = PAGE_ALIGN(addr);
100931 vma = find_vma(mm, addr);
100932 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
100933 - (!vma || addr + len <= vma->vm_start))
100934 + check_heap_stack_gap(vma, addr, len, offset))
100935 return addr;
100936 }
100937
100938 @@ -1896,6 +2166,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
100939 info.low_limit = mm->mmap_base;
100940 info.high_limit = TASK_SIZE;
100941 info.align_mask = 0;
100942 + info.threadstack_offset = offset;
100943 return vm_unmapped_area(&info);
100944 }
100945 #endif
100946 @@ -1914,6 +2185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
100947 struct mm_struct *mm = current->mm;
100948 unsigned long addr = addr0;
100949 struct vm_unmapped_area_info info;
100950 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
100951
100952 /* requested length too big for entire address space */
100953 if (len > TASK_SIZE - mmap_min_addr)
100954 @@ -1922,12 +2194,16 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
100955 if (flags & MAP_FIXED)
100956 return addr;
100957
100958 +#ifdef CONFIG_PAX_RANDMMAP
100959 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
100960 +#endif
100961 +
100962 /* requesting a specific address */
100963 if (addr) {
100964 addr = PAGE_ALIGN(addr);
100965 vma = find_vma(mm, addr);
100966 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
100967 - (!vma || addr + len <= vma->vm_start))
100968 + check_heap_stack_gap(vma, addr, len, offset))
100969 return addr;
100970 }
100971
100972 @@ -1936,6 +2212,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
100973 info.low_limit = max(PAGE_SIZE, mmap_min_addr);
100974 info.high_limit = mm->mmap_base;
100975 info.align_mask = 0;
100976 + info.threadstack_offset = offset;
100977 addr = vm_unmapped_area(&info);
100978
100979 /*
100980 @@ -1948,6 +2225,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
100981 VM_BUG_ON(addr != -ENOMEM);
100982 info.flags = 0;
100983 info.low_limit = TASK_UNMAPPED_BASE;
100984 +
100985 +#ifdef CONFIG_PAX_RANDMMAP
100986 + if (mm->pax_flags & MF_PAX_RANDMMAP)
100987 + info.low_limit += mm->delta_mmap;
100988 +#endif
100989 +
100990 info.high_limit = TASK_SIZE;
100991 addr = vm_unmapped_area(&info);
100992 }
100993 @@ -2048,6 +2331,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
100994 return vma;
100995 }
100996
100997 +#ifdef CONFIG_PAX_SEGMEXEC
100998 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
100999 +{
101000 + struct vm_area_struct *vma_m;
101001 +
101002 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
101003 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
101004 + BUG_ON(vma->vm_mirror);
101005 + return NULL;
101006 + }
101007 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
101008 + vma_m = vma->vm_mirror;
101009 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
101010 + BUG_ON(vma->vm_file != vma_m->vm_file);
101011 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
101012 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
101013 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
101014 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
101015 + return vma_m;
101016 +}
101017 +#endif
101018 +
101019 /*
101020 * Verify that the stack growth is acceptable and
101021 * update accounting. This is shared with both the
101022 @@ -2064,6 +2369,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
101023 return -ENOMEM;
101024
101025 /* Stack limit test */
101026 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
101027 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
101028 return -ENOMEM;
101029
101030 @@ -2074,6 +2380,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
101031 locked = mm->locked_vm + grow;
101032 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
101033 limit >>= PAGE_SHIFT;
101034 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
101035 if (locked > limit && !capable(CAP_IPC_LOCK))
101036 return -ENOMEM;
101037 }
101038 @@ -2103,37 +2410,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
101039 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
101040 * vma is the last one with address > vma->vm_end. Have to extend vma.
101041 */
101042 +#ifndef CONFIG_IA64
101043 +static
101044 +#endif
101045 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
101046 {
101047 int error;
101048 + bool locknext;
101049
101050 if (!(vma->vm_flags & VM_GROWSUP))
101051 return -EFAULT;
101052
101053 + /* Also guard against wrapping around to address 0. */
101054 + if (address < PAGE_ALIGN(address+1))
101055 + address = PAGE_ALIGN(address+1);
101056 + else
101057 + return -ENOMEM;
101058 +
101059 /*
101060 * We must make sure the anon_vma is allocated
101061 * so that the anon_vma locking is not a noop.
101062 */
101063 if (unlikely(anon_vma_prepare(vma)))
101064 return -ENOMEM;
101065 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
101066 + if (locknext && anon_vma_prepare(vma->vm_next))
101067 + return -ENOMEM;
101068 vma_lock_anon_vma(vma);
101069 + if (locknext)
101070 + vma_lock_anon_vma(vma->vm_next);
101071
101072 /*
101073 * vma->vm_start/vm_end cannot change under us because the caller
101074 * is required to hold the mmap_sem in read mode. We need the
101075 - * anon_vma lock to serialize against concurrent expand_stacks.
101076 - * Also guard against wrapping around to address 0.
101077 + * anon_vma locks to serialize against concurrent expand_stacks
101078 + * and expand_upwards.
101079 */
101080 - if (address < PAGE_ALIGN(address+4))
101081 - address = PAGE_ALIGN(address+4);
101082 - else {
101083 - vma_unlock_anon_vma(vma);
101084 - return -ENOMEM;
101085 - }
101086 error = 0;
101087
101088 /* Somebody else might have raced and expanded it already */
101089 - if (address > vma->vm_end) {
101090 + 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)
101091 + error = -ENOMEM;
101092 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
101093 unsigned long size, grow;
101094
101095 size = address - vma->vm_start;
101096 @@ -2168,6 +2486,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
101097 }
101098 }
101099 }
101100 + if (locknext)
101101 + vma_unlock_anon_vma(vma->vm_next);
101102 vma_unlock_anon_vma(vma);
101103 khugepaged_enter_vma_merge(vma);
101104 validate_mm(vma->vm_mm);
101105 @@ -2182,6 +2502,8 @@ int expand_downwards(struct vm_area_struct *vma,
101106 unsigned long address)
101107 {
101108 int error;
101109 + bool lockprev = false;
101110 + struct vm_area_struct *prev;
101111
101112 /*
101113 * We must make sure the anon_vma is allocated
101114 @@ -2195,6 +2517,15 @@ int expand_downwards(struct vm_area_struct *vma,
101115 if (error)
101116 return error;
101117
101118 + prev = vma->vm_prev;
101119 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
101120 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
101121 +#endif
101122 + if (lockprev && anon_vma_prepare(prev))
101123 + return -ENOMEM;
101124 + if (lockprev)
101125 + vma_lock_anon_vma(prev);
101126 +
101127 vma_lock_anon_vma(vma);
101128
101129 /*
101130 @@ -2204,9 +2535,17 @@ int expand_downwards(struct vm_area_struct *vma,
101131 */
101132
101133 /* Somebody else might have raced and expanded it already */
101134 - if (address < vma->vm_start) {
101135 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
101136 + error = -ENOMEM;
101137 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
101138 unsigned long size, grow;
101139
101140 +#ifdef CONFIG_PAX_SEGMEXEC
101141 + struct vm_area_struct *vma_m;
101142 +
101143 + vma_m = pax_find_mirror_vma(vma);
101144 +#endif
101145 +
101146 size = vma->vm_end - address;
101147 grow = (vma->vm_start - address) >> PAGE_SHIFT;
101148
101149 @@ -2231,13 +2570,27 @@ int expand_downwards(struct vm_area_struct *vma,
101150 vma->vm_pgoff -= grow;
101151 anon_vma_interval_tree_post_update_vma(vma);
101152 vma_gap_update(vma);
101153 +
101154 +#ifdef CONFIG_PAX_SEGMEXEC
101155 + if (vma_m) {
101156 + anon_vma_interval_tree_pre_update_vma(vma_m);
101157 + vma_m->vm_start -= grow << PAGE_SHIFT;
101158 + vma_m->vm_pgoff -= grow;
101159 + anon_vma_interval_tree_post_update_vma(vma_m);
101160 + vma_gap_update(vma_m);
101161 + }
101162 +#endif
101163 +
101164 spin_unlock(&vma->vm_mm->page_table_lock);
101165
101166 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
101167 perf_event_mmap(vma);
101168 }
101169 }
101170 }
101171 vma_unlock_anon_vma(vma);
101172 + if (lockprev)
101173 + vma_unlock_anon_vma(prev);
101174 khugepaged_enter_vma_merge(vma);
101175 validate_mm(vma->vm_mm);
101176 return error;
101177 @@ -2335,6 +2688,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
101178 do {
101179 long nrpages = vma_pages(vma);
101180
101181 +#ifdef CONFIG_PAX_SEGMEXEC
101182 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
101183 + vma = remove_vma(vma);
101184 + continue;
101185 + }
101186 +#endif
101187 +
101188 if (vma->vm_flags & VM_ACCOUNT)
101189 nr_accounted += nrpages;
101190 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
101191 @@ -2379,6 +2739,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
101192 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
101193 vma->vm_prev = NULL;
101194 do {
101195 +
101196 +#ifdef CONFIG_PAX_SEGMEXEC
101197 + if (vma->vm_mirror) {
101198 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
101199 + vma->vm_mirror->vm_mirror = NULL;
101200 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
101201 + vma->vm_mirror = NULL;
101202 + }
101203 +#endif
101204 +
101205 vma_rb_erase(vma, &mm->mm_rb);
101206 mm->map_count--;
101207 tail_vma = vma;
101208 @@ -2406,14 +2776,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
101209 struct vm_area_struct *new;
101210 int err = -ENOMEM;
101211
101212 +#ifdef CONFIG_PAX_SEGMEXEC
101213 + struct vm_area_struct *vma_m, *new_m = NULL;
101214 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
101215 +#endif
101216 +
101217 if (is_vm_hugetlb_page(vma) && (addr &
101218 ~(huge_page_mask(hstate_vma(vma)))))
101219 return -EINVAL;
101220
101221 +#ifdef CONFIG_PAX_SEGMEXEC
101222 + vma_m = pax_find_mirror_vma(vma);
101223 +#endif
101224 +
101225 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
101226 if (!new)
101227 goto out_err;
101228
101229 +#ifdef CONFIG_PAX_SEGMEXEC
101230 + if (vma_m) {
101231 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
101232 + if (!new_m) {
101233 + kmem_cache_free(vm_area_cachep, new);
101234 + goto out_err;
101235 + }
101236 + }
101237 +#endif
101238 +
101239 /* most fields are the same, copy all, and then fixup */
101240 *new = *vma;
101241
101242 @@ -2426,6 +2815,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
101243 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
101244 }
101245
101246 +#ifdef CONFIG_PAX_SEGMEXEC
101247 + if (vma_m) {
101248 + *new_m = *vma_m;
101249 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
101250 + new_m->vm_mirror = new;
101251 + new->vm_mirror = new_m;
101252 +
101253 + if (new_below)
101254 + new_m->vm_end = addr_m;
101255 + else {
101256 + new_m->vm_start = addr_m;
101257 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
101258 + }
101259 + }
101260 +#endif
101261 +
101262 err = vma_dup_policy(vma, new);
101263 if (err)
101264 goto out_free_vma;
101265 @@ -2445,6 +2850,38 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
101266 else
101267 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
101268
101269 +#ifdef CONFIG_PAX_SEGMEXEC
101270 + if (!err && vma_m) {
101271 + struct mempolicy *pol = vma_policy(new);
101272 +
101273 + if (anon_vma_clone(new_m, vma_m))
101274 + goto out_free_mpol;
101275 +
101276 + mpol_get(pol);
101277 + set_vma_policy(new_m, pol);
101278 +
101279 + if (new_m->vm_file)
101280 + get_file(new_m->vm_file);
101281 +
101282 + if (new_m->vm_ops && new_m->vm_ops->open)
101283 + new_m->vm_ops->open(new_m);
101284 +
101285 + if (new_below)
101286 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
101287 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
101288 + else
101289 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
101290 +
101291 + if (err) {
101292 + if (new_m->vm_ops && new_m->vm_ops->close)
101293 + new_m->vm_ops->close(new_m);
101294 + if (new_m->vm_file)
101295 + fput(new_m->vm_file);
101296 + mpol_put(pol);
101297 + }
101298 + }
101299 +#endif
101300 +
101301 /* Success. */
101302 if (!err)
101303 return 0;
101304 @@ -2454,10 +2891,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
101305 new->vm_ops->close(new);
101306 if (new->vm_file)
101307 fput(new->vm_file);
101308 - unlink_anon_vmas(new);
101309 out_free_mpol:
101310 mpol_put(vma_policy(new));
101311 out_free_vma:
101312 +
101313 +#ifdef CONFIG_PAX_SEGMEXEC
101314 + if (new_m) {
101315 + unlink_anon_vmas(new_m);
101316 + kmem_cache_free(vm_area_cachep, new_m);
101317 + }
101318 +#endif
101319 +
101320 + unlink_anon_vmas(new);
101321 kmem_cache_free(vm_area_cachep, new);
101322 out_err:
101323 return err;
101324 @@ -2470,6 +2915,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
101325 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
101326 unsigned long addr, int new_below)
101327 {
101328 +
101329 +#ifdef CONFIG_PAX_SEGMEXEC
101330 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
101331 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
101332 + if (mm->map_count >= sysctl_max_map_count-1)
101333 + return -ENOMEM;
101334 + } else
101335 +#endif
101336 +
101337 if (mm->map_count >= sysctl_max_map_count)
101338 return -ENOMEM;
101339
101340 @@ -2481,11 +2935,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
101341 * work. This now handles partial unmappings.
101342 * Jeremy Fitzhardinge <jeremy@goop.org>
101343 */
101344 +#ifdef CONFIG_PAX_SEGMEXEC
101345 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
101346 {
101347 + int ret = __do_munmap(mm, start, len);
101348 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
101349 + return ret;
101350 +
101351 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
101352 +}
101353 +
101354 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
101355 +#else
101356 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
101357 +#endif
101358 +{
101359 unsigned long end;
101360 struct vm_area_struct *vma, *prev, *last;
101361
101362 + /*
101363 + * mm->mmap_sem is required to protect against another thread
101364 + * changing the mappings in case we sleep.
101365 + */
101366 + verify_mm_writelocked(mm);
101367 +
101368 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
101369 return -EINVAL;
101370
101371 @@ -2560,6 +3033,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
101372 /* Fix up all other VM information */
101373 remove_vma_list(mm, vma);
101374
101375 + track_exec_limit(mm, start, end, 0UL);
101376 +
101377 return 0;
101378 }
101379
101380 @@ -2568,6 +3043,13 @@ int vm_munmap(unsigned long start, size_t len)
101381 int ret;
101382 struct mm_struct *mm = current->mm;
101383
101384 +
101385 +#ifdef CONFIG_PAX_SEGMEXEC
101386 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
101387 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
101388 + return -EINVAL;
101389 +#endif
101390 +
101391 down_write(&mm->mmap_sem);
101392 ret = do_munmap(mm, start, len);
101393 up_write(&mm->mmap_sem);
101394 @@ -2581,16 +3063,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
101395 return vm_munmap(addr, len);
101396 }
101397
101398 -static inline void verify_mm_writelocked(struct mm_struct *mm)
101399 -{
101400 -#ifdef CONFIG_DEBUG_VM
101401 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
101402 - WARN_ON(1);
101403 - up_read(&mm->mmap_sem);
101404 - }
101405 -#endif
101406 -}
101407 -
101408 /*
101409 * this is really a simplified "do_mmap". it only handles
101410 * anonymous maps. eventually we may be able to do some
101411 @@ -2604,6 +3076,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
101412 struct rb_node ** rb_link, * rb_parent;
101413 pgoff_t pgoff = addr >> PAGE_SHIFT;
101414 int error;
101415 + unsigned long charged;
101416
101417 len = PAGE_ALIGN(len);
101418 if (!len)
101419 @@ -2611,10 +3084,24 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
101420
101421 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
101422
101423 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
101424 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
101425 + flags &= ~VM_EXEC;
101426 +
101427 +#ifdef CONFIG_PAX_MPROTECT
101428 + if (mm->pax_flags & MF_PAX_MPROTECT)
101429 + flags &= ~VM_MAYEXEC;
101430 +#endif
101431 +
101432 + }
101433 +#endif
101434 +
101435 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
101436 if (error & ~PAGE_MASK)
101437 return error;
101438
101439 + charged = len >> PAGE_SHIFT;
101440 +
101441 error = mlock_future_check(mm, mm->def_flags, len);
101442 if (error)
101443 return error;
101444 @@ -2628,21 +3115,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
101445 /*
101446 * Clear old maps. this also does some error checking for us
101447 */
101448 - munmap_back:
101449 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
101450 if (do_munmap(mm, addr, len))
101451 return -ENOMEM;
101452 - goto munmap_back;
101453 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
101454 }
101455
101456 /* Check against address space limits *after* clearing old maps... */
101457 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
101458 + if (!may_expand_vm(mm, charged))
101459 return -ENOMEM;
101460
101461 if (mm->map_count > sysctl_max_map_count)
101462 return -ENOMEM;
101463
101464 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
101465 + if (security_vm_enough_memory_mm(mm, charged))
101466 return -ENOMEM;
101467
101468 /* Can we just expand an old private anonymous mapping? */
101469 @@ -2656,7 +3142,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
101470 */
101471 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
101472 if (!vma) {
101473 - vm_unacct_memory(len >> PAGE_SHIFT);
101474 + vm_unacct_memory(charged);
101475 return -ENOMEM;
101476 }
101477
101478 @@ -2670,10 +3156,11 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
101479 vma_link(mm, vma, prev, rb_link, rb_parent);
101480 out:
101481 perf_event_mmap(vma);
101482 - mm->total_vm += len >> PAGE_SHIFT;
101483 + mm->total_vm += charged;
101484 if (flags & VM_LOCKED)
101485 - mm->locked_vm += (len >> PAGE_SHIFT);
101486 + mm->locked_vm += charged;
101487 vma->vm_flags |= VM_SOFTDIRTY;
101488 + track_exec_limit(mm, addr, addr + len, flags);
101489 return addr;
101490 }
101491
101492 @@ -2735,6 +3222,7 @@ void exit_mmap(struct mm_struct *mm)
101493 while (vma) {
101494 if (vma->vm_flags & VM_ACCOUNT)
101495 nr_accounted += vma_pages(vma);
101496 + vma->vm_mirror = NULL;
101497 vma = remove_vma(vma);
101498 }
101499 vm_unacct_memory(nr_accounted);
101500 @@ -2752,6 +3240,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
101501 struct vm_area_struct *prev;
101502 struct rb_node **rb_link, *rb_parent;
101503
101504 +#ifdef CONFIG_PAX_SEGMEXEC
101505 + struct vm_area_struct *vma_m = NULL;
101506 +#endif
101507 +
101508 + if (security_mmap_addr(vma->vm_start))
101509 + return -EPERM;
101510 +
101511 /*
101512 * The vm_pgoff of a purely anonymous vma should be irrelevant
101513 * until its first write fault, when page's anon_vma and index
101514 @@ -2775,7 +3270,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
101515 security_vm_enough_memory_mm(mm, vma_pages(vma)))
101516 return -ENOMEM;
101517
101518 +#ifdef CONFIG_PAX_SEGMEXEC
101519 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
101520 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
101521 + if (!vma_m)
101522 + return -ENOMEM;
101523 + }
101524 +#endif
101525 +
101526 vma_link(mm, vma, prev, rb_link, rb_parent);
101527 +
101528 +#ifdef CONFIG_PAX_SEGMEXEC
101529 + if (vma_m)
101530 + BUG_ON(pax_mirror_vma(vma_m, vma));
101531 +#endif
101532 +
101533 return 0;
101534 }
101535
101536 @@ -2794,6 +3303,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
101537 struct rb_node **rb_link, *rb_parent;
101538 bool faulted_in_anon_vma = true;
101539
101540 + BUG_ON(vma->vm_mirror);
101541 +
101542 /*
101543 * If anonymous vma has not yet been faulted, update new pgoff
101544 * to match new location, to increase its chance of merging.
101545 @@ -2858,6 +3369,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
101546 return NULL;
101547 }
101548
101549 +#ifdef CONFIG_PAX_SEGMEXEC
101550 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
101551 +{
101552 + struct vm_area_struct *prev_m;
101553 + struct rb_node **rb_link_m, *rb_parent_m;
101554 + struct mempolicy *pol_m;
101555 +
101556 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
101557 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
101558 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
101559 + *vma_m = *vma;
101560 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
101561 + if (anon_vma_clone(vma_m, vma))
101562 + return -ENOMEM;
101563 + pol_m = vma_policy(vma_m);
101564 + mpol_get(pol_m);
101565 + set_vma_policy(vma_m, pol_m);
101566 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
101567 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
101568 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
101569 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
101570 + if (vma_m->vm_file)
101571 + get_file(vma_m->vm_file);
101572 + if (vma_m->vm_ops && vma_m->vm_ops->open)
101573 + vma_m->vm_ops->open(vma_m);
101574 + BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
101575 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
101576 + vma_m->vm_mirror = vma;
101577 + vma->vm_mirror = vma_m;
101578 + return 0;
101579 +}
101580 +#endif
101581 +
101582 /*
101583 * Return true if the calling process may expand its vm space by the passed
101584 * number of pages
101585 @@ -2869,6 +3413,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
101586
101587 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
101588
101589 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
101590 if (cur + npages > lim)
101591 return 0;
101592 return 1;
101593 @@ -2951,6 +3496,22 @@ static struct vm_area_struct *__install_special_mapping(
101594 vma->vm_start = addr;
101595 vma->vm_end = addr + len;
101596
101597 +#ifdef CONFIG_PAX_MPROTECT
101598 + if (mm->pax_flags & MF_PAX_MPROTECT) {
101599 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
101600 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
101601 + return ERR_PTR(-EPERM);
101602 + if (!(vm_flags & VM_EXEC))
101603 + vm_flags &= ~VM_MAYEXEC;
101604 +#else
101605 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
101606 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
101607 +#endif
101608 + else
101609 + vm_flags &= ~VM_MAYWRITE;
101610 + }
101611 +#endif
101612 +
101613 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND | VM_SOFTDIRTY;
101614 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
101615
101616 diff --git a/mm/mprotect.c b/mm/mprotect.c
101617 index c43d557..0b7ccd2 100644
101618 --- a/mm/mprotect.c
101619 +++ b/mm/mprotect.c
101620 @@ -24,10 +24,18 @@
101621 #include <linux/migrate.h>
101622 #include <linux/perf_event.h>
101623 #include <linux/ksm.h>
101624 +#include <linux/sched/sysctl.h>
101625 +
101626 +#ifdef CONFIG_PAX_MPROTECT
101627 +#include <linux/elf.h>
101628 +#include <linux/binfmts.h>
101629 +#endif
101630 +
101631 #include <asm/uaccess.h>
101632 #include <asm/pgtable.h>
101633 #include <asm/cacheflush.h>
101634 #include <asm/tlbflush.h>
101635 +#include <asm/mmu_context.h>
101636
101637 #ifndef pgprot_modify
101638 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
101639 @@ -256,6 +264,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
101640 return pages;
101641 }
101642
101643 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
101644 +/* called while holding the mmap semaphor for writing except stack expansion */
101645 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
101646 +{
101647 + unsigned long oldlimit, newlimit = 0UL;
101648 +
101649 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
101650 + return;
101651 +
101652 + spin_lock(&mm->page_table_lock);
101653 + oldlimit = mm->context.user_cs_limit;
101654 + if ((prot & VM_EXEC) && oldlimit < end)
101655 + /* USER_CS limit moved up */
101656 + newlimit = end;
101657 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
101658 + /* USER_CS limit moved down */
101659 + newlimit = start;
101660 +
101661 + if (newlimit) {
101662 + mm->context.user_cs_limit = newlimit;
101663 +
101664 +#ifdef CONFIG_SMP
101665 + wmb();
101666 + cpus_clear(mm->context.cpu_user_cs_mask);
101667 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
101668 +#endif
101669 +
101670 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
101671 + }
101672 + spin_unlock(&mm->page_table_lock);
101673 + if (newlimit == end) {
101674 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
101675 +
101676 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
101677 + if (is_vm_hugetlb_page(vma))
101678 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
101679 + else
101680 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
101681 + }
101682 +}
101683 +#endif
101684 +
101685 int
101686 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
101687 unsigned long start, unsigned long end, unsigned long newflags)
101688 @@ -268,11 +318,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
101689 int error;
101690 int dirty_accountable = 0;
101691
101692 +#ifdef CONFIG_PAX_SEGMEXEC
101693 + struct vm_area_struct *vma_m = NULL;
101694 + unsigned long start_m, end_m;
101695 +
101696 + start_m = start + SEGMEXEC_TASK_SIZE;
101697 + end_m = end + SEGMEXEC_TASK_SIZE;
101698 +#endif
101699 +
101700 if (newflags == oldflags) {
101701 *pprev = vma;
101702 return 0;
101703 }
101704
101705 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
101706 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
101707 +
101708 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
101709 + return -ENOMEM;
101710 +
101711 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
101712 + return -ENOMEM;
101713 + }
101714 +
101715 /*
101716 * If we make a private mapping writable we increase our commit;
101717 * but (without finer accounting) cannot reduce our commit if we
101718 @@ -289,6 +357,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
101719 }
101720 }
101721
101722 +#ifdef CONFIG_PAX_SEGMEXEC
101723 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
101724 + if (start != vma->vm_start) {
101725 + error = split_vma(mm, vma, start, 1);
101726 + if (error)
101727 + goto fail;
101728 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
101729 + *pprev = (*pprev)->vm_next;
101730 + }
101731 +
101732 + if (end != vma->vm_end) {
101733 + error = split_vma(mm, vma, end, 0);
101734 + if (error)
101735 + goto fail;
101736 + }
101737 +
101738 + if (pax_find_mirror_vma(vma)) {
101739 + error = __do_munmap(mm, start_m, end_m - start_m);
101740 + if (error)
101741 + goto fail;
101742 + } else {
101743 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
101744 + if (!vma_m) {
101745 + error = -ENOMEM;
101746 + goto fail;
101747 + }
101748 + vma->vm_flags = newflags;
101749 + error = pax_mirror_vma(vma_m, vma);
101750 + if (error) {
101751 + vma->vm_flags = oldflags;
101752 + goto fail;
101753 + }
101754 + }
101755 + }
101756 +#endif
101757 +
101758 /*
101759 * First try to merge with previous and/or next vma.
101760 */
101761 @@ -319,9 +423,21 @@ success:
101762 * vm_flags and vm_page_prot are protected by the mmap_sem
101763 * held in write mode.
101764 */
101765 +
101766 +#ifdef CONFIG_PAX_SEGMEXEC
101767 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
101768 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
101769 +#endif
101770 +
101771 vma->vm_flags = newflags;
101772 +
101773 +#ifdef CONFIG_PAX_MPROTECT
101774 + if (mm->binfmt && mm->binfmt->handle_mprotect)
101775 + mm->binfmt->handle_mprotect(vma, newflags);
101776 +#endif
101777 +
101778 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
101779 - vm_get_page_prot(newflags));
101780 + vm_get_page_prot(vma->vm_flags));
101781
101782 if (vma_wants_writenotify(vma)) {
101783 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
101784 @@ -360,6 +476,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
101785 end = start + len;
101786 if (end <= start)
101787 return -ENOMEM;
101788 +
101789 +#ifdef CONFIG_PAX_SEGMEXEC
101790 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
101791 + if (end > SEGMEXEC_TASK_SIZE)
101792 + return -EINVAL;
101793 + } else
101794 +#endif
101795 +
101796 + if (end > TASK_SIZE)
101797 + return -EINVAL;
101798 +
101799 if (!arch_validate_prot(prot))
101800 return -EINVAL;
101801
101802 @@ -367,7 +494,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
101803 /*
101804 * Does the application expect PROT_READ to imply PROT_EXEC:
101805 */
101806 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
101807 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
101808 prot |= PROT_EXEC;
101809
101810 vm_flags = calc_vm_prot_bits(prot);
101811 @@ -399,6 +526,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
101812 if (start > vma->vm_start)
101813 prev = vma;
101814
101815 +#ifdef CONFIG_PAX_MPROTECT
101816 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
101817 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
101818 +#endif
101819 +
101820 for (nstart = start ; ; ) {
101821 unsigned long newflags;
101822
101823 @@ -409,6 +541,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
101824
101825 /* newflags >> 4 shift VM_MAY% in place of VM_% */
101826 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
101827 + if (prot & (PROT_WRITE | PROT_EXEC))
101828 + gr_log_rwxmprotect(vma);
101829 +
101830 + error = -EACCES;
101831 + goto out;
101832 + }
101833 +
101834 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
101835 error = -EACCES;
101836 goto out;
101837 }
101838 @@ -423,6 +563,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
101839 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
101840 if (error)
101841 goto out;
101842 +
101843 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
101844 +
101845 nstart = tmp;
101846
101847 if (nstart < prev->vm_end)
101848 diff --git a/mm/mremap.c b/mm/mremap.c
101849 index 05f1180..c3cde48 100644
101850 --- a/mm/mremap.c
101851 +++ b/mm/mremap.c
101852 @@ -144,6 +144,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
101853 continue;
101854 pte = ptep_get_and_clear(mm, old_addr, old_pte);
101855 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
101856 +
101857 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
101858 + if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
101859 + pte = pte_exprotect(pte);
101860 +#endif
101861 +
101862 pte = move_soft_dirty_pte(pte);
101863 set_pte_at(mm, new_addr, new_pte, pte);
101864 }
101865 @@ -344,6 +350,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
101866 if (is_vm_hugetlb_page(vma))
101867 goto Einval;
101868
101869 +#ifdef CONFIG_PAX_SEGMEXEC
101870 + if (pax_find_mirror_vma(vma))
101871 + goto Einval;
101872 +#endif
101873 +
101874 /* We can't remap across vm area boundaries */
101875 if (old_len > vma->vm_end - addr)
101876 goto Efault;
101877 @@ -399,20 +410,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
101878 unsigned long ret = -EINVAL;
101879 unsigned long charged = 0;
101880 unsigned long map_flags;
101881 + unsigned long pax_task_size = TASK_SIZE;
101882
101883 if (new_addr & ~PAGE_MASK)
101884 goto out;
101885
101886 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
101887 +#ifdef CONFIG_PAX_SEGMEXEC
101888 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
101889 + pax_task_size = SEGMEXEC_TASK_SIZE;
101890 +#endif
101891 +
101892 + pax_task_size -= PAGE_SIZE;
101893 +
101894 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
101895 goto out;
101896
101897 /* Check if the location we're moving into overlaps the
101898 * old location at all, and fail if it does.
101899 */
101900 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
101901 - goto out;
101902 -
101903 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
101904 + if (addr + old_len > new_addr && new_addr + new_len > addr)
101905 goto out;
101906
101907 ret = do_munmap(mm, new_addr, new_len);
101908 @@ -481,6 +497,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
101909 unsigned long ret = -EINVAL;
101910 unsigned long charged = 0;
101911 bool locked = false;
101912 + unsigned long pax_task_size = TASK_SIZE;
101913
101914 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
101915 return ret;
101916 @@ -502,6 +519,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
101917 if (!new_len)
101918 return ret;
101919
101920 +#ifdef CONFIG_PAX_SEGMEXEC
101921 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
101922 + pax_task_size = SEGMEXEC_TASK_SIZE;
101923 +#endif
101924 +
101925 + pax_task_size -= PAGE_SIZE;
101926 +
101927 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
101928 + old_len > pax_task_size || addr > pax_task_size-old_len)
101929 + return ret;
101930 +
101931 down_write(&current->mm->mmap_sem);
101932
101933 if (flags & MREMAP_FIXED) {
101934 @@ -552,6 +580,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
101935 new_addr = addr;
101936 }
101937 ret = addr;
101938 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
101939 goto out;
101940 }
101941 }
101942 @@ -575,7 +604,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
101943 goto out;
101944 }
101945
101946 + map_flags = vma->vm_flags;
101947 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
101948 + if (!(ret & ~PAGE_MASK)) {
101949 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
101950 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
101951 + }
101952 }
101953 out:
101954 if (ret & ~PAGE_MASK)
101955 diff --git a/mm/nommu.c b/mm/nommu.c
101956 index 4a852f6..4371a6b 100644
101957 --- a/mm/nommu.c
101958 +++ b/mm/nommu.c
101959 @@ -70,7 +70,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
101960 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
101961 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
101962 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
101963 -int heap_stack_gap = 0;
101964
101965 atomic_long_t mmap_pages_allocated;
101966
101967 @@ -857,15 +856,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
101968 EXPORT_SYMBOL(find_vma);
101969
101970 /*
101971 - * find a VMA
101972 - * - we don't extend stack VMAs under NOMMU conditions
101973 - */
101974 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
101975 -{
101976 - return find_vma(mm, addr);
101977 -}
101978 -
101979 -/*
101980 * expand a stack to a given address
101981 * - not supported under NOMMU conditions
101982 */
101983 @@ -1572,6 +1562,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
101984
101985 /* most fields are the same, copy all, and then fixup */
101986 *new = *vma;
101987 + INIT_LIST_HEAD(&new->anon_vma_chain);
101988 *region = *vma->vm_region;
101989 new->vm_region = region;
101990
101991 @@ -2007,8 +1998,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
101992 }
101993 EXPORT_SYMBOL(generic_file_remap_pages);
101994
101995 -static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
101996 - unsigned long addr, void *buf, int len, int write)
101997 +static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
101998 + unsigned long addr, void *buf, size_t len, int write)
101999 {
102000 struct vm_area_struct *vma;
102001
102002 @@ -2049,8 +2040,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
102003 *
102004 * The caller must hold a reference on @mm.
102005 */
102006 -int access_remote_vm(struct mm_struct *mm, unsigned long addr,
102007 - void *buf, int len, int write)
102008 +ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
102009 + void *buf, size_t len, int write)
102010 {
102011 return __access_remote_vm(NULL, mm, addr, buf, len, write);
102012 }
102013 @@ -2059,7 +2050,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
102014 * Access another process' address space.
102015 * - source/target buffer must be kernel space
102016 */
102017 -int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
102018 +ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
102019 {
102020 struct mm_struct *mm;
102021
102022 diff --git a/mm/page-writeback.c b/mm/page-writeback.c
102023 index e0c9430..3c6bf79 100644
102024 --- a/mm/page-writeback.c
102025 +++ b/mm/page-writeback.c
102026 @@ -667,7 +667,7 @@ static long long pos_ratio_polynom(unsigned long setpoint,
102027 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
102028 * - the bdi dirty thresh drops quickly due to change of JBOD workload
102029 */
102030 -static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
102031 +static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
102032 unsigned long thresh,
102033 unsigned long bg_thresh,
102034 unsigned long dirty,
102035 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
102036 index ef44ad7..1056bc7 100644
102037 --- a/mm/page_alloc.c
102038 +++ b/mm/page_alloc.c
102039 @@ -61,6 +61,7 @@
102040 #include <linux/page-debug-flags.h>
102041 #include <linux/hugetlb.h>
102042 #include <linux/sched/rt.h>
102043 +#include <linux/random.h>
102044
102045 #include <asm/sections.h>
102046 #include <asm/tlbflush.h>
102047 @@ -357,7 +358,7 @@ out:
102048 * This usage means that zero-order pages may not be compound.
102049 */
102050
102051 -static void free_compound_page(struct page *page)
102052 +void free_compound_page(struct page *page)
102053 {
102054 __free_pages_ok(page, compound_order(page));
102055 }
102056 @@ -745,6 +746,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
102057 int i;
102058 int bad = 0;
102059
102060 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
102061 + unsigned long index = 1UL << order;
102062 +#endif
102063 +
102064 trace_mm_page_free(page, order);
102065 kmemcheck_free_shadow(page, order);
102066
102067 @@ -761,6 +766,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
102068 debug_check_no_obj_freed(page_address(page),
102069 PAGE_SIZE << order);
102070 }
102071 +
102072 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
102073 + for (; index; --index)
102074 + sanitize_highpage(page + index - 1);
102075 +#endif
102076 +
102077 arch_free_page(page, order);
102078 kernel_map_pages(page, 1 << order, 0);
102079
102080 @@ -784,6 +795,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
102081 local_irq_restore(flags);
102082 }
102083
102084 +#ifdef CONFIG_PAX_LATENT_ENTROPY
102085 +bool __meminitdata extra_latent_entropy;
102086 +
102087 +static int __init setup_pax_extra_latent_entropy(char *str)
102088 +{
102089 + extra_latent_entropy = true;
102090 + return 0;
102091 +}
102092 +early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
102093 +
102094 +volatile u64 latent_entropy __latent_entropy;
102095 +EXPORT_SYMBOL(latent_entropy);
102096 +#endif
102097 +
102098 void __init __free_pages_bootmem(struct page *page, unsigned int order)
102099 {
102100 unsigned int nr_pages = 1 << order;
102101 @@ -799,6 +824,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
102102 __ClearPageReserved(p);
102103 set_page_count(p, 0);
102104
102105 +#ifdef CONFIG_PAX_LATENT_ENTROPY
102106 + if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
102107 + u64 hash = 0;
102108 + size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
102109 + const u64 *data = lowmem_page_address(page);
102110 +
102111 + for (index = 0; index < end; index++)
102112 + hash ^= hash + data[index];
102113 + latent_entropy ^= hash;
102114 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
102115 + }
102116 +#endif
102117 +
102118 page_zone(page)->managed_pages += nr_pages;
102119 set_page_refcounted(page);
102120 __free_pages(page, order);
102121 @@ -927,8 +965,10 @@ static int prep_new_page(struct page *page, unsigned int order, gfp_t gfp_flags)
102122 arch_alloc_page(page, order);
102123 kernel_map_pages(page, 1 << order, 1);
102124
102125 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
102126 if (gfp_flags & __GFP_ZERO)
102127 prep_zero_page(page, order, gfp_flags);
102128 +#endif
102129
102130 if (order && (gfp_flags & __GFP_COMP))
102131 prep_compound_page(page, order);
102132 @@ -2427,7 +2467,7 @@ static void reset_alloc_batches(struct zonelist *zonelist,
102133 continue;
102134 mod_zone_page_state(zone, NR_ALLOC_BATCH,
102135 high_wmark_pages(zone) - low_wmark_pages(zone) -
102136 - atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]));
102137 + atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]));
102138 }
102139 }
102140
102141 diff --git a/mm/percpu.c b/mm/percpu.c
102142 index 2ddf9a9..f8fc075 100644
102143 --- a/mm/percpu.c
102144 +++ b/mm/percpu.c
102145 @@ -123,7 +123,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
102146 static unsigned int pcpu_high_unit_cpu __read_mostly;
102147
102148 /* the address of the first chunk which starts with the kernel static area */
102149 -void *pcpu_base_addr __read_mostly;
102150 +void *pcpu_base_addr __read_only;
102151 EXPORT_SYMBOL_GPL(pcpu_base_addr);
102152
102153 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
102154 diff --git a/mm/pgtable-generic.c b/mm/pgtable-generic.c
102155 index a8b9199..dfb79e0 100644
102156 --- a/mm/pgtable-generic.c
102157 +++ b/mm/pgtable-generic.c
102158 @@ -195,7 +195,7 @@ void pmdp_invalidate(struct vm_area_struct *vma, unsigned long address,
102159 pmd_t entry = *pmdp;
102160 if (pmd_numa(entry))
102161 entry = pmd_mknonnuma(entry);
102162 - set_pmd_at(vma->vm_mm, address, pmdp, pmd_mknotpresent(*pmdp));
102163 + set_pmd_at(vma->vm_mm, address, pmdp, pmd_mknotpresent(entry));
102164 flush_tlb_range(vma, address, address + HPAGE_PMD_SIZE);
102165 }
102166 #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
102167 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
102168 index 5077afc..846c9ef 100644
102169 --- a/mm/process_vm_access.c
102170 +++ b/mm/process_vm_access.c
102171 @@ -13,6 +13,7 @@
102172 #include <linux/uio.h>
102173 #include <linux/sched.h>
102174 #include <linux/highmem.h>
102175 +#include <linux/security.h>
102176 #include <linux/ptrace.h>
102177 #include <linux/slab.h>
102178 #include <linux/syscalls.h>
102179 @@ -157,19 +158,19 @@ static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter,
102180 ssize_t iov_len;
102181 size_t total_len = iov_iter_count(iter);
102182
102183 + return -ENOSYS; // PaX: until properly audited
102184 +
102185 /*
102186 * Work out how many pages of struct pages we're going to need
102187 * when eventually calling get_user_pages
102188 */
102189 for (i = 0; i < riovcnt; i++) {
102190 iov_len = rvec[i].iov_len;
102191 - if (iov_len > 0) {
102192 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
102193 - + iov_len)
102194 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
102195 - / PAGE_SIZE + 1;
102196 - nr_pages = max(nr_pages, nr_pages_iov);
102197 - }
102198 + if (iov_len <= 0)
102199 + continue;
102200 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
102201 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
102202 + nr_pages = max(nr_pages, nr_pages_iov);
102203 }
102204
102205 if (nr_pages == 0)
102206 @@ -197,6 +198,11 @@ static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter,
102207 goto free_proc_pages;
102208 }
102209
102210 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
102211 + rc = -EPERM;
102212 + goto put_task_struct;
102213 + }
102214 +
102215 mm = mm_access(task, PTRACE_MODE_ATTACH);
102216 if (!mm || IS_ERR(mm)) {
102217 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
102218 diff --git a/mm/rmap.c b/mm/rmap.c
102219 index 22a4a76..9551288 100644
102220 --- a/mm/rmap.c
102221 +++ b/mm/rmap.c
102222 @@ -164,6 +164,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
102223 struct anon_vma *anon_vma = vma->anon_vma;
102224 struct anon_vma_chain *avc;
102225
102226 +#ifdef CONFIG_PAX_SEGMEXEC
102227 + struct anon_vma_chain *avc_m = NULL;
102228 +#endif
102229 +
102230 might_sleep();
102231 if (unlikely(!anon_vma)) {
102232 struct mm_struct *mm = vma->vm_mm;
102233 @@ -173,6 +177,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
102234 if (!avc)
102235 goto out_enomem;
102236
102237 +#ifdef CONFIG_PAX_SEGMEXEC
102238 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
102239 + if (!avc_m)
102240 + goto out_enomem_free_avc;
102241 +#endif
102242 +
102243 anon_vma = find_mergeable_anon_vma(vma);
102244 allocated = NULL;
102245 if (!anon_vma) {
102246 @@ -186,6 +196,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
102247 /* page_table_lock to protect against threads */
102248 spin_lock(&mm->page_table_lock);
102249 if (likely(!vma->anon_vma)) {
102250 +
102251 +#ifdef CONFIG_PAX_SEGMEXEC
102252 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
102253 +
102254 + if (vma_m) {
102255 + BUG_ON(vma_m->anon_vma);
102256 + vma_m->anon_vma = anon_vma;
102257 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
102258 + avc_m = NULL;
102259 + }
102260 +#endif
102261 +
102262 vma->anon_vma = anon_vma;
102263 anon_vma_chain_link(vma, avc, anon_vma);
102264 allocated = NULL;
102265 @@ -196,12 +218,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
102266
102267 if (unlikely(allocated))
102268 put_anon_vma(allocated);
102269 +
102270 +#ifdef CONFIG_PAX_SEGMEXEC
102271 + if (unlikely(avc_m))
102272 + anon_vma_chain_free(avc_m);
102273 +#endif
102274 +
102275 if (unlikely(avc))
102276 anon_vma_chain_free(avc);
102277 }
102278 return 0;
102279
102280 out_enomem_free_avc:
102281 +
102282 +#ifdef CONFIG_PAX_SEGMEXEC
102283 + if (avc_m)
102284 + anon_vma_chain_free(avc_m);
102285 +#endif
102286 +
102287 anon_vma_chain_free(avc);
102288 out_enomem:
102289 return -ENOMEM;
102290 @@ -237,7 +271,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
102291 * Attach the anon_vmas from src to dst.
102292 * Returns 0 on success, -ENOMEM on failure.
102293 */
102294 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
102295 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
102296 {
102297 struct anon_vma_chain *avc, *pavc;
102298 struct anon_vma *root = NULL;
102299 @@ -270,7 +304,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
102300 * the corresponding VMA in the parent process is attached to.
102301 * Returns 0 on success, non-zero on failure.
102302 */
102303 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
102304 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
102305 {
102306 struct anon_vma_chain *avc;
102307 struct anon_vma *anon_vma;
102308 @@ -374,8 +408,10 @@ static void anon_vma_ctor(void *data)
102309 void __init anon_vma_init(void)
102310 {
102311 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
102312 - 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
102313 - anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
102314 + 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
102315 + anon_vma_ctor);
102316 + anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
102317 + SLAB_PANIC|SLAB_NO_SANITIZE);
102318 }
102319
102320 /*
102321 diff --git a/mm/shmem.c b/mm/shmem.c
102322 index af68b15..1227320 100644
102323 --- a/mm/shmem.c
102324 +++ b/mm/shmem.c
102325 @@ -33,7 +33,7 @@
102326 #include <linux/swap.h>
102327 #include <linux/aio.h>
102328
102329 -static struct vfsmount *shm_mnt;
102330 +struct vfsmount *shm_mnt;
102331
102332 #ifdef CONFIG_SHMEM
102333 /*
102334 @@ -77,7 +77,7 @@ static struct vfsmount *shm_mnt;
102335 #define BOGO_DIRENT_SIZE 20
102336
102337 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
102338 -#define SHORT_SYMLINK_LEN 128
102339 +#define SHORT_SYMLINK_LEN 64
102340
102341 /*
102342 * shmem_fallocate communicates with shmem_fault or shmem_writepage via
102343 @@ -2219,6 +2219,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
102344 static int shmem_xattr_validate(const char *name)
102345 {
102346 struct { const char *prefix; size_t len; } arr[] = {
102347 +
102348 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
102349 + { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
102350 +#endif
102351 +
102352 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
102353 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
102354 };
102355 @@ -2274,6 +2279,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
102356 if (err)
102357 return err;
102358
102359 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
102360 + if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
102361 + if (strcmp(name, XATTR_NAME_PAX_FLAGS))
102362 + return -EOPNOTSUPP;
102363 + if (size > 8)
102364 + return -EINVAL;
102365 + }
102366 +#endif
102367 +
102368 return simple_xattr_set(&info->xattrs, name, value, size, flags);
102369 }
102370
102371 @@ -2586,8 +2600,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
102372 int err = -ENOMEM;
102373
102374 /* Round up to L1_CACHE_BYTES to resist false sharing */
102375 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
102376 - L1_CACHE_BYTES), GFP_KERNEL);
102377 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
102378 if (!sbinfo)
102379 return -ENOMEM;
102380
102381 diff --git a/mm/slab.c b/mm/slab.c
102382 index 3070b92..bcfff83 100644
102383 --- a/mm/slab.c
102384 +++ b/mm/slab.c
102385 @@ -311,10 +311,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
102386 if ((x)->max_freeable < i) \
102387 (x)->max_freeable = i; \
102388 } while (0)
102389 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
102390 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
102391 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
102392 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
102393 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
102394 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
102395 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
102396 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
102397 +#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
102398 +#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
102399 #else
102400 #define STATS_INC_ACTIVE(x) do { } while (0)
102401 #define STATS_DEC_ACTIVE(x) do { } while (0)
102402 @@ -331,6 +333,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
102403 #define STATS_INC_ALLOCMISS(x) do { } while (0)
102404 #define STATS_INC_FREEHIT(x) do { } while (0)
102405 #define STATS_INC_FREEMISS(x) do { } while (0)
102406 +#define STATS_INC_SANITIZED(x) do { } while (0)
102407 +#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
102408 #endif
102409
102410 #if DEBUG
102411 @@ -447,7 +451,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct page *page,
102412 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
102413 */
102414 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
102415 - const struct page *page, void *obj)
102416 + const struct page *page, const void *obj)
102417 {
102418 u32 offset = (obj - page->s_mem);
102419 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
102420 @@ -1558,12 +1562,12 @@ void __init kmem_cache_init(void)
102421 */
102422
102423 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
102424 - kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
102425 + kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
102426
102427 if (INDEX_AC != INDEX_NODE)
102428 kmalloc_caches[INDEX_NODE] =
102429 create_kmalloc_cache("kmalloc-node",
102430 - kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
102431 + kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
102432
102433 slab_early_init = 0;
102434
102435 @@ -3512,6 +3516,21 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
102436 struct array_cache *ac = cpu_cache_get(cachep);
102437
102438 check_irq_off();
102439 +
102440 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
102441 + if (pax_sanitize_slab) {
102442 + if (!(cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))) {
102443 + memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
102444 +
102445 + if (cachep->ctor)
102446 + cachep->ctor(objp);
102447 +
102448 + STATS_INC_SANITIZED(cachep);
102449 + } else
102450 + STATS_INC_NOT_SANITIZED(cachep);
102451 + }
102452 +#endif
102453 +
102454 kmemleak_free_recursive(objp, cachep->flags);
102455 objp = cache_free_debugcheck(cachep, objp, caller);
102456
102457 @@ -3735,6 +3754,7 @@ void kfree(const void *objp)
102458
102459 if (unlikely(ZERO_OR_NULL_PTR(objp)))
102460 return;
102461 + VM_BUG_ON(!virt_addr_valid(objp));
102462 local_irq_save(flags);
102463 kfree_debugcheck(objp);
102464 c = virt_to_cache(objp);
102465 @@ -4176,14 +4196,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
102466 }
102467 /* cpu stats */
102468 {
102469 - unsigned long allochit = atomic_read(&cachep->allochit);
102470 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
102471 - unsigned long freehit = atomic_read(&cachep->freehit);
102472 - unsigned long freemiss = atomic_read(&cachep->freemiss);
102473 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
102474 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
102475 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
102476 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
102477
102478 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
102479 allochit, allocmiss, freehit, freemiss);
102480 }
102481 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
102482 + {
102483 + unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
102484 + unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
102485 +
102486 + seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
102487 + }
102488 +#endif
102489 #endif
102490 }
102491
102492 @@ -4404,13 +4432,69 @@ static const struct file_operations proc_slabstats_operations = {
102493 static int __init slab_proc_init(void)
102494 {
102495 #ifdef CONFIG_DEBUG_SLAB_LEAK
102496 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
102497 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
102498 #endif
102499 return 0;
102500 }
102501 module_init(slab_proc_init);
102502 #endif
102503
102504 +bool is_usercopy_object(const void *ptr)
102505 +{
102506 + struct page *page;
102507 + struct kmem_cache *cachep;
102508 +
102509 + if (ZERO_OR_NULL_PTR(ptr))
102510 + return false;
102511 +
102512 + if (!slab_is_available())
102513 + return false;
102514 +
102515 + if (!virt_addr_valid(ptr))
102516 + return false;
102517 +
102518 + page = virt_to_head_page(ptr);
102519 +
102520 + if (!PageSlab(page))
102521 + return false;
102522 +
102523 + cachep = page->slab_cache;
102524 + return cachep->flags & SLAB_USERCOPY;
102525 +}
102526 +
102527 +#ifdef CONFIG_PAX_USERCOPY
102528 +const char *check_heap_object(const void *ptr, unsigned long n)
102529 +{
102530 + struct page *page;
102531 + struct kmem_cache *cachep;
102532 + unsigned int objnr;
102533 + unsigned long offset;
102534 +
102535 + if (ZERO_OR_NULL_PTR(ptr))
102536 + return "<null>";
102537 +
102538 + if (!virt_addr_valid(ptr))
102539 + return NULL;
102540 +
102541 + page = virt_to_head_page(ptr);
102542 +
102543 + if (!PageSlab(page))
102544 + return NULL;
102545 +
102546 + cachep = page->slab_cache;
102547 + if (!(cachep->flags & SLAB_USERCOPY))
102548 + return cachep->name;
102549 +
102550 + objnr = obj_to_index(cachep, page, ptr);
102551 + BUG_ON(objnr >= cachep->num);
102552 + offset = ptr - index_to_obj(cachep, page, objnr) - obj_offset(cachep);
102553 + if (offset <= cachep->object_size && n <= cachep->object_size - offset)
102554 + return NULL;
102555 +
102556 + return cachep->name;
102557 +}
102558 +#endif
102559 +
102560 /**
102561 * ksize - get the actual amount of memory allocated for a given object
102562 * @objp: Pointer to the object
102563 diff --git a/mm/slab.h b/mm/slab.h
102564 index 961a3fb..6b12514 100644
102565 --- a/mm/slab.h
102566 +++ b/mm/slab.h
102567 @@ -32,6 +32,15 @@ extern struct list_head slab_caches;
102568 /* The slab cache that manages slab cache information */
102569 extern struct kmem_cache *kmem_cache;
102570
102571 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
102572 +#ifdef CONFIG_X86_64
102573 +#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
102574 +#else
102575 +#define PAX_MEMORY_SANITIZE_VALUE '\xff'
102576 +#endif
102577 +extern bool pax_sanitize_slab;
102578 +#endif
102579 +
102580 unsigned long calculate_alignment(unsigned long flags,
102581 unsigned long align, unsigned long size);
102582
102583 @@ -67,7 +76,8 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
102584
102585 /* Legal flag mask for kmem_cache_create(), for various configurations */
102586 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
102587 - SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
102588 + SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
102589 + SLAB_USERCOPY | SLAB_NO_SANITIZE)
102590
102591 #if defined(CONFIG_DEBUG_SLAB)
102592 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
102593 @@ -251,6 +261,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
102594 return s;
102595
102596 page = virt_to_head_page(x);
102597 +
102598 + BUG_ON(!PageSlab(page));
102599 +
102600 cachep = page->slab_cache;
102601 if (slab_equal_or_root(cachep, s))
102602 return cachep;
102603 diff --git a/mm/slab_common.c b/mm/slab_common.c
102604 index d31c4ba..1121296 100644
102605 --- a/mm/slab_common.c
102606 +++ b/mm/slab_common.c
102607 @@ -23,11 +23,22 @@
102608
102609 #include "slab.h"
102610
102611 -enum slab_state slab_state;
102612 +enum slab_state slab_state __read_only;
102613 LIST_HEAD(slab_caches);
102614 DEFINE_MUTEX(slab_mutex);
102615 struct kmem_cache *kmem_cache;
102616
102617 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
102618 +bool pax_sanitize_slab __read_only = true;
102619 +static int __init pax_sanitize_slab_setup(char *str)
102620 +{
102621 + pax_sanitize_slab = !!simple_strtol(str, NULL, 0);
102622 + printk("%sabled PaX slab sanitization\n", pax_sanitize_slab ? "En" : "Dis");
102623 + return 1;
102624 +}
102625 +__setup("pax_sanitize_slab=", pax_sanitize_slab_setup);
102626 +#endif
102627 +
102628 #ifdef CONFIG_DEBUG_VM
102629 static int kmem_cache_sanity_check(const char *name, size_t size)
102630 {
102631 @@ -158,7 +169,7 @@ do_kmem_cache_create(char *name, size_t object_size, size_t size, size_t align,
102632 if (err)
102633 goto out_free_cache;
102634
102635 - s->refcount = 1;
102636 + atomic_set(&s->refcount, 1);
102637 list_add(&s->list, &slab_caches);
102638 out:
102639 if (err)
102640 @@ -339,8 +350,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
102641
102642 mutex_lock(&slab_mutex);
102643
102644 - s->refcount--;
102645 - if (s->refcount)
102646 + if (!atomic_dec_and_test(&s->refcount))
102647 goto out_unlock;
102648
102649 if (memcg_cleanup_cache_params(s) != 0)
102650 @@ -360,7 +370,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
102651 rcu_barrier();
102652
102653 memcg_free_cache_params(s);
102654 -#ifdef SLAB_SUPPORTS_SYSFS
102655 +#if defined(SLAB_SUPPORTS_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
102656 sysfs_slab_remove(s);
102657 #else
102658 slab_kmem_cache_release(s);
102659 @@ -416,7 +426,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
102660 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
102661 name, size, err);
102662
102663 - s->refcount = -1; /* Exempt from merging for now */
102664 + atomic_set(&s->refcount, -1); /* Exempt from merging for now */
102665 }
102666
102667 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
102668 @@ -429,7 +439,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
102669
102670 create_boot_cache(s, name, size, flags);
102671 list_add(&s->list, &slab_caches);
102672 - s->refcount = 1;
102673 + atomic_set(&s->refcount, 1);
102674 return s;
102675 }
102676
102677 @@ -441,6 +451,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
102678 EXPORT_SYMBOL(kmalloc_dma_caches);
102679 #endif
102680
102681 +#ifdef CONFIG_PAX_USERCOPY_SLABS
102682 +struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
102683 +EXPORT_SYMBOL(kmalloc_usercopy_caches);
102684 +#endif
102685 +
102686 /*
102687 * Conversion table for small slabs sizes / 8 to the index in the
102688 * kmalloc array. This is necessary for slabs < 192 since we have non power
102689 @@ -505,6 +520,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
102690 return kmalloc_dma_caches[index];
102691
102692 #endif
102693 +
102694 +#ifdef CONFIG_PAX_USERCOPY_SLABS
102695 + if (unlikely((flags & GFP_USERCOPY)))
102696 + return kmalloc_usercopy_caches[index];
102697 +
102698 +#endif
102699 +
102700 return kmalloc_caches[index];
102701 }
102702
102703 @@ -561,7 +583,7 @@ void __init create_kmalloc_caches(unsigned long flags)
102704 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
102705 if (!kmalloc_caches[i]) {
102706 kmalloc_caches[i] = create_kmalloc_cache(NULL,
102707 - 1 << i, flags);
102708 + 1 << i, SLAB_USERCOPY | flags);
102709 }
102710
102711 /*
102712 @@ -570,10 +592,10 @@ void __init create_kmalloc_caches(unsigned long flags)
102713 * earlier power of two caches
102714 */
102715 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
102716 - kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
102717 + kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
102718
102719 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
102720 - kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
102721 + kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
102722 }
102723
102724 /* Kmalloc array is now usable */
102725 @@ -606,6 +628,23 @@ void __init create_kmalloc_caches(unsigned long flags)
102726 }
102727 }
102728 #endif
102729 +
102730 +#ifdef CONFIG_PAX_USERCOPY_SLABS
102731 + for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
102732 + struct kmem_cache *s = kmalloc_caches[i];
102733 +
102734 + if (s) {
102735 + int size = kmalloc_size(i);
102736 + char *n = kasprintf(GFP_NOWAIT,
102737 + "usercopy-kmalloc-%d", size);
102738 +
102739 + BUG_ON(!n);
102740 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
102741 + size, SLAB_USERCOPY | flags);
102742 + }
102743 + }
102744 +#endif
102745 +
102746 }
102747 #endif /* !CONFIG_SLOB */
102748
102749 @@ -664,6 +703,9 @@ void print_slabinfo_header(struct seq_file *m)
102750 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
102751 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
102752 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
102753 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
102754 + seq_puts(m, " : pax <sanitized> <not_sanitized>");
102755 +#endif
102756 #endif
102757 seq_putc(m, '\n');
102758 }
102759 diff --git a/mm/slob.c b/mm/slob.c
102760 index 21980e0..ed9a648 100644
102761 --- a/mm/slob.c
102762 +++ b/mm/slob.c
102763 @@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
102764 /*
102765 * Return the size of a slob block.
102766 */
102767 -static slobidx_t slob_units(slob_t *s)
102768 +static slobidx_t slob_units(const slob_t *s)
102769 {
102770 if (s->units > 0)
102771 return s->units;
102772 @@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
102773 /*
102774 * Return the next free slob block pointer after this one.
102775 */
102776 -static slob_t *slob_next(slob_t *s)
102777 +static slob_t *slob_next(const slob_t *s)
102778 {
102779 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
102780 slobidx_t next;
102781 @@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
102782 /*
102783 * Returns true if s is the last free block in its page.
102784 */
102785 -static int slob_last(slob_t *s)
102786 +static int slob_last(const slob_t *s)
102787 {
102788 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
102789 }
102790
102791 -static void *slob_new_pages(gfp_t gfp, int order, int node)
102792 +static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
102793 {
102794 - void *page;
102795 + struct page *page;
102796
102797 #ifdef CONFIG_NUMA
102798 if (node != NUMA_NO_NODE)
102799 @@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
102800 if (!page)
102801 return NULL;
102802
102803 - return page_address(page);
102804 + __SetPageSlab(page);
102805 + return page;
102806 }
102807
102808 -static void slob_free_pages(void *b, int order)
102809 +static void slob_free_pages(struct page *sp, int order)
102810 {
102811 if (current->reclaim_state)
102812 current->reclaim_state->reclaimed_slab += 1 << order;
102813 - free_pages((unsigned long)b, order);
102814 + __ClearPageSlab(sp);
102815 + page_mapcount_reset(sp);
102816 + sp->private = 0;
102817 + __free_pages(sp, order);
102818 }
102819
102820 /*
102821 @@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
102822
102823 /* Not enough space: must allocate a new page */
102824 if (!b) {
102825 - b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
102826 - if (!b)
102827 + sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
102828 + if (!sp)
102829 return NULL;
102830 - sp = virt_to_page(b);
102831 - __SetPageSlab(sp);
102832 + b = page_address(sp);
102833
102834 spin_lock_irqsave(&slob_lock, flags);
102835 sp->units = SLOB_UNITS(PAGE_SIZE);
102836 sp->freelist = b;
102837 + sp->private = 0;
102838 INIT_LIST_HEAD(&sp->lru);
102839 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
102840 set_slob_page_free(sp, slob_list);
102841 @@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
102842 if (slob_page_free(sp))
102843 clear_slob_page_free(sp);
102844 spin_unlock_irqrestore(&slob_lock, flags);
102845 - __ClearPageSlab(sp);
102846 - page_mapcount_reset(sp);
102847 - slob_free_pages(b, 0);
102848 + slob_free_pages(sp, 0);
102849 return;
102850 }
102851
102852 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
102853 + if (pax_sanitize_slab)
102854 + memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
102855 +#endif
102856 +
102857 if (!slob_page_free(sp)) {
102858 /* This slob page is about to become partially free. Easy! */
102859 sp->units = units;
102860 @@ -424,11 +431,10 @@ out:
102861 */
102862
102863 static __always_inline void *
102864 -__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
102865 +__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
102866 {
102867 - unsigned int *m;
102868 - int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
102869 - void *ret;
102870 + slob_t *m;
102871 + void *ret = NULL;
102872
102873 gfp &= gfp_allowed_mask;
102874
102875 @@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
102876
102877 if (!m)
102878 return NULL;
102879 - *m = size;
102880 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
102881 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
102882 + m[0].units = size;
102883 + m[1].units = align;
102884 ret = (void *)m + align;
102885
102886 trace_kmalloc_node(caller, ret,
102887 size, size + align, gfp, node);
102888 } else {
102889 unsigned int order = get_order(size);
102890 + struct page *page;
102891
102892 if (likely(order))
102893 gfp |= __GFP_COMP;
102894 - ret = slob_new_pages(gfp, order, node);
102895 + page = slob_new_pages(gfp, order, node);
102896 + if (page) {
102897 + ret = page_address(page);
102898 + page->private = size;
102899 + }
102900
102901 trace_kmalloc_node(caller, ret,
102902 size, PAGE_SIZE << order, gfp, node);
102903 }
102904
102905 - kmemleak_alloc(ret, size, 1, gfp);
102906 + return ret;
102907 +}
102908 +
102909 +static __always_inline void *
102910 +__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
102911 +{
102912 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
102913 + void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
102914 +
102915 + if (!ZERO_OR_NULL_PTR(ret))
102916 + kmemleak_alloc(ret, size, 1, gfp);
102917 return ret;
102918 }
102919
102920 @@ -493,34 +517,112 @@ void kfree(const void *block)
102921 return;
102922 kmemleak_free(block);
102923
102924 + VM_BUG_ON(!virt_addr_valid(block));
102925 sp = virt_to_page(block);
102926 - if (PageSlab(sp)) {
102927 + VM_BUG_ON(!PageSlab(sp));
102928 + if (!sp->private) {
102929 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
102930 - unsigned int *m = (unsigned int *)(block - align);
102931 - slob_free(m, *m + align);
102932 - } else
102933 + slob_t *m = (slob_t *)(block - align);
102934 + slob_free(m, m[0].units + align);
102935 + } else {
102936 + __ClearPageSlab(sp);
102937 + page_mapcount_reset(sp);
102938 + sp->private = 0;
102939 __free_pages(sp, compound_order(sp));
102940 + }
102941 }
102942 EXPORT_SYMBOL(kfree);
102943
102944 +bool is_usercopy_object(const void *ptr)
102945 +{
102946 + if (!slab_is_available())
102947 + return false;
102948 +
102949 + // PAX: TODO
102950 +
102951 + return false;
102952 +}
102953 +
102954 +#ifdef CONFIG_PAX_USERCOPY
102955 +const char *check_heap_object(const void *ptr, unsigned long n)
102956 +{
102957 + struct page *page;
102958 + const slob_t *free;
102959 + const void *base;
102960 + unsigned long flags;
102961 +
102962 + if (ZERO_OR_NULL_PTR(ptr))
102963 + return "<null>";
102964 +
102965 + if (!virt_addr_valid(ptr))
102966 + return NULL;
102967 +
102968 + page = virt_to_head_page(ptr);
102969 + if (!PageSlab(page))
102970 + return NULL;
102971 +
102972 + if (page->private) {
102973 + base = page;
102974 + if (base <= ptr && n <= page->private - (ptr - base))
102975 + return NULL;
102976 + return "<slob>";
102977 + }
102978 +
102979 + /* some tricky double walking to find the chunk */
102980 + spin_lock_irqsave(&slob_lock, flags);
102981 + base = (void *)((unsigned long)ptr & PAGE_MASK);
102982 + free = page->freelist;
102983 +
102984 + while (!slob_last(free) && (void *)free <= ptr) {
102985 + base = free + slob_units(free);
102986 + free = slob_next(free);
102987 + }
102988 +
102989 + while (base < (void *)free) {
102990 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
102991 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
102992 + int offset;
102993 +
102994 + if (ptr < base + align)
102995 + break;
102996 +
102997 + offset = ptr - base - align;
102998 + if (offset >= m) {
102999 + base += size;
103000 + continue;
103001 + }
103002 +
103003 + if (n > m - offset)
103004 + break;
103005 +
103006 + spin_unlock_irqrestore(&slob_lock, flags);
103007 + return NULL;
103008 + }
103009 +
103010 + spin_unlock_irqrestore(&slob_lock, flags);
103011 + return "<slob>";
103012 +}
103013 +#endif
103014 +
103015 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
103016 size_t ksize(const void *block)
103017 {
103018 struct page *sp;
103019 int align;
103020 - unsigned int *m;
103021 + slob_t *m;
103022
103023 BUG_ON(!block);
103024 if (unlikely(block == ZERO_SIZE_PTR))
103025 return 0;
103026
103027 sp = virt_to_page(block);
103028 - if (unlikely(!PageSlab(sp)))
103029 - return PAGE_SIZE << compound_order(sp);
103030 + VM_BUG_ON(!PageSlab(sp));
103031 + if (sp->private)
103032 + return sp->private;
103033
103034 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
103035 - m = (unsigned int *)(block - align);
103036 - return SLOB_UNITS(*m) * SLOB_UNIT;
103037 + m = (slob_t *)(block - align);
103038 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
103039 }
103040 EXPORT_SYMBOL(ksize);
103041
103042 @@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
103043
103044 void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
103045 {
103046 - void *b;
103047 + void *b = NULL;
103048
103049 flags &= gfp_allowed_mask;
103050
103051 lockdep_trace_alloc(flags);
103052
103053 +#ifdef CONFIG_PAX_USERCOPY_SLABS
103054 + b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
103055 +#else
103056 if (c->size < PAGE_SIZE) {
103057 b = slob_alloc(c->size, flags, c->align, node);
103058 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
103059 SLOB_UNITS(c->size) * SLOB_UNIT,
103060 flags, node);
103061 } else {
103062 - b = slob_new_pages(flags, get_order(c->size), node);
103063 + struct page *sp;
103064 +
103065 + sp = slob_new_pages(flags, get_order(c->size), node);
103066 + if (sp) {
103067 + b = page_address(sp);
103068 + sp->private = c->size;
103069 + }
103070 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
103071 PAGE_SIZE << get_order(c->size),
103072 flags, node);
103073 }
103074 +#endif
103075
103076 if (b && c->ctor)
103077 c->ctor(b);
103078 @@ -584,10 +696,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
103079
103080 static void __kmem_cache_free(void *b, int size)
103081 {
103082 - if (size < PAGE_SIZE)
103083 + struct page *sp;
103084 +
103085 + sp = virt_to_page(b);
103086 + BUG_ON(!PageSlab(sp));
103087 + if (!sp->private)
103088 slob_free(b, size);
103089 else
103090 - slob_free_pages(b, get_order(size));
103091 + slob_free_pages(sp, get_order(size));
103092 }
103093
103094 static void kmem_rcu_free(struct rcu_head *head)
103095 @@ -600,17 +716,31 @@ static void kmem_rcu_free(struct rcu_head *head)
103096
103097 void kmem_cache_free(struct kmem_cache *c, void *b)
103098 {
103099 + int size = c->size;
103100 +
103101 +#ifdef CONFIG_PAX_USERCOPY_SLABS
103102 + if (size + c->align < PAGE_SIZE) {
103103 + size += c->align;
103104 + b -= c->align;
103105 + }
103106 +#endif
103107 +
103108 kmemleak_free_recursive(b, c->flags);
103109 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
103110 struct slob_rcu *slob_rcu;
103111 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
103112 - slob_rcu->size = c->size;
103113 + slob_rcu = b + (size - sizeof(struct slob_rcu));
103114 + slob_rcu->size = size;
103115 call_rcu(&slob_rcu->head, kmem_rcu_free);
103116 } else {
103117 - __kmem_cache_free(b, c->size);
103118 + __kmem_cache_free(b, size);
103119 }
103120
103121 +#ifdef CONFIG_PAX_USERCOPY_SLABS
103122 + trace_kfree(_RET_IP_, b);
103123 +#else
103124 trace_kmem_cache_free(_RET_IP_, b);
103125 +#endif
103126 +
103127 }
103128 EXPORT_SYMBOL(kmem_cache_free);
103129
103130 diff --git a/mm/slub.c b/mm/slub.c
103131 index 7300480..cb92846 100644
103132 --- a/mm/slub.c
103133 +++ b/mm/slub.c
103134 @@ -207,7 +207,7 @@ struct track {
103135
103136 enum track_item { TRACK_ALLOC, TRACK_FREE };
103137
103138 -#ifdef CONFIG_SYSFS
103139 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
103140 static int sysfs_slab_add(struct kmem_cache *);
103141 static int sysfs_slab_alias(struct kmem_cache *, const char *);
103142 static void memcg_propagate_slab_attrs(struct kmem_cache *s);
103143 @@ -546,7 +546,7 @@ static void print_track(const char *s, struct track *t)
103144 if (!t->addr)
103145 return;
103146
103147 - pr_err("INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
103148 + pr_err("INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
103149 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
103150 #ifdef CONFIG_STACKTRACE
103151 {
103152 @@ -2673,6 +2673,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
103153
103154 slab_free_hook(s, x);
103155
103156 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
103157 + if (pax_sanitize_slab && !(s->flags & SLAB_NO_SANITIZE)) {
103158 + memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
103159 + if (s->ctor)
103160 + s->ctor(x);
103161 + }
103162 +#endif
103163 +
103164 redo:
103165 /*
103166 * Determine the currently cpus per cpu slab.
103167 @@ -2740,7 +2748,7 @@ static int slub_min_objects;
103168 * Merge control. If this is set then no merging of slab caches will occur.
103169 * (Could be removed. This was introduced to pacify the merge skeptics.)
103170 */
103171 -static int slub_nomerge;
103172 +static int slub_nomerge = 1;
103173
103174 /*
103175 * Calculate the order of allocation given an slab object size.
103176 @@ -3019,6 +3027,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
103177 s->inuse = size;
103178
103179 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
103180 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
103181 + (pax_sanitize_slab && !(flags & SLAB_NO_SANITIZE)) ||
103182 +#endif
103183 s->ctor)) {
103184 /*
103185 * Relocate free pointer after the object if it is not
103186 @@ -3347,6 +3358,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
103187 EXPORT_SYMBOL(__kmalloc_node);
103188 #endif
103189
103190 +bool is_usercopy_object(const void *ptr)
103191 +{
103192 + struct page *page;
103193 + struct kmem_cache *s;
103194 +
103195 + if (ZERO_OR_NULL_PTR(ptr))
103196 + return false;
103197 +
103198 + if (!slab_is_available())
103199 + return false;
103200 +
103201 + if (!virt_addr_valid(ptr))
103202 + return false;
103203 +
103204 + page = virt_to_head_page(ptr);
103205 +
103206 + if (!PageSlab(page))
103207 + return false;
103208 +
103209 + s = page->slab_cache;
103210 + return s->flags & SLAB_USERCOPY;
103211 +}
103212 +
103213 +#ifdef CONFIG_PAX_USERCOPY
103214 +const char *check_heap_object(const void *ptr, unsigned long n)
103215 +{
103216 + struct page *page;
103217 + struct kmem_cache *s;
103218 + unsigned long offset;
103219 +
103220 + if (ZERO_OR_NULL_PTR(ptr))
103221 + return "<null>";
103222 +
103223 + if (!virt_addr_valid(ptr))
103224 + return NULL;
103225 +
103226 + page = virt_to_head_page(ptr);
103227 +
103228 + if (!PageSlab(page))
103229 + return NULL;
103230 +
103231 + s = page->slab_cache;
103232 + if (!(s->flags & SLAB_USERCOPY))
103233 + return s->name;
103234 +
103235 + offset = (ptr - page_address(page)) % s->size;
103236 + if (offset <= s->object_size && n <= s->object_size - offset)
103237 + return NULL;
103238 +
103239 + return s->name;
103240 +}
103241 +#endif
103242 +
103243 size_t ksize(const void *object)
103244 {
103245 struct page *page;
103246 @@ -3375,6 +3439,7 @@ void kfree(const void *x)
103247 if (unlikely(ZERO_OR_NULL_PTR(x)))
103248 return;
103249
103250 + VM_BUG_ON(!virt_addr_valid(x));
103251 page = virt_to_head_page(x);
103252 if (unlikely(!PageSlab(page))) {
103253 BUG_ON(!PageCompound(page));
103254 @@ -3680,7 +3745,7 @@ static int slab_unmergeable(struct kmem_cache *s)
103255 /*
103256 * We may have set a slab to be unmergeable during bootstrap.
103257 */
103258 - if (s->refcount < 0)
103259 + if (atomic_read(&s->refcount) < 0)
103260 return 1;
103261
103262 return 0;
103263 @@ -3737,7 +3802,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
103264 int i;
103265 struct kmem_cache *c;
103266
103267 - s->refcount++;
103268 + atomic_inc(&s->refcount);
103269
103270 /*
103271 * Adjust the object sizes so that we clear
103272 @@ -3756,7 +3821,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
103273 }
103274
103275 if (sysfs_slab_alias(s, name)) {
103276 - s->refcount--;
103277 + atomic_dec(&s->refcount);
103278 s = NULL;
103279 }
103280 }
103281 @@ -3873,7 +3938,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
103282 }
103283 #endif
103284
103285 -#ifdef CONFIG_SYSFS
103286 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
103287 static int count_inuse(struct page *page)
103288 {
103289 return page->inuse;
103290 @@ -4156,7 +4221,11 @@ static int list_locations(struct kmem_cache *s, char *buf,
103291 len += sprintf(buf + len, "%7ld ", l->count);
103292
103293 if (l->addr)
103294 +#ifdef CONFIG_GRKERNSEC_HIDESYM
103295 + len += sprintf(buf + len, "%pS", NULL);
103296 +#else
103297 len += sprintf(buf + len, "%pS", (void *)l->addr);
103298 +#endif
103299 else
103300 len += sprintf(buf + len, "<not-available>");
103301
103302 @@ -4258,12 +4327,12 @@ static void resiliency_test(void)
103303 validate_slab_cache(kmalloc_caches[9]);
103304 }
103305 #else
103306 -#ifdef CONFIG_SYSFS
103307 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
103308 static void resiliency_test(void) {};
103309 #endif
103310 #endif
103311
103312 -#ifdef CONFIG_SYSFS
103313 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
103314 enum slab_stat_type {
103315 SL_ALL, /* All slabs */
103316 SL_PARTIAL, /* Only partially allocated slabs */
103317 @@ -4503,13 +4572,17 @@ static ssize_t ctor_show(struct kmem_cache *s, char *buf)
103318 {
103319 if (!s->ctor)
103320 return 0;
103321 +#ifdef CONFIG_GRKERNSEC_HIDESYM
103322 + return sprintf(buf, "%pS\n", NULL);
103323 +#else
103324 return sprintf(buf, "%pS\n", s->ctor);
103325 +#endif
103326 }
103327 SLAB_ATTR_RO(ctor);
103328
103329 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
103330 {
103331 - return sprintf(buf, "%d\n", s->refcount - 1);
103332 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
103333 }
103334 SLAB_ATTR_RO(aliases);
103335
103336 @@ -4597,6 +4670,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
103337 SLAB_ATTR_RO(cache_dma);
103338 #endif
103339
103340 +#ifdef CONFIG_PAX_USERCOPY_SLABS
103341 +static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
103342 +{
103343 + return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
103344 +}
103345 +SLAB_ATTR_RO(usercopy);
103346 +#endif
103347 +
103348 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
103349 {
103350 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
103351 @@ -4931,6 +5012,9 @@ static struct attribute *slab_attrs[] = {
103352 #ifdef CONFIG_ZONE_DMA
103353 &cache_dma_attr.attr,
103354 #endif
103355 +#ifdef CONFIG_PAX_USERCOPY_SLABS
103356 + &usercopy_attr.attr,
103357 +#endif
103358 #ifdef CONFIG_NUMA
103359 &remote_node_defrag_ratio_attr.attr,
103360 #endif
103361 @@ -5181,6 +5265,7 @@ static char *create_unique_id(struct kmem_cache *s)
103362 return name;
103363 }
103364
103365 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
103366 static int sysfs_slab_add(struct kmem_cache *s)
103367 {
103368 int err;
103369 @@ -5254,6 +5339,7 @@ void sysfs_slab_remove(struct kmem_cache *s)
103370 kobject_del(&s->kobj);
103371 kobject_put(&s->kobj);
103372 }
103373 +#endif
103374
103375 /*
103376 * Need to buffer aliases during bootup until sysfs becomes
103377 @@ -5267,6 +5353,7 @@ struct saved_alias {
103378
103379 static struct saved_alias *alias_list;
103380
103381 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
103382 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
103383 {
103384 struct saved_alias *al;
103385 @@ -5289,6 +5376,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
103386 alias_list = al;
103387 return 0;
103388 }
103389 +#endif
103390
103391 static int __init slab_sysfs_init(void)
103392 {
103393 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
103394 index 4cba9c2..b4f9fcc 100644
103395 --- a/mm/sparse-vmemmap.c
103396 +++ b/mm/sparse-vmemmap.c
103397 @@ -131,7 +131,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
103398 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
103399 if (!p)
103400 return NULL;
103401 - pud_populate(&init_mm, pud, p);
103402 + pud_populate_kernel(&init_mm, pud, p);
103403 }
103404 return pud;
103405 }
103406 @@ -143,7 +143,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
103407 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
103408 if (!p)
103409 return NULL;
103410 - pgd_populate(&init_mm, pgd, p);
103411 + pgd_populate_kernel(&init_mm, pgd, p);
103412 }
103413 return pgd;
103414 }
103415 diff --git a/mm/sparse.c b/mm/sparse.c
103416 index d1b48b6..6e8590e 100644
103417 --- a/mm/sparse.c
103418 +++ b/mm/sparse.c
103419 @@ -750,7 +750,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
103420
103421 for (i = 0; i < PAGES_PER_SECTION; i++) {
103422 if (PageHWPoison(&memmap[i])) {
103423 - atomic_long_sub(1, &num_poisoned_pages);
103424 + atomic_long_sub_unchecked(1, &num_poisoned_pages);
103425 ClearPageHWPoison(&memmap[i]);
103426 }
103427 }
103428 diff --git a/mm/swap.c b/mm/swap.c
103429 index 9e8e347..3c22e0f 100644
103430 --- a/mm/swap.c
103431 +++ b/mm/swap.c
103432 @@ -31,6 +31,7 @@
103433 #include <linux/memcontrol.h>
103434 #include <linux/gfp.h>
103435 #include <linux/uio.h>
103436 +#include <linux/hugetlb.h>
103437
103438 #include "internal.h"
103439
103440 @@ -76,6 +77,8 @@ static void __put_compound_page(struct page *page)
103441
103442 __page_cache_release(page);
103443 dtor = get_compound_page_dtor(page);
103444 + if (!PageHuge(page))
103445 + BUG_ON(dtor != free_compound_page);
103446 (*dtor)(page);
103447 }
103448
103449 diff --git a/mm/swapfile.c b/mm/swapfile.c
103450 index 4c524f7..f7601f17 100644
103451 --- a/mm/swapfile.c
103452 +++ b/mm/swapfile.c
103453 @@ -84,7 +84,7 @@ static DEFINE_MUTEX(swapon_mutex);
103454
103455 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
103456 /* Activity counter to indicate that a swapon or swapoff has occurred */
103457 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
103458 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
103459
103460 static inline unsigned char swap_count(unsigned char ent)
103461 {
103462 @@ -1945,7 +1945,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
103463 spin_unlock(&swap_lock);
103464
103465 err = 0;
103466 - atomic_inc(&proc_poll_event);
103467 + atomic_inc_unchecked(&proc_poll_event);
103468 wake_up_interruptible(&proc_poll_wait);
103469
103470 out_dput:
103471 @@ -1962,8 +1962,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
103472
103473 poll_wait(file, &proc_poll_wait, wait);
103474
103475 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
103476 - seq->poll_event = atomic_read(&proc_poll_event);
103477 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
103478 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
103479 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
103480 }
103481
103482 @@ -2061,7 +2061,7 @@ static int swaps_open(struct inode *inode, struct file *file)
103483 return ret;
103484
103485 seq = file->private_data;
103486 - seq->poll_event = atomic_read(&proc_poll_event);
103487 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
103488 return 0;
103489 }
103490
103491 @@ -2521,7 +2521,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
103492 (frontswap_map) ? "FS" : "");
103493
103494 mutex_unlock(&swapon_mutex);
103495 - atomic_inc(&proc_poll_event);
103496 + atomic_inc_unchecked(&proc_poll_event);
103497 wake_up_interruptible(&proc_poll_wait);
103498
103499 if (S_ISREG(inode->i_mode))
103500 diff --git a/mm/util.c b/mm/util.c
103501 index d5ea733..e8953f9 100644
103502 --- a/mm/util.c
103503 +++ b/mm/util.c
103504 @@ -299,6 +299,12 @@ done:
103505 void arch_pick_mmap_layout(struct mm_struct *mm)
103506 {
103507 mm->mmap_base = TASK_UNMAPPED_BASE;
103508 +
103509 +#ifdef CONFIG_PAX_RANDMMAP
103510 + if (mm->pax_flags & MF_PAX_RANDMMAP)
103511 + mm->mmap_base += mm->delta_mmap;
103512 +#endif
103513 +
103514 mm->get_unmapped_area = arch_get_unmapped_area;
103515 }
103516 #endif
103517 @@ -475,6 +481,9 @@ int get_cmdline(struct task_struct *task, char *buffer, int buflen)
103518 if (!mm->arg_end)
103519 goto out_mm; /* Shh! No looking before we're done */
103520
103521 + if (gr_acl_handle_procpidmem(task))
103522 + goto out_mm;
103523 +
103524 len = mm->arg_end - mm->arg_start;
103525
103526 if (len > buflen)
103527 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
103528 index f64632b..e8c52e7 100644
103529 --- a/mm/vmalloc.c
103530 +++ b/mm/vmalloc.c
103531 @@ -40,6 +40,21 @@ struct vfree_deferred {
103532 };
103533 static DEFINE_PER_CPU(struct vfree_deferred, vfree_deferred);
103534
103535 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
103536 +struct stack_deferred_llist {
103537 + struct llist_head list;
103538 + void *stack;
103539 + void *lowmem_stack;
103540 +};
103541 +
103542 +struct stack_deferred {
103543 + struct stack_deferred_llist list;
103544 + struct work_struct wq;
103545 +};
103546 +
103547 +static DEFINE_PER_CPU(struct stack_deferred, stack_deferred);
103548 +#endif
103549 +
103550 static void __vunmap(const void *, int);
103551
103552 static void free_work(struct work_struct *w)
103553 @@ -47,12 +62,30 @@ static void free_work(struct work_struct *w)
103554 struct vfree_deferred *p = container_of(w, struct vfree_deferred, wq);
103555 struct llist_node *llnode = llist_del_all(&p->list);
103556 while (llnode) {
103557 - void *p = llnode;
103558 + void *x = llnode;
103559 llnode = llist_next(llnode);
103560 - __vunmap(p, 1);
103561 + __vunmap(x, 1);
103562 }
103563 }
103564
103565 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
103566 +static void unmap_work(struct work_struct *w)
103567 +{
103568 + struct stack_deferred *p = container_of(w, struct stack_deferred, wq);
103569 + struct llist_node *llnode = llist_del_all(&p->list.list);
103570 + while (llnode) {
103571 + struct stack_deferred_llist *x =
103572 + llist_entry((struct llist_head *)llnode,
103573 + struct stack_deferred_llist, list);
103574 + void *stack = ACCESS_ONCE(x->stack);
103575 + void *lowmem_stack = ACCESS_ONCE(x->lowmem_stack);
103576 + llnode = llist_next(llnode);
103577 + __vunmap(stack, 0);
103578 + free_kmem_pages((unsigned long)lowmem_stack, THREAD_SIZE_ORDER);
103579 + }
103580 +}
103581 +#endif
103582 +
103583 /*** Page table manipulation functions ***/
103584
103585 static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
103586 @@ -61,8 +94,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
103587
103588 pte = pte_offset_kernel(pmd, addr);
103589 do {
103590 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
103591 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
103592 +
103593 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
103594 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
103595 + BUG_ON(!pte_exec(*pte));
103596 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
103597 + continue;
103598 + }
103599 +#endif
103600 +
103601 + {
103602 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
103603 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
103604 + }
103605 } while (pte++, addr += PAGE_SIZE, addr != end);
103606 }
103607
103608 @@ -122,16 +166,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
103609 pte = pte_alloc_kernel(pmd, addr);
103610 if (!pte)
103611 return -ENOMEM;
103612 +
103613 + pax_open_kernel();
103614 do {
103615 struct page *page = pages[*nr];
103616
103617 - if (WARN_ON(!pte_none(*pte)))
103618 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
103619 + if (pgprot_val(prot) & _PAGE_NX)
103620 +#endif
103621 +
103622 + if (!pte_none(*pte)) {
103623 + pax_close_kernel();
103624 + WARN_ON(1);
103625 return -EBUSY;
103626 - if (WARN_ON(!page))
103627 + }
103628 + if (!page) {
103629 + pax_close_kernel();
103630 + WARN_ON(1);
103631 return -ENOMEM;
103632 + }
103633 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
103634 (*nr)++;
103635 } while (pte++, addr += PAGE_SIZE, addr != end);
103636 + pax_close_kernel();
103637 return 0;
103638 }
103639
103640 @@ -141,7 +198,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
103641 pmd_t *pmd;
103642 unsigned long next;
103643
103644 - pmd = pmd_alloc(&init_mm, pud, addr);
103645 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
103646 if (!pmd)
103647 return -ENOMEM;
103648 do {
103649 @@ -158,7 +215,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
103650 pud_t *pud;
103651 unsigned long next;
103652
103653 - pud = pud_alloc(&init_mm, pgd, addr);
103654 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
103655 if (!pud)
103656 return -ENOMEM;
103657 do {
103658 @@ -218,6 +275,12 @@ int is_vmalloc_or_module_addr(const void *x)
103659 if (addr >= MODULES_VADDR && addr < MODULES_END)
103660 return 1;
103661 #endif
103662 +
103663 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
103664 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
103665 + return 1;
103666 +#endif
103667 +
103668 return is_vmalloc_addr(x);
103669 }
103670
103671 @@ -238,8 +301,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
103672
103673 if (!pgd_none(*pgd)) {
103674 pud_t *pud = pud_offset(pgd, addr);
103675 +#ifdef CONFIG_X86
103676 + if (!pud_large(*pud))
103677 +#endif
103678 if (!pud_none(*pud)) {
103679 pmd_t *pmd = pmd_offset(pud, addr);
103680 +#ifdef CONFIG_X86
103681 + if (!pmd_large(*pmd))
103682 +#endif
103683 if (!pmd_none(*pmd)) {
103684 pte_t *ptep, pte;
103685
103686 @@ -1183,13 +1252,23 @@ void __init vmalloc_init(void)
103687 for_each_possible_cpu(i) {
103688 struct vmap_block_queue *vbq;
103689 struct vfree_deferred *p;
103690 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
103691 + struct stack_deferred *p2;
103692 +#endif
103693
103694 vbq = &per_cpu(vmap_block_queue, i);
103695 spin_lock_init(&vbq->lock);
103696 INIT_LIST_HEAD(&vbq->free);
103697 +
103698 p = &per_cpu(vfree_deferred, i);
103699 init_llist_head(&p->list);
103700 INIT_WORK(&p->wq, free_work);
103701 +
103702 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
103703 + p2 = &per_cpu(stack_deferred, i);
103704 + init_llist_head(&p2->list.list);
103705 + INIT_WORK(&p2->wq, unmap_work);
103706 +#endif
103707 }
103708
103709 /* Import existing vmlist entries. */
103710 @@ -1318,6 +1397,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
103711 struct vm_struct *area;
103712
103713 BUG_ON(in_interrupt());
103714 +
103715 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
103716 + if (flags & VM_KERNEXEC) {
103717 + if (start != VMALLOC_START || end != VMALLOC_END)
103718 + return NULL;
103719 + start = (unsigned long)MODULES_EXEC_VADDR;
103720 + end = (unsigned long)MODULES_EXEC_END;
103721 + }
103722 +#endif
103723 +
103724 if (flags & VM_IOREMAP)
103725 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
103726
103727 @@ -1523,6 +1612,23 @@ void vunmap(const void *addr)
103728 }
103729 EXPORT_SYMBOL(vunmap);
103730
103731 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
103732 +void unmap_process_stacks(struct task_struct *task)
103733 +{
103734 + if (unlikely(in_interrupt())) {
103735 + struct stack_deferred *p = &__get_cpu_var(stack_deferred);
103736 + struct stack_deferred_llist *list = task->stack;
103737 + list->stack = task->stack;
103738 + list->lowmem_stack = task->lowmem_stack;
103739 + if (llist_add((struct llist_node *)&list->list, &p->list.list))
103740 + schedule_work(&p->wq);
103741 + } else {
103742 + __vunmap(task->stack, 0);
103743 + free_kmem_pages((unsigned long)task->lowmem_stack, THREAD_SIZE_ORDER);
103744 + }
103745 +}
103746 +#endif
103747 +
103748 /**
103749 * vmap - map an array of pages into virtually contiguous space
103750 * @pages: array of page pointers
103751 @@ -1543,6 +1649,11 @@ void *vmap(struct page **pages, unsigned int count,
103752 if (count > totalram_pages)
103753 return NULL;
103754
103755 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
103756 + if (!(pgprot_val(prot) & _PAGE_NX))
103757 + flags |= VM_KERNEXEC;
103758 +#endif
103759 +
103760 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
103761 __builtin_return_address(0));
103762 if (!area)
103763 @@ -1643,6 +1754,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
103764 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
103765 goto fail;
103766
103767 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
103768 + if (!(pgprot_val(prot) & _PAGE_NX))
103769 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
103770 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
103771 + else
103772 +#endif
103773 +
103774 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
103775 start, end, node, gfp_mask, caller);
103776 if (!area)
103777 @@ -1819,10 +1937,9 @@ EXPORT_SYMBOL(vzalloc_node);
103778 * For tight control over page level allocator and protection flags
103779 * use __vmalloc() instead.
103780 */
103781 -
103782 void *vmalloc_exec(unsigned long size)
103783 {
103784 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
103785 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
103786 NUMA_NO_NODE, __builtin_return_address(0));
103787 }
103788
103789 @@ -2129,6 +2246,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
103790 {
103791 struct vm_struct *area;
103792
103793 + BUG_ON(vma->vm_mirror);
103794 +
103795 size = PAGE_ALIGN(size);
103796
103797 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
103798 @@ -2611,7 +2730,11 @@ static int s_show(struct seq_file *m, void *p)
103799 v->addr, v->addr + v->size, v->size);
103800
103801 if (v->caller)
103802 +#ifdef CONFIG_GRKERNSEC_HIDESYM
103803 + seq_printf(m, " %pK", v->caller);
103804 +#else
103805 seq_printf(m, " %pS", v->caller);
103806 +#endif
103807
103808 if (v->nr_pages)
103809 seq_printf(m, " pages=%d", v->nr_pages);
103810 diff --git a/mm/vmstat.c b/mm/vmstat.c
103811 index b37bd49..4d7b3da 100644
103812 --- a/mm/vmstat.c
103813 +++ b/mm/vmstat.c
103814 @@ -20,6 +20,7 @@
103815 #include <linux/writeback.h>
103816 #include <linux/compaction.h>
103817 #include <linux/mm_inline.h>
103818 +#include <linux/grsecurity.h>
103819
103820 #include "internal.h"
103821
103822 @@ -79,7 +80,7 @@ void vm_events_fold_cpu(int cpu)
103823 *
103824 * vm_stat contains the global counters
103825 */
103826 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
103827 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
103828 EXPORT_SYMBOL(vm_stat);
103829
103830 #ifdef CONFIG_SMP
103831 @@ -425,7 +426,7 @@ static inline void fold_diff(int *diff)
103832
103833 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
103834 if (diff[i])
103835 - atomic_long_add(diff[i], &vm_stat[i]);
103836 + atomic_long_add_unchecked(diff[i], &vm_stat[i]);
103837 }
103838
103839 /*
103840 @@ -457,7 +458,7 @@ static void refresh_cpu_vm_stats(void)
103841 v = this_cpu_xchg(p->vm_stat_diff[i], 0);
103842 if (v) {
103843
103844 - atomic_long_add(v, &zone->vm_stat[i]);
103845 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
103846 global_diff[i] += v;
103847 #ifdef CONFIG_NUMA
103848 /* 3 seconds idle till flush */
103849 @@ -519,7 +520,7 @@ void cpu_vm_stats_fold(int cpu)
103850
103851 v = p->vm_stat_diff[i];
103852 p->vm_stat_diff[i] = 0;
103853 - atomic_long_add(v, &zone->vm_stat[i]);
103854 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
103855 global_diff[i] += v;
103856 }
103857 }
103858 @@ -539,8 +540,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
103859 if (pset->vm_stat_diff[i]) {
103860 int v = pset->vm_stat_diff[i];
103861 pset->vm_stat_diff[i] = 0;
103862 - atomic_long_add(v, &zone->vm_stat[i]);
103863 - atomic_long_add(v, &vm_stat[i]);
103864 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
103865 + atomic_long_add_unchecked(v, &vm_stat[i]);
103866 }
103867 }
103868 #endif
103869 @@ -1162,10 +1163,22 @@ static void *vmstat_start(struct seq_file *m, loff_t *pos)
103870 stat_items_size += sizeof(struct vm_event_state);
103871 #endif
103872
103873 - v = kmalloc(stat_items_size, GFP_KERNEL);
103874 + v = kzalloc(stat_items_size, GFP_KERNEL);
103875 m->private = v;
103876 if (!v)
103877 return ERR_PTR(-ENOMEM);
103878 +
103879 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
103880 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
103881 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
103882 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
103883 + && !in_group_p(grsec_proc_gid)
103884 +#endif
103885 + )
103886 + return (unsigned long *)m->private + *pos;
103887 +#endif
103888 +#endif
103889 +
103890 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
103891 v[i] = global_page_state(i);
103892 v += NR_VM_ZONE_STAT_ITEMS;
103893 @@ -1314,10 +1327,16 @@ static int __init setup_vmstat(void)
103894 cpu_notifier_register_done();
103895 #endif
103896 #ifdef CONFIG_PROC_FS
103897 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
103898 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
103899 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
103900 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
103901 + {
103902 + mode_t gr_mode = S_IRUGO;
103903 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
103904 + gr_mode = S_IRUSR;
103905 +#endif
103906 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
103907 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
103908 + proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
103909 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
103910 + }
103911 #endif
103912 return 0;
103913 }
103914 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
103915 index 44ebd5c..1f732bae 100644
103916 --- a/net/8021q/vlan.c
103917 +++ b/net/8021q/vlan.c
103918 @@ -475,7 +475,7 @@ out:
103919 return NOTIFY_DONE;
103920 }
103921
103922 -static struct notifier_block vlan_notifier_block __read_mostly = {
103923 +static struct notifier_block vlan_notifier_block = {
103924 .notifier_call = vlan_device_event,
103925 };
103926
103927 @@ -550,8 +550,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
103928 err = -EPERM;
103929 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
103930 break;
103931 - if ((args.u.name_type >= 0) &&
103932 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
103933 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
103934 struct vlan_net *vn;
103935
103936 vn = net_generic(net, vlan_net_id);
103937 diff --git a/net/9p/client.c b/net/9p/client.c
103938 index 0004cba..feba240 100644
103939 --- a/net/9p/client.c
103940 +++ b/net/9p/client.c
103941 @@ -596,7 +596,7 @@ static int p9_check_zc_errors(struct p9_client *c, struct p9_req_t *req,
103942 len - inline_len);
103943 } else {
103944 err = copy_from_user(ename + inline_len,
103945 - uidata, len - inline_len);
103946 + (char __force_user *)uidata, len - inline_len);
103947 if (err) {
103948 err = -EFAULT;
103949 goto out_err;
103950 @@ -1571,7 +1571,7 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
103951 kernel_buf = 1;
103952 indata = data;
103953 } else
103954 - indata = (__force char *)udata;
103955 + indata = (__force_kernel char *)udata;
103956 /*
103957 * response header len is 11
103958 * PDU Header(7) + IO Size (4)
103959 @@ -1646,7 +1646,7 @@ p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
103960 kernel_buf = 1;
103961 odata = data;
103962 } else
103963 - odata = (char *)udata;
103964 + odata = (char __force_kernel *)udata;
103965 req = p9_client_zc_rpc(clnt, P9_TWRITE, NULL, odata, 0, rsize,
103966 P9_ZC_HDR_SZ, kernel_buf, "dqd",
103967 fid->fid, offset, rsize);
103968 diff --git a/net/9p/mod.c b/net/9p/mod.c
103969 index 6ab36ae..6f1841b 100644
103970 --- a/net/9p/mod.c
103971 +++ b/net/9p/mod.c
103972 @@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
103973 void v9fs_register_trans(struct p9_trans_module *m)
103974 {
103975 spin_lock(&v9fs_trans_lock);
103976 - list_add_tail(&m->list, &v9fs_trans_list);
103977 + pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
103978 spin_unlock(&v9fs_trans_lock);
103979 }
103980 EXPORT_SYMBOL(v9fs_register_trans);
103981 @@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
103982 void v9fs_unregister_trans(struct p9_trans_module *m)
103983 {
103984 spin_lock(&v9fs_trans_lock);
103985 - list_del_init(&m->list);
103986 + pax_list_del_init((struct list_head *)&m->list);
103987 spin_unlock(&v9fs_trans_lock);
103988 }
103989 EXPORT_SYMBOL(v9fs_unregister_trans);
103990 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
103991 index 80d08f6..de63fd1 100644
103992 --- a/net/9p/trans_fd.c
103993 +++ b/net/9p/trans_fd.c
103994 @@ -428,7 +428,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
103995 oldfs = get_fs();
103996 set_fs(get_ds());
103997 /* The cast to a user pointer is valid due to the set_fs() */
103998 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
103999 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
104000 set_fs(oldfs);
104001
104002 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
104003 diff --git a/net/Kconfig b/net/Kconfig
104004 index d92afe4..ab63892 100644
104005 --- a/net/Kconfig
104006 +++ b/net/Kconfig
104007 @@ -89,12 +89,8 @@ config NETWORK_SECMARK
104008 to nfmark, but designated for security purposes.
104009 If you are unsure how to answer this question, answer N.
104010
104011 -config NET_PTP_CLASSIFY
104012 - def_bool n
104013 -
104014 config NETWORK_PHY_TIMESTAMPING
104015 bool "Timestamping in PHY devices"
104016 - select NET_PTP_CLASSIFY
104017 help
104018 This allows timestamping of network packets by PHYs with
104019 hardware timestamping capabilities. This option adds some
104020 @@ -269,7 +265,7 @@ config BQL
104021 config BPF_JIT
104022 bool "enable BPF Just In Time compiler"
104023 depends on HAVE_BPF_JIT
104024 - depends on MODULES
104025 + depends on MODULES && X86
104026 ---help---
104027 Berkeley Packet Filter filtering capabilities are normally handled
104028 by an interpreter. This option allows kernel to generate a native
104029 diff --git a/net/appletalk/atalk_proc.c b/net/appletalk/atalk_proc.c
104030 index af46bc4..f9adfcd 100644
104031 --- a/net/appletalk/atalk_proc.c
104032 +++ b/net/appletalk/atalk_proc.c
104033 @@ -256,7 +256,7 @@ int __init atalk_proc_init(void)
104034 struct proc_dir_entry *p;
104035 int rc = -ENOMEM;
104036
104037 - atalk_proc_dir = proc_mkdir("atalk", init_net.proc_net);
104038 + atalk_proc_dir = proc_mkdir_restrict("atalk", init_net.proc_net);
104039 if (!atalk_proc_dir)
104040 goto out;
104041
104042 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
104043 index 876fbe8..8bbea9f 100644
104044 --- a/net/atm/atm_misc.c
104045 +++ b/net/atm/atm_misc.c
104046 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
104047 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
104048 return 1;
104049 atm_return(vcc, truesize);
104050 - atomic_inc(&vcc->stats->rx_drop);
104051 + atomic_inc_unchecked(&vcc->stats->rx_drop);
104052 return 0;
104053 }
104054 EXPORT_SYMBOL(atm_charge);
104055 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
104056 }
104057 }
104058 atm_return(vcc, guess);
104059 - atomic_inc(&vcc->stats->rx_drop);
104060 + atomic_inc_unchecked(&vcc->stats->rx_drop);
104061 return NULL;
104062 }
104063 EXPORT_SYMBOL(atm_alloc_charge);
104064 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
104065
104066 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
104067 {
104068 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
104069 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
104070 __SONET_ITEMS
104071 #undef __HANDLE_ITEM
104072 }
104073 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
104074
104075 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
104076 {
104077 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
104078 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
104079 __SONET_ITEMS
104080 #undef __HANDLE_ITEM
104081 }
104082 diff --git a/net/atm/lec.c b/net/atm/lec.c
104083 index 4c5b8ba..95f7005 100644
104084 --- a/net/atm/lec.c
104085 +++ b/net/atm/lec.c
104086 @@ -111,9 +111,9 @@ static inline void lec_arp_put(struct lec_arp_table *entry)
104087 }
104088
104089 static struct lane2_ops lane2_ops = {
104090 - lane2_resolve, /* resolve, spec 3.1.3 */
104091 - lane2_associate_req, /* associate_req, spec 3.1.4 */
104092 - NULL /* associate indicator, spec 3.1.5 */
104093 + .resolve = lane2_resolve,
104094 + .associate_req = lane2_associate_req,
104095 + .associate_indicator = NULL
104096 };
104097
104098 static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
104099 diff --git a/net/atm/lec.h b/net/atm/lec.h
104100 index 4149db1..f2ab682 100644
104101 --- a/net/atm/lec.h
104102 +++ b/net/atm/lec.h
104103 @@ -48,7 +48,7 @@ struct lane2_ops {
104104 const u8 *tlvs, u32 sizeoftlvs);
104105 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
104106 const u8 *tlvs, u32 sizeoftlvs);
104107 -};
104108 +} __no_const;
104109
104110 /*
104111 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
104112 diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
104113 index d1b2d9a..d549f7f 100644
104114 --- a/net/atm/mpoa_caches.c
104115 +++ b/net/atm/mpoa_caches.c
104116 @@ -535,30 +535,30 @@ static void eg_destroy_cache(struct mpoa_client *mpc)
104117
104118
104119 static struct in_cache_ops ingress_ops = {
104120 - in_cache_add_entry, /* add_entry */
104121 - in_cache_get, /* get */
104122 - in_cache_get_with_mask, /* get_with_mask */
104123 - in_cache_get_by_vcc, /* get_by_vcc */
104124 - in_cache_put, /* put */
104125 - in_cache_remove_entry, /* remove_entry */
104126 - cache_hit, /* cache_hit */
104127 - clear_count_and_expired, /* clear_count */
104128 - check_resolving_entries, /* check_resolving */
104129 - refresh_entries, /* refresh */
104130 - in_destroy_cache /* destroy_cache */
104131 + .add_entry = in_cache_add_entry,
104132 + .get = in_cache_get,
104133 + .get_with_mask = in_cache_get_with_mask,
104134 + .get_by_vcc = in_cache_get_by_vcc,
104135 + .put = in_cache_put,
104136 + .remove_entry = in_cache_remove_entry,
104137 + .cache_hit = cache_hit,
104138 + .clear_count = clear_count_and_expired,
104139 + .check_resolving = check_resolving_entries,
104140 + .refresh = refresh_entries,
104141 + .destroy_cache = in_destroy_cache
104142 };
104143
104144 static struct eg_cache_ops egress_ops = {
104145 - eg_cache_add_entry, /* add_entry */
104146 - eg_cache_get_by_cache_id, /* get_by_cache_id */
104147 - eg_cache_get_by_tag, /* get_by_tag */
104148 - eg_cache_get_by_vcc, /* get_by_vcc */
104149 - eg_cache_get_by_src_ip, /* get_by_src_ip */
104150 - eg_cache_put, /* put */
104151 - eg_cache_remove_entry, /* remove_entry */
104152 - update_eg_cache_entry, /* update */
104153 - clear_expired, /* clear_expired */
104154 - eg_destroy_cache /* destroy_cache */
104155 + .add_entry = eg_cache_add_entry,
104156 + .get_by_cache_id = eg_cache_get_by_cache_id,
104157 + .get_by_tag = eg_cache_get_by_tag,
104158 + .get_by_vcc = eg_cache_get_by_vcc,
104159 + .get_by_src_ip = eg_cache_get_by_src_ip,
104160 + .put = eg_cache_put,
104161 + .remove_entry = eg_cache_remove_entry,
104162 + .update = update_eg_cache_entry,
104163 + .clear_expired = clear_expired,
104164 + .destroy_cache = eg_destroy_cache
104165 };
104166
104167
104168 diff --git a/net/atm/proc.c b/net/atm/proc.c
104169 index bbb6461..cf04016 100644
104170 --- a/net/atm/proc.c
104171 +++ b/net/atm/proc.c
104172 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
104173 const struct k_atm_aal_stats *stats)
104174 {
104175 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
104176 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
104177 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
104178 - atomic_read(&stats->rx_drop));
104179 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
104180 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
104181 + atomic_read_unchecked(&stats->rx_drop));
104182 }
104183
104184 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
104185 diff --git a/net/atm/resources.c b/net/atm/resources.c
104186 index 0447d5d..3cf4728 100644
104187 --- a/net/atm/resources.c
104188 +++ b/net/atm/resources.c
104189 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
104190 static void copy_aal_stats(struct k_atm_aal_stats *from,
104191 struct atm_aal_stats *to)
104192 {
104193 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
104194 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
104195 __AAL_STAT_ITEMS
104196 #undef __HANDLE_ITEM
104197 }
104198 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
104199 static void subtract_aal_stats(struct k_atm_aal_stats *from,
104200 struct atm_aal_stats *to)
104201 {
104202 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
104203 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
104204 __AAL_STAT_ITEMS
104205 #undef __HANDLE_ITEM
104206 }
104207 diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
104208 index 919a5ce..cc6b444 100644
104209 --- a/net/ax25/sysctl_net_ax25.c
104210 +++ b/net/ax25/sysctl_net_ax25.c
104211 @@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
104212 {
104213 char path[sizeof("net/ax25/") + IFNAMSIZ];
104214 int k;
104215 - struct ctl_table *table;
104216 + ctl_table_no_const *table;
104217
104218 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
104219 if (!table)
104220 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
104221 index f04224c..f326579 100644
104222 --- a/net/batman-adv/bat_iv_ogm.c
104223 +++ b/net/batman-adv/bat_iv_ogm.c
104224 @@ -312,7 +312,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
104225
104226 /* randomize initial seqno to avoid collision */
104227 get_random_bytes(&random_seqno, sizeof(random_seqno));
104228 - atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
104229 + atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
104230
104231 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
104232 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
104233 @@ -917,9 +917,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
104234 batadv_ogm_packet->tvlv_len = htons(tvlv_len);
104235
104236 /* change sequence number to network order */
104237 - seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
104238 + seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
104239 batadv_ogm_packet->seqno = htonl(seqno);
104240 - atomic_inc(&hard_iface->bat_iv.ogm_seqno);
104241 + atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
104242
104243 batadv_iv_ogm_slide_own_bcast_window(hard_iface);
104244
104245 @@ -1596,7 +1596,7 @@ static void batadv_iv_ogm_process(const struct sk_buff *skb, int ogm_offset,
104246 return;
104247
104248 /* could be changed by schedule_own_packet() */
104249 - if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
104250 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
104251
104252 if (ogm_packet->flags & BATADV_DIRECTLINK)
104253 has_directlink_flag = true;
104254 diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c
104255 index 022d18a..919daff 100644
104256 --- a/net/batman-adv/fragmentation.c
104257 +++ b/net/batman-adv/fragmentation.c
104258 @@ -450,7 +450,7 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
104259 frag_header.packet_type = BATADV_UNICAST_FRAG;
104260 frag_header.version = BATADV_COMPAT_VERSION;
104261 frag_header.ttl = BATADV_TTL;
104262 - frag_header.seqno = htons(atomic_inc_return(&bat_priv->frag_seqno));
104263 + frag_header.seqno = htons(atomic_inc_return_unchecked(&bat_priv->frag_seqno));
104264 frag_header.reserved = 0;
104265 frag_header.no = 0;
104266 frag_header.total_size = htons(skb->len);
104267 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
104268 index cbd677f..b783347 100644
104269 --- a/net/batman-adv/soft-interface.c
104270 +++ b/net/batman-adv/soft-interface.c
104271 @@ -296,7 +296,7 @@ send:
104272 primary_if->net_dev->dev_addr);
104273
104274 /* set broadcast sequence number */
104275 - seqno = atomic_inc_return(&bat_priv->bcast_seqno);
104276 + seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
104277 bcast_packet->seqno = htonl(seqno);
104278
104279 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
104280 @@ -761,7 +761,7 @@ static int batadv_softif_init_late(struct net_device *dev)
104281 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
104282
104283 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
104284 - atomic_set(&bat_priv->bcast_seqno, 1);
104285 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
104286 atomic_set(&bat_priv->tt.vn, 0);
104287 atomic_set(&bat_priv->tt.local_changes, 0);
104288 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
104289 @@ -775,7 +775,7 @@ static int batadv_softif_init_late(struct net_device *dev)
104290
104291 /* randomize initial seqno to avoid collision */
104292 get_random_bytes(&random_seqno, sizeof(random_seqno));
104293 - atomic_set(&bat_priv->frag_seqno, random_seqno);
104294 + atomic_set_unchecked(&bat_priv->frag_seqno, random_seqno);
104295
104296 bat_priv->primary_if = NULL;
104297 bat_priv->num_ifaces = 0;
104298 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
104299 index 8854c05..ee5d5497 100644
104300 --- a/net/batman-adv/types.h
104301 +++ b/net/batman-adv/types.h
104302 @@ -67,7 +67,7 @@ enum batadv_dhcp_recipient {
104303 struct batadv_hard_iface_bat_iv {
104304 unsigned char *ogm_buff;
104305 int ogm_buff_len;
104306 - atomic_t ogm_seqno;
104307 + atomic_unchecked_t ogm_seqno;
104308 };
104309
104310 /**
104311 @@ -768,7 +768,7 @@ struct batadv_priv {
104312 atomic_t bonding;
104313 atomic_t fragmentation;
104314 atomic_t packet_size_max;
104315 - atomic_t frag_seqno;
104316 + atomic_unchecked_t frag_seqno;
104317 #ifdef CONFIG_BATMAN_ADV_BLA
104318 atomic_t bridge_loop_avoidance;
104319 #endif
104320 @@ -787,7 +787,7 @@ struct batadv_priv {
104321 #endif
104322 uint32_t isolation_mark;
104323 uint32_t isolation_mark_mask;
104324 - atomic_t bcast_seqno;
104325 + atomic_unchecked_t bcast_seqno;
104326 atomic_t bcast_queue_left;
104327 atomic_t batman_queue_left;
104328 char num_ifaces;
104329 diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
104330 index 80d25c1..aa99a98 100644
104331 --- a/net/bluetooth/hci_sock.c
104332 +++ b/net/bluetooth/hci_sock.c
104333 @@ -1044,7 +1044,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
104334 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
104335 }
104336
104337 - len = min_t(unsigned int, len, sizeof(uf));
104338 + len = min((size_t)len, sizeof(uf));
104339 if (copy_from_user(&uf, optval, len)) {
104340 err = -EFAULT;
104341 break;
104342 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
104343 index 323f23c..5e27529 100644
104344 --- a/net/bluetooth/l2cap_core.c
104345 +++ b/net/bluetooth/l2cap_core.c
104346 @@ -3548,8 +3548,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
104347 break;
104348
104349 case L2CAP_CONF_RFC:
104350 - if (olen == sizeof(rfc))
104351 - memcpy(&rfc, (void *)val, olen);
104352 + if (olen != sizeof(rfc))
104353 + break;
104354 +
104355 + memcpy(&rfc, (void *)val, olen);
104356
104357 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
104358 rfc.mode != chan->mode)
104359 diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
104360 index e137869..33f3ebd 100644
104361 --- a/net/bluetooth/l2cap_sock.c
104362 +++ b/net/bluetooth/l2cap_sock.c
104363 @@ -628,7 +628,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
104364 struct sock *sk = sock->sk;
104365 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
104366 struct l2cap_options opts;
104367 - int len, err = 0;
104368 + int err = 0;
104369 + size_t len = optlen;
104370 u32 opt;
104371
104372 BT_DBG("sk %p", sk);
104373 @@ -655,7 +656,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
104374 opts.max_tx = chan->max_tx;
104375 opts.txwin_size = chan->tx_win;
104376
104377 - len = min_t(unsigned int, sizeof(opts), optlen);
104378 + len = min(sizeof(opts), len);
104379 if (copy_from_user((char *) &opts, optval, len)) {
104380 err = -EFAULT;
104381 break;
104382 @@ -742,7 +743,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
104383 struct bt_security sec;
104384 struct bt_power pwr;
104385 struct l2cap_conn *conn;
104386 - int len, err = 0;
104387 + int err = 0;
104388 + size_t len = optlen;
104389 u32 opt;
104390
104391 BT_DBG("sk %p", sk);
104392 @@ -766,7 +768,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
104393
104394 sec.level = BT_SECURITY_LOW;
104395
104396 - len = min_t(unsigned int, sizeof(sec), optlen);
104397 + len = min(sizeof(sec), len);
104398 if (copy_from_user((char *) &sec, optval, len)) {
104399 err = -EFAULT;
104400 break;
104401 @@ -861,7 +863,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
104402
104403 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
104404
104405 - len = min_t(unsigned int, sizeof(pwr), optlen);
104406 + len = min(sizeof(pwr), len);
104407 if (copy_from_user((char *) &pwr, optval, len)) {
104408 err = -EFAULT;
104409 break;
104410 diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
104411 index c603a5e..7f08991 100644
104412 --- a/net/bluetooth/rfcomm/sock.c
104413 +++ b/net/bluetooth/rfcomm/sock.c
104414 @@ -687,7 +687,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
104415 struct sock *sk = sock->sk;
104416 struct bt_security sec;
104417 int err = 0;
104418 - size_t len;
104419 + size_t len = optlen;
104420 u32 opt;
104421
104422 BT_DBG("sk %p", sk);
104423 @@ -709,7 +709,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
104424
104425 sec.level = BT_SECURITY_LOW;
104426
104427 - len = min_t(unsigned int, sizeof(sec), optlen);
104428 + len = min(sizeof(sec), len);
104429 if (copy_from_user((char *) &sec, optval, len)) {
104430 err = -EFAULT;
104431 break;
104432 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
104433 index 8e385a0..a5bdd8e 100644
104434 --- a/net/bluetooth/rfcomm/tty.c
104435 +++ b/net/bluetooth/rfcomm/tty.c
104436 @@ -752,7 +752,7 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
104437 BT_DBG("tty %p id %d", tty, tty->index);
104438
104439 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
104440 - dev->channel, dev->port.count);
104441 + dev->channel, atomic_read(&dev->port.count));
104442
104443 err = tty_port_open(&dev->port, tty, filp);
104444 if (err)
104445 @@ -775,7 +775,7 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
104446 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
104447
104448 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
104449 - dev->port.count);
104450 + atomic_read(&dev->port.count));
104451
104452 tty_port_close(&dev->port, tty, filp);
104453 }
104454 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
104455 index 1059ed3..d70846a 100644
104456 --- a/net/bridge/netfilter/ebtables.c
104457 +++ b/net/bridge/netfilter/ebtables.c
104458 @@ -1524,7 +1524,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
104459 tmp.valid_hooks = t->table->valid_hooks;
104460 }
104461 mutex_unlock(&ebt_mutex);
104462 - if (copy_to_user(user, &tmp, *len) != 0) {
104463 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
104464 BUGPRINT("c2u Didn't work\n");
104465 ret = -EFAULT;
104466 break;
104467 @@ -2330,7 +2330,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
104468 goto out;
104469 tmp.valid_hooks = t->valid_hooks;
104470
104471 - if (copy_to_user(user, &tmp, *len) != 0) {
104472 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
104473 ret = -EFAULT;
104474 break;
104475 }
104476 @@ -2341,7 +2341,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
104477 tmp.entries_size = t->table->entries_size;
104478 tmp.valid_hooks = t->table->valid_hooks;
104479
104480 - if (copy_to_user(user, &tmp, *len) != 0) {
104481 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
104482 ret = -EFAULT;
104483 break;
104484 }
104485 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
104486 index 0f45522..dab651f 100644
104487 --- a/net/caif/cfctrl.c
104488 +++ b/net/caif/cfctrl.c
104489 @@ -10,6 +10,7 @@
104490 #include <linux/spinlock.h>
104491 #include <linux/slab.h>
104492 #include <linux/pkt_sched.h>
104493 +#include <linux/sched.h>
104494 #include <net/caif/caif_layer.h>
104495 #include <net/caif/cfpkt.h>
104496 #include <net/caif/cfctrl.h>
104497 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
104498 memset(&dev_info, 0, sizeof(dev_info));
104499 dev_info.id = 0xff;
104500 cfsrvl_init(&this->serv, 0, &dev_info, false);
104501 - atomic_set(&this->req_seq_no, 1);
104502 - atomic_set(&this->rsp_seq_no, 1);
104503 + atomic_set_unchecked(&this->req_seq_no, 1);
104504 + atomic_set_unchecked(&this->rsp_seq_no, 1);
104505 this->serv.layer.receive = cfctrl_recv;
104506 sprintf(this->serv.layer.name, "ctrl");
104507 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
104508 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
104509 struct cfctrl_request_info *req)
104510 {
104511 spin_lock_bh(&ctrl->info_list_lock);
104512 - atomic_inc(&ctrl->req_seq_no);
104513 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
104514 + atomic_inc_unchecked(&ctrl->req_seq_no);
104515 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
104516 list_add_tail(&req->list, &ctrl->list);
104517 spin_unlock_bh(&ctrl->info_list_lock);
104518 }
104519 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
104520 if (p != first)
104521 pr_warn("Requests are not received in order\n");
104522
104523 - atomic_set(&ctrl->rsp_seq_no,
104524 + atomic_set_unchecked(&ctrl->rsp_seq_no,
104525 p->sequence_no);
104526 list_del(&p->list);
104527 goto out;
104528 diff --git a/net/can/af_can.c b/net/can/af_can.c
104529 index ce82337..5d17b4d 100644
104530 --- a/net/can/af_can.c
104531 +++ b/net/can/af_can.c
104532 @@ -884,7 +884,7 @@ static const struct net_proto_family can_family_ops = {
104533 };
104534
104535 /* notifier block for netdevice event */
104536 -static struct notifier_block can_netdev_notifier __read_mostly = {
104537 +static struct notifier_block can_netdev_notifier = {
104538 .notifier_call = can_notifier,
104539 };
104540
104541 diff --git a/net/can/bcm.c b/net/can/bcm.c
104542 index dcb75c0..24b1b43 100644
104543 --- a/net/can/bcm.c
104544 +++ b/net/can/bcm.c
104545 @@ -1624,7 +1624,7 @@ static int __init bcm_module_init(void)
104546 }
104547
104548 /* create /proc/net/can-bcm directory */
104549 - proc_dir = proc_mkdir("can-bcm", init_net.proc_net);
104550 + proc_dir = proc_mkdir_restrict("can-bcm", init_net.proc_net);
104551 return 0;
104552 }
104553
104554 diff --git a/net/can/gw.c b/net/can/gw.c
104555 index 050a211..bb9fe33 100644
104556 --- a/net/can/gw.c
104557 +++ b/net/can/gw.c
104558 @@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
104559 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
104560
104561 static HLIST_HEAD(cgw_list);
104562 -static struct notifier_block notifier;
104563
104564 static struct kmem_cache *cgw_cache __read_mostly;
104565
104566 @@ -947,6 +946,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
104567 return err;
104568 }
104569
104570 +static struct notifier_block notifier = {
104571 + .notifier_call = cgw_notifier
104572 +};
104573 +
104574 static __init int cgw_module_init(void)
104575 {
104576 /* sanitize given module parameter */
104577 @@ -962,7 +965,6 @@ static __init int cgw_module_init(void)
104578 return -ENOMEM;
104579
104580 /* set notifier */
104581 - notifier.notifier_call = cgw_notifier;
104582 register_netdevice_notifier(&notifier);
104583
104584 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
104585 diff --git a/net/can/proc.c b/net/can/proc.c
104586 index 1a19b98..df2b4ec 100644
104587 --- a/net/can/proc.c
104588 +++ b/net/can/proc.c
104589 @@ -514,7 +514,7 @@ static void can_remove_proc_readentry(const char *name)
104590 void can_init_proc(void)
104591 {
104592 /* create /proc/net/can directory */
104593 - can_dir = proc_mkdir("can", init_net.proc_net);
104594 + can_dir = proc_mkdir_restrict("can", init_net.proc_net);
104595
104596 if (!can_dir) {
104597 printk(KERN_INFO "can: failed to create /proc/net/can . "
104598 diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
104599 index 1948d59..9e854d5 100644
104600 --- a/net/ceph/messenger.c
104601 +++ b/net/ceph/messenger.c
104602 @@ -187,7 +187,7 @@ static void con_fault(struct ceph_connection *con);
104603 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
104604
104605 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
104606 -static atomic_t addr_str_seq = ATOMIC_INIT(0);
104607 +static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
104608
104609 static struct page *zero_page; /* used in certain error cases */
104610
104611 @@ -198,7 +198,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
104612 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
104613 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
104614
104615 - i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
104616 + i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
104617 s = addr_str[i];
104618
104619 switch (ss->ss_family) {
104620 diff --git a/net/compat.c b/net/compat.c
104621 index bc8aeef..f9c070c 100644
104622 --- a/net/compat.c
104623 +++ b/net/compat.c
104624 @@ -73,9 +73,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
104625 return -EFAULT;
104626 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
104627 kmsg->msg_namelen = sizeof(struct sockaddr_storage);
104628 - kmsg->msg_name = compat_ptr(tmp1);
104629 - kmsg->msg_iov = compat_ptr(tmp2);
104630 - kmsg->msg_control = compat_ptr(tmp3);
104631 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
104632 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
104633 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
104634 return 0;
104635 }
104636
104637 @@ -87,7 +87,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
104638
104639 if (kern_msg->msg_name && kern_msg->msg_namelen) {
104640 if (mode == VERIFY_READ) {
104641 - int err = move_addr_to_kernel(kern_msg->msg_name,
104642 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
104643 kern_msg->msg_namelen,
104644 kern_address);
104645 if (err < 0)
104646 @@ -100,7 +100,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
104647 }
104648
104649 tot_len = iov_from_user_compat_to_kern(kern_iov,
104650 - (struct compat_iovec __user *)kern_msg->msg_iov,
104651 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
104652 kern_msg->msg_iovlen);
104653 if (tot_len >= 0)
104654 kern_msg->msg_iov = kern_iov;
104655 @@ -120,20 +120,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
104656
104657 #define CMSG_COMPAT_FIRSTHDR(msg) \
104658 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
104659 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
104660 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
104661 (struct compat_cmsghdr __user *)NULL)
104662
104663 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
104664 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
104665 (ucmlen) <= (unsigned long) \
104666 ((mhdr)->msg_controllen - \
104667 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
104668 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
104669
104670 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
104671 struct compat_cmsghdr __user *cmsg, int cmsg_len)
104672 {
104673 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
104674 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
104675 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
104676 msg->msg_controllen)
104677 return NULL;
104678 return (struct compat_cmsghdr __user *)ptr;
104679 @@ -223,7 +223,7 @@ Efault:
104680
104681 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
104682 {
104683 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
104684 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
104685 struct compat_cmsghdr cmhdr;
104686 struct compat_timeval ctv;
104687 struct compat_timespec cts[3];
104688 @@ -279,7 +279,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
104689
104690 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
104691 {
104692 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
104693 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
104694 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
104695 int fdnum = scm->fp->count;
104696 struct file **fp = scm->fp->fp;
104697 @@ -367,7 +367,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
104698 return -EFAULT;
104699 old_fs = get_fs();
104700 set_fs(KERNEL_DS);
104701 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
104702 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
104703 set_fs(old_fs);
104704
104705 return err;
104706 @@ -428,7 +428,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
104707 len = sizeof(ktime);
104708 old_fs = get_fs();
104709 set_fs(KERNEL_DS);
104710 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
104711 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
104712 set_fs(old_fs);
104713
104714 if (!err) {
104715 @@ -571,7 +571,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
104716 case MCAST_JOIN_GROUP:
104717 case MCAST_LEAVE_GROUP:
104718 {
104719 - struct compat_group_req __user *gr32 = (void *)optval;
104720 + struct compat_group_req __user *gr32 = (void __user *)optval;
104721 struct group_req __user *kgr =
104722 compat_alloc_user_space(sizeof(struct group_req));
104723 u32 interface;
104724 @@ -592,7 +592,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
104725 case MCAST_BLOCK_SOURCE:
104726 case MCAST_UNBLOCK_SOURCE:
104727 {
104728 - struct compat_group_source_req __user *gsr32 = (void *)optval;
104729 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
104730 struct group_source_req __user *kgsr = compat_alloc_user_space(
104731 sizeof(struct group_source_req));
104732 u32 interface;
104733 @@ -613,7 +613,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
104734 }
104735 case MCAST_MSFILTER:
104736 {
104737 - struct compat_group_filter __user *gf32 = (void *)optval;
104738 + struct compat_group_filter __user *gf32 = (void __user *)optval;
104739 struct group_filter __user *kgf;
104740 u32 interface, fmode, numsrc;
104741
104742 @@ -651,7 +651,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
104743 char __user *optval, int __user *optlen,
104744 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
104745 {
104746 - struct compat_group_filter __user *gf32 = (void *)optval;
104747 + struct compat_group_filter __user *gf32 = (void __user *)optval;
104748 struct group_filter __user *kgf;
104749 int __user *koptlen;
104750 u32 interface, fmode, numsrc;
104751 @@ -804,7 +804,7 @@ COMPAT_SYSCALL_DEFINE2(socketcall, int, call, u32 __user *, args)
104752
104753 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
104754 return -EINVAL;
104755 - if (copy_from_user(a, args, nas[call]))
104756 + if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
104757 return -EFAULT;
104758 a0 = a[0];
104759 a1 = a[1];
104760 diff --git a/net/core/Makefile b/net/core/Makefile
104761 index 71093d9..a8a035b 100644
104762 --- a/net/core/Makefile
104763 +++ b/net/core/Makefile
104764 @@ -21,6 +21,5 @@ obj-$(CONFIG_FIB_RULES) += fib_rules.o
104765 obj-$(CONFIG_TRACEPOINTS) += net-traces.o
104766 obj-$(CONFIG_NET_DROP_MONITOR) += drop_monitor.o
104767 obj-$(CONFIG_NETWORK_PHY_TIMESTAMPING) += timestamping.o
104768 -obj-$(CONFIG_NET_PTP_CLASSIFY) += ptp_classifier.o
104769 obj-$(CONFIG_CGROUP_NET_PRIO) += netprio_cgroup.o
104770 obj-$(CONFIG_CGROUP_NET_CLASSID) += netclassid_cgroup.o
104771 diff --git a/net/core/datagram.c b/net/core/datagram.c
104772 index 488dd1a..7179f0f 100644
104773 --- a/net/core/datagram.c
104774 +++ b/net/core/datagram.c
104775 @@ -301,7 +301,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
104776 }
104777
104778 kfree_skb(skb);
104779 - atomic_inc(&sk->sk_drops);
104780 + atomic_inc_unchecked(&sk->sk_drops);
104781 sk_mem_reclaim_partial(sk);
104782
104783 return err;
104784 diff --git a/net/core/dev.c b/net/core/dev.c
104785 index 367a586..ef2fe17 100644
104786 --- a/net/core/dev.c
104787 +++ b/net/core/dev.c
104788 @@ -1672,14 +1672,14 @@ int __dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
104789 {
104790 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
104791 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
104792 - atomic_long_inc(&dev->rx_dropped);
104793 + atomic_long_inc_unchecked(&dev->rx_dropped);
104794 kfree_skb(skb);
104795 return NET_RX_DROP;
104796 }
104797 }
104798
104799 if (unlikely(!is_skb_forwardable(dev, skb))) {
104800 - atomic_long_inc(&dev->rx_dropped);
104801 + atomic_long_inc_unchecked(&dev->rx_dropped);
104802 kfree_skb(skb);
104803 return NET_RX_DROP;
104804 }
104805 @@ -2476,7 +2476,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
104806
104807 struct dev_gso_cb {
104808 void (*destructor)(struct sk_buff *skb);
104809 -};
104810 +} __no_const;
104811
104812 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
104813
104814 @@ -2932,7 +2932,7 @@ recursion_alert:
104815 rc = -ENETDOWN;
104816 rcu_read_unlock_bh();
104817
104818 - atomic_long_inc(&dev->tx_dropped);
104819 + atomic_long_inc_unchecked(&dev->tx_dropped);
104820 kfree_skb(skb);
104821 return rc;
104822 out:
104823 @@ -3276,7 +3276,7 @@ enqueue:
104824
104825 local_irq_restore(flags);
104826
104827 - atomic_long_inc(&skb->dev->rx_dropped);
104828 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
104829 kfree_skb(skb);
104830 return NET_RX_DROP;
104831 }
104832 @@ -3353,7 +3353,7 @@ int netif_rx_ni(struct sk_buff *skb)
104833 }
104834 EXPORT_SYMBOL(netif_rx_ni);
104835
104836 -static void net_tx_action(struct softirq_action *h)
104837 +static __latent_entropy void net_tx_action(void)
104838 {
104839 struct softnet_data *sd = &__get_cpu_var(softnet_data);
104840
104841 @@ -3686,7 +3686,7 @@ ncls:
104842 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
104843 } else {
104844 drop:
104845 - atomic_long_inc(&skb->dev->rx_dropped);
104846 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
104847 kfree_skb(skb);
104848 /* Jamal, now you will not able to escape explaining
104849 * me how you were going to use this. :-)
104850 @@ -4406,7 +4406,7 @@ void netif_napi_del(struct napi_struct *napi)
104851 }
104852 EXPORT_SYMBOL(netif_napi_del);
104853
104854 -static void net_rx_action(struct softirq_action *h)
104855 +static __latent_entropy void net_rx_action(void)
104856 {
104857 struct softnet_data *sd = &__get_cpu_var(softnet_data);
104858 unsigned long time_limit = jiffies + 2;
104859 @@ -6403,8 +6403,8 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
104860 } else {
104861 netdev_stats_to_stats64(storage, &dev->stats);
104862 }
104863 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
104864 - storage->tx_dropped += atomic_long_read(&dev->tx_dropped);
104865 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
104866 + storage->tx_dropped += atomic_long_read_unchecked(&dev->tx_dropped);
104867 return storage;
104868 }
104869 EXPORT_SYMBOL(dev_get_stats);
104870 diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
104871 index cf999e0..c59a975 100644
104872 --- a/net/core/dev_ioctl.c
104873 +++ b/net/core/dev_ioctl.c
104874 @@ -366,9 +366,13 @@ void dev_load(struct net *net, const char *name)
104875 if (no_module && capable(CAP_NET_ADMIN))
104876 no_module = request_module("netdev-%s", name);
104877 if (no_module && capable(CAP_SYS_MODULE)) {
104878 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
104879 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
104880 +#else
104881 if (!request_module("%s", name))
104882 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
104883 name);
104884 +#endif
104885 }
104886 }
104887 EXPORT_SYMBOL(dev_load);
104888 diff --git a/net/core/filter.c b/net/core/filter.c
104889 index 1dbf646..0f95703 100644
104890 --- a/net/core/filter.c
104891 +++ b/net/core/filter.c
104892 @@ -1,16 +1,11 @@
104893 /*
104894 * Linux Socket Filter - Kernel level socket filtering
104895 *
104896 - * Based on the design of the Berkeley Packet Filter. The new
104897 - * internal format has been designed by PLUMgrid:
104898 + * Author:
104899 + * Jay Schulist <jschlst@samba.org>
104900 *
104901 - * Copyright (c) 2011 - 2014 PLUMgrid, http://plumgrid.com
104902 - *
104903 - * Authors:
104904 - *
104905 - * Jay Schulist <jschlst@samba.org>
104906 - * Alexei Starovoitov <ast@plumgrid.com>
104907 - * Daniel Borkmann <dborkman@redhat.com>
104908 + * Based on the design of:
104909 + * - The Berkeley Packet Filter
104910 *
104911 * This program is free software; you can redistribute it and/or
104912 * modify it under the terms of the GNU General Public License
104913 @@ -45,27 +40,6 @@
104914 #include <linux/seccomp.h>
104915 #include <linux/if_vlan.h>
104916
104917 -/* Registers */
104918 -#define BPF_R0 regs[BPF_REG_0]
104919 -#define BPF_R1 regs[BPF_REG_1]
104920 -#define BPF_R2 regs[BPF_REG_2]
104921 -#define BPF_R3 regs[BPF_REG_3]
104922 -#define BPF_R4 regs[BPF_REG_4]
104923 -#define BPF_R5 regs[BPF_REG_5]
104924 -#define BPF_R6 regs[BPF_REG_6]
104925 -#define BPF_R7 regs[BPF_REG_7]
104926 -#define BPF_R8 regs[BPF_REG_8]
104927 -#define BPF_R9 regs[BPF_REG_9]
104928 -#define BPF_R10 regs[BPF_REG_10]
104929 -
104930 -/* Named registers */
104931 -#define DST regs[insn->dst_reg]
104932 -#define SRC regs[insn->src_reg]
104933 -#define FP regs[BPF_REG_FP]
104934 -#define ARG1 regs[BPF_REG_ARG1]
104935 -#define CTX regs[BPF_REG_CTX]
104936 -#define IMM insn->imm
104937 -
104938 /* No hurry in this branch
104939 *
104940 * Exported for the bpf jit load helper.
104941 @@ -78,9 +52,9 @@ void *bpf_internal_load_pointer_neg_helper(const struct sk_buff *skb, int k, uns
104942 ptr = skb_network_header(skb) + k - SKF_NET_OFF;
104943 else if (k >= SKF_LL_OFF)
104944 ptr = skb_mac_header(skb) + k - SKF_LL_OFF;
104945 +
104946 if (ptr >= skb->head && ptr + size <= skb_tail_pointer(skb))
104947 return ptr;
104948 -
104949 return NULL;
104950 }
104951
104952 @@ -89,7 +63,6 @@ static inline void *load_pointer(const struct sk_buff *skb, int k,
104953 {
104954 if (k >= 0)
104955 return skb_header_pointer(skb, k, size, buffer);
104956 -
104957 return bpf_internal_load_pointer_neg_helper(skb, k, size);
104958 }
104959
104960 @@ -135,960 +108,309 @@ int sk_filter(struct sock *sk, struct sk_buff *skb)
104961 }
104962 EXPORT_SYMBOL(sk_filter);
104963
104964 -/* Base function for offset calculation. Needs to go into .text section,
104965 - * therefore keeping it non-static as well; will also be used by JITs
104966 - * anyway later on, so do not let the compiler omit it.
104967 - */
104968 -noinline u64 __bpf_call_base(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5)
104969 -{
104970 - return 0;
104971 -}
104972 -
104973 /**
104974 - * __sk_run_filter - run a filter on a given context
104975 - * @ctx: buffer to run the filter on
104976 - * @insn: filter to apply
104977 + * sk_run_filter - run a filter on a socket
104978 + * @skb: buffer to run the filter on
104979 + * @fentry: filter to apply
104980 *
104981 - * Decode and apply filter instructions to the skb->data. Return length to
104982 - * keep, 0 for none. @ctx is the data we are operating on, @insn is the
104983 - * array of filter instructions.
104984 + * Decode and apply filter instructions to the skb->data.
104985 + * Return length to keep, 0 for none. @skb is the data we are
104986 + * filtering, @filter is the array of filter instructions.
104987 + * Because all jumps are guaranteed to be before last instruction,
104988 + * and last instruction guaranteed to be a RET, we dont need to check
104989 + * flen. (We used to pass to this function the length of filter)
104990 */
104991 -static unsigned int __sk_run_filter(void *ctx, const struct sock_filter_int *insn)
104992 +unsigned int sk_run_filter(const struct sk_buff *skb,
104993 + const struct sock_filter *fentry)
104994 {
104995 - u64 stack[MAX_BPF_STACK / sizeof(u64)];
104996 - u64 regs[MAX_BPF_REG], tmp;
104997 - static const void *jumptable[256] = {
104998 - [0 ... 255] = &&default_label,
104999 - /* Now overwrite non-defaults ... */
105000 - /* 32 bit ALU operations */
105001 - [BPF_ALU | BPF_ADD | BPF_X] = &&ALU_ADD_X,
105002 - [BPF_ALU | BPF_ADD | BPF_K] = &&ALU_ADD_K,
105003 - [BPF_ALU | BPF_SUB | BPF_X] = &&ALU_SUB_X,
105004 - [BPF_ALU | BPF_SUB | BPF_K] = &&ALU_SUB_K,
105005 - [BPF_ALU | BPF_AND | BPF_X] = &&ALU_AND_X,
105006 - [BPF_ALU | BPF_AND | BPF_K] = &&ALU_AND_K,
105007 - [BPF_ALU | BPF_OR | BPF_X] = &&ALU_OR_X,
105008 - [BPF_ALU | BPF_OR | BPF_K] = &&ALU_OR_K,
105009 - [BPF_ALU | BPF_LSH | BPF_X] = &&ALU_LSH_X,
105010 - [BPF_ALU | BPF_LSH | BPF_K] = &&ALU_LSH_K,
105011 - [BPF_ALU | BPF_RSH | BPF_X] = &&ALU_RSH_X,
105012 - [BPF_ALU | BPF_RSH | BPF_K] = &&ALU_RSH_K,
105013 - [BPF_ALU | BPF_XOR | BPF_X] = &&ALU_XOR_X,
105014 - [BPF_ALU | BPF_XOR | BPF_K] = &&ALU_XOR_K,
105015 - [BPF_ALU | BPF_MUL | BPF_X] = &&ALU_MUL_X,
105016 - [BPF_ALU | BPF_MUL | BPF_K] = &&ALU_MUL_K,
105017 - [BPF_ALU | BPF_MOV | BPF_X] = &&ALU_MOV_X,
105018 - [BPF_ALU | BPF_MOV | BPF_K] = &&ALU_MOV_K,
105019 - [BPF_ALU | BPF_DIV | BPF_X] = &&ALU_DIV_X,
105020 - [BPF_ALU | BPF_DIV | BPF_K] = &&ALU_DIV_K,
105021 - [BPF_ALU | BPF_MOD | BPF_X] = &&ALU_MOD_X,
105022 - [BPF_ALU | BPF_MOD | BPF_K] = &&ALU_MOD_K,
105023 - [BPF_ALU | BPF_NEG] = &&ALU_NEG,
105024 - [BPF_ALU | BPF_END | BPF_TO_BE] = &&ALU_END_TO_BE,
105025 - [BPF_ALU | BPF_END | BPF_TO_LE] = &&ALU_END_TO_LE,
105026 - /* 64 bit ALU operations */
105027 - [BPF_ALU64 | BPF_ADD | BPF_X] = &&ALU64_ADD_X,
105028 - [BPF_ALU64 | BPF_ADD | BPF_K] = &&ALU64_ADD_K,
105029 - [BPF_ALU64 | BPF_SUB | BPF_X] = &&ALU64_SUB_X,
105030 - [BPF_ALU64 | BPF_SUB | BPF_K] = &&ALU64_SUB_K,
105031 - [BPF_ALU64 | BPF_AND | BPF_X] = &&ALU64_AND_X,
105032 - [BPF_ALU64 | BPF_AND | BPF_K] = &&ALU64_AND_K,
105033 - [BPF_ALU64 | BPF_OR | BPF_X] = &&ALU64_OR_X,
105034 - [BPF_ALU64 | BPF_OR | BPF_K] = &&ALU64_OR_K,
105035 - [BPF_ALU64 | BPF_LSH | BPF_X] = &&ALU64_LSH_X,
105036 - [BPF_ALU64 | BPF_LSH | BPF_K] = &&ALU64_LSH_K,
105037 - [BPF_ALU64 | BPF_RSH | BPF_X] = &&ALU64_RSH_X,
105038 - [BPF_ALU64 | BPF_RSH | BPF_K] = &&ALU64_RSH_K,
105039 - [BPF_ALU64 | BPF_XOR | BPF_X] = &&ALU64_XOR_X,
105040 - [BPF_ALU64 | BPF_XOR | BPF_K] = &&ALU64_XOR_K,
105041 - [BPF_ALU64 | BPF_MUL | BPF_X] = &&ALU64_MUL_X,
105042 - [BPF_ALU64 | BPF_MUL | BPF_K] = &&ALU64_MUL_K,
105043 - [BPF_ALU64 | BPF_MOV | BPF_X] = &&ALU64_MOV_X,
105044 - [BPF_ALU64 | BPF_MOV | BPF_K] = &&ALU64_MOV_K,
105045 - [BPF_ALU64 | BPF_ARSH | BPF_X] = &&ALU64_ARSH_X,
105046 - [BPF_ALU64 | BPF_ARSH | BPF_K] = &&ALU64_ARSH_K,
105047 - [BPF_ALU64 | BPF_DIV | BPF_X] = &&ALU64_DIV_X,
105048 - [BPF_ALU64 | BPF_DIV | BPF_K] = &&ALU64_DIV_K,
105049 - [BPF_ALU64 | BPF_MOD | BPF_X] = &&ALU64_MOD_X,
105050 - [BPF_ALU64 | BPF_MOD | BPF_K] = &&ALU64_MOD_K,
105051 - [BPF_ALU64 | BPF_NEG] = &&ALU64_NEG,
105052 - /* Call instruction */
105053 - [BPF_JMP | BPF_CALL] = &&JMP_CALL,
105054 - /* Jumps */
105055 - [BPF_JMP | BPF_JA] = &&JMP_JA,
105056 - [BPF_JMP | BPF_JEQ | BPF_X] = &&JMP_JEQ_X,
105057 - [BPF_JMP | BPF_JEQ | BPF_K] = &&JMP_JEQ_K,
105058 - [BPF_JMP | BPF_JNE | BPF_X] = &&JMP_JNE_X,
105059 - [BPF_JMP | BPF_JNE | BPF_K] = &&JMP_JNE_K,
105060 - [BPF_JMP | BPF_JGT | BPF_X] = &&JMP_JGT_X,
105061 - [BPF_JMP | BPF_JGT | BPF_K] = &&JMP_JGT_K,
105062 - [BPF_JMP | BPF_JGE | BPF_X] = &&JMP_JGE_X,
105063 - [BPF_JMP | BPF_JGE | BPF_K] = &&JMP_JGE_K,
105064 - [BPF_JMP | BPF_JSGT | BPF_X] = &&JMP_JSGT_X,
105065 - [BPF_JMP | BPF_JSGT | BPF_K] = &&JMP_JSGT_K,
105066 - [BPF_JMP | BPF_JSGE | BPF_X] = &&JMP_JSGE_X,
105067 - [BPF_JMP | BPF_JSGE | BPF_K] = &&JMP_JSGE_K,
105068 - [BPF_JMP | BPF_JSET | BPF_X] = &&JMP_JSET_X,
105069 - [BPF_JMP | BPF_JSET | BPF_K] = &&JMP_JSET_K,
105070 - /* Program return */
105071 - [BPF_JMP | BPF_EXIT] = &&JMP_EXIT,
105072 - /* Store instructions */
105073 - [BPF_STX | BPF_MEM | BPF_B] = &&STX_MEM_B,
105074 - [BPF_STX | BPF_MEM | BPF_H] = &&STX_MEM_H,
105075 - [BPF_STX | BPF_MEM | BPF_W] = &&STX_MEM_W,
105076 - [BPF_STX | BPF_MEM | BPF_DW] = &&STX_MEM_DW,
105077 - [BPF_STX | BPF_XADD | BPF_W] = &&STX_XADD_W,
105078 - [BPF_STX | BPF_XADD | BPF_DW] = &&STX_XADD_DW,
105079 - [BPF_ST | BPF_MEM | BPF_B] = &&ST_MEM_B,
105080 - [BPF_ST | BPF_MEM | BPF_H] = &&ST_MEM_H,
105081 - [BPF_ST | BPF_MEM | BPF_W] = &&ST_MEM_W,
105082 - [BPF_ST | BPF_MEM | BPF_DW] = &&ST_MEM_DW,
105083 - /* Load instructions */
105084 - [BPF_LDX | BPF_MEM | BPF_B] = &&LDX_MEM_B,
105085 - [BPF_LDX | BPF_MEM | BPF_H] = &&LDX_MEM_H,
105086 - [BPF_LDX | BPF_MEM | BPF_W] = &&LDX_MEM_W,
105087 - [BPF_LDX | BPF_MEM | BPF_DW] = &&LDX_MEM_DW,
105088 - [BPF_LD | BPF_ABS | BPF_W] = &&LD_ABS_W,
105089 - [BPF_LD | BPF_ABS | BPF_H] = &&LD_ABS_H,
105090 - [BPF_LD | BPF_ABS | BPF_B] = &&LD_ABS_B,
105091 - [BPF_LD | BPF_IND | BPF_W] = &&LD_IND_W,
105092 - [BPF_LD | BPF_IND | BPF_H] = &&LD_IND_H,
105093 - [BPF_LD | BPF_IND | BPF_B] = &&LD_IND_B,
105094 - };
105095 void *ptr;
105096 - int off;
105097 -
105098 -#define CONT ({ insn++; goto select_insn; })
105099 -#define CONT_JMP ({ insn++; goto select_insn; })
105100 -
105101 - FP = (u64) (unsigned long) &stack[ARRAY_SIZE(stack)];
105102 - ARG1 = (u64) (unsigned long) ctx;
105103 -
105104 - /* Registers used in classic BPF programs need to be reset first. */
105105 - regs[BPF_REG_A] = 0;
105106 - regs[BPF_REG_X] = 0;
105107 -
105108 -select_insn:
105109 - goto *jumptable[insn->code];
105110 -
105111 - /* ALU */
105112 -#define ALU(OPCODE, OP) \
105113 - ALU64_##OPCODE##_X: \
105114 - DST = DST OP SRC; \
105115 - CONT; \
105116 - ALU_##OPCODE##_X: \
105117 - DST = (u32) DST OP (u32) SRC; \
105118 - CONT; \
105119 - ALU64_##OPCODE##_K: \
105120 - DST = DST OP IMM; \
105121 - CONT; \
105122 - ALU_##OPCODE##_K: \
105123 - DST = (u32) DST OP (u32) IMM; \
105124 - CONT;
105125 -
105126 - ALU(ADD, +)
105127 - ALU(SUB, -)
105128 - ALU(AND, &)
105129 - ALU(OR, |)
105130 - ALU(LSH, <<)
105131 - ALU(RSH, >>)
105132 - ALU(XOR, ^)
105133 - ALU(MUL, *)
105134 -#undef ALU
105135 - ALU_NEG:
105136 - DST = (u32) -DST;
105137 - CONT;
105138 - ALU64_NEG:
105139 - DST = -DST;
105140 - CONT;
105141 - ALU_MOV_X:
105142 - DST = (u32) SRC;
105143 - CONT;
105144 - ALU_MOV_K:
105145 - DST = (u32) IMM;
105146 - CONT;
105147 - ALU64_MOV_X:
105148 - DST = SRC;
105149 - CONT;
105150 - ALU64_MOV_K:
105151 - DST = IMM;
105152 - CONT;
105153 - ALU64_ARSH_X:
105154 - (*(s64 *) &DST) >>= SRC;
105155 - CONT;
105156 - ALU64_ARSH_K:
105157 - (*(s64 *) &DST) >>= IMM;
105158 - CONT;
105159 - ALU64_MOD_X:
105160 - if (unlikely(SRC == 0))
105161 - return 0;
105162 - tmp = DST;
105163 - DST = do_div(tmp, SRC);
105164 - CONT;
105165 - ALU_MOD_X:
105166 - if (unlikely(SRC == 0))
105167 - return 0;
105168 - tmp = (u32) DST;
105169 - DST = do_div(tmp, (u32) SRC);
105170 - CONT;
105171 - ALU64_MOD_K:
105172 - tmp = DST;
105173 - DST = do_div(tmp, IMM);
105174 - CONT;
105175 - ALU_MOD_K:
105176 - tmp = (u32) DST;
105177 - DST = do_div(tmp, (u32) IMM);
105178 - CONT;
105179 - ALU64_DIV_X:
105180 - if (unlikely(SRC == 0))
105181 - return 0;
105182 - do_div(DST, SRC);
105183 - CONT;
105184 - ALU_DIV_X:
105185 - if (unlikely(SRC == 0))
105186 - return 0;
105187 - tmp = (u32) DST;
105188 - do_div(tmp, (u32) SRC);
105189 - DST = (u32) tmp;
105190 - CONT;
105191 - ALU64_DIV_K:
105192 - do_div(DST, IMM);
105193 - CONT;
105194 - ALU_DIV_K:
105195 - tmp = (u32) DST;
105196 - do_div(tmp, (u32) IMM);
105197 - DST = (u32) tmp;
105198 - CONT;
105199 - ALU_END_TO_BE:
105200 - switch (IMM) {
105201 - case 16:
105202 - DST = (__force u16) cpu_to_be16(DST);
105203 - break;
105204 - case 32:
105205 - DST = (__force u32) cpu_to_be32(DST);
105206 - break;
105207 - case 64:
105208 - DST = (__force u64) cpu_to_be64(DST);
105209 - break;
105210 - }
105211 - CONT;
105212 - ALU_END_TO_LE:
105213 - switch (IMM) {
105214 - case 16:
105215 - DST = (__force u16) cpu_to_le16(DST);
105216 - break;
105217 - case 32:
105218 - DST = (__force u32) cpu_to_le32(DST);
105219 - break;
105220 - case 64:
105221 - DST = (__force u64) cpu_to_le64(DST);
105222 - break;
105223 - }
105224 - CONT;
105225 -
105226 - /* CALL */
105227 - JMP_CALL:
105228 - /* Function call scratches BPF_R1-BPF_R5 registers,
105229 - * preserves BPF_R6-BPF_R9, and stores return value
105230 - * into BPF_R0.
105231 - */
105232 - BPF_R0 = (__bpf_call_base + insn->imm)(BPF_R1, BPF_R2, BPF_R3,
105233 - BPF_R4, BPF_R5);
105234 - CONT;
105235 -
105236 - /* JMP */
105237 - JMP_JA:
105238 - insn += insn->off;
105239 - CONT;
105240 - JMP_JEQ_X:
105241 - if (DST == SRC) {
105242 - insn += insn->off;
105243 - CONT_JMP;
105244 - }
105245 - CONT;
105246 - JMP_JEQ_K:
105247 - if (DST == IMM) {
105248 - insn += insn->off;
105249 - CONT_JMP;
105250 - }
105251 - CONT;
105252 - JMP_JNE_X:
105253 - if (DST != SRC) {
105254 - insn += insn->off;
105255 - CONT_JMP;
105256 - }
105257 - CONT;
105258 - JMP_JNE_K:
105259 - if (DST != IMM) {
105260 - insn += insn->off;
105261 - CONT_JMP;
105262 - }
105263 - CONT;
105264 - JMP_JGT_X:
105265 - if (DST > SRC) {
105266 - insn += insn->off;
105267 - CONT_JMP;
105268 - }
105269 - CONT;
105270 - JMP_JGT_K:
105271 - if (DST > IMM) {
105272 - insn += insn->off;
105273 - CONT_JMP;
105274 - }
105275 - CONT;
105276 - JMP_JGE_X:
105277 - if (DST >= SRC) {
105278 - insn += insn->off;
105279 - CONT_JMP;
105280 - }
105281 - CONT;
105282 - JMP_JGE_K:
105283 - if (DST >= IMM) {
105284 - insn += insn->off;
105285 - CONT_JMP;
105286 - }
105287 - CONT;
105288 - JMP_JSGT_X:
105289 - if (((s64) DST) > ((s64) SRC)) {
105290 - insn += insn->off;
105291 - CONT_JMP;
105292 - }
105293 - CONT;
105294 - JMP_JSGT_K:
105295 - if (((s64) DST) > ((s64) IMM)) {
105296 - insn += insn->off;
105297 - CONT_JMP;
105298 - }
105299 - CONT;
105300 - JMP_JSGE_X:
105301 - if (((s64) DST) >= ((s64) SRC)) {
105302 - insn += insn->off;
105303 - CONT_JMP;
105304 - }
105305 - CONT;
105306 - JMP_JSGE_K:
105307 - if (((s64) DST) >= ((s64) IMM)) {
105308 - insn += insn->off;
105309 - CONT_JMP;
105310 - }
105311 - CONT;
105312 - JMP_JSET_X:
105313 - if (DST & SRC) {
105314 - insn += insn->off;
105315 - CONT_JMP;
105316 - }
105317 - CONT;
105318 - JMP_JSET_K:
105319 - if (DST & IMM) {
105320 - insn += insn->off;
105321 - CONT_JMP;
105322 - }
105323 - CONT;
105324 - JMP_EXIT:
105325 - return BPF_R0;
105326 -
105327 - /* STX and ST and LDX*/
105328 -#define LDST(SIZEOP, SIZE) \
105329 - STX_MEM_##SIZEOP: \
105330 - *(SIZE *)(unsigned long) (DST + insn->off) = SRC; \
105331 - CONT; \
105332 - ST_MEM_##SIZEOP: \
105333 - *(SIZE *)(unsigned long) (DST + insn->off) = IMM; \
105334 - CONT; \
105335 - LDX_MEM_##SIZEOP: \
105336 - DST = *(SIZE *)(unsigned long) (SRC + insn->off); \
105337 - CONT;
105338 -
105339 - LDST(B, u8)
105340 - LDST(H, u16)
105341 - LDST(W, u32)
105342 - LDST(DW, u64)
105343 -#undef LDST
105344 - STX_XADD_W: /* lock xadd *(u32 *)(dst_reg + off16) += src_reg */
105345 - atomic_add((u32) SRC, (atomic_t *)(unsigned long)
105346 - (DST + insn->off));
105347 - CONT;
105348 - STX_XADD_DW: /* lock xadd *(u64 *)(dst_reg + off16) += src_reg */
105349 - atomic64_add((u64) SRC, (atomic64_t *)(unsigned long)
105350 - (DST + insn->off));
105351 - CONT;
105352 - LD_ABS_W: /* BPF_R0 = ntohl(*(u32 *) (skb->data + imm32)) */
105353 - off = IMM;
105354 -load_word:
105355 - /* BPF_LD + BPD_ABS and BPF_LD + BPF_IND insns are
105356 - * only appearing in the programs where ctx ==
105357 - * skb. All programs keep 'ctx' in regs[BPF_REG_CTX]
105358 - * == BPF_R6, sk_convert_filter() saves it in BPF_R6,
105359 - * internal BPF verifier will check that BPF_R6 ==
105360 - * ctx.
105361 - *
105362 - * BPF_ABS and BPF_IND are wrappers of function calls,
105363 - * so they scratch BPF_R1-BPF_R5 registers, preserve
105364 - * BPF_R6-BPF_R9, and store return value into BPF_R0.
105365 - *
105366 - * Implicit input:
105367 - * ctx == skb == BPF_R6 == CTX
105368 - *
105369 - * Explicit input:
105370 - * SRC == any register
105371 - * IMM == 32-bit immediate
105372 - *
105373 - * Output:
105374 - * BPF_R0 - 8/16/32-bit skb data converted to cpu endianness
105375 - */
105376 -
105377 - ptr = load_pointer((struct sk_buff *) (unsigned long) CTX, off, 4, &tmp);
105378 - if (likely(ptr != NULL)) {
105379 - BPF_R0 = get_unaligned_be32(ptr);
105380 - CONT;
105381 - }
105382 -
105383 - return 0;
105384 - LD_ABS_H: /* BPF_R0 = ntohs(*(u16 *) (skb->data + imm32)) */
105385 - off = IMM;
105386 -load_half:
105387 - ptr = load_pointer((struct sk_buff *) (unsigned long) CTX, off, 2, &tmp);
105388 - if (likely(ptr != NULL)) {
105389 - BPF_R0 = get_unaligned_be16(ptr);
105390 - CONT;
105391 - }
105392 -
105393 - return 0;
105394 - LD_ABS_B: /* BPF_R0 = *(u8 *) (skb->data + imm32) */
105395 - off = IMM;
105396 -load_byte:
105397 - ptr = load_pointer((struct sk_buff *) (unsigned long) CTX, off, 1, &tmp);
105398 - if (likely(ptr != NULL)) {
105399 - BPF_R0 = *(u8 *)ptr;
105400 - CONT;
105401 - }
105402 -
105403 - return 0;
105404 - LD_IND_W: /* BPF_R0 = ntohl(*(u32 *) (skb->data + src_reg + imm32)) */
105405 - off = IMM + SRC;
105406 - goto load_word;
105407 - LD_IND_H: /* BPF_R0 = ntohs(*(u16 *) (skb->data + src_reg + imm32)) */
105408 - off = IMM + SRC;
105409 - goto load_half;
105410 - LD_IND_B: /* BPF_R0 = *(u8 *) (skb->data + src_reg + imm32) */
105411 - off = IMM + SRC;
105412 - goto load_byte;
105413 -
105414 - default_label:
105415 - /* If we ever reach this, we have a bug somewhere. */
105416 - WARN_RATELIMIT(1, "unknown opcode %02x\n", insn->code);
105417 - return 0;
105418 -}
105419 -
105420 -/* Helper to find the offset of pkt_type in sk_buff structure. We want
105421 - * to make sure its still a 3bit field starting at a byte boundary;
105422 - * taken from arch/x86/net/bpf_jit_comp.c.
105423 - */
105424 -#ifdef __BIG_ENDIAN_BITFIELD
105425 -#define PKT_TYPE_MAX (7 << 5)
105426 + u32 A = 0; /* Accumulator */
105427 + u32 X = 0; /* Index Register */
105428 + u32 mem[BPF_MEMWORDS] = {}; /* Scratch Memory Store */
105429 + u32 tmp;
105430 + int k;
105431 +
105432 + /*
105433 + * Process array of filter instructions.
105434 + */
105435 + for (;; fentry++) {
105436 +#if defined(CONFIG_X86_32)
105437 +#define K (fentry->k)
105438 #else
105439 -#define PKT_TYPE_MAX 7
105440 + const u32 K = fentry->k;
105441 #endif
105442 -static unsigned int pkt_type_offset(void)
105443 -{
105444 - struct sk_buff skb_probe = { .pkt_type = ~0, };
105445 - u8 *ct = (u8 *) &skb_probe;
105446 - unsigned int off;
105447
105448 - for (off = 0; off < sizeof(struct sk_buff); off++) {
105449 - if (ct[off] == PKT_TYPE_MAX)
105450 - return off;
105451 - }
105452 -
105453 - pr_err_once("Please fix %s, as pkt_type couldn't be found!\n", __func__);
105454 - return -1;
105455 -}
105456 -
105457 -static u64 __skb_get_pay_offset(u64 ctx, u64 a, u64 x, u64 r4, u64 r5)
105458 -{
105459 - return __skb_get_poff((struct sk_buff *)(unsigned long) ctx);
105460 -}
105461 -
105462 -static u64 __skb_get_nlattr(u64 ctx, u64 a, u64 x, u64 r4, u64 r5)
105463 -{
105464 - struct sk_buff *skb = (struct sk_buff *)(unsigned long) ctx;
105465 - struct nlattr *nla;
105466 -
105467 - if (skb_is_nonlinear(skb))
105468 - return 0;
105469 -
105470 - if (skb->len < sizeof(struct nlattr))
105471 - return 0;
105472 -
105473 - if (a > skb->len - sizeof(struct nlattr))
105474 - return 0;
105475 -
105476 - nla = nla_find((struct nlattr *) &skb->data[a], skb->len - a, x);
105477 - if (nla)
105478 - return (void *) nla - (void *) skb->data;
105479 -
105480 - return 0;
105481 -}
105482 -
105483 -static u64 __skb_get_nlattr_nest(u64 ctx, u64 a, u64 x, u64 r4, u64 r5)
105484 -{
105485 - struct sk_buff *skb = (struct sk_buff *)(unsigned long) ctx;
105486 - struct nlattr *nla;
105487 -
105488 - if (skb_is_nonlinear(skb))
105489 - return 0;
105490 -
105491 - if (skb->len < sizeof(struct nlattr))
105492 - return 0;
105493 -
105494 - if (a > skb->len - sizeof(struct nlattr))
105495 - return 0;
105496 -
105497 - nla = (struct nlattr *) &skb->data[a];
105498 - if (nla->nla_len > skb->len - a)
105499 - return 0;
105500 -
105501 - nla = nla_find_nested(nla, x);
105502 - if (nla)
105503 - return (void *) nla - (void *) skb->data;
105504 -
105505 - return 0;
105506 -}
105507 -
105508 -static u64 __get_raw_cpu_id(u64 ctx, u64 a, u64 x, u64 r4, u64 r5)
105509 -{
105510 - return raw_smp_processor_id();
105511 -}
105512 -
105513 -/* note that this only generates 32-bit random numbers */
105514 -static u64 __get_random_u32(u64 ctx, u64 a, u64 x, u64 r4, u64 r5)
105515 -{
105516 - return prandom_u32();
105517 -}
105518 -
105519 -static bool convert_bpf_extensions(struct sock_filter *fp,
105520 - struct sock_filter_int **insnp)
105521 -{
105522 - struct sock_filter_int *insn = *insnp;
105523 -
105524 - switch (fp->k) {
105525 - case SKF_AD_OFF + SKF_AD_PROTOCOL:
105526 - BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, protocol) != 2);
105527 -
105528 - /* A = *(u16 *) (CTX + offsetof(protocol)) */
105529 - *insn++ = BPF_LDX_MEM(BPF_H, BPF_REG_A, BPF_REG_CTX,
105530 - offsetof(struct sk_buff, protocol));
105531 - /* A = ntohs(A) [emitting a nop or swap16] */
105532 - *insn = BPF_ENDIAN(BPF_FROM_BE, BPF_REG_A, 16);
105533 - break;
105534 -
105535 - case SKF_AD_OFF + SKF_AD_PKTTYPE:
105536 - *insn = BPF_LDX_MEM(BPF_B, BPF_REG_A, BPF_REG_CTX,
105537 - pkt_type_offset());
105538 - if (insn->off < 0)
105539 - return false;
105540 - insn++;
105541 - *insn = BPF_ALU32_IMM(BPF_AND, BPF_REG_A, PKT_TYPE_MAX);
105542 -#ifdef __BIG_ENDIAN_BITFIELD
105543 - insn++;
105544 - *insn = BPF_ALU32_IMM(BPF_RSH, BPF_REG_A, 5);
105545 -#endif
105546 - break;
105547 -
105548 - case SKF_AD_OFF + SKF_AD_IFINDEX:
105549 - case SKF_AD_OFF + SKF_AD_HATYPE:
105550 - BUILD_BUG_ON(FIELD_SIZEOF(struct net_device, ifindex) != 4);
105551 - BUILD_BUG_ON(FIELD_SIZEOF(struct net_device, type) != 2);
105552 - BUILD_BUG_ON(bytes_to_bpf_size(FIELD_SIZEOF(struct sk_buff, dev)) < 0);
105553 -
105554 - *insn++ = BPF_LDX_MEM(bytes_to_bpf_size(FIELD_SIZEOF(struct sk_buff, dev)),
105555 - BPF_REG_TMP, BPF_REG_CTX,
105556 - offsetof(struct sk_buff, dev));
105557 - /* if (tmp != 0) goto pc + 1 */
105558 - *insn++ = BPF_JMP_IMM(BPF_JNE, BPF_REG_TMP, 0, 1);
105559 - *insn++ = BPF_EXIT_INSN();
105560 - if (fp->k == SKF_AD_OFF + SKF_AD_IFINDEX)
105561 - *insn = BPF_LDX_MEM(BPF_W, BPF_REG_A, BPF_REG_TMP,
105562 - offsetof(struct net_device, ifindex));
105563 - else
105564 - *insn = BPF_LDX_MEM(BPF_H, BPF_REG_A, BPF_REG_TMP,
105565 - offsetof(struct net_device, type));
105566 - break;
105567 -
105568 - case SKF_AD_OFF + SKF_AD_MARK:
105569 - BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, mark) != 4);
105570 -
105571 - *insn = BPF_LDX_MEM(BPF_W, BPF_REG_A, BPF_REG_CTX,
105572 - offsetof(struct sk_buff, mark));
105573 - break;
105574 -
105575 - case SKF_AD_OFF + SKF_AD_RXHASH:
105576 - BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, hash) != 4);
105577 -
105578 - *insn = BPF_LDX_MEM(BPF_W, BPF_REG_A, BPF_REG_CTX,
105579 - offsetof(struct sk_buff, hash));
105580 - break;
105581 -
105582 - case SKF_AD_OFF + SKF_AD_QUEUE:
105583 - BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, queue_mapping) != 2);
105584 -
105585 - *insn = BPF_LDX_MEM(BPF_H, BPF_REG_A, BPF_REG_CTX,
105586 - offsetof(struct sk_buff, queue_mapping));
105587 - break;
105588 -
105589 - case SKF_AD_OFF + SKF_AD_VLAN_TAG:
105590 - case SKF_AD_OFF + SKF_AD_VLAN_TAG_PRESENT:
105591 - BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, vlan_tci) != 2);
105592 - BUILD_BUG_ON(VLAN_TAG_PRESENT != 0x1000);
105593 -
105594 - /* A = *(u16 *) (CTX + offsetof(vlan_tci)) */
105595 - *insn++ = BPF_LDX_MEM(BPF_H, BPF_REG_A, BPF_REG_CTX,
105596 - offsetof(struct sk_buff, vlan_tci));
105597 - if (fp->k == SKF_AD_OFF + SKF_AD_VLAN_TAG) {
105598 - *insn = BPF_ALU32_IMM(BPF_AND, BPF_REG_A,
105599 - ~VLAN_TAG_PRESENT);
105600 - } else {
105601 - /* A >>= 12 */
105602 - *insn++ = BPF_ALU32_IMM(BPF_RSH, BPF_REG_A, 12);
105603 - /* A &= 1 */
105604 - *insn = BPF_ALU32_IMM(BPF_AND, BPF_REG_A, 1);
105605 - }
105606 - break;
105607 -
105608 - case SKF_AD_OFF + SKF_AD_PAY_OFFSET:
105609 - case SKF_AD_OFF + SKF_AD_NLATTR:
105610 - case SKF_AD_OFF + SKF_AD_NLATTR_NEST:
105611 - case SKF_AD_OFF + SKF_AD_CPU:
105612 - case SKF_AD_OFF + SKF_AD_RANDOM:
105613 - /* arg1 = CTX */
105614 - *insn++ = BPF_MOV64_REG(BPF_REG_ARG1, BPF_REG_CTX);
105615 - /* arg2 = A */
105616 - *insn++ = BPF_MOV64_REG(BPF_REG_ARG2, BPF_REG_A);
105617 - /* arg3 = X */
105618 - *insn++ = BPF_MOV64_REG(BPF_REG_ARG3, BPF_REG_X);
105619 - /* Emit call(arg1=CTX, arg2=A, arg3=X) */
105620 - switch (fp->k) {
105621 - case SKF_AD_OFF + SKF_AD_PAY_OFFSET:
105622 - *insn = BPF_EMIT_CALL(__skb_get_pay_offset);
105623 - break;
105624 - case SKF_AD_OFF + SKF_AD_NLATTR:
105625 - *insn = BPF_EMIT_CALL(__skb_get_nlattr);
105626 - break;
105627 - case SKF_AD_OFF + SKF_AD_NLATTR_NEST:
105628 - *insn = BPF_EMIT_CALL(__skb_get_nlattr_nest);
105629 - break;
105630 - case SKF_AD_OFF + SKF_AD_CPU:
105631 - *insn = BPF_EMIT_CALL(__get_raw_cpu_id);
105632 - break;
105633 - case SKF_AD_OFF + SKF_AD_RANDOM:
105634 - *insn = BPF_EMIT_CALL(__get_random_u32);
105635 - break;
105636 - }
105637 - break;
105638 -
105639 - case SKF_AD_OFF + SKF_AD_ALU_XOR_X:
105640 - /* A ^= X */
105641 - *insn = BPF_ALU32_REG(BPF_XOR, BPF_REG_A, BPF_REG_X);
105642 - break;
105643 -
105644 - default:
105645 - /* This is just a dummy call to avoid letting the compiler
105646 - * evict __bpf_call_base() as an optimization. Placed here
105647 - * where no-one bothers.
105648 - */
105649 - BUG_ON(__bpf_call_base(0, 0, 0, 0, 0) != 0);
105650 - return false;
105651 - }
105652 -
105653 - *insnp = insn;
105654 - return true;
105655 -}
105656 -
105657 -/**
105658 - * sk_convert_filter - convert filter program
105659 - * @prog: the user passed filter program
105660 - * @len: the length of the user passed filter program
105661 - * @new_prog: buffer where converted program will be stored
105662 - * @new_len: pointer to store length of converted program
105663 - *
105664 - * Remap 'sock_filter' style BPF instruction set to 'sock_filter_ext' style.
105665 - * Conversion workflow:
105666 - *
105667 - * 1) First pass for calculating the new program length:
105668 - * sk_convert_filter(old_prog, old_len, NULL, &new_len)
105669 - *
105670 - * 2) 2nd pass to remap in two passes: 1st pass finds new
105671 - * jump offsets, 2nd pass remapping:
105672 - * new_prog = kmalloc(sizeof(struct sock_filter_int) * new_len);
105673 - * sk_convert_filter(old_prog, old_len, new_prog, &new_len);
105674 - *
105675 - * User BPF's register A is mapped to our BPF register 6, user BPF
105676 - * register X is mapped to BPF register 7; frame pointer is always
105677 - * register 10; Context 'void *ctx' is stored in register 1, that is,
105678 - * for socket filters: ctx == 'struct sk_buff *', for seccomp:
105679 - * ctx == 'struct seccomp_data *'.
105680 - */
105681 -int sk_convert_filter(struct sock_filter *prog, int len,
105682 - struct sock_filter_int *new_prog, int *new_len)
105683 -{
105684 - int new_flen = 0, pass = 0, target, i;
105685 - struct sock_filter_int *new_insn;
105686 - struct sock_filter *fp;
105687 - int *addrs = NULL;
105688 - u8 bpf_src;
105689 -
105690 - BUILD_BUG_ON(BPF_MEMWORDS * sizeof(u32) > MAX_BPF_STACK);
105691 - BUILD_BUG_ON(BPF_REG_FP + 1 != MAX_BPF_REG);
105692 -
105693 - if (len <= 0 || len > BPF_MAXINSNS)
105694 - return -EINVAL;
105695 -
105696 - if (new_prog) {
105697 - addrs = kcalloc(len, sizeof(*addrs), GFP_KERNEL);
105698 - if (!addrs)
105699 - return -ENOMEM;
105700 - }
105701 -
105702 -do_pass:
105703 - new_insn = new_prog;
105704 - fp = prog;
105705 -
105706 - if (new_insn)
105707 - *new_insn = BPF_MOV64_REG(BPF_REG_CTX, BPF_REG_ARG1);
105708 - new_insn++;
105709 -
105710 - for (i = 0; i < len; fp++, i++) {
105711 - struct sock_filter_int tmp_insns[6] = { };
105712 - struct sock_filter_int *insn = tmp_insns;
105713 -
105714 - if (addrs)
105715 - addrs[i] = new_insn - new_prog;
105716 -
105717 - switch (fp->code) {
105718 - /* All arithmetic insns and skb loads map as-is. */
105719 - case BPF_ALU | BPF_ADD | BPF_X:
105720 - case BPF_ALU | BPF_ADD | BPF_K:
105721 - case BPF_ALU | BPF_SUB | BPF_X:
105722 - case BPF_ALU | BPF_SUB | BPF_K:
105723 - case BPF_ALU | BPF_AND | BPF_X:
105724 - case BPF_ALU | BPF_AND | BPF_K:
105725 - case BPF_ALU | BPF_OR | BPF_X:
105726 - case BPF_ALU | BPF_OR | BPF_K:
105727 - case BPF_ALU | BPF_LSH | BPF_X:
105728 - case BPF_ALU | BPF_LSH | BPF_K:
105729 - case BPF_ALU | BPF_RSH | BPF_X:
105730 - case BPF_ALU | BPF_RSH | BPF_K:
105731 - case BPF_ALU | BPF_XOR | BPF_X:
105732 - case BPF_ALU | BPF_XOR | BPF_K:
105733 - case BPF_ALU | BPF_MUL | BPF_X:
105734 - case BPF_ALU | BPF_MUL | BPF_K:
105735 - case BPF_ALU | BPF_DIV | BPF_X:
105736 - case BPF_ALU | BPF_DIV | BPF_K:
105737 - case BPF_ALU | BPF_MOD | BPF_X:
105738 - case BPF_ALU | BPF_MOD | BPF_K:
105739 - case BPF_ALU | BPF_NEG:
105740 - case BPF_LD | BPF_ABS | BPF_W:
105741 - case BPF_LD | BPF_ABS | BPF_H:
105742 - case BPF_LD | BPF_ABS | BPF_B:
105743 - case BPF_LD | BPF_IND | BPF_W:
105744 - case BPF_LD | BPF_IND | BPF_H:
105745 - case BPF_LD | BPF_IND | BPF_B:
105746 - /* Check for overloaded BPF extension and
105747 - * directly convert it if found, otherwise
105748 - * just move on with mapping.
105749 - */
105750 - if (BPF_CLASS(fp->code) == BPF_LD &&
105751 - BPF_MODE(fp->code) == BPF_ABS &&
105752 - convert_bpf_extensions(fp, &insn))
105753 - break;
105754 -
105755 - *insn = BPF_RAW_INSN(fp->code, BPF_REG_A, BPF_REG_X, 0, fp->k);
105756 - break;
105757 -
105758 - /* Jump transformation cannot use BPF block macros
105759 - * everywhere as offset calculation and target updates
105760 - * require a bit more work than the rest, i.e. jump
105761 - * opcodes map as-is, but offsets need adjustment.
105762 - */
105763 -
105764 -#define BPF_EMIT_JMP \
105765 - do { \
105766 - if (target >= len || target < 0) \
105767 - goto err; \
105768 - insn->off = addrs ? addrs[target] - addrs[i] - 1 : 0; \
105769 - /* Adjust pc relative offset for 2nd or 3rd insn. */ \
105770 - insn->off -= insn - tmp_insns; \
105771 - } while (0)
105772 -
105773 - case BPF_JMP | BPF_JA:
105774 - target = i + fp->k + 1;
105775 - insn->code = fp->code;
105776 - BPF_EMIT_JMP;
105777 - break;
105778 -
105779 - case BPF_JMP | BPF_JEQ | BPF_K:
105780 - case BPF_JMP | BPF_JEQ | BPF_X:
105781 - case BPF_JMP | BPF_JSET | BPF_K:
105782 - case BPF_JMP | BPF_JSET | BPF_X:
105783 - case BPF_JMP | BPF_JGT | BPF_K:
105784 - case BPF_JMP | BPF_JGT | BPF_X:
105785 - case BPF_JMP | BPF_JGE | BPF_K:
105786 - case BPF_JMP | BPF_JGE | BPF_X:
105787 - if (BPF_SRC(fp->code) == BPF_K && (int) fp->k < 0) {
105788 - /* BPF immediates are signed, zero extend
105789 - * immediate into tmp register and use it
105790 - * in compare insn.
105791 - */
105792 - *insn++ = BPF_MOV32_IMM(BPF_REG_TMP, fp->k);
105793 -
105794 - insn->dst_reg = BPF_REG_A;
105795 - insn->src_reg = BPF_REG_TMP;
105796 - bpf_src = BPF_X;
105797 - } else {
105798 - insn->dst_reg = BPF_REG_A;
105799 - insn->src_reg = BPF_REG_X;
105800 - insn->imm = fp->k;
105801 - bpf_src = BPF_SRC(fp->code);
105802 + switch (fentry->code) {
105803 + case BPF_S_ALU_ADD_X:
105804 + A += X;
105805 + continue;
105806 + case BPF_S_ALU_ADD_K:
105807 + A += K;
105808 + continue;
105809 + case BPF_S_ALU_SUB_X:
105810 + A -= X;
105811 + continue;
105812 + case BPF_S_ALU_SUB_K:
105813 + A -= K;
105814 + continue;
105815 + case BPF_S_ALU_MUL_X:
105816 + A *= X;
105817 + continue;
105818 + case BPF_S_ALU_MUL_K:
105819 + A *= K;
105820 + continue;
105821 + case BPF_S_ALU_DIV_X:
105822 + if (X == 0)
105823 + return 0;
105824 + A /= X;
105825 + continue;
105826 + case BPF_S_ALU_DIV_K:
105827 + A /= K;
105828 + continue;
105829 + case BPF_S_ALU_MOD_X:
105830 + if (X == 0)
105831 + return 0;
105832 + A %= X;
105833 + continue;
105834 + case BPF_S_ALU_MOD_K:
105835 + A %= K;
105836 + continue;
105837 + case BPF_S_ALU_AND_X:
105838 + A &= X;
105839 + continue;
105840 + case BPF_S_ALU_AND_K:
105841 + A &= K;
105842 + continue;
105843 + case BPF_S_ALU_OR_X:
105844 + A |= X;
105845 + continue;
105846 + case BPF_S_ALU_OR_K:
105847 + A |= K;
105848 + continue;
105849 + case BPF_S_ANC_ALU_XOR_X:
105850 + case BPF_S_ALU_XOR_X:
105851 + A ^= X;
105852 + continue;
105853 + case BPF_S_ALU_XOR_K:
105854 + A ^= K;
105855 + continue;
105856 + case BPF_S_ALU_LSH_X:
105857 + A <<= X;
105858 + continue;
105859 + case BPF_S_ALU_LSH_K:
105860 + A <<= K;
105861 + continue;
105862 + case BPF_S_ALU_RSH_X:
105863 + A >>= X;
105864 + continue;
105865 + case BPF_S_ALU_RSH_K:
105866 + A >>= K;
105867 + continue;
105868 + case BPF_S_ALU_NEG:
105869 + A = -A;
105870 + continue;
105871 + case BPF_S_JMP_JA:
105872 + fentry += K;
105873 + continue;
105874 + case BPF_S_JMP_JGT_K:
105875 + fentry += (A > K) ? fentry->jt : fentry->jf;
105876 + continue;
105877 + case BPF_S_JMP_JGE_K:
105878 + fentry += (A >= K) ? fentry->jt : fentry->jf;
105879 + continue;
105880 + case BPF_S_JMP_JEQ_K:
105881 + fentry += (A == K) ? fentry->jt : fentry->jf;
105882 + continue;
105883 + case BPF_S_JMP_JSET_K:
105884 + fentry += (A & K) ? fentry->jt : fentry->jf;
105885 + continue;
105886 + case BPF_S_JMP_JGT_X:
105887 + fentry += (A > X) ? fentry->jt : fentry->jf;
105888 + continue;
105889 + case BPF_S_JMP_JGE_X:
105890 + fentry += (A >= X) ? fentry->jt : fentry->jf;
105891 + continue;
105892 + case BPF_S_JMP_JEQ_X:
105893 + fentry += (A == X) ? fentry->jt : fentry->jf;
105894 + continue;
105895 + case BPF_S_JMP_JSET_X:
105896 + fentry += (A & X) ? fentry->jt : fentry->jf;
105897 + continue;
105898 + case BPF_S_LD_W_ABS:
105899 + k = K;
105900 +load_w:
105901 + ptr = load_pointer(skb, k, 4, &tmp);
105902 + if (ptr != NULL) {
105903 + A = get_unaligned_be32(ptr);
105904 + continue;
105905 }
105906 -
105907 - /* Common case where 'jump_false' is next insn. */
105908 - if (fp->jf == 0) {
105909 - insn->code = BPF_JMP | BPF_OP(fp->code) | bpf_src;
105910 - target = i + fp->jt + 1;
105911 - BPF_EMIT_JMP;
105912 - break;
105913 + return 0;
105914 + case BPF_S_LD_H_ABS:
105915 + k = K;
105916 +load_h:
105917 + ptr = load_pointer(skb, k, 2, &tmp);
105918 + if (ptr != NULL) {
105919 + A = get_unaligned_be16(ptr);
105920 + continue;
105921 }
105922 -
105923 - /* Convert JEQ into JNE when 'jump_true' is next insn. */
105924 - if (fp->jt == 0 && BPF_OP(fp->code) == BPF_JEQ) {
105925 - insn->code = BPF_JMP | BPF_JNE | bpf_src;
105926 - target = i + fp->jf + 1;
105927 - BPF_EMIT_JMP;
105928 - break;
105929 + return 0;
105930 + case BPF_S_LD_B_ABS:
105931 + k = K;
105932 +load_b:
105933 + ptr = load_pointer(skb, k, 1, &tmp);
105934 + if (ptr != NULL) {
105935 + A = *(u8 *)ptr;
105936 + continue;
105937 }
105938 -
105939 - /* Other jumps are mapped into two insns: Jxx and JA. */
105940 - target = i + fp->jt + 1;
105941 - insn->code = BPF_JMP | BPF_OP(fp->code) | bpf_src;
105942 - BPF_EMIT_JMP;
105943 - insn++;
105944 -
105945 - insn->code = BPF_JMP | BPF_JA;
105946 - target = i + fp->jf + 1;
105947 - BPF_EMIT_JMP;
105948 - break;
105949 -
105950 - /* ldxb 4 * ([14] & 0xf) is remaped into 6 insns. */
105951 - case BPF_LDX | BPF_MSH | BPF_B:
105952 - /* tmp = A */
105953 - *insn++ = BPF_MOV64_REG(BPF_REG_TMP, BPF_REG_A);
105954 - /* A = BPF_R0 = *(u8 *) (skb->data + K) */
105955 - *insn++ = BPF_LD_ABS(BPF_B, fp->k);
105956 - /* A &= 0xf */
105957 - *insn++ = BPF_ALU32_IMM(BPF_AND, BPF_REG_A, 0xf);
105958 - /* A <<= 2 */
105959 - *insn++ = BPF_ALU32_IMM(BPF_LSH, BPF_REG_A, 2);
105960 - /* X = A */
105961 - *insn++ = BPF_MOV64_REG(BPF_REG_X, BPF_REG_A);
105962 - /* A = tmp */
105963 - *insn = BPF_MOV64_REG(BPF_REG_A, BPF_REG_TMP);
105964 - break;
105965 -
105966 - /* RET_K, RET_A are remaped into 2 insns. */
105967 - case BPF_RET | BPF_A:
105968 - case BPF_RET | BPF_K:
105969 - *insn++ = BPF_MOV32_RAW(BPF_RVAL(fp->code) == BPF_K ?
105970 - BPF_K : BPF_X, BPF_REG_0,
105971 - BPF_REG_A, fp->k);
105972 - *insn = BPF_EXIT_INSN();
105973 - break;
105974 -
105975 - /* Store to stack. */
105976 - case BPF_ST:
105977 - case BPF_STX:
105978 - *insn = BPF_STX_MEM(BPF_W, BPF_REG_FP, BPF_CLASS(fp->code) ==
105979 - BPF_ST ? BPF_REG_A : BPF_REG_X,
105980 - -(BPF_MEMWORDS - fp->k) * 4);
105981 - break;
105982 -
105983 - /* Load from stack. */
105984 - case BPF_LD | BPF_MEM:
105985 - case BPF_LDX | BPF_MEM:
105986 - *insn = BPF_LDX_MEM(BPF_W, BPF_CLASS(fp->code) == BPF_LD ?
105987 - BPF_REG_A : BPF_REG_X, BPF_REG_FP,
105988 - -(BPF_MEMWORDS - fp->k) * 4);
105989 - break;
105990 -
105991 - /* A = K or X = K */
105992 - case BPF_LD | BPF_IMM:
105993 - case BPF_LDX | BPF_IMM:
105994 - *insn = BPF_MOV32_IMM(BPF_CLASS(fp->code) == BPF_LD ?
105995 - BPF_REG_A : BPF_REG_X, fp->k);
105996 - break;
105997 -
105998 - /* X = A */
105999 - case BPF_MISC | BPF_TAX:
106000 - *insn = BPF_MOV64_REG(BPF_REG_X, BPF_REG_A);
106001 - break;
106002 -
106003 - /* A = X */
106004 - case BPF_MISC | BPF_TXA:
106005 - *insn = BPF_MOV64_REG(BPF_REG_A, BPF_REG_X);
106006 - break;
106007 -
106008 - /* A = skb->len or X = skb->len */
106009 - case BPF_LD | BPF_W | BPF_LEN:
106010 - case BPF_LDX | BPF_W | BPF_LEN:
106011 - *insn = BPF_LDX_MEM(BPF_W, BPF_CLASS(fp->code) == BPF_LD ?
106012 - BPF_REG_A : BPF_REG_X, BPF_REG_CTX,
106013 - offsetof(struct sk_buff, len));
106014 - break;
106015 -
106016 - /* Access seccomp_data fields. */
106017 - case BPF_LDX | BPF_ABS | BPF_W:
106018 - /* A = *(u32 *) (ctx + K) */
106019 - *insn = BPF_LDX_MEM(BPF_W, BPF_REG_A, BPF_REG_CTX, fp->k);
106020 - break;
106021 -
106022 - /* Unkown instruction. */
106023 + return 0;
106024 + case BPF_S_LD_W_LEN:
106025 + A = skb->len;
106026 + continue;
106027 + case BPF_S_LDX_W_LEN:
106028 + X = skb->len;
106029 + continue;
106030 + case BPF_S_LD_W_IND:
106031 + k = X + K;
106032 + goto load_w;
106033 + case BPF_S_LD_H_IND:
106034 + k = X + K;
106035 + goto load_h;
106036 + case BPF_S_LD_B_IND:
106037 + k = X + K;
106038 + goto load_b;
106039 + case BPF_S_LDX_B_MSH:
106040 + ptr = load_pointer(skb, K, 1, &tmp);
106041 + if (ptr != NULL) {
106042 + X = (*(u8 *)ptr & 0xf) << 2;
106043 + continue;
106044 + }
106045 + return 0;
106046 + case BPF_S_LD_IMM:
106047 + A = K;
106048 + continue;
106049 + case BPF_S_LDX_IMM:
106050 + X = K;
106051 + continue;
106052 + case BPF_S_LD_MEM:
106053 + A = mem[K&15];
106054 + continue;
106055 + case BPF_S_LDX_MEM:
106056 + X = mem[K&15];
106057 + continue;
106058 + case BPF_S_MISC_TAX:
106059 + X = A;
106060 + continue;
106061 + case BPF_S_MISC_TXA:
106062 + A = X;
106063 + continue;
106064 + case BPF_S_RET_K:
106065 + return K;
106066 + case BPF_S_RET_A:
106067 + return A;
106068 + case BPF_S_ST:
106069 + mem[K&15] = A;
106070 + continue;
106071 + case BPF_S_STX:
106072 + mem[K&15] = X;
106073 + continue;
106074 + case BPF_S_ANC_PROTOCOL:
106075 + A = ntohs(skb->protocol);
106076 + continue;
106077 + case BPF_S_ANC_PKTTYPE:
106078 + A = skb->pkt_type;
106079 + continue;
106080 + case BPF_S_ANC_IFINDEX:
106081 + if (!skb->dev)
106082 + return 0;
106083 + A = skb->dev->ifindex;
106084 + continue;
106085 + case BPF_S_ANC_MARK:
106086 + A = skb->mark;
106087 + continue;
106088 + case BPF_S_ANC_QUEUE:
106089 + A = skb->queue_mapping;
106090 + continue;
106091 + case BPF_S_ANC_HATYPE:
106092 + if (!skb->dev)
106093 + return 0;
106094 + A = skb->dev->type;
106095 + continue;
106096 + case BPF_S_ANC_RXHASH:
106097 + A = skb->hash;
106098 + continue;
106099 + case BPF_S_ANC_CPU:
106100 + A = raw_smp_processor_id();
106101 + continue;
106102 + case BPF_S_ANC_VLAN_TAG:
106103 + A = vlan_tx_tag_get(skb);
106104 + continue;
106105 + case BPF_S_ANC_VLAN_TAG_PRESENT:
106106 + A = !!vlan_tx_tag_present(skb);
106107 + continue;
106108 + case BPF_S_ANC_PAY_OFFSET:
106109 + A = __skb_get_poff(skb);
106110 + continue;
106111 + case BPF_S_ANC_NLATTR: {
106112 + struct nlattr *nla;
106113 +
106114 + if (skb_is_nonlinear(skb))
106115 + return 0;
106116 + if (skb->len < sizeof(struct nlattr))
106117 + return 0;
106118 + if (A > skb->len - sizeof(struct nlattr))
106119 + return 0;
106120 +
106121 + nla = nla_find((struct nlattr *)&skb->data[A],
106122 + skb->len - A, X);
106123 + if (nla)
106124 + A = (void *)nla - (void *)skb->data;
106125 + else
106126 + A = 0;
106127 + continue;
106128 + }
106129 + case BPF_S_ANC_NLATTR_NEST: {
106130 + struct nlattr *nla;
106131 +
106132 + if (skb_is_nonlinear(skb))
106133 + return 0;
106134 + if (skb->len < sizeof(struct nlattr))
106135 + return 0;
106136 + if (A > skb->len - sizeof(struct nlattr))
106137 + return 0;
106138 +
106139 + nla = (struct nlattr *)&skb->data[A];
106140 + if (nla->nla_len > skb->len - A)
106141 + return 0;
106142 +
106143 + nla = nla_find_nested(nla, X);
106144 + if (nla)
106145 + A = (void *)nla - (void *)skb->data;
106146 + else
106147 + A = 0;
106148 + continue;
106149 + }
106150 +#ifdef CONFIG_SECCOMP_FILTER
106151 + case BPF_S_ANC_SECCOMP_LD_W:
106152 + A = seccomp_bpf_load(fentry->k);
106153 + continue;
106154 +#endif
106155 default:
106156 - goto err;
106157 + WARN(1, KERN_ALERT "Unknown sock filter code:%u jt:%u tf:%u k:%u\n",
106158 + fentry->code, fentry->jt,
106159 + fentry->jf, fentry->k);
106160 + BUG();
106161 + return 0;
106162 }
106163 -
106164 - insn++;
106165 - if (new_prog)
106166 - memcpy(new_insn, tmp_insns,
106167 - sizeof(*insn) * (insn - tmp_insns));
106168 - new_insn += insn - tmp_insns;
106169 - }
106170 -
106171 - if (!new_prog) {
106172 - /* Only calculating new length. */
106173 - *new_len = new_insn - new_prog;
106174 - return 0;
106175 - }
106176 -
106177 - pass++;
106178 - if (new_flen != new_insn - new_prog) {
106179 - new_flen = new_insn - new_prog;
106180 - if (pass > 2)
106181 - goto err;
106182 - goto do_pass;
106183 }
106184
106185 - kfree(addrs);
106186 - BUG_ON(*new_len != new_flen);
106187 return 0;
106188 -err:
106189 - kfree(addrs);
106190 - return -EINVAL;
106191 }
106192 +EXPORT_SYMBOL(sk_run_filter);
106193
106194 -/* Security:
106195 - *
106196 +/*
106197 + * Security :
106198 * A BPF program is able to use 16 cells of memory to store intermediate
106199 - * values (check u32 mem[BPF_MEMWORDS] in sk_run_filter()).
106200 - *
106201 + * values (check u32 mem[BPF_MEMWORDS] in sk_run_filter())
106202 * As we dont want to clear mem[] array for each packet going through
106203 * sk_run_filter(), we check that filter loaded by user never try to read
106204 * a cell if not previously written, and we check all branches to be sure
106205 @@ -1096,46 +418,44 @@ err:
106206 */
106207 static int check_load_and_stores(struct sock_filter *filter, int flen)
106208 {
106209 - u16 *masks, memvalid = 0; /* One bit per cell, 16 cells */
106210 + u16 *masks, memvalid = 0; /* one bit per cell, 16 cells */
106211 int pc, ret = 0;
106212
106213 - BUILD_BUG_ON(BPF_MEMWORDS > 16);
106214 -
106215 - masks = kmalloc_array(flen, sizeof(*masks), GFP_KERNEL);
106216 + BUILD_BUG_ON(BPF_MEMWORDS != 16);
106217 + masks = kmalloc(flen * sizeof(*masks), GFP_KERNEL);
106218 if (!masks)
106219 return -ENOMEM;
106220 -
106221 memset(masks, 0xff, flen * sizeof(*masks));
106222
106223 for (pc = 0; pc < flen; pc++) {
106224 memvalid &= masks[pc];
106225
106226 switch (filter[pc].code) {
106227 - case BPF_ST:
106228 - case BPF_STX:
106229 + case BPF_S_ST:
106230 + case BPF_S_STX:
106231 memvalid |= (1 << filter[pc].k);
106232 break;
106233 - case BPF_LD | BPF_MEM:
106234 - case BPF_LDX | BPF_MEM:
106235 + case BPF_S_LD_MEM:
106236 + case BPF_S_LDX_MEM:
106237 if (!(memvalid & (1 << filter[pc].k))) {
106238 ret = -EINVAL;
106239 goto error;
106240 }
106241 break;
106242 - case BPF_JMP | BPF_JA:
106243 - /* A jump must set masks on target */
106244 + case BPF_S_JMP_JA:
106245 + /* a jump must set masks on target */
106246 masks[pc + 1 + filter[pc].k] &= memvalid;
106247 memvalid = ~0;
106248 break;
106249 - case BPF_JMP | BPF_JEQ | BPF_K:
106250 - case BPF_JMP | BPF_JEQ | BPF_X:
106251 - case BPF_JMP | BPF_JGE | BPF_K:
106252 - case BPF_JMP | BPF_JGE | BPF_X:
106253 - case BPF_JMP | BPF_JGT | BPF_K:
106254 - case BPF_JMP | BPF_JGT | BPF_X:
106255 - case BPF_JMP | BPF_JSET | BPF_K:
106256 - case BPF_JMP | BPF_JSET | BPF_X:
106257 - /* A jump must set masks on targets */
106258 + case BPF_S_JMP_JEQ_K:
106259 + case BPF_S_JMP_JEQ_X:
106260 + case BPF_S_JMP_JGE_K:
106261 + case BPF_S_JMP_JGE_X:
106262 + case BPF_S_JMP_JGT_K:
106263 + case BPF_S_JMP_JGT_X:
106264 + case BPF_S_JMP_JSET_X:
106265 + case BPF_S_JMP_JSET_K:
106266 + /* a jump must set masks on targets */
106267 masks[pc + 1 + filter[pc].jt] &= memvalid;
106268 masks[pc + 1 + filter[pc].jf] &= memvalid;
106269 memvalid = ~0;
106270 @@ -1147,72 +467,6 @@ error:
106271 return ret;
106272 }
106273
106274 -static bool chk_code_allowed(u16 code_to_probe)
106275 -{
106276 - static const bool codes[] = {
106277 - /* 32 bit ALU operations */
106278 - [BPF_ALU | BPF_ADD | BPF_K] = true,
106279 - [BPF_ALU | BPF_ADD | BPF_X] = true,
106280 - [BPF_ALU | BPF_SUB | BPF_K] = true,
106281 - [BPF_ALU | BPF_SUB | BPF_X] = true,
106282 - [BPF_ALU | BPF_MUL | BPF_K] = true,
106283 - [BPF_ALU | BPF_MUL | BPF_X] = true,
106284 - [BPF_ALU | BPF_DIV | BPF_K] = true,
106285 - [BPF_ALU | BPF_DIV | BPF_X] = true,
106286 - [BPF_ALU | BPF_MOD | BPF_K] = true,
106287 - [BPF_ALU | BPF_MOD | BPF_X] = true,
106288 - [BPF_ALU | BPF_AND | BPF_K] = true,
106289 - [BPF_ALU | BPF_AND | BPF_X] = true,
106290 - [BPF_ALU | BPF_OR | BPF_K] = true,
106291 - [BPF_ALU | BPF_OR | BPF_X] = true,
106292 - [BPF_ALU | BPF_XOR | BPF_K] = true,
106293 - [BPF_ALU | BPF_XOR | BPF_X] = true,
106294 - [BPF_ALU | BPF_LSH | BPF_K] = true,
106295 - [BPF_ALU | BPF_LSH | BPF_X] = true,
106296 - [BPF_ALU | BPF_RSH | BPF_K] = true,
106297 - [BPF_ALU | BPF_RSH | BPF_X] = true,
106298 - [BPF_ALU | BPF_NEG] = true,
106299 - /* Load instructions */
106300 - [BPF_LD | BPF_W | BPF_ABS] = true,
106301 - [BPF_LD | BPF_H | BPF_ABS] = true,
106302 - [BPF_LD | BPF_B | BPF_ABS] = true,
106303 - [BPF_LD | BPF_W | BPF_LEN] = true,
106304 - [BPF_LD | BPF_W | BPF_IND] = true,
106305 - [BPF_LD | BPF_H | BPF_IND] = true,
106306 - [BPF_LD | BPF_B | BPF_IND] = true,
106307 - [BPF_LD | BPF_IMM] = true,
106308 - [BPF_LD | BPF_MEM] = true,
106309 - [BPF_LDX | BPF_W | BPF_LEN] = true,
106310 - [BPF_LDX | BPF_B | BPF_MSH] = true,
106311 - [BPF_LDX | BPF_IMM] = true,
106312 - [BPF_LDX | BPF_MEM] = true,
106313 - /* Store instructions */
106314 - [BPF_ST] = true,
106315 - [BPF_STX] = true,
106316 - /* Misc instructions */
106317 - [BPF_MISC | BPF_TAX] = true,
106318 - [BPF_MISC | BPF_TXA] = true,
106319 - /* Return instructions */
106320 - [BPF_RET | BPF_K] = true,
106321 - [BPF_RET | BPF_A] = true,
106322 - /* Jump instructions */
106323 - [BPF_JMP | BPF_JA] = true,
106324 - [BPF_JMP | BPF_JEQ | BPF_K] = true,
106325 - [BPF_JMP | BPF_JEQ | BPF_X] = true,
106326 - [BPF_JMP | BPF_JGE | BPF_K] = true,
106327 - [BPF_JMP | BPF_JGE | BPF_X] = true,
106328 - [BPF_JMP | BPF_JGT | BPF_K] = true,
106329 - [BPF_JMP | BPF_JGT | BPF_X] = true,
106330 - [BPF_JMP | BPF_JSET | BPF_K] = true,
106331 - [BPF_JMP | BPF_JSET | BPF_X] = true,
106332 - };
106333 -
106334 - if (code_to_probe >= ARRAY_SIZE(codes))
106335 - return false;
106336 -
106337 - return codes[code_to_probe];
106338 -}
106339 -
106340 /**
106341 * sk_chk_filter - verify socket filter code
106342 * @filter: filter to verify
106343 @@ -1229,303 +483,187 @@ static bool chk_code_allowed(u16 code_to_probe)
106344 */
106345 int sk_chk_filter(struct sock_filter *filter, unsigned int flen)
106346 {
106347 - bool anc_found;
106348 + /*
106349 + * Valid instructions are initialized to non-0.
106350 + * Invalid instructions are initialized to 0.
106351 + */
106352 + static const u8 codes[] = {
106353 + [BPF_ALU|BPF_ADD|BPF_K] = BPF_S_ALU_ADD_K,
106354 + [BPF_ALU|BPF_ADD|BPF_X] = BPF_S_ALU_ADD_X,
106355 + [BPF_ALU|BPF_SUB|BPF_K] = BPF_S_ALU_SUB_K,
106356 + [BPF_ALU|BPF_SUB|BPF_X] = BPF_S_ALU_SUB_X,
106357 + [BPF_ALU|BPF_MUL|BPF_K] = BPF_S_ALU_MUL_K,
106358 + [BPF_ALU|BPF_MUL|BPF_X] = BPF_S_ALU_MUL_X,
106359 + [BPF_ALU|BPF_DIV|BPF_X] = BPF_S_ALU_DIV_X,
106360 + [BPF_ALU|BPF_MOD|BPF_K] = BPF_S_ALU_MOD_K,
106361 + [BPF_ALU|BPF_MOD|BPF_X] = BPF_S_ALU_MOD_X,
106362 + [BPF_ALU|BPF_AND|BPF_K] = BPF_S_ALU_AND_K,
106363 + [BPF_ALU|BPF_AND|BPF_X] = BPF_S_ALU_AND_X,
106364 + [BPF_ALU|BPF_OR|BPF_K] = BPF_S_ALU_OR_K,
106365 + [BPF_ALU|BPF_OR|BPF_X] = BPF_S_ALU_OR_X,
106366 + [BPF_ALU|BPF_XOR|BPF_K] = BPF_S_ALU_XOR_K,
106367 + [BPF_ALU|BPF_XOR|BPF_X] = BPF_S_ALU_XOR_X,
106368 + [BPF_ALU|BPF_LSH|BPF_K] = BPF_S_ALU_LSH_K,
106369 + [BPF_ALU|BPF_LSH|BPF_X] = BPF_S_ALU_LSH_X,
106370 + [BPF_ALU|BPF_RSH|BPF_K] = BPF_S_ALU_RSH_K,
106371 + [BPF_ALU|BPF_RSH|BPF_X] = BPF_S_ALU_RSH_X,
106372 + [BPF_ALU|BPF_NEG] = BPF_S_ALU_NEG,
106373 + [BPF_LD|BPF_W|BPF_ABS] = BPF_S_LD_W_ABS,
106374 + [BPF_LD|BPF_H|BPF_ABS] = BPF_S_LD_H_ABS,
106375 + [BPF_LD|BPF_B|BPF_ABS] = BPF_S_LD_B_ABS,
106376 + [BPF_LD|BPF_W|BPF_LEN] = BPF_S_LD_W_LEN,
106377 + [BPF_LD|BPF_W|BPF_IND] = BPF_S_LD_W_IND,
106378 + [BPF_LD|BPF_H|BPF_IND] = BPF_S_LD_H_IND,
106379 + [BPF_LD|BPF_B|BPF_IND] = BPF_S_LD_B_IND,
106380 + [BPF_LD|BPF_IMM] = BPF_S_LD_IMM,
106381 + [BPF_LDX|BPF_W|BPF_LEN] = BPF_S_LDX_W_LEN,
106382 + [BPF_LDX|BPF_B|BPF_MSH] = BPF_S_LDX_B_MSH,
106383 + [BPF_LDX|BPF_IMM] = BPF_S_LDX_IMM,
106384 + [BPF_MISC|BPF_TAX] = BPF_S_MISC_TAX,
106385 + [BPF_MISC|BPF_TXA] = BPF_S_MISC_TXA,
106386 + [BPF_RET|BPF_K] = BPF_S_RET_K,
106387 + [BPF_RET|BPF_A] = BPF_S_RET_A,
106388 + [BPF_ALU|BPF_DIV|BPF_K] = BPF_S_ALU_DIV_K,
106389 + [BPF_LD|BPF_MEM] = BPF_S_LD_MEM,
106390 + [BPF_LDX|BPF_MEM] = BPF_S_LDX_MEM,
106391 + [BPF_ST] = BPF_S_ST,
106392 + [BPF_STX] = BPF_S_STX,
106393 + [BPF_JMP|BPF_JA] = BPF_S_JMP_JA,
106394 + [BPF_JMP|BPF_JEQ|BPF_K] = BPF_S_JMP_JEQ_K,
106395 + [BPF_JMP|BPF_JEQ|BPF_X] = BPF_S_JMP_JEQ_X,
106396 + [BPF_JMP|BPF_JGE|BPF_K] = BPF_S_JMP_JGE_K,
106397 + [BPF_JMP|BPF_JGE|BPF_X] = BPF_S_JMP_JGE_X,
106398 + [BPF_JMP|BPF_JGT|BPF_K] = BPF_S_JMP_JGT_K,
106399 + [BPF_JMP|BPF_JGT|BPF_X] = BPF_S_JMP_JGT_X,
106400 + [BPF_JMP|BPF_JSET|BPF_K] = BPF_S_JMP_JSET_K,
106401 + [BPF_JMP|BPF_JSET|BPF_X] = BPF_S_JMP_JSET_X,
106402 + };
106403 int pc;
106404 + bool anc_found;
106405
106406 if (flen == 0 || flen > BPF_MAXINSNS)
106407 return -EINVAL;
106408
106409 - /* Check the filter code now */
106410 + /* check the filter code now */
106411 for (pc = 0; pc < flen; pc++) {
106412 struct sock_filter *ftest = &filter[pc];
106413 + u16 code = ftest->code;
106414
106415 - /* May we actually operate on this code? */
106416 - if (!chk_code_allowed(ftest->code))
106417 + if (code >= ARRAY_SIZE(codes))
106418 + return -EINVAL;
106419 + code = codes[code];
106420 + if (!code)
106421 return -EINVAL;
106422 -
106423 /* Some instructions need special checks */
106424 - switch (ftest->code) {
106425 - case BPF_ALU | BPF_DIV | BPF_K:
106426 - case BPF_ALU | BPF_MOD | BPF_K:
106427 - /* Check for division by zero */
106428 + switch (code) {
106429 + case BPF_S_ALU_DIV_K:
106430 + case BPF_S_ALU_MOD_K:
106431 + /* check for division by zero */
106432 if (ftest->k == 0)
106433 return -EINVAL;
106434 break;
106435 - case BPF_LD | BPF_MEM:
106436 - case BPF_LDX | BPF_MEM:
106437 - case BPF_ST:
106438 - case BPF_STX:
106439 - /* Check for invalid memory addresses */
106440 + case BPF_S_LD_MEM:
106441 + case BPF_S_LDX_MEM:
106442 + case BPF_S_ST:
106443 + case BPF_S_STX:
106444 + /* check for invalid memory addresses */
106445 if (ftest->k >= BPF_MEMWORDS)
106446 return -EINVAL;
106447 break;
106448 - case BPF_JMP | BPF_JA:
106449 - /* Note, the large ftest->k might cause loops.
106450 + case BPF_S_JMP_JA:
106451 + /*
106452 + * Note, the large ftest->k might cause loops.
106453 * Compare this with conditional jumps below,
106454 * where offsets are limited. --ANK (981016)
106455 */
106456 - if (ftest->k >= (unsigned int)(flen - pc - 1))
106457 + if (ftest->k >= (unsigned int)(flen-pc-1))
106458 return -EINVAL;
106459 break;
106460 - case BPF_JMP | BPF_JEQ | BPF_K:
106461 - case BPF_JMP | BPF_JEQ | BPF_X:
106462 - case BPF_JMP | BPF_JGE | BPF_K:
106463 - case BPF_JMP | BPF_JGE | BPF_X:
106464 - case BPF_JMP | BPF_JGT | BPF_K:
106465 - case BPF_JMP | BPF_JGT | BPF_X:
106466 - case BPF_JMP | BPF_JSET | BPF_K:
106467 - case BPF_JMP | BPF_JSET | BPF_X:
106468 - /* Both conditionals must be safe */
106469 + case BPF_S_JMP_JEQ_K:
106470 + case BPF_S_JMP_JEQ_X:
106471 + case BPF_S_JMP_JGE_K:
106472 + case BPF_S_JMP_JGE_X:
106473 + case BPF_S_JMP_JGT_K:
106474 + case BPF_S_JMP_JGT_X:
106475 + case BPF_S_JMP_JSET_X:
106476 + case BPF_S_JMP_JSET_K:
106477 + /* for conditionals both must be safe */
106478 if (pc + ftest->jt + 1 >= flen ||
106479 pc + ftest->jf + 1 >= flen)
106480 return -EINVAL;
106481 break;
106482 - case BPF_LD | BPF_W | BPF_ABS:
106483 - case BPF_LD | BPF_H | BPF_ABS:
106484 - case BPF_LD | BPF_B | BPF_ABS:
106485 + case BPF_S_LD_W_ABS:
106486 + case BPF_S_LD_H_ABS:
106487 + case BPF_S_LD_B_ABS:
106488 anc_found = false;
106489 - if (bpf_anc_helper(ftest) & BPF_ANC)
106490 - anc_found = true;
106491 - /* Ancillary operation unknown or unsupported */
106492 +#define ANCILLARY(CODE) case SKF_AD_OFF + SKF_AD_##CODE: \
106493 + code = BPF_S_ANC_##CODE; \
106494 + anc_found = true; \
106495 + break
106496 + switch (ftest->k) {
106497 + ANCILLARY(PROTOCOL);
106498 + ANCILLARY(PKTTYPE);
106499 + ANCILLARY(IFINDEX);
106500 + ANCILLARY(NLATTR);
106501 + ANCILLARY(NLATTR_NEST);
106502 + ANCILLARY(MARK);
106503 + ANCILLARY(QUEUE);
106504 + ANCILLARY(HATYPE);
106505 + ANCILLARY(RXHASH);
106506 + ANCILLARY(CPU);
106507 + ANCILLARY(ALU_XOR_X);
106508 + ANCILLARY(VLAN_TAG);
106509 + ANCILLARY(VLAN_TAG_PRESENT);
106510 + ANCILLARY(PAY_OFFSET);
106511 + }
106512 +
106513 + /* ancillary operation unknown or unsupported */
106514 if (anc_found == false && ftest->k >= SKF_AD_OFF)
106515 return -EINVAL;
106516 }
106517 + ftest->code = code;
106518 }
106519
106520 - /* Last instruction must be a RET code */
106521 + /* last instruction must be a RET code */
106522 switch (filter[flen - 1].code) {
106523 - case BPF_RET | BPF_K:
106524 - case BPF_RET | BPF_A:
106525 + case BPF_S_RET_K:
106526 + case BPF_S_RET_A:
106527 return check_load_and_stores(filter, flen);
106528 }
106529 -
106530 return -EINVAL;
106531 }
106532 EXPORT_SYMBOL(sk_chk_filter);
106533
106534 -static int sk_store_orig_filter(struct sk_filter *fp,
106535 - const struct sock_fprog *fprog)
106536 -{
106537 - unsigned int fsize = sk_filter_proglen(fprog);
106538 - struct sock_fprog_kern *fkprog;
106539 -
106540 - fp->orig_prog = kmalloc(sizeof(*fkprog), GFP_KERNEL);
106541 - if (!fp->orig_prog)
106542 - return -ENOMEM;
106543 -
106544 - fkprog = fp->orig_prog;
106545 - fkprog->len = fprog->len;
106546 - fkprog->filter = kmemdup(fp->insns, fsize, GFP_KERNEL);
106547 - if (!fkprog->filter) {
106548 - kfree(fp->orig_prog);
106549 - return -ENOMEM;
106550 - }
106551 -
106552 - return 0;
106553 -}
106554 -
106555 -static void sk_release_orig_filter(struct sk_filter *fp)
106556 -{
106557 - struct sock_fprog_kern *fprog = fp->orig_prog;
106558 -
106559 - if (fprog) {
106560 - kfree(fprog->filter);
106561 - kfree(fprog);
106562 - }
106563 -}
106564 -
106565 /**
106566 * sk_filter_release_rcu - Release a socket filter by rcu_head
106567 * @rcu: rcu_head that contains the sk_filter to free
106568 */
106569 -static void sk_filter_release_rcu(struct rcu_head *rcu)
106570 +void sk_filter_release_rcu(struct rcu_head *rcu)
106571 {
106572 struct sk_filter *fp = container_of(rcu, struct sk_filter, rcu);
106573
106574 - sk_release_orig_filter(fp);
106575 - sk_filter_free(fp);
106576 -}
106577 -
106578 -/**
106579 - * sk_filter_release - release a socket filter
106580 - * @fp: filter to remove
106581 - *
106582 - * Remove a filter from a socket and release its resources.
106583 - */
106584 -static void sk_filter_release(struct sk_filter *fp)
106585 -{
106586 - if (atomic_dec_and_test(&fp->refcnt))
106587 - call_rcu(&fp->rcu, sk_filter_release_rcu);
106588 -}
106589 -
106590 -void sk_filter_uncharge(struct sock *sk, struct sk_filter *fp)
106591 -{
106592 - atomic_sub(sk_filter_size(fp->len), &sk->sk_omem_alloc);
106593 - sk_filter_release(fp);
106594 -}
106595 -
106596 -void sk_filter_charge(struct sock *sk, struct sk_filter *fp)
106597 -{
106598 - atomic_inc(&fp->refcnt);
106599 - atomic_add(sk_filter_size(fp->len), &sk->sk_omem_alloc);
106600 -}
106601 -
106602 -static struct sk_filter *__sk_migrate_realloc(struct sk_filter *fp,
106603 - struct sock *sk,
106604 - unsigned int len)
106605 -{
106606 - struct sk_filter *fp_new;
106607 -
106608 - if (sk == NULL)
106609 - return krealloc(fp, len, GFP_KERNEL);
106610 -
106611 - fp_new = sock_kmalloc(sk, len, GFP_KERNEL);
106612 - if (fp_new) {
106613 - *fp_new = *fp;
106614 - /* As we're keeping orig_prog in fp_new along,
106615 - * we need to make sure we're not evicting it
106616 - * from the old fp.
106617 - */
106618 - fp->orig_prog = NULL;
106619 - sk_filter_uncharge(sk, fp);
106620 - }
106621 -
106622 - return fp_new;
106623 -}
106624 -
106625 -static struct sk_filter *__sk_migrate_filter(struct sk_filter *fp,
106626 - struct sock *sk)
106627 -{
106628 - struct sock_filter *old_prog;
106629 - struct sk_filter *old_fp;
106630 - int err, new_len, old_len = fp->len;
106631 -
106632 - /* We are free to overwrite insns et al right here as it
106633 - * won't be used at this point in time anymore internally
106634 - * after the migration to the internal BPF instruction
106635 - * representation.
106636 - */
106637 - BUILD_BUG_ON(sizeof(struct sock_filter) !=
106638 - sizeof(struct sock_filter_int));
106639 -
106640 - /* Conversion cannot happen on overlapping memory areas,
106641 - * so we need to keep the user BPF around until the 2nd
106642 - * pass. At this time, the user BPF is stored in fp->insns.
106643 - */
106644 - old_prog = kmemdup(fp->insns, old_len * sizeof(struct sock_filter),
106645 - GFP_KERNEL);
106646 - if (!old_prog) {
106647 - err = -ENOMEM;
106648 - goto out_err;
106649 - }
106650 -
106651 - /* 1st pass: calculate the new program length. */
106652 - err = sk_convert_filter(old_prog, old_len, NULL, &new_len);
106653 - if (err)
106654 - goto out_err_free;
106655 -
106656 - /* Expand fp for appending the new filter representation. */
106657 - old_fp = fp;
106658 - fp = __sk_migrate_realloc(old_fp, sk, sk_filter_size(new_len));
106659 - if (!fp) {
106660 - /* The old_fp is still around in case we couldn't
106661 - * allocate new memory, so uncharge on that one.
106662 - */
106663 - fp = old_fp;
106664 - err = -ENOMEM;
106665 - goto out_err_free;
106666 - }
106667 -
106668 - fp->len = new_len;
106669 -
106670 - /* 2nd pass: remap sock_filter insns into sock_filter_int insns. */
106671 - err = sk_convert_filter(old_prog, old_len, fp->insnsi, &new_len);
106672 - if (err)
106673 - /* 2nd sk_convert_filter() can fail only if it fails
106674 - * to allocate memory, remapping must succeed. Note,
106675 - * that at this time old_fp has already been released
106676 - * by __sk_migrate_realloc().
106677 - */
106678 - goto out_err_free;
106679 -
106680 - sk_filter_select_runtime(fp);
106681 -
106682 - kfree(old_prog);
106683 - return fp;
106684 -
106685 -out_err_free:
106686 - kfree(old_prog);
106687 -out_err:
106688 - /* Rollback filter setup. */
106689 - if (sk != NULL)
106690 - sk_filter_uncharge(sk, fp);
106691 - else
106692 - kfree(fp);
106693 - return ERR_PTR(err);
106694 -}
106695 -
106696 -void __weak bpf_int_jit_compile(struct sk_filter *prog)
106697 -{
106698 -}
106699 -
106700 -/**
106701 - * sk_filter_select_runtime - select execution runtime for BPF program
106702 - * @fp: sk_filter populated with internal BPF program
106703 - *
106704 - * try to JIT internal BPF program, if JIT is not available select interpreter
106705 - * BPF program will be executed via SK_RUN_FILTER() macro
106706 - */
106707 -void sk_filter_select_runtime(struct sk_filter *fp)
106708 -{
106709 - fp->bpf_func = (void *) __sk_run_filter;
106710 -
106711 - /* Probe if internal BPF can be JITed */
106712 - bpf_int_jit_compile(fp);
106713 -}
106714 -EXPORT_SYMBOL_GPL(sk_filter_select_runtime);
106715 -
106716 -/* free internal BPF program */
106717 -void sk_filter_free(struct sk_filter *fp)
106718 -{
106719 bpf_jit_free(fp);
106720 }
106721 -EXPORT_SYMBOL_GPL(sk_filter_free);
106722 +EXPORT_SYMBOL(sk_filter_release_rcu);
106723
106724 -static struct sk_filter *__sk_prepare_filter(struct sk_filter *fp,
106725 - struct sock *sk)
106726 +static int __sk_prepare_filter(struct sk_filter *fp)
106727 {
106728 int err;
106729
106730 - fp->bpf_func = NULL;
106731 - fp->jited = 0;
106732 + fp->bpf_func = sk_run_filter;
106733
106734 err = sk_chk_filter(fp->insns, fp->len);
106735 - if (err) {
106736 - if (sk != NULL)
106737 - sk_filter_uncharge(sk, fp);
106738 - else
106739 - kfree(fp);
106740 - return ERR_PTR(err);
106741 - }
106742 + if (err)
106743 + return err;
106744
106745 - /* Probe if we can JIT compile the filter and if so, do
106746 - * the compilation of the filter.
106747 - */
106748 bpf_jit_compile(fp);
106749 -
106750 - /* JIT compiler couldn't process this filter, so do the
106751 - * internal BPF translation for the optimized interpreter.
106752 - */
106753 - if (!fp->jited)
106754 - fp = __sk_migrate_filter(fp, sk);
106755 -
106756 - return fp;
106757 + return 0;
106758 }
106759
106760 /**
106761 * sk_unattached_filter_create - create an unattached filter
106762 + * @fprog: the filter program
106763 * @pfp: the unattached filter that is created
106764 - * @fprog: the filter program
106765 *
106766 * Create a filter independent of any socket. We first run some
106767 * sanity checks on it to make sure it does not explode on us later.
106768 @@ -1533,10 +671,11 @@ static struct sk_filter *__sk_prepare_filter(struct sk_filter *fp,
106769 * a negative errno code is returned. On success the return is zero.
106770 */
106771 int sk_unattached_filter_create(struct sk_filter **pfp,
106772 - struct sock_fprog_kern *fprog)
106773 + struct sock_fprog *fprog)
106774 {
106775 - unsigned int fsize = sk_filter_proglen(fprog);
106776 struct sk_filter *fp;
106777 + unsigned int fsize = sizeof(struct sock_filter) * fprog->len;
106778 + int err;
106779
106780 /* Make sure new filter is there and in the right amounts. */
106781 if (fprog->filter == NULL)
106782 @@ -1545,26 +684,20 @@ int sk_unattached_filter_create(struct sk_filter **pfp,
106783 fp = kmalloc(sk_filter_size(fprog->len), GFP_KERNEL);
106784 if (!fp)
106785 return -ENOMEM;
106786 -
106787 - memcpy(fp->insns, fprog->filter, fsize);
106788 + memcpy(fp->insns, (void __force_kernel *)fprog->filter, fsize);
106789
106790 atomic_set(&fp->refcnt, 1);
106791 fp->len = fprog->len;
106792 - /* Since unattached filters are not copied back to user
106793 - * space through sk_get_filter(), we do not need to hold
106794 - * a copy here, and can spare us the work.
106795 - */
106796 - fp->orig_prog = NULL;
106797
106798 - /* __sk_prepare_filter() already takes care of uncharging
106799 - * memory in case something goes wrong.
106800 - */
106801 - fp = __sk_prepare_filter(fp, NULL);
106802 - if (IS_ERR(fp))
106803 - return PTR_ERR(fp);
106804 + err = __sk_prepare_filter(fp);
106805 + if (err)
106806 + goto free_mem;
106807
106808 *pfp = fp;
106809 return 0;
106810 +free_mem:
106811 + kfree(fp);
106812 + return err;
106813 }
106814 EXPORT_SYMBOL_GPL(sk_unattached_filter_create);
106815
106816 @@ -1587,7 +720,7 @@ EXPORT_SYMBOL_GPL(sk_unattached_filter_destroy);
106817 int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk)
106818 {
106819 struct sk_filter *fp, *old_fp;
106820 - unsigned int fsize = sk_filter_proglen(fprog);
106821 + unsigned int fsize = sizeof(struct sock_filter) * fprog->len;
106822 unsigned int sk_fsize = sk_filter_size(fprog->len);
106823 int err;
106824
106825 @@ -1601,7 +734,6 @@ int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk)
106826 fp = sock_kmalloc(sk, sk_fsize, GFP_KERNEL);
106827 if (!fp)
106828 return -ENOMEM;
106829 -
106830 if (copy_from_user(fp->insns, fprog->filter, fsize)) {
106831 sock_kfree_s(sk, fp, sk_fsize);
106832 return -EFAULT;
106833 @@ -1610,26 +742,18 @@ int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk)
106834 atomic_set(&fp->refcnt, 1);
106835 fp->len = fprog->len;
106836
106837 - err = sk_store_orig_filter(fp, fprog);
106838 + err = __sk_prepare_filter(fp);
106839 if (err) {
106840 sk_filter_uncharge(sk, fp);
106841 - return -ENOMEM;
106842 + return err;
106843 }
106844
106845 - /* __sk_prepare_filter() already takes care of uncharging
106846 - * memory in case something goes wrong.
106847 - */
106848 - fp = __sk_prepare_filter(fp, sk);
106849 - if (IS_ERR(fp))
106850 - return PTR_ERR(fp);
106851 -
106852 old_fp = rcu_dereference_protected(sk->sk_filter,
106853 sock_owned_by_user(sk));
106854 rcu_assign_pointer(sk->sk_filter, fp);
106855
106856 if (old_fp)
106857 sk_filter_uncharge(sk, old_fp);
106858 -
106859 return 0;
106860 }
106861 EXPORT_SYMBOL_GPL(sk_attach_filter);
106862 @@ -1649,46 +773,116 @@ int sk_detach_filter(struct sock *sk)
106863 sk_filter_uncharge(sk, filter);
106864 ret = 0;
106865 }
106866 -
106867 return ret;
106868 }
106869 EXPORT_SYMBOL_GPL(sk_detach_filter);
106870
106871 -int sk_get_filter(struct sock *sk, struct sock_filter __user *ubuf,
106872 - unsigned int len)
106873 +void sk_decode_filter(struct sock_filter *filt, struct sock_filter *to)
106874 +{
106875 + static const u16 decodes[] = {
106876 + [BPF_S_ALU_ADD_K] = BPF_ALU|BPF_ADD|BPF_K,
106877 + [BPF_S_ALU_ADD_X] = BPF_ALU|BPF_ADD|BPF_X,
106878 + [BPF_S_ALU_SUB_K] = BPF_ALU|BPF_SUB|BPF_K,
106879 + [BPF_S_ALU_SUB_X] = BPF_ALU|BPF_SUB|BPF_X,
106880 + [BPF_S_ALU_MUL_K] = BPF_ALU|BPF_MUL|BPF_K,
106881 + [BPF_S_ALU_MUL_X] = BPF_ALU|BPF_MUL|BPF_X,
106882 + [BPF_S_ALU_DIV_X] = BPF_ALU|BPF_DIV|BPF_X,
106883 + [BPF_S_ALU_MOD_K] = BPF_ALU|BPF_MOD|BPF_K,
106884 + [BPF_S_ALU_MOD_X] = BPF_ALU|BPF_MOD|BPF_X,
106885 + [BPF_S_ALU_AND_K] = BPF_ALU|BPF_AND|BPF_K,
106886 + [BPF_S_ALU_AND_X] = BPF_ALU|BPF_AND|BPF_X,
106887 + [BPF_S_ALU_OR_K] = BPF_ALU|BPF_OR|BPF_K,
106888 + [BPF_S_ALU_OR_X] = BPF_ALU|BPF_OR|BPF_X,
106889 + [BPF_S_ALU_XOR_K] = BPF_ALU|BPF_XOR|BPF_K,
106890 + [BPF_S_ALU_XOR_X] = BPF_ALU|BPF_XOR|BPF_X,
106891 + [BPF_S_ALU_LSH_K] = BPF_ALU|BPF_LSH|BPF_K,
106892 + [BPF_S_ALU_LSH_X] = BPF_ALU|BPF_LSH|BPF_X,
106893 + [BPF_S_ALU_RSH_K] = BPF_ALU|BPF_RSH|BPF_K,
106894 + [BPF_S_ALU_RSH_X] = BPF_ALU|BPF_RSH|BPF_X,
106895 + [BPF_S_ALU_NEG] = BPF_ALU|BPF_NEG,
106896 + [BPF_S_LD_W_ABS] = BPF_LD|BPF_W|BPF_ABS,
106897 + [BPF_S_LD_H_ABS] = BPF_LD|BPF_H|BPF_ABS,
106898 + [BPF_S_LD_B_ABS] = BPF_LD|BPF_B|BPF_ABS,
106899 + [BPF_S_ANC_PROTOCOL] = BPF_LD|BPF_B|BPF_ABS,
106900 + [BPF_S_ANC_PKTTYPE] = BPF_LD|BPF_B|BPF_ABS,
106901 + [BPF_S_ANC_IFINDEX] = BPF_LD|BPF_B|BPF_ABS,
106902 + [BPF_S_ANC_NLATTR] = BPF_LD|BPF_B|BPF_ABS,
106903 + [BPF_S_ANC_NLATTR_NEST] = BPF_LD|BPF_B|BPF_ABS,
106904 + [BPF_S_ANC_MARK] = BPF_LD|BPF_B|BPF_ABS,
106905 + [BPF_S_ANC_QUEUE] = BPF_LD|BPF_B|BPF_ABS,
106906 + [BPF_S_ANC_HATYPE] = BPF_LD|BPF_B|BPF_ABS,
106907 + [BPF_S_ANC_RXHASH] = BPF_LD|BPF_B|BPF_ABS,
106908 + [BPF_S_ANC_CPU] = BPF_LD|BPF_B|BPF_ABS,
106909 + [BPF_S_ANC_ALU_XOR_X] = BPF_LD|BPF_B|BPF_ABS,
106910 + [BPF_S_ANC_SECCOMP_LD_W] = BPF_LD|BPF_B|BPF_ABS,
106911 + [BPF_S_ANC_VLAN_TAG] = BPF_LD|BPF_B|BPF_ABS,
106912 + [BPF_S_ANC_VLAN_TAG_PRESENT] = BPF_LD|BPF_B|BPF_ABS,
106913 + [BPF_S_ANC_PAY_OFFSET] = BPF_LD|BPF_B|BPF_ABS,
106914 + [BPF_S_LD_W_LEN] = BPF_LD|BPF_W|BPF_LEN,
106915 + [BPF_S_LD_W_IND] = BPF_LD|BPF_W|BPF_IND,
106916 + [BPF_S_LD_H_IND] = BPF_LD|BPF_H|BPF_IND,
106917 + [BPF_S_LD_B_IND] = BPF_LD|BPF_B|BPF_IND,
106918 + [BPF_S_LD_IMM] = BPF_LD|BPF_IMM,
106919 + [BPF_S_LDX_W_LEN] = BPF_LDX|BPF_W|BPF_LEN,
106920 + [BPF_S_LDX_B_MSH] = BPF_LDX|BPF_B|BPF_MSH,
106921 + [BPF_S_LDX_IMM] = BPF_LDX|BPF_IMM,
106922 + [BPF_S_MISC_TAX] = BPF_MISC|BPF_TAX,
106923 + [BPF_S_MISC_TXA] = BPF_MISC|BPF_TXA,
106924 + [BPF_S_RET_K] = BPF_RET|BPF_K,
106925 + [BPF_S_RET_A] = BPF_RET|BPF_A,
106926 + [BPF_S_ALU_DIV_K] = BPF_ALU|BPF_DIV|BPF_K,
106927 + [BPF_S_LD_MEM] = BPF_LD|BPF_MEM,
106928 + [BPF_S_LDX_MEM] = BPF_LDX|BPF_MEM,
106929 + [BPF_S_ST] = BPF_ST,
106930 + [BPF_S_STX] = BPF_STX,
106931 + [BPF_S_JMP_JA] = BPF_JMP|BPF_JA,
106932 + [BPF_S_JMP_JEQ_K] = BPF_JMP|BPF_JEQ|BPF_K,
106933 + [BPF_S_JMP_JEQ_X] = BPF_JMP|BPF_JEQ|BPF_X,
106934 + [BPF_S_JMP_JGE_K] = BPF_JMP|BPF_JGE|BPF_K,
106935 + [BPF_S_JMP_JGE_X] = BPF_JMP|BPF_JGE|BPF_X,
106936 + [BPF_S_JMP_JGT_K] = BPF_JMP|BPF_JGT|BPF_K,
106937 + [BPF_S_JMP_JGT_X] = BPF_JMP|BPF_JGT|BPF_X,
106938 + [BPF_S_JMP_JSET_K] = BPF_JMP|BPF_JSET|BPF_K,
106939 + [BPF_S_JMP_JSET_X] = BPF_JMP|BPF_JSET|BPF_X,
106940 + };
106941 + u16 code;
106942 +
106943 + code = filt->code;
106944 +
106945 + to->code = decodes[code];
106946 + to->jt = filt->jt;
106947 + to->jf = filt->jf;
106948 + to->k = filt->k;
106949 +}
106950 +
106951 +int sk_get_filter(struct sock *sk, struct sock_filter __user *ubuf, unsigned int len)
106952 {
106953 - struct sock_fprog_kern *fprog;
106954 struct sk_filter *filter;
106955 - int ret = 0;
106956 + int i, ret;
106957
106958 lock_sock(sk);
106959 filter = rcu_dereference_protected(sk->sk_filter,
106960 - sock_owned_by_user(sk));
106961 + sock_owned_by_user(sk));
106962 + ret = 0;
106963 if (!filter)
106964 goto out;
106965 -
106966 - /* We're copying the filter that has been originally attached,
106967 - * so no conversion/decode needed anymore.
106968 - */
106969 - fprog = filter->orig_prog;
106970 -
106971 - ret = fprog->len;
106972 + ret = filter->len;
106973 if (!len)
106974 - /* User space only enquires number of filter blocks. */
106975 goto out;
106976 -
106977 ret = -EINVAL;
106978 - if (len < fprog->len)
106979 + if (len < filter->len)
106980 goto out;
106981
106982 ret = -EFAULT;
106983 - if (copy_to_user(ubuf, fprog->filter, sk_filter_proglen(fprog)))
106984 - goto out;
106985 + for (i = 0; i < filter->len; i++) {
106986 + struct sock_filter fb;
106987
106988 - /* Instead of bytes, the API requests to return the number
106989 - * of filter blocks.
106990 - */
106991 - ret = fprog->len;
106992 + sk_decode_filter(&filter->insns[i], &fb);
106993 + if (copy_to_user(&ubuf[i], &fb, sizeof(fb)))
106994 + goto out;
106995 + }
106996 +
106997 + ret = filter->len;
106998 out:
106999 release_sock(sk);
107000 return ret;
107001 diff --git a/net/core/flow.c b/net/core/flow.c
107002 index a0348fd..6951c76 100644
107003 --- a/net/core/flow.c
107004 +++ b/net/core/flow.c
107005 @@ -65,7 +65,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
107006 static int flow_entry_valid(struct flow_cache_entry *fle,
107007 struct netns_xfrm *xfrm)
107008 {
107009 - if (atomic_read(&xfrm->flow_cache_genid) != fle->genid)
107010 + if (atomic_read_unchecked(&xfrm->flow_cache_genid) != fle->genid)
107011 return 0;
107012 if (fle->object && !fle->object->ops->check(fle->object))
107013 return 0;
107014 @@ -242,7 +242,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
107015 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
107016 fcp->hash_count++;
107017 }
107018 - } else if (likely(fle->genid == atomic_read(&net->xfrm.flow_cache_genid))) {
107019 + } else if (likely(fle->genid == atomic_read_unchecked(&net->xfrm.flow_cache_genid))) {
107020 flo = fle->object;
107021 if (!flo)
107022 goto ret_object;
107023 @@ -263,7 +263,7 @@ nocache:
107024 }
107025 flo = resolver(net, key, family, dir, flo, ctx);
107026 if (fle) {
107027 - fle->genid = atomic_read(&net->xfrm.flow_cache_genid);
107028 + fle->genid = atomic_read_unchecked(&net->xfrm.flow_cache_genid);
107029 if (!IS_ERR(flo))
107030 fle->object = flo;
107031 else
107032 diff --git a/net/core/iovec.c b/net/core/iovec.c
107033 index e1ec45a..e5c6f16 100644
107034 --- a/net/core/iovec.c
107035 +++ b/net/core/iovec.c
107036 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
107037 if (m->msg_name && m->msg_namelen) {
107038 if (mode == VERIFY_READ) {
107039 void __user *namep;
107040 - namep = (void __user __force *) m->msg_name;
107041 + namep = (void __force_user *) m->msg_name;
107042 err = move_addr_to_kernel(namep, m->msg_namelen,
107043 address);
107044 if (err < 0)
107045 @@ -55,7 +55,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
107046 }
107047
107048 size = m->msg_iovlen * sizeof(struct iovec);
107049 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
107050 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
107051 return -EFAULT;
107052
107053 m->msg_iov = iov;
107054 diff --git a/net/core/neighbour.c b/net/core/neighbour.c
107055 index ef31fef..8be66d9 100644
107056 --- a/net/core/neighbour.c
107057 +++ b/net/core/neighbour.c
107058 @@ -2825,7 +2825,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
107059 void __user *buffer, size_t *lenp, loff_t *ppos)
107060 {
107061 int size, ret;
107062 - struct ctl_table tmp = *ctl;
107063 + ctl_table_no_const tmp = *ctl;
107064
107065 tmp.extra1 = &zero;
107066 tmp.extra2 = &unres_qlen_max;
107067 @@ -2887,7 +2887,7 @@ static int neigh_proc_dointvec_zero_intmax(struct ctl_table *ctl, int write,
107068 void __user *buffer,
107069 size_t *lenp, loff_t *ppos)
107070 {
107071 - struct ctl_table tmp = *ctl;
107072 + ctl_table_no_const tmp = *ctl;
107073 int ret;
107074
107075 tmp.extra1 = &zero;
107076 diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
107077 index 2bf8329..2eb1423 100644
107078 --- a/net/core/net-procfs.c
107079 +++ b/net/core/net-procfs.c
107080 @@ -79,7 +79,13 @@ static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
107081 struct rtnl_link_stats64 temp;
107082 const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
107083
107084 - seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
107085 + if (gr_proc_is_restricted())
107086 + seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
107087 + "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
107088 + dev->name, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL,
107089 + 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL);
107090 + else
107091 + seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
107092 "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
107093 dev->name, stats->rx_bytes, stats->rx_packets,
107094 stats->rx_errors,
107095 @@ -166,7 +172,7 @@ static int softnet_seq_show(struct seq_file *seq, void *v)
107096 return 0;
107097 }
107098
107099 -static const struct seq_operations dev_seq_ops = {
107100 +const struct seq_operations dev_seq_ops = {
107101 .start = dev_seq_start,
107102 .next = dev_seq_next,
107103 .stop = dev_seq_stop,
107104 @@ -196,7 +202,7 @@ static const struct seq_operations softnet_seq_ops = {
107105
107106 static int softnet_seq_open(struct inode *inode, struct file *file)
107107 {
107108 - return seq_open(file, &softnet_seq_ops);
107109 + return seq_open_restrict(file, &softnet_seq_ops);
107110 }
107111
107112 static const struct file_operations softnet_seq_fops = {
107113 @@ -283,8 +289,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
107114 else
107115 seq_printf(seq, "%04x", ntohs(pt->type));
107116
107117 +#ifdef CONFIG_GRKERNSEC_HIDESYM
107118 + seq_printf(seq, " %-8s %pf\n",
107119 + pt->dev ? pt->dev->name : "", NULL);
107120 +#else
107121 seq_printf(seq, " %-8s %pf\n",
107122 pt->dev ? pt->dev->name : "", pt->func);
107123 +#endif
107124 }
107125
107126 return 0;
107127 diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
107128 index 1cac29e..fb482f3 100644
107129 --- a/net/core/net-sysfs.c
107130 +++ b/net/core/net-sysfs.c
107131 @@ -259,7 +259,7 @@ static ssize_t carrier_changes_show(struct device *dev,
107132 {
107133 struct net_device *netdev = to_net_dev(dev);
107134 return sprintf(buf, fmt_dec,
107135 - atomic_read(&netdev->carrier_changes));
107136 + atomic_read_unchecked(&netdev->carrier_changes));
107137 }
107138 static DEVICE_ATTR_RO(carrier_changes);
107139
107140 diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
107141 index 85b6269..fc77ea0 100644
107142 --- a/net/core/net_namespace.c
107143 +++ b/net/core/net_namespace.c
107144 @@ -443,7 +443,7 @@ static int __register_pernet_operations(struct list_head *list,
107145 int error;
107146 LIST_HEAD(net_exit_list);
107147
107148 - list_add_tail(&ops->list, list);
107149 + pax_list_add_tail((struct list_head *)&ops->list, list);
107150 if (ops->init || (ops->id && ops->size)) {
107151 for_each_net(net) {
107152 error = ops_init(ops, net);
107153 @@ -456,7 +456,7 @@ static int __register_pernet_operations(struct list_head *list,
107154
107155 out_undo:
107156 /* If I have an error cleanup all namespaces I initialized */
107157 - list_del(&ops->list);
107158 + pax_list_del((struct list_head *)&ops->list);
107159 ops_exit_list(ops, &net_exit_list);
107160 ops_free_list(ops, &net_exit_list);
107161 return error;
107162 @@ -467,7 +467,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
107163 struct net *net;
107164 LIST_HEAD(net_exit_list);
107165
107166 - list_del(&ops->list);
107167 + pax_list_del((struct list_head *)&ops->list);
107168 for_each_net(net)
107169 list_add_tail(&net->exit_list, &net_exit_list);
107170 ops_exit_list(ops, &net_exit_list);
107171 @@ -601,7 +601,7 @@ int register_pernet_device(struct pernet_operations *ops)
107172 mutex_lock(&net_mutex);
107173 error = register_pernet_operations(&pernet_list, ops);
107174 if (!error && (first_device == &pernet_list))
107175 - first_device = &ops->list;
107176 + first_device = (struct list_head *)&ops->list;
107177 mutex_unlock(&net_mutex);
107178 return error;
107179 }
107180 diff --git a/net/core/netpoll.c b/net/core/netpoll.c
107181 index e33937f..b2b4981 100644
107182 --- a/net/core/netpoll.c
107183 +++ b/net/core/netpoll.c
107184 @@ -382,7 +382,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
107185 struct udphdr *udph;
107186 struct iphdr *iph;
107187 struct ethhdr *eth;
107188 - static atomic_t ip_ident;
107189 + static atomic_unchecked_t ip_ident;
107190 struct ipv6hdr *ip6h;
107191
107192 udp_len = len + sizeof(*udph);
107193 @@ -453,7 +453,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
107194 put_unaligned(0x45, (unsigned char *)iph);
107195 iph->tos = 0;
107196 put_unaligned(htons(ip_len), &(iph->tot_len));
107197 - iph->id = htons(atomic_inc_return(&ip_ident));
107198 + iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
107199 iph->frag_off = 0;
107200 iph->ttl = 64;
107201 iph->protocol = IPPROTO_UDP;
107202 diff --git a/net/core/pktgen.c b/net/core/pktgen.c
107203 index fc17a9d..d4a3d88 100644
107204 --- a/net/core/pktgen.c
107205 +++ b/net/core/pktgen.c
107206 @@ -3725,7 +3725,7 @@ static int __net_init pg_net_init(struct net *net)
107207 pn->net = net;
107208 INIT_LIST_HEAD(&pn->pktgen_threads);
107209 pn->pktgen_exiting = false;
107210 - pn->proc_dir = proc_mkdir(PG_PROC_DIR, pn->net->proc_net);
107211 + pn->proc_dir = proc_mkdir_restrict(PG_PROC_DIR, pn->net->proc_net);
107212 if (!pn->proc_dir) {
107213 pr_warn("cannot create /proc/net/%s\n", PG_PROC_DIR);
107214 return -ENODEV;
107215 diff --git a/net/core/ptp_classifier.c b/net/core/ptp_classifier.c
107216 deleted file mode 100644
107217 index d3027a7..0000000
107218 --- a/net/core/ptp_classifier.c
107219 +++ /dev/null
107220 @@ -1,141 +0,0 @@
107221 -/* PTP classifier
107222 - *
107223 - * This program is free software; you can redistribute it and/or
107224 - * modify it under the terms of version 2 of the GNU General Public
107225 - * License as published by the Free Software Foundation.
107226 - *
107227 - * This program is distributed in the hope that it will be useful, but
107228 - * WITHOUT ANY WARRANTY; without even the implied warranty of
107229 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
107230 - * General Public License for more details.
107231 - */
107232 -
107233 -/* The below program is the bpf_asm (tools/net/) representation of
107234 - * the opcode array in the ptp_filter structure.
107235 - *
107236 - * For convenience, this can easily be altered and reviewed with
107237 - * bpf_asm and bpf_dbg, e.g. `./bpf_asm -c prog` where prog is a
107238 - * simple file containing the below program:
107239 - *
107240 - * ldh [12] ; load ethertype
107241 - *
107242 - * ; PTP over UDP over IPv4 over Ethernet
107243 - * test_ipv4:
107244 - * jneq #0x800, test_ipv6 ; ETH_P_IP ?
107245 - * ldb [23] ; load proto
107246 - * jneq #17, drop_ipv4 ; IPPROTO_UDP ?
107247 - * ldh [20] ; load frag offset field
107248 - * jset #0x1fff, drop_ipv4 ; don't allow fragments
107249 - * ldxb 4*([14]&0xf) ; load IP header len
107250 - * ldh [x + 16] ; load UDP dst port
107251 - * jneq #319, drop_ipv4 ; is port PTP_EV_PORT ?
107252 - * ldh [x + 22] ; load payload
107253 - * and #0xf ; mask PTP_CLASS_VMASK
107254 - * or #0x10 ; PTP_CLASS_IPV4
107255 - * ret a ; return PTP class
107256 - * drop_ipv4: ret #0x0 ; PTP_CLASS_NONE
107257 - *
107258 - * ; PTP over UDP over IPv6 over Ethernet
107259 - * test_ipv6:
107260 - * jneq #0x86dd, test_8021q ; ETH_P_IPV6 ?
107261 - * ldb [20] ; load proto
107262 - * jneq #17, drop_ipv6 ; IPPROTO_UDP ?
107263 - * ldh [56] ; load UDP dst port
107264 - * jneq #319, drop_ipv6 ; is port PTP_EV_PORT ?
107265 - * ldh [62] ; load payload
107266 - * and #0xf ; mask PTP_CLASS_VMASK
107267 - * or #0x20 ; PTP_CLASS_IPV6
107268 - * ret a ; return PTP class
107269 - * drop_ipv6: ret #0x0 ; PTP_CLASS_NONE
107270 - *
107271 - * ; PTP over 802.1Q over Ethernet
107272 - * test_8021q:
107273 - * jneq #0x8100, test_ieee1588 ; ETH_P_8021Q ?
107274 - * ldh [16] ; load inner type
107275 - * jneq #0x88f7, drop_ieee1588 ; ETH_P_1588 ?
107276 - * ldb [18] ; load payload
107277 - * and #0x8 ; as we don't have ports here, test
107278 - * jneq #0x0, drop_ieee1588 ; for PTP_GEN_BIT and drop these
107279 - * ldh [18] ; reload payload
107280 - * and #0xf ; mask PTP_CLASS_VMASK
107281 - * or #0x40 ; PTP_CLASS_V2_VLAN
107282 - * ret a ; return PTP class
107283 - *
107284 - * ; PTP over Ethernet
107285 - * test_ieee1588:
107286 - * jneq #0x88f7, drop_ieee1588 ; ETH_P_1588 ?
107287 - * ldb [14] ; load payload
107288 - * and #0x8 ; as we don't have ports here, test
107289 - * jneq #0x0, drop_ieee1588 ; for PTP_GEN_BIT and drop these
107290 - * ldh [14] ; reload payload
107291 - * and #0xf ; mask PTP_CLASS_VMASK
107292 - * or #0x30 ; PTP_CLASS_L2
107293 - * ret a ; return PTP class
107294 - * drop_ieee1588: ret #0x0 ; PTP_CLASS_NONE
107295 - */
107296 -
107297 -#include <linux/skbuff.h>
107298 -#include <linux/filter.h>
107299 -#include <linux/ptp_classify.h>
107300 -
107301 -static struct sk_filter *ptp_insns __read_mostly;
107302 -
107303 -unsigned int ptp_classify_raw(const struct sk_buff *skb)
107304 -{
107305 - return SK_RUN_FILTER(ptp_insns, skb);
107306 -}
107307 -EXPORT_SYMBOL_GPL(ptp_classify_raw);
107308 -
107309 -void __init ptp_classifier_init(void)
107310 -{
107311 - static struct sock_filter ptp_filter[] __initdata = {
107312 - { 0x28, 0, 0, 0x0000000c },
107313 - { 0x15, 0, 12, 0x00000800 },
107314 - { 0x30, 0, 0, 0x00000017 },
107315 - { 0x15, 0, 9, 0x00000011 },
107316 - { 0x28, 0, 0, 0x00000014 },
107317 - { 0x45, 7, 0, 0x00001fff },
107318 - { 0xb1, 0, 0, 0x0000000e },
107319 - { 0x48, 0, 0, 0x00000010 },
107320 - { 0x15, 0, 4, 0x0000013f },
107321 - { 0x48, 0, 0, 0x00000016 },
107322 - { 0x54, 0, 0, 0x0000000f },
107323 - { 0x44, 0, 0, 0x00000010 },
107324 - { 0x16, 0, 0, 0x00000000 },
107325 - { 0x06, 0, 0, 0x00000000 },
107326 - { 0x15, 0, 9, 0x000086dd },
107327 - { 0x30, 0, 0, 0x00000014 },
107328 - { 0x15, 0, 6, 0x00000011 },
107329 - { 0x28, 0, 0, 0x00000038 },
107330 - { 0x15, 0, 4, 0x0000013f },
107331 - { 0x28, 0, 0, 0x0000003e },
107332 - { 0x54, 0, 0, 0x0000000f },
107333 - { 0x44, 0, 0, 0x00000020 },
107334 - { 0x16, 0, 0, 0x00000000 },
107335 - { 0x06, 0, 0, 0x00000000 },
107336 - { 0x15, 0, 9, 0x00008100 },
107337 - { 0x28, 0, 0, 0x00000010 },
107338 - { 0x15, 0, 15, 0x000088f7 },
107339 - { 0x30, 0, 0, 0x00000012 },
107340 - { 0x54, 0, 0, 0x00000008 },
107341 - { 0x15, 0, 12, 0x00000000 },
107342 - { 0x28, 0, 0, 0x00000012 },
107343 - { 0x54, 0, 0, 0x0000000f },
107344 - { 0x44, 0, 0, 0x00000040 },
107345 - { 0x16, 0, 0, 0x00000000 },
107346 - { 0x15, 0, 7, 0x000088f7 },
107347 - { 0x30, 0, 0, 0x0000000e },
107348 - { 0x54, 0, 0, 0x00000008 },
107349 - { 0x15, 0, 4, 0x00000000 },
107350 - { 0x28, 0, 0, 0x0000000e },
107351 - { 0x54, 0, 0, 0x0000000f },
107352 - { 0x44, 0, 0, 0x00000030 },
107353 - { 0x16, 0, 0, 0x00000000 },
107354 - { 0x06, 0, 0, 0x00000000 },
107355 - };
107356 - struct sock_fprog_kern ptp_prog = {
107357 - .len = ARRAY_SIZE(ptp_filter), .filter = ptp_filter,
107358 - };
107359 -
107360 - BUG_ON(sk_unattached_filter_create(&ptp_insns, &ptp_prog));
107361 -}
107362 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
107363 index 1063996..0729c19 100644
107364 --- a/net/core/rtnetlink.c
107365 +++ b/net/core/rtnetlink.c
107366 @@ -58,7 +58,7 @@ struct rtnl_link {
107367 rtnl_doit_func doit;
107368 rtnl_dumpit_func dumpit;
107369 rtnl_calcit_func calcit;
107370 -};
107371 +} __no_const;
107372
107373 static DEFINE_MUTEX(rtnl_mutex);
107374
107375 @@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
107376 if (rtnl_link_ops_get(ops->kind))
107377 return -EEXIST;
107378
107379 - if (!ops->dellink)
107380 - ops->dellink = unregister_netdevice_queue;
107381 + if (!ops->dellink) {
107382 + pax_open_kernel();
107383 + *(void **)&ops->dellink = unregister_netdevice_queue;
107384 + pax_close_kernel();
107385 + }
107386
107387 - list_add_tail(&ops->list, &link_ops);
107388 + pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
107389 return 0;
107390 }
107391 EXPORT_SYMBOL_GPL(__rtnl_link_register);
107392 @@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
107393 for_each_net(net) {
107394 __rtnl_kill_links(net, ops);
107395 }
107396 - list_del(&ops->list);
107397 + pax_list_del((struct list_head *)&ops->list);
107398 }
107399 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
107400
107401 @@ -1008,7 +1011,7 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
107402 (dev->ifalias &&
107403 nla_put_string(skb, IFLA_IFALIAS, dev->ifalias)) ||
107404 nla_put_u32(skb, IFLA_CARRIER_CHANGES,
107405 - atomic_read(&dev->carrier_changes)))
107406 + atomic_read_unchecked(&dev->carrier_changes)))
107407 goto nla_put_failure;
107408
107409 if (1) {
107410 diff --git a/net/core/scm.c b/net/core/scm.c
107411 index b442e7e..6f5b5a2 100644
107412 --- a/net/core/scm.c
107413 +++ b/net/core/scm.c
107414 @@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
107415 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
107416 {
107417 struct cmsghdr __user *cm
107418 - = (__force struct cmsghdr __user *)msg->msg_control;
107419 + = (struct cmsghdr __force_user *)msg->msg_control;
107420 struct cmsghdr cmhdr;
107421 int cmlen = CMSG_LEN(len);
107422 int err;
107423 @@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
107424 err = -EFAULT;
107425 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
107426 goto out;
107427 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
107428 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
107429 goto out;
107430 cmlen = CMSG_SPACE(len);
107431 if (msg->msg_controllen < cmlen)
107432 @@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
107433 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
107434 {
107435 struct cmsghdr __user *cm
107436 - = (__force struct cmsghdr __user*)msg->msg_control;
107437 + = (struct cmsghdr __force_user *)msg->msg_control;
107438
107439 int fdmax = 0;
107440 int fdnum = scm->fp->count;
107441 @@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
107442 if (fdnum < fdmax)
107443 fdmax = fdnum;
107444
107445 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
107446 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
107447 i++, cmfptr++)
107448 {
107449 struct socket *sock;
107450 diff --git a/net/core/skbuff.c b/net/core/skbuff.c
107451 index 58ff88e..af9b458 100644
107452 --- a/net/core/skbuff.c
107453 +++ b/net/core/skbuff.c
107454 @@ -2010,7 +2010,7 @@ EXPORT_SYMBOL(__skb_checksum);
107455 __wsum skb_checksum(const struct sk_buff *skb, int offset,
107456 int len, __wsum csum)
107457 {
107458 - const struct skb_checksum_ops ops = {
107459 + static const struct skb_checksum_ops ops = {
107460 .update = csum_partial_ext,
107461 .combine = csum_block_add_ext,
107462 };
107463 @@ -3233,13 +3233,15 @@ void __init skb_init(void)
107464 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
107465 sizeof(struct sk_buff),
107466 0,
107467 - SLAB_HWCACHE_ALIGN|SLAB_PANIC,
107468 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|
107469 + SLAB_NO_SANITIZE,
107470 NULL);
107471 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
107472 (2*sizeof(struct sk_buff)) +
107473 sizeof(atomic_t),
107474 0,
107475 - SLAB_HWCACHE_ALIGN|SLAB_PANIC,
107476 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|
107477 + SLAB_NO_SANITIZE,
107478 NULL);
107479 }
107480
107481 diff --git a/net/core/sock.c b/net/core/sock.c
107482 index 026e01f..f54f908 100644
107483 --- a/net/core/sock.c
107484 +++ b/net/core/sock.c
107485 @@ -442,7 +442,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
107486 struct sk_buff_head *list = &sk->sk_receive_queue;
107487
107488 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
107489 - atomic_inc(&sk->sk_drops);
107490 + atomic_inc_unchecked(&sk->sk_drops);
107491 trace_sock_rcvqueue_full(sk, skb);
107492 return -ENOMEM;
107493 }
107494 @@ -452,7 +452,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
107495 return err;
107496
107497 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
107498 - atomic_inc(&sk->sk_drops);
107499 + atomic_inc_unchecked(&sk->sk_drops);
107500 return -ENOBUFS;
107501 }
107502
107503 @@ -472,7 +472,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
107504 skb_dst_force(skb);
107505
107506 spin_lock_irqsave(&list->lock, flags);
107507 - skb->dropcount = atomic_read(&sk->sk_drops);
107508 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
107509 __skb_queue_tail(list, skb);
107510 spin_unlock_irqrestore(&list->lock, flags);
107511
107512 @@ -492,7 +492,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
107513 skb->dev = NULL;
107514
107515 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
107516 - atomic_inc(&sk->sk_drops);
107517 + atomic_inc_unchecked(&sk->sk_drops);
107518 goto discard_and_relse;
107519 }
107520 if (nested)
107521 @@ -510,7 +510,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
107522 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
107523 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
107524 bh_unlock_sock(sk);
107525 - atomic_inc(&sk->sk_drops);
107526 + atomic_inc_unchecked(&sk->sk_drops);
107527 goto discard_and_relse;
107528 }
107529
107530 @@ -998,12 +998,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
107531 struct timeval tm;
107532 } v;
107533
107534 - int lv = sizeof(int);
107535 - int len;
107536 + unsigned int lv = sizeof(int);
107537 + unsigned int len;
107538
107539 if (get_user(len, optlen))
107540 return -EFAULT;
107541 - if (len < 0)
107542 + if (len > INT_MAX)
107543 return -EINVAL;
107544
107545 memset(&v, 0, sizeof(v));
107546 @@ -1155,11 +1155,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
107547
107548 case SO_PEERNAME:
107549 {
107550 - char address[128];
107551 + char address[_K_SS_MAXSIZE];
107552
107553 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
107554 return -ENOTCONN;
107555 - if (lv < len)
107556 + if (lv < len || sizeof address < len)
107557 return -EINVAL;
107558 if (copy_to_user(optval, address, len))
107559 return -EFAULT;
107560 @@ -1240,7 +1240,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
107561
107562 if (len > lv)
107563 len = lv;
107564 - if (copy_to_user(optval, &v, len))
107565 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
107566 return -EFAULT;
107567 lenout:
107568 if (put_user(len, optlen))
107569 @@ -2375,7 +2375,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
107570 */
107571 smp_wmb();
107572 atomic_set(&sk->sk_refcnt, 1);
107573 - atomic_set(&sk->sk_drops, 0);
107574 + atomic_set_unchecked(&sk->sk_drops, 0);
107575 }
107576 EXPORT_SYMBOL(sock_init_data);
107577
107578 @@ -2503,6 +2503,7 @@ void sock_enable_timestamp(struct sock *sk, int flag)
107579 int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
107580 int level, int type)
107581 {
107582 + struct sock_extended_err ee;
107583 struct sock_exterr_skb *serr;
107584 struct sk_buff *skb, *skb2;
107585 int copied, err;
107586 @@ -2524,7 +2525,8 @@ int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
107587 sock_recv_timestamp(msg, sk, skb);
107588
107589 serr = SKB_EXT_ERR(skb);
107590 - put_cmsg(msg, level, type, sizeof(serr->ee), &serr->ee);
107591 + ee = serr->ee;
107592 + put_cmsg(msg, level, type, sizeof ee, &ee);
107593
107594 msg->msg_flags |= MSG_ERRQUEUE;
107595 err = copied;
107596 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
107597 index a4216a4..773e3d7 100644
107598 --- a/net/core/sock_diag.c
107599 +++ b/net/core/sock_diag.c
107600 @@ -9,26 +9,33 @@
107601 #include <linux/inet_diag.h>
107602 #include <linux/sock_diag.h>
107603
107604 -static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
107605 +static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
107606 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
107607 static DEFINE_MUTEX(sock_diag_table_mutex);
107608
107609 int sock_diag_check_cookie(void *sk, __u32 *cookie)
107610 {
107611 +#ifndef CONFIG_GRKERNSEC_HIDESYM
107612 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
107613 cookie[1] != INET_DIAG_NOCOOKIE) &&
107614 ((u32)(unsigned long)sk != cookie[0] ||
107615 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
107616 return -ESTALE;
107617 else
107618 +#endif
107619 return 0;
107620 }
107621 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
107622
107623 void sock_diag_save_cookie(void *sk, __u32 *cookie)
107624 {
107625 +#ifdef CONFIG_GRKERNSEC_HIDESYM
107626 + cookie[0] = 0;
107627 + cookie[1] = 0;
107628 +#else
107629 cookie[0] = (u32)(unsigned long)sk;
107630 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
107631 +#endif
107632 }
107633 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
107634
107635 @@ -52,10 +59,9 @@ EXPORT_SYMBOL_GPL(sock_diag_put_meminfo);
107636 int sock_diag_put_filterinfo(bool may_report_filterinfo, struct sock *sk,
107637 struct sk_buff *skb, int attrtype)
107638 {
107639 - struct sock_fprog_kern *fprog;
107640 - struct sk_filter *filter;
107641 struct nlattr *attr;
107642 - unsigned int flen;
107643 + struct sk_filter *filter;
107644 + unsigned int len;
107645 int err = 0;
107646
107647 if (!may_report_filterinfo) {
107648 @@ -64,20 +70,24 @@ int sock_diag_put_filterinfo(bool may_report_filterinfo, struct sock *sk,
107649 }
107650
107651 rcu_read_lock();
107652 +
107653 filter = rcu_dereference(sk->sk_filter);
107654 - if (!filter)
107655 - goto out;
107656 + len = filter ? filter->len * sizeof(struct sock_filter) : 0;
107657
107658 - fprog = filter->orig_prog;
107659 - flen = sk_filter_proglen(fprog);
107660 -
107661 - attr = nla_reserve(skb, attrtype, flen);
107662 + attr = nla_reserve(skb, attrtype, len);
107663 if (attr == NULL) {
107664 err = -EMSGSIZE;
107665 goto out;
107666 }
107667
107668 - memcpy(nla_data(attr), fprog->filter, flen);
107669 + if (filter) {
107670 + struct sock_filter *fb = (struct sock_filter *)nla_data(attr);
107671 + int i;
107672 +
107673 + for (i = 0; i < filter->len; i++, fb++)
107674 + sk_decode_filter(&filter->insns[i], fb);
107675 + }
107676 +
107677 out:
107678 rcu_read_unlock();
107679 return err;
107680 @@ -110,8 +120,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
107681 mutex_lock(&sock_diag_table_mutex);
107682 if (sock_diag_handlers[hndl->family])
107683 err = -EBUSY;
107684 - else
107685 + else {
107686 + pax_open_kernel();
107687 sock_diag_handlers[hndl->family] = hndl;
107688 + pax_close_kernel();
107689 + }
107690 mutex_unlock(&sock_diag_table_mutex);
107691
107692 return err;
107693 @@ -127,7 +140,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
107694
107695 mutex_lock(&sock_diag_table_mutex);
107696 BUG_ON(sock_diag_handlers[family] != hnld);
107697 + pax_open_kernel();
107698 sock_diag_handlers[family] = NULL;
107699 + pax_close_kernel();
107700 mutex_unlock(&sock_diag_table_mutex);
107701 }
107702 EXPORT_SYMBOL_GPL(sock_diag_unregister);
107703 diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
107704 index cf9cd13..8b56af3 100644
107705 --- a/net/core/sysctl_net_core.c
107706 +++ b/net/core/sysctl_net_core.c
107707 @@ -32,7 +32,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
107708 {
107709 unsigned int orig_size, size;
107710 int ret, i;
107711 - struct ctl_table tmp = {
107712 + ctl_table_no_const tmp = {
107713 .data = &size,
107714 .maxlen = sizeof(size),
107715 .mode = table->mode
107716 @@ -200,7 +200,7 @@ static int set_default_qdisc(struct ctl_table *table, int write,
107717 void __user *buffer, size_t *lenp, loff_t *ppos)
107718 {
107719 char id[IFNAMSIZ];
107720 - struct ctl_table tbl = {
107721 + ctl_table_no_const tbl = {
107722 .data = id,
107723 .maxlen = IFNAMSIZ,
107724 };
107725 @@ -379,13 +379,12 @@ static struct ctl_table netns_core_table[] = {
107726
107727 static __net_init int sysctl_core_net_init(struct net *net)
107728 {
107729 - struct ctl_table *tbl;
107730 + ctl_table_no_const *tbl = NULL;
107731
107732 net->core.sysctl_somaxconn = SOMAXCONN;
107733
107734 - tbl = netns_core_table;
107735 if (!net_eq(net, &init_net)) {
107736 - tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
107737 + tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
107738 if (tbl == NULL)
107739 goto err_dup;
107740
107741 @@ -395,17 +394,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
107742 if (net->user_ns != &init_user_ns) {
107743 tbl[0].procname = NULL;
107744 }
107745 - }
107746 -
107747 - net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
107748 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
107749 + } else
107750 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
107751 if (net->core.sysctl_hdr == NULL)
107752 goto err_reg;
107753
107754 return 0;
107755
107756 err_reg:
107757 - if (tbl != netns_core_table)
107758 - kfree(tbl);
107759 + kfree(tbl);
107760 err_dup:
107761 return -ENOMEM;
107762 }
107763 @@ -420,7 +418,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
107764 kfree(tbl);
107765 }
107766
107767 -static __net_initdata struct pernet_operations sysctl_core_ops = {
107768 +static __net_initconst struct pernet_operations sysctl_core_ops = {
107769 .init = sysctl_core_net_init,
107770 .exit = sysctl_core_net_exit,
107771 };
107772 diff --git a/net/core/timestamping.c b/net/core/timestamping.c
107773 index 6521dfd..661b5a4 100644
107774 --- a/net/core/timestamping.c
107775 +++ b/net/core/timestamping.c
107776 @@ -23,11 +23,16 @@
107777 #include <linux/skbuff.h>
107778 #include <linux/export.h>
107779
107780 +static struct sock_filter ptp_filter[] = {
107781 + PTP_FILTER
107782 +};
107783 +
107784 static unsigned int classify(const struct sk_buff *skb)
107785 {
107786 - if (likely(skb->dev && skb->dev->phydev &&
107787 + if (likely(skb->dev &&
107788 + skb->dev->phydev &&
107789 skb->dev->phydev->drv))
107790 - return ptp_classify_raw(skb);
107791 + return sk_run_filter(skb, ptp_filter);
107792 else
107793 return PTP_CLASS_NONE;
107794 }
107795 @@ -55,13 +60,11 @@ void skb_clone_tx_timestamp(struct sk_buff *skb)
107796 if (likely(phydev->drv->txtstamp)) {
107797 if (!atomic_inc_not_zero(&sk->sk_refcnt))
107798 return;
107799 -
107800 clone = skb_clone(skb, GFP_ATOMIC);
107801 if (!clone) {
107802 sock_put(sk);
107803 return;
107804 }
107805 -
107806 clone->sk = sk;
107807 phydev->drv->txtstamp(phydev, clone, type);
107808 }
107809 @@ -86,15 +89,12 @@ void skb_complete_tx_timestamp(struct sk_buff *skb,
107810 }
107811
107812 *skb_hwtstamps(skb) = *hwtstamps;
107813 -
107814 serr = SKB_EXT_ERR(skb);
107815 memset(serr, 0, sizeof(*serr));
107816 serr->ee.ee_errno = ENOMSG;
107817 serr->ee.ee_origin = SO_EE_ORIGIN_TIMESTAMPING;
107818 skb->sk = NULL;
107819 -
107820 err = sock_queue_err_skb(sk, skb);
107821 -
107822 sock_put(sk);
107823 if (err)
107824 kfree_skb(skb);
107825 @@ -132,3 +132,8 @@ bool skb_defer_rx_timestamp(struct sk_buff *skb)
107826 return false;
107827 }
107828 EXPORT_SYMBOL_GPL(skb_defer_rx_timestamp);
107829 +
107830 +void __init skb_timestamping_init(void)
107831 +{
107832 + BUG_ON(sk_chk_filter(ptp_filter, ARRAY_SIZE(ptp_filter)));
107833 +}
107834 diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
107835 index ae011b4..d2d18bf 100644
107836 --- a/net/decnet/af_decnet.c
107837 +++ b/net/decnet/af_decnet.c
107838 @@ -465,6 +465,7 @@ static struct proto dn_proto = {
107839 .sysctl_rmem = sysctl_decnet_rmem,
107840 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
107841 .obj_size = sizeof(struct dn_sock),
107842 + .slab_flags = SLAB_USERCOPY,
107843 };
107844
107845 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
107846 diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
107847 index 3b726f3..1af6368 100644
107848 --- a/net/decnet/dn_dev.c
107849 +++ b/net/decnet/dn_dev.c
107850 @@ -200,7 +200,7 @@ static struct dn_dev_sysctl_table {
107851 .extra1 = &min_t3,
107852 .extra2 = &max_t3
107853 },
107854 - {0}
107855 + { }
107856 },
107857 };
107858
107859 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
107860 index 5325b54..a0d4d69 100644
107861 --- a/net/decnet/sysctl_net_decnet.c
107862 +++ b/net/decnet/sysctl_net_decnet.c
107863 @@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
107864
107865 if (len > *lenp) len = *lenp;
107866
107867 - if (copy_to_user(buffer, addr, len))
107868 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
107869 return -EFAULT;
107870
107871 *lenp = len;
107872 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
107873
107874 if (len > *lenp) len = *lenp;
107875
107876 - if (copy_to_user(buffer, devname, len))
107877 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
107878 return -EFAULT;
107879
107880 *lenp = len;
107881 diff --git a/net/ieee802154/reassembly.c b/net/ieee802154/reassembly.c
107882 index 6f1428c..9586b83 100644
107883 --- a/net/ieee802154/reassembly.c
107884 +++ b/net/ieee802154/reassembly.c
107885 @@ -438,14 +438,13 @@ static struct ctl_table lowpan_frags_ctl_table[] = {
107886
107887 static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
107888 {
107889 - struct ctl_table *table;
107890 + ctl_table_no_const *table = NULL;
107891 struct ctl_table_header *hdr;
107892 struct netns_ieee802154_lowpan *ieee802154_lowpan =
107893 net_ieee802154_lowpan(net);
107894
107895 - table = lowpan_frags_ns_ctl_table;
107896 if (!net_eq(net, &init_net)) {
107897 - table = kmemdup(table, sizeof(lowpan_frags_ns_ctl_table),
107898 + table = kmemdup(lowpan_frags_ns_ctl_table, sizeof(lowpan_frags_ns_ctl_table),
107899 GFP_KERNEL);
107900 if (table == NULL)
107901 goto err_alloc;
107902 @@ -458,9 +457,9 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
107903 /* Don't export sysctls to unprivileged users */
107904 if (net->user_ns != &init_user_ns)
107905 table[0].procname = NULL;
107906 - }
107907 -
107908 - hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", table);
107909 + hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", table);
107910 + } else
107911 + hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", lowpan_frags_ns_ctl_table);
107912 if (hdr == NULL)
107913 goto err_reg;
107914
107915 @@ -468,8 +467,7 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
107916 return 0;
107917
107918 err_reg:
107919 - if (!net_eq(net, &init_net))
107920 - kfree(table);
107921 + kfree(table);
107922 err_alloc:
107923 return -ENOMEM;
107924 }
107925 diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
107926 index e944937..368fe78 100644
107927 --- a/net/ipv4/devinet.c
107928 +++ b/net/ipv4/devinet.c
107929 @@ -1540,7 +1540,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
107930 idx = 0;
107931 head = &net->dev_index_head[h];
107932 rcu_read_lock();
107933 - cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
107934 + cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
107935 net->dev_base_seq;
107936 hlist_for_each_entry_rcu(dev, head, index_hlist) {
107937 if (idx < s_idx)
107938 @@ -1858,7 +1858,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
107939 idx = 0;
107940 head = &net->dev_index_head[h];
107941 rcu_read_lock();
107942 - cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
107943 + cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
107944 net->dev_base_seq;
107945 hlist_for_each_entry_rcu(dev, head, index_hlist) {
107946 if (idx < s_idx)
107947 @@ -2093,7 +2093,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
107948 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
107949 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
107950
107951 -static struct devinet_sysctl_table {
107952 +static const struct devinet_sysctl_table {
107953 struct ctl_table_header *sysctl_header;
107954 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
107955 } devinet_sysctl = {
107956 @@ -2215,7 +2215,7 @@ static __net_init int devinet_init_net(struct net *net)
107957 int err;
107958 struct ipv4_devconf *all, *dflt;
107959 #ifdef CONFIG_SYSCTL
107960 - struct ctl_table *tbl = ctl_forward_entry;
107961 + ctl_table_no_const *tbl = NULL;
107962 struct ctl_table_header *forw_hdr;
107963 #endif
107964
107965 @@ -2233,7 +2233,7 @@ static __net_init int devinet_init_net(struct net *net)
107966 goto err_alloc_dflt;
107967
107968 #ifdef CONFIG_SYSCTL
107969 - tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
107970 + tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
107971 if (tbl == NULL)
107972 goto err_alloc_ctl;
107973
107974 @@ -2253,7 +2253,10 @@ static __net_init int devinet_init_net(struct net *net)
107975 goto err_reg_dflt;
107976
107977 err = -ENOMEM;
107978 - forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
107979 + if (!net_eq(net, &init_net))
107980 + forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
107981 + else
107982 + forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
107983 if (forw_hdr == NULL)
107984 goto err_reg_ctl;
107985 net->ipv4.forw_hdr = forw_hdr;
107986 @@ -2269,8 +2272,7 @@ err_reg_ctl:
107987 err_reg_dflt:
107988 __devinet_sysctl_unregister(all);
107989 err_reg_all:
107990 - if (tbl != ctl_forward_entry)
107991 - kfree(tbl);
107992 + kfree(tbl);
107993 err_alloc_ctl:
107994 #endif
107995 if (dflt != &ipv4_devconf_dflt)
107996 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
107997 index 255aa99..45c78f8 100644
107998 --- a/net/ipv4/fib_frontend.c
107999 +++ b/net/ipv4/fib_frontend.c
108000 @@ -1015,12 +1015,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
108001 #ifdef CONFIG_IP_ROUTE_MULTIPATH
108002 fib_sync_up(dev);
108003 #endif
108004 - atomic_inc(&net->ipv4.dev_addr_genid);
108005 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
108006 rt_cache_flush(dev_net(dev));
108007 break;
108008 case NETDEV_DOWN:
108009 fib_del_ifaddr(ifa, NULL);
108010 - atomic_inc(&net->ipv4.dev_addr_genid);
108011 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
108012 if (ifa->ifa_dev->ifa_list == NULL) {
108013 /* Last address was deleted from this interface.
108014 * Disable IP.
108015 @@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
108016 #ifdef CONFIG_IP_ROUTE_MULTIPATH
108017 fib_sync_up(dev);
108018 #endif
108019 - atomic_inc(&net->ipv4.dev_addr_genid);
108020 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
108021 rt_cache_flush(net);
108022 break;
108023 case NETDEV_DOWN:
108024 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
108025 index b10cd43a..22327f9 100644
108026 --- a/net/ipv4/fib_semantics.c
108027 +++ b/net/ipv4/fib_semantics.c
108028 @@ -768,7 +768,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
108029 nh->nh_saddr = inet_select_addr(nh->nh_dev,
108030 nh->nh_gw,
108031 nh->nh_parent->fib_scope);
108032 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
108033 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
108034
108035 return nh->nh_saddr;
108036 }
108037 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
108038 index 43116e8..e3e6159 100644
108039 --- a/net/ipv4/inet_hashtables.c
108040 +++ b/net/ipv4/inet_hashtables.c
108041 @@ -18,6 +18,7 @@
108042 #include <linux/sched.h>
108043 #include <linux/slab.h>
108044 #include <linux/wait.h>
108045 +#include <linux/security.h>
108046
108047 #include <net/inet_connection_sock.h>
108048 #include <net/inet_hashtables.h>
108049 @@ -49,6 +50,8 @@ static unsigned int inet_sk_ehashfn(const struct sock *sk)
108050 return inet_ehashfn(net, laddr, lport, faddr, fport);
108051 }
108052
108053 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
108054 +
108055 /*
108056 * Allocate and initialize a new local port bind bucket.
108057 * The bindhash mutex for snum's hash chain must be held here.
108058 @@ -554,6 +557,8 @@ ok:
108059 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
108060 spin_unlock(&head->lock);
108061
108062 + gr_update_task_in_ip_table(current, inet_sk(sk));
108063 +
108064 if (tw) {
108065 inet_twsk_deschedule(tw, death_row);
108066 while (twrefcnt) {
108067 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
108068 index bd5f592..e80e605 100644
108069 --- a/net/ipv4/inetpeer.c
108070 +++ b/net/ipv4/inetpeer.c
108071 @@ -482,7 +482,7 @@ relookup:
108072 if (p) {
108073 p->daddr = *daddr;
108074 atomic_set(&p->refcnt, 1);
108075 - atomic_set(&p->rid, 0);
108076 + atomic_set_unchecked(&p->rid, 0);
108077 p->metrics[RTAX_LOCK-1] = INETPEER_METRICS_NEW;
108078 p->rate_tokens = 0;
108079 /* 60*HZ is arbitrary, but chosen enough high so that the first
108080 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
108081 index ed32313..3762abe 100644
108082 --- a/net/ipv4/ip_fragment.c
108083 +++ b/net/ipv4/ip_fragment.c
108084 @@ -284,7 +284,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
108085 return 0;
108086
108087 start = qp->rid;
108088 - end = atomic_inc_return(&peer->rid);
108089 + end = atomic_inc_return_unchecked(&peer->rid);
108090 qp->rid = end;
108091
108092 rc = qp->q.fragments && (end - start) > max;
108093 @@ -761,12 +761,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
108094
108095 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
108096 {
108097 - struct ctl_table *table;
108098 + ctl_table_no_const *table = NULL;
108099 struct ctl_table_header *hdr;
108100
108101 - table = ip4_frags_ns_ctl_table;
108102 if (!net_eq(net, &init_net)) {
108103 - table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
108104 + table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
108105 if (table == NULL)
108106 goto err_alloc;
108107
108108 @@ -777,9 +776,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
108109 /* Don't export sysctls to unprivileged users */
108110 if (net->user_ns != &init_user_ns)
108111 table[0].procname = NULL;
108112 - }
108113 + hdr = register_net_sysctl(net, "net/ipv4", table);
108114 + } else
108115 + hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
108116
108117 - hdr = register_net_sysctl(net, "net/ipv4", table);
108118 if (hdr == NULL)
108119 goto err_reg;
108120
108121 @@ -787,8 +787,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
108122 return 0;
108123
108124 err_reg:
108125 - if (!net_eq(net, &init_net))
108126 - kfree(table);
108127 + kfree(table);
108128 err_alloc:
108129 return -ENOMEM;
108130 }
108131 diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
108132 index 9b84254..c776611 100644
108133 --- a/net/ipv4/ip_gre.c
108134 +++ b/net/ipv4/ip_gre.c
108135 @@ -115,7 +115,7 @@ static bool log_ecn_error = true;
108136 module_param(log_ecn_error, bool, 0644);
108137 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
108138
108139 -static struct rtnl_link_ops ipgre_link_ops __read_mostly;
108140 +static struct rtnl_link_ops ipgre_link_ops;
108141 static int ipgre_tunnel_init(struct net_device *dev);
108142
108143 static int ipgre_net_id __read_mostly;
108144 @@ -733,7 +733,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
108145 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
108146 };
108147
108148 -static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
108149 +static struct rtnl_link_ops ipgre_link_ops = {
108150 .kind = "gre",
108151 .maxtype = IFLA_GRE_MAX,
108152 .policy = ipgre_policy,
108153 @@ -747,7 +747,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
108154 .fill_info = ipgre_fill_info,
108155 };
108156
108157 -static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
108158 +static struct rtnl_link_ops ipgre_tap_ops = {
108159 .kind = "gretap",
108160 .maxtype = IFLA_GRE_MAX,
108161 .policy = ipgre_policy,
108162 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
108163 index 64741b9..6f334a2 100644
108164 --- a/net/ipv4/ip_sockglue.c
108165 +++ b/net/ipv4/ip_sockglue.c
108166 @@ -1188,7 +1188,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
108167 len = min_t(unsigned int, len, opt->optlen);
108168 if (put_user(len, optlen))
108169 return -EFAULT;
108170 - if (copy_to_user(optval, opt->__data, len))
108171 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
108172 + copy_to_user(optval, opt->__data, len))
108173 return -EFAULT;
108174 return 0;
108175 }
108176 @@ -1319,7 +1320,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
108177 if (sk->sk_type != SOCK_STREAM)
108178 return -ENOPROTOOPT;
108179
108180 - msg.msg_control = optval;
108181 + msg.msg_control = (void __force_kernel *)optval;
108182 msg.msg_controllen = len;
108183 msg.msg_flags = flags;
108184
108185 diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
108186 index b8960f3..0f025db 100644
108187 --- a/net/ipv4/ip_vti.c
108188 +++ b/net/ipv4/ip_vti.c
108189 @@ -45,7 +45,7 @@
108190 #include <net/net_namespace.h>
108191 #include <net/netns/generic.h>
108192
108193 -static struct rtnl_link_ops vti_link_ops __read_mostly;
108194 +static struct rtnl_link_ops vti_link_ops;
108195
108196 static int vti_net_id __read_mostly;
108197 static int vti_tunnel_init(struct net_device *dev);
108198 @@ -519,7 +519,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
108199 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
108200 };
108201
108202 -static struct rtnl_link_ops vti_link_ops __read_mostly = {
108203 +static struct rtnl_link_ops vti_link_ops = {
108204 .kind = "vti",
108205 .maxtype = IFLA_VTI_MAX,
108206 .policy = vti_policy,
108207 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
108208 index b3e86ea..18ce98c 100644
108209 --- a/net/ipv4/ipconfig.c
108210 +++ b/net/ipv4/ipconfig.c
108211 @@ -334,7 +334,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
108212
108213 mm_segment_t oldfs = get_fs();
108214 set_fs(get_ds());
108215 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
108216 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
108217 set_fs(oldfs);
108218 return res;
108219 }
108220 @@ -345,7 +345,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
108221
108222 mm_segment_t oldfs = get_fs();
108223 set_fs(get_ds());
108224 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
108225 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
108226 set_fs(oldfs);
108227 return res;
108228 }
108229 @@ -356,7 +356,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
108230
108231 mm_segment_t oldfs = get_fs();
108232 set_fs(get_ds());
108233 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
108234 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
108235 set_fs(oldfs);
108236 return res;
108237 }
108238 diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
108239 index 62eaa00..29b2dc2 100644
108240 --- a/net/ipv4/ipip.c
108241 +++ b/net/ipv4/ipip.c
108242 @@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
108243 static int ipip_net_id __read_mostly;
108244
108245 static int ipip_tunnel_init(struct net_device *dev);
108246 -static struct rtnl_link_ops ipip_link_ops __read_mostly;
108247 +static struct rtnl_link_ops ipip_link_ops;
108248
108249 static int ipip_err(struct sk_buff *skb, u32 info)
108250 {
108251 @@ -409,7 +409,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
108252 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
108253 };
108254
108255 -static struct rtnl_link_ops ipip_link_ops __read_mostly = {
108256 +static struct rtnl_link_ops ipip_link_ops = {
108257 .kind = "ipip",
108258 .maxtype = IFLA_IPTUN_MAX,
108259 .policy = ipip_policy,
108260 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
108261 index f95b6f9..2ee2097 100644
108262 --- a/net/ipv4/netfilter/arp_tables.c
108263 +++ b/net/ipv4/netfilter/arp_tables.c
108264 @@ -885,14 +885,14 @@ static int compat_table_info(const struct xt_table_info *info,
108265 #endif
108266
108267 static int get_info(struct net *net, void __user *user,
108268 - const int *len, int compat)
108269 + int len, int compat)
108270 {
108271 char name[XT_TABLE_MAXNAMELEN];
108272 struct xt_table *t;
108273 int ret;
108274
108275 - if (*len != sizeof(struct arpt_getinfo)) {
108276 - duprintf("length %u != %Zu\n", *len,
108277 + if (len != sizeof(struct arpt_getinfo)) {
108278 + duprintf("length %u != %Zu\n", len,
108279 sizeof(struct arpt_getinfo));
108280 return -EINVAL;
108281 }
108282 @@ -929,7 +929,7 @@ static int get_info(struct net *net, void __user *user,
108283 info.size = private->size;
108284 strcpy(info.name, name);
108285
108286 - if (copy_to_user(user, &info, *len) != 0)
108287 + if (copy_to_user(user, &info, len) != 0)
108288 ret = -EFAULT;
108289 else
108290 ret = 0;
108291 @@ -1690,7 +1690,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
108292
108293 switch (cmd) {
108294 case ARPT_SO_GET_INFO:
108295 - ret = get_info(sock_net(sk), user, len, 1);
108296 + ret = get_info(sock_net(sk), user, *len, 1);
108297 break;
108298 case ARPT_SO_GET_ENTRIES:
108299 ret = compat_get_entries(sock_net(sk), user, len);
108300 @@ -1735,7 +1735,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
108301
108302 switch (cmd) {
108303 case ARPT_SO_GET_INFO:
108304 - ret = get_info(sock_net(sk), user, len, 0);
108305 + ret = get_info(sock_net(sk), user, *len, 0);
108306 break;
108307
108308 case ARPT_SO_GET_ENTRIES:
108309 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
108310 index 99e810f..3711b81 100644
108311 --- a/net/ipv4/netfilter/ip_tables.c
108312 +++ b/net/ipv4/netfilter/ip_tables.c
108313 @@ -1073,14 +1073,14 @@ static int compat_table_info(const struct xt_table_info *info,
108314 #endif
108315
108316 static int get_info(struct net *net, void __user *user,
108317 - const int *len, int compat)
108318 + int len, int compat)
108319 {
108320 char name[XT_TABLE_MAXNAMELEN];
108321 struct xt_table *t;
108322 int ret;
108323
108324 - if (*len != sizeof(struct ipt_getinfo)) {
108325 - duprintf("length %u != %zu\n", *len,
108326 + if (len != sizeof(struct ipt_getinfo)) {
108327 + duprintf("length %u != %zu\n", len,
108328 sizeof(struct ipt_getinfo));
108329 return -EINVAL;
108330 }
108331 @@ -1117,7 +1117,7 @@ static int get_info(struct net *net, void __user *user,
108332 info.size = private->size;
108333 strcpy(info.name, name);
108334
108335 - if (copy_to_user(user, &info, *len) != 0)
108336 + if (copy_to_user(user, &info, len) != 0)
108337 ret = -EFAULT;
108338 else
108339 ret = 0;
108340 @@ -1973,7 +1973,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
108341
108342 switch (cmd) {
108343 case IPT_SO_GET_INFO:
108344 - ret = get_info(sock_net(sk), user, len, 1);
108345 + ret = get_info(sock_net(sk), user, *len, 1);
108346 break;
108347 case IPT_SO_GET_ENTRIES:
108348 ret = compat_get_entries(sock_net(sk), user, len);
108349 @@ -2020,7 +2020,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
108350
108351 switch (cmd) {
108352 case IPT_SO_GET_INFO:
108353 - ret = get_info(sock_net(sk), user, len, 0);
108354 + ret = get_info(sock_net(sk), user, *len, 0);
108355 break;
108356
108357 case IPT_SO_GET_ENTRIES:
108358 diff --git a/net/ipv4/netfilter/ipt_CLUSTERIP.c b/net/ipv4/netfilter/ipt_CLUSTERIP.c
108359 index 2510c02..cfb34fa 100644
108360 --- a/net/ipv4/netfilter/ipt_CLUSTERIP.c
108361 +++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c
108362 @@ -720,7 +720,7 @@ static int clusterip_net_init(struct net *net)
108363 spin_lock_init(&cn->lock);
108364
108365 #ifdef CONFIG_PROC_FS
108366 - cn->procdir = proc_mkdir("ipt_CLUSTERIP", net->proc_net);
108367 + cn->procdir = proc_mkdir_restrict("ipt_CLUSTERIP", net->proc_net);
108368 if (!cn->procdir) {
108369 pr_err("Unable to proc dir entry\n");
108370 return -ENOMEM;
108371 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
108372 index 044a0dd..3399751 100644
108373 --- a/net/ipv4/ping.c
108374 +++ b/net/ipv4/ping.c
108375 @@ -59,7 +59,7 @@ struct ping_table {
108376 };
108377
108378 static struct ping_table ping_table;
108379 -struct pingv6_ops pingv6_ops;
108380 +struct pingv6_ops *pingv6_ops;
108381 EXPORT_SYMBOL_GPL(pingv6_ops);
108382
108383 static u16 ping_port_rover;
108384 @@ -348,7 +348,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
108385 return -ENODEV;
108386 }
108387 }
108388 - has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
108389 + has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
108390 scoped);
108391 rcu_read_unlock();
108392
108393 @@ -556,7 +556,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
108394 }
108395 #if IS_ENABLED(CONFIG_IPV6)
108396 } else if (skb->protocol == htons(ETH_P_IPV6)) {
108397 - harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
108398 + harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
108399 #endif
108400 }
108401
108402 @@ -574,7 +574,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
108403 info, (u8 *)icmph);
108404 #if IS_ENABLED(CONFIG_IPV6)
108405 } else if (family == AF_INET6) {
108406 - pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
108407 + pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
108408 info, (u8 *)icmph);
108409 #endif
108410 }
108411 @@ -858,7 +858,7 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
108412 return ip_recv_error(sk, msg, len, addr_len);
108413 #if IS_ENABLED(CONFIG_IPV6)
108414 } else if (family == AF_INET6) {
108415 - return pingv6_ops.ipv6_recv_error(sk, msg, len,
108416 + return pingv6_ops->ipv6_recv_error(sk, msg, len,
108417 addr_len);
108418 #endif
108419 }
108420 @@ -916,10 +916,10 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
108421 }
108422
108423 if (inet6_sk(sk)->rxopt.all)
108424 - pingv6_ops.ip6_datagram_recv_common_ctl(sk, msg, skb);
108425 + pingv6_ops->ip6_datagram_recv_common_ctl(sk, msg, skb);
108426 if (skb->protocol == htons(ETH_P_IPV6) &&
108427 inet6_sk(sk)->rxopt.all)
108428 - pingv6_ops.ip6_datagram_recv_specific_ctl(sk, msg, skb);
108429 + pingv6_ops->ip6_datagram_recv_specific_ctl(sk, msg, skb);
108430 else if (skb->protocol == htons(ETH_P_IP) && isk->cmsg_flags)
108431 ip_cmsg_recv(msg, skb);
108432 #endif
108433 @@ -1111,7 +1111,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
108434 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
108435 0, sock_i_ino(sp),
108436 atomic_read(&sp->sk_refcnt), sp,
108437 - atomic_read(&sp->sk_drops));
108438 + atomic_read_unchecked(&sp->sk_drops));
108439 }
108440
108441 static int ping_v4_seq_show(struct seq_file *seq, void *v)
108442 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
108443 index 2c65160..213ecdf 100644
108444 --- a/net/ipv4/raw.c
108445 +++ b/net/ipv4/raw.c
108446 @@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
108447 int raw_rcv(struct sock *sk, struct sk_buff *skb)
108448 {
108449 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
108450 - atomic_inc(&sk->sk_drops);
108451 + atomic_inc_unchecked(&sk->sk_drops);
108452 kfree_skb(skb);
108453 return NET_RX_DROP;
108454 }
108455 @@ -748,16 +748,20 @@ static int raw_init(struct sock *sk)
108456
108457 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
108458 {
108459 + struct icmp_filter filter;
108460 +
108461 if (optlen > sizeof(struct icmp_filter))
108462 optlen = sizeof(struct icmp_filter);
108463 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
108464 + if (copy_from_user(&filter, optval, optlen))
108465 return -EFAULT;
108466 + raw_sk(sk)->filter = filter;
108467 return 0;
108468 }
108469
108470 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
108471 {
108472 int len, ret = -EFAULT;
108473 + struct icmp_filter filter;
108474
108475 if (get_user(len, optlen))
108476 goto out;
108477 @@ -767,8 +771,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
108478 if (len > sizeof(struct icmp_filter))
108479 len = sizeof(struct icmp_filter);
108480 ret = -EFAULT;
108481 - if (put_user(len, optlen) ||
108482 - copy_to_user(optval, &raw_sk(sk)->filter, len))
108483 + filter = raw_sk(sk)->filter;
108484 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
108485 goto out;
108486 ret = 0;
108487 out: return ret;
108488 @@ -997,7 +1001,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
108489 0, 0L, 0,
108490 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
108491 0, sock_i_ino(sp),
108492 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
108493 + atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
108494 }
108495
108496 static int raw_seq_show(struct seq_file *seq, void *v)
108497 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
108498 index 1901998..a9a850a 100644
108499 --- a/net/ipv4/route.c
108500 +++ b/net/ipv4/route.c
108501 @@ -228,7 +228,7 @@ static const struct seq_operations rt_cache_seq_ops = {
108502
108503 static int rt_cache_seq_open(struct inode *inode, struct file *file)
108504 {
108505 - return seq_open(file, &rt_cache_seq_ops);
108506 + return seq_open_restrict(file, &rt_cache_seq_ops);
108507 }
108508
108509 static const struct file_operations rt_cache_seq_fops = {
108510 @@ -319,7 +319,7 @@ static const struct seq_operations rt_cpu_seq_ops = {
108511
108512 static int rt_cpu_seq_open(struct inode *inode, struct file *file)
108513 {
108514 - return seq_open(file, &rt_cpu_seq_ops);
108515 + return seq_open_restrict(file, &rt_cpu_seq_ops);
108516 }
108517
108518 static const struct file_operations rt_cpu_seq_fops = {
108519 @@ -357,7 +357,7 @@ static int rt_acct_proc_show(struct seq_file *m, void *v)
108520
108521 static int rt_acct_proc_open(struct inode *inode, struct file *file)
108522 {
108523 - return single_open(file, rt_acct_proc_show, NULL);
108524 + return single_open_restrict(file, rt_acct_proc_show, NULL);
108525 }
108526
108527 static const struct file_operations rt_acct_proc_fops = {
108528 @@ -459,11 +459,11 @@ static struct neighbour *ipv4_neigh_lookup(const struct dst_entry *dst,
108529
108530 #define IP_IDENTS_SZ 2048u
108531 struct ip_ident_bucket {
108532 - atomic_t id;
108533 + atomic_unchecked_t id;
108534 u32 stamp32;
108535 };
108536
108537 -static struct ip_ident_bucket *ip_idents __read_mostly;
108538 +static struct ip_ident_bucket ip_idents[IP_IDENTS_SZ] __read_mostly;
108539
108540 /* In order to protect privacy, we add a perturbation to identifiers
108541 * if one generator is seldom used. This makes hard for an attacker
108542 @@ -479,7 +479,7 @@ u32 ip_idents_reserve(u32 hash, int segs)
108543 if (old != now && cmpxchg(&bucket->stamp32, old, now) == old)
108544 delta = prandom_u32_max(now - old);
108545
108546 - return atomic_add_return(segs + delta, &bucket->id) - segs;
108547 + return atomic_add_return_unchecked(segs + delta, &bucket->id) - segs;
108548 }
108549 EXPORT_SYMBOL(ip_idents_reserve);
108550
108551 @@ -2625,34 +2625,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
108552 .maxlen = sizeof(int),
108553 .mode = 0200,
108554 .proc_handler = ipv4_sysctl_rtcache_flush,
108555 + .extra1 = &init_net,
108556 },
108557 { },
108558 };
108559
108560 static __net_init int sysctl_route_net_init(struct net *net)
108561 {
108562 - struct ctl_table *tbl;
108563 + ctl_table_no_const *tbl = NULL;
108564
108565 - tbl = ipv4_route_flush_table;
108566 if (!net_eq(net, &init_net)) {
108567 - tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
108568 + tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
108569 if (tbl == NULL)
108570 goto err_dup;
108571
108572 /* Don't export sysctls to unprivileged users */
108573 if (net->user_ns != &init_user_ns)
108574 tbl[0].procname = NULL;
108575 - }
108576 - tbl[0].extra1 = net;
108577 + tbl[0].extra1 = net;
108578 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
108579 + } else
108580 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
108581
108582 - net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
108583 if (net->ipv4.route_hdr == NULL)
108584 goto err_reg;
108585 return 0;
108586
108587 err_reg:
108588 - if (tbl != ipv4_route_flush_table)
108589 - kfree(tbl);
108590 + kfree(tbl);
108591 err_dup:
108592 return -ENOMEM;
108593 }
108594 @@ -2675,8 +2675,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
108595
108596 static __net_init int rt_genid_init(struct net *net)
108597 {
108598 - atomic_set(&net->ipv4.rt_genid, 0);
108599 - atomic_set(&net->fnhe_genid, 0);
108600 + atomic_set_unchecked(&net->ipv4.rt_genid, 0);
108601 + atomic_set_unchecked(&net->fnhe_genid, 0);
108602 get_random_bytes(&net->ipv4.dev_addr_genid,
108603 sizeof(net->ipv4.dev_addr_genid));
108604 return 0;
108605 @@ -2719,11 +2719,7 @@ int __init ip_rt_init(void)
108606 {
108607 int rc = 0;
108608
108609 - ip_idents = kmalloc(IP_IDENTS_SZ * sizeof(*ip_idents), GFP_KERNEL);
108610 - if (!ip_idents)
108611 - panic("IP: failed to allocate ip_idents\n");
108612 -
108613 - prandom_bytes(ip_idents, IP_IDENTS_SZ * sizeof(*ip_idents));
108614 + prandom_bytes(ip_idents, sizeof(ip_idents));
108615
108616 #ifdef CONFIG_IP_ROUTE_CLASSID
108617 ip_rt_acct = __alloc_percpu(256 * sizeof(struct ip_rt_acct), __alignof__(struct ip_rt_acct));
108618 diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
108619 index 79a007c..5023029 100644
108620 --- a/net/ipv4/sysctl_net_ipv4.c
108621 +++ b/net/ipv4/sysctl_net_ipv4.c
108622 @@ -60,7 +60,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
108623 container_of(table->data, struct net, ipv4.ip_local_ports.range);
108624 int ret;
108625 int range[2];
108626 - struct ctl_table tmp = {
108627 + ctl_table_no_const tmp = {
108628 .data = &range,
108629 .maxlen = sizeof(range),
108630 .mode = table->mode,
108631 @@ -118,7 +118,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
108632 int ret;
108633 gid_t urange[2];
108634 kgid_t low, high;
108635 - struct ctl_table tmp = {
108636 + ctl_table_no_const tmp = {
108637 .data = &urange,
108638 .maxlen = sizeof(urange),
108639 .mode = table->mode,
108640 @@ -149,7 +149,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
108641 void __user *buffer, size_t *lenp, loff_t *ppos)
108642 {
108643 char val[TCP_CA_NAME_MAX];
108644 - struct ctl_table tbl = {
108645 + ctl_table_no_const tbl = {
108646 .data = val,
108647 .maxlen = TCP_CA_NAME_MAX,
108648 };
108649 @@ -168,7 +168,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
108650 void __user *buffer, size_t *lenp,
108651 loff_t *ppos)
108652 {
108653 - struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
108654 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
108655 int ret;
108656
108657 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
108658 @@ -185,7 +185,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
108659 void __user *buffer, size_t *lenp,
108660 loff_t *ppos)
108661 {
108662 - struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
108663 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
108664 int ret;
108665
108666 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
108667 @@ -204,7 +204,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
108668 void __user *buffer, size_t *lenp,
108669 loff_t *ppos)
108670 {
108671 - struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
108672 + ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
108673 struct tcp_fastopen_context *ctxt;
108674 int ret;
108675 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
108676 @@ -857,13 +857,12 @@ static struct ctl_table ipv4_net_table[] = {
108677
108678 static __net_init int ipv4_sysctl_init_net(struct net *net)
108679 {
108680 - struct ctl_table *table;
108681 + ctl_table_no_const *table = NULL;
108682
108683 - table = ipv4_net_table;
108684 if (!net_eq(net, &init_net)) {
108685 int i;
108686
108687 - table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
108688 + table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
108689 if (table == NULL)
108690 goto err_alloc;
108691
108692 @@ -872,7 +871,10 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
108693 table[i].data += (void *)net - (void *)&init_net;
108694 }
108695
108696 - net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
108697 + if (!net_eq(net, &init_net))
108698 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
108699 + else
108700 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
108701 if (net->ipv4.ipv4_hdr == NULL)
108702 goto err_reg;
108703
108704 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
108705 index 40639c2..dfc86b2 100644
108706 --- a/net/ipv4/tcp_input.c
108707 +++ b/net/ipv4/tcp_input.c
108708 @@ -754,7 +754,7 @@ static void tcp_update_pacing_rate(struct sock *sk)
108709 * without any lock. We want to make sure compiler wont store
108710 * intermediate values in this location.
108711 */
108712 - ACCESS_ONCE(sk->sk_pacing_rate) = min_t(u64, rate,
108713 + ACCESS_ONCE_RW(sk->sk_pacing_rate) = min_t(u64, rate,
108714 sk->sk_max_pacing_rate);
108715 }
108716
108717 @@ -4478,7 +4478,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
108718 * simplifies code)
108719 */
108720 static void
108721 -tcp_collapse(struct sock *sk, struct sk_buff_head *list,
108722 +__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
108723 struct sk_buff *head, struct sk_buff *tail,
108724 u32 start, u32 end)
108725 {
108726 @@ -5536,6 +5536,7 @@ discard:
108727 tcp_paws_reject(&tp->rx_opt, 0))
108728 goto discard_and_undo;
108729
108730 +#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
108731 if (th->syn) {
108732 /* We see SYN without ACK. It is attempt of
108733 * simultaneous connect with crossed SYNs.
108734 @@ -5586,6 +5587,7 @@ discard:
108735 goto discard;
108736 #endif
108737 }
108738 +#endif
108739 /* "fifth, if neither of the SYN or RST bits is set then
108740 * drop the segment and return."
108741 */
108742 @@ -5632,7 +5634,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
108743 goto discard;
108744
108745 if (th->syn) {
108746 - if (th->fin)
108747 + if (th->fin || th->urg || th->psh)
108748 goto discard;
108749 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
108750 return 1;
108751 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
108752 index 77cccda..10122c4 100644
108753 --- a/net/ipv4/tcp_ipv4.c
108754 +++ b/net/ipv4/tcp_ipv4.c
108755 @@ -91,6 +91,10 @@ int sysctl_tcp_low_latency __read_mostly;
108756 EXPORT_SYMBOL(sysctl_tcp_low_latency);
108757
108758
108759 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
108760 +extern int grsec_enable_blackhole;
108761 +#endif
108762 +
108763 #ifdef CONFIG_TCP_MD5SIG
108764 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
108765 __be32 daddr, __be32 saddr, const struct tcphdr *th);
108766 @@ -1591,6 +1595,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
108767 return 0;
108768
108769 reset:
108770 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
108771 + if (!grsec_enable_blackhole)
108772 +#endif
108773 tcp_v4_send_reset(rsk, skb);
108774 discard:
108775 kfree_skb(skb);
108776 @@ -1737,12 +1744,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
108777 TCP_SKB_CB(skb)->sacked = 0;
108778
108779 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
108780 - if (!sk)
108781 + if (!sk) {
108782 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
108783 + ret = 1;
108784 +#endif
108785 goto no_tcp_socket;
108786 -
108787 + }
108788 process:
108789 - if (sk->sk_state == TCP_TIME_WAIT)
108790 + if (sk->sk_state == TCP_TIME_WAIT) {
108791 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
108792 + ret = 2;
108793 +#endif
108794 goto do_time_wait;
108795 + }
108796
108797 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
108798 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
108799 @@ -1796,6 +1810,10 @@ csum_error:
108800 bad_packet:
108801 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
108802 } else {
108803 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
108804 + if (!grsec_enable_blackhole || (ret == 1 &&
108805 + (skb->dev->flags & IFF_LOOPBACK)))
108806 +#endif
108807 tcp_v4_send_reset(NULL, skb);
108808 }
108809
108810 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
108811 index e68e0d4..0334263 100644
108812 --- a/net/ipv4/tcp_minisocks.c
108813 +++ b/net/ipv4/tcp_minisocks.c
108814 @@ -27,6 +27,10 @@
108815 #include <net/inet_common.h>
108816 #include <net/xfrm.h>
108817
108818 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
108819 +extern int grsec_enable_blackhole;
108820 +#endif
108821 +
108822 int sysctl_tcp_syncookies __read_mostly = 1;
108823 EXPORT_SYMBOL(sysctl_tcp_syncookies);
108824
108825 @@ -740,7 +744,10 @@ embryonic_reset:
108826 * avoid becoming vulnerable to outside attack aiming at
108827 * resetting legit local connections.
108828 */
108829 - req->rsk_ops->send_reset(sk, skb);
108830 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
108831 + if (!grsec_enable_blackhole)
108832 +#endif
108833 + req->rsk_ops->send_reset(sk, skb);
108834 } else if (fastopen) { /* received a valid RST pkt */
108835 reqsk_fastopen_remove(sk, req, true);
108836 tcp_reset(sk);
108837 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
108838 index 3b66610..bfbe23a 100644
108839 --- a/net/ipv4/tcp_probe.c
108840 +++ b/net/ipv4/tcp_probe.c
108841 @@ -238,7 +238,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
108842 if (cnt + width >= len)
108843 break;
108844
108845 - if (copy_to_user(buf + cnt, tbuf, width))
108846 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
108847 return -EFAULT;
108848 cnt += width;
108849 }
108850 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
108851 index 286227a..c495a76 100644
108852 --- a/net/ipv4/tcp_timer.c
108853 +++ b/net/ipv4/tcp_timer.c
108854 @@ -22,6 +22,10 @@
108855 #include <linux/gfp.h>
108856 #include <net/tcp.h>
108857
108858 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
108859 +extern int grsec_lastack_retries;
108860 +#endif
108861 +
108862 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
108863 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
108864 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
108865 @@ -192,6 +196,13 @@ static int tcp_write_timeout(struct sock *sk)
108866 }
108867 }
108868
108869 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
108870 + if ((sk->sk_state == TCP_LAST_ACK) &&
108871 + (grsec_lastack_retries > 0) &&
108872 + (grsec_lastack_retries < retry_until))
108873 + retry_until = grsec_lastack_retries;
108874 +#endif
108875 +
108876 if (retransmits_timed_out(sk, retry_until,
108877 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
108878 /* Has it gone just too far? */
108879 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
108880 index 7d5a866..4874211 100644
108881 --- a/net/ipv4/udp.c
108882 +++ b/net/ipv4/udp.c
108883 @@ -87,6 +87,7 @@
108884 #include <linux/types.h>
108885 #include <linux/fcntl.h>
108886 #include <linux/module.h>
108887 +#include <linux/security.h>
108888 #include <linux/socket.h>
108889 #include <linux/sockios.h>
108890 #include <linux/igmp.h>
108891 @@ -113,6 +114,10 @@
108892 #include <net/busy_poll.h>
108893 #include "udp_impl.h"
108894
108895 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
108896 +extern int grsec_enable_blackhole;
108897 +#endif
108898 +
108899 struct udp_table udp_table __read_mostly;
108900 EXPORT_SYMBOL(udp_table);
108901
108902 @@ -615,6 +620,9 @@ found:
108903 return s;
108904 }
108905
108906 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
108907 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
108908 +
108909 /*
108910 * This routine is called by the ICMP module when it gets some
108911 * sort of error condition. If err < 0 then the socket should
108912 @@ -952,9 +960,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
108913 dport = usin->sin_port;
108914 if (dport == 0)
108915 return -EINVAL;
108916 +
108917 + err = gr_search_udp_sendmsg(sk, usin);
108918 + if (err)
108919 + return err;
108920 } else {
108921 if (sk->sk_state != TCP_ESTABLISHED)
108922 return -EDESTADDRREQ;
108923 +
108924 + err = gr_search_udp_sendmsg(sk, NULL);
108925 + if (err)
108926 + return err;
108927 +
108928 daddr = inet->inet_daddr;
108929 dport = inet->inet_dport;
108930 /* Open fast path for connected socket.
108931 @@ -1202,7 +1219,7 @@ static unsigned int first_packet_length(struct sock *sk)
108932 IS_UDPLITE(sk));
108933 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
108934 IS_UDPLITE(sk));
108935 - atomic_inc(&sk->sk_drops);
108936 + atomic_inc_unchecked(&sk->sk_drops);
108937 __skb_unlink(skb, rcvq);
108938 __skb_queue_tail(&list_kill, skb);
108939 }
108940 @@ -1282,6 +1299,10 @@ try_again:
108941 if (!skb)
108942 goto out;
108943
108944 + err = gr_search_udp_recvmsg(sk, skb);
108945 + if (err)
108946 + goto out_free;
108947 +
108948 ulen = skb->len - sizeof(struct udphdr);
108949 copied = len;
108950 if (copied > ulen)
108951 @@ -1315,7 +1336,7 @@ try_again:
108952 if (unlikely(err)) {
108953 trace_kfree_skb(skb, udp_recvmsg);
108954 if (!peeked) {
108955 - atomic_inc(&sk->sk_drops);
108956 + atomic_inc_unchecked(&sk->sk_drops);
108957 UDP_INC_STATS_USER(sock_net(sk),
108958 UDP_MIB_INERRORS, is_udplite);
108959 }
108960 @@ -1612,7 +1633,7 @@ csum_error:
108961 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
108962 drop:
108963 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
108964 - atomic_inc(&sk->sk_drops);
108965 + atomic_inc_unchecked(&sk->sk_drops);
108966 kfree_skb(skb);
108967 return -1;
108968 }
108969 @@ -1631,7 +1652,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
108970 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
108971
108972 if (!skb1) {
108973 - atomic_inc(&sk->sk_drops);
108974 + atomic_inc_unchecked(&sk->sk_drops);
108975 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
108976 IS_UDPLITE(sk));
108977 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
108978 @@ -1817,6 +1838,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
108979 goto csum_error;
108980
108981 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
108982 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
108983 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
108984 +#endif
108985 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
108986
108987 /*
108988 @@ -2403,7 +2427,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
108989 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
108990 0, sock_i_ino(sp),
108991 atomic_read(&sp->sk_refcnt), sp,
108992 - atomic_read(&sp->sk_drops));
108993 + atomic_read_unchecked(&sp->sk_drops));
108994 }
108995
108996 int udp4_seq_show(struct seq_file *seq, void *v)
108997 diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
108998 index 6156f68..d6ab46d 100644
108999 --- a/net/ipv4/xfrm4_policy.c
109000 +++ b/net/ipv4/xfrm4_policy.c
109001 @@ -186,11 +186,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
109002 fl4->flowi4_tos = iph->tos;
109003 }
109004
109005 -static inline int xfrm4_garbage_collect(struct dst_ops *ops)
109006 +static int xfrm4_garbage_collect(struct dst_ops *ops)
109007 {
109008 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
109009
109010 - xfrm4_policy_afinfo.garbage_collect(net);
109011 + xfrm_garbage_collect_deferred(net);
109012 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
109013 }
109014
109015 @@ -269,19 +269,18 @@ static struct ctl_table xfrm4_policy_table[] = {
109016
109017 static int __net_init xfrm4_net_init(struct net *net)
109018 {
109019 - struct ctl_table *table;
109020 + ctl_table_no_const *table = NULL;
109021 struct ctl_table_header *hdr;
109022
109023 - table = xfrm4_policy_table;
109024 if (!net_eq(net, &init_net)) {
109025 - table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
109026 + table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
109027 if (!table)
109028 goto err_alloc;
109029
109030 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
109031 - }
109032 -
109033 - hdr = register_net_sysctl(net, "net/ipv4", table);
109034 + hdr = register_net_sysctl(net, "net/ipv4", table);
109035 + } else
109036 + hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
109037 if (!hdr)
109038 goto err_reg;
109039
109040 @@ -289,8 +288,7 @@ static int __net_init xfrm4_net_init(struct net *net)
109041 return 0;
109042
109043 err_reg:
109044 - if (!net_eq(net, &init_net))
109045 - kfree(table);
109046 + kfree(table);
109047 err_alloc:
109048 return -ENOMEM;
109049 }
109050 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
109051 index 5667b30..9b1b876 100644
109052 --- a/net/ipv6/addrconf.c
109053 +++ b/net/ipv6/addrconf.c
109054 @@ -593,7 +593,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
109055 idx = 0;
109056 head = &net->dev_index_head[h];
109057 rcu_read_lock();
109058 - cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
109059 + cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
109060 net->dev_base_seq;
109061 hlist_for_each_entry_rcu(dev, head, index_hlist) {
109062 if (idx < s_idx)
109063 @@ -2390,7 +2390,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
109064 p.iph.ihl = 5;
109065 p.iph.protocol = IPPROTO_IPV6;
109066 p.iph.ttl = 64;
109067 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
109068 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
109069
109070 if (ops->ndo_do_ioctl) {
109071 mm_segment_t oldfs = get_fs();
109072 @@ -3516,16 +3516,23 @@ static const struct file_operations if6_fops = {
109073 .release = seq_release_net,
109074 };
109075
109076 +extern void register_ipv6_seq_ops_addr(struct seq_operations *addr);
109077 +extern void unregister_ipv6_seq_ops_addr(void);
109078 +
109079 static int __net_init if6_proc_net_init(struct net *net)
109080 {
109081 - if (!proc_create("if_inet6", S_IRUGO, net->proc_net, &if6_fops))
109082 + register_ipv6_seq_ops_addr(&if6_seq_ops);
109083 + if (!proc_create("if_inet6", S_IRUGO, net->proc_net, &if6_fops)) {
109084 + unregister_ipv6_seq_ops_addr();
109085 return -ENOMEM;
109086 + }
109087 return 0;
109088 }
109089
109090 static void __net_exit if6_proc_net_exit(struct net *net)
109091 {
109092 remove_proc_entry("if_inet6", net->proc_net);
109093 + unregister_ipv6_seq_ops_addr();
109094 }
109095
109096 static struct pernet_operations if6_proc_net_ops = {
109097 @@ -4141,7 +4148,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
109098 s_ip_idx = ip_idx = cb->args[2];
109099
109100 rcu_read_lock();
109101 - cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
109102 + cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
109103 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
109104 idx = 0;
109105 head = &net->dev_index_head[h];
109106 @@ -4753,7 +4760,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
109107 dst_free(&ifp->rt->dst);
109108 break;
109109 }
109110 - atomic_inc(&net->ipv6.dev_addr_genid);
109111 + atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
109112 rt_genid_bump_ipv6(net);
109113 }
109114
109115 @@ -4774,7 +4781,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
109116 int *valp = ctl->data;
109117 int val = *valp;
109118 loff_t pos = *ppos;
109119 - struct ctl_table lctl;
109120 + ctl_table_no_const lctl;
109121 int ret;
109122
109123 /*
109124 @@ -4859,7 +4866,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
109125 int *valp = ctl->data;
109126 int val = *valp;
109127 loff_t pos = *ppos;
109128 - struct ctl_table lctl;
109129 + ctl_table_no_const lctl;
109130 int ret;
109131
109132 /*
109133 diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
109134 index 7cb4392..dc96d28 100644
109135 --- a/net/ipv6/af_inet6.c
109136 +++ b/net/ipv6/af_inet6.c
109137 @@ -765,7 +765,7 @@ static int __net_init inet6_net_init(struct net *net)
109138 net->ipv6.sysctl.bindv6only = 0;
109139 net->ipv6.sysctl.icmpv6_time = 1*HZ;
109140 net->ipv6.sysctl.flowlabel_consistency = 1;
109141 - atomic_set(&net->ipv6.rt_genid, 0);
109142 + atomic_set_unchecked(&net->ipv6.rt_genid, 0);
109143
109144 err = ipv6_init_mibs(net);
109145 if (err)
109146 diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
109147 index c3bf2d2..1f00573 100644
109148 --- a/net/ipv6/datagram.c
109149 +++ b/net/ipv6/datagram.c
109150 @@ -938,5 +938,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
109151 0,
109152 sock_i_ino(sp),
109153 atomic_read(&sp->sk_refcnt), sp,
109154 - atomic_read(&sp->sk_drops));
109155 + atomic_read_unchecked(&sp->sk_drops));
109156 }
109157 diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
109158 index f6c84a6..9f2084e 100644
109159 --- a/net/ipv6/icmp.c
109160 +++ b/net/ipv6/icmp.c
109161 @@ -990,7 +990,7 @@ static struct ctl_table ipv6_icmp_table_template[] = {
109162
109163 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
109164 {
109165 - struct ctl_table *table;
109166 + ctl_table_no_const *table;
109167
109168 table = kmemdup(ipv6_icmp_table_template,
109169 sizeof(ipv6_icmp_table_template),
109170 diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
109171 index 3873181..220ad3f 100644
109172 --- a/net/ipv6/ip6_gre.c
109173 +++ b/net/ipv6/ip6_gre.c
109174 @@ -71,8 +71,8 @@ struct ip6gre_net {
109175 struct net_device *fb_tunnel_dev;
109176 };
109177
109178 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
109179 -static struct rtnl_link_ops ip6gre_tap_ops __read_mostly;
109180 +static struct rtnl_link_ops ip6gre_link_ops;
109181 +static struct rtnl_link_ops ip6gre_tap_ops;
109182 static int ip6gre_tunnel_init(struct net_device *dev);
109183 static void ip6gre_tunnel_setup(struct net_device *dev);
109184 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
109185 @@ -1280,7 +1280,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
109186 }
109187
109188
109189 -static struct inet6_protocol ip6gre_protocol __read_mostly = {
109190 +static struct inet6_protocol ip6gre_protocol = {
109191 .handler = ip6gre_rcv,
109192 .err_handler = ip6gre_err,
109193 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
109194 @@ -1638,7 +1638,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
109195 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
109196 };
109197
109198 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
109199 +static struct rtnl_link_ops ip6gre_link_ops = {
109200 .kind = "ip6gre",
109201 .maxtype = IFLA_GRE_MAX,
109202 .policy = ip6gre_policy,
109203 @@ -1652,7 +1652,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
109204 .fill_info = ip6gre_fill_info,
109205 };
109206
109207 -static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
109208 +static struct rtnl_link_ops ip6gre_tap_ops = {
109209 .kind = "ip6gretap",
109210 .maxtype = IFLA_GRE_MAX,
109211 .policy = ip6gre_policy,
109212 diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
109213 index afa0824..04ba530 100644
109214 --- a/net/ipv6/ip6_tunnel.c
109215 +++ b/net/ipv6/ip6_tunnel.c
109216 @@ -86,7 +86,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
109217
109218 static int ip6_tnl_dev_init(struct net_device *dev);
109219 static void ip6_tnl_dev_setup(struct net_device *dev);
109220 -static struct rtnl_link_ops ip6_link_ops __read_mostly;
109221 +static struct rtnl_link_ops ip6_link_ops;
109222
109223 static int ip6_tnl_net_id __read_mostly;
109224 struct ip6_tnl_net {
109225 @@ -1708,7 +1708,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
109226 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
109227 };
109228
109229 -static struct rtnl_link_ops ip6_link_ops __read_mostly = {
109230 +static struct rtnl_link_ops ip6_link_ops = {
109231 .kind = "ip6tnl",
109232 .maxtype = IFLA_IPTUN_MAX,
109233 .policy = ip6_tnl_policy,
109234 diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c
109235 index 9aaa6bb..5c13e57 100644
109236 --- a/net/ipv6/ip6_vti.c
109237 +++ b/net/ipv6/ip6_vti.c
109238 @@ -62,7 +62,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
109239
109240 static int vti6_dev_init(struct net_device *dev);
109241 static void vti6_dev_setup(struct net_device *dev);
109242 -static struct rtnl_link_ops vti6_link_ops __read_mostly;
109243 +static struct rtnl_link_ops vti6_link_ops;
109244
109245 static int vti6_net_id __read_mostly;
109246 struct vti6_net {
109247 @@ -977,7 +977,7 @@ static const struct nla_policy vti6_policy[IFLA_VTI_MAX + 1] = {
109248 [IFLA_VTI_OKEY] = { .type = NLA_U32 },
109249 };
109250
109251 -static struct rtnl_link_ops vti6_link_ops __read_mostly = {
109252 +static struct rtnl_link_ops vti6_link_ops = {
109253 .kind = "vti6",
109254 .maxtype = IFLA_VTI_MAX,
109255 .policy = vti6_policy,
109256 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
109257 index edb58af..78de133 100644
109258 --- a/net/ipv6/ipv6_sockglue.c
109259 +++ b/net/ipv6/ipv6_sockglue.c
109260 @@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
109261 if (sk->sk_type != SOCK_STREAM)
109262 return -ENOPROTOOPT;
109263
109264 - msg.msg_control = optval;
109265 + msg.msg_control = (void __force_kernel *)optval;
109266 msg.msg_controllen = len;
109267 msg.msg_flags = flags;
109268
109269 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
109270 index e080fbb..412b3cf 100644
109271 --- a/net/ipv6/netfilter/ip6_tables.c
109272 +++ b/net/ipv6/netfilter/ip6_tables.c
109273 @@ -1083,14 +1083,14 @@ static int compat_table_info(const struct xt_table_info *info,
109274 #endif
109275
109276 static int get_info(struct net *net, void __user *user,
109277 - const int *len, int compat)
109278 + int len, int compat)
109279 {
109280 char name[XT_TABLE_MAXNAMELEN];
109281 struct xt_table *t;
109282 int ret;
109283
109284 - if (*len != sizeof(struct ip6t_getinfo)) {
109285 - duprintf("length %u != %zu\n", *len,
109286 + if (len != sizeof(struct ip6t_getinfo)) {
109287 + duprintf("length %u != %zu\n", len,
109288 sizeof(struct ip6t_getinfo));
109289 return -EINVAL;
109290 }
109291 @@ -1127,7 +1127,7 @@ static int get_info(struct net *net, void __user *user,
109292 info.size = private->size;
109293 strcpy(info.name, name);
109294
109295 - if (copy_to_user(user, &info, *len) != 0)
109296 + if (copy_to_user(user, &info, len) != 0)
109297 ret = -EFAULT;
109298 else
109299 ret = 0;
109300 @@ -1983,7 +1983,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
109301
109302 switch (cmd) {
109303 case IP6T_SO_GET_INFO:
109304 - ret = get_info(sock_net(sk), user, len, 1);
109305 + ret = get_info(sock_net(sk), user, *len, 1);
109306 break;
109307 case IP6T_SO_GET_ENTRIES:
109308 ret = compat_get_entries(sock_net(sk), user, len);
109309 @@ -2030,7 +2030,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
109310
109311 switch (cmd) {
109312 case IP6T_SO_GET_INFO:
109313 - ret = get_info(sock_net(sk), user, len, 0);
109314 + ret = get_info(sock_net(sk), user, *len, 0);
109315 break;
109316
109317 case IP6T_SO_GET_ENTRIES:
109318 diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
109319 index 0d5279f..89d9f6f 100644
109320 --- a/net/ipv6/netfilter/nf_conntrack_reasm.c
109321 +++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
109322 @@ -90,12 +90,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
109323
109324 static int nf_ct_frag6_sysctl_register(struct net *net)
109325 {
109326 - struct ctl_table *table;
109327 + ctl_table_no_const *table = NULL;
109328 struct ctl_table_header *hdr;
109329
109330 - table = nf_ct_frag6_sysctl_table;
109331 if (!net_eq(net, &init_net)) {
109332 - table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
109333 + table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
109334 GFP_KERNEL);
109335 if (table == NULL)
109336 goto err_alloc;
109337 @@ -103,9 +102,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
109338 table[0].data = &net->nf_frag.frags.timeout;
109339 table[1].data = &net->nf_frag.frags.low_thresh;
109340 table[2].data = &net->nf_frag.frags.high_thresh;
109341 - }
109342 -
109343 - hdr = register_net_sysctl(net, "net/netfilter", table);
109344 + hdr = register_net_sysctl(net, "net/netfilter", table);
109345 + } else
109346 + hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
109347 if (hdr == NULL)
109348 goto err_reg;
109349
109350 @@ -113,8 +112,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
109351 return 0;
109352
109353 err_reg:
109354 - if (!net_eq(net, &init_net))
109355 - kfree(table);
109356 + kfree(table);
109357 err_alloc:
109358 return -ENOMEM;
109359 }
109360 diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
109361 index 5b7a1ed..d9da205 100644
109362 --- a/net/ipv6/ping.c
109363 +++ b/net/ipv6/ping.c
109364 @@ -240,6 +240,24 @@ static struct pernet_operations ping_v6_net_ops = {
109365 };
109366 #endif
109367
109368 +static struct pingv6_ops real_pingv6_ops = {
109369 + .ipv6_recv_error = ipv6_recv_error,
109370 + .ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl,
109371 + .ip6_datagram_recv_specific_ctl = ip6_datagram_recv_specific_ctl,
109372 + .icmpv6_err_convert = icmpv6_err_convert,
109373 + .ipv6_icmp_error = ipv6_icmp_error,
109374 + .ipv6_chk_addr = ipv6_chk_addr,
109375 +};
109376 +
109377 +static struct pingv6_ops dummy_pingv6_ops = {
109378 + .ipv6_recv_error = dummy_ipv6_recv_error,
109379 + .ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl,
109380 + .ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl,
109381 + .icmpv6_err_convert = dummy_icmpv6_err_convert,
109382 + .ipv6_icmp_error = dummy_ipv6_icmp_error,
109383 + .ipv6_chk_addr = dummy_ipv6_chk_addr,
109384 +};
109385 +
109386 int __init pingv6_init(void)
109387 {
109388 #ifdef CONFIG_PROC_FS
109389 @@ -247,13 +265,7 @@ int __init pingv6_init(void)
109390 if (ret)
109391 return ret;
109392 #endif
109393 - pingv6_ops.ipv6_recv_error = ipv6_recv_error;
109394 - pingv6_ops.ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl;
109395 - pingv6_ops.ip6_datagram_recv_specific_ctl =
109396 - ip6_datagram_recv_specific_ctl;
109397 - pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
109398 - pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
109399 - pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
109400 + pingv6_ops = &real_pingv6_ops;
109401 return inet6_register_protosw(&pingv6_protosw);
109402 }
109403
109404 @@ -262,14 +274,9 @@ int __init pingv6_init(void)
109405 */
109406 void pingv6_exit(void)
109407 {
109408 - pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
109409 - pingv6_ops.ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl;
109410 - pingv6_ops.ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl;
109411 - pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
109412 - pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
109413 - pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
109414 #ifdef CONFIG_PROC_FS
109415 unregister_pernet_subsys(&ping_v6_net_ops);
109416 #endif
109417 + pingv6_ops = &dummy_pingv6_ops;
109418 inet6_unregister_protosw(&pingv6_protosw);
109419 }
109420 diff --git a/net/ipv6/proc.c b/net/ipv6/proc.c
109421 index 3317440..201764e 100644
109422 --- a/net/ipv6/proc.c
109423 +++ b/net/ipv6/proc.c
109424 @@ -309,7 +309,7 @@ static int __net_init ipv6_proc_init_net(struct net *net)
109425 if (!proc_create("snmp6", S_IRUGO, net->proc_net, &snmp6_seq_fops))
109426 goto proc_snmp6_fail;
109427
109428 - net->mib.proc_net_devsnmp6 = proc_mkdir("dev_snmp6", net->proc_net);
109429 + net->mib.proc_net_devsnmp6 = proc_mkdir_restrict("dev_snmp6", net->proc_net);
109430 if (!net->mib.proc_net_devsnmp6)
109431 goto proc_dev_snmp6_fail;
109432 return 0;
109433 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
109434 index b2dc60b..a6b6c10 100644
109435 --- a/net/ipv6/raw.c
109436 +++ b/net/ipv6/raw.c
109437 @@ -388,7 +388,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
109438 {
109439 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
109440 skb_checksum_complete(skb)) {
109441 - atomic_inc(&sk->sk_drops);
109442 + atomic_inc_unchecked(&sk->sk_drops);
109443 kfree_skb(skb);
109444 return NET_RX_DROP;
109445 }
109446 @@ -416,7 +416,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
109447 struct raw6_sock *rp = raw6_sk(sk);
109448
109449 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
109450 - atomic_inc(&sk->sk_drops);
109451 + atomic_inc_unchecked(&sk->sk_drops);
109452 kfree_skb(skb);
109453 return NET_RX_DROP;
109454 }
109455 @@ -440,7 +440,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
109456
109457 if (inet->hdrincl) {
109458 if (skb_checksum_complete(skb)) {
109459 - atomic_inc(&sk->sk_drops);
109460 + atomic_inc_unchecked(&sk->sk_drops);
109461 kfree_skb(skb);
109462 return NET_RX_DROP;
109463 }
109464 @@ -610,7 +610,7 @@ out:
109465 return err;
109466 }
109467
109468 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
109469 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
109470 struct flowi6 *fl6, struct dst_entry **dstp,
109471 unsigned int flags)
109472 {
109473 @@ -916,12 +916,15 @@ do_confirm:
109474 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
109475 char __user *optval, int optlen)
109476 {
109477 + struct icmp6_filter filter;
109478 +
109479 switch (optname) {
109480 case ICMPV6_FILTER:
109481 if (optlen > sizeof(struct icmp6_filter))
109482 optlen = sizeof(struct icmp6_filter);
109483 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
109484 + if (copy_from_user(&filter, optval, optlen))
109485 return -EFAULT;
109486 + raw6_sk(sk)->filter = filter;
109487 return 0;
109488 default:
109489 return -ENOPROTOOPT;
109490 @@ -934,6 +937,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
109491 char __user *optval, int __user *optlen)
109492 {
109493 int len;
109494 + struct icmp6_filter filter;
109495
109496 switch (optname) {
109497 case ICMPV6_FILTER:
109498 @@ -945,7 +949,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
109499 len = sizeof(struct icmp6_filter);
109500 if (put_user(len, optlen))
109501 return -EFAULT;
109502 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
109503 + filter = raw6_sk(sk)->filter;
109504 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
109505 return -EFAULT;
109506 return 0;
109507 default:
109508 diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
109509 index cc85a9b..526a133 100644
109510 --- a/net/ipv6/reassembly.c
109511 +++ b/net/ipv6/reassembly.c
109512 @@ -626,12 +626,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
109513
109514 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
109515 {
109516 - struct ctl_table *table;
109517 + ctl_table_no_const *table = NULL;
109518 struct ctl_table_header *hdr;
109519
109520 - table = ip6_frags_ns_ctl_table;
109521 if (!net_eq(net, &init_net)) {
109522 - table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
109523 + table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
109524 if (table == NULL)
109525 goto err_alloc;
109526
109527 @@ -642,9 +641,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
109528 /* Don't export sysctls to unprivileged users */
109529 if (net->user_ns != &init_user_ns)
109530 table[0].procname = NULL;
109531 - }
109532 + hdr = register_net_sysctl(net, "net/ipv6", table);
109533 + } else
109534 + hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
109535
109536 - hdr = register_net_sysctl(net, "net/ipv6", table);
109537 if (hdr == NULL)
109538 goto err_reg;
109539
109540 @@ -652,8 +652,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
109541 return 0;
109542
109543 err_reg:
109544 - if (!net_eq(net, &init_net))
109545 - kfree(table);
109546 + kfree(table);
109547 err_alloc:
109548 return -ENOMEM;
109549 }
109550 diff --git a/net/ipv6/route.c b/net/ipv6/route.c
109551 index f23fbd2..7868241 100644
109552 --- a/net/ipv6/route.c
109553 +++ b/net/ipv6/route.c
109554 @@ -2971,7 +2971,7 @@ struct ctl_table ipv6_route_table_template[] = {
109555
109556 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
109557 {
109558 - struct ctl_table *table;
109559 + ctl_table_no_const *table;
109560
109561 table = kmemdup(ipv6_route_table_template,
109562 sizeof(ipv6_route_table_template),
109563 diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
109564 index 4f40817..54dcbef 100644
109565 --- a/net/ipv6/sit.c
109566 +++ b/net/ipv6/sit.c
109567 @@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
109568 static void ipip6_dev_free(struct net_device *dev);
109569 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
109570 __be32 *v4dst);
109571 -static struct rtnl_link_ops sit_link_ops __read_mostly;
109572 +static struct rtnl_link_ops sit_link_ops;
109573
109574 static int sit_net_id __read_mostly;
109575 struct sit_net {
109576 @@ -1661,7 +1661,7 @@ static void ipip6_dellink(struct net_device *dev, struct list_head *head)
109577 unregister_netdevice_queue(dev, head);
109578 }
109579
109580 -static struct rtnl_link_ops sit_link_ops __read_mostly = {
109581 +static struct rtnl_link_ops sit_link_ops = {
109582 .kind = "sit",
109583 .maxtype = IFLA_IPTUN_MAX,
109584 .policy = ipip6_policy,
109585 diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
109586 index 058f3ec..dec973d 100644
109587 --- a/net/ipv6/sysctl_net_ipv6.c
109588 +++ b/net/ipv6/sysctl_net_ipv6.c
109589 @@ -61,7 +61,7 @@ static struct ctl_table ipv6_rotable[] = {
109590
109591 static int __net_init ipv6_sysctl_net_init(struct net *net)
109592 {
109593 - struct ctl_table *ipv6_table;
109594 + ctl_table_no_const *ipv6_table;
109595 struct ctl_table *ipv6_route_table;
109596 struct ctl_table *ipv6_icmp_table;
109597 int err;
109598 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
109599 index 229239ad..ee2802f 100644
109600 --- a/net/ipv6/tcp_ipv6.c
109601 +++ b/net/ipv6/tcp_ipv6.c
109602 @@ -102,6 +102,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
109603 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
109604 }
109605
109606 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
109607 +extern int grsec_enable_blackhole;
109608 +#endif
109609 +
109610 static void tcp_v6_hash(struct sock *sk)
109611 {
109612 if (sk->sk_state != TCP_CLOSE) {
109613 @@ -1424,6 +1428,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
109614 return 0;
109615
109616 reset:
109617 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
109618 + if (!grsec_enable_blackhole)
109619 +#endif
109620 tcp_v6_send_reset(sk, skb);
109621 discard:
109622 if (opt_skb)
109623 @@ -1508,12 +1515,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
109624 TCP_SKB_CB(skb)->sacked = 0;
109625
109626 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
109627 - if (!sk)
109628 + if (!sk) {
109629 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
109630 + ret = 1;
109631 +#endif
109632 goto no_tcp_socket;
109633 + }
109634
109635 process:
109636 - if (sk->sk_state == TCP_TIME_WAIT)
109637 + if (sk->sk_state == TCP_TIME_WAIT) {
109638 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
109639 + ret = 2;
109640 +#endif
109641 goto do_time_wait;
109642 + }
109643
109644 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
109645 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
109646 @@ -1565,6 +1580,10 @@ csum_error:
109647 bad_packet:
109648 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
109649 } else {
109650 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
109651 + if (!grsec_enable_blackhole || (ret == 1 &&
109652 + (skb->dev->flags & IFF_LOOPBACK)))
109653 +#endif
109654 tcp_v6_send_reset(NULL, skb);
109655 }
109656
109657 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
109658 index 7092ff7..3fd0eb4 100644
109659 --- a/net/ipv6/udp.c
109660 +++ b/net/ipv6/udp.c
109661 @@ -76,6 +76,10 @@ static unsigned int udp6_ehashfn(struct net *net,
109662 udp_ipv6_hash_secret + net_hash_mix(net));
109663 }
109664
109665 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
109666 +extern int grsec_enable_blackhole;
109667 +#endif
109668 +
109669 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
109670 {
109671 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
109672 @@ -435,7 +439,7 @@ try_again:
109673 if (unlikely(err)) {
109674 trace_kfree_skb(skb, udpv6_recvmsg);
109675 if (!peeked) {
109676 - atomic_inc(&sk->sk_drops);
109677 + atomic_inc_unchecked(&sk->sk_drops);
109678 if (is_udp4)
109679 UDP_INC_STATS_USER(sock_net(sk),
109680 UDP_MIB_INERRORS,
109681 @@ -698,7 +702,7 @@ csum_error:
109682 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
109683 drop:
109684 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
109685 - atomic_inc(&sk->sk_drops);
109686 + atomic_inc_unchecked(&sk->sk_drops);
109687 kfree_skb(skb);
109688 return -1;
109689 }
109690 @@ -754,7 +758,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
109691 if (likely(skb1 == NULL))
109692 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
109693 if (!skb1) {
109694 - atomic_inc(&sk->sk_drops);
109695 + atomic_inc_unchecked(&sk->sk_drops);
109696 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
109697 IS_UDPLITE(sk));
109698 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
109699 @@ -920,6 +924,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
109700 goto csum_error;
109701
109702 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
109703 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
109704 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
109705 +#endif
109706 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
109707
109708 kfree_skb(skb);
109709 diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
109710 index 2a0bbda..d75ca57 100644
109711 --- a/net/ipv6/xfrm6_policy.c
109712 +++ b/net/ipv6/xfrm6_policy.c
109713 @@ -212,11 +212,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
109714 }
109715 }
109716
109717 -static inline int xfrm6_garbage_collect(struct dst_ops *ops)
109718 +static int xfrm6_garbage_collect(struct dst_ops *ops)
109719 {
109720 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
109721
109722 - xfrm6_policy_afinfo.garbage_collect(net);
109723 + xfrm_garbage_collect_deferred(net);
109724 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
109725 }
109726
109727 @@ -329,19 +329,19 @@ static struct ctl_table xfrm6_policy_table[] = {
109728
109729 static int __net_init xfrm6_net_init(struct net *net)
109730 {
109731 - struct ctl_table *table;
109732 + ctl_table_no_const *table = NULL;
109733 struct ctl_table_header *hdr;
109734
109735 - table = xfrm6_policy_table;
109736 if (!net_eq(net, &init_net)) {
109737 - table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
109738 + table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
109739 if (!table)
109740 goto err_alloc;
109741
109742 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
109743 - }
109744 + hdr = register_net_sysctl(net, "net/ipv6", table);
109745 + } else
109746 + hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
109747
109748 - hdr = register_net_sysctl(net, "net/ipv6", table);
109749 if (!hdr)
109750 goto err_reg;
109751
109752 @@ -349,8 +349,7 @@ static int __net_init xfrm6_net_init(struct net *net)
109753 return 0;
109754
109755 err_reg:
109756 - if (!net_eq(net, &init_net))
109757 - kfree(table);
109758 + kfree(table);
109759 err_alloc:
109760 return -ENOMEM;
109761 }
109762 diff --git a/net/ipx/ipx_proc.c b/net/ipx/ipx_proc.c
109763 index e15c16a..7cf07aa 100644
109764 --- a/net/ipx/ipx_proc.c
109765 +++ b/net/ipx/ipx_proc.c
109766 @@ -289,7 +289,7 @@ int __init ipx_proc_init(void)
109767 struct proc_dir_entry *p;
109768 int rc = -ENOMEM;
109769
109770 - ipx_proc_dir = proc_mkdir("ipx", init_net.proc_net);
109771 + ipx_proc_dir = proc_mkdir_restrict("ipx", init_net.proc_net);
109772
109773 if (!ipx_proc_dir)
109774 goto out;
109775 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
109776 index 2ba8b97..6d33010 100644
109777 --- a/net/irda/ircomm/ircomm_tty.c
109778 +++ b/net/irda/ircomm/ircomm_tty.c
109779 @@ -317,11 +317,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
109780 add_wait_queue(&port->open_wait, &wait);
109781
109782 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
109783 - __FILE__, __LINE__, tty->driver->name, port->count);
109784 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
109785
109786 spin_lock_irqsave(&port->lock, flags);
109787 if (!tty_hung_up_p(filp))
109788 - port->count--;
109789 + atomic_dec(&port->count);
109790 port->blocked_open++;
109791 spin_unlock_irqrestore(&port->lock, flags);
109792
109793 @@ -356,7 +356,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
109794 }
109795
109796 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
109797 - __FILE__, __LINE__, tty->driver->name, port->count);
109798 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
109799
109800 schedule();
109801 }
109802 @@ -366,12 +366,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
109803
109804 spin_lock_irqsave(&port->lock, flags);
109805 if (!tty_hung_up_p(filp))
109806 - port->count++;
109807 + atomic_inc(&port->count);
109808 port->blocked_open--;
109809 spin_unlock_irqrestore(&port->lock, flags);
109810
109811 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
109812 - __FILE__, __LINE__, tty->driver->name, port->count);
109813 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
109814
109815 if (!retval)
109816 port->flags |= ASYNC_NORMAL_ACTIVE;
109817 @@ -445,12 +445,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
109818
109819 /* ++ is not atomic, so this should be protected - Jean II */
109820 spin_lock_irqsave(&self->port.lock, flags);
109821 - self->port.count++;
109822 + atomic_inc(&self->port.count);
109823 spin_unlock_irqrestore(&self->port.lock, flags);
109824 tty_port_tty_set(&self->port, tty);
109825
109826 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
109827 - self->line, self->port.count);
109828 + self->line, atomic_read(&self->port.count));
109829
109830 /* Not really used by us, but lets do it anyway */
109831 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
109832 @@ -987,7 +987,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
109833 tty_kref_put(port->tty);
109834 }
109835 port->tty = NULL;
109836 - port->count = 0;
109837 + atomic_set(&port->count, 0);
109838 spin_unlock_irqrestore(&port->lock, flags);
109839
109840 wake_up_interruptible(&port->open_wait);
109841 @@ -1344,7 +1344,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
109842 seq_putc(m, '\n');
109843
109844 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
109845 - seq_printf(m, "Open count: %d\n", self->port.count);
109846 + seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
109847 seq_printf(m, "Max data size: %d\n", self->max_data_size);
109848 seq_printf(m, "Max header size: %d\n", self->max_header_size);
109849
109850 diff --git a/net/irda/irproc.c b/net/irda/irproc.c
109851 index b9ac598..f88cc56 100644
109852 --- a/net/irda/irproc.c
109853 +++ b/net/irda/irproc.c
109854 @@ -66,7 +66,7 @@ void __init irda_proc_register(void)
109855 {
109856 int i;
109857
109858 - proc_irda = proc_mkdir("irda", init_net.proc_net);
109859 + proc_irda = proc_mkdir_restrict("irda", init_net.proc_net);
109860 if (proc_irda == NULL)
109861 return;
109862
109863 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
109864 index 7a95fa4..57be196 100644
109865 --- a/net/iucv/af_iucv.c
109866 +++ b/net/iucv/af_iucv.c
109867 @@ -686,10 +686,10 @@ static void __iucv_auto_name(struct iucv_sock *iucv)
109868 {
109869 char name[12];
109870
109871 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
109872 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
109873 while (__iucv_get_sock_by_name(name)) {
109874 sprintf(name, "%08x",
109875 - atomic_inc_return(&iucv_sk_list.autobind_name));
109876 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
109877 }
109878 memcpy(iucv->src_name, name, 8);
109879 }
109880 diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
109881 index da78793..bdd78cf 100644
109882 --- a/net/iucv/iucv.c
109883 +++ b/net/iucv/iucv.c
109884 @@ -702,7 +702,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
109885 return NOTIFY_OK;
109886 }
109887
109888 -static struct notifier_block __refdata iucv_cpu_notifier = {
109889 +static struct notifier_block iucv_cpu_notifier = {
109890 .notifier_call = iucv_cpu_notify,
109891 };
109892
109893 diff --git a/net/key/af_key.c b/net/key/af_key.c
109894 index ba2a2f9..b658bc3 100644
109895 --- a/net/key/af_key.c
109896 +++ b/net/key/af_key.c
109897 @@ -3052,10 +3052,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
109898 static u32 get_acqseq(void)
109899 {
109900 u32 res;
109901 - static atomic_t acqseq;
109902 + static atomic_unchecked_t acqseq;
109903
109904 do {
109905 - res = atomic_inc_return(&acqseq);
109906 + res = atomic_inc_return_unchecked(&acqseq);
109907 } while (!res);
109908 return res;
109909 }
109910 diff --git a/net/l2tp/l2tp_eth.c b/net/l2tp/l2tp_eth.c
109911 index 76125c5..e474828 100644
109912 --- a/net/l2tp/l2tp_eth.c
109913 +++ b/net/l2tp/l2tp_eth.c
109914 @@ -42,12 +42,12 @@ struct l2tp_eth {
109915 struct sock *tunnel_sock;
109916 struct l2tp_session *session;
109917 struct list_head list;
109918 - atomic_long_t tx_bytes;
109919 - atomic_long_t tx_packets;
109920 - atomic_long_t tx_dropped;
109921 - atomic_long_t rx_bytes;
109922 - atomic_long_t rx_packets;
109923 - atomic_long_t rx_errors;
109924 + atomic_long_unchecked_t tx_bytes;
109925 + atomic_long_unchecked_t tx_packets;
109926 + atomic_long_unchecked_t tx_dropped;
109927 + atomic_long_unchecked_t rx_bytes;
109928 + atomic_long_unchecked_t rx_packets;
109929 + atomic_long_unchecked_t rx_errors;
109930 };
109931
109932 /* via l2tp_session_priv() */
109933 @@ -98,10 +98,10 @@ static int l2tp_eth_dev_xmit(struct sk_buff *skb, struct net_device *dev)
109934 int ret = l2tp_xmit_skb(session, skb, session->hdr_len);
109935
109936 if (likely(ret == NET_XMIT_SUCCESS)) {
109937 - atomic_long_add(len, &priv->tx_bytes);
109938 - atomic_long_inc(&priv->tx_packets);
109939 + atomic_long_add_unchecked(len, &priv->tx_bytes);
109940 + atomic_long_inc_unchecked(&priv->tx_packets);
109941 } else {
109942 - atomic_long_inc(&priv->tx_dropped);
109943 + atomic_long_inc_unchecked(&priv->tx_dropped);
109944 }
109945 return NETDEV_TX_OK;
109946 }
109947 @@ -111,12 +111,12 @@ static struct rtnl_link_stats64 *l2tp_eth_get_stats64(struct net_device *dev,
109948 {
109949 struct l2tp_eth *priv = netdev_priv(dev);
109950
109951 - stats->tx_bytes = atomic_long_read(&priv->tx_bytes);
109952 - stats->tx_packets = atomic_long_read(&priv->tx_packets);
109953 - stats->tx_dropped = atomic_long_read(&priv->tx_dropped);
109954 - stats->rx_bytes = atomic_long_read(&priv->rx_bytes);
109955 - stats->rx_packets = atomic_long_read(&priv->rx_packets);
109956 - stats->rx_errors = atomic_long_read(&priv->rx_errors);
109957 + stats->tx_bytes = atomic_long_read_unchecked(&priv->tx_bytes);
109958 + stats->tx_packets = atomic_long_read_unchecked(&priv->tx_packets);
109959 + stats->tx_dropped = atomic_long_read_unchecked(&priv->tx_dropped);
109960 + stats->rx_bytes = atomic_long_read_unchecked(&priv->rx_bytes);
109961 + stats->rx_packets = atomic_long_read_unchecked(&priv->rx_packets);
109962 + stats->rx_errors = atomic_long_read_unchecked(&priv->rx_errors);
109963 return stats;
109964 }
109965
109966 @@ -166,15 +166,15 @@ static void l2tp_eth_dev_recv(struct l2tp_session *session, struct sk_buff *skb,
109967 nf_reset(skb);
109968
109969 if (dev_forward_skb(dev, skb) == NET_RX_SUCCESS) {
109970 - atomic_long_inc(&priv->rx_packets);
109971 - atomic_long_add(data_len, &priv->rx_bytes);
109972 + atomic_long_inc_unchecked(&priv->rx_packets);
109973 + atomic_long_add_unchecked(data_len, &priv->rx_bytes);
109974 } else {
109975 - atomic_long_inc(&priv->rx_errors);
109976 + atomic_long_inc_unchecked(&priv->rx_errors);
109977 }
109978 return;
109979
109980 error:
109981 - atomic_long_inc(&priv->rx_errors);
109982 + atomic_long_inc_unchecked(&priv->rx_errors);
109983 kfree_skb(skb);
109984 }
109985
109986 diff --git a/net/llc/llc_proc.c b/net/llc/llc_proc.c
109987 index 1a3c7e0..80f8b0c 100644
109988 --- a/net/llc/llc_proc.c
109989 +++ b/net/llc/llc_proc.c
109990 @@ -247,7 +247,7 @@ int __init llc_proc_init(void)
109991 int rc = -ENOMEM;
109992 struct proc_dir_entry *p;
109993
109994 - llc_proc_dir = proc_mkdir("llc", init_net.proc_net);
109995 + llc_proc_dir = proc_mkdir_restrict("llc", init_net.proc_net);
109996 if (!llc_proc_dir)
109997 goto out;
109998
109999 diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
110000 index 592f4b1..efa7aa9 100644
110001 --- a/net/mac80211/cfg.c
110002 +++ b/net/mac80211/cfg.c
110003 @@ -864,7 +864,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
110004 ret = ieee80211_vif_use_channel(sdata, chandef,
110005 IEEE80211_CHANCTX_EXCLUSIVE);
110006 }
110007 - } else if (local->open_count == local->monitors) {
110008 + } else if (local_read(&local->open_count) == local->monitors) {
110009 local->_oper_chandef = *chandef;
110010 ieee80211_hw_config(local, 0);
110011 }
110012 @@ -3574,7 +3574,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
110013 else
110014 local->probe_req_reg--;
110015
110016 - if (!local->open_count)
110017 + if (!local_read(&local->open_count))
110018 break;
110019
110020 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
110021 @@ -3723,8 +3723,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
110022 if (chanctx_conf) {
110023 *chandef = chanctx_conf->def;
110024 ret = 0;
110025 - } else if (local->open_count > 0 &&
110026 - local->open_count == local->monitors &&
110027 + } else if (local_read(&local->open_count) > 0 &&
110028 + local_read(&local->open_count) == local->monitors &&
110029 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
110030 if (local->use_chanctx)
110031 *chandef = local->monitor_chandef;
110032 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
110033 index ac9836e..32613c1 100644
110034 --- a/net/mac80211/ieee80211_i.h
110035 +++ b/net/mac80211/ieee80211_i.h
110036 @@ -28,6 +28,7 @@
110037 #include <net/ieee80211_radiotap.h>
110038 #include <net/cfg80211.h>
110039 #include <net/mac80211.h>
110040 +#include <asm/local.h>
110041 #include "key.h"
110042 #include "sta_info.h"
110043 #include "debug.h"
110044 @@ -1011,7 +1012,7 @@ struct ieee80211_local {
110045 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
110046 spinlock_t queue_stop_reason_lock;
110047
110048 - int open_count;
110049 + local_t open_count;
110050 int monitors, cooked_mntrs;
110051 /* number of interfaces with corresponding FIF_ flags */
110052 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
110053 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
110054 index 388b863..6575b55 100644
110055 --- a/net/mac80211/iface.c
110056 +++ b/net/mac80211/iface.c
110057 @@ -531,7 +531,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
110058 break;
110059 }
110060
110061 - if (local->open_count == 0) {
110062 + if (local_read(&local->open_count) == 0) {
110063 res = drv_start(local);
110064 if (res)
110065 goto err_del_bss;
110066 @@ -578,7 +578,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
110067 res = drv_add_interface(local, sdata);
110068 if (res)
110069 goto err_stop;
110070 - } else if (local->monitors == 0 && local->open_count == 0) {
110071 + } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
110072 res = ieee80211_add_virtual_monitor(local);
110073 if (res)
110074 goto err_stop;
110075 @@ -687,7 +687,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
110076 atomic_inc(&local->iff_promiscs);
110077
110078 if (coming_up)
110079 - local->open_count++;
110080 + local_inc(&local->open_count);
110081
110082 if (hw_reconf_flags)
110083 ieee80211_hw_config(local, hw_reconf_flags);
110084 @@ -725,7 +725,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
110085 err_del_interface:
110086 drv_remove_interface(local, sdata);
110087 err_stop:
110088 - if (!local->open_count)
110089 + if (!local_read(&local->open_count))
110090 drv_stop(local);
110091 err_del_bss:
110092 sdata->bss = NULL;
110093 @@ -888,7 +888,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
110094 }
110095
110096 if (going_down)
110097 - local->open_count--;
110098 + local_dec(&local->open_count);
110099
110100 switch (sdata->vif.type) {
110101 case NL80211_IFTYPE_AP_VLAN:
110102 @@ -949,7 +949,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
110103 }
110104 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
110105
110106 - if (local->open_count == 0)
110107 + if (local_read(&local->open_count) == 0)
110108 ieee80211_clear_tx_pending(local);
110109
110110 /*
110111 @@ -989,7 +989,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
110112
110113 ieee80211_recalc_ps(local, -1);
110114
110115 - if (local->open_count == 0) {
110116 + if (local_read(&local->open_count) == 0) {
110117 ieee80211_stop_device(local);
110118
110119 /* no reconfiguring after stop! */
110120 @@ -1000,7 +1000,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
110121 ieee80211_configure_filter(local);
110122 ieee80211_hw_config(local, hw_reconf_flags);
110123
110124 - if (local->monitors == local->open_count)
110125 + if (local->monitors == local_read(&local->open_count))
110126 ieee80211_add_virtual_monitor(local);
110127 }
110128
110129 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
110130 index d17c26d..43d6bfb 100644
110131 --- a/net/mac80211/main.c
110132 +++ b/net/mac80211/main.c
110133 @@ -174,7 +174,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
110134 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
110135 IEEE80211_CONF_CHANGE_POWER);
110136
110137 - if (changed && local->open_count) {
110138 + if (changed && local_read(&local->open_count)) {
110139 ret = drv_config(local, changed);
110140 /*
110141 * Goal:
110142 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
110143 index d478b88..8c8d157 100644
110144 --- a/net/mac80211/pm.c
110145 +++ b/net/mac80211/pm.c
110146 @@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
110147 struct ieee80211_sub_if_data *sdata;
110148 struct sta_info *sta;
110149
110150 - if (!local->open_count)
110151 + if (!local_read(&local->open_count))
110152 goto suspend;
110153
110154 ieee80211_scan_cancel(local);
110155 @@ -58,7 +58,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
110156 cancel_work_sync(&local->dynamic_ps_enable_work);
110157 del_timer_sync(&local->dynamic_ps_timer);
110158
110159 - local->wowlan = wowlan && local->open_count;
110160 + local->wowlan = wowlan && local_read(&local->open_count);
110161 if (local->wowlan) {
110162 int err = drv_suspend(local, wowlan);
110163 if (err < 0) {
110164 @@ -123,7 +123,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
110165 WARN_ON(!list_empty(&local->chanctx_list));
110166
110167 /* stop hardware - this must stop RX */
110168 - if (local->open_count)
110169 + if (local_read(&local->open_count))
110170 ieee80211_stop_device(local);
110171
110172 suspend:
110173 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
110174 index 8fdadfd..a4f72b8 100644
110175 --- a/net/mac80211/rate.c
110176 +++ b/net/mac80211/rate.c
110177 @@ -720,7 +720,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
110178
110179 ASSERT_RTNL();
110180
110181 - if (local->open_count)
110182 + if (local_read(&local->open_count))
110183 return -EBUSY;
110184
110185 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
110186 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
110187 index 6ff1346..936ca9a 100644
110188 --- a/net/mac80211/rc80211_pid_debugfs.c
110189 +++ b/net/mac80211/rc80211_pid_debugfs.c
110190 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
110191
110192 spin_unlock_irqrestore(&events->lock, status);
110193
110194 - if (copy_to_user(buf, pb, p))
110195 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
110196 return -EFAULT;
110197
110198 return p;
110199 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
110200 index a6cda52..f3b6776 100644
110201 --- a/net/mac80211/util.c
110202 +++ b/net/mac80211/util.c
110203 @@ -1548,7 +1548,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
110204 }
110205 #endif
110206 /* everything else happens only if HW was up & running */
110207 - if (!local->open_count)
110208 + if (!local_read(&local->open_count))
110209 goto wake_up;
110210
110211 /*
110212 @@ -1772,7 +1772,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
110213 local->in_reconfig = false;
110214 barrier();
110215
110216 - if (local->monitors == local->open_count && local->monitors > 0)
110217 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
110218 ieee80211_add_virtual_monitor(local);
110219
110220 /*
110221 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
110222 index e9410d1..77b6378 100644
110223 --- a/net/netfilter/Kconfig
110224 +++ b/net/netfilter/Kconfig
110225 @@ -1081,6 +1081,16 @@ config NETFILTER_XT_MATCH_ESP
110226
110227 To compile it as a module, choose M here. If unsure, say N.
110228
110229 +config NETFILTER_XT_MATCH_GRADM
110230 + tristate '"gradm" match support'
110231 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
110232 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
110233 + ---help---
110234 + The gradm match allows to match on grsecurity RBAC being enabled.
110235 + It is useful when iptables rules are applied early on bootup to
110236 + prevent connections to the machine (except from a trusted host)
110237 + while the RBAC system is disabled.
110238 +
110239 config NETFILTER_XT_MATCH_HASHLIMIT
110240 tristate '"hashlimit" match support'
110241 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
110242 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
110243 index bffdad7..f9317d1 100644
110244 --- a/net/netfilter/Makefile
110245 +++ b/net/netfilter/Makefile
110246 @@ -133,6 +133,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
110247 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
110248 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
110249 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
110250 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
110251 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
110252 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
110253 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
110254 diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
110255 index ec8114f..6b2bfba 100644
110256 --- a/net/netfilter/ipset/ip_set_core.c
110257 +++ b/net/netfilter/ipset/ip_set_core.c
110258 @@ -1921,7 +1921,7 @@ done:
110259 return ret;
110260 }
110261
110262 -static struct nf_sockopt_ops so_set __read_mostly = {
110263 +static struct nf_sockopt_ops so_set = {
110264 .pf = PF_INET,
110265 .get_optmin = SO_IP_SET,
110266 .get_optmax = SO_IP_SET + 1,
110267 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
110268 index 610e19c..08d0c3f 100644
110269 --- a/net/netfilter/ipvs/ip_vs_conn.c
110270 +++ b/net/netfilter/ipvs/ip_vs_conn.c
110271 @@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
110272 /* Increase the refcnt counter of the dest */
110273 ip_vs_dest_hold(dest);
110274
110275 - conn_flags = atomic_read(&dest->conn_flags);
110276 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
110277 if (cp->protocol != IPPROTO_UDP)
110278 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
110279 flags = cp->flags;
110280 @@ -899,7 +899,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
110281
110282 cp->control = NULL;
110283 atomic_set(&cp->n_control, 0);
110284 - atomic_set(&cp->in_pkts, 0);
110285 + atomic_set_unchecked(&cp->in_pkts, 0);
110286
110287 cp->packet_xmit = NULL;
110288 cp->app = NULL;
110289 @@ -1187,7 +1187,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
110290
110291 /* Don't drop the entry if its number of incoming packets is not
110292 located in [0, 8] */
110293 - i = atomic_read(&cp->in_pkts);
110294 + i = atomic_read_unchecked(&cp->in_pkts);
110295 if (i > 8 || i < 0) return 0;
110296
110297 if (!todrop_rate[i]) return 0;
110298 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
110299 index e683675..67cb16b 100644
110300 --- a/net/netfilter/ipvs/ip_vs_core.c
110301 +++ b/net/netfilter/ipvs/ip_vs_core.c
110302 @@ -567,7 +567,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
110303 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
110304 /* do not touch skb anymore */
110305
110306 - atomic_inc(&cp->in_pkts);
110307 + atomic_inc_unchecked(&cp->in_pkts);
110308 ip_vs_conn_put(cp);
110309 return ret;
110310 }
110311 @@ -1711,7 +1711,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
110312 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
110313 pkts = sysctl_sync_threshold(ipvs);
110314 else
110315 - pkts = atomic_add_return(1, &cp->in_pkts);
110316 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
110317
110318 if (ipvs->sync_state & IP_VS_STATE_MASTER)
110319 ip_vs_sync_conn(net, cp, pkts);
110320 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
110321 index 581a658..910e112 100644
110322 --- a/net/netfilter/ipvs/ip_vs_ctl.c
110323 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
110324 @@ -794,7 +794,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
110325 */
110326 ip_vs_rs_hash(ipvs, dest);
110327 }
110328 - atomic_set(&dest->conn_flags, conn_flags);
110329 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
110330
110331 /* bind the service */
110332 old_svc = rcu_dereference_protected(dest->svc, 1);
110333 @@ -1654,7 +1654,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
110334 * align with netns init in ip_vs_control_net_init()
110335 */
110336
110337 -static struct ctl_table vs_vars[] = {
110338 +static ctl_table_no_const vs_vars[] __read_only = {
110339 {
110340 .procname = "amemthresh",
110341 .maxlen = sizeof(int),
110342 @@ -2075,7 +2075,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
110343 " %-7s %-6d %-10d %-10d\n",
110344 &dest->addr.in6,
110345 ntohs(dest->port),
110346 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
110347 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
110348 atomic_read(&dest->weight),
110349 atomic_read(&dest->activeconns),
110350 atomic_read(&dest->inactconns));
110351 @@ -2086,7 +2086,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
110352 "%-7s %-6d %-10d %-10d\n",
110353 ntohl(dest->addr.ip),
110354 ntohs(dest->port),
110355 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
110356 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
110357 atomic_read(&dest->weight),
110358 atomic_read(&dest->activeconns),
110359 atomic_read(&dest->inactconns));
110360 @@ -2564,7 +2564,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
110361
110362 entry.addr = dest->addr.ip;
110363 entry.port = dest->port;
110364 - entry.conn_flags = atomic_read(&dest->conn_flags);
110365 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
110366 entry.weight = atomic_read(&dest->weight);
110367 entry.u_threshold = dest->u_threshold;
110368 entry.l_threshold = dest->l_threshold;
110369 @@ -3107,7 +3107,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
110370 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
110371 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
110372 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
110373 - (atomic_read(&dest->conn_flags) &
110374 + (atomic_read_unchecked(&dest->conn_flags) &
110375 IP_VS_CONN_F_FWD_MASK)) ||
110376 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
110377 atomic_read(&dest->weight)) ||
110378 @@ -3697,7 +3697,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
110379 {
110380 int idx;
110381 struct netns_ipvs *ipvs = net_ipvs(net);
110382 - struct ctl_table *tbl;
110383 + ctl_table_no_const *tbl;
110384
110385 atomic_set(&ipvs->dropentry, 0);
110386 spin_lock_init(&ipvs->dropentry_lock);
110387 diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
110388 index 547ff33..c8c8117 100644
110389 --- a/net/netfilter/ipvs/ip_vs_lblc.c
110390 +++ b/net/netfilter/ipvs/ip_vs_lblc.c
110391 @@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
110392 * IPVS LBLC sysctl table
110393 */
110394 #ifdef CONFIG_SYSCTL
110395 -static struct ctl_table vs_vars_table[] = {
110396 +static ctl_table_no_const vs_vars_table[] __read_only = {
110397 {
110398 .procname = "lblc_expiration",
110399 .data = NULL,
110400 diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
110401 index 3f21a2f..a112e85 100644
110402 --- a/net/netfilter/ipvs/ip_vs_lblcr.c
110403 +++ b/net/netfilter/ipvs/ip_vs_lblcr.c
110404 @@ -289,7 +289,7 @@ struct ip_vs_lblcr_table {
110405 * IPVS LBLCR sysctl table
110406 */
110407
110408 -static struct ctl_table vs_vars_table[] = {
110409 +static ctl_table_no_const vs_vars_table[] __read_only = {
110410 {
110411 .procname = "lblcr_expiration",
110412 .data = NULL,
110413 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
110414 index db80126..ef7110e 100644
110415 --- a/net/netfilter/ipvs/ip_vs_sync.c
110416 +++ b/net/netfilter/ipvs/ip_vs_sync.c
110417 @@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
110418 cp = cp->control;
110419 if (cp) {
110420 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
110421 - pkts = atomic_add_return(1, &cp->in_pkts);
110422 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
110423 else
110424 pkts = sysctl_sync_threshold(ipvs);
110425 ip_vs_sync_conn(net, cp->control, pkts);
110426 @@ -771,7 +771,7 @@ control:
110427 if (!cp)
110428 return;
110429 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
110430 - pkts = atomic_add_return(1, &cp->in_pkts);
110431 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
110432 else
110433 pkts = sysctl_sync_threshold(ipvs);
110434 goto sloop;
110435 @@ -895,7 +895,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
110436
110437 if (opt)
110438 memcpy(&cp->in_seq, opt, sizeof(*opt));
110439 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
110440 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
110441 cp->state = state;
110442 cp->old_state = cp->state;
110443 /*
110444 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
110445 index 73ba1cc..1adfc7a 100644
110446 --- a/net/netfilter/ipvs/ip_vs_xmit.c
110447 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
110448 @@ -1102,7 +1102,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
110449 else
110450 rc = NF_ACCEPT;
110451 /* do not touch skb anymore */
110452 - atomic_inc(&cp->in_pkts);
110453 + atomic_inc_unchecked(&cp->in_pkts);
110454 goto out;
110455 }
110456
110457 @@ -1194,7 +1194,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
110458 else
110459 rc = NF_ACCEPT;
110460 /* do not touch skb anymore */
110461 - atomic_inc(&cp->in_pkts);
110462 + atomic_inc_unchecked(&cp->in_pkts);
110463 goto out;
110464 }
110465
110466 diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
110467 index a4b5e2a..13b1de3 100644
110468 --- a/net/netfilter/nf_conntrack_acct.c
110469 +++ b/net/netfilter/nf_conntrack_acct.c
110470 @@ -62,7 +62,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
110471 #ifdef CONFIG_SYSCTL
110472 static int nf_conntrack_acct_init_sysctl(struct net *net)
110473 {
110474 - struct ctl_table *table;
110475 + ctl_table_no_const *table;
110476
110477 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
110478 GFP_KERNEL);
110479 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
110480 index 1f4f954..e364ad7 100644
110481 --- a/net/netfilter/nf_conntrack_core.c
110482 +++ b/net/netfilter/nf_conntrack_core.c
110483 @@ -1789,6 +1789,10 @@ void nf_conntrack_init_end(void)
110484 #define DYING_NULLS_VAL ((1<<30)+1)
110485 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
110486
110487 +#ifdef CONFIG_GRKERNSEC_HIDESYM
110488 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
110489 +#endif
110490 +
110491 int nf_conntrack_init_net(struct net *net)
110492 {
110493 int ret = -ENOMEM;
110494 @@ -1814,7 +1818,11 @@ int nf_conntrack_init_net(struct net *net)
110495 if (!net->ct.stat)
110496 goto err_pcpu_lists;
110497
110498 +#ifdef CONFIG_GRKERNSEC_HIDESYM
110499 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08x", atomic_inc_return_unchecked(&conntrack_cache_id));
110500 +#else
110501 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
110502 +#endif
110503 if (!net->ct.slabname)
110504 goto err_slabname;
110505
110506 diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
110507 index 1df1761..ce8b88a 100644
110508 --- a/net/netfilter/nf_conntrack_ecache.c
110509 +++ b/net/netfilter/nf_conntrack_ecache.c
110510 @@ -188,7 +188,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
110511 #ifdef CONFIG_SYSCTL
110512 static int nf_conntrack_event_init_sysctl(struct net *net)
110513 {
110514 - struct ctl_table *table;
110515 + ctl_table_no_const *table;
110516
110517 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
110518 GFP_KERNEL);
110519 diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
110520 index 5b3eae7..dd4b8fe 100644
110521 --- a/net/netfilter/nf_conntrack_helper.c
110522 +++ b/net/netfilter/nf_conntrack_helper.c
110523 @@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
110524
110525 static int nf_conntrack_helper_init_sysctl(struct net *net)
110526 {
110527 - struct ctl_table *table;
110528 + ctl_table_no_const *table;
110529
110530 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
110531 GFP_KERNEL);
110532 diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
110533 index b65d586..beec902 100644
110534 --- a/net/netfilter/nf_conntrack_proto.c
110535 +++ b/net/netfilter/nf_conntrack_proto.c
110536 @@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
110537
110538 static void
110539 nf_ct_unregister_sysctl(struct ctl_table_header **header,
110540 - struct ctl_table **table,
110541 + ctl_table_no_const **table,
110542 unsigned int users)
110543 {
110544 if (users > 0)
110545 diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
110546 index f641751..d3c5b51 100644
110547 --- a/net/netfilter/nf_conntrack_standalone.c
110548 +++ b/net/netfilter/nf_conntrack_standalone.c
110549 @@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
110550
110551 static int nf_conntrack_standalone_init_sysctl(struct net *net)
110552 {
110553 - struct ctl_table *table;
110554 + ctl_table_no_const *table;
110555
110556 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
110557 GFP_KERNEL);
110558 diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
110559 index 7a394df..bd91a8a 100644
110560 --- a/net/netfilter/nf_conntrack_timestamp.c
110561 +++ b/net/netfilter/nf_conntrack_timestamp.c
110562 @@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
110563 #ifdef CONFIG_SYSCTL
110564 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
110565 {
110566 - struct ctl_table *table;
110567 + ctl_table_no_const *table;
110568
110569 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
110570 GFP_KERNEL);
110571 diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
110572 index 85296d4..8becdec 100644
110573 --- a/net/netfilter/nf_log.c
110574 +++ b/net/netfilter/nf_log.c
110575 @@ -243,7 +243,7 @@ static const struct file_operations nflog_file_ops = {
110576
110577 #ifdef CONFIG_SYSCTL
110578 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
110579 -static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
110580 +static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
110581
110582 static int nf_log_proc_dostring(struct ctl_table *table, int write,
110583 void __user *buffer, size_t *lenp, loff_t *ppos)
110584 @@ -274,14 +274,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
110585 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
110586 mutex_unlock(&nf_log_mutex);
110587 } else {
110588 + ctl_table_no_const nf_log_table = *table;
110589 +
110590 mutex_lock(&nf_log_mutex);
110591 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
110592 lockdep_is_held(&nf_log_mutex));
110593 if (!logger)
110594 - table->data = "NONE";
110595 + nf_log_table.data = "NONE";
110596 else
110597 - table->data = logger->name;
110598 - r = proc_dostring(table, write, buffer, lenp, ppos);
110599 + nf_log_table.data = logger->name;
110600 + r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
110601 mutex_unlock(&nf_log_mutex);
110602 }
110603
110604 diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
110605 index f042ae5..30ea486 100644
110606 --- a/net/netfilter/nf_sockopt.c
110607 +++ b/net/netfilter/nf_sockopt.c
110608 @@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
110609 }
110610 }
110611
110612 - list_add(&reg->list, &nf_sockopts);
110613 + pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
110614 out:
110615 mutex_unlock(&nf_sockopt_mutex);
110616 return ret;
110617 @@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
110618 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
110619 {
110620 mutex_lock(&nf_sockopt_mutex);
110621 - list_del(&reg->list);
110622 + pax_list_del((struct list_head *)&reg->list);
110623 mutex_unlock(&nf_sockopt_mutex);
110624 }
110625 EXPORT_SYMBOL(nf_unregister_sockopt);
110626 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
110627 index d292c8d..9f1e166 100644
110628 --- a/net/netfilter/nfnetlink_log.c
110629 +++ b/net/netfilter/nfnetlink_log.c
110630 @@ -79,7 +79,7 @@ static int nfnl_log_net_id __read_mostly;
110631 struct nfnl_log_net {
110632 spinlock_t instances_lock;
110633 struct hlist_head instance_table[INSTANCE_BUCKETS];
110634 - atomic_t global_seq;
110635 + atomic_unchecked_t global_seq;
110636 };
110637
110638 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
110639 @@ -561,7 +561,7 @@ __build_packet_message(struct nfnl_log_net *log,
110640 /* global sequence number */
110641 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
110642 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
110643 - htonl(atomic_inc_return(&log->global_seq))))
110644 + htonl(atomic_inc_return_unchecked(&log->global_seq))))
110645 goto nla_put_failure;
110646
110647 if (data_len) {
110648 diff --git a/net/netfilter/nft_compat.c b/net/netfilter/nft_compat.c
110649 index 1840989..6895744 100644
110650 --- a/net/netfilter/nft_compat.c
110651 +++ b/net/netfilter/nft_compat.c
110652 @@ -225,7 +225,7 @@ target_dump_info(struct sk_buff *skb, const struct xt_target *t, const void *in)
110653 /* We want to reuse existing compat_to_user */
110654 old_fs = get_fs();
110655 set_fs(KERNEL_DS);
110656 - t->compat_to_user(out, in);
110657 + t->compat_to_user((void __force_user *)out, in);
110658 set_fs(old_fs);
110659 ret = nla_put(skb, NFTA_TARGET_INFO, XT_ALIGN(t->targetsize), out);
110660 kfree(out);
110661 @@ -421,7 +421,7 @@ match_dump_info(struct sk_buff *skb, const struct xt_match *m, const void *in)
110662 /* We want to reuse existing compat_to_user */
110663 old_fs = get_fs();
110664 set_fs(KERNEL_DS);
110665 - m->compat_to_user(out, in);
110666 + m->compat_to_user((void __force_user *)out, in);
110667 set_fs(old_fs);
110668 ret = nla_put(skb, NFTA_MATCH_INFO, XT_ALIGN(m->matchsize), out);
110669 kfree(out);
110670 diff --git a/net/netfilter/xt_bpf.c b/net/netfilter/xt_bpf.c
110671 index bbffdbda..12d4da8 100644
110672 --- a/net/netfilter/xt_bpf.c
110673 +++ b/net/netfilter/xt_bpf.c
110674 @@ -23,11 +23,10 @@ MODULE_ALIAS("ip6t_bpf");
110675 static int bpf_mt_check(const struct xt_mtchk_param *par)
110676 {
110677 struct xt_bpf_info *info = par->matchinfo;
110678 - struct sock_fprog_kern program;
110679 + struct sock_fprog program;
110680
110681 program.len = info->bpf_program_num_elem;
110682 - program.filter = info->bpf_program;
110683 -
110684 + program.filter = (struct sock_filter __user *) info->bpf_program;
110685 if (sk_unattached_filter_create(&info->filter, &program)) {
110686 pr_info("bpf: check failed: parse error\n");
110687 return -EINVAL;
110688 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
110689 new file mode 100644
110690 index 0000000..c566332
110691 --- /dev/null
110692 +++ b/net/netfilter/xt_gradm.c
110693 @@ -0,0 +1,51 @@
110694 +/*
110695 + * gradm match for netfilter
110696 + * Copyright © Zbigniew Krzystolik, 2010
110697 + *
110698 + * This program is free software; you can redistribute it and/or modify
110699 + * it under the terms of the GNU General Public License; either version
110700 + * 2 or 3 as published by the Free Software Foundation.
110701 + */
110702 +#include <linux/module.h>
110703 +#include <linux/moduleparam.h>
110704 +#include <linux/skbuff.h>
110705 +#include <linux/netfilter/x_tables.h>
110706 +#include <linux/grsecurity.h>
110707 +#include <linux/netfilter/xt_gradm.h>
110708 +
110709 +static bool
110710 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
110711 +{
110712 + const struct xt_gradm_mtinfo *info = par->matchinfo;
110713 + bool retval = false;
110714 + if (gr_acl_is_enabled())
110715 + retval = true;
110716 + return retval ^ info->invflags;
110717 +}
110718 +
110719 +static struct xt_match gradm_mt_reg __read_mostly = {
110720 + .name = "gradm",
110721 + .revision = 0,
110722 + .family = NFPROTO_UNSPEC,
110723 + .match = gradm_mt,
110724 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
110725 + .me = THIS_MODULE,
110726 +};
110727 +
110728 +static int __init gradm_mt_init(void)
110729 +{
110730 + return xt_register_match(&gradm_mt_reg);
110731 +}
110732 +
110733 +static void __exit gradm_mt_exit(void)
110734 +{
110735 + xt_unregister_match(&gradm_mt_reg);
110736 +}
110737 +
110738 +module_init(gradm_mt_init);
110739 +module_exit(gradm_mt_exit);
110740 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
110741 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
110742 +MODULE_LICENSE("GPL");
110743 +MODULE_ALIAS("ipt_gradm");
110744 +MODULE_ALIAS("ip6t_gradm");
110745 diff --git a/net/netfilter/xt_hashlimit.c b/net/netfilter/xt_hashlimit.c
110746 index a3910fc..2d2ba14 100644
110747 --- a/net/netfilter/xt_hashlimit.c
110748 +++ b/net/netfilter/xt_hashlimit.c
110749 @@ -870,11 +870,11 @@ static int __net_init hashlimit_proc_net_init(struct net *net)
110750 {
110751 struct hashlimit_net *hashlimit_net = hashlimit_pernet(net);
110752
110753 - hashlimit_net->ipt_hashlimit = proc_mkdir("ipt_hashlimit", net->proc_net);
110754 + hashlimit_net->ipt_hashlimit = proc_mkdir_restrict("ipt_hashlimit", net->proc_net);
110755 if (!hashlimit_net->ipt_hashlimit)
110756 return -ENOMEM;
110757 #if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
110758 - hashlimit_net->ip6t_hashlimit = proc_mkdir("ip6t_hashlimit", net->proc_net);
110759 + hashlimit_net->ip6t_hashlimit = proc_mkdir_restrict("ip6t_hashlimit", net->proc_net);
110760 if (!hashlimit_net->ip6t_hashlimit) {
110761 remove_proc_entry("ipt_hashlimit", net->proc_net);
110762 return -ENOMEM;
110763 diff --git a/net/netfilter/xt_recent.c b/net/netfilter/xt_recent.c
110764 index a9faae8..1ea30e0 100644
110765 --- a/net/netfilter/xt_recent.c
110766 +++ b/net/netfilter/xt_recent.c
110767 @@ -615,7 +615,7 @@ static int __net_init recent_proc_net_init(struct net *net)
110768 {
110769 struct recent_net *recent_net = recent_pernet(net);
110770
110771 - recent_net->xt_recent = proc_mkdir("xt_recent", net->proc_net);
110772 + recent_net->xt_recent = proc_mkdir_restrict("xt_recent", net->proc_net);
110773 if (!recent_net->xt_recent)
110774 return -ENOMEM;
110775 return 0;
110776 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
110777 index 11de55e..f25e448 100644
110778 --- a/net/netfilter/xt_statistic.c
110779 +++ b/net/netfilter/xt_statistic.c
110780 @@ -19,7 +19,7 @@
110781 #include <linux/module.h>
110782
110783 struct xt_statistic_priv {
110784 - atomic_t count;
110785 + atomic_unchecked_t count;
110786 } ____cacheline_aligned_in_smp;
110787
110788 MODULE_LICENSE("GPL");
110789 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
110790 break;
110791 case XT_STATISTIC_MODE_NTH:
110792 do {
110793 - oval = atomic_read(&info->master->count);
110794 + oval = atomic_read_unchecked(&info->master->count);
110795 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
110796 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
110797 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
110798 if (nval == 0)
110799 ret = !ret;
110800 break;
110801 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
110802 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
110803 if (info->master == NULL)
110804 return -ENOMEM;
110805 - atomic_set(&info->master->count, info->u.nth.count);
110806 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
110807
110808 return 0;
110809 }
110810 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
110811 index e6fac7e..cdcd25e 100644
110812 --- a/net/netlink/af_netlink.c
110813 +++ b/net/netlink/af_netlink.c
110814 @@ -257,7 +257,7 @@ static void netlink_overrun(struct sock *sk)
110815 sk->sk_error_report(sk);
110816 }
110817 }
110818 - atomic_inc(&sk->sk_drops);
110819 + atomic_inc_unchecked(&sk->sk_drops);
110820 }
110821
110822 static void netlink_rcv_wake(struct sock *sk)
110823 @@ -3058,7 +3058,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
110824 sk_wmem_alloc_get(s),
110825 nlk->cb_running,
110826 atomic_read(&s->sk_refcnt),
110827 - atomic_read(&s->sk_drops),
110828 + atomic_read_unchecked(&s->sk_drops),
110829 sock_i_ino(s)
110830 );
110831
110832 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
110833 index b85c67c..09705b7 100644
110834 --- a/net/packet/af_packet.c
110835 +++ b/net/packet/af_packet.c
110836 @@ -275,7 +275,7 @@ static int packet_direct_xmit(struct sk_buff *skb)
110837
110838 return ret;
110839 drop:
110840 - atomic_long_inc(&dev->tx_dropped);
110841 + atomic_long_inc_unchecked(&dev->tx_dropped);
110842 kfree_skb(skb);
110843 return NET_XMIT_DROP;
110844 }
110845 @@ -636,6 +636,7 @@ static void init_prb_bdqc(struct packet_sock *po,
110846 p1->tov_in_jiffies = msecs_to_jiffies(p1->retire_blk_tov);
110847 p1->blk_sizeof_priv = req_u->req3.tp_sizeof_priv;
110848
110849 + p1->max_frame_len = p1->kblk_size - BLK_PLUS_PRIV(p1->blk_sizeof_priv);
110850 prb_init_ft_ops(p1, req_u);
110851 prb_setup_retire_blk_timer(po, tx_ring);
110852 prb_open_block(p1, pbd);
110853 @@ -1845,7 +1846,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
110854
110855 spin_lock(&sk->sk_receive_queue.lock);
110856 po->stats.stats1.tp_packets++;
110857 - skb->dropcount = atomic_read(&sk->sk_drops);
110858 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
110859 __skb_queue_tail(&sk->sk_receive_queue, skb);
110860 spin_unlock(&sk->sk_receive_queue.lock);
110861 sk->sk_data_ready(sk);
110862 @@ -1854,7 +1855,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
110863 drop_n_acct:
110864 spin_lock(&sk->sk_receive_queue.lock);
110865 po->stats.stats1.tp_drops++;
110866 - atomic_inc(&sk->sk_drops);
110867 + atomic_inc_unchecked(&sk->sk_drops);
110868 spin_unlock(&sk->sk_receive_queue.lock);
110869
110870 drop_n_restore:
110871 @@ -1946,6 +1947,18 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev,
110872 if ((int)snaplen < 0)
110873 snaplen = 0;
110874 }
110875 + } else if (unlikely(macoff + snaplen >
110876 + GET_PBDQC_FROM_RB(&po->rx_ring)->max_frame_len)) {
110877 + u32 nval;
110878 +
110879 + nval = GET_PBDQC_FROM_RB(&po->rx_ring)->max_frame_len - macoff;
110880 + pr_err_once("tpacket_rcv: packet too big, clamped from %u to %u. macoff=%u\n",
110881 + snaplen, nval, macoff);
110882 + snaplen = nval;
110883 + if (unlikely((int)snaplen < 0)) {
110884 + snaplen = 0;
110885 + macoff = GET_PBDQC_FROM_RB(&po->rx_ring)->max_frame_len;
110886 + }
110887 }
110888 spin_lock(&sk->sk_receive_queue.lock);
110889 h.raw = packet_current_rx_frame(po, skb,
110890 @@ -3459,7 +3472,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
110891 case PACKET_HDRLEN:
110892 if (len > sizeof(int))
110893 len = sizeof(int);
110894 - if (copy_from_user(&val, optval, len))
110895 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
110896 return -EFAULT;
110897 switch (val) {
110898 case TPACKET_V1:
110899 @@ -3505,7 +3518,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
110900 len = lv;
110901 if (put_user(len, optlen))
110902 return -EFAULT;
110903 - if (copy_to_user(optval, data, len))
110904 + if (len > sizeof(st) || copy_to_user(optval, data, len))
110905 return -EFAULT;
110906 return 0;
110907 }
110908 @@ -3789,6 +3802,10 @@ static int packet_set_ring(struct sock *sk, union tpacket_req_u *req_u,
110909 goto out;
110910 if (unlikely(req->tp_block_size & (PAGE_SIZE - 1)))
110911 goto out;
110912 + if (po->tp_version >= TPACKET_V3 &&
110913 + (int)(req->tp_block_size -
110914 + BLK_PLUS_PRIV(req_u->req3.tp_sizeof_priv)) <= 0)
110915 + goto out;
110916 if (unlikely(req->tp_frame_size < po->tp_hdrlen +
110917 po->tp_reserve))
110918 goto out;
110919 diff --git a/net/packet/internal.h b/net/packet/internal.h
110920 index eb9580a..cdddf6a 100644
110921 --- a/net/packet/internal.h
110922 +++ b/net/packet/internal.h
110923 @@ -29,6 +29,7 @@ struct tpacket_kbdq_core {
110924 char *pkblk_start;
110925 char *pkblk_end;
110926 int kblk_size;
110927 + unsigned int max_frame_len;
110928 unsigned int knum_blocks;
110929 uint64_t knxt_seq_num;
110930 char *prev;
110931 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
110932 index 70a547e..23477fe 100644
110933 --- a/net/phonet/pep.c
110934 +++ b/net/phonet/pep.c
110935 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
110936
110937 case PNS_PEP_CTRL_REQ:
110938 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
110939 - atomic_inc(&sk->sk_drops);
110940 + atomic_inc_unchecked(&sk->sk_drops);
110941 break;
110942 }
110943 __skb_pull(skb, 4);
110944 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
110945 }
110946
110947 if (pn->rx_credits == 0) {
110948 - atomic_inc(&sk->sk_drops);
110949 + atomic_inc_unchecked(&sk->sk_drops);
110950 err = -ENOBUFS;
110951 break;
110952 }
110953 @@ -579,7 +579,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
110954 }
110955
110956 if (pn->rx_credits == 0) {
110957 - atomic_inc(&sk->sk_drops);
110958 + atomic_inc_unchecked(&sk->sk_drops);
110959 err = NET_RX_DROP;
110960 break;
110961 }
110962 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
110963 index 008214a..bb68240 100644
110964 --- a/net/phonet/socket.c
110965 +++ b/net/phonet/socket.c
110966 @@ -611,7 +611,7 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
110967 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sk)),
110968 sock_i_ino(sk),
110969 atomic_read(&sk->sk_refcnt), sk,
110970 - atomic_read(&sk->sk_drops));
110971 + atomic_read_unchecked(&sk->sk_drops));
110972 }
110973 seq_pad(seq, '\n');
110974 return 0;
110975 diff --git a/net/phonet/sysctl.c b/net/phonet/sysctl.c
110976 index c02a8c4..3c5b600 100644
110977 --- a/net/phonet/sysctl.c
110978 +++ b/net/phonet/sysctl.c
110979 @@ -67,7 +67,7 @@ static int proc_local_port_range(struct ctl_table *table, int write,
110980 {
110981 int ret;
110982 int range[2] = {local_port_range[0], local_port_range[1]};
110983 - struct ctl_table tmp = {
110984 + ctl_table_no_const tmp = {
110985 .data = &range,
110986 .maxlen = sizeof(range),
110987 .mode = table->mode,
110988 diff --git a/net/rds/cong.c b/net/rds/cong.c
110989 index e5b65ac..f3b6fb7 100644
110990 --- a/net/rds/cong.c
110991 +++ b/net/rds/cong.c
110992 @@ -78,7 +78,7 @@
110993 * finds that the saved generation number is smaller than the global generation
110994 * number, it wakes up the process.
110995 */
110996 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
110997 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
110998
110999 /*
111000 * Congestion monitoring
111001 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
111002 rdsdebug("waking map %p for %pI4\n",
111003 map, &map->m_addr);
111004 rds_stats_inc(s_cong_update_received);
111005 - atomic_inc(&rds_cong_generation);
111006 + atomic_inc_unchecked(&rds_cong_generation);
111007 if (waitqueue_active(&map->m_waitq))
111008 wake_up(&map->m_waitq);
111009 if (waitqueue_active(&rds_poll_waitq))
111010 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
111011
111012 int rds_cong_updated_since(unsigned long *recent)
111013 {
111014 - unsigned long gen = atomic_read(&rds_cong_generation);
111015 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
111016
111017 if (likely(*recent == gen))
111018 return 0;
111019 diff --git a/net/rds/ib.h b/net/rds/ib.h
111020 index 7280ab8..e04f4ea 100644
111021 --- a/net/rds/ib.h
111022 +++ b/net/rds/ib.h
111023 @@ -128,7 +128,7 @@ struct rds_ib_connection {
111024 /* sending acks */
111025 unsigned long i_ack_flags;
111026 #ifdef KERNEL_HAS_ATOMIC64
111027 - atomic64_t i_ack_next; /* next ACK to send */
111028 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
111029 #else
111030 spinlock_t i_ack_lock; /* protect i_ack_next */
111031 u64 i_ack_next; /* next ACK to send */
111032 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
111033 index 31b74f5..dc1fbfa 100644
111034 --- a/net/rds/ib_cm.c
111035 +++ b/net/rds/ib_cm.c
111036 @@ -717,7 +717,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
111037 /* Clear the ACK state */
111038 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
111039 #ifdef KERNEL_HAS_ATOMIC64
111040 - atomic64_set(&ic->i_ack_next, 0);
111041 + atomic64_set_unchecked(&ic->i_ack_next, 0);
111042 #else
111043 ic->i_ack_next = 0;
111044 #endif
111045 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
111046 index d67de45..73dbf51 100644
111047 --- a/net/rds/ib_recv.c
111048 +++ b/net/rds/ib_recv.c
111049 @@ -596,7 +596,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
111050 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
111051 int ack_required)
111052 {
111053 - atomic64_set(&ic->i_ack_next, seq);
111054 + atomic64_set_unchecked(&ic->i_ack_next, seq);
111055 if (ack_required) {
111056 smp_mb__before_atomic();
111057 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
111058 @@ -608,7 +608,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
111059 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
111060 smp_mb__after_atomic();
111061
111062 - return atomic64_read(&ic->i_ack_next);
111063 + return atomic64_read_unchecked(&ic->i_ack_next);
111064 }
111065 #endif
111066
111067 diff --git a/net/rds/iw.h b/net/rds/iw.h
111068 index 04ce3b1..48119a6 100644
111069 --- a/net/rds/iw.h
111070 +++ b/net/rds/iw.h
111071 @@ -134,7 +134,7 @@ struct rds_iw_connection {
111072 /* sending acks */
111073 unsigned long i_ack_flags;
111074 #ifdef KERNEL_HAS_ATOMIC64
111075 - atomic64_t i_ack_next; /* next ACK to send */
111076 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
111077 #else
111078 spinlock_t i_ack_lock; /* protect i_ack_next */
111079 u64 i_ack_next; /* next ACK to send */
111080 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
111081 index a91e1db..cf3053f 100644
111082 --- a/net/rds/iw_cm.c
111083 +++ b/net/rds/iw_cm.c
111084 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
111085 /* Clear the ACK state */
111086 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
111087 #ifdef KERNEL_HAS_ATOMIC64
111088 - atomic64_set(&ic->i_ack_next, 0);
111089 + atomic64_set_unchecked(&ic->i_ack_next, 0);
111090 #else
111091 ic->i_ack_next = 0;
111092 #endif
111093 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
111094 index aa8bf67..b70133c 100644
111095 --- a/net/rds/iw_recv.c
111096 +++ b/net/rds/iw_recv.c
111097 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
111098 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
111099 int ack_required)
111100 {
111101 - atomic64_set(&ic->i_ack_next, seq);
111102 + atomic64_set_unchecked(&ic->i_ack_next, seq);
111103 if (ack_required) {
111104 smp_mb__before_atomic();
111105 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
111106 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
111107 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
111108 smp_mb__after_atomic();
111109
111110 - return atomic64_read(&ic->i_ack_next);
111111 + return atomic64_read_unchecked(&ic->i_ack_next);
111112 }
111113 #endif
111114
111115 diff --git a/net/rds/rds.h b/net/rds/rds.h
111116 index 48f8ffc..0ef3eec 100644
111117 --- a/net/rds/rds.h
111118 +++ b/net/rds/rds.h
111119 @@ -449,7 +449,7 @@ struct rds_transport {
111120 void (*sync_mr)(void *trans_private, int direction);
111121 void (*free_mr)(void *trans_private, int invalidate);
111122 void (*flush_mrs)(void);
111123 -};
111124 +} __do_const;
111125
111126 struct rds_sock {
111127 struct sock rs_sk;
111128 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
111129 index edac9ef..16bcb98 100644
111130 --- a/net/rds/tcp.c
111131 +++ b/net/rds/tcp.c
111132 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
111133 int val = 1;
111134
111135 set_fs(KERNEL_DS);
111136 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
111137 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
111138 sizeof(val));
111139 set_fs(oldfs);
111140 }
111141 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
111142 index 53b17ca..45463e7 100644
111143 --- a/net/rds/tcp_send.c
111144 +++ b/net/rds/tcp_send.c
111145 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
111146
111147 oldfs = get_fs();
111148 set_fs(KERNEL_DS);
111149 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
111150 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
111151 sizeof(val));
111152 set_fs(oldfs);
111153 }
111154 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
111155 index 7b16704..9628ec6 100644
111156 --- a/net/rxrpc/af_rxrpc.c
111157 +++ b/net/rxrpc/af_rxrpc.c
111158 @@ -40,7 +40,7 @@ static const struct proto_ops rxrpc_rpc_ops;
111159 __be32 rxrpc_epoch;
111160
111161 /* current debugging ID */
111162 -atomic_t rxrpc_debug_id;
111163 +atomic_unchecked_t rxrpc_debug_id;
111164
111165 /* count of skbs currently in use */
111166 atomic_t rxrpc_n_skbs;
111167 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
111168 index c6be17a..2a6200a 100644
111169 --- a/net/rxrpc/ar-ack.c
111170 +++ b/net/rxrpc/ar-ack.c
111171 @@ -223,7 +223,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
111172
111173 _enter("{%d,%d,%d,%d},",
111174 call->acks_hard, call->acks_unacked,
111175 - atomic_read(&call->sequence),
111176 + atomic_read_unchecked(&call->sequence),
111177 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
111178
111179 stop = 0;
111180 @@ -247,7 +247,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
111181
111182 /* each Tx packet has a new serial number */
111183 sp->hdr.serial =
111184 - htonl(atomic_inc_return(&call->conn->serial));
111185 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
111186
111187 hdr = (struct rxrpc_header *) txb->head;
111188 hdr->serial = sp->hdr.serial;
111189 @@ -451,7 +451,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
111190 */
111191 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
111192 {
111193 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
111194 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
111195 }
111196
111197 /*
111198 @@ -677,7 +677,7 @@ process_further:
111199
111200 latest = ntohl(sp->hdr.serial);
111201 hard = ntohl(ack.firstPacket);
111202 - tx = atomic_read(&call->sequence);
111203 + tx = atomic_read_unchecked(&call->sequence);
111204
111205 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
111206 latest,
111207 @@ -1209,7 +1209,7 @@ void rxrpc_process_call(struct work_struct *work)
111208 goto maybe_reschedule;
111209
111210 send_ACK_with_skew:
111211 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
111212 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
111213 ntohl(ack.serial));
111214 send_ACK:
111215 mtu = call->conn->trans->peer->if_mtu;
111216 @@ -1221,7 +1221,7 @@ send_ACK:
111217 ackinfo.rxMTU = htonl(rxrpc_rx_mtu);
111218 ackinfo.jumbo_max = htonl(rxrpc_rx_jumbo_max);
111219
111220 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
111221 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
111222 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
111223 ntohl(hdr.serial),
111224 ntohs(ack.maxSkew),
111225 @@ -1239,7 +1239,7 @@ send_ACK:
111226 send_message:
111227 _debug("send message");
111228
111229 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
111230 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
111231 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
111232 send_message_2:
111233
111234 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
111235 index a9e05db..194e793 100644
111236 --- a/net/rxrpc/ar-call.c
111237 +++ b/net/rxrpc/ar-call.c
111238 @@ -232,7 +232,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
111239 spin_lock_init(&call->lock);
111240 rwlock_init(&call->state_lock);
111241 atomic_set(&call->usage, 1);
111242 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
111243 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
111244 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
111245
111246 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
111247 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
111248 index 6631f4f..bfdf056 100644
111249 --- a/net/rxrpc/ar-connection.c
111250 +++ b/net/rxrpc/ar-connection.c
111251 @@ -210,7 +210,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
111252 rwlock_init(&conn->lock);
111253 spin_lock_init(&conn->state_lock);
111254 atomic_set(&conn->usage, 1);
111255 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
111256 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
111257 conn->avail_calls = RXRPC_MAXCALLS;
111258 conn->size_align = 4;
111259 conn->header_size = sizeof(struct rxrpc_header);
111260 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
111261 index e7ed43a..6afa140 100644
111262 --- a/net/rxrpc/ar-connevent.c
111263 +++ b/net/rxrpc/ar-connevent.c
111264 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
111265
111266 len = iov[0].iov_len + iov[1].iov_len;
111267
111268 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
111269 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
111270 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
111271
111272 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
111273 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
111274 index 63b21e5..330232e 100644
111275 --- a/net/rxrpc/ar-input.c
111276 +++ b/net/rxrpc/ar-input.c
111277 @@ -338,9 +338,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
111278 /* track the latest serial number on this connection for ACK packet
111279 * information */
111280 serial = ntohl(sp->hdr.serial);
111281 - hi_serial = atomic_read(&call->conn->hi_serial);
111282 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
111283 while (serial > hi_serial)
111284 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
111285 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
111286 serial);
111287
111288 /* request ACK generation for any ACK or DATA packet that requests
111289 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
111290 index ba9fd36..9bbfe01 100644
111291 --- a/net/rxrpc/ar-internal.h
111292 +++ b/net/rxrpc/ar-internal.h
111293 @@ -272,8 +272,8 @@ struct rxrpc_connection {
111294 int error; /* error code for local abort */
111295 int debug_id; /* debug ID for printks */
111296 unsigned int call_counter; /* call ID counter */
111297 - atomic_t serial; /* packet serial number counter */
111298 - atomic_t hi_serial; /* highest serial number received */
111299 + atomic_unchecked_t serial; /* packet serial number counter */
111300 + atomic_unchecked_t hi_serial; /* highest serial number received */
111301 u8 avail_calls; /* number of calls available */
111302 u8 size_align; /* data size alignment (for security) */
111303 u8 header_size; /* rxrpc + security header size */
111304 @@ -346,7 +346,7 @@ struct rxrpc_call {
111305 spinlock_t lock;
111306 rwlock_t state_lock; /* lock for state transition */
111307 atomic_t usage;
111308 - atomic_t sequence; /* Tx data packet sequence counter */
111309 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
111310 u32 abort_code; /* local/remote abort code */
111311 enum { /* current state of call */
111312 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
111313 @@ -431,7 +431,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
111314 */
111315 extern atomic_t rxrpc_n_skbs;
111316 extern __be32 rxrpc_epoch;
111317 -extern atomic_t rxrpc_debug_id;
111318 +extern atomic_unchecked_t rxrpc_debug_id;
111319 extern struct workqueue_struct *rxrpc_workqueue;
111320
111321 /*
111322 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
111323 index 87f7135..74d3703 100644
111324 --- a/net/rxrpc/ar-local.c
111325 +++ b/net/rxrpc/ar-local.c
111326 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
111327 spin_lock_init(&local->lock);
111328 rwlock_init(&local->services_lock);
111329 atomic_set(&local->usage, 1);
111330 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
111331 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
111332 memcpy(&local->srx, srx, sizeof(*srx));
111333 }
111334
111335 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
111336 index 0b4b9a7..966ffbb 100644
111337 --- a/net/rxrpc/ar-output.c
111338 +++ b/net/rxrpc/ar-output.c
111339 @@ -682,14 +682,14 @@ static int rxrpc_send_data(struct kiocb *iocb,
111340 memset(skb_put(skb, pad), 0, pad);
111341 }
111342
111343 - seq = atomic_inc_return(&call->sequence);
111344 + seq = atomic_inc_return_unchecked(&call->sequence);
111345
111346 sp->hdr.epoch = conn->epoch;
111347 sp->hdr.cid = call->cid;
111348 sp->hdr.callNumber = call->call_id;
111349 sp->hdr.seq = htonl(seq);
111350 sp->hdr.serial =
111351 - htonl(atomic_inc_return(&conn->serial));
111352 + htonl(atomic_inc_return_unchecked(&conn->serial));
111353 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
111354 sp->hdr.userStatus = 0;
111355 sp->hdr.securityIndex = conn->security_ix;
111356 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
111357 index bebaa43..2644591 100644
111358 --- a/net/rxrpc/ar-peer.c
111359 +++ b/net/rxrpc/ar-peer.c
111360 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
111361 INIT_LIST_HEAD(&peer->error_targets);
111362 spin_lock_init(&peer->lock);
111363 atomic_set(&peer->usage, 1);
111364 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
111365 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
111366 memcpy(&peer->srx, srx, sizeof(*srx));
111367
111368 rxrpc_assess_MTU_size(peer);
111369 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
111370 index 38047f7..9f48511 100644
111371 --- a/net/rxrpc/ar-proc.c
111372 +++ b/net/rxrpc/ar-proc.c
111373 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
111374 atomic_read(&conn->usage),
111375 rxrpc_conn_states[conn->state],
111376 key_serial(conn->key),
111377 - atomic_read(&conn->serial),
111378 - atomic_read(&conn->hi_serial));
111379 + atomic_read_unchecked(&conn->serial),
111380 + atomic_read_unchecked(&conn->hi_serial));
111381
111382 return 0;
111383 }
111384 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
111385 index 1976dec..aa70be5 100644
111386 --- a/net/rxrpc/ar-transport.c
111387 +++ b/net/rxrpc/ar-transport.c
111388 @@ -51,7 +51,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
111389 spin_lock_init(&trans->client_lock);
111390 rwlock_init(&trans->conn_lock);
111391 atomic_set(&trans->usage, 1);
111392 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
111393 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
111394
111395 if (peer->srx.transport.family == AF_INET) {
111396 switch (peer->srx.transport_type) {
111397 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
111398 index f226709..0e735a8 100644
111399 --- a/net/rxrpc/rxkad.c
111400 +++ b/net/rxrpc/rxkad.c
111401 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
111402
111403 len = iov[0].iov_len + iov[1].iov_len;
111404
111405 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
111406 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
111407 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
111408
111409 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
111410 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
111411
111412 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
111413
111414 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
111415 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
111416 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
111417
111418 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
111419 diff --git a/net/sched/cls_bpf.c b/net/sched/cls_bpf.c
111420 index 13f64df..1618696 100644
111421 --- a/net/sched/cls_bpf.c
111422 +++ b/net/sched/cls_bpf.c
111423 @@ -160,7 +160,7 @@ static int cls_bpf_modify_existing(struct net *net, struct tcf_proto *tp,
111424 {
111425 struct sock_filter *bpf_ops, *bpf_old;
111426 struct tcf_exts exts;
111427 - struct sock_fprog_kern tmp;
111428 + struct sock_fprog tmp;
111429 struct sk_filter *fp, *fp_old;
111430 u16 bpf_size, bpf_len;
111431 u32 classid;
111432 @@ -191,7 +191,7 @@ static int cls_bpf_modify_existing(struct net *net, struct tcf_proto *tp,
111433 memcpy(bpf_ops, nla_data(tb[TCA_BPF_OPS]), bpf_size);
111434
111435 tmp.len = bpf_len;
111436 - tmp.filter = bpf_ops;
111437 + tmp.filter = (struct sock_filter __user *) bpf_ops;
111438
111439 ret = sk_unattached_filter_create(&fp, &tmp);
111440 if (ret)
111441 diff --git a/net/sched/sch_generic.c b/net/sched/sch_generic.c
111442 index e1543b0..7ce8bd0 100644
111443 --- a/net/sched/sch_generic.c
111444 +++ b/net/sched/sch_generic.c
111445 @@ -310,7 +310,7 @@ void netif_carrier_on(struct net_device *dev)
111446 if (test_and_clear_bit(__LINK_STATE_NOCARRIER, &dev->state)) {
111447 if (dev->reg_state == NETREG_UNINITIALIZED)
111448 return;
111449 - atomic_inc(&dev->carrier_changes);
111450 + atomic_inc_unchecked(&dev->carrier_changes);
111451 linkwatch_fire_event(dev);
111452 if (netif_running(dev))
111453 __netdev_watchdog_up(dev);
111454 @@ -329,7 +329,7 @@ void netif_carrier_off(struct net_device *dev)
111455 if (!test_and_set_bit(__LINK_STATE_NOCARRIER, &dev->state)) {
111456 if (dev->reg_state == NETREG_UNINITIALIZED)
111457 return;
111458 - atomic_inc(&dev->carrier_changes);
111459 + atomic_inc_unchecked(&dev->carrier_changes);
111460 linkwatch_fire_event(dev);
111461 }
111462 }
111463 diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
111464 index 1999592..6684af6 100644
111465 --- a/net/sctp/ipv6.c
111466 +++ b/net/sctp/ipv6.c
111467 @@ -964,7 +964,7 @@ static const struct inet6_protocol sctpv6_protocol = {
111468 .flags = INET6_PROTO_NOPOLICY | INET6_PROTO_FINAL,
111469 };
111470
111471 -static struct sctp_af sctp_af_inet6 = {
111472 +static struct sctp_af sctp_af_inet6 __read_only = {
111473 .sa_family = AF_INET6,
111474 .sctp_xmit = sctp_v6_xmit,
111475 .setsockopt = ipv6_setsockopt,
111476 @@ -996,7 +996,7 @@ static struct sctp_af sctp_af_inet6 = {
111477 #endif
111478 };
111479
111480 -static struct sctp_pf sctp_pf_inet6 = {
111481 +static struct sctp_pf sctp_pf_inet6 __read_only = {
111482 .event_msgname = sctp_inet6_event_msgname,
111483 .skb_msgname = sctp_inet6_skb_msgname,
111484 .af_supported = sctp_inet6_af_supported,
111485 @@ -1021,7 +1021,7 @@ void sctp_v6_pf_init(void)
111486
111487 void sctp_v6_pf_exit(void)
111488 {
111489 - list_del(&sctp_af_inet6.list);
111490 + pax_list_del(&sctp_af_inet6.list);
111491 }
111492
111493 /* Initialize IPv6 support and register with socket layer. */
111494 diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
111495 index 6789d785..0798d76 100644
111496 --- a/net/sctp/protocol.c
111497 +++ b/net/sctp/protocol.c
111498 @@ -836,8 +836,10 @@ int sctp_register_af(struct sctp_af *af)
111499 return 0;
111500 }
111501
111502 + pax_open_kernel();
111503 INIT_LIST_HEAD(&af->list);
111504 - list_add_tail(&af->list, &sctp_address_families);
111505 + pax_close_kernel();
111506 + pax_list_add_tail(&af->list, &sctp_address_families);
111507 return 1;
111508 }
111509
111510 @@ -967,7 +969,7 @@ static inline int sctp_v4_xmit(struct sk_buff *skb,
111511
111512 static struct sctp_af sctp_af_inet;
111513
111514 -static struct sctp_pf sctp_pf_inet = {
111515 +static struct sctp_pf sctp_pf_inet __read_only = {
111516 .event_msgname = sctp_inet_event_msgname,
111517 .skb_msgname = sctp_inet_skb_msgname,
111518 .af_supported = sctp_inet_af_supported,
111519 @@ -1037,7 +1039,7 @@ static const struct net_protocol sctp_protocol = {
111520 };
111521
111522 /* IPv4 address related functions. */
111523 -static struct sctp_af sctp_af_inet = {
111524 +static struct sctp_af sctp_af_inet __read_only = {
111525 .sa_family = AF_INET,
111526 .sctp_xmit = sctp_v4_xmit,
111527 .setsockopt = ip_setsockopt,
111528 @@ -1123,7 +1125,7 @@ static void sctp_v4_pf_init(void)
111529
111530 static void sctp_v4_pf_exit(void)
111531 {
111532 - list_del(&sctp_af_inet.list);
111533 + pax_list_del(&sctp_af_inet.list);
111534 }
111535
111536 static int sctp_v4_protosw_init(void)
111537 diff --git a/net/sctp/sm_sideeffect.c b/net/sctp/sm_sideeffect.c
111538 index fef2acd..c705c4f 100644
111539 --- a/net/sctp/sm_sideeffect.c
111540 +++ b/net/sctp/sm_sideeffect.c
111541 @@ -439,7 +439,7 @@ static void sctp_generate_sack_event(unsigned long data)
111542 sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_SACK);
111543 }
111544
111545 -sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
111546 +sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
111547 NULL,
111548 sctp_generate_t1_cookie_event,
111549 sctp_generate_t1_init_event,
111550 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
111551 index 4298996..fa5f636 100644
111552 --- a/net/sctp/socket.c
111553 +++ b/net/sctp/socket.c
111554 @@ -2176,11 +2176,13 @@ static int sctp_setsockopt_events(struct sock *sk, char __user *optval,
111555 {
111556 struct sctp_association *asoc;
111557 struct sctp_ulpevent *event;
111558 + struct sctp_event_subscribe subscribe;
111559
111560 if (optlen > sizeof(struct sctp_event_subscribe))
111561 return -EINVAL;
111562 - if (copy_from_user(&sctp_sk(sk)->subscribe, optval, optlen))
111563 + if (copy_from_user(&subscribe, optval, optlen))
111564 return -EFAULT;
111565 + sctp_sk(sk)->subscribe = subscribe;
111566
111567 /*
111568 * At the time when a user app subscribes to SCTP_SENDER_DRY_EVENT,
111569 @@ -4260,13 +4262,16 @@ static int sctp_getsockopt_disable_fragments(struct sock *sk, int len,
111570 static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
111571 int __user *optlen)
111572 {
111573 + struct sctp_event_subscribe subscribe;
111574 +
111575 if (len <= 0)
111576 return -EINVAL;
111577 if (len > sizeof(struct sctp_event_subscribe))
111578 len = sizeof(struct sctp_event_subscribe);
111579 if (put_user(len, optlen))
111580 return -EFAULT;
111581 - if (copy_to_user(optval, &sctp_sk(sk)->subscribe, len))
111582 + subscribe = sctp_sk(sk)->subscribe;
111583 + if (copy_to_user(optval, &subscribe, len))
111584 return -EFAULT;
111585 return 0;
111586 }
111587 @@ -4284,6 +4289,8 @@ static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
111588 */
111589 static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optval, int __user *optlen)
111590 {
111591 + __u32 autoclose;
111592 +
111593 /* Applicable to UDP-style socket only */
111594 if (sctp_style(sk, TCP))
111595 return -EOPNOTSUPP;
111596 @@ -4292,7 +4299,8 @@ static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optv
111597 len = sizeof(int);
111598 if (put_user(len, optlen))
111599 return -EFAULT;
111600 - if (copy_to_user(optval, &sctp_sk(sk)->autoclose, sizeof(int)))
111601 + autoclose = sctp_sk(sk)->autoclose;
111602 + if (copy_to_user(optval, &autoclose, sizeof(int)))
111603 return -EFAULT;
111604 return 0;
111605 }
111606 @@ -4667,12 +4675,15 @@ static int sctp_getsockopt_delayed_ack(struct sock *sk, int len,
111607 */
111608 static int sctp_getsockopt_initmsg(struct sock *sk, int len, char __user *optval, int __user *optlen)
111609 {
111610 + struct sctp_initmsg initmsg;
111611 +
111612 if (len < sizeof(struct sctp_initmsg))
111613 return -EINVAL;
111614 len = sizeof(struct sctp_initmsg);
111615 if (put_user(len, optlen))
111616 return -EFAULT;
111617 - if (copy_to_user(optval, &sctp_sk(sk)->initmsg, len))
111618 + initmsg = sctp_sk(sk)->initmsg;
111619 + if (copy_to_user(optval, &initmsg, len))
111620 return -EFAULT;
111621 return 0;
111622 }
111623 @@ -4713,6 +4724,8 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
111624 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
111625 if (space_left < addrlen)
111626 return -ENOMEM;
111627 + if (addrlen > sizeof(temp) || addrlen < 0)
111628 + return -EFAULT;
111629 if (copy_to_user(to, &temp, addrlen))
111630 return -EFAULT;
111631 to += addrlen;
111632 diff --git a/net/sctp/sysctl.c b/net/sctp/sysctl.c
111633 index 12c7e01..a755b3e 100644
111634 --- a/net/sctp/sysctl.c
111635 +++ b/net/sctp/sysctl.c
111636 @@ -321,7 +321,7 @@ static int proc_sctp_do_hmac_alg(struct ctl_table *ctl, int write,
111637 loff_t *ppos)
111638 {
111639 struct net *net = current->nsproxy->net_ns;
111640 - struct ctl_table tbl;
111641 + ctl_table_no_const tbl;
111642 bool changed = false;
111643 char *none = "none";
111644 char tmp[8];
111645 @@ -369,7 +369,7 @@ static int proc_sctp_do_rto_min(struct ctl_table *ctl, int write,
111646 struct net *net = current->nsproxy->net_ns;
111647 unsigned int min = *(unsigned int *) ctl->extra1;
111648 unsigned int max = *(unsigned int *) ctl->extra2;
111649 - struct ctl_table tbl;
111650 + ctl_table_no_const tbl;
111651 int ret, new_value;
111652
111653 memset(&tbl, 0, sizeof(struct ctl_table));
111654 @@ -398,7 +398,7 @@ static int proc_sctp_do_rto_max(struct ctl_table *ctl, int write,
111655 struct net *net = current->nsproxy->net_ns;
111656 unsigned int min = *(unsigned int *) ctl->extra1;
111657 unsigned int max = *(unsigned int *) ctl->extra2;
111658 - struct ctl_table tbl;
111659 + ctl_table_no_const tbl;
111660 int ret, new_value;
111661
111662 memset(&tbl, 0, sizeof(struct ctl_table));
111663 @@ -435,7 +435,7 @@ static int proc_sctp_do_auth(struct ctl_table *ctl, int write,
111664 loff_t *ppos)
111665 {
111666 struct net *net = current->nsproxy->net_ns;
111667 - struct ctl_table tbl;
111668 + ctl_table_no_const tbl;
111669 int new_value, ret;
111670
111671 memset(&tbl, 0, sizeof(struct ctl_table));
111672 @@ -462,7 +462,7 @@ static int proc_sctp_do_auth(struct ctl_table *ctl, int write,
111673
111674 int sctp_sysctl_net_register(struct net *net)
111675 {
111676 - struct ctl_table *table;
111677 + ctl_table_no_const *table;
111678 int i;
111679
111680 table = kmemdup(sctp_net_table, sizeof(sctp_net_table), GFP_KERNEL);
111681 diff --git a/net/socket.c b/net/socket.c
111682 index abf56b2..4cac767 100644
111683 --- a/net/socket.c
111684 +++ b/net/socket.c
111685 @@ -72,7 +72,6 @@
111686 #include <linux/if_bridge.h>
111687 #include <linux/if_frad.h>
111688 #include <linux/if_vlan.h>
111689 -#include <linux/ptp_classify.h>
111690 #include <linux/init.h>
111691 #include <linux/poll.h>
111692 #include <linux/cache.h>
111693 @@ -89,6 +88,7 @@
111694 #include <linux/magic.h>
111695 #include <linux/slab.h>
111696 #include <linux/xattr.h>
111697 +#include <linux/in.h>
111698
111699 #include <asm/uaccess.h>
111700 #include <asm/unistd.h>
111701 @@ -112,6 +112,8 @@ unsigned int sysctl_net_busy_read __read_mostly;
111702 unsigned int sysctl_net_busy_poll __read_mostly;
111703 #endif
111704
111705 +#include <linux/grsock.h>
111706 +
111707 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
111708 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
111709 unsigned long nr_segs, loff_t pos);
111710 @@ -163,7 +165,7 @@ static const struct file_operations socket_file_ops = {
111711 */
111712
111713 static DEFINE_SPINLOCK(net_family_lock);
111714 -static const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
111715 +const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
111716
111717 /*
111718 * Statistics counters of the socket lists
111719 @@ -329,7 +331,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
111720 &sockfs_dentry_operations, SOCKFS_MAGIC);
111721 }
111722
111723 -static struct vfsmount *sock_mnt __read_mostly;
111724 +struct vfsmount *sock_mnt __read_mostly;
111725
111726 static struct file_system_type sock_fs_type = {
111727 .name = "sockfs",
111728 @@ -1257,6 +1259,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
111729 return -EAFNOSUPPORT;
111730 if (type < 0 || type >= SOCK_MAX)
111731 return -EINVAL;
111732 + if (protocol < 0)
111733 + return -EINVAL;
111734
111735 /* Compatibility.
111736
111737 @@ -1277,6 +1281,20 @@ int __sock_create(struct net *net, int family, int type, int protocol,
111738 if (err)
111739 return err;
111740
111741 + if(!kern && !gr_search_socket(family, type, protocol)) {
111742 + if (rcu_access_pointer(net_families[family]) == NULL)
111743 + return -EAFNOSUPPORT;
111744 + else
111745 + return -EACCES;
111746 + }
111747 +
111748 + if (!kern && gr_handle_sock_all(family, type, protocol)) {
111749 + if (rcu_access_pointer(net_families[family]) == NULL)
111750 + return -EAFNOSUPPORT;
111751 + else
111752 + return -EACCES;
111753 + }
111754 +
111755 /*
111756 * Allocate the socket and allow the family to set things up. if
111757 * the protocol is 0, the family is instructed to select an appropriate
111758 @@ -1528,6 +1546,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
111759 if (sock) {
111760 err = move_addr_to_kernel(umyaddr, addrlen, &address);
111761 if (err >= 0) {
111762 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
111763 + err = -EACCES;
111764 + goto error;
111765 + }
111766 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
111767 + if (err)
111768 + goto error;
111769 +
111770 err = security_socket_bind(sock,
111771 (struct sockaddr *)&address,
111772 addrlen);
111773 @@ -1536,6 +1562,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
111774 (struct sockaddr *)
111775 &address, addrlen);
111776 }
111777 +error:
111778 fput_light(sock->file, fput_needed);
111779 }
111780 return err;
111781 @@ -1559,10 +1586,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
111782 if ((unsigned int)backlog > somaxconn)
111783 backlog = somaxconn;
111784
111785 + if (gr_handle_sock_server_other(sock->sk)) {
111786 + err = -EPERM;
111787 + goto error;
111788 + }
111789 +
111790 + err = gr_search_listen(sock);
111791 + if (err)
111792 + goto error;
111793 +
111794 err = security_socket_listen(sock, backlog);
111795 if (!err)
111796 err = sock->ops->listen(sock, backlog);
111797
111798 +error:
111799 fput_light(sock->file, fput_needed);
111800 }
111801 return err;
111802 @@ -1606,6 +1643,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
111803 newsock->type = sock->type;
111804 newsock->ops = sock->ops;
111805
111806 + if (gr_handle_sock_server_other(sock->sk)) {
111807 + err = -EPERM;
111808 + sock_release(newsock);
111809 + goto out_put;
111810 + }
111811 +
111812 + err = gr_search_accept(sock);
111813 + if (err) {
111814 + sock_release(newsock);
111815 + goto out_put;
111816 + }
111817 +
111818 /*
111819 * We don't need try_module_get here, as the listening socket (sock)
111820 * has the protocol module (sock->ops->owner) held.
111821 @@ -1651,6 +1700,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
111822 fd_install(newfd, newfile);
111823 err = newfd;
111824
111825 + gr_attach_curr_ip(newsock->sk);
111826 +
111827 out_put:
111828 fput_light(sock->file, fput_needed);
111829 out:
111830 @@ -1683,6 +1734,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
111831 int, addrlen)
111832 {
111833 struct socket *sock;
111834 + struct sockaddr *sck;
111835 struct sockaddr_storage address;
111836 int err, fput_needed;
111837
111838 @@ -1693,6 +1745,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
111839 if (err < 0)
111840 goto out_put;
111841
111842 + sck = (struct sockaddr *)&address;
111843 +
111844 + if (gr_handle_sock_client(sck)) {
111845 + err = -EACCES;
111846 + goto out_put;
111847 + }
111848 +
111849 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
111850 + if (err)
111851 + goto out_put;
111852 +
111853 err =
111854 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
111855 if (err)
111856 @@ -1774,6 +1837,8 @@ SYSCALL_DEFINE3(getpeername, int, fd, struct sockaddr __user *, usockaddr,
111857 * the protocol.
111858 */
111859
111860 +asmlinkage long sys_sendto(int, void __user *, size_t, unsigned, struct sockaddr __user *, int);
111861 +
111862 SYSCALL_DEFINE6(sendto, int, fd, void __user *, buff, size_t, len,
111863 unsigned int, flags, struct sockaddr __user *, addr,
111864 int, addr_len)
111865 @@ -1840,7 +1905,7 @@ SYSCALL_DEFINE6(recvfrom, int, fd, void __user *, ubuf, size_t, size,
111866 struct socket *sock;
111867 struct iovec iov;
111868 struct msghdr msg;
111869 - struct sockaddr_storage address;
111870 + struct sockaddr_storage address = { };
111871 int err, err2;
111872 int fput_needed;
111873
111874 @@ -2066,7 +2131,7 @@ static int ___sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
111875 * checking falls down on this.
111876 */
111877 if (copy_from_user(ctl_buf,
111878 - (void __user __force *)msg_sys->msg_control,
111879 + (void __force_user *)msg_sys->msg_control,
111880 ctl_len))
111881 goto out_freectl;
111882 msg_sys->msg_control = ctl_buf;
111883 @@ -2217,7 +2282,7 @@ static int ___sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
111884 int err, total_len, len;
111885
111886 /* kernel mode address */
111887 - struct sockaddr_storage addr;
111888 + struct sockaddr_storage addr = { };
111889
111890 /* user mode address pointers */
111891 struct sockaddr __user *uaddr;
111892 @@ -2246,7 +2311,7 @@ static int ___sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
111893 /* Save the user-mode address (verify_iovec will change the
111894 * kernel msghdr to use the kernel address space)
111895 */
111896 - uaddr = (__force void __user *)msg_sys->msg_name;
111897 + uaddr = (void __force_user *)msg_sys->msg_name;
111898 uaddr_len = COMPAT_NAMELEN(msg);
111899 if (MSG_CMSG_COMPAT & flags)
111900 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
111901 @@ -2686,7 +2751,9 @@ static int __init sock_init(void)
111902 goto out;
111903 #endif
111904
111905 - ptp_classifier_init();
111906 +#ifdef CONFIG_NETWORK_PHY_TIMESTAMPING
111907 + skb_timestamping_init();
111908 +#endif
111909
111910 out:
111911 return err;
111912 @@ -2887,7 +2954,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
111913 ifr = compat_alloc_user_space(buf_size);
111914 rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
111915
111916 - if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
111917 + if (copy_in_user(ifr->ifr_name, ifr32->ifr_name, IFNAMSIZ))
111918 return -EFAULT;
111919
111920 if (put_user(convert_in ? rxnfc : compat_ptr(data),
111921 @@ -2998,7 +3065,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
111922 old_fs = get_fs();
111923 set_fs(KERNEL_DS);
111924 err = dev_ioctl(net, cmd,
111925 - (struct ifreq __user __force *) &kifr);
111926 + (struct ifreq __force_user *) &kifr);
111927 set_fs(old_fs);
111928
111929 return err;
111930 @@ -3091,7 +3158,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
111931
111932 old_fs = get_fs();
111933 set_fs(KERNEL_DS);
111934 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
111935 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
111936 set_fs(old_fs);
111937
111938 if (cmd == SIOCGIFMAP && !err) {
111939 @@ -3175,7 +3242,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
111940 ret |= get_user(rtdev, &(ur4->rt_dev));
111941 if (rtdev) {
111942 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
111943 - r4.rt_dev = (char __user __force *)devname;
111944 + r4.rt_dev = (char __force_user *)devname;
111945 devname[15] = 0;
111946 } else
111947 r4.rt_dev = NULL;
111948 @@ -3402,8 +3469,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
111949 int __user *uoptlen;
111950 int err;
111951
111952 - uoptval = (char __user __force *) optval;
111953 - uoptlen = (int __user __force *) optlen;
111954 + uoptval = (char __force_user *) optval;
111955 + uoptlen = (int __force_user *) optlen;
111956
111957 set_fs(KERNEL_DS);
111958 if (level == SOL_SOCKET)
111959 @@ -3423,7 +3490,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
111960 char __user *uoptval;
111961 int err;
111962
111963 - uoptval = (char __user __force *) optval;
111964 + uoptval = (char __force_user *) optval;
111965
111966 set_fs(KERNEL_DS);
111967 if (level == SOL_SOCKET)
111968 diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c
111969 index 4ce5ecce..7bef300 100644
111970 --- a/net/sunrpc/auth_gss/svcauth_gss.c
111971 +++ b/net/sunrpc/auth_gss/svcauth_gss.c
111972 @@ -1140,7 +1140,7 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
111973 uint64_t *handle)
111974 {
111975 struct rsc rsci, *rscp = NULL;
111976 - static atomic64_t ctxhctr;
111977 + static atomic64_unchecked_t ctxhctr = ATOMIC64_INIT(0);
111978 long long ctxh;
111979 struct gss_api_mech *gm = NULL;
111980 time_t expiry;
111981 @@ -1151,7 +1151,7 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
111982 status = -ENOMEM;
111983 /* the handle needs to be just a unique id,
111984 * use a static counter */
111985 - ctxh = atomic64_inc_return(&ctxhctr);
111986 + ctxh = atomic64_inc_return_unchecked(&ctxhctr);
111987
111988 /* make a copy for the caller */
111989 *handle = ctxh;
111990 diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c
111991 index 0663621..c4928d4 100644
111992 --- a/net/sunrpc/cache.c
111993 +++ b/net/sunrpc/cache.c
111994 @@ -1609,7 +1609,7 @@ static int create_cache_proc_entries(struct cache_detail *cd, struct net *net)
111995 struct sunrpc_net *sn;
111996
111997 sn = net_generic(net, sunrpc_net_id);
111998 - cd->u.procfs.proc_ent = proc_mkdir(cd->name, sn->proc_net_rpc);
111999 + cd->u.procfs.proc_ent = proc_mkdir_restrict(cd->name, sn->proc_net_rpc);
112000 if (cd->u.procfs.proc_ent == NULL)
112001 goto out_nomem;
112002 cd->u.procfs.channel_ent = NULL;
112003 diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
112004 index 2e6ab10..3170800 100644
112005 --- a/net/sunrpc/clnt.c
112006 +++ b/net/sunrpc/clnt.c
112007 @@ -1425,7 +1425,9 @@ call_start(struct rpc_task *task)
112008 (RPC_IS_ASYNC(task) ? "async" : "sync"));
112009
112010 /* Increment call count */
112011 - task->tk_msg.rpc_proc->p_count++;
112012 + pax_open_kernel();
112013 + (*(unsigned int *)&task->tk_msg.rpc_proc->p_count)++;
112014 + pax_close_kernel();
112015 clnt->cl_stats->rpccnt++;
112016 task->tk_action = call_reserve;
112017 }
112018 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
112019 index c0365c1..b7f02b3 100644
112020 --- a/net/sunrpc/sched.c
112021 +++ b/net/sunrpc/sched.c
112022 @@ -261,9 +261,9 @@ static int rpc_wait_bit_killable(void *word)
112023 #if defined(RPC_DEBUG) || defined(RPC_TRACEPOINTS)
112024 static void rpc_task_set_debuginfo(struct rpc_task *task)
112025 {
112026 - static atomic_t rpc_pid;
112027 + static atomic_unchecked_t rpc_pid;
112028
112029 - task->tk_pid = atomic_inc_return(&rpc_pid);
112030 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
112031 }
112032 #else
112033 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
112034 diff --git a/net/sunrpc/stats.c b/net/sunrpc/stats.c
112035 index 5453049..465669a 100644
112036 --- a/net/sunrpc/stats.c
112037 +++ b/net/sunrpc/stats.c
112038 @@ -267,7 +267,7 @@ int rpc_proc_init(struct net *net)
112039
112040 dprintk("RPC: registering /proc/net/rpc\n");
112041 sn = net_generic(net, sunrpc_net_id);
112042 - sn->proc_net_rpc = proc_mkdir("rpc", net->proc_net);
112043 + sn->proc_net_rpc = proc_mkdir_restrict("rpc", net->proc_net);
112044 if (sn->proc_net_rpc == NULL)
112045 return -ENOMEM;
112046
112047 diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c
112048 index 5de6801..b4e330d 100644
112049 --- a/net/sunrpc/svc.c
112050 +++ b/net/sunrpc/svc.c
112051 @@ -1167,7 +1167,9 @@ svc_process_common(struct svc_rqst *rqstp, struct kvec *argv, struct kvec *resv)
112052 svc_putnl(resv, RPC_SUCCESS);
112053
112054 /* Bump per-procedure stats counter */
112055 - procp->pc_count++;
112056 + pax_open_kernel();
112057 + (*(unsigned int *)&procp->pc_count)++;
112058 + pax_close_kernel();
112059
112060 /* Initialize storage for argp and resp */
112061 memset(rqstp->rq_argp, 0, procp->pc_argsize);
112062 diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c
112063 index 621ca7b..59421dd 100644
112064 --- a/net/sunrpc/svcauth_unix.c
112065 +++ b/net/sunrpc/svcauth_unix.c
112066 @@ -414,7 +414,7 @@ struct unix_gid {
112067 struct group_info *gi;
112068 };
112069
112070 -static int unix_gid_hash(kuid_t uid)
112071 +static int __intentional_overflow(-1) unix_gid_hash(kuid_t uid)
112072 {
112073 return hash_long(from_kuid(&init_user_ns, uid), GID_HASHBITS);
112074 }
112075 @@ -470,7 +470,7 @@ static void unix_gid_request(struct cache_detail *cd,
112076 (*bpp)[-1] = '\n';
112077 }
112078
112079 -static struct unix_gid *unix_gid_lookup(struct cache_detail *cd, kuid_t uid);
112080 +static struct unix_gid * __intentional_overflow(-1) unix_gid_lookup(struct cache_detail *cd, kuid_t uid);
112081
112082 static int unix_gid_parse(struct cache_detail *cd,
112083 char *mesg, int mlen)
112084 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
112085 index c1b6270..05089c1 100644
112086 --- a/net/sunrpc/xprtrdma/svc_rdma.c
112087 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
112088 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
112089 static unsigned int min_max_inline = 4096;
112090 static unsigned int max_max_inline = 65536;
112091
112092 -atomic_t rdma_stat_recv;
112093 -atomic_t rdma_stat_read;
112094 -atomic_t rdma_stat_write;
112095 -atomic_t rdma_stat_sq_starve;
112096 -atomic_t rdma_stat_rq_starve;
112097 -atomic_t rdma_stat_rq_poll;
112098 -atomic_t rdma_stat_rq_prod;
112099 -atomic_t rdma_stat_sq_poll;
112100 -atomic_t rdma_stat_sq_prod;
112101 +atomic_unchecked_t rdma_stat_recv;
112102 +atomic_unchecked_t rdma_stat_read;
112103 +atomic_unchecked_t rdma_stat_write;
112104 +atomic_unchecked_t rdma_stat_sq_starve;
112105 +atomic_unchecked_t rdma_stat_rq_starve;
112106 +atomic_unchecked_t rdma_stat_rq_poll;
112107 +atomic_unchecked_t rdma_stat_rq_prod;
112108 +atomic_unchecked_t rdma_stat_sq_poll;
112109 +atomic_unchecked_t rdma_stat_sq_prod;
112110
112111 /* Temporary NFS request map and context caches */
112112 struct kmem_cache *svc_rdma_map_cachep;
112113 @@ -110,7 +110,7 @@ static int read_reset_stat(struct ctl_table *table, int write,
112114 len -= *ppos;
112115 if (len > *lenp)
112116 len = *lenp;
112117 - if (len && copy_to_user(buffer, str_buf, len))
112118 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
112119 return -EFAULT;
112120 *lenp = len;
112121 *ppos += len;
112122 @@ -151,63 +151,63 @@ static struct ctl_table svcrdma_parm_table[] = {
112123 {
112124 .procname = "rdma_stat_read",
112125 .data = &rdma_stat_read,
112126 - .maxlen = sizeof(atomic_t),
112127 + .maxlen = sizeof(atomic_unchecked_t),
112128 .mode = 0644,
112129 .proc_handler = read_reset_stat,
112130 },
112131 {
112132 .procname = "rdma_stat_recv",
112133 .data = &rdma_stat_recv,
112134 - .maxlen = sizeof(atomic_t),
112135 + .maxlen = sizeof(atomic_unchecked_t),
112136 .mode = 0644,
112137 .proc_handler = read_reset_stat,
112138 },
112139 {
112140 .procname = "rdma_stat_write",
112141 .data = &rdma_stat_write,
112142 - .maxlen = sizeof(atomic_t),
112143 + .maxlen = sizeof(atomic_unchecked_t),
112144 .mode = 0644,
112145 .proc_handler = read_reset_stat,
112146 },
112147 {
112148 .procname = "rdma_stat_sq_starve",
112149 .data = &rdma_stat_sq_starve,
112150 - .maxlen = sizeof(atomic_t),
112151 + .maxlen = sizeof(atomic_unchecked_t),
112152 .mode = 0644,
112153 .proc_handler = read_reset_stat,
112154 },
112155 {
112156 .procname = "rdma_stat_rq_starve",
112157 .data = &rdma_stat_rq_starve,
112158 - .maxlen = sizeof(atomic_t),
112159 + .maxlen = sizeof(atomic_unchecked_t),
112160 .mode = 0644,
112161 .proc_handler = read_reset_stat,
112162 },
112163 {
112164 .procname = "rdma_stat_rq_poll",
112165 .data = &rdma_stat_rq_poll,
112166 - .maxlen = sizeof(atomic_t),
112167 + .maxlen = sizeof(atomic_unchecked_t),
112168 .mode = 0644,
112169 .proc_handler = read_reset_stat,
112170 },
112171 {
112172 .procname = "rdma_stat_rq_prod",
112173 .data = &rdma_stat_rq_prod,
112174 - .maxlen = sizeof(atomic_t),
112175 + .maxlen = sizeof(atomic_unchecked_t),
112176 .mode = 0644,
112177 .proc_handler = read_reset_stat,
112178 },
112179 {
112180 .procname = "rdma_stat_sq_poll",
112181 .data = &rdma_stat_sq_poll,
112182 - .maxlen = sizeof(atomic_t),
112183 + .maxlen = sizeof(atomic_unchecked_t),
112184 .mode = 0644,
112185 .proc_handler = read_reset_stat,
112186 },
112187 {
112188 .procname = "rdma_stat_sq_prod",
112189 .data = &rdma_stat_sq_prod,
112190 - .maxlen = sizeof(atomic_t),
112191 + .maxlen = sizeof(atomic_unchecked_t),
112192 .mode = 0644,
112193 .proc_handler = read_reset_stat,
112194 },
112195 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
112196 index 8f92a61..eb13b74 100644
112197 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
112198 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
112199 @@ -219,7 +219,7 @@ static int rdma_read_chunk_lcl(struct svcxprt_rdma *xprt,
112200 *page_no = pg_no;
112201 *page_offset = pg_off;
112202 ret = read;
112203 - atomic_inc(&rdma_stat_read);
112204 + atomic_inc_unchecked(&rdma_stat_read);
112205 return ret;
112206 err:
112207 svc_rdma_unmap_dma(ctxt);
112208 @@ -355,7 +355,7 @@ static int rdma_read_chunk_frmr(struct svcxprt_rdma *xprt,
112209 *page_no = pg_no;
112210 *page_offset = pg_off;
112211 ret = read;
112212 - atomic_inc(&rdma_stat_read);
112213 + atomic_inc_unchecked(&rdma_stat_read);
112214 return ret;
112215 err:
112216 svc_rdma_unmap_dma(ctxt);
112217 @@ -512,7 +512,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
112218 dto_q);
112219 list_del_init(&ctxt->dto_q);
112220 } else {
112221 - atomic_inc(&rdma_stat_rq_starve);
112222 + atomic_inc_unchecked(&rdma_stat_rq_starve);
112223 clear_bit(XPT_DATA, &xprt->xpt_flags);
112224 ctxt = NULL;
112225 }
112226 @@ -531,7 +531,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
112227 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
112228 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
112229 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
112230 - atomic_inc(&rdma_stat_recv);
112231 + atomic_inc_unchecked(&rdma_stat_recv);
112232
112233 /* Build up the XDR from the receive buffers. */
112234 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
112235 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
112236 index 49fd21a..4bc455b 100644
112237 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
112238 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
112239 @@ -206,7 +206,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
112240 write_wr.wr.rdma.remote_addr = to;
112241
112242 /* Post It */
112243 - atomic_inc(&rdma_stat_write);
112244 + atomic_inc_unchecked(&rdma_stat_write);
112245 if (svc_rdma_send(xprt, &write_wr))
112246 goto err;
112247 return 0;
112248 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
112249 index e7323fb..5e892b3 100644
112250 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
112251 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
112252 @@ -294,7 +294,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
112253 return;
112254
112255 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
112256 - atomic_inc(&rdma_stat_rq_poll);
112257 + atomic_inc_unchecked(&rdma_stat_rq_poll);
112258
112259 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
112260 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
112261 @@ -316,7 +316,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
112262 }
112263
112264 if (ctxt)
112265 - atomic_inc(&rdma_stat_rq_prod);
112266 + atomic_inc_unchecked(&rdma_stat_rq_prod);
112267
112268 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
112269 /*
112270 @@ -391,7 +391,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
112271 return;
112272
112273 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
112274 - atomic_inc(&rdma_stat_sq_poll);
112275 + atomic_inc_unchecked(&rdma_stat_sq_poll);
112276 while ((ret = ib_poll_cq(cq, ARRAY_SIZE(wc_a), wc_a)) > 0) {
112277 int i;
112278
112279 @@ -419,7 +419,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
112280 }
112281
112282 if (ctxt)
112283 - atomic_inc(&rdma_stat_sq_prod);
112284 + atomic_inc_unchecked(&rdma_stat_sq_prod);
112285 }
112286
112287 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
112288 @@ -1278,7 +1278,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
112289 spin_lock_bh(&xprt->sc_lock);
112290 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
112291 spin_unlock_bh(&xprt->sc_lock);
112292 - atomic_inc(&rdma_stat_sq_starve);
112293 + atomic_inc_unchecked(&rdma_stat_sq_starve);
112294
112295 /* See if we can opportunistically reap SQ WR to make room */
112296 sq_cq_reap(xprt);
112297 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
112298 index e7000be..e3b0ba7 100644
112299 --- a/net/sysctl_net.c
112300 +++ b/net/sysctl_net.c
112301 @@ -46,7 +46,7 @@ static int net_ctl_permissions(struct ctl_table_header *head,
112302 kgid_t root_gid = make_kgid(net->user_ns, 0);
112303
112304 /* Allow network administrator to have same access as root. */
112305 - if (ns_capable(net->user_ns, CAP_NET_ADMIN) ||
112306 + if (ns_capable_nolog(net->user_ns, CAP_NET_ADMIN) ||
112307 uid_eq(root_uid, current_euid())) {
112308 int mode = (table->mode >> 6) & 7;
112309 return (mode << 6) | (mode << 3) | mode;
112310 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
112311 index 6424372..afd36e9 100644
112312 --- a/net/tipc/subscr.c
112313 +++ b/net/tipc/subscr.c
112314 @@ -97,7 +97,7 @@ static void subscr_send_event(struct tipc_subscription *sub, u32 found_lower,
112315 struct tipc_subscriber *subscriber = sub->subscriber;
112316 struct kvec msg_sect;
112317
112318 - msg_sect.iov_base = (void *)&sub->evt;
112319 + msg_sect.iov_base = &sub->evt;
112320 msg_sect.iov_len = sizeof(struct tipc_event);
112321 sub->evt.event = htohl(event, sub->swap);
112322 sub->evt.found_lower = htohl(found_lower, sub->swap);
112323 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
112324 index e968843..bc95776 100644
112325 --- a/net/unix/af_unix.c
112326 +++ b/net/unix/af_unix.c
112327 @@ -791,6 +791,12 @@ static struct sock *unix_find_other(struct net *net,
112328 err = -ECONNREFUSED;
112329 if (!S_ISSOCK(inode->i_mode))
112330 goto put_fail;
112331 +
112332 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
112333 + err = -EACCES;
112334 + goto put_fail;
112335 + }
112336 +
112337 u = unix_find_socket_byinode(inode);
112338 if (!u)
112339 goto put_fail;
112340 @@ -811,6 +817,13 @@ static struct sock *unix_find_other(struct net *net,
112341 if (u) {
112342 struct dentry *dentry;
112343 dentry = unix_sk(u)->path.dentry;
112344 +
112345 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
112346 + err = -EPERM;
112347 + sock_put(u);
112348 + goto fail;
112349 + }
112350 +
112351 if (dentry)
112352 touch_atime(&unix_sk(u)->path);
112353 } else
112354 @@ -844,12 +857,18 @@ static int unix_mknod(const char *sun_path, umode_t mode, struct path *res)
112355 */
112356 err = security_path_mknod(&path, dentry, mode, 0);
112357 if (!err) {
112358 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
112359 + err = -EACCES;
112360 + goto out;
112361 + }
112362 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
112363 if (!err) {
112364 res->mnt = mntget(path.mnt);
112365 res->dentry = dget(dentry);
112366 + gr_handle_create(dentry, path.mnt);
112367 }
112368 }
112369 +out:
112370 done_path_create(&path, dentry);
112371 return err;
112372 }
112373 @@ -2350,9 +2369,13 @@ static int unix_seq_show(struct seq_file *seq, void *v)
112374 seq_puts(seq, "Num RefCount Protocol Flags Type St "
112375 "Inode Path\n");
112376 else {
112377 - struct sock *s = v;
112378 + struct sock *s = v, *peer;
112379 struct unix_sock *u = unix_sk(s);
112380 unix_state_lock(s);
112381 + peer = unix_peer(s);
112382 + unix_state_unlock(s);
112383 +
112384 + unix_state_double_lock(s, peer);
112385
112386 seq_printf(seq, "%pK: %08X %08X %08X %04X %02X %5lu",
112387 s,
112388 @@ -2379,8 +2402,10 @@ static int unix_seq_show(struct seq_file *seq, void *v)
112389 }
112390 for ( ; i < len; i++)
112391 seq_putc(seq, u->addr->name->sun_path[i]);
112392 - }
112393 - unix_state_unlock(s);
112394 + } else if (peer)
112395 + seq_printf(seq, " P%lu", sock_i_ino(peer));
112396 +
112397 + unix_state_double_unlock(s, peer);
112398 seq_putc(seq, '\n');
112399 }
112400
112401 diff --git a/net/unix/sysctl_net_unix.c b/net/unix/sysctl_net_unix.c
112402 index b3d5150..ff3a837 100644
112403 --- a/net/unix/sysctl_net_unix.c
112404 +++ b/net/unix/sysctl_net_unix.c
112405 @@ -28,7 +28,7 @@ static struct ctl_table unix_table[] = {
112406
112407 int __net_init unix_sysctl_register(struct net *net)
112408 {
112409 - struct ctl_table *table;
112410 + ctl_table_no_const *table;
112411
112412 table = kmemdup(unix_table, sizeof(unix_table), GFP_KERNEL);
112413 if (table == NULL)
112414 diff --git a/net/vmw_vsock/vmci_transport_notify.c b/net/vmw_vsock/vmci_transport_notify.c
112415 index 9b7f207..2596621 100644
112416 --- a/net/vmw_vsock/vmci_transport_notify.c
112417 +++ b/net/vmw_vsock/vmci_transport_notify.c
112418 @@ -662,19 +662,19 @@ static void vmci_transport_notify_pkt_process_negotiate(struct sock *sk)
112419
112420 /* Socket control packet based operations. */
112421 struct vmci_transport_notify_ops vmci_transport_notify_pkt_ops = {
112422 - vmci_transport_notify_pkt_socket_init,
112423 - vmci_transport_notify_pkt_socket_destruct,
112424 - vmci_transport_notify_pkt_poll_in,
112425 - vmci_transport_notify_pkt_poll_out,
112426 - vmci_transport_notify_pkt_handle_pkt,
112427 - vmci_transport_notify_pkt_recv_init,
112428 - vmci_transport_notify_pkt_recv_pre_block,
112429 - vmci_transport_notify_pkt_recv_pre_dequeue,
112430 - vmci_transport_notify_pkt_recv_post_dequeue,
112431 - vmci_transport_notify_pkt_send_init,
112432 - vmci_transport_notify_pkt_send_pre_block,
112433 - vmci_transport_notify_pkt_send_pre_enqueue,
112434 - vmci_transport_notify_pkt_send_post_enqueue,
112435 - vmci_transport_notify_pkt_process_request,
112436 - vmci_transport_notify_pkt_process_negotiate,
112437 + .socket_init = vmci_transport_notify_pkt_socket_init,
112438 + .socket_destruct = vmci_transport_notify_pkt_socket_destruct,
112439 + .poll_in = vmci_transport_notify_pkt_poll_in,
112440 + .poll_out = vmci_transport_notify_pkt_poll_out,
112441 + .handle_notify_pkt = vmci_transport_notify_pkt_handle_pkt,
112442 + .recv_init = vmci_transport_notify_pkt_recv_init,
112443 + .recv_pre_block = vmci_transport_notify_pkt_recv_pre_block,
112444 + .recv_pre_dequeue = vmci_transport_notify_pkt_recv_pre_dequeue,
112445 + .recv_post_dequeue = vmci_transport_notify_pkt_recv_post_dequeue,
112446 + .send_init = vmci_transport_notify_pkt_send_init,
112447 + .send_pre_block = vmci_transport_notify_pkt_send_pre_block,
112448 + .send_pre_enqueue = vmci_transport_notify_pkt_send_pre_enqueue,
112449 + .send_post_enqueue = vmci_transport_notify_pkt_send_post_enqueue,
112450 + .process_request = vmci_transport_notify_pkt_process_request,
112451 + .process_negotiate = vmci_transport_notify_pkt_process_negotiate,
112452 };
112453 diff --git a/net/vmw_vsock/vmci_transport_notify_qstate.c b/net/vmw_vsock/vmci_transport_notify_qstate.c
112454 index dc9c792..3089de0 100644
112455 --- a/net/vmw_vsock/vmci_transport_notify_qstate.c
112456 +++ b/net/vmw_vsock/vmci_transport_notify_qstate.c
112457 @@ -420,19 +420,19 @@ vmci_transport_notify_pkt_send_pre_enqueue(
112458
112459 /* Socket always on control packet based operations. */
112460 struct vmci_transport_notify_ops vmci_transport_notify_pkt_q_state_ops = {
112461 - vmci_transport_notify_pkt_socket_init,
112462 - vmci_transport_notify_pkt_socket_destruct,
112463 - vmci_transport_notify_pkt_poll_in,
112464 - vmci_transport_notify_pkt_poll_out,
112465 - vmci_transport_notify_pkt_handle_pkt,
112466 - vmci_transport_notify_pkt_recv_init,
112467 - vmci_transport_notify_pkt_recv_pre_block,
112468 - vmci_transport_notify_pkt_recv_pre_dequeue,
112469 - vmci_transport_notify_pkt_recv_post_dequeue,
112470 - vmci_transport_notify_pkt_send_init,
112471 - vmci_transport_notify_pkt_send_pre_block,
112472 - vmci_transport_notify_pkt_send_pre_enqueue,
112473 - vmci_transport_notify_pkt_send_post_enqueue,
112474 - vmci_transport_notify_pkt_process_request,
112475 - vmci_transport_notify_pkt_process_negotiate,
112476 + .socket_init = vmci_transport_notify_pkt_socket_init,
112477 + .socket_destruct = vmci_transport_notify_pkt_socket_destruct,
112478 + .poll_in = vmci_transport_notify_pkt_poll_in,
112479 + .poll_out = vmci_transport_notify_pkt_poll_out,
112480 + .handle_notify_pkt = vmci_transport_notify_pkt_handle_pkt,
112481 + .recv_init = vmci_transport_notify_pkt_recv_init,
112482 + .recv_pre_block = vmci_transport_notify_pkt_recv_pre_block,
112483 + .recv_pre_dequeue = vmci_transport_notify_pkt_recv_pre_dequeue,
112484 + .recv_post_dequeue = vmci_transport_notify_pkt_recv_post_dequeue,
112485 + .send_init = vmci_transport_notify_pkt_send_init,
112486 + .send_pre_block = vmci_transport_notify_pkt_send_pre_block,
112487 + .send_pre_enqueue = vmci_transport_notify_pkt_send_pre_enqueue,
112488 + .send_post_enqueue = vmci_transport_notify_pkt_send_post_enqueue,
112489 + .process_request = vmci_transport_notify_pkt_process_request,
112490 + .process_negotiate = vmci_transport_notify_pkt_process_negotiate,
112491 };
112492 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
112493 index c8717c1..08539f5 100644
112494 --- a/net/wireless/wext-core.c
112495 +++ b/net/wireless/wext-core.c
112496 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
112497 */
112498
112499 /* Support for very large requests */
112500 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
112501 - (user_length > descr->max_tokens)) {
112502 + if (user_length > descr->max_tokens) {
112503 /* Allow userspace to GET more than max so
112504 * we can support any size GET requests.
112505 * There is still a limit : -ENOMEM.
112506 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
112507 }
112508 }
112509
112510 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
112511 - /*
112512 - * If this is a GET, but not NOMAX, it means that the extra
112513 - * data is not bounded by userspace, but by max_tokens. Thus
112514 - * set the length to max_tokens. This matches the extra data
112515 - * allocation.
112516 - * The driver should fill it with the number of tokens it
112517 - * provided, and it may check iwp->length rather than having
112518 - * knowledge of max_tokens. If the driver doesn't change the
112519 - * iwp->length, this ioctl just copies back max_token tokens
112520 - * filled with zeroes. Hopefully the driver isn't claiming
112521 - * them to be valid data.
112522 - */
112523 - iwp->length = descr->max_tokens;
112524 - }
112525 -
112526 err = handler(dev, info, (union iwreq_data *) iwp, extra);
112527
112528 iwp->length += essid_compat;
112529 diff --git a/net/x25/sysctl_net_x25.c b/net/x25/sysctl_net_x25.c
112530 index 4323952..a06dfe1 100644
112531 --- a/net/x25/sysctl_net_x25.c
112532 +++ b/net/x25/sysctl_net_x25.c
112533 @@ -70,7 +70,7 @@ static struct ctl_table x25_table[] = {
112534 .mode = 0644,
112535 .proc_handler = proc_dointvec,
112536 },
112537 - { 0, },
112538 + { },
112539 };
112540
112541 void __init x25_register_sysctl(void)
112542 diff --git a/net/x25/x25_proc.c b/net/x25/x25_proc.c
112543 index 0917f04..f4e3d8c 100644
112544 --- a/net/x25/x25_proc.c
112545 +++ b/net/x25/x25_proc.c
112546 @@ -209,7 +209,7 @@ static const struct file_operations x25_seq_forward_fops = {
112547
112548 int __init x25_proc_init(void)
112549 {
112550 - if (!proc_mkdir("x25", init_net.proc_net))
112551 + if (!proc_mkdir_restrict("x25", init_net.proc_net))
112552 return -ENOMEM;
112553
112554 if (!proc_create("x25/route", S_IRUGO, init_net.proc_net,
112555 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
112556 index 0525d78..cccf7fd 100644
112557 --- a/net/xfrm/xfrm_policy.c
112558 +++ b/net/xfrm/xfrm_policy.c
112559 @@ -325,7 +325,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
112560 {
112561 policy->walk.dead = 1;
112562
112563 - atomic_inc(&policy->genid);
112564 + atomic_inc_unchecked(&policy->genid);
112565
112566 if (del_timer(&policy->polq.hold_timer))
112567 xfrm_pol_put(policy);
112568 @@ -659,7 +659,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
112569 hlist_add_head(&policy->bydst, chain);
112570 xfrm_pol_hold(policy);
112571 net->xfrm.policy_count[dir]++;
112572 - atomic_inc(&net->xfrm.flow_cache_genid);
112573 + atomic_inc_unchecked(&net->xfrm.flow_cache_genid);
112574
112575 /* After previous checking, family can either be AF_INET or AF_INET6 */
112576 if (policy->family == AF_INET)
112577 @@ -1749,7 +1749,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
112578
112579 xdst->num_pols = num_pols;
112580 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy *) * num_pols);
112581 - xdst->policy_genid = atomic_read(&pols[0]->genid);
112582 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
112583
112584 return xdst;
112585 }
112586 @@ -2538,10 +2538,11 @@ void xfrm_garbage_collect(struct net *net)
112587 }
112588 EXPORT_SYMBOL(xfrm_garbage_collect);
112589
112590 -static void xfrm_garbage_collect_deferred(struct net *net)
112591 +void xfrm_garbage_collect_deferred(struct net *net)
112592 {
112593 flow_cache_flush_deferred(net);
112594 }
112595 +EXPORT_SYMBOL(xfrm_garbage_collect_deferred);
112596
112597 static void xfrm_init_pmtu(struct dst_entry *dst)
112598 {
112599 @@ -2591,7 +2592,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
112600 if (xdst->xfrm_genid != dst->xfrm->genid)
112601 return 0;
112602 if (xdst->num_pols > 0 &&
112603 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
112604 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
112605 return 0;
112606
112607 mtu = dst_mtu(dst->child);
112608 @@ -2679,8 +2680,6 @@ int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo)
112609 dst_ops->link_failure = xfrm_link_failure;
112610 if (likely(dst_ops->neigh_lookup == NULL))
112611 dst_ops->neigh_lookup = xfrm_neigh_lookup;
112612 - if (likely(afinfo->garbage_collect == NULL))
112613 - afinfo->garbage_collect = xfrm_garbage_collect_deferred;
112614 rcu_assign_pointer(xfrm_policy_afinfo[afinfo->family], afinfo);
112615 }
112616 spin_unlock(&xfrm_policy_afinfo_lock);
112617 @@ -2734,7 +2733,6 @@ int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo)
112618 dst_ops->check = NULL;
112619 dst_ops->negative_advice = NULL;
112620 dst_ops->link_failure = NULL;
112621 - afinfo->garbage_collect = NULL;
112622 }
112623 return err;
112624 }
112625 @@ -3119,7 +3117,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
112626 sizeof(pol->xfrm_vec[i].saddr));
112627 pol->xfrm_vec[i].encap_family = mp->new_family;
112628 /* flush bundles */
112629 - atomic_inc(&pol->genid);
112630 + atomic_inc_unchecked(&pol->genid);
112631 }
112632 }
112633
112634 diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
112635 index 0ab5413..73dd2cf 100644
112636 --- a/net/xfrm/xfrm_state.c
112637 +++ b/net/xfrm/xfrm_state.c
112638 @@ -173,12 +173,14 @@ int xfrm_register_type(const struct xfrm_type *type, unsigned short family)
112639
112640 if (unlikely(afinfo == NULL))
112641 return -EAFNOSUPPORT;
112642 - typemap = afinfo->type_map;
112643 + typemap = (const struct xfrm_type **)afinfo->type_map;
112644 spin_lock_bh(&xfrm_type_lock);
112645
112646 - if (likely(typemap[type->proto] == NULL))
112647 + if (likely(typemap[type->proto] == NULL)) {
112648 + pax_open_kernel();
112649 typemap[type->proto] = type;
112650 - else
112651 + pax_close_kernel();
112652 + } else
112653 err = -EEXIST;
112654 spin_unlock_bh(&xfrm_type_lock);
112655 xfrm_state_put_afinfo(afinfo);
112656 @@ -194,13 +196,16 @@ int xfrm_unregister_type(const struct xfrm_type *type, unsigned short family)
112657
112658 if (unlikely(afinfo == NULL))
112659 return -EAFNOSUPPORT;
112660 - typemap = afinfo->type_map;
112661 + typemap = (const struct xfrm_type **)afinfo->type_map;
112662 spin_lock_bh(&xfrm_type_lock);
112663
112664 if (unlikely(typemap[type->proto] != type))
112665 err = -ENOENT;
112666 - else
112667 + else {
112668 + pax_open_kernel();
112669 typemap[type->proto] = NULL;
112670 + pax_close_kernel();
112671 + }
112672 spin_unlock_bh(&xfrm_type_lock);
112673 xfrm_state_put_afinfo(afinfo);
112674 return err;
112675 @@ -210,7 +215,6 @@ EXPORT_SYMBOL(xfrm_unregister_type);
112676 static const struct xfrm_type *xfrm_get_type(u8 proto, unsigned short family)
112677 {
112678 struct xfrm_state_afinfo *afinfo;
112679 - const struct xfrm_type **typemap;
112680 const struct xfrm_type *type;
112681 int modload_attempted = 0;
112682
112683 @@ -218,9 +222,8 @@ retry:
112684 afinfo = xfrm_state_get_afinfo(family);
112685 if (unlikely(afinfo == NULL))
112686 return NULL;
112687 - typemap = afinfo->type_map;
112688
112689 - type = typemap[proto];
112690 + type = afinfo->type_map[proto];
112691 if (unlikely(type && !try_module_get(type->owner)))
112692 type = NULL;
112693 if (!type && !modload_attempted) {
112694 @@ -254,7 +257,7 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
112695 return -EAFNOSUPPORT;
112696
112697 err = -EEXIST;
112698 - modemap = afinfo->mode_map;
112699 + modemap = (struct xfrm_mode **)afinfo->mode_map;
112700 spin_lock_bh(&xfrm_mode_lock);
112701 if (modemap[mode->encap])
112702 goto out;
112703 @@ -263,8 +266,10 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
112704 if (!try_module_get(afinfo->owner))
112705 goto out;
112706
112707 - mode->afinfo = afinfo;
112708 + pax_open_kernel();
112709 + *(const void **)&mode->afinfo = afinfo;
112710 modemap[mode->encap] = mode;
112711 + pax_close_kernel();
112712 err = 0;
112713
112714 out:
112715 @@ -288,10 +293,12 @@ int xfrm_unregister_mode(struct xfrm_mode *mode, int family)
112716 return -EAFNOSUPPORT;
112717
112718 err = -ENOENT;
112719 - modemap = afinfo->mode_map;
112720 + modemap = (struct xfrm_mode **)afinfo->mode_map;
112721 spin_lock_bh(&xfrm_mode_lock);
112722 if (likely(modemap[mode->encap] == mode)) {
112723 + pax_open_kernel();
112724 modemap[mode->encap] = NULL;
112725 + pax_close_kernel();
112726 module_put(mode->afinfo->owner);
112727 err = 0;
112728 }
112729 @@ -1512,10 +1519,10 @@ EXPORT_SYMBOL(xfrm_find_acq_byseq);
112730 u32 xfrm_get_acqseq(void)
112731 {
112732 u32 res;
112733 - static atomic_t acqseq;
112734 + static atomic_unchecked_t acqseq;
112735
112736 do {
112737 - res = atomic_inc_return(&acqseq);
112738 + res = atomic_inc_return_unchecked(&acqseq);
112739 } while (!res);
112740
112741 return res;
112742 diff --git a/net/xfrm/xfrm_sysctl.c b/net/xfrm/xfrm_sysctl.c
112743 index 05a6e3d..6716ec9 100644
112744 --- a/net/xfrm/xfrm_sysctl.c
112745 +++ b/net/xfrm/xfrm_sysctl.c
112746 @@ -42,7 +42,7 @@ static struct ctl_table xfrm_table[] = {
112747
112748 int __net_init xfrm_sysctl_init(struct net *net)
112749 {
112750 - struct ctl_table *table;
112751 + ctl_table_no_const *table;
112752
112753 __xfrm_sysctl_init(net);
112754
112755 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
112756 index bf3e677..c7d426e 100644
112757 --- a/scripts/Makefile.build
112758 +++ b/scripts/Makefile.build
112759 @@ -60,7 +60,7 @@ endif
112760 endif
112761
112762 # Do not include host rules unless needed
112763 -ifneq ($(hostprogs-y)$(hostprogs-m),)
112764 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
112765 include scripts/Makefile.host
112766 endif
112767
112768 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
112769 index 686cb0d..9d653bf 100644
112770 --- a/scripts/Makefile.clean
112771 +++ b/scripts/Makefile.clean
112772 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
112773 __clean-files := $(extra-y) $(always) \
112774 $(targets) $(clean-files) \
112775 $(host-progs) \
112776 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
112777 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
112778 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
112779
112780 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
112781
112782 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
112783 index 6689364..e56dc6a 100644
112784 --- a/scripts/Makefile.host
112785 +++ b/scripts/Makefile.host
112786 @@ -31,6 +31,8 @@
112787 # Note: Shared libraries consisting of C++ files are not supported
112788
112789 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
112790 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
112791 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
112792
112793 # C code
112794 # Executables compiled from a single .c file
112795 @@ -54,11 +56,15 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
112796 # Shared libaries (only .c supported)
112797 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
112798 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
112799 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
112800 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
112801 # Remove .so files from "xxx-objs"
112802 host-cobjs := $(filter-out %.so,$(host-cobjs))
112803 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
112804
112805 -#Object (.o) files used by the shared libaries
112806 +# Object (.o) files used by the shared libaries
112807 host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
112808 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
112809
112810 # output directory for programs/.o files
112811 # hostprogs-y := tools/build may have been specified. Retrieve directory
112812 @@ -82,7 +88,9 @@ host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
112813 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
112814 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
112815 host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
112816 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
112817 host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
112818 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
112819 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
112820
112821 obj-dirs += $(host-objdirs)
112822 @@ -156,6 +164,13 @@ quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
112823 $(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
112824 $(call if_changed_dep,host-cshobjs)
112825
112826 +# Compile .c file, create position independent .o file
112827 +# host-cxxshobjs -> .o
112828 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
112829 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
112830 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
112831 + $(call if_changed_dep,host-cxxshobjs)
112832 +
112833 # Link a shared library, based on position independent .o files
112834 # *.o -> .so shared library (host-cshlib)
112835 quiet_cmd_host-cshlib = HOSTLLD -shared $@
112836 @@ -165,5 +180,14 @@ quiet_cmd_host-cshlib = HOSTLLD -shared $@
112837 $(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
112838 $(call if_changed,host-cshlib)
112839
112840 +# Link a shared library, based on position independent .o files
112841 +# *.o -> .so shared library (host-cxxshlib)
112842 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
112843 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
112844 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
112845 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
112846 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
112847 + $(call if_changed,host-cxxshlib)
112848 +
112849 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
112850 - $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs)
112851 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
112852 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
112853 index b304068..462d24e 100644
112854 --- a/scripts/basic/fixdep.c
112855 +++ b/scripts/basic/fixdep.c
112856 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
112857 /*
112858 * Lookup a value in the configuration string.
112859 */
112860 -static int is_defined_config(const char *name, int len, unsigned int hash)
112861 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
112862 {
112863 struct item *aux;
112864
112865 @@ -211,10 +211,10 @@ static void clear_config(void)
112866 /*
112867 * Record the use of a CONFIG_* word.
112868 */
112869 -static void use_config(const char *m, int slen)
112870 +static void use_config(const char *m, unsigned int slen)
112871 {
112872 unsigned int hash = strhash(m, slen);
112873 - int c, i;
112874 + unsigned int c, i;
112875
112876 if (is_defined_config(m, slen, hash))
112877 return;
112878 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
112879
112880 static void parse_config_file(const char *map, size_t len)
112881 {
112882 - const int *end = (const int *) (map + len);
112883 + const unsigned int *end = (const unsigned int *) (map + len);
112884 /* start at +1, so that p can never be < map */
112885 - const int *m = (const int *) map + 1;
112886 + const unsigned int *m = (const unsigned int *) map + 1;
112887 const char *p, *q;
112888
112889 for (; m < end; m++) {
112890 @@ -435,7 +435,7 @@ static void print_deps(void)
112891 static void traps(void)
112892 {
112893 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
112894 - int *p = (int *)test;
112895 + unsigned int *p = (unsigned int *)test;
112896
112897 if (*p != INT_CONF) {
112898 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianness? %#x\n",
112899 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
112900 new file mode 100644
112901 index 0000000..3fd3699
112902 --- /dev/null
112903 +++ b/scripts/gcc-plugin.sh
112904 @@ -0,0 +1,43 @@
112905 +#!/bin/bash
112906 +srctree=$(dirname "$0")
112907 +gccplugins_dir=$($3 -print-file-name=plugin)
112908 +plugincc=$($1 -E - -o /dev/null -I${srctree}/../tools/gcc -I${gccplugins_dir}/include 2>&1 <<EOF
112909 +#include "gcc-common.h"
112910 +#if BUILDING_GCC_VERSION >= 4008 || defined(ENABLE_BUILD_WITH_CXX)
112911 +#warning $2 CXX
112912 +#else
112913 +#warning $1 CC
112914 +#endif
112915 +EOF
112916 +)
112917 +
112918 +if [ $? -ne 0 ]
112919 +then
112920 + exit 1
112921 +fi
112922 +
112923 +if [[ "$plugincc" =~ "$1 CC" ]]
112924 +then
112925 + echo "$1"
112926 + exit 0
112927 +fi
112928 +
112929 +if [[ "$plugincc" =~ "$2 CXX" ]]
112930 +then
112931 +plugincc=$($1 -c -x c++ -std=gnu++98 - -o /dev/null -I${srctree}/../tools/gcc -I${gccplugins_dir}/include 2>&1 <<EOF
112932 +#include "gcc-common.h"
112933 +class test {
112934 +public:
112935 + int test;
112936 +} test = {
112937 + .test = 1
112938 +};
112939 +EOF
112940 +)
112941 +if [ $? -eq 0 ]
112942 +then
112943 + echo "$2"
112944 + exit 0
112945 +fi
112946 +fi
112947 +exit 1
112948 diff --git a/scripts/headers_install.sh b/scripts/headers_install.sh
112949 index 5de5660..d3deb89 100644
112950 --- a/scripts/headers_install.sh
112951 +++ b/scripts/headers_install.sh
112952 @@ -32,6 +32,7 @@ do
112953 FILE="$(basename "$i")"
112954 sed -r \
112955 -e 's/([ \t(])(__user|__force|__iomem)[ \t]/\1/g' \
112956 + -e 's/__intentional_overflow\([- \t,0-9]*\)//g' \
112957 -e 's/__attribute_const__([ \t]|$)/\1/g' \
112958 -e 's@^#include <linux/compiler.h>@@' \
112959 -e 's/(^|[^a-zA-Z0-9])__packed([^a-zA-Z0-9_]|$)/\1__attribute__((packed))\2/g' \
112960 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
112961 index 86a4fe7..99e91f9 100644
112962 --- a/scripts/link-vmlinux.sh
112963 +++ b/scripts/link-vmlinux.sh
112964 @@ -166,7 +166,7 @@ else
112965 fi;
112966
112967 # final build of init/
112968 -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
112969 +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
112970
112971 kallsymso=""
112972 kallsyms_vmlinux=""
112973 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
112974 index e614ef6..d9d2b01 100644
112975 --- a/scripts/mod/file2alias.c
112976 +++ b/scripts/mod/file2alias.c
112977 @@ -142,7 +142,7 @@ static void device_id_check(const char *modname, const char *device_id,
112978 unsigned long size, unsigned long id_size,
112979 void *symval)
112980 {
112981 - int i;
112982 + unsigned int i;
112983
112984 if (size % id_size || size < id_size) {
112985 fatal("%s: sizeof(struct %s_device_id)=%lu is not a modulo "
112986 @@ -171,7 +171,7 @@ static void device_id_check(const char *modname, const char *device_id,
112987 /* USB is special because the bcdDevice can be matched against a numeric range */
112988 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
112989 static void do_usb_entry(void *symval,
112990 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
112991 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
112992 unsigned char range_lo, unsigned char range_hi,
112993 unsigned char max, struct module *mod)
112994 {
112995 @@ -281,7 +281,7 @@ static void do_usb_entry_multi(void *symval, struct module *mod)
112996 {
112997 unsigned int devlo, devhi;
112998 unsigned char chi, clo, max;
112999 - int ndigits;
113000 + unsigned int ndigits;
113001
113002 DEF_FIELD(symval, usb_device_id, match_flags);
113003 DEF_FIELD(symval, usb_device_id, idVendor);
113004 @@ -534,7 +534,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
113005 for (i = 0; i < count; i++) {
113006 DEF_FIELD_ADDR(symval + i*id_size, pnp_device_id, id);
113007 char acpi_id[sizeof(*id)];
113008 - int j;
113009 + unsigned int j;
113010
113011 buf_printf(&mod->dev_table_buf,
113012 "MODULE_ALIAS(\"pnp:d%s*\");\n", *id);
113013 @@ -563,7 +563,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
113014
113015 for (j = 0; j < PNP_MAX_DEVICES; j++) {
113016 const char *id = (char *)(*devs)[j].id;
113017 - int i2, j2;
113018 + unsigned int i2, j2;
113019 int dup = 0;
113020
113021 if (!id[0])
113022 @@ -589,7 +589,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
113023 /* add an individual alias for every device entry */
113024 if (!dup) {
113025 char acpi_id[PNP_ID_LEN];
113026 - int k;
113027 + unsigned int k;
113028
113029 buf_printf(&mod->dev_table_buf,
113030 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
113031 @@ -939,7 +939,7 @@ static void dmi_ascii_filter(char *d, const char *s)
113032 static int do_dmi_entry(const char *filename, void *symval,
113033 char *alias)
113034 {
113035 - int i, j;
113036 + unsigned int i, j;
113037 DEF_FIELD_ADDR(symval, dmi_system_id, matches);
113038 sprintf(alias, "dmi*");
113039
113040 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
113041 index 9d9c5b9..a3af177 100644
113042 --- a/scripts/mod/modpost.c
113043 +++ b/scripts/mod/modpost.c
113044 @@ -949,6 +949,7 @@ enum mismatch {
113045 ANY_INIT_TO_ANY_EXIT,
113046 ANY_EXIT_TO_ANY_INIT,
113047 EXPORT_TO_INIT_EXIT,
113048 + DATA_TO_TEXT
113049 };
113050
113051 struct sectioncheck {
113052 @@ -1035,6 +1036,12 @@ const struct sectioncheck sectioncheck[] = {
113053 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
113054 .mismatch = EXPORT_TO_INIT_EXIT,
113055 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
113056 +},
113057 +/* Do not reference code from writable data */
113058 +{
113059 + .fromsec = { DATA_SECTIONS, NULL },
113060 + .tosec = { TEXT_SECTIONS, NULL },
113061 + .mismatch = DATA_TO_TEXT
113062 }
113063 };
113064
113065 @@ -1155,10 +1162,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
113066 continue;
113067 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
113068 continue;
113069 - if (sym->st_value == addr)
113070 - return sym;
113071 /* Find a symbol nearby - addr are maybe negative */
113072 d = sym->st_value - addr;
113073 + if (d == 0)
113074 + return sym;
113075 if (d < 0)
113076 d = addr - sym->st_value;
113077 if (d < distance) {
113078 @@ -1436,6 +1443,14 @@ static void report_sec_mismatch(const char *modname,
113079 tosym, prl_to, prl_to, tosym);
113080 free(prl_to);
113081 break;
113082 + case DATA_TO_TEXT:
113083 +#if 0
113084 + fprintf(stderr,
113085 + "The %s %s:%s references\n"
113086 + "the %s %s:%s%s\n",
113087 + from, fromsec, fromsym, to, tosec, tosym, to_p);
113088 +#endif
113089 + break;
113090 }
113091 fprintf(stderr, "\n");
113092 }
113093 @@ -1687,7 +1702,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
113094 static void check_sec_ref(struct module *mod, const char *modname,
113095 struct elf_info *elf)
113096 {
113097 - int i;
113098 + unsigned int i;
113099 Elf_Shdr *sechdrs = elf->sechdrs;
113100
113101 /* Walk through all sections */
113102 @@ -1819,7 +1834,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
113103 va_end(ap);
113104 }
113105
113106 -void buf_write(struct buffer *buf, const char *s, int len)
113107 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
113108 {
113109 if (buf->size - buf->pos < len) {
113110 buf->size += len + SZ;
113111 @@ -2038,7 +2053,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
113112 if (fstat(fileno(file), &st) < 0)
113113 goto close_write;
113114
113115 - if (st.st_size != b->pos)
113116 + if (st.st_size != (off_t)b->pos)
113117 goto close_write;
113118
113119 tmp = NOFAIL(malloc(b->pos));
113120 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
113121 index 168b43d..77914bf 100644
113122 --- a/scripts/mod/modpost.h
113123 +++ b/scripts/mod/modpost.h
113124 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
113125
113126 struct buffer {
113127 char *p;
113128 - int pos;
113129 - int size;
113130 + unsigned int pos;
113131 + unsigned int size;
113132 };
113133
113134 void __attribute__((format(printf, 2, 3)))
113135 buf_printf(struct buffer *buf, const char *fmt, ...);
113136
113137 void
113138 -buf_write(struct buffer *buf, const char *s, int len);
113139 +buf_write(struct buffer *buf, const char *s, unsigned int len);
113140
113141 struct module {
113142 struct module *next;
113143 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
113144 index 944418d..15291e4 100644
113145 --- a/scripts/mod/sumversion.c
113146 +++ b/scripts/mod/sumversion.c
113147 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
113148 goto out;
113149 }
113150
113151 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
113152 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
113153 warn("writing sum in %s failed: %s\n",
113154 filename, strerror(errno));
113155 goto out;
113156 diff --git a/scripts/module-common.lds b/scripts/module-common.lds
113157 index 0865b3e..7235dd4 100644
113158 --- a/scripts/module-common.lds
113159 +++ b/scripts/module-common.lds
113160 @@ -6,6 +6,10 @@
113161 SECTIONS {
113162 /DISCARD/ : { *(.discard) }
113163
113164 + .rodata : {
113165 + *(.rodata) *(.rodata.*)
113166 + *(.data..read_only)
113167 + }
113168 __ksymtab : { *(SORT(___ksymtab+*)) }
113169 __ksymtab_gpl : { *(SORT(___ksymtab_gpl+*)) }
113170 __ksymtab_unused : { *(SORT(___ksymtab_unused+*)) }
113171 diff --git a/scripts/package/builddeb b/scripts/package/builddeb
113172 index 35d5a58..9e04789 100644
113173 --- a/scripts/package/builddeb
113174 +++ b/scripts/package/builddeb
113175 @@ -295,6 +295,7 @@ fi
113176 (cd $srctree; find arch/$SRCARCH -name module.lds -o -name Kbuild.platforms -o -name Platform) >> "$objtree/debian/hdrsrcfiles"
113177 (cd $srctree; find $(find arch/$SRCARCH -name include -o -name scripts -type d) -type f) >> "$objtree/debian/hdrsrcfiles"
113178 (cd $objtree; find arch/$SRCARCH/include Module.symvers include scripts -type f) >> "$objtree/debian/hdrobjfiles"
113179 +(cd $objtree; find tools/gcc -name \*.so >> "$objtree/debian/hdrobjfiles")
113180 destdir=$kernel_headers_dir/usr/src/linux-headers-$version
113181 mkdir -p "$destdir"
113182 (cd $srctree; tar -c -f - -T -) < "$objtree/debian/hdrsrcfiles" | (cd $destdir; tar -xf -)
113183 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
113184 index 4718d78..9220d58 100644
113185 --- a/scripts/pnmtologo.c
113186 +++ b/scripts/pnmtologo.c
113187 @@ -244,14 +244,14 @@ static void write_header(void)
113188 fprintf(out, " * Linux logo %s\n", logoname);
113189 fputs(" */\n\n", out);
113190 fputs("#include <linux/linux_logo.h>\n\n", out);
113191 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
113192 + fprintf(out, "static unsigned char %s_data[] = {\n",
113193 logoname);
113194 }
113195
113196 static void write_footer(void)
113197 {
113198 fputs("\n};\n\n", out);
113199 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
113200 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
113201 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
113202 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
113203 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
113204 @@ -381,7 +381,7 @@ static void write_logo_clut224(void)
113205 fputs("\n};\n\n", out);
113206
113207 /* write logo clut */
113208 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
113209 + fprintf(out, "static unsigned char %s_clut[] = {\n",
113210 logoname);
113211 write_hex_cnt = 0;
113212 for (i = 0; i < logo_clutsize; i++) {
113213 diff --git a/scripts/sortextable.h b/scripts/sortextable.h
113214 index 8fac3fd..32ff38d 100644
113215 --- a/scripts/sortextable.h
113216 +++ b/scripts/sortextable.h
113217 @@ -108,9 +108,9 @@ do_func(Elf_Ehdr *ehdr, char const *const fname, table_sort_t custom_sort)
113218 const char *secstrtab;
113219 const char *strtab;
113220 char *extab_image;
113221 - int extab_index = 0;
113222 - int i;
113223 - int idx;
113224 + unsigned int extab_index = 0;
113225 + unsigned int i;
113226 + unsigned int idx;
113227 unsigned int num_sections;
113228 unsigned int secindex_strings;
113229
113230 diff --git a/security/Kconfig b/security/Kconfig
113231 index beb86b5..40b1edb 100644
113232 --- a/security/Kconfig
113233 +++ b/security/Kconfig
113234 @@ -4,6 +4,957 @@
113235
113236 menu "Security options"
113237
113238 +menu "Grsecurity"
113239 +
113240 + config ARCH_TRACK_EXEC_LIMIT
113241 + bool
113242 +
113243 + config PAX_KERNEXEC_PLUGIN
113244 + bool
113245 +
113246 + config PAX_PER_CPU_PGD
113247 + bool
113248 +
113249 + config TASK_SIZE_MAX_SHIFT
113250 + int
113251 + depends on X86_64
113252 + default 47 if !PAX_PER_CPU_PGD
113253 + default 42 if PAX_PER_CPU_PGD
113254 +
113255 + config PAX_ENABLE_PAE
113256 + bool
113257 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
113258 +
113259 + config PAX_USERCOPY_SLABS
113260 + bool
113261 +
113262 +config GRKERNSEC
113263 + bool "Grsecurity"
113264 + select CRYPTO
113265 + select CRYPTO_SHA256
113266 + select PROC_FS
113267 + select STOP_MACHINE
113268 + select TTY
113269 + select DEBUG_KERNEL
113270 + select DEBUG_LIST
113271 + help
113272 + If you say Y here, you will be able to configure many features
113273 + that will enhance the security of your system. It is highly
113274 + recommended that you say Y here and read through the help
113275 + for each option so that you fully understand the features and
113276 + can evaluate their usefulness for your machine.
113277 +
113278 +choice
113279 + prompt "Configuration Method"
113280 + depends on GRKERNSEC
113281 + default GRKERNSEC_CONFIG_CUSTOM
113282 + help
113283 +
113284 +config GRKERNSEC_CONFIG_AUTO
113285 + bool "Automatic"
113286 + help
113287 + If you choose this configuration method, you'll be able to answer a small
113288 + number of simple questions about how you plan to use this kernel.
113289 + The settings of grsecurity and PaX will be automatically configured for
113290 + the highest commonly-used settings within the provided constraints.
113291 +
113292 + If you require additional configuration, custom changes can still be made
113293 + from the "custom configuration" menu.
113294 +
113295 +config GRKERNSEC_CONFIG_CUSTOM
113296 + bool "Custom"
113297 + help
113298 + If you choose this configuration method, you'll be able to configure all
113299 + grsecurity and PaX settings manually. Via this method, no options are
113300 + automatically enabled.
113301 +
113302 +endchoice
113303 +
113304 +choice
113305 + prompt "Usage Type"
113306 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
113307 + default GRKERNSEC_CONFIG_SERVER
113308 + help
113309 +
113310 +config GRKERNSEC_CONFIG_SERVER
113311 + bool "Server"
113312 + help
113313 + Choose this option if you plan to use this kernel on a server.
113314 +
113315 +config GRKERNSEC_CONFIG_DESKTOP
113316 + bool "Desktop"
113317 + help
113318 + Choose this option if you plan to use this kernel on a desktop.
113319 +
113320 +endchoice
113321 +
113322 +choice
113323 + prompt "Virtualization Type"
113324 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
113325 + default GRKERNSEC_CONFIG_VIRT_NONE
113326 + help
113327 +
113328 +config GRKERNSEC_CONFIG_VIRT_NONE
113329 + bool "None"
113330 + help
113331 + Choose this option if this kernel will be run on bare metal.
113332 +
113333 +config GRKERNSEC_CONFIG_VIRT_GUEST
113334 + bool "Guest"
113335 + help
113336 + Choose this option if this kernel will be run as a VM guest.
113337 +
113338 +config GRKERNSEC_CONFIG_VIRT_HOST
113339 + bool "Host"
113340 + help
113341 + Choose this option if this kernel will be run as a VM host.
113342 +
113343 +endchoice
113344 +
113345 +choice
113346 + prompt "Virtualization Hardware"
113347 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
113348 + help
113349 +
113350 +config GRKERNSEC_CONFIG_VIRT_EPT
113351 + bool "EPT/RVI Processor Support"
113352 + depends on X86
113353 + help
113354 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
113355 + hardware virtualization. This allows for additional kernel hardening protections
113356 + to operate without additional performance impact.
113357 +
113358 + To see if your Intel processor supports EPT, see:
113359 + http://ark.intel.com/Products/VirtualizationTechnology
113360 + (Most Core i3/5/7 support EPT)
113361 +
113362 + To see if your AMD processor supports RVI, see:
113363 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
113364 +
113365 +config GRKERNSEC_CONFIG_VIRT_SOFT
113366 + bool "First-gen/No Hardware Virtualization"
113367 + help
113368 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
113369 + support hardware virtualization or doesn't support the EPT/RVI extensions.
113370 +
113371 +endchoice
113372 +
113373 +choice
113374 + prompt "Virtualization Software"
113375 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
113376 + help
113377 +
113378 +config GRKERNSEC_CONFIG_VIRT_XEN
113379 + bool "Xen"
113380 + help
113381 + Choose this option if this kernel is running as a Xen guest or host.
113382 +
113383 +config GRKERNSEC_CONFIG_VIRT_VMWARE
113384 + bool "VMWare"
113385 + help
113386 + Choose this option if this kernel is running as a VMWare guest or host.
113387 +
113388 +config GRKERNSEC_CONFIG_VIRT_KVM
113389 + bool "KVM"
113390 + help
113391 + Choose this option if this kernel is running as a KVM guest or host.
113392 +
113393 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
113394 + bool "VirtualBox"
113395 + help
113396 + Choose this option if this kernel is running as a VirtualBox guest or host.
113397 +
113398 +endchoice
113399 +
113400 +choice
113401 + prompt "Required Priorities"
113402 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
113403 + default GRKERNSEC_CONFIG_PRIORITY_PERF
113404 + help
113405 +
113406 +config GRKERNSEC_CONFIG_PRIORITY_PERF
113407 + bool "Performance"
113408 + help
113409 + Choose this option if performance is of highest priority for this deployment
113410 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
113411 + clearing of structures intended for userland, and freed memory sanitizing will
113412 + be disabled.
113413 +
113414 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
113415 + bool "Security"
113416 + help
113417 + Choose this option if security is of highest priority for this deployment of
113418 + grsecurity. UDEREF, kernel stack clearing, clearing of structures intended
113419 + for userland, and freed memory sanitizing will be enabled for this kernel.
113420 + In a worst-case scenario, these features can introduce a 20% performance hit
113421 + (UDEREF on x64 contributing half of this hit).
113422 +
113423 +endchoice
113424 +
113425 +menu "Default Special Groups"
113426 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
113427 +
113428 +config GRKERNSEC_PROC_GID
113429 + int "GID exempted from /proc restrictions"
113430 + default 1001
113431 + help
113432 + Setting this GID determines which group will be exempted from
113433 + grsecurity's /proc restrictions, allowing users of the specified
113434 + group to view network statistics and the existence of other users'
113435 + processes on the system. This GID may also be chosen at boot time
113436 + via "grsec_proc_gid=" on the kernel commandline.
113437 +
113438 +config GRKERNSEC_TPE_UNTRUSTED_GID
113439 + int "GID for TPE-untrusted users"
113440 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
113441 + default 1005
113442 + help
113443 + Setting this GID determines which group untrusted users should
113444 + be added to. These users will be placed under grsecurity's Trusted Path
113445 + Execution mechanism, preventing them from executing their own binaries.
113446 + The users will only be able to execute binaries in directories owned and
113447 + writable only by the root user. If the sysctl option is enabled, a sysctl
113448 + option with name "tpe_gid" is created.
113449 +
113450 +config GRKERNSEC_TPE_TRUSTED_GID
113451 + int "GID for TPE-trusted users"
113452 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
113453 + default 1005
113454 + help
113455 + Setting this GID determines what group TPE restrictions will be
113456 + *disabled* for. If the sysctl option is enabled, a sysctl option
113457 + with name "tpe_gid" is created.
113458 +
113459 +config GRKERNSEC_SYMLINKOWN_GID
113460 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
113461 + depends on GRKERNSEC_CONFIG_SERVER
113462 + default 1006
113463 + help
113464 + Setting this GID determines what group kernel-enforced
113465 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
113466 + is enabled, a sysctl option with name "symlinkown_gid" is created.
113467 +
113468 +
113469 +endmenu
113470 +
113471 +menu "Customize Configuration"
113472 +depends on GRKERNSEC
113473 +
113474 +menu "PaX"
113475 +
113476 +config PAX
113477 + bool "Enable various PaX features"
113478 + default y if GRKERNSEC_CONFIG_AUTO
113479 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
113480 + help
113481 + This allows you to enable various PaX features. PaX adds
113482 + intrusion prevention mechanisms to the kernel that reduce
113483 + the risks posed by exploitable memory corruption bugs.
113484 +
113485 +menu "PaX Control"
113486 + depends on PAX
113487 +
113488 +config PAX_SOFTMODE
113489 + bool 'Support soft mode'
113490 + help
113491 + Enabling this option will allow you to run PaX in soft mode, that
113492 + is, PaX features will not be enforced by default, only on executables
113493 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
113494 + support as they are the only way to mark executables for soft mode use.
113495 +
113496 + Soft mode can be activated by using the "pax_softmode=1" kernel command
113497 + line option on boot. Furthermore you can control various PaX features
113498 + at runtime via the entries in /proc/sys/kernel/pax.
113499 +
113500 +config PAX_EI_PAX
113501 + bool 'Use legacy ELF header marking'
113502 + default y if GRKERNSEC_CONFIG_AUTO
113503 + help
113504 + Enabling this option will allow you to control PaX features on
113505 + a per executable basis via the 'chpax' utility available at
113506 + http://pax.grsecurity.net/. The control flags will be read from
113507 + an otherwise reserved part of the ELF header. This marking has
113508 + numerous drawbacks (no support for soft-mode, toolchain does not
113509 + know about the non-standard use of the ELF header) therefore it
113510 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
113511 + support.
113512 +
113513 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
113514 + support as well, they will override the legacy EI_PAX marks.
113515 +
113516 + If you enable none of the marking options then all applications
113517 + will run with PaX enabled on them by default.
113518 +
113519 +config PAX_PT_PAX_FLAGS
113520 + bool 'Use ELF program header marking'
113521 + default y if GRKERNSEC_CONFIG_AUTO
113522 + help
113523 + Enabling this option will allow you to control PaX features on
113524 + a per executable basis via the 'paxctl' utility available at
113525 + http://pax.grsecurity.net/. The control flags will be read from
113526 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
113527 + has the benefits of supporting both soft mode and being fully
113528 + integrated into the toolchain (the binutils patch is available
113529 + from http://pax.grsecurity.net).
113530 +
113531 + Note that if you enable the legacy EI_PAX marking support as well,
113532 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
113533 +
113534 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
113535 + must make sure that the marks are the same if a binary has both marks.
113536 +
113537 + If you enable none of the marking options then all applications
113538 + will run with PaX enabled on them by default.
113539 +
113540 +config PAX_XATTR_PAX_FLAGS
113541 + bool 'Use filesystem extended attributes marking'
113542 + default y if GRKERNSEC_CONFIG_AUTO
113543 + select CIFS_XATTR if CIFS
113544 + select F2FS_FS_XATTR if F2FS_FS
113545 + select EXT2_FS_XATTR if EXT2_FS
113546 + select EXT3_FS_XATTR if EXT3_FS
113547 + select JFFS2_FS_XATTR if JFFS2_FS
113548 + select REISERFS_FS_XATTR if REISERFS_FS
113549 + select SQUASHFS_XATTR if SQUASHFS
113550 + select TMPFS_XATTR if TMPFS
113551 + help
113552 + Enabling this option will allow you to control PaX features on
113553 + a per executable basis via the 'setfattr' utility. The control
113554 + flags will be read from the user.pax.flags extended attribute of
113555 + the file. This marking has the benefit of supporting binary-only
113556 + applications that self-check themselves (e.g., skype) and would
113557 + not tolerate chpax/paxctl changes. The main drawback is that
113558 + extended attributes are not supported by some filesystems (e.g.,
113559 + isofs, udf, vfat) so copying files through such filesystems will
113560 + lose the extended attributes and these PaX markings.
113561 +
113562 + Note that if you enable the legacy EI_PAX marking support as well,
113563 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
113564 +
113565 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
113566 + must make sure that the marks are the same if a binary has both marks.
113567 +
113568 + If you enable none of the marking options then all applications
113569 + will run with PaX enabled on them by default.
113570 +
113571 +choice
113572 + prompt 'MAC system integration'
113573 + default PAX_HAVE_ACL_FLAGS
113574 + help
113575 + Mandatory Access Control systems have the option of controlling
113576 + PaX flags on a per executable basis, choose the method supported
113577 + by your particular system.
113578 +
113579 + - "none": if your MAC system does not interact with PaX,
113580 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
113581 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
113582 +
113583 + NOTE: this option is for developers/integrators only.
113584 +
113585 + config PAX_NO_ACL_FLAGS
113586 + bool 'none'
113587 +
113588 + config PAX_HAVE_ACL_FLAGS
113589 + bool 'direct'
113590 +
113591 + config PAX_HOOK_ACL_FLAGS
113592 + bool 'hook'
113593 +endchoice
113594 +
113595 +endmenu
113596 +
113597 +menu "Non-executable pages"
113598 + depends on PAX
113599 +
113600 +config PAX_NOEXEC
113601 + bool "Enforce non-executable pages"
113602 + default y if GRKERNSEC_CONFIG_AUTO
113603 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V6K || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
113604 + help
113605 + By design some architectures do not allow for protecting memory
113606 + pages against execution or even if they do, Linux does not make
113607 + use of this feature. In practice this means that if a page is
113608 + readable (such as the stack or heap) it is also executable.
113609 +
113610 + There is a well known exploit technique that makes use of this
113611 + fact and a common programming mistake where an attacker can
113612 + introduce code of his choice somewhere in the attacked program's
113613 + memory (typically the stack or the heap) and then execute it.
113614 +
113615 + If the attacked program was running with different (typically
113616 + higher) privileges than that of the attacker, then he can elevate
113617 + his own privilege level (e.g. get a root shell, write to files for
113618 + which he does not have write access to, etc).
113619 +
113620 + Enabling this option will let you choose from various features
113621 + that prevent the injection and execution of 'foreign' code in
113622 + a program.
113623 +
113624 + This will also break programs that rely on the old behaviour and
113625 + expect that dynamically allocated memory via the malloc() family
113626 + of functions is executable (which it is not). Notable examples
113627 + are the XFree86 4.x server, the java runtime and wine.
113628 +
113629 +config PAX_PAGEEXEC
113630 + bool "Paging based non-executable pages"
113631 + default y if GRKERNSEC_CONFIG_AUTO
113632 + 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)
113633 + select ARCH_TRACK_EXEC_LIMIT if X86_32
113634 + help
113635 + This implementation is based on the paging feature of the CPU.
113636 + On i386 without hardware non-executable bit support there is a
113637 + variable but usually low performance impact, however on Intel's
113638 + P4 core based CPUs it is very high so you should not enable this
113639 + for kernels meant to be used on such CPUs.
113640 +
113641 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
113642 + with hardware non-executable bit support there is no performance
113643 + impact, on ppc the impact is negligible.
113644 +
113645 + Note that several architectures require various emulations due to
113646 + badly designed userland ABIs, this will cause a performance impact
113647 + but will disappear as soon as userland is fixed. For example, ppc
113648 + userland MUST have been built with secure-plt by a recent toolchain.
113649 +
113650 +config PAX_SEGMEXEC
113651 + bool "Segmentation based non-executable pages"
113652 + default y if GRKERNSEC_CONFIG_AUTO
113653 + depends on PAX_NOEXEC && X86_32
113654 + help
113655 + This implementation is based on the segmentation feature of the
113656 + CPU and has a very small performance impact, however applications
113657 + will be limited to a 1.5 GB address space instead of the normal
113658 + 3 GB.
113659 +
113660 +config PAX_EMUTRAMP
113661 + bool "Emulate trampolines"
113662 + default y if PARISC || GRKERNSEC_CONFIG_AUTO
113663 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
113664 + help
113665 + There are some programs and libraries that for one reason or
113666 + another attempt to execute special small code snippets from
113667 + non-executable memory pages. Most notable examples are the
113668 + signal handler return code generated by the kernel itself and
113669 + the GCC trampolines.
113670 +
113671 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
113672 + such programs will no longer work under your kernel.
113673 +
113674 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
113675 + utilities to enable trampoline emulation for the affected programs
113676 + yet still have the protection provided by the non-executable pages.
113677 +
113678 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
113679 + your system will not even boot.
113680 +
113681 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
113682 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
113683 + for the affected files.
113684 +
113685 + NOTE: enabling this feature *may* open up a loophole in the
113686 + protection provided by non-executable pages that an attacker
113687 + could abuse. Therefore the best solution is to not have any
113688 + files on your system that would require this option. This can
113689 + be achieved by not using libc5 (which relies on the kernel
113690 + signal handler return code) and not using or rewriting programs
113691 + that make use of the nested function implementation of GCC.
113692 + Skilled users can just fix GCC itself so that it implements
113693 + nested function calls in a way that does not interfere with PaX.
113694 +
113695 +config PAX_EMUSIGRT
113696 + bool "Automatically emulate sigreturn trampolines"
113697 + depends on PAX_EMUTRAMP && PARISC
113698 + default y
113699 + help
113700 + Enabling this option will have the kernel automatically detect
113701 + and emulate signal return trampolines executing on the stack
113702 + that would otherwise lead to task termination.
113703 +
113704 + This solution is intended as a temporary one for users with
113705 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
113706 + Modula-3 runtime, etc) or executables linked to such, basically
113707 + everything that does not specify its own SA_RESTORER function in
113708 + normal executable memory like glibc 2.1+ does.
113709 +
113710 + On parisc you MUST enable this option, otherwise your system will
113711 + not even boot.
113712 +
113713 + NOTE: this feature cannot be disabled on a per executable basis
113714 + and since it *does* open up a loophole in the protection provided
113715 + by non-executable pages, the best solution is to not have any
113716 + files on your system that would require this option.
113717 +
113718 +config PAX_MPROTECT
113719 + bool "Restrict mprotect()"
113720 + default y if GRKERNSEC_CONFIG_AUTO
113721 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
113722 + help
113723 + Enabling this option will prevent programs from
113724 + - changing the executable status of memory pages that were
113725 + not originally created as executable,
113726 + - making read-only executable pages writable again,
113727 + - creating executable pages from anonymous memory,
113728 + - making read-only-after-relocations (RELRO) data pages writable again.
113729 +
113730 + You should say Y here to complete the protection provided by
113731 + the enforcement of non-executable pages.
113732 +
113733 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
113734 + this feature on a per file basis.
113735 +
113736 +config PAX_MPROTECT_COMPAT
113737 + bool "Use legacy/compat protection demoting (read help)"
113738 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
113739 + depends on PAX_MPROTECT
113740 + help
113741 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
113742 + by sending the proper error code to the application. For some broken
113743 + userland, this can cause problems with Python or other applications. The
113744 + current implementation however allows for applications like clamav to
113745 + detect if JIT compilation/execution is allowed and to fall back gracefully
113746 + to an interpreter-based mode if it does not. While we encourage everyone
113747 + to use the current implementation as-is and push upstream to fix broken
113748 + userland (note that the RWX logging option can assist with this), in some
113749 + environments this may not be possible. Having to disable MPROTECT
113750 + completely on certain binaries reduces the security benefit of PaX,
113751 + so this option is provided for those environments to revert to the old
113752 + behavior.
113753 +
113754 +config PAX_ELFRELOCS
113755 + bool "Allow ELF text relocations (read help)"
113756 + depends on PAX_MPROTECT
113757 + default n
113758 + help
113759 + Non-executable pages and mprotect() restrictions are effective
113760 + in preventing the introduction of new executable code into an
113761 + attacked task's address space. There remain only two venues
113762 + for this kind of attack: if the attacker can execute already
113763 + existing code in the attacked task then he can either have it
113764 + create and mmap() a file containing his code or have it mmap()
113765 + an already existing ELF library that does not have position
113766 + independent code in it and use mprotect() on it to make it
113767 + writable and copy his code there. While protecting against
113768 + the former approach is beyond PaX, the latter can be prevented
113769 + by having only PIC ELF libraries on one's system (which do not
113770 + need to relocate their code). If you are sure this is your case,
113771 + as is the case with all modern Linux distributions, then leave
113772 + this option disabled. You should say 'n' here.
113773 +
113774 +config PAX_ETEXECRELOCS
113775 + bool "Allow ELF ET_EXEC text relocations"
113776 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
113777 + select PAX_ELFRELOCS
113778 + default y
113779 + help
113780 + On some architectures there are incorrectly created applications
113781 + that require text relocations and would not work without enabling
113782 + this option. If you are an alpha, ia64 or parisc user, you should
113783 + enable this option and disable it once you have made sure that
113784 + none of your applications need it.
113785 +
113786 +config PAX_EMUPLT
113787 + bool "Automatically emulate ELF PLT"
113788 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
113789 + default y
113790 + help
113791 + Enabling this option will have the kernel automatically detect
113792 + and emulate the Procedure Linkage Table entries in ELF files.
113793 + On some architectures such entries are in writable memory, and
113794 + become non-executable leading to task termination. Therefore
113795 + it is mandatory that you enable this option on alpha, parisc,
113796 + sparc and sparc64, otherwise your system would not even boot.
113797 +
113798 + NOTE: this feature *does* open up a loophole in the protection
113799 + provided by the non-executable pages, therefore the proper
113800 + solution is to modify the toolchain to produce a PLT that does
113801 + not need to be writable.
113802 +
113803 +config PAX_DLRESOLVE
113804 + bool 'Emulate old glibc resolver stub'
113805 + depends on PAX_EMUPLT && SPARC
113806 + default n
113807 + help
113808 + This option is needed if userland has an old glibc (before 2.4)
113809 + that puts a 'save' instruction into the runtime generated resolver
113810 + stub that needs special emulation.
113811 +
113812 +config PAX_KERNEXEC
113813 + bool "Enforce non-executable kernel pages"
113814 + 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))
113815 + depends on (X86 || (ARM && (CPU_V6 || CPU_V6K || CPU_V7) && !(ARM_LPAE && MODULES))) && !XEN
113816 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
113817 + select PAX_KERNEXEC_PLUGIN if X86_64
113818 + help
113819 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
113820 + that is, enabling this option will make it harder to inject
113821 + and execute 'foreign' code in kernel memory itself.
113822 +
113823 +choice
113824 + prompt "Return Address Instrumentation Method"
113825 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
113826 + depends on PAX_KERNEXEC_PLUGIN
113827 + help
113828 + Select the method used to instrument function pointer dereferences.
113829 + Note that binary modules cannot be instrumented by this approach.
113830 +
113831 + Note that the implementation requires a gcc with plugin support,
113832 + i.e., gcc 4.5 or newer. You may need to install the supporting
113833 + headers explicitly in addition to the normal gcc package.
113834 +
113835 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
113836 + bool "bts"
113837 + help
113838 + This method is compatible with binary only modules but has
113839 + a higher runtime overhead.
113840 +
113841 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
113842 + bool "or"
113843 + depends on !PARAVIRT
113844 + help
113845 + This method is incompatible with binary only modules but has
113846 + a lower runtime overhead.
113847 +endchoice
113848 +
113849 +config PAX_KERNEXEC_PLUGIN_METHOD
113850 + string
113851 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
113852 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
113853 + default ""
113854 +
113855 +config PAX_KERNEXEC_MODULE_TEXT
113856 + int "Minimum amount of memory reserved for module code"
113857 + default "4" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
113858 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
113859 + depends on PAX_KERNEXEC && X86_32
113860 + help
113861 + Due to implementation details the kernel must reserve a fixed
113862 + amount of memory for runtime allocated code (such as modules)
113863 + at compile time that cannot be changed at runtime. Here you
113864 + can specify the minimum amount in MB that will be reserved.
113865 + Due to the same implementation details this size will always
113866 + be rounded up to the next 2/4 MB boundary (depends on PAE) so
113867 + the actually available memory for runtime allocated code will
113868 + usually be more than this minimum.
113869 +
113870 + The default 4 MB should be enough for most users but if you have
113871 + an excessive number of modules (e.g., most distribution configs
113872 + compile many drivers as modules) or use huge modules such as
113873 + nvidia's kernel driver, you will need to adjust this amount.
113874 + A good rule of thumb is to look at your currently loaded kernel
113875 + modules and add up their sizes.
113876 +
113877 +endmenu
113878 +
113879 +menu "Address Space Layout Randomization"
113880 + depends on PAX
113881 +
113882 +config PAX_ASLR
113883 + bool "Address Space Layout Randomization"
113884 + default y if GRKERNSEC_CONFIG_AUTO
113885 + help
113886 + Many if not most exploit techniques rely on the knowledge of
113887 + certain addresses in the attacked program. The following options
113888 + will allow the kernel to apply a certain amount of randomization
113889 + to specific parts of the program thereby forcing an attacker to
113890 + guess them in most cases. Any failed guess will most likely crash
113891 + the attacked program which allows the kernel to detect such attempts
113892 + and react on them. PaX itself provides no reaction mechanisms,
113893 + instead it is strongly encouraged that you make use of grsecurity's
113894 + (http://www.grsecurity.net/) built-in crash detection features or
113895 + develop one yourself.
113896 +
113897 + By saying Y here you can choose to randomize the following areas:
113898 + - top of the task's kernel stack
113899 + - top of the task's userland stack
113900 + - base address for mmap() requests that do not specify one
113901 + (this includes all libraries)
113902 + - base address of the main executable
113903 +
113904 + It is strongly recommended to say Y here as address space layout
113905 + randomization has negligible impact on performance yet it provides
113906 + a very effective protection.
113907 +
113908 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
113909 + this feature on a per file basis.
113910 +
113911 +config PAX_RANDKSTACK
113912 + bool "Randomize kernel stack base"
113913 + default y if GRKERNSEC_CONFIG_AUTO && !(GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_VIRTUALBOX)
113914 + depends on X86_TSC && X86
113915 + help
113916 + By saying Y here the kernel will randomize every task's kernel
113917 + stack on every system call. This will not only force an attacker
113918 + to guess it but also prevent him from making use of possible
113919 + leaked information about it.
113920 +
113921 + Since the kernel stack is a rather scarce resource, randomization
113922 + may cause unexpected stack overflows, therefore you should very
113923 + carefully test your system. Note that once enabled in the kernel
113924 + configuration, this feature cannot be disabled on a per file basis.
113925 +
113926 +config PAX_RANDUSTACK
113927 + bool
113928 +
113929 +config PAX_RANDMMAP
113930 + bool "Randomize user stack and mmap() bases"
113931 + default y if GRKERNSEC_CONFIG_AUTO
113932 + depends on PAX_ASLR
113933 + select PAX_RANDUSTACK
113934 + help
113935 + By saying Y here the kernel will randomize every task's userland
113936 + stack and use a randomized base address for mmap() requests that
113937 + do not specify one themselves.
113938 +
113939 + The stack randomization is done in two steps where the second
113940 + one may apply a big amount of shift to the top of the stack and
113941 + cause problems for programs that want to use lots of memory (more
113942 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
113943 +
113944 + As a result of mmap randomization all dynamically loaded libraries
113945 + will appear at random addresses and therefore be harder to exploit
113946 + by a technique where an attacker attempts to execute library code
113947 + for his purposes (e.g. spawn a shell from an exploited program that
113948 + is running at an elevated privilege level).
113949 +
113950 + Furthermore, if a program is relinked as a dynamic ELF file, its
113951 + base address will be randomized as well, completing the full
113952 + randomization of the address space layout. Attacking such programs
113953 + becomes a guess game. You can find an example of doing this at
113954 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
113955 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
113956 +
113957 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
113958 + feature on a per file basis.
113959 +
113960 +endmenu
113961 +
113962 +menu "Miscellaneous hardening features"
113963 +
113964 +config PAX_MEMORY_SANITIZE
113965 + bool "Sanitize all freed memory"
113966 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
113967 + help
113968 + By saying Y here the kernel will erase memory pages and slab objects
113969 + as soon as they are freed. This in turn reduces the lifetime of data
113970 + stored in them, making it less likely that sensitive information such
113971 + as passwords, cryptographic secrets, etc stay in memory for too long.
113972 +
113973 + This is especially useful for programs whose runtime is short, long
113974 + lived processes and the kernel itself benefit from this as long as
113975 + they ensure timely freeing of memory that may hold sensitive
113976 + information.
113977 +
113978 + A nice side effect of the sanitization of slab objects is the
113979 + reduction of possible info leaks caused by padding bytes within the
113980 + leaky structures. Use-after-free bugs for structures containing
113981 + pointers can also be detected as dereferencing the sanitized pointer
113982 + will generate an access violation.
113983 +
113984 + The tradeoff is performance impact, on a single CPU system kernel
113985 + compilation sees a 3% slowdown, other systems and workloads may vary
113986 + and you are advised to test this feature on your expected workload
113987 + before deploying it.
113988 +
113989 + To reduce the performance penalty by sanitizing pages only, albeit
113990 + limiting the effectiveness of this feature at the same time, slab
113991 + sanitization can be disabled with the kernel commandline parameter
113992 + "pax_sanitize_slab=0".
113993 +
113994 + Note that this feature does not protect data stored in live pages,
113995 + e.g., process memory swapped to disk may stay there for a long time.
113996 +
113997 +config PAX_MEMORY_STACKLEAK
113998 + bool "Sanitize kernel stack"
113999 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
114000 + depends on X86
114001 + help
114002 + By saying Y here the kernel will erase the kernel stack before it
114003 + returns from a system call. This in turn reduces the information
114004 + that a kernel stack leak bug can reveal.
114005 +
114006 + Note that such a bug can still leak information that was put on
114007 + the stack by the current system call (the one eventually triggering
114008 + the bug) but traces of earlier system calls on the kernel stack
114009 + cannot leak anymore.
114010 +
114011 + The tradeoff is performance impact: on a single CPU system kernel
114012 + compilation sees a 1% slowdown, other systems and workloads may vary
114013 + and you are advised to test this feature on your expected workload
114014 + before deploying it.
114015 +
114016 + Note that the full feature requires a gcc with plugin support,
114017 + i.e., gcc 4.5 or newer. You may need to install the supporting
114018 + headers explicitly in addition to the normal gcc package. Using
114019 + older gcc versions means that functions with large enough stack
114020 + frames may leave uninitialized memory behind that may be exposed
114021 + to a later syscall leaking the stack.
114022 +
114023 +config PAX_MEMORY_STRUCTLEAK
114024 + bool "Forcibly initialize local variables copied to userland"
114025 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
114026 + help
114027 + By saying Y here the kernel will zero initialize some local
114028 + variables that are going to be copied to userland. This in
114029 + turn prevents unintended information leakage from the kernel
114030 + stack should later code forget to explicitly set all parts of
114031 + the copied variable.
114032 +
114033 + The tradeoff is less performance impact than PAX_MEMORY_STACKLEAK
114034 + at a much smaller coverage.
114035 +
114036 + Note that the implementation requires a gcc with plugin support,
114037 + i.e., gcc 4.5 or newer. You may need to install the supporting
114038 + headers explicitly in addition to the normal gcc package.
114039 +
114040 +config PAX_MEMORY_UDEREF
114041 + bool "Prevent invalid userland pointer dereference"
114042 + default y if GRKERNSEC_CONFIG_AUTO && !(X86_64 && GRKERNSEC_CONFIG_PRIORITY_PERF) && (!X86 || GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
114043 + depends on (X86 || (ARM && (CPU_V6 || CPU_V6K || CPU_V7) && !ARM_LPAE)) && !UML_X86 && !XEN
114044 + select PAX_PER_CPU_PGD if X86_64
114045 + help
114046 + By saying Y here the kernel will be prevented from dereferencing
114047 + userland pointers in contexts where the kernel expects only kernel
114048 + pointers. This is both a useful runtime debugging feature and a
114049 + security measure that prevents exploiting a class of kernel bugs.
114050 +
114051 + The tradeoff is that some virtualization solutions may experience
114052 + a huge slowdown and therefore you should not enable this feature
114053 + for kernels meant to run in such environments. Whether a given VM
114054 + solution is affected or not is best determined by simply trying it
114055 + out, the performance impact will be obvious right on boot as this
114056 + mechanism engages from very early on. A good rule of thumb is that
114057 + VMs running on CPUs without hardware virtualization support (i.e.,
114058 + the majority of IA-32 CPUs) will likely experience the slowdown.
114059 +
114060 + On X86_64 the kernel will make use of PCID support when available
114061 + (Intel's Westmere, Sandy Bridge, etc) for better security (default)
114062 + or performance impact. Pass pax_weakuderef on the kernel command
114063 + line to choose the latter.
114064 +
114065 +config PAX_REFCOUNT
114066 + bool "Prevent various kernel object reference counter overflows"
114067 + default y if GRKERNSEC_CONFIG_AUTO
114068 + depends on GRKERNSEC && ((ARM && (CPU_V6 || CPU_V6K || CPU_V7)) || MIPS || SPARC64 || X86)
114069 + help
114070 + By saying Y here the kernel will detect and prevent overflowing
114071 + various (but not all) kinds of object reference counters. Such
114072 + overflows can normally occur due to bugs only and are often, if
114073 + not always, exploitable.
114074 +
114075 + The tradeoff is that data structures protected by an overflowed
114076 + refcount will never be freed and therefore will leak memory. Note
114077 + that this leak also happens even without this protection but in
114078 + that case the overflow can eventually trigger the freeing of the
114079 + data structure while it is still being used elsewhere, resulting
114080 + in the exploitable situation that this feature prevents.
114081 +
114082 + Since this has a negligible performance impact, you should enable
114083 + this feature.
114084 +
114085 +config PAX_CONSTIFY_PLUGIN
114086 + bool "Automatically constify eligible structures"
114087 + default y
114088 + depends on !UML && PAX_KERNEXEC
114089 + help
114090 + By saying Y here the compiler will automatically constify a class
114091 + of types that contain only function pointers. This reduces the
114092 + kernel's attack surface and also produces a better memory layout.
114093 +
114094 + Note that the implementation requires a gcc with plugin support,
114095 + i.e., gcc 4.5 or newer. You may need to install the supporting
114096 + headers explicitly in addition to the normal gcc package.
114097 +
114098 + Note that if some code really has to modify constified variables
114099 + then the source code will have to be patched to allow it. Examples
114100 + can be found in PaX itself (the no_const attribute) and for some
114101 + out-of-tree modules at http://www.grsecurity.net/~paxguy1/ .
114102 +
114103 +config PAX_USERCOPY
114104 + bool "Harden heap object copies between kernel and userland"
114105 + default y if GRKERNSEC_CONFIG_AUTO
114106 + depends on ARM || IA64 || PPC || SPARC || X86
114107 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
114108 + select PAX_USERCOPY_SLABS
114109 + help
114110 + By saying Y here the kernel will enforce the size of heap objects
114111 + when they are copied in either direction between the kernel and
114112 + userland, even if only a part of the heap object is copied.
114113 +
114114 + Specifically, this checking prevents information leaking from the
114115 + kernel heap during kernel to userland copies (if the kernel heap
114116 + object is otherwise fully initialized) and prevents kernel heap
114117 + overflows during userland to kernel copies.
114118 +
114119 + Note that the current implementation provides the strictest bounds
114120 + checks for the SLUB allocator.
114121 +
114122 + Enabling this option also enables per-slab cache protection against
114123 + data in a given cache being copied into/out of via userland
114124 + accessors. Though the whitelist of regions will be reduced over
114125 + time, it notably protects important data structures like task structs.
114126 +
114127 + If frame pointers are enabled on x86, this option will also restrict
114128 + copies into and out of the kernel stack to local variables within a
114129 + single frame.
114130 +
114131 + Since this has a negligible performance impact, you should enable
114132 + this feature.
114133 +
114134 +config PAX_USERCOPY_DEBUG
114135 + bool
114136 + depends on X86 && PAX_USERCOPY
114137 + default n
114138 +
114139 +config PAX_SIZE_OVERFLOW
114140 + bool "Prevent various integer overflows in function size parameters"
114141 + default y if GRKERNSEC_CONFIG_AUTO
114142 + depends on X86
114143 + help
114144 + By saying Y here the kernel recomputes expressions of function
114145 + arguments marked by a size_overflow attribute with double integer
114146 + precision (DImode/TImode for 32/64 bit integer types).
114147 +
114148 + The recomputed argument is checked against TYPE_MAX and an event
114149 + is logged on overflow and the triggering process is killed.
114150 +
114151 + Homepage: http://www.grsecurity.net/~ephox/overflow_plugin/
114152 +
114153 + Note that the implementation requires a gcc with plugin support,
114154 + i.e., gcc 4.5 or newer. You may need to install the supporting
114155 + headers explicitly in addition to the normal gcc package.
114156 +
114157 +config PAX_LATENT_ENTROPY
114158 + bool "Generate some entropy during boot and runtime"
114159 + default y if GRKERNSEC_CONFIG_AUTO
114160 + help
114161 + By saying Y here the kernel will instrument some kernel code to
114162 + extract some entropy from both original and artificially created
114163 + program state. This will help especially embedded systems where
114164 + there is little 'natural' source of entropy normally. The cost
114165 + is some slowdown of the boot process and fork and irq processing.
114166 +
114167 + When pax_extra_latent_entropy is passed on the kernel command line,
114168 + entropy will be extracted from up to the first 4GB of RAM while the
114169 + runtime memory allocator is being initialized. This costs even more
114170 + slowdown of the boot process.
114171 +
114172 + Note that the implementation requires a gcc with plugin support,
114173 + i.e., gcc 4.5 or newer. You may need to install the supporting
114174 + headers explicitly in addition to the normal gcc package.
114175 +
114176 + Note that entropy extracted this way is not cryptographically
114177 + secure!
114178 +
114179 +endmenu
114180 +
114181 +endmenu
114182 +
114183 +source grsecurity/Kconfig
114184 +
114185 +endmenu
114186 +
114187 +endmenu
114188 +
114189 source security/keys/Kconfig
114190
114191 config SECURITY_DMESG_RESTRICT
114192 @@ -103,7 +1054,7 @@ config INTEL_TXT
114193 config LSM_MMAP_MIN_ADDR
114194 int "Low address space for LSM to protect from user allocation"
114195 depends on SECURITY && SECURITY_SELINUX
114196 - default 32768 if ARM || (ARM64 && COMPAT)
114197 + default 32768 if ALPHA || ARM || (ARM64 && COMPAT) || PARISC || SPARC32
114198 default 65536
114199 help
114200 This is the portion of low virtual memory which should be protected
114201 diff --git a/security/apparmor/file.c b/security/apparmor/file.c
114202 index fdaa50c..2761dcb 100644
114203 --- a/security/apparmor/file.c
114204 +++ b/security/apparmor/file.c
114205 @@ -348,8 +348,8 @@ static inline bool xindex_is_subset(u32 link, u32 target)
114206 int aa_path_link(struct aa_profile *profile, struct dentry *old_dentry,
114207 struct path *new_dir, struct dentry *new_dentry)
114208 {
114209 - struct path link = { new_dir->mnt, new_dentry };
114210 - struct path target = { new_dir->mnt, old_dentry };
114211 + struct path link = { .mnt = new_dir->mnt, .dentry = new_dentry };
114212 + struct path target = { .mnt = new_dir->mnt, .dentry = old_dentry };
114213 struct path_cond cond = {
114214 old_dentry->d_inode->i_uid,
114215 old_dentry->d_inode->i_mode
114216 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
114217 index 9981000..eb21356 100644
114218 --- a/security/apparmor/lsm.c
114219 +++ b/security/apparmor/lsm.c
114220 @@ -186,7 +186,7 @@ static int common_perm_dir_dentry(int op, struct path *dir,
114221 struct dentry *dentry, u32 mask,
114222 struct path_cond *cond)
114223 {
114224 - struct path path = { dir->mnt, dentry };
114225 + struct path path = { .mnt = dir->mnt, .dentry = dentry };
114226
114227 return common_perm(op, &path, mask, cond);
114228 }
114229 @@ -203,7 +203,7 @@ static int common_perm_dir_dentry(int op, struct path *dir,
114230 static int common_perm_mnt_dentry(int op, struct vfsmount *mnt,
114231 struct dentry *dentry, u32 mask)
114232 {
114233 - struct path path = { mnt, dentry };
114234 + struct path path = { .mnt = mnt, .dentry = dentry };
114235 struct path_cond cond = { dentry->d_inode->i_uid,
114236 dentry->d_inode->i_mode
114237 };
114238 @@ -325,8 +325,8 @@ static int apparmor_path_rename(struct path *old_dir, struct dentry *old_dentry,
114239
114240 profile = aa_current_profile();
114241 if (!unconfined(profile)) {
114242 - struct path old_path = { old_dir->mnt, old_dentry };
114243 - struct path new_path = { new_dir->mnt, new_dentry };
114244 + struct path old_path = { .mnt = old_dir->mnt, .dentry = old_dentry };
114245 + struct path new_path = { .mnt = new_dir->mnt, .dentry = new_dentry };
114246 struct path_cond cond = { old_dentry->d_inode->i_uid,
114247 old_dentry->d_inode->i_mode
114248 };
114249 @@ -615,7 +615,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
114250 return error;
114251 }
114252
114253 -static struct security_operations apparmor_ops = {
114254 +static struct security_operations apparmor_ops __read_only = {
114255 .name = "apparmor",
114256
114257 .ptrace_access_check = apparmor_ptrace_access_check,
114258 diff --git a/security/commoncap.c b/security/commoncap.c
114259 index b9d613e..f68305c 100644
114260 --- a/security/commoncap.c
114261 +++ b/security/commoncap.c
114262 @@ -424,6 +424,32 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
114263 return 0;
114264 }
114265
114266 +/* returns:
114267 + 1 for suid privilege
114268 + 2 for sgid privilege
114269 + 3 for fscap privilege
114270 +*/
114271 +int is_privileged_binary(const struct dentry *dentry)
114272 +{
114273 + struct cpu_vfs_cap_data capdata;
114274 + struct inode *inode = dentry->d_inode;
114275 +
114276 + if (!inode || S_ISDIR(inode->i_mode))
114277 + return 0;
114278 +
114279 + if (inode->i_mode & S_ISUID)
114280 + return 1;
114281 + if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
114282 + return 2;
114283 +
114284 + if (!get_vfs_caps_from_disk(dentry, &capdata)) {
114285 + if (!cap_isclear(capdata.inheritable) || !cap_isclear(capdata.permitted))
114286 + return 3;
114287 + }
114288 +
114289 + return 0;
114290 +}
114291 +
114292 /*
114293 * Attempt to get the on-exec apply capability sets for an executable file from
114294 * its xattrs and, if present, apply them to the proposed credentials being
114295 @@ -592,6 +618,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
114296 const struct cred *cred = current_cred();
114297 kuid_t root_uid = make_kuid(cred->user_ns, 0);
114298
114299 + if (gr_acl_enable_at_secure())
114300 + return 1;
114301 +
114302 if (!uid_eq(cred->uid, root_uid)) {
114303 if (bprm->cap_effective)
114304 return 1;
114305 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
114306 index f79fa8b..6161868 100644
114307 --- a/security/integrity/ima/ima.h
114308 +++ b/security/integrity/ima/ima.h
114309 @@ -118,8 +118,8 @@ int ima_init_template(void);
114310 extern spinlock_t ima_queue_lock;
114311
114312 struct ima_h_table {
114313 - atomic_long_t len; /* number of stored measurements in the list */
114314 - atomic_long_t violations;
114315 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
114316 + atomic_long_unchecked_t violations;
114317 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
114318 };
114319 extern struct ima_h_table ima_htable;
114320 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
114321 index d9cd5ce..c5c29ac 100644
114322 --- a/security/integrity/ima/ima_api.c
114323 +++ b/security/integrity/ima/ima_api.c
114324 @@ -137,7 +137,7 @@ void ima_add_violation(struct file *file, const unsigned char *filename,
114325 int result;
114326
114327 /* can overflow, only indicator */
114328 - atomic_long_inc(&ima_htable.violations);
114329 + atomic_long_inc_unchecked(&ima_htable.violations);
114330
114331 result = ima_alloc_init_template(NULL, file, filename,
114332 NULL, 0, &entry);
114333 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
114334 index da92fcc..8a5d390 100644
114335 --- a/security/integrity/ima/ima_fs.c
114336 +++ b/security/integrity/ima/ima_fs.c
114337 @@ -28,12 +28,12 @@
114338 static int valid_policy = 1;
114339 #define TMPBUFLEN 12
114340 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
114341 - loff_t *ppos, atomic_long_t *val)
114342 + loff_t *ppos, atomic_long_unchecked_t *val)
114343 {
114344 char tmpbuf[TMPBUFLEN];
114345 ssize_t len;
114346
114347 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
114348 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
114349 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
114350 }
114351
114352 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
114353 index 552705d..9920f4fb 100644
114354 --- a/security/integrity/ima/ima_queue.c
114355 +++ b/security/integrity/ima/ima_queue.c
114356 @@ -83,7 +83,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
114357 INIT_LIST_HEAD(&qe->later);
114358 list_add_tail_rcu(&qe->later, &ima_measurements);
114359
114360 - atomic_long_inc(&ima_htable.len);
114361 + atomic_long_inc_unchecked(&ima_htable.len);
114362 key = ima_hash_key(entry->digest);
114363 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
114364 return 0;
114365 diff --git a/security/keys/compat.c b/security/keys/compat.c
114366 index 3478965..ec7bb9e 100644
114367 --- a/security/keys/compat.c
114368 +++ b/security/keys/compat.c
114369 @@ -44,7 +44,7 @@ static long compat_keyctl_instantiate_key_iov(
114370 if (ret == 0)
114371 goto no_payload_free;
114372
114373 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
114374 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
114375 err:
114376 if (iov != iovstack)
114377 kfree(iov);
114378 diff --git a/security/keys/internal.h b/security/keys/internal.h
114379 index 5f20da0..444ccf1 100644
114380 --- a/security/keys/internal.h
114381 +++ b/security/keys/internal.h
114382 @@ -244,7 +244,7 @@ extern long keyctl_instantiate_key_iov(key_serial_t,
114383 extern long keyctl_invalidate_key(key_serial_t);
114384
114385 extern long keyctl_instantiate_key_common(key_serial_t,
114386 - const struct iovec *,
114387 + const struct iovec __user *,
114388 unsigned, size_t, key_serial_t);
114389 #ifdef CONFIG_PERSISTENT_KEYRINGS
114390 extern long keyctl_get_persistent(uid_t, key_serial_t);
114391 diff --git a/security/keys/key.c b/security/keys/key.c
114392 index 2048a11..101df4c 100644
114393 --- a/security/keys/key.c
114394 +++ b/security/keys/key.c
114395 @@ -285,7 +285,7 @@ struct key *key_alloc(struct key_type *type, const char *desc,
114396
114397 atomic_set(&key->usage, 1);
114398 init_rwsem(&key->sem);
114399 - lockdep_set_class(&key->sem, &type->lock_class);
114400 + lockdep_set_class(&key->sem, (struct lock_class_key *)&type->lock_class);
114401 key->index_key.type = type;
114402 key->user = user;
114403 key->quotalen = quotalen;
114404 @@ -1036,7 +1036,9 @@ int register_key_type(struct key_type *ktype)
114405 struct key_type *p;
114406 int ret;
114407
114408 - memset(&ktype->lock_class, 0, sizeof(ktype->lock_class));
114409 + pax_open_kernel();
114410 + memset((void *)&ktype->lock_class, 0, sizeof(ktype->lock_class));
114411 + pax_close_kernel();
114412
114413 ret = -EEXIST;
114414 down_write(&key_types_sem);
114415 @@ -1048,7 +1050,7 @@ int register_key_type(struct key_type *ktype)
114416 }
114417
114418 /* store the type */
114419 - list_add(&ktype->link, &key_types_list);
114420 + pax_list_add((struct list_head *)&ktype->link, &key_types_list);
114421
114422 pr_notice("Key type %s registered\n", ktype->name);
114423 ret = 0;
114424 @@ -1070,7 +1072,7 @@ EXPORT_SYMBOL(register_key_type);
114425 void unregister_key_type(struct key_type *ktype)
114426 {
114427 down_write(&key_types_sem);
114428 - list_del_init(&ktype->link);
114429 + pax_list_del_init((struct list_head *)&ktype->link);
114430 downgrade_write(&key_types_sem);
114431 key_gc_keytype(ktype);
114432 pr_notice("Key type %s unregistered\n", ktype->name);
114433 @@ -1088,10 +1090,10 @@ void __init key_init(void)
114434 0, SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
114435
114436 /* add the special key types */
114437 - list_add_tail(&key_type_keyring.link, &key_types_list);
114438 - list_add_tail(&key_type_dead.link, &key_types_list);
114439 - list_add_tail(&key_type_user.link, &key_types_list);
114440 - list_add_tail(&key_type_logon.link, &key_types_list);
114441 + pax_list_add_tail((struct list_head *)&key_type_keyring.link, &key_types_list);
114442 + pax_list_add_tail((struct list_head *)&key_type_dead.link, &key_types_list);
114443 + pax_list_add_tail((struct list_head *)&key_type_user.link, &key_types_list);
114444 + pax_list_add_tail((struct list_head *)&key_type_logon.link, &key_types_list);
114445
114446 /* record the root user tracking */
114447 rb_link_node(&root_key_user.node,
114448 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
114449 index cd5bd0c..acd0d5c 100644
114450 --- a/security/keys/keyctl.c
114451 +++ b/security/keys/keyctl.c
114452 @@ -987,7 +987,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
114453 /*
114454 * Copy the iovec data from userspace
114455 */
114456 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
114457 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
114458 unsigned ioc)
114459 {
114460 for (; ioc > 0; ioc--) {
114461 @@ -1009,7 +1009,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
114462 * If successful, 0 will be returned.
114463 */
114464 long keyctl_instantiate_key_common(key_serial_t id,
114465 - const struct iovec *payload_iov,
114466 + const struct iovec __user *payload_iov,
114467 unsigned ioc,
114468 size_t plen,
114469 key_serial_t ringid)
114470 @@ -1104,7 +1104,7 @@ long keyctl_instantiate_key(key_serial_t id,
114471 [0].iov_len = plen
114472 };
114473
114474 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
114475 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
114476 }
114477
114478 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
114479 @@ -1137,7 +1137,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
114480 if (ret == 0)
114481 goto no_payload_free;
114482
114483 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
114484 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
114485 err:
114486 if (iov != iovstack)
114487 kfree(iov);
114488 diff --git a/security/min_addr.c b/security/min_addr.c
114489 index f728728..6457a0c 100644
114490 --- a/security/min_addr.c
114491 +++ b/security/min_addr.c
114492 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
114493 */
114494 static void update_mmap_min_addr(void)
114495 {
114496 +#ifndef SPARC
114497 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
114498 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
114499 mmap_min_addr = dac_mmap_min_addr;
114500 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
114501 #else
114502 mmap_min_addr = dac_mmap_min_addr;
114503 #endif
114504 +#endif
114505 }
114506
114507 /*
114508 diff --git a/security/security.c b/security/security.c
114509 index 31614e9..8b86b12 100644
114510 --- a/security/security.c
114511 +++ b/security/security.c
114512 @@ -33,8 +33,8 @@
114513 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
114514 CONFIG_DEFAULT_SECURITY;
114515
114516 -static struct security_operations *security_ops;
114517 -static struct security_operations default_security_ops = {
114518 +struct security_operations *security_ops __read_only;
114519 +struct security_operations default_security_ops __read_only = {
114520 .name = "default",
114521 };
114522
114523 @@ -73,11 +73,6 @@ int __init security_init(void)
114524 return 0;
114525 }
114526
114527 -void reset_security_ops(void)
114528 -{
114529 - security_ops = &default_security_ops;
114530 -}
114531 -
114532 /* Save user chosen LSM */
114533 static int __init choose_lsm(char *str)
114534 {
114535 diff --git a/security/selinux/avc.c b/security/selinux/avc.c
114536 index a18f1fa..c9b9fc4 100644
114537 --- a/security/selinux/avc.c
114538 +++ b/security/selinux/avc.c
114539 @@ -59,7 +59,7 @@ struct avc_node {
114540 struct avc_cache {
114541 struct hlist_head slots[AVC_CACHE_SLOTS]; /* head for avc_node->list */
114542 spinlock_t slots_lock[AVC_CACHE_SLOTS]; /* lock for writes */
114543 - atomic_t lru_hint; /* LRU hint for reclaim scan */
114544 + atomic_unchecked_t lru_hint; /* LRU hint for reclaim scan */
114545 atomic_t active_nodes;
114546 u32 latest_notif; /* latest revocation notification */
114547 };
114548 @@ -167,7 +167,7 @@ void __init avc_init(void)
114549 spin_lock_init(&avc_cache.slots_lock[i]);
114550 }
114551 atomic_set(&avc_cache.active_nodes, 0);
114552 - atomic_set(&avc_cache.lru_hint, 0);
114553 + atomic_set_unchecked(&avc_cache.lru_hint, 0);
114554
114555 avc_node_cachep = kmem_cache_create("avc_node", sizeof(struct avc_node),
114556 0, SLAB_PANIC, NULL);
114557 @@ -242,7 +242,7 @@ static inline int avc_reclaim_node(void)
114558 spinlock_t *lock;
114559
114560 for (try = 0, ecx = 0; try < AVC_CACHE_SLOTS; try++) {
114561 - hvalue = atomic_inc_return(&avc_cache.lru_hint) & (AVC_CACHE_SLOTS - 1);
114562 + hvalue = atomic_inc_return_unchecked(&avc_cache.lru_hint) & (AVC_CACHE_SLOTS - 1);
114563 head = &avc_cache.slots[hvalue];
114564 lock = &avc_cache.slots_lock[hvalue];
114565
114566 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
114567 index 83d06db..d4d6861 100644
114568 --- a/security/selinux/hooks.c
114569 +++ b/security/selinux/hooks.c
114570 @@ -95,8 +95,6 @@
114571 #include "audit.h"
114572 #include "avc_ss.h"
114573
114574 -extern struct security_operations *security_ops;
114575 -
114576 /* SECMARK reference count */
114577 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
114578
114579 @@ -5761,7 +5759,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
114580
114581 #endif
114582
114583 -static struct security_operations selinux_ops = {
114584 +static struct security_operations selinux_ops __read_only = {
114585 .name = "selinux",
114586
114587 .ptrace_access_check = selinux_ptrace_access_check,
114588 @@ -6114,6 +6112,9 @@ static void selinux_nf_ip_exit(void)
114589 #ifdef CONFIG_SECURITY_SELINUX_DISABLE
114590 static int selinux_disabled;
114591
114592 +extern struct security_operations *security_ops;
114593 +extern struct security_operations default_security_ops;
114594 +
114595 int selinux_disable(void)
114596 {
114597 if (ss_initialized) {
114598 @@ -6131,7 +6132,9 @@ int selinux_disable(void)
114599 selinux_disabled = 1;
114600 selinux_enabled = 0;
114601
114602 - reset_security_ops();
114603 + pax_open_kernel();
114604 + security_ops = &default_security_ops;
114605 + pax_close_kernel();
114606
114607 /* Try to destroy the avc node cache */
114608 avc_disable();
114609 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
114610 index 1450f85..a91e0bc 100644
114611 --- a/security/selinux/include/xfrm.h
114612 +++ b/security/selinux/include/xfrm.h
114613 @@ -48,7 +48,7 @@ static inline void selinux_xfrm_notify_policyload(void)
114614
114615 rtnl_lock();
114616 for_each_net(net) {
114617 - atomic_inc(&net->xfrm.flow_cache_genid);
114618 + atomic_inc_unchecked(&net->xfrm.flow_cache_genid);
114619 rt_genid_bump_all(net);
114620 }
114621 rtnl_unlock();
114622 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
114623 index f2c3080..813c85e 100644
114624 --- a/security/smack/smack_lsm.c
114625 +++ b/security/smack/smack_lsm.c
114626 @@ -3849,7 +3849,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
114627 return 0;
114628 }
114629
114630 -struct security_operations smack_ops = {
114631 +struct security_operations smack_ops __read_only = {
114632 .name = "smack",
114633
114634 .ptrace_access_check = smack_ptrace_access_check,
114635 diff --git a/security/tomoyo/file.c b/security/tomoyo/file.c
114636 index 4003907..13a2b55 100644
114637 --- a/security/tomoyo/file.c
114638 +++ b/security/tomoyo/file.c
114639 @@ -692,7 +692,7 @@ int tomoyo_path_number_perm(const u8 type, struct path *path,
114640 {
114641 struct tomoyo_request_info r;
114642 struct tomoyo_obj_info obj = {
114643 - .path1 = *path,
114644 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
114645 };
114646 int error = -ENOMEM;
114647 struct tomoyo_path_info buf;
114648 @@ -740,7 +740,7 @@ int tomoyo_check_open_permission(struct tomoyo_domain_info *domain,
114649 struct tomoyo_path_info buf;
114650 struct tomoyo_request_info r;
114651 struct tomoyo_obj_info obj = {
114652 - .path1 = *path,
114653 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
114654 };
114655 int idx;
114656
114657 @@ -786,7 +786,7 @@ int tomoyo_path_perm(const u8 operation, struct path *path, const char *target)
114658 {
114659 struct tomoyo_request_info r;
114660 struct tomoyo_obj_info obj = {
114661 - .path1 = *path,
114662 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
114663 };
114664 int error;
114665 struct tomoyo_path_info buf;
114666 @@ -843,7 +843,7 @@ int tomoyo_mkdev_perm(const u8 operation, struct path *path,
114667 {
114668 struct tomoyo_request_info r;
114669 struct tomoyo_obj_info obj = {
114670 - .path1 = *path,
114671 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
114672 };
114673 int error = -ENOMEM;
114674 struct tomoyo_path_info buf;
114675 @@ -890,8 +890,8 @@ int tomoyo_path2_perm(const u8 operation, struct path *path1,
114676 struct tomoyo_path_info buf2;
114677 struct tomoyo_request_info r;
114678 struct tomoyo_obj_info obj = {
114679 - .path1 = *path1,
114680 - .path2 = *path2,
114681 + .path1 = { .mnt = path1->mnt, .dentry = path1->dentry },
114682 + .path2 = { .mnt = path2->mnt, .dentry = path2->dentry }
114683 };
114684 int idx;
114685
114686 diff --git a/security/tomoyo/mount.c b/security/tomoyo/mount.c
114687 index 390c646..f2f8db3 100644
114688 --- a/security/tomoyo/mount.c
114689 +++ b/security/tomoyo/mount.c
114690 @@ -118,6 +118,10 @@ static int tomoyo_mount_acl(struct tomoyo_request_info *r,
114691 type == tomoyo_mounts[TOMOYO_MOUNT_MOVE]) {
114692 need_dev = -1; /* dev_name is a directory */
114693 } else {
114694 + if (!capable(CAP_SYS_ADMIN)) {
114695 + error = -EPERM;
114696 + goto out;
114697 + }
114698 fstype = get_fs_type(type);
114699 if (!fstype) {
114700 error = -ENODEV;
114701 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
114702 index f0b756e..8aa497b 100644
114703 --- a/security/tomoyo/tomoyo.c
114704 +++ b/security/tomoyo/tomoyo.c
114705 @@ -146,7 +146,7 @@ static int tomoyo_bprm_check_security(struct linux_binprm *bprm)
114706 */
114707 static int tomoyo_inode_getattr(struct vfsmount *mnt, struct dentry *dentry)
114708 {
114709 - struct path path = { mnt, dentry };
114710 + struct path path = { .mnt = mnt, .dentry = dentry };
114711 return tomoyo_path_perm(TOMOYO_TYPE_GETATTR, &path, NULL);
114712 }
114713
114714 @@ -172,7 +172,7 @@ static int tomoyo_path_truncate(struct path *path)
114715 */
114716 static int tomoyo_path_unlink(struct path *parent, struct dentry *dentry)
114717 {
114718 - struct path path = { parent->mnt, dentry };
114719 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
114720 return tomoyo_path_perm(TOMOYO_TYPE_UNLINK, &path, NULL);
114721 }
114722
114723 @@ -188,7 +188,7 @@ static int tomoyo_path_unlink(struct path *parent, struct dentry *dentry)
114724 static int tomoyo_path_mkdir(struct path *parent, struct dentry *dentry,
114725 umode_t mode)
114726 {
114727 - struct path path = { parent->mnt, dentry };
114728 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
114729 return tomoyo_path_number_perm(TOMOYO_TYPE_MKDIR, &path,
114730 mode & S_IALLUGO);
114731 }
114732 @@ -203,7 +203,7 @@ static int tomoyo_path_mkdir(struct path *parent, struct dentry *dentry,
114733 */
114734 static int tomoyo_path_rmdir(struct path *parent, struct dentry *dentry)
114735 {
114736 - struct path path = { parent->mnt, dentry };
114737 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
114738 return tomoyo_path_perm(TOMOYO_TYPE_RMDIR, &path, NULL);
114739 }
114740
114741 @@ -219,7 +219,7 @@ static int tomoyo_path_rmdir(struct path *parent, struct dentry *dentry)
114742 static int tomoyo_path_symlink(struct path *parent, struct dentry *dentry,
114743 const char *old_name)
114744 {
114745 - struct path path = { parent->mnt, dentry };
114746 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
114747 return tomoyo_path_perm(TOMOYO_TYPE_SYMLINK, &path, old_name);
114748 }
114749
114750 @@ -236,7 +236,7 @@ static int tomoyo_path_symlink(struct path *parent, struct dentry *dentry,
114751 static int tomoyo_path_mknod(struct path *parent, struct dentry *dentry,
114752 umode_t mode, unsigned int dev)
114753 {
114754 - struct path path = { parent->mnt, dentry };
114755 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
114756 int type = TOMOYO_TYPE_CREATE;
114757 const unsigned int perm = mode & S_IALLUGO;
114758
114759 @@ -275,8 +275,8 @@ static int tomoyo_path_mknod(struct path *parent, struct dentry *dentry,
114760 static int tomoyo_path_link(struct dentry *old_dentry, struct path *new_dir,
114761 struct dentry *new_dentry)
114762 {
114763 - struct path path1 = { new_dir->mnt, old_dentry };
114764 - struct path path2 = { new_dir->mnt, new_dentry };
114765 + struct path path1 = { .mnt = new_dir->mnt, .dentry = old_dentry };
114766 + struct path path2 = { .mnt = new_dir->mnt, .dentry = new_dentry };
114767 return tomoyo_path2_perm(TOMOYO_TYPE_LINK, &path1, &path2);
114768 }
114769
114770 @@ -295,8 +295,8 @@ static int tomoyo_path_rename(struct path *old_parent,
114771 struct path *new_parent,
114772 struct dentry *new_dentry)
114773 {
114774 - struct path path1 = { old_parent->mnt, old_dentry };
114775 - struct path path2 = { new_parent->mnt, new_dentry };
114776 + struct path path1 = { .mnt = old_parent->mnt, .dentry = old_dentry };
114777 + struct path path2 = { .mnt = new_parent->mnt, .dentry = new_dentry };
114778 return tomoyo_path2_perm(TOMOYO_TYPE_RENAME, &path1, &path2);
114779 }
114780
114781 @@ -424,7 +424,7 @@ static int tomoyo_sb_mount(const char *dev_name, struct path *path,
114782 */
114783 static int tomoyo_sb_umount(struct vfsmount *mnt, int flags)
114784 {
114785 - struct path path = { mnt, mnt->mnt_root };
114786 + struct path path = { .mnt = mnt, .dentry = mnt->mnt_root };
114787 return tomoyo_path_perm(TOMOYO_TYPE_UMOUNT, &path, NULL);
114788 }
114789
114790 @@ -503,7 +503,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
114791 * tomoyo_security_ops is a "struct security_operations" which is used for
114792 * registering TOMOYO.
114793 */
114794 -static struct security_operations tomoyo_security_ops = {
114795 +static struct security_operations tomoyo_security_ops __read_only = {
114796 .name = "tomoyo",
114797 .cred_alloc_blank = tomoyo_cred_alloc_blank,
114798 .cred_prepare = tomoyo_cred_prepare,
114799 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
114800 index 20ef514..4182bed 100644
114801 --- a/security/yama/Kconfig
114802 +++ b/security/yama/Kconfig
114803 @@ -1,6 +1,6 @@
114804 config SECURITY_YAMA
114805 bool "Yama support"
114806 - depends on SECURITY
114807 + depends on SECURITY && !GRKERNSEC
114808 select SECURITYFS
114809 select SECURITY_PATH
114810 default n
114811 diff --git a/security/yama/yama_lsm.c b/security/yama/yama_lsm.c
114812 index 13c88fbc..f8c115e 100644
114813 --- a/security/yama/yama_lsm.c
114814 +++ b/security/yama/yama_lsm.c
114815 @@ -365,7 +365,7 @@ int yama_ptrace_traceme(struct task_struct *parent)
114816 }
114817
114818 #ifndef CONFIG_SECURITY_YAMA_STACKED
114819 -static struct security_operations yama_ops = {
114820 +static struct security_operations yama_ops __read_only = {
114821 .name = "yama",
114822
114823 .ptrace_access_check = yama_ptrace_access_check,
114824 @@ -376,28 +376,24 @@ static struct security_operations yama_ops = {
114825 #endif
114826
114827 #ifdef CONFIG_SYSCTL
114828 +static int zero __read_only;
114829 +static int max_scope __read_only = YAMA_SCOPE_NO_ATTACH;
114830 +
114831 static int yama_dointvec_minmax(struct ctl_table *table, int write,
114832 void __user *buffer, size_t *lenp, loff_t *ppos)
114833 {
114834 - int rc;
114835 + ctl_table_no_const yama_table;
114836
114837 if (write && !capable(CAP_SYS_PTRACE))
114838 return -EPERM;
114839
114840 - rc = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
114841 - if (rc)
114842 - return rc;
114843 -
114844 + yama_table = *table;
114845 /* Lock the max value if it ever gets set. */
114846 - if (write && *(int *)table->data == *(int *)table->extra2)
114847 - table->extra1 = table->extra2;
114848 -
114849 - return rc;
114850 + if (ptrace_scope == max_scope)
114851 + yama_table.extra1 = &max_scope;
114852 + return proc_dointvec_minmax(&yama_table, write, buffer, lenp, ppos);
114853 }
114854
114855 -static int zero;
114856 -static int max_scope = YAMA_SCOPE_NO_ATTACH;
114857 -
114858 struct ctl_path yama_sysctl_path[] = {
114859 { .procname = "kernel", },
114860 { .procname = "yama", },
114861 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
114862 index 401107b..b9c47c6 100644
114863 --- a/sound/aoa/codecs/onyx.c
114864 +++ b/sound/aoa/codecs/onyx.c
114865 @@ -54,7 +54,7 @@ struct onyx {
114866 spdif_locked:1,
114867 analog_locked:1,
114868 original_mute:2;
114869 - int open_count;
114870 + local_t open_count;
114871 struct codec_info *codec_info;
114872
114873 /* mutex serializes concurrent access to the device
114874 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
114875 struct onyx *onyx = cii->codec_data;
114876
114877 mutex_lock(&onyx->mutex);
114878 - onyx->open_count++;
114879 + local_inc(&onyx->open_count);
114880 mutex_unlock(&onyx->mutex);
114881
114882 return 0;
114883 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
114884 struct onyx *onyx = cii->codec_data;
114885
114886 mutex_lock(&onyx->mutex);
114887 - onyx->open_count--;
114888 - if (!onyx->open_count)
114889 + if (local_dec_and_test(&onyx->open_count))
114890 onyx->spdif_locked = onyx->analog_locked = 0;
114891 mutex_unlock(&onyx->mutex);
114892
114893 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
114894 index ffd2025..df062c9 100644
114895 --- a/sound/aoa/codecs/onyx.h
114896 +++ b/sound/aoa/codecs/onyx.h
114897 @@ -11,6 +11,7 @@
114898 #include <linux/i2c.h>
114899 #include <asm/pmac_low_i2c.h>
114900 #include <asm/prom.h>
114901 +#include <asm/local.h>
114902
114903 /* PCM3052 register definitions */
114904
114905 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
114906 index ada69d7..5f65386 100644
114907 --- a/sound/core/oss/pcm_oss.c
114908 +++ b/sound/core/oss/pcm_oss.c
114909 @@ -1190,10 +1190,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
114910 if (in_kernel) {
114911 mm_segment_t fs;
114912 fs = snd_enter_user();
114913 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
114914 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
114915 snd_leave_user(fs);
114916 } else {
114917 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
114918 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
114919 }
114920 if (ret != -EPIPE && ret != -ESTRPIPE)
114921 break;
114922 @@ -1233,10 +1233,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
114923 if (in_kernel) {
114924 mm_segment_t fs;
114925 fs = snd_enter_user();
114926 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
114927 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
114928 snd_leave_user(fs);
114929 } else {
114930 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
114931 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
114932 }
114933 if (ret == -EPIPE) {
114934 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
114935 @@ -1332,7 +1332,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
114936 struct snd_pcm_plugin_channel *channels;
114937 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
114938 if (!in_kernel) {
114939 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
114940 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
114941 return -EFAULT;
114942 buf = runtime->oss.buffer;
114943 }
114944 @@ -1402,7 +1402,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
114945 }
114946 } else {
114947 tmp = snd_pcm_oss_write2(substream,
114948 - (const char __force *)buf,
114949 + (const char __force_kernel *)buf,
114950 runtime->oss.period_bytes, 0);
114951 if (tmp <= 0)
114952 goto err;
114953 @@ -1428,7 +1428,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
114954 struct snd_pcm_runtime *runtime = substream->runtime;
114955 snd_pcm_sframes_t frames, frames1;
114956 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
114957 - char __user *final_dst = (char __force __user *)buf;
114958 + char __user *final_dst = (char __force_user *)buf;
114959 if (runtime->oss.plugin_first) {
114960 struct snd_pcm_plugin_channel *channels;
114961 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
114962 @@ -1490,7 +1490,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
114963 xfer += tmp;
114964 runtime->oss.buffer_used -= tmp;
114965 } else {
114966 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
114967 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
114968 runtime->oss.period_bytes, 0);
114969 if (tmp <= 0)
114970 goto err;
114971 @@ -1659,7 +1659,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
114972 size1);
114973 size1 /= runtime->channels; /* frames */
114974 fs = snd_enter_user();
114975 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
114976 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
114977 snd_leave_user(fs);
114978 }
114979 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
114980 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
114981 index af49721..e85058e 100644
114982 --- a/sound/core/pcm_compat.c
114983 +++ b/sound/core/pcm_compat.c
114984 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
114985 int err;
114986
114987 fs = snd_enter_user();
114988 - err = snd_pcm_delay(substream, &delay);
114989 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
114990 snd_leave_user(fs);
114991 if (err < 0)
114992 return err;
114993 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
114994 index b653ab0..a4738e3 100644
114995 --- a/sound/core/pcm_native.c
114996 +++ b/sound/core/pcm_native.c
114997 @@ -2812,11 +2812,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
114998 switch (substream->stream) {
114999 case SNDRV_PCM_STREAM_PLAYBACK:
115000 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
115001 - (void __user *)arg);
115002 + (void __force_user *)arg);
115003 break;
115004 case SNDRV_PCM_STREAM_CAPTURE:
115005 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
115006 - (void __user *)arg);
115007 + (void __force_user *)arg);
115008 break;
115009 default:
115010 result = -EINVAL;
115011 diff --git a/sound/core/seq/oss/seq_oss.c b/sound/core/seq/oss/seq_oss.c
115012 index 16d4267..fe8b49b 100644
115013 --- a/sound/core/seq/oss/seq_oss.c
115014 +++ b/sound/core/seq/oss/seq_oss.c
115015 @@ -69,8 +69,8 @@ static int __init alsa_seq_oss_init(void)
115016 {
115017 int rc;
115018 static struct snd_seq_dev_ops ops = {
115019 - snd_seq_oss_synth_register,
115020 - snd_seq_oss_synth_unregister,
115021 + .init_device = snd_seq_oss_synth_register,
115022 + .free_device = snd_seq_oss_synth_unregister,
115023 };
115024
115025 snd_seq_autoload_lock();
115026 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
115027 index 91a786a..4c07ed4 100644
115028 --- a/sound/core/seq/seq_device.c
115029 +++ b/sound/core/seq/seq_device.c
115030 @@ -64,7 +64,7 @@ struct ops_list {
115031 int argsize; /* argument size */
115032
115033 /* operators */
115034 - struct snd_seq_dev_ops ops;
115035 + struct snd_seq_dev_ops *ops;
115036
115037 /* registered devices */
115038 struct list_head dev_list; /* list of devices */
115039 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
115040
115041 mutex_lock(&ops->reg_mutex);
115042 /* copy driver operators */
115043 - ops->ops = *entry;
115044 + ops->ops = entry;
115045 ops->driver |= DRIVER_LOADED;
115046 ops->argsize = argsize;
115047
115048 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
115049 dev->name, ops->id, ops->argsize, dev->argsize);
115050 return -EINVAL;
115051 }
115052 - if (ops->ops.init_device(dev) >= 0) {
115053 + if (ops->ops->init_device(dev) >= 0) {
115054 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
115055 ops->num_init_devices++;
115056 } else {
115057 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
115058 dev->name, ops->id, ops->argsize, dev->argsize);
115059 return -EINVAL;
115060 }
115061 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
115062 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
115063 dev->status = SNDRV_SEQ_DEVICE_FREE;
115064 dev->driver_data = NULL;
115065 ops->num_init_devices--;
115066 diff --git a/sound/core/seq/seq_midi.c b/sound/core/seq/seq_midi.c
115067 index a1fd77a..69cd659 100644
115068 --- a/sound/core/seq/seq_midi.c
115069 +++ b/sound/core/seq/seq_midi.c
115070 @@ -462,8 +462,8 @@ snd_seq_midisynth_unregister_port(struct snd_seq_device *dev)
115071 static int __init alsa_seq_midi_init(void)
115072 {
115073 static struct snd_seq_dev_ops ops = {
115074 - snd_seq_midisynth_register_port,
115075 - snd_seq_midisynth_unregister_port,
115076 + .init_device = snd_seq_midisynth_register_port,
115077 + .free_device = snd_seq_midisynth_unregister_port,
115078 };
115079 memset(&synths, 0, sizeof(synths));
115080 snd_seq_autoload_lock();
115081 diff --git a/sound/core/sound.c b/sound/core/sound.c
115082 index 38ad1a0..5010a40 100644
115083 --- a/sound/core/sound.c
115084 +++ b/sound/core/sound.c
115085 @@ -86,7 +86,7 @@ static void snd_request_other(int minor)
115086 case SNDRV_MINOR_TIMER: str = "snd-timer"; break;
115087 default: return;
115088 }
115089 - request_module(str);
115090 + request_module("%s", str);
115091 }
115092
115093 #endif /* modular kernel */
115094 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
115095 index f5fd448..6ae276da 100644
115096 --- a/sound/drivers/mts64.c
115097 +++ b/sound/drivers/mts64.c
115098 @@ -29,6 +29,7 @@
115099 #include <sound/initval.h>
115100 #include <sound/rawmidi.h>
115101 #include <sound/control.h>
115102 +#include <asm/local.h>
115103
115104 #define CARD_NAME "Miditerminal 4140"
115105 #define DRIVER_NAME "MTS64"
115106 @@ -67,7 +68,7 @@ struct mts64 {
115107 struct pardevice *pardev;
115108 int pardev_claimed;
115109
115110 - int open_count;
115111 + local_t open_count;
115112 int current_midi_output_port;
115113 int current_midi_input_port;
115114 u8 mode[MTS64_NUM_INPUT_PORTS];
115115 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
115116 {
115117 struct mts64 *mts = substream->rmidi->private_data;
115118
115119 - if (mts->open_count == 0) {
115120 + if (local_read(&mts->open_count) == 0) {
115121 /* We don't need a spinlock here, because this is just called
115122 if the device has not been opened before.
115123 So there aren't any IRQs from the device */
115124 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
115125
115126 msleep(50);
115127 }
115128 - ++(mts->open_count);
115129 + local_inc(&mts->open_count);
115130
115131 return 0;
115132 }
115133 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
115134 struct mts64 *mts = substream->rmidi->private_data;
115135 unsigned long flags;
115136
115137 - --(mts->open_count);
115138 - if (mts->open_count == 0) {
115139 + if (local_dec_return(&mts->open_count) == 0) {
115140 /* We need the spinlock_irqsave here because we can still
115141 have IRQs at this point */
115142 spin_lock_irqsave(&mts->lock, flags);
115143 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
115144
115145 msleep(500);
115146
115147 - } else if (mts->open_count < 0)
115148 - mts->open_count = 0;
115149 + } else if (local_read(&mts->open_count) < 0)
115150 + local_set(&mts->open_count, 0);
115151
115152 return 0;
115153 }
115154 diff --git a/sound/drivers/opl3/opl3_seq.c b/sound/drivers/opl3/opl3_seq.c
115155 index 6839953..7a0f4b9 100644
115156 --- a/sound/drivers/opl3/opl3_seq.c
115157 +++ b/sound/drivers/opl3/opl3_seq.c
115158 @@ -281,8 +281,8 @@ static int __init alsa_opl3_seq_init(void)
115159 {
115160 static struct snd_seq_dev_ops ops =
115161 {
115162 - snd_opl3_seq_new_device,
115163 - snd_opl3_seq_delete_device
115164 + .init_device = snd_opl3_seq_new_device,
115165 + .free_device = snd_opl3_seq_delete_device
115166 };
115167
115168 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL3, &ops,
115169 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
115170 index b953fb4..1999c01 100644
115171 --- a/sound/drivers/opl4/opl4_lib.c
115172 +++ b/sound/drivers/opl4/opl4_lib.c
115173 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
115174 MODULE_DESCRIPTION("OPL4 driver");
115175 MODULE_LICENSE("GPL");
115176
115177 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
115178 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
115179 {
115180 int timeout = 10;
115181 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
115182 diff --git a/sound/drivers/opl4/opl4_seq.c b/sound/drivers/opl4/opl4_seq.c
115183 index 9919769..d7de36c 100644
115184 --- a/sound/drivers/opl4/opl4_seq.c
115185 +++ b/sound/drivers/opl4/opl4_seq.c
115186 @@ -198,8 +198,8 @@ static int snd_opl4_seq_delete_device(struct snd_seq_device *dev)
115187 static int __init alsa_opl4_synth_init(void)
115188 {
115189 static struct snd_seq_dev_ops ops = {
115190 - snd_opl4_seq_new_device,
115191 - snd_opl4_seq_delete_device
115192 + .init_device = snd_opl4_seq_new_device,
115193 + .free_device = snd_opl4_seq_delete_device
115194 };
115195
115196 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL4, &ops,
115197 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
115198 index 78ccfa4..7a0857b 100644
115199 --- a/sound/drivers/portman2x4.c
115200 +++ b/sound/drivers/portman2x4.c
115201 @@ -48,6 +48,7 @@
115202 #include <sound/initval.h>
115203 #include <sound/rawmidi.h>
115204 #include <sound/control.h>
115205 +#include <asm/local.h>
115206
115207 #define CARD_NAME "Portman 2x4"
115208 #define DRIVER_NAME "portman"
115209 @@ -85,7 +86,7 @@ struct portman {
115210 struct pardevice *pardev;
115211 int pardev_claimed;
115212
115213 - int open_count;
115214 + local_t open_count;
115215 int mode[PORTMAN_NUM_INPUT_PORTS];
115216 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
115217 };
115218 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
115219 index f96bf4c..f3bd1e0 100644
115220 --- a/sound/firewire/amdtp.c
115221 +++ b/sound/firewire/amdtp.c
115222 @@ -512,7 +512,7 @@ static void update_pcm_pointers(struct amdtp_stream *s,
115223 ptr = s->pcm_buffer_pointer + frames;
115224 if (ptr >= pcm->runtime->buffer_size)
115225 ptr -= pcm->runtime->buffer_size;
115226 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
115227 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
115228
115229 s->pcm_period_pointer += frames;
115230 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
115231 @@ -952,7 +952,7 @@ EXPORT_SYMBOL(amdtp_stream_pcm_pointer);
115232 */
115233 void amdtp_stream_update(struct amdtp_stream *s)
115234 {
115235 - ACCESS_ONCE(s->source_node_id_field) =
115236 + ACCESS_ONCE_RW(s->source_node_id_field) =
115237 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
115238 }
115239 EXPORT_SYMBOL(amdtp_stream_update);
115240 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
115241 index d8ee7b0..79dfa2a 100644
115242 --- a/sound/firewire/amdtp.h
115243 +++ b/sound/firewire/amdtp.h
115244 @@ -211,7 +211,7 @@ static inline bool amdtp_stream_pcm_running(struct amdtp_stream *s)
115245 static inline void amdtp_stream_pcm_trigger(struct amdtp_stream *s,
115246 struct snd_pcm_substream *pcm)
115247 {
115248 - ACCESS_ONCE(s->pcm) = pcm;
115249 + ACCESS_ONCE_RW(s->pcm) = pcm;
115250 }
115251
115252 /**
115253 @@ -229,7 +229,7 @@ static inline void amdtp_stream_midi_trigger(struct amdtp_stream *s,
115254 struct snd_rawmidi_substream *midi)
115255 {
115256 if (port < s->midi_ports)
115257 - ACCESS_ONCE(s->midi[port]) = midi;
115258 + ACCESS_ONCE_RW(s->midi[port]) = midi;
115259 }
115260
115261 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
115262 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
115263 index 7ac9443..0ec6274 100644
115264 --- a/sound/firewire/isight.c
115265 +++ b/sound/firewire/isight.c
115266 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
115267 ptr += count;
115268 if (ptr >= runtime->buffer_size)
115269 ptr -= runtime->buffer_size;
115270 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
115271 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
115272
115273 isight->period_counter += count;
115274 if (isight->period_counter >= runtime->period_size) {
115275 @@ -299,7 +299,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
115276 if (err < 0)
115277 return err;
115278
115279 - ACCESS_ONCE(isight->pcm_active) = true;
115280 + ACCESS_ONCE_RW(isight->pcm_active) = true;
115281
115282 return 0;
115283 }
115284 @@ -337,7 +337,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
115285 {
115286 struct isight *isight = substream->private_data;
115287
115288 - ACCESS_ONCE(isight->pcm_active) = false;
115289 + ACCESS_ONCE_RW(isight->pcm_active) = false;
115290
115291 mutex_lock(&isight->mutex);
115292 isight_stop_streaming(isight);
115293 @@ -430,10 +430,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
115294
115295 switch (cmd) {
115296 case SNDRV_PCM_TRIGGER_START:
115297 - ACCESS_ONCE(isight->pcm_running) = true;
115298 + ACCESS_ONCE_RW(isight->pcm_running) = true;
115299 break;
115300 case SNDRV_PCM_TRIGGER_STOP:
115301 - ACCESS_ONCE(isight->pcm_running) = false;
115302 + ACCESS_ONCE_RW(isight->pcm_running) = false;
115303 break;
115304 default:
115305 return -EINVAL;
115306 diff --git a/sound/firewire/scs1x.c b/sound/firewire/scs1x.c
115307 index 2dba848..c682aef 100644
115308 --- a/sound/firewire/scs1x.c
115309 +++ b/sound/firewire/scs1x.c
115310 @@ -74,7 +74,7 @@ static void scs_output_trigger(struct snd_rawmidi_substream *stream, int up)
115311 {
115312 struct scs *scs = stream->rmidi->private_data;
115313
115314 - ACCESS_ONCE(scs->output) = up ? stream : NULL;
115315 + ACCESS_ONCE_RW(scs->output) = up ? stream : NULL;
115316 if (up) {
115317 scs->output_idle = false;
115318 tasklet_schedule(&scs->tasklet);
115319 @@ -257,7 +257,7 @@ static void scs_input_trigger(struct snd_rawmidi_substream *stream, int up)
115320 {
115321 struct scs *scs = stream->rmidi->private_data;
115322
115323 - ACCESS_ONCE(scs->input) = up ? stream : NULL;
115324 + ACCESS_ONCE_RW(scs->input) = up ? stream : NULL;
115325 }
115326
115327 static void scs_input_escaped_byte(struct snd_rawmidi_substream *stream,
115328 @@ -473,8 +473,8 @@ static void scs_remove(struct fw_unit *unit)
115329
115330 snd_card_disconnect(scs->card);
115331
115332 - ACCESS_ONCE(scs->output) = NULL;
115333 - ACCESS_ONCE(scs->input) = NULL;
115334 + ACCESS_ONCE_RW(scs->output) = NULL;
115335 + ACCESS_ONCE_RW(scs->input) = NULL;
115336
115337 wait_event(scs->idle_wait, scs->output_idle);
115338
115339 diff --git a/sound/isa/sb/emu8000_synth.c b/sound/isa/sb/emu8000_synth.c
115340 index 4e3fcfb..ab45a9d 100644
115341 --- a/sound/isa/sb/emu8000_synth.c
115342 +++ b/sound/isa/sb/emu8000_synth.c
115343 @@ -120,8 +120,8 @@ static int __init alsa_emu8000_init(void)
115344 {
115345
115346 static struct snd_seq_dev_ops ops = {
115347 - snd_emu8000_new_device,
115348 - snd_emu8000_delete_device,
115349 + .init_device = snd_emu8000_new_device,
115350 + .free_device = snd_emu8000_delete_device,
115351 };
115352 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU8000, &ops,
115353 sizeof(struct snd_emu8000*));
115354 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
115355 index 048439a..3be9f6f 100644
115356 --- a/sound/oss/sb_audio.c
115357 +++ b/sound/oss/sb_audio.c
115358 @@ -904,7 +904,7 @@ sb16_copy_from_user(int dev,
115359 buf16 = (signed short *)(localbuf + localoffs);
115360 while (c)
115361 {
115362 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
115363 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
115364 if (copy_from_user(lbuf8,
115365 userbuf+useroffs + p,
115366 locallen))
115367 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
115368 index a33e8ce..2262303 100644
115369 --- a/sound/oss/swarm_cs4297a.c
115370 +++ b/sound/oss/swarm_cs4297a.c
115371 @@ -2623,7 +2623,6 @@ static int __init cs4297a_init(void)
115372 {
115373 struct cs4297a_state *s;
115374 u32 pwr, id;
115375 - mm_segment_t fs;
115376 int rval;
115377 u64 cfg;
115378 int mdio_val;
115379 @@ -2709,22 +2708,23 @@ static int __init cs4297a_init(void)
115380 if (!rval) {
115381 char *sb1250_duart_present;
115382
115383 +#if 0
115384 + mm_segment_t fs;
115385 fs = get_fs();
115386 set_fs(KERNEL_DS);
115387 -#if 0
115388 val = SOUND_MASK_LINE;
115389 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
115390 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
115391 val = initvol[i].vol;
115392 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
115393 }
115394 + set_fs(fs);
115395 // cs4297a_write_ac97(s, 0x18, 0x0808);
115396 #else
115397 // cs4297a_write_ac97(s, 0x5e, 0x180);
115398 cs4297a_write_ac97(s, 0x02, 0x0808);
115399 cs4297a_write_ac97(s, 0x18, 0x0808);
115400 #endif
115401 - set_fs(fs);
115402
115403 list_add(&s->list, &cs4297a_devs);
115404
115405 diff --git a/sound/pci/emu10k1/emu10k1_synth.c b/sound/pci/emu10k1/emu10k1_synth.c
115406 index 4c41c90..37f3631 100644
115407 --- a/sound/pci/emu10k1/emu10k1_synth.c
115408 +++ b/sound/pci/emu10k1/emu10k1_synth.c
115409 @@ -108,8 +108,8 @@ static int __init alsa_emu10k1_synth_init(void)
115410 {
115411
115412 static struct snd_seq_dev_ops ops = {
115413 - snd_emu10k1_synth_new_device,
115414 - snd_emu10k1_synth_delete_device,
115415 + .init_device = snd_emu10k1_synth_new_device,
115416 + .free_device = snd_emu10k1_synth_delete_device,
115417 };
115418 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH, &ops,
115419 sizeof(struct snd_emu10k1_synth_arg));
115420 diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
115421 index 4c20277..91abdce 100644
115422 --- a/sound/pci/hda/hda_codec.c
115423 +++ b/sound/pci/hda/hda_codec.c
115424 @@ -966,14 +966,10 @@ find_codec_preset(struct hda_codec *codec)
115425 mutex_unlock(&preset_mutex);
115426
115427 if (mod_requested < HDA_MODREQ_MAX_COUNT) {
115428 - char name[32];
115429 if (!mod_requested)
115430 - snprintf(name, sizeof(name), "snd-hda-codec-id:%08x",
115431 - codec->vendor_id);
115432 + request_module("snd-hda-codec-id:%08x", codec->vendor_id);
115433 else
115434 - snprintf(name, sizeof(name), "snd-hda-codec-id:%04x*",
115435 - (codec->vendor_id >> 16) & 0xffff);
115436 - request_module(name);
115437 + request_module("snd-hda-codec-id:%04x*", (codec->vendor_id >> 16) & 0xffff);
115438 mod_requested++;
115439 goto again;
115440 }
115441 @@ -2777,7 +2773,7 @@ static int get_kctl_0dB_offset(struct snd_kcontrol *kctl, int *step_to_check)
115442 /* FIXME: set_fs() hack for obtaining user-space TLV data */
115443 mm_segment_t fs = get_fs();
115444 set_fs(get_ds());
115445 - if (!kctl->tlv.c(kctl, 0, sizeof(_tlv), _tlv))
115446 + if (!kctl->tlv.c(kctl, 0, sizeof(_tlv), (unsigned int __force_user *)_tlv))
115447 tlv = _tlv;
115448 set_fs(fs);
115449 } else if (kctl->vd[0].access & SNDRV_CTL_ELEM_ACCESS_TLV_READ)
115450 diff --git a/sound/pci/ymfpci/ymfpci.h b/sound/pci/ymfpci/ymfpci.h
115451 index 4631a23..001ae57 100644
115452 --- a/sound/pci/ymfpci/ymfpci.h
115453 +++ b/sound/pci/ymfpci/ymfpci.h
115454 @@ -358,7 +358,7 @@ struct snd_ymfpci {
115455 spinlock_t reg_lock;
115456 spinlock_t voice_lock;
115457 wait_queue_head_t interrupt_sleep;
115458 - atomic_t interrupt_sleep_count;
115459 + atomic_unchecked_t interrupt_sleep_count;
115460 struct snd_info_entry *proc_entry;
115461 const struct firmware *dsp_microcode;
115462 const struct firmware *controller_microcode;
115463 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
115464 index 81c916a..516f0bf 100644
115465 --- a/sound/pci/ymfpci/ymfpci_main.c
115466 +++ b/sound/pci/ymfpci/ymfpci_main.c
115467 @@ -204,8 +204,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
115468 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
115469 break;
115470 }
115471 - if (atomic_read(&chip->interrupt_sleep_count)) {
115472 - atomic_set(&chip->interrupt_sleep_count, 0);
115473 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
115474 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
115475 wake_up(&chip->interrupt_sleep);
115476 }
115477 __end:
115478 @@ -789,7 +789,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
115479 continue;
115480 init_waitqueue_entry(&wait, current);
115481 add_wait_queue(&chip->interrupt_sleep, &wait);
115482 - atomic_inc(&chip->interrupt_sleep_count);
115483 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
115484 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
115485 remove_wait_queue(&chip->interrupt_sleep, &wait);
115486 }
115487 @@ -827,8 +827,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
115488 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
115489 spin_unlock(&chip->reg_lock);
115490
115491 - if (atomic_read(&chip->interrupt_sleep_count)) {
115492 - atomic_set(&chip->interrupt_sleep_count, 0);
115493 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
115494 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
115495 wake_up(&chip->interrupt_sleep);
115496 }
115497 }
115498 @@ -2423,7 +2423,7 @@ int snd_ymfpci_create(struct snd_card *card,
115499 spin_lock_init(&chip->reg_lock);
115500 spin_lock_init(&chip->voice_lock);
115501 init_waitqueue_head(&chip->interrupt_sleep);
115502 - atomic_set(&chip->interrupt_sleep_count, 0);
115503 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
115504 chip->card = card;
115505 chip->pci = pci;
115506 chip->irq = -1;
115507 diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
115508 index b87d7d8..0ccaac3 100644
115509 --- a/sound/soc/soc-core.c
115510 +++ b/sound/soc/soc-core.c
115511 @@ -2279,8 +2279,10 @@ int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops,
115512 if (ret)
115513 return ret;
115514
115515 - ops->warm_reset = snd_soc_ac97_warm_reset;
115516 - ops->reset = snd_soc_ac97_reset;
115517 + pax_open_kernel();
115518 + *(void **)&ops->warm_reset = snd_soc_ac97_warm_reset;
115519 + *(void **)&ops->reset = snd_soc_ac97_reset;
115520 + pax_close_kernel();
115521
115522 snd_ac97_rst_cfg = cfg;
115523 return 0;
115524 diff --git a/sound/synth/emux/emux_seq.c b/sound/synth/emux/emux_seq.c
115525 index 7778b8e..3d619fc 100644
115526 --- a/sound/synth/emux/emux_seq.c
115527 +++ b/sound/synth/emux/emux_seq.c
115528 @@ -33,13 +33,13 @@ static int snd_emux_unuse(void *private_data, struct snd_seq_port_subscribe *inf
115529 * MIDI emulation operators
115530 */
115531 static struct snd_midi_op emux_ops = {
115532 - snd_emux_note_on,
115533 - snd_emux_note_off,
115534 - snd_emux_key_press,
115535 - snd_emux_terminate_note,
115536 - snd_emux_control,
115537 - snd_emux_nrpn,
115538 - snd_emux_sysex,
115539 + .note_on = snd_emux_note_on,
115540 + .note_off = snd_emux_note_off,
115541 + .key_press = snd_emux_key_press,
115542 + .note_terminate = snd_emux_terminate_note,
115543 + .control = snd_emux_control,
115544 + .nrpn = snd_emux_nrpn,
115545 + .sysex = snd_emux_sysex,
115546 };
115547
115548
115549 diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
115550 new file mode 100644
115551 index 0000000..de92ed9
115552 --- /dev/null
115553 +++ b/tools/gcc/.gitignore
115554 @@ -0,0 +1 @@
115555 +randomize_layout_seed.h
115556 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
115557 new file mode 100644
115558 index 0000000..7b8921f
115559 --- /dev/null
115560 +++ b/tools/gcc/Makefile
115561 @@ -0,0 +1,52 @@
115562 +#CC := gcc
115563 +#PLUGIN_SOURCE_FILES := pax_plugin.c
115564 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
115565 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
115566 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
115567 +
115568 +ifeq ($(PLUGINCC),$(HOSTCC))
115569 +HOSTLIBS := hostlibs
115570 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(src) -std=gnu99 -ggdb
115571 +export HOST_EXTRACFLAGS
115572 +else
115573 +HOSTLIBS := hostcxxlibs
115574 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(src) -std=gnu++98 -fno-rtti -ggdb -Wno-unused-parameter -Wno-narrowing -Wno-unused-variable
115575 +export HOST_EXTRACXXFLAGS
115576 +endif
115577 +
115578 +export GCCPLUGINS_DIR HOSTLIBS
115579 +
115580 +$(HOSTLIBS)-$(CONFIG_PAX_CONSTIFY_PLUGIN) := constify_plugin.so
115581 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
115582 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
115583 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
115584 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
115585 +$(HOSTLIBS)-y += colorize_plugin.so
115586 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
115587 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STRUCTLEAK) += structleak_plugin.so
115588 +$(HOSTLIBS)-$(CONFIG_GRKERNSEC_RANDSTRUCT) += randomize_layout_plugin.so
115589 +
115590 +subdir-$(CONFIG_PAX_SIZE_OVERFLOW) := size_overflow_plugin
115591 +subdir- += size_overflow_plugin
115592 +
115593 +always := $($(HOSTLIBS)-y)
115594 +
115595 +constify_plugin-objs := constify_plugin.o
115596 +stackleak_plugin-objs := stackleak_plugin.o
115597 +kallocstat_plugin-objs := kallocstat_plugin.o
115598 +kernexec_plugin-objs := kernexec_plugin.o
115599 +checker_plugin-objs := checker_plugin.o
115600 +colorize_plugin-objs := colorize_plugin.o
115601 +latent_entropy_plugin-objs := latent_entropy_plugin.o
115602 +structleak_plugin-objs := structleak_plugin.o
115603 +randomize_layout_plugin-objs := randomize_layout_plugin.o
115604 +
115605 +$(obj)/randomize_layout_plugin.o: $(objtree)/$(obj)/randomize_layout_seed.h
115606 +
115607 +quiet_cmd_create_randomize_layout_seed = GENSEED $@
115608 + cmd_create_randomize_layout_seed = \
115609 + $(CONFIG_SHELL) $(srctree)/$(src)/gen-random-seed.sh $@ $(objtree)/include/generated/randomize_layout_hash.h
115610 +$(objtree)/$(obj)/randomize_layout_seed.h: FORCE
115611 + $(call if_changed,create_randomize_layout_seed)
115612 +
115613 +targets += randomize_layout_seed.h randomize_layout_hash.h
115614 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
115615 new file mode 100644
115616 index 0000000..5452feea
115617 --- /dev/null
115618 +++ b/tools/gcc/checker_plugin.c
115619 @@ -0,0 +1,150 @@
115620 +/*
115621 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
115622 + * Licensed under the GPL v2
115623 + *
115624 + * Note: the choice of the license means that the compilation process is
115625 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
115626 + * but for the kernel it doesn't matter since it doesn't link against
115627 + * any of the gcc libraries
115628 + *
115629 + * gcc plugin to implement various sparse (source code checker) features
115630 + *
115631 + * TODO:
115632 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
115633 + *
115634 + * BUGS:
115635 + * - none known
115636 + */
115637 +
115638 +#include "gcc-common.h"
115639 +
115640 +extern void c_register_addr_space (const char *str, addr_space_t as);
115641 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
115642 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
115643 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
115644 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
115645 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
115646 +
115647 +int plugin_is_GPL_compatible;
115648 +
115649 +static struct plugin_info checker_plugin_info = {
115650 + .version = "201304082245",
115651 + .help = NULL,
115652 +};
115653 +
115654 +#define ADDR_SPACE_KERNEL 0
115655 +#define ADDR_SPACE_FORCE_KERNEL 1
115656 +#define ADDR_SPACE_USER 2
115657 +#define ADDR_SPACE_FORCE_USER 3
115658 +#define ADDR_SPACE_IOMEM 0
115659 +#define ADDR_SPACE_FORCE_IOMEM 0
115660 +#define ADDR_SPACE_PERCPU 0
115661 +#define ADDR_SPACE_FORCE_PERCPU 0
115662 +#define ADDR_SPACE_RCU 0
115663 +#define ADDR_SPACE_FORCE_RCU 0
115664 +
115665 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
115666 +{
115667 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
115668 +}
115669 +
115670 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
115671 +{
115672 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
115673 +}
115674 +
115675 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
115676 +{
115677 + return default_addr_space_valid_pointer_mode(mode, as);
115678 +}
115679 +
115680 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
115681 +{
115682 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
115683 +}
115684 +
115685 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
115686 +{
115687 + return default_addr_space_legitimize_address(x, oldx, mode, as);
115688 +}
115689 +
115690 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
115691 +{
115692 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
115693 + return true;
115694 +
115695 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
115696 + return true;
115697 +
115698 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
115699 + return true;
115700 +
115701 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
115702 + return true;
115703 +
115704 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
115705 + return true;
115706 +
115707 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
115708 + return true;
115709 +
115710 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
115711 + return true;
115712 +
115713 + return subset == superset;
115714 +}
115715 +
115716 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
115717 +{
115718 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
115719 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
115720 +
115721 + return op;
115722 +}
115723 +
115724 +static void register_checker_address_spaces(void *event_data, void *data)
115725 +{
115726 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
115727 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
115728 + c_register_addr_space("__user", ADDR_SPACE_USER);
115729 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
115730 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
115731 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
115732 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
115733 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
115734 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
115735 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
115736 +
115737 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
115738 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
115739 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
115740 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
115741 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
115742 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
115743 + targetm.addr_space.convert = checker_addr_space_convert;
115744 +}
115745 +
115746 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
115747 +{
115748 + const char * const plugin_name = plugin_info->base_name;
115749 + const int argc = plugin_info->argc;
115750 + const struct plugin_argument * const argv = plugin_info->argv;
115751 + int i;
115752 +
115753 + if (!plugin_default_version_check(version, &gcc_version)) {
115754 + error(G_("incompatible gcc/plugin versions"));
115755 + return 1;
115756 + }
115757 +
115758 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
115759 +
115760 + for (i = 0; i < argc; ++i)
115761 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
115762 +
115763 + if (TARGET_64BIT == 0)
115764 + return 0;
115765 +
115766 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
115767 +
115768 + return 0;
115769 +}
115770 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
115771 new file mode 100644
115772 index 0000000..54461af
115773 --- /dev/null
115774 +++ b/tools/gcc/colorize_plugin.c
115775 @@ -0,0 +1,210 @@
115776 +/*
115777 + * Copyright 2012-2014 by PaX Team <pageexec@freemail.hu>
115778 + * Licensed under the GPL v2
115779 + *
115780 + * Note: the choice of the license means that the compilation process is
115781 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
115782 + * but for the kernel it doesn't matter since it doesn't link against
115783 + * any of the gcc libraries
115784 + *
115785 + * gcc plugin to colorize diagnostic output
115786 + *
115787 + */
115788 +
115789 +#include "gcc-common.h"
115790 +
115791 +int plugin_is_GPL_compatible;
115792 +
115793 +static struct plugin_info colorize_plugin_info = {
115794 + .version = "201404202350",
115795 + .help = "color=[never|always|auto]\tdetermine when to colorize\n",
115796 +};
115797 +
115798 +#define GREEN "\033[32m\033[K"
115799 +#define LIGHTGREEN "\033[1;32m\033[K"
115800 +#define YELLOW "\033[33m\033[K"
115801 +#define LIGHTYELLOW "\033[1;33m\033[K"
115802 +#define RED "\033[31m\033[K"
115803 +#define LIGHTRED "\033[1;31m\033[K"
115804 +#define BLUE "\033[34m\033[K"
115805 +#define LIGHTBLUE "\033[1;34m\033[K"
115806 +#define BRIGHT "\033[1;m\033[K"
115807 +#define NORMAL "\033[m\033[K"
115808 +
115809 +static diagnostic_starter_fn old_starter;
115810 +static diagnostic_finalizer_fn old_finalizer;
115811 +
115812 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
115813 +{
115814 + const char *color;
115815 + char *newprefix;
115816 +
115817 + switch (diagnostic->kind) {
115818 + case DK_NOTE:
115819 + color = LIGHTBLUE;
115820 + break;
115821 +
115822 + case DK_PEDWARN:
115823 + case DK_WARNING:
115824 + color = LIGHTYELLOW;
115825 + break;
115826 +
115827 + case DK_ERROR:
115828 + case DK_FATAL:
115829 + case DK_ICE:
115830 + case DK_PERMERROR:
115831 + case DK_SORRY:
115832 + color = LIGHTRED;
115833 + break;
115834 +
115835 + default:
115836 + color = NORMAL;
115837 + }
115838 +
115839 + old_starter(context, diagnostic);
115840 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
115841 + return;
115842 + pp_destroy_prefix(context->printer);
115843 + pp_set_prefix(context->printer, newprefix);
115844 +}
115845 +
115846 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
115847 +{
115848 + old_finalizer(context, diagnostic);
115849 +}
115850 +
115851 +static void colorize_arm(void)
115852 +{
115853 + old_starter = diagnostic_starter(global_dc);
115854 + old_finalizer = diagnostic_finalizer(global_dc);
115855 +
115856 + diagnostic_starter(global_dc) = start_colorize;
115857 + diagnostic_finalizer(global_dc) = finalize_colorize;
115858 +}
115859 +
115860 +static unsigned int execute_colorize_rearm(void)
115861 +{
115862 + if (diagnostic_starter(global_dc) == start_colorize)
115863 + return 0;
115864 +
115865 + colorize_arm();
115866 + return 0;
115867 +}
115868 +
115869 +#if BUILDING_GCC_VERSION >= 4009
115870 +static const struct pass_data colorize_rearm_pass_data = {
115871 +#else
115872 +struct simple_ipa_opt_pass colorize_rearm_pass = {
115873 + .pass = {
115874 +#endif
115875 + .type = SIMPLE_IPA_PASS,
115876 + .name = "colorize_rearm",
115877 +#if BUILDING_GCC_VERSION >= 4008
115878 + .optinfo_flags = OPTGROUP_NONE,
115879 +#endif
115880 +#if BUILDING_GCC_VERSION >= 4009
115881 + .has_gate = false,
115882 + .has_execute = true,
115883 +#else
115884 + .gate = NULL,
115885 + .execute = execute_colorize_rearm,
115886 + .sub = NULL,
115887 + .next = NULL,
115888 + .static_pass_number = 0,
115889 +#endif
115890 + .tv_id = TV_NONE,
115891 + .properties_required = 0,
115892 + .properties_provided = 0,
115893 + .properties_destroyed = 0,
115894 + .todo_flags_start = 0,
115895 + .todo_flags_finish = 0
115896 +#if BUILDING_GCC_VERSION < 4009
115897 + }
115898 +#endif
115899 +};
115900 +
115901 +#if BUILDING_GCC_VERSION >= 4009
115902 +namespace {
115903 +class colorize_rearm_pass : public simple_ipa_opt_pass {
115904 +public:
115905 + colorize_rearm_pass() : simple_ipa_opt_pass(colorize_rearm_pass_data, g) {}
115906 + unsigned int execute() { return execute_colorize_rearm(); }
115907 +};
115908 +}
115909 +
115910 +static opt_pass *make_colorize_rearm_pass(void)
115911 +{
115912 + return new colorize_rearm_pass();
115913 +}
115914 +#else
115915 +static struct opt_pass *make_colorize_rearm_pass(void)
115916 +{
115917 + return &colorize_rearm_pass.pass;
115918 +}
115919 +#endif
115920 +
115921 +static void colorize_start_unit(void *gcc_data, void *user_data)
115922 +{
115923 + colorize_arm();
115924 +}
115925 +
115926 +static bool should_colorize(void)
115927 +{
115928 +#if BUILDING_GCC_VERSION >= 4009
115929 + return false;
115930 +#else
115931 + char const *t = getenv("TERM");
115932 +
115933 + return t && strcmp(t, "dumb") && isatty(STDERR_FILENO);
115934 +#endif
115935 +}
115936 +
115937 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
115938 +{
115939 + const char * const plugin_name = plugin_info->base_name;
115940 + const int argc = plugin_info->argc;
115941 + const struct plugin_argument * const argv = plugin_info->argv;
115942 + int i;
115943 + struct register_pass_info colorize_rearm_pass_info;
115944 + bool colorize;
115945 +
115946 + colorize_rearm_pass_info.pass = make_colorize_rearm_pass();
115947 + colorize_rearm_pass_info.reference_pass_name = "*free_lang_data";
115948 + colorize_rearm_pass_info.ref_pass_instance_number = 1;
115949 + colorize_rearm_pass_info.pos_op = PASS_POS_INSERT_AFTER;
115950 +
115951 + if (!plugin_default_version_check(version, &gcc_version)) {
115952 + error(G_("incompatible gcc/plugin versions"));
115953 + return 1;
115954 + }
115955 +
115956 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
115957 +
115958 + colorize = getenv("GCC_COLORS") ? should_colorize() : false;
115959 +
115960 + for (i = 0; i < argc; ++i) {
115961 + if (!strcmp(argv[i].key, "color")) {
115962 + if (!argv[i].value) {
115963 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
115964 + continue;
115965 + }
115966 + if (!strcmp(argv[i].value, "always"))
115967 + colorize = true;
115968 + else if (!strcmp(argv[i].value, "never"))
115969 + colorize = false;
115970 + else if (!strcmp(argv[i].value, "auto"))
115971 + colorize = should_colorize();
115972 + else
115973 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
115974 + continue;
115975 + }
115976 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
115977 + }
115978 +
115979 + if (colorize) {
115980 + // TODO: parse GCC_COLORS as used by gcc 4.9+
115981 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
115982 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
115983 + }
115984 + return 0;
115985 +}
115986 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
115987 new file mode 100644
115988 index 0000000..82bc5a8
115989 --- /dev/null
115990 +++ b/tools/gcc/constify_plugin.c
115991 @@ -0,0 +1,557 @@
115992 +/*
115993 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
115994 + * Copyright 2011-2014 by PaX Team <pageexec@freemail.hu>
115995 + * Licensed under the GPL v2, or (at your option) v3
115996 + *
115997 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
115998 + *
115999 + * Homepage:
116000 + * http://www.grsecurity.net/~ephox/const_plugin/
116001 + *
116002 + * Usage:
116003 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
116004 + * $ gcc -fplugin=constify_plugin.so test.c -O2
116005 + */
116006 +
116007 +#include "gcc-common.h"
116008 +
116009 +// unused C type flag in all versions 4.5-4.9
116010 +#define TYPE_CONSTIFY_VISITED(TYPE) TYPE_LANG_FLAG_4(TYPE)
116011 +
116012 +int plugin_is_GPL_compatible;
116013 +
116014 +static struct plugin_info const_plugin_info = {
116015 + .version = "201401270210",
116016 + .help = "no-constify\tturn off constification\n",
116017 +};
116018 +
116019 +typedef struct {
116020 + bool has_fptr_field;
116021 + bool has_writable_field;
116022 + bool has_do_const_field;
116023 + bool has_no_const_field;
116024 +} constify_info;
116025 +
116026 +static const_tree get_field_type(const_tree field)
116027 +{
116028 + return strip_array_types(TREE_TYPE(field));
116029 +}
116030 +
116031 +static bool is_fptr(const_tree field)
116032 +{
116033 + const_tree ptr = get_field_type(field);
116034 +
116035 + if (TREE_CODE(ptr) != POINTER_TYPE)
116036 + return false;
116037 +
116038 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
116039 +}
116040 +
116041 +/*
116042 + * determine whether the given structure type meets the requirements for automatic constification,
116043 + * including the constification attributes on nested structure types
116044 + */
116045 +static void constifiable(const_tree node, constify_info *cinfo)
116046 +{
116047 + const_tree field;
116048 +
116049 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
116050 +
116051 + // e.g., pointer to structure fields while still constructing the structure type
116052 + if (TYPE_FIELDS(node) == NULL_TREE)
116053 + return;
116054 +
116055 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
116056 + const_tree type = get_field_type(field);
116057 + enum tree_code code = TREE_CODE(type);
116058 +
116059 + if (node == type)
116060 + continue;
116061 +
116062 + if (is_fptr(field))
116063 + cinfo->has_fptr_field = true;
116064 + else if (!TREE_READONLY(field))
116065 + cinfo->has_writable_field = true;
116066 +
116067 + if (code == RECORD_TYPE || code == UNION_TYPE) {
116068 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
116069 + cinfo->has_do_const_field = true;
116070 + else if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
116071 + cinfo->has_no_const_field = true;
116072 + else
116073 + constifiable(type, cinfo);
116074 + }
116075 + }
116076 +}
116077 +
116078 +static bool constified(const_tree node)
116079 +{
116080 + constify_info cinfo = {
116081 + .has_fptr_field = false,
116082 + .has_writable_field = false,
116083 + .has_do_const_field = false,
116084 + .has_no_const_field = false
116085 + };
116086 +
116087 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
116088 +
116089 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
116090 +// gcc_assert(!TYPE_READONLY(node));
116091 + return false;
116092 + }
116093 +
116094 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(node))) {
116095 + gcc_assert(TYPE_READONLY(node));
116096 + return true;
116097 + }
116098 +
116099 + constifiable(node, &cinfo);
116100 + if ((!cinfo.has_fptr_field || cinfo.has_writable_field) && !cinfo.has_do_const_field)
116101 + return false;
116102 +
116103 + return TYPE_READONLY(node);
116104 +}
116105 +
116106 +static void deconstify_tree(tree node);
116107 +
116108 +static void deconstify_type(tree type)
116109 +{
116110 + tree field;
116111 +
116112 + gcc_assert(TREE_CODE(type) == RECORD_TYPE || TREE_CODE(type) == UNION_TYPE);
116113 +
116114 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
116115 + const_tree fieldtype = get_field_type(field);
116116 +
116117 + // special case handling of simple ptr-to-same-array-type members
116118 + if (TREE_CODE(TREE_TYPE(field)) == POINTER_TYPE) {
116119 + tree ptrtype = TREE_TYPE(TREE_TYPE(field));
116120 +
116121 + if (TREE_TYPE(TREE_TYPE(field)) == type)
116122 + continue;
116123 + if (TREE_CODE(ptrtype) != RECORD_TYPE && TREE_CODE(ptrtype) != UNION_TYPE)
116124 + continue;
116125 + if (!constified(ptrtype))
116126 + continue;
116127 + if (TYPE_MAIN_VARIANT(ptrtype) == TYPE_MAIN_VARIANT(type)) {
116128 + TREE_TYPE(field) = copy_node(TREE_TYPE(field));
116129 + TREE_TYPE(TREE_TYPE(field)) = build_qualified_type(type, TYPE_QUALS(ptrtype) & ~TYPE_QUAL_CONST);
116130 + }
116131 + continue;
116132 + }
116133 + if (TREE_CODE(fieldtype) != RECORD_TYPE && TREE_CODE(fieldtype) != UNION_TYPE)
116134 + continue;
116135 + if (!constified(fieldtype))
116136 + continue;
116137 +
116138 + deconstify_tree(field);
116139 + TREE_READONLY(field) = 0;
116140 + }
116141 + TYPE_READONLY(type) = 0;
116142 + C_TYPE_FIELDS_READONLY(type) = 0;
116143 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
116144 + TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
116145 + TYPE_ATTRIBUTES(type) = remove_attribute("do_const", TYPE_ATTRIBUTES(type));
116146 + }
116147 +}
116148 +
116149 +static void deconstify_tree(tree node)
116150 +{
116151 + tree old_type, new_type, field;
116152 +
116153 + old_type = TREE_TYPE(node);
116154 + while (TREE_CODE(old_type) == ARRAY_TYPE && TREE_CODE(TREE_TYPE(old_type)) != ARRAY_TYPE) {
116155 + node = TREE_TYPE(node) = copy_node(old_type);
116156 + old_type = TREE_TYPE(old_type);
116157 + }
116158 +
116159 + gcc_assert(TREE_CODE(old_type) == RECORD_TYPE || TREE_CODE(old_type) == UNION_TYPE);
116160 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
116161 +
116162 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
116163 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
116164 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
116165 + DECL_FIELD_CONTEXT(field) = new_type;
116166 +
116167 + deconstify_type(new_type);
116168 +
116169 + TREE_TYPE(node) = new_type;
116170 +}
116171 +
116172 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
116173 +{
116174 + tree type;
116175 + constify_info cinfo = {
116176 + .has_fptr_field = false,
116177 + .has_writable_field = false,
116178 + .has_do_const_field = false,
116179 + .has_no_const_field = false
116180 + };
116181 +
116182 + *no_add_attrs = true;
116183 + if (TREE_CODE(*node) == FUNCTION_DECL) {
116184 + error("%qE attribute does not apply to functions (%qF)", name, *node);
116185 + return NULL_TREE;
116186 + }
116187 +
116188 + if (TREE_CODE(*node) == PARM_DECL) {
116189 + error("%qE attribute does not apply to function parameters (%qD)", name, *node);
116190 + return NULL_TREE;
116191 + }
116192 +
116193 + if (TREE_CODE(*node) == VAR_DECL) {
116194 + error("%qE attribute does not apply to variables (%qD)", name, *node);
116195 + return NULL_TREE;
116196 + }
116197 +
116198 + if (TYPE_P(*node)) {
116199 + type = *node;
116200 + } else {
116201 + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
116202 + type = TREE_TYPE(*node);
116203 + }
116204 +
116205 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
116206 + error("%qE attribute used on %qT applies to struct and union types only", name, type);
116207 + return NULL_TREE;
116208 + }
116209 +
116210 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
116211 + error("%qE attribute is already applied to the type %qT", name, type);
116212 + return NULL_TREE;
116213 + }
116214 +
116215 + if (TYPE_P(*node)) {
116216 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
116217 + error("%qE attribute used on type %qT is incompatible with 'do_const'", name, type);
116218 + else
116219 + *no_add_attrs = false;
116220 + return NULL_TREE;
116221 + }
116222 +
116223 + constifiable(type, &cinfo);
116224 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
116225 + deconstify_tree(*node);
116226 + TYPE_CONSTIFY_VISITED(TREE_TYPE(*node)) = 1;
116227 + return NULL_TREE;
116228 + }
116229 +
116230 + error("%qE attribute used on type %qT that is not constified", name, type);
116231 + return NULL_TREE;
116232 +}
116233 +
116234 +static void constify_type(tree type)
116235 +{
116236 + TYPE_READONLY(type) = 1;
116237 + C_TYPE_FIELDS_READONLY(type) = 1;
116238 + TYPE_CONSTIFY_VISITED(type) = 1;
116239 +// TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
116240 +// TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("do_const"), NULL_TREE, TYPE_ATTRIBUTES(type));
116241 +}
116242 +
116243 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
116244 +{
116245 + *no_add_attrs = true;
116246 + if (!TYPE_P(*node)) {
116247 + error("%qE attribute applies to types only (%qD)", name, *node);
116248 + return NULL_TREE;
116249 + }
116250 +
116251 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
116252 + error("%qE attribute used on %qT applies to struct and union types only", name, *node);
116253 + return NULL_TREE;
116254 + }
116255 +
116256 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(*node))) {
116257 + error("%qE attribute used on %qT is already applied to the type", name, *node);
116258 + return NULL_TREE;
116259 + }
116260 +
116261 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(*node))) {
116262 + error("%qE attribute used on %qT is incompatible with 'no_const'", name, *node);
116263 + return NULL_TREE;
116264 + }
116265 +
116266 + *no_add_attrs = false;
116267 + return NULL_TREE;
116268 +}
116269 +
116270 +static struct attribute_spec no_const_attr = {
116271 + .name = "no_const",
116272 + .min_length = 0,
116273 + .max_length = 0,
116274 + .decl_required = false,
116275 + .type_required = false,
116276 + .function_type_required = false,
116277 + .handler = handle_no_const_attribute,
116278 +#if BUILDING_GCC_VERSION >= 4007
116279 + .affects_type_identity = true
116280 +#endif
116281 +};
116282 +
116283 +static struct attribute_spec do_const_attr = {
116284 + .name = "do_const",
116285 + .min_length = 0,
116286 + .max_length = 0,
116287 + .decl_required = false,
116288 + .type_required = false,
116289 + .function_type_required = false,
116290 + .handler = handle_do_const_attribute,
116291 +#if BUILDING_GCC_VERSION >= 4007
116292 + .affects_type_identity = true
116293 +#endif
116294 +};
116295 +
116296 +static void register_attributes(void *event_data, void *data)
116297 +{
116298 + register_attribute(&no_const_attr);
116299 + register_attribute(&do_const_attr);
116300 +}
116301 +
116302 +static void finish_type(void *event_data, void *data)
116303 +{
116304 + tree type = (tree)event_data;
116305 + constify_info cinfo = {
116306 + .has_fptr_field = false,
116307 + .has_writable_field = false,
116308 + .has_do_const_field = false,
116309 + .has_no_const_field = false
116310 + };
116311 +
116312 + if (type == NULL_TREE || type == error_mark_node)
116313 + return;
116314 +
116315 + if (TYPE_FIELDS(type) == NULL_TREE || TYPE_CONSTIFY_VISITED(type))
116316 + return;
116317 +
116318 + constifiable(type, &cinfo);
116319 +
116320 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type))) {
116321 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || cinfo.has_do_const_field) {
116322 + deconstify_type(type);
116323 + TYPE_CONSTIFY_VISITED(type) = 1;
116324 + } else
116325 + error("'no_const' attribute used on type %qT that is not constified", type);
116326 + return;
116327 + }
116328 +
116329 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
116330 + if (!cinfo.has_writable_field) {
116331 + error("'do_const' attribute used on type %qT that is%sconstified", type, cinfo.has_fptr_field ? " " : " not ");
116332 + return;
116333 + }
116334 + constify_type(type);
116335 + return;
116336 + }
116337 +
116338 + if (cinfo.has_fptr_field && !cinfo.has_writable_field) {
116339 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
116340 + error("'do_const' attribute used on type %qT that is constified", type);
116341 + return;
116342 + }
116343 + constify_type(type);
116344 + return;
116345 + }
116346 +
116347 + deconstify_type(type);
116348 + TYPE_CONSTIFY_VISITED(type) = 1;
116349 +}
116350 +
116351 +static void check_global_variables(void *event_data, void *data)
116352 +{
116353 +#if BUILDING_GCC_VERSION >= 4009
116354 + varpool_node *node;
116355 +#else
116356 + struct varpool_node *node;
116357 +#endif
116358 +
116359 + FOR_EACH_VARIABLE(node) {
116360 + tree var = NODE_DECL(node);
116361 + tree type = TREE_TYPE(var);
116362 +
116363 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
116364 + continue;
116365 +
116366 + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
116367 + continue;
116368 +
116369 + if (!TYPE_CONSTIFY_VISITED(type))
116370 + continue;
116371 +
116372 + if (DECL_EXTERNAL(var))
116373 + continue;
116374 +
116375 + if (DECL_INITIAL(var))
116376 + continue;
116377 +
116378 + // this works around a gcc bug/feature where uninitialized globals
116379 + // are moved into the .bss section regardless of any constification
116380 + DECL_INITIAL(var) = build_constructor(type, NULL);
116381 +// inform(DECL_SOURCE_LOCATION(var), "constified variable %qE moved into .rodata", var);
116382 + }
116383 +}
116384 +
116385 +static unsigned int check_local_variables(void)
116386 +{
116387 + unsigned int ret = 0;
116388 + tree var;
116389 +
116390 + unsigned int i;
116391 +
116392 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
116393 + tree type = TREE_TYPE(var);
116394 +
116395 + gcc_assert(DECL_P(var));
116396 + if (is_global_var(var))
116397 + continue;
116398 +
116399 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
116400 + continue;
116401 +
116402 + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
116403 + continue;
116404 +
116405 + if (!TYPE_CONSTIFY_VISITED(type))
116406 + continue;
116407 +
116408 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
116409 + ret = 1;
116410 + }
116411 + return ret;
116412 +}
116413 +
116414 +#if BUILDING_GCC_VERSION >= 4009
116415 +static const struct pass_data check_local_variables_pass_data = {
116416 +#else
116417 +static struct gimple_opt_pass check_local_variables_pass = {
116418 + .pass = {
116419 +#endif
116420 + .type = GIMPLE_PASS,
116421 + .name = "check_local_variables",
116422 +#if BUILDING_GCC_VERSION >= 4008
116423 + .optinfo_flags = OPTGROUP_NONE,
116424 +#endif
116425 +#if BUILDING_GCC_VERSION >= 4009
116426 + .has_gate = false,
116427 + .has_execute = true,
116428 +#else
116429 + .gate = NULL,
116430 + .execute = check_local_variables,
116431 + .sub = NULL,
116432 + .next = NULL,
116433 + .static_pass_number = 0,
116434 +#endif
116435 + .tv_id = TV_NONE,
116436 + .properties_required = 0,
116437 + .properties_provided = 0,
116438 + .properties_destroyed = 0,
116439 + .todo_flags_start = 0,
116440 + .todo_flags_finish = 0
116441 +#if BUILDING_GCC_VERSION < 4009
116442 + }
116443 +#endif
116444 +};
116445 +
116446 +#if BUILDING_GCC_VERSION >= 4009
116447 +namespace {
116448 +class check_local_variables_pass : public gimple_opt_pass {
116449 +public:
116450 + check_local_variables_pass() : gimple_opt_pass(check_local_variables_pass_data, g) {}
116451 + unsigned int execute() { return check_local_variables(); }
116452 +};
116453 +}
116454 +
116455 +static opt_pass *make_check_local_variables_pass(void)
116456 +{
116457 + return new check_local_variables_pass();
116458 +}
116459 +#else
116460 +static struct opt_pass *make_check_local_variables_pass(void)
116461 +{
116462 + return &check_local_variables_pass.pass;
116463 +}
116464 +#endif
116465 +
116466 +static struct {
116467 + const char *name;
116468 + const char *asm_op;
116469 +} sections[] = {
116470 + {".init.rodata", "\t.section\t.init.rodata,\"a\""},
116471 + {".ref.rodata", "\t.section\t.ref.rodata,\"a\""},
116472 + {".devinit.rodata", "\t.section\t.devinit.rodata,\"a\""},
116473 + {".devexit.rodata", "\t.section\t.devexit.rodata,\"a\""},
116474 + {".cpuinit.rodata", "\t.section\t.cpuinit.rodata,\"a\""},
116475 + {".cpuexit.rodata", "\t.section\t.cpuexit.rodata,\"a\""},
116476 + {".meminit.rodata", "\t.section\t.meminit.rodata,\"a\""},
116477 + {".memexit.rodata", "\t.section\t.memexit.rodata,\"a\""},
116478 + {".data..read_only", "\t.section\t.data..read_only,\"a\""},
116479 +};
116480 +
116481 +static unsigned int (*old_section_type_flags)(tree decl, const char *name, int reloc);
116482 +
116483 +static unsigned int constify_section_type_flags(tree decl, const char *name, int reloc)
116484 +{
116485 + size_t i;
116486 +
116487 + for (i = 0; i < ARRAY_SIZE(sections); i++)
116488 + if (!strcmp(sections[i].name, name))
116489 + return 0;
116490 + return old_section_type_flags(decl, name, reloc);
116491 +}
116492 +
116493 +static void constify_start_unit(void *gcc_data, void *user_data)
116494 +{
116495 +// size_t i;
116496 +
116497 +// for (i = 0; i < ARRAY_SIZE(sections); i++)
116498 +// sections[i].section = get_unnamed_section(0, output_section_asm_op, sections[i].asm_op);
116499 +// sections[i].section = get_section(sections[i].name, 0, NULL);
116500 +
116501 + old_section_type_flags = targetm.section_type_flags;
116502 + targetm.section_type_flags = constify_section_type_flags;
116503 +}
116504 +
116505 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
116506 +{
116507 + const char * const plugin_name = plugin_info->base_name;
116508 + const int argc = plugin_info->argc;
116509 + const struct plugin_argument * const argv = plugin_info->argv;
116510 + int i;
116511 + bool constify = true;
116512 +
116513 + struct register_pass_info check_local_variables_pass_info;
116514 +
116515 + check_local_variables_pass_info.pass = make_check_local_variables_pass();
116516 + check_local_variables_pass_info.reference_pass_name = "ssa";
116517 + check_local_variables_pass_info.ref_pass_instance_number = 1;
116518 + check_local_variables_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
116519 +
116520 + if (!plugin_default_version_check(version, &gcc_version)) {
116521 + error(G_("incompatible gcc/plugin versions"));
116522 + return 1;
116523 + }
116524 +
116525 + for (i = 0; i < argc; ++i) {
116526 + if (!(strcmp(argv[i].key, "no-constify"))) {
116527 + constify = false;
116528 + continue;
116529 + }
116530 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
116531 + }
116532 +
116533 + if (strcmp(lang_hooks.name, "GNU C")) {
116534 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
116535 + constify = false;
116536 + }
116537 +
116538 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
116539 + if (constify) {
116540 + register_callback(plugin_name, PLUGIN_ALL_IPA_PASSES_START, check_global_variables, NULL);
116541 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
116542 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &check_local_variables_pass_info);
116543 + register_callback(plugin_name, PLUGIN_START_UNIT, constify_start_unit, NULL);
116544 + }
116545 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
116546 +
116547 + return 0;
116548 +}
116549 diff --git a/tools/gcc/gcc-common.h b/tools/gcc/gcc-common.h
116550 new file mode 100644
116551 index 0000000..e90c205
116552 --- /dev/null
116553 +++ b/tools/gcc/gcc-common.h
116554 @@ -0,0 +1,295 @@
116555 +#ifndef GCC_COMMON_H_INCLUDED
116556 +#define GCC_COMMON_H_INCLUDED
116557 +
116558 +#include "plugin.h"
116559 +#include "bversion.h"
116560 +#include "plugin-version.h"
116561 +#include "config.h"
116562 +#include "system.h"
116563 +#include "coretypes.h"
116564 +#include "tm.h"
116565 +#include "line-map.h"
116566 +#include "input.h"
116567 +#include "tree.h"
116568 +
116569 +#include "tree-inline.h"
116570 +#include "version.h"
116571 +#include "rtl.h"
116572 +#include "tm_p.h"
116573 +#include "flags.h"
116574 +//#include "insn-attr.h"
116575 +//#include "insn-config.h"
116576 +//#include "insn-flags.h"
116577 +#include "hard-reg-set.h"
116578 +//#include "recog.h"
116579 +#include "output.h"
116580 +#include "except.h"
116581 +#include "function.h"
116582 +#include "toplev.h"
116583 +//#include "expr.h"
116584 +#include "basic-block.h"
116585 +#include "intl.h"
116586 +#include "ggc.h"
116587 +//#include "regs.h"
116588 +#include "timevar.h"
116589 +
116590 +#include "params.h"
116591 +#include "pointer-set.h"
116592 +#include "emit-rtl.h"
116593 +//#include "reload.h"
116594 +//#include "ira.h"
116595 +//#include "dwarf2asm.h"
116596 +#include "debug.h"
116597 +#include "target.h"
116598 +#include "langhooks.h"
116599 +#include "cfgloop.h"
116600 +//#include "hosthooks.h"
116601 +#include "cgraph.h"
116602 +#include "opts.h"
116603 +//#include "coverage.h"
116604 +//#include "value-prof.h"
116605 +
116606 +#if BUILDING_GCC_VERSION >= 4007
116607 +#include "tree-pretty-print.h"
116608 +#include "gimple-pretty-print.h"
116609 +#include "c-tree.h"
116610 +//#include "alloc-pool.h"
116611 +#endif
116612 +
116613 +#if BUILDING_GCC_VERSION <= 4008
116614 +#include "tree-flow.h"
116615 +#else
116616 +#include "tree-cfgcleanup.h"
116617 +#endif
116618 +
116619 +#include "diagnostic.h"
116620 +//#include "tree-diagnostic.h"
116621 +#include "tree-dump.h"
116622 +#include "tree-pass.h"
116623 +//#include "df.h"
116624 +#include "predict.h"
116625 +#include "ipa-utils.h"
116626 +
116627 +#if BUILDING_GCC_VERSION >= 4009
116628 +#include "varasm.h"
116629 +#include "stor-layout.h"
116630 +#include "internal-fn.h"
116631 +#include "gimple-expr.h"
116632 +//#include "diagnostic-color.h"
116633 +#include "context.h"
116634 +#include "tree-ssa-alias.h"
116635 +#include "stringpool.h"
116636 +#include "tree-ssanames.h"
116637 +#include "print-tree.h"
116638 +#include "tree-eh.h"
116639 +#include "stmt.h"
116640 +#endif
116641 +
116642 +#include "gimple.h"
116643 +
116644 +#if BUILDING_GCC_VERSION >= 4009
116645 +#include "tree-ssa-operands.h"
116646 +#include "tree-phinodes.h"
116647 +#include "tree-cfg.h"
116648 +#include "gimple-iterator.h"
116649 +#include "gimple-ssa.h"
116650 +#include "ssa-iterators.h"
116651 +#endif
116652 +
116653 +//#include "lto/lto.h"
116654 +//#include "data-streamer.h"
116655 +//#include "lto-compress.h"
116656 +
116657 +//#include "expr.h" where are you...
116658 +extern rtx emit_move_insn(rtx x, rtx y);
116659 +
116660 +// missing from basic_block.h...
116661 +extern void debug_dominance_info(enum cdi_direction dir);
116662 +extern void debug_dominance_tree(enum cdi_direction dir, basic_block root);
116663 +
116664 +#define __unused __attribute__((__unused__))
116665 +
116666 +#define DECL_NAME_POINTER(node) IDENTIFIER_POINTER(DECL_NAME(node))
116667 +#define DECL_NAME_LENGTH(node) IDENTIFIER_LENGTH(DECL_NAME(node))
116668 +#define TYPE_NAME_POINTER(node) IDENTIFIER_POINTER(TYPE_NAME(node))
116669 +#define TYPE_NAME_LENGTH(node) IDENTIFIER_LENGTH(TYPE_NAME(node))
116670 +
116671 +#if BUILDING_GCC_VERSION == 4005
116672 +#define FOR_EACH_LOCAL_DECL(FUN, I, D) for (tree vars = (FUN)->local_decls; vars && (D = TREE_VALUE(vars)); vars = TREE_CHAIN(vars), I)
116673 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
116674 +#define FOR_EACH_VEC_ELT(T, V, I, P) for (I = 0; VEC_iterate(T, (V), (I), (P)); ++(I))
116675 +#define TODO_rebuild_cgraph_edges 0
116676 +
116677 +static inline bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
116678 +{
116679 + tree fndecl;
116680 +
116681 + if (!is_gimple_call(stmt))
116682 + return false;
116683 + fndecl = gimple_call_fndecl(stmt);
116684 + if (!fndecl || DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
116685 + return false;
116686 +// print_node(stderr, "pax", fndecl, 4);
116687 + return DECL_FUNCTION_CODE(fndecl) == code;
116688 +}
116689 +
116690 +static inline bool is_simple_builtin(tree decl)
116691 +{
116692 + if (decl && DECL_BUILT_IN_CLASS(decl) != BUILT_IN_NORMAL)
116693 + return false;
116694 +
116695 + switch (DECL_FUNCTION_CODE(decl)) {
116696 + /* Builtins that expand to constants. */
116697 + case BUILT_IN_CONSTANT_P:
116698 + case BUILT_IN_EXPECT:
116699 + case BUILT_IN_OBJECT_SIZE:
116700 + case BUILT_IN_UNREACHABLE:
116701 + /* Simple register moves or loads from stack. */
116702 + case BUILT_IN_RETURN_ADDRESS:
116703 + case BUILT_IN_EXTRACT_RETURN_ADDR:
116704 + case BUILT_IN_FROB_RETURN_ADDR:
116705 + case BUILT_IN_RETURN:
116706 + case BUILT_IN_AGGREGATE_INCOMING_ADDRESS:
116707 + case BUILT_IN_FRAME_ADDRESS:
116708 + case BUILT_IN_VA_END:
116709 + case BUILT_IN_STACK_SAVE:
116710 + case BUILT_IN_STACK_RESTORE:
116711 + /* Exception state returns or moves registers around. */
116712 + case BUILT_IN_EH_FILTER:
116713 + case BUILT_IN_EH_POINTER:
116714 + case BUILT_IN_EH_COPY_VALUES:
116715 + return true;
116716 +
116717 + default:
116718 + return false;
116719 + }
116720 +}
116721 +#endif
116722 +
116723 +#if BUILDING_GCC_VERSION <= 4006
116724 +#define ANY_RETURN_P(rtx) (GET_CODE(rtx) == RETURN)
116725 +#define C_DECL_REGISTER(EXP) DECL_LANG_FLAG_4(EXP)
116726 +
116727 +// should come from c-tree.h if only it were installed for gcc 4.5...
116728 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
116729 +
116730 +#define get_random_seed(noinit) ({ \
116731 + unsigned HOST_WIDE_INT seed; \
116732 + sscanf(get_random_seed(noinit), "%" HOST_WIDE_INT_PRINT "x", &seed); \
116733 + seed * seed; })
116734 +
116735 +static inline bool gimple_clobber_p(gimple s)
116736 +{
116737 + return false;
116738 +}
116739 +
116740 +static inline tree builtin_decl_implicit(enum built_in_function fncode)
116741 +{
116742 + return implicit_built_in_decls[fncode];
116743 +}
116744 +
116745 +static inline struct cgraph_node *cgraph_get_create_node(tree decl)
116746 +{
116747 + struct cgraph_node *node = cgraph_get_node(decl);
116748 +
116749 + return node ? node : cgraph_node(decl);
116750 +}
116751 +
116752 +static inline bool cgraph_function_with_gimple_body_p(struct cgraph_node *node)
116753 +{
116754 + return node->analyzed && !node->thunk.thunk_p && !node->alias;
116755 +}
116756 +
116757 +static inline struct cgraph_node *cgraph_first_function_with_gimple_body(void)
116758 +{
116759 + struct cgraph_node *node;
116760 +
116761 + for (node = cgraph_nodes; node; node = node->next)
116762 + if (cgraph_function_with_gimple_body_p(node))
116763 + return node;
116764 + return NULL;
116765 +}
116766 +
116767 +static inline struct cgraph_node *cgraph_next_function_with_gimple_body(struct cgraph_node *node)
116768 +{
116769 + for (node = node->next; node; node = node->next)
116770 + if (cgraph_function_with_gimple_body_p(node))
116771 + return node;
116772 + return NULL;
116773 +}
116774 +
116775 +#define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
116776 + for ((node) = cgraph_first_function_with_gimple_body(); (node); \
116777 + (node) = cgraph_next_function_with_gimple_body(node))
116778 +#endif
116779 +
116780 +#if BUILDING_GCC_VERSION == 4006
116781 +extern void debug_gimple_stmt(gimple);
116782 +extern void debug_gimple_seq(gimple_seq);
116783 +extern void print_gimple_seq(FILE *, gimple_seq, int, int);
116784 +extern void print_gimple_stmt(FILE *, gimple, int, int);
116785 +extern void print_gimple_expr(FILE *, gimple, int, int);
116786 +extern void dump_gimple_stmt(pretty_printer *, gimple, int, int);
116787 +#endif
116788 +
116789 +#if BUILDING_GCC_VERSION <= 4007
116790 +#define FOR_EACH_VARIABLE(node) for (node = varpool_nodes; node; node = node->next)
116791 +#define PROP_loops 0
116792 +
116793 +static inline int bb_loop_depth(const_basic_block bb)
116794 +{
116795 + return bb->loop_father ? loop_depth(bb->loop_father) : 0;
116796 +}
116797 +
116798 +static inline bool gimple_store_p(gimple gs)
116799 +{
116800 + tree lhs = gimple_get_lhs(gs);
116801 + return lhs && !is_gimple_reg(lhs);
116802 +}
116803 +#endif
116804 +
116805 +#if BUILDING_GCC_VERSION >= 4007
116806 +#define cgraph_create_edge(caller, callee, call_stmt, count, freq, nest) \
116807 + cgraph_create_edge((caller), (callee), (call_stmt), (count), (freq))
116808 +#define cgraph_create_edge_including_clones(caller, callee, old_call_stmt, call_stmt, count, freq, nest, reason) \
116809 + cgraph_create_edge_including_clones((caller), (callee), (old_call_stmt), (call_stmt), (count), (freq), (reason))
116810 +#endif
116811 +
116812 +#if BUILDING_GCC_VERSION <= 4008
116813 +#define ENTRY_BLOCK_PTR_FOR_FN(FN) ENTRY_BLOCK_PTR_FOR_FUNCTION(FN)
116814 +#define EXIT_BLOCK_PTR_FOR_FN(FN) EXIT_BLOCK_PTR_FOR_FUNCTION(FN)
116815 +#define basic_block_info_for_fn(FN) ((FN)->cfg->x_basic_block_info)
116816 +#define n_basic_blocks_for_fn(FN) ((FN)->cfg->x_n_basic_blocks)
116817 +#define n_edges_for_fn(FN) ((FN)->cfg->x_n_edges)
116818 +#define last_basic_block_for_fn(FN) ((FN)->cfg->x_last_basic_block)
116819 +#define label_to_block_map_for_fn(FN) ((FN)->cfg->x_label_to_block_map)
116820 +#define profile_status_for_fn(FN) ((FN)->cfg->x_profile_status)
116821 +
116822 +static inline const char *get_tree_code_name(enum tree_code code)
116823 +{
116824 + gcc_assert(code < MAX_TREE_CODES);
116825 + return tree_code_name[code];
116826 +}
116827 +
116828 +#define ipa_remove_stmt_references(cnode, stmt)
116829 +#endif
116830 +
116831 +#if BUILDING_GCC_VERSION == 4008
116832 +#define NODE_DECL(node) node->symbol.decl
116833 +#else
116834 +#define NODE_DECL(node) node->decl
116835 +#endif
116836 +
116837 +#if BUILDING_GCC_VERSION >= 4008
116838 +#define add_referenced_var(var)
116839 +#define mark_sym_for_renaming(var)
116840 +#define varpool_mark_needed_node(node)
116841 +#define TODO_dump_func 0
116842 +#define TODO_dump_cgraph 0
116843 +#endif
116844 +
116845 +#if BUILDING_GCC_VERSION >= 4009
116846 +#define TODO_ggc_collect 0
116847 +#endif
116848 +
116849 +#endif
116850 diff --git a/tools/gcc/gen-random-seed.sh b/tools/gcc/gen-random-seed.sh
116851 new file mode 100644
116852 index 0000000..7514850
116853 --- /dev/null
116854 +++ b/tools/gcc/gen-random-seed.sh
116855 @@ -0,0 +1,8 @@
116856 +#!/bin/sh
116857 +
116858 +if [ ! -f "$1" ]; then
116859 + SEED=`od -A n -t x8 -N 32 /dev/urandom | tr -d ' \n'`
116860 + echo "const char *randstruct_seed = \"$SEED\";" > "$1"
116861 + HASH=`echo -n "$SEED" | sha256sum | cut -d" " -f1 | tr -d ' \n'`
116862 + echo "#define RANDSTRUCT_HASHED_SEED \"$HASH\"" > "$2"
116863 +fi
116864 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
116865 new file mode 100644
116866 index 0000000..d81c094
116867 --- /dev/null
116868 +++ b/tools/gcc/kallocstat_plugin.c
116869 @@ -0,0 +1,183 @@
116870 +/*
116871 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
116872 + * Licensed under the GPL v2
116873 + *
116874 + * Note: the choice of the license means that the compilation process is
116875 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
116876 + * but for the kernel it doesn't matter since it doesn't link against
116877 + * any of the gcc libraries
116878 + *
116879 + * gcc plugin to find the distribution of k*alloc sizes
116880 + *
116881 + * TODO:
116882 + *
116883 + * BUGS:
116884 + * - none known
116885 + */
116886 +
116887 +#include "gcc-common.h"
116888 +
116889 +int plugin_is_GPL_compatible;
116890 +
116891 +static struct plugin_info kallocstat_plugin_info = {
116892 + .version = "201401260140",
116893 + .help = NULL
116894 +};
116895 +
116896 +static const char * const kalloc_functions[] = {
116897 + "__kmalloc",
116898 + "kmalloc",
116899 + "kmalloc_large",
116900 + "kmalloc_node",
116901 + "kmalloc_order",
116902 + "kmalloc_order_trace",
116903 + "kmalloc_slab",
116904 + "kzalloc",
116905 + "kzalloc_node",
116906 +};
116907 +
116908 +static bool is_kalloc(const char *fnname)
116909 +{
116910 + size_t i;
116911 +
116912 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
116913 + if (!strcmp(fnname, kalloc_functions[i]))
116914 + return true;
116915 + return false;
116916 +}
116917 +
116918 +static unsigned int execute_kallocstat(void)
116919 +{
116920 + basic_block bb;
116921 +
116922 + // 1. loop through BBs and GIMPLE statements
116923 + FOR_EACH_BB_FN(bb, cfun) {
116924 + gimple_stmt_iterator gsi;
116925 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
116926 + // gimple match:
116927 + tree fndecl, size;
116928 + gimple stmt;
116929 + const char *fnname;
116930 +
116931 + // is it a call
116932 + stmt = gsi_stmt(gsi);
116933 + if (!is_gimple_call(stmt))
116934 + continue;
116935 + fndecl = gimple_call_fndecl(stmt);
116936 + if (fndecl == NULL_TREE)
116937 + continue;
116938 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
116939 + continue;
116940 +
116941 + // is it a call to k*alloc
116942 + fnname = DECL_NAME_POINTER(fndecl);
116943 + if (!is_kalloc(fnname))
116944 + continue;
116945 +
116946 + // is the size arg const or the result of a simple const assignment
116947 + size = gimple_call_arg(stmt, 0);
116948 + while (true) {
116949 + expanded_location xloc;
116950 + size_t size_val;
116951 +
116952 + if (TREE_CONSTANT(size)) {
116953 + xloc = expand_location(gimple_location(stmt));
116954 + if (!xloc.file)
116955 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
116956 + size_val = TREE_INT_CST_LOW(size);
116957 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
116958 + break;
116959 + }
116960 +
116961 + if (TREE_CODE(size) != SSA_NAME)
116962 + break;
116963 + stmt = SSA_NAME_DEF_STMT(size);
116964 +//debug_gimple_stmt(stmt);
116965 +//debug_tree(size);
116966 + if (!stmt || !is_gimple_assign(stmt))
116967 + break;
116968 + if (gimple_num_ops(stmt) != 2)
116969 + break;
116970 + size = gimple_assign_rhs1(stmt);
116971 + }
116972 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
116973 +//debug_tree(gimple_call_fn(call_stmt));
116974 +//print_node(stderr, "pax", fndecl, 4);
116975 + }
116976 + }
116977 +
116978 + return 0;
116979 +}
116980 +
116981 +#if BUILDING_GCC_VERSION >= 4009
116982 +static const struct pass_data kallocstat_pass_data = {
116983 +#else
116984 +static struct gimple_opt_pass kallocstat_pass = {
116985 + .pass = {
116986 +#endif
116987 + .type = GIMPLE_PASS,
116988 + .name = "kallocstat",
116989 +#if BUILDING_GCC_VERSION >= 4008
116990 + .optinfo_flags = OPTGROUP_NONE,
116991 +#endif
116992 +#if BUILDING_GCC_VERSION >= 4009
116993 + .has_gate = false,
116994 + .has_execute = true,
116995 +#else
116996 + .gate = NULL,
116997 + .execute = execute_kallocstat,
116998 + .sub = NULL,
116999 + .next = NULL,
117000 + .static_pass_number = 0,
117001 +#endif
117002 + .tv_id = TV_NONE,
117003 + .properties_required = 0,
117004 + .properties_provided = 0,
117005 + .properties_destroyed = 0,
117006 + .todo_flags_start = 0,
117007 + .todo_flags_finish = 0
117008 +#if BUILDING_GCC_VERSION < 4009
117009 + }
117010 +#endif
117011 +};
117012 +
117013 +#if BUILDING_GCC_VERSION >= 4009
117014 +namespace {
117015 +class kallocstat_pass : public gimple_opt_pass {
117016 +public:
117017 + kallocstat_pass() : gimple_opt_pass(kallocstat_pass_data, g) {}
117018 + unsigned int execute() { return execute_kallocstat(); }
117019 +};
117020 +}
117021 +
117022 +static opt_pass *make_kallocstat_pass(void)
117023 +{
117024 + return new kallocstat_pass();
117025 +}
117026 +#else
117027 +static struct opt_pass *make_kallocstat_pass(void)
117028 +{
117029 + return &kallocstat_pass.pass;
117030 +}
117031 +#endif
117032 +
117033 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
117034 +{
117035 + const char * const plugin_name = plugin_info->base_name;
117036 + struct register_pass_info kallocstat_pass_info;
117037 +
117038 + kallocstat_pass_info.pass = make_kallocstat_pass();
117039 + kallocstat_pass_info.reference_pass_name = "ssa";
117040 + kallocstat_pass_info.ref_pass_instance_number = 1;
117041 + kallocstat_pass_info.pos_op = PASS_POS_INSERT_AFTER;
117042 +
117043 + if (!plugin_default_version_check(version, &gcc_version)) {
117044 + error(G_("incompatible gcc/plugin versions"));
117045 + return 1;
117046 + }
117047 +
117048 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
117049 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
117050 +
117051 + return 0;
117052 +}
117053 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
117054 new file mode 100644
117055 index 0000000..89f256d
117056 --- /dev/null
117057 +++ b/tools/gcc/kernexec_plugin.c
117058 @@ -0,0 +1,522 @@
117059 +/*
117060 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
117061 + * Licensed under the GPL v2
117062 + *
117063 + * Note: the choice of the license means that the compilation process is
117064 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
117065 + * but for the kernel it doesn't matter since it doesn't link against
117066 + * any of the gcc libraries
117067 + *
117068 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
117069 + *
117070 + * TODO:
117071 + *
117072 + * BUGS:
117073 + * - none known
117074 + */
117075 +
117076 +#include "gcc-common.h"
117077 +
117078 +int plugin_is_GPL_compatible;
117079 +
117080 +static struct plugin_info kernexec_plugin_info = {
117081 + .version = "201401260140",
117082 + .help = "method=[bts|or]\tinstrumentation method\n"
117083 +};
117084 +
117085 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
117086 +static void (*kernexec_instrument_retaddr)(rtx);
117087 +
117088 +/*
117089 + * add special KERNEXEC instrumentation: reload %r12 after it has been clobbered
117090 + */
117091 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
117092 +{
117093 + gimple asm_movabs_stmt;
117094 +
117095 + // build asm volatile("movabs $0x8000000000000000, %%r12\n\t" : : : );
117096 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r12\n\t", NULL, NULL, NULL, NULL);
117097 + gimple_asm_set_volatile(asm_movabs_stmt, true);
117098 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
117099 + update_stmt(asm_movabs_stmt);
117100 +}
117101 +
117102 +/*
117103 + * find all asm() stmts that clobber r12 and add a reload of r12
117104 + */
117105 +static unsigned int execute_kernexec_reload(void)
117106 +{
117107 + basic_block bb;
117108 +
117109 + // 1. loop through BBs and GIMPLE statements
117110 + FOR_EACH_BB_FN(bb, cfun) {
117111 + gimple_stmt_iterator gsi;
117112 +
117113 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
117114 + // gimple match: __asm__ ("" : : : "r12");
117115 + gimple asm_stmt;
117116 + size_t nclobbers;
117117 +
117118 + // is it an asm ...
117119 + asm_stmt = gsi_stmt(gsi);
117120 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
117121 + continue;
117122 +
117123 + // ... clobbering r12
117124 + nclobbers = gimple_asm_nclobbers(asm_stmt);
117125 + while (nclobbers--) {
117126 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
117127 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r12"))
117128 + continue;
117129 + kernexec_reload_fptr_mask(&gsi);
117130 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
117131 + break;
117132 + }
117133 + }
117134 + }
117135 +
117136 + return 0;
117137 +}
117138 +
117139 +/*
117140 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
117141 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
117142 + */
117143 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
117144 +{
117145 + gimple assign_intptr, assign_new_fptr, call_stmt;
117146 + tree intptr, orptr, old_fptr, new_fptr, kernexec_mask;
117147 +
117148 + call_stmt = gsi_stmt(*gsi);
117149 + old_fptr = gimple_call_fn(call_stmt);
117150 +
117151 + // create temporary unsigned long variable used for bitops and cast fptr to it
117152 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
117153 + add_referenced_var(intptr);
117154 + intptr = make_ssa_name(intptr, NULL);
117155 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
117156 + SSA_NAME_DEF_STMT(intptr) = assign_intptr;
117157 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
117158 + update_stmt(assign_intptr);
117159 +
117160 + // apply logical or to temporary unsigned long and bitmask
117161 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
117162 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
117163 + orptr = fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask);
117164 + intptr = make_ssa_name(SSA_NAME_VAR(intptr), NULL);
117165 + assign_intptr = gimple_build_assign(intptr, orptr);
117166 + SSA_NAME_DEF_STMT(intptr) = assign_intptr;
117167 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
117168 + update_stmt(assign_intptr);
117169 +
117170 + // cast temporary unsigned long back to a temporary fptr variable
117171 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
117172 + add_referenced_var(new_fptr);
117173 + new_fptr = make_ssa_name(new_fptr, NULL);
117174 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
117175 + SSA_NAME_DEF_STMT(new_fptr) = assign_new_fptr;
117176 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
117177 + update_stmt(assign_new_fptr);
117178 +
117179 + // replace call stmt fn with the new fptr
117180 + gimple_call_set_fn(call_stmt, new_fptr);
117181 + update_stmt(call_stmt);
117182 +}
117183 +
117184 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
117185 +{
117186 + gimple asm_or_stmt, call_stmt;
117187 + tree old_fptr, new_fptr, input, output;
117188 +#if BUILDING_GCC_VERSION <= 4007
117189 + VEC(tree, gc) *inputs = NULL;
117190 + VEC(tree, gc) *outputs = NULL;
117191 +#else
117192 + vec<tree, va_gc> *inputs = NULL;
117193 + vec<tree, va_gc> *outputs = NULL;
117194 +#endif
117195 +
117196 + call_stmt = gsi_stmt(*gsi);
117197 + old_fptr = gimple_call_fn(call_stmt);
117198 +
117199 + // create temporary fptr variable
117200 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
117201 + add_referenced_var(new_fptr);
117202 + new_fptr = make_ssa_name(new_fptr, NULL);
117203 +
117204 + // build asm volatile("orq %%r12, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
117205 + input = build_tree_list(NULL_TREE, build_string(1, "0"));
117206 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
117207 + output = build_tree_list(NULL_TREE, build_string(2, "=r"));
117208 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
117209 +#if BUILDING_GCC_VERSION <= 4007
117210 + VEC_safe_push(tree, gc, inputs, input);
117211 + VEC_safe_push(tree, gc, outputs, output);
117212 +#else
117213 + vec_safe_push(inputs, input);
117214 + vec_safe_push(outputs, output);
117215 +#endif
117216 + asm_or_stmt = gimple_build_asm_vec("orq %%r12, %0\n\t", inputs, outputs, NULL, NULL);
117217 + SSA_NAME_DEF_STMT(new_fptr) = asm_or_stmt;
117218 + gimple_asm_set_volatile(asm_or_stmt, true);
117219 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
117220 + update_stmt(asm_or_stmt);
117221 +
117222 + // replace call stmt fn with the new fptr
117223 + gimple_call_set_fn(call_stmt, new_fptr);
117224 + update_stmt(call_stmt);
117225 +}
117226 +
117227 +/*
117228 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
117229 + */
117230 +static unsigned int execute_kernexec_fptr(void)
117231 +{
117232 + basic_block bb;
117233 +
117234 + // 1. loop through BBs and GIMPLE statements
117235 + FOR_EACH_BB_FN(bb, cfun) {
117236 + gimple_stmt_iterator gsi;
117237 +
117238 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
117239 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
117240 + tree fn;
117241 + gimple call_stmt;
117242 +
117243 + // is it a call ...
117244 + call_stmt = gsi_stmt(gsi);
117245 + if (!is_gimple_call(call_stmt))
117246 + continue;
117247 + fn = gimple_call_fn(call_stmt);
117248 + if (TREE_CODE(fn) == ADDR_EXPR)
117249 + continue;
117250 + if (TREE_CODE(fn) != SSA_NAME)
117251 + gcc_unreachable();
117252 +
117253 + // ... through a function pointer
117254 + if (SSA_NAME_VAR(fn) != NULL_TREE) {
117255 + fn = SSA_NAME_VAR(fn);
117256 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL) {
117257 + debug_tree(fn);
117258 + gcc_unreachable();
117259 + }
117260 + }
117261 + fn = TREE_TYPE(fn);
117262 + if (TREE_CODE(fn) != POINTER_TYPE)
117263 + continue;
117264 + fn = TREE_TYPE(fn);
117265 + if (TREE_CODE(fn) != FUNCTION_TYPE)
117266 + continue;
117267 +
117268 + kernexec_instrument_fptr(&gsi);
117269 +
117270 +//debug_tree(gimple_call_fn(call_stmt));
117271 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
117272 + }
117273 + }
117274 +
117275 + return 0;
117276 +}
117277 +
117278 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
117279 +static void kernexec_instrument_retaddr_bts(rtx insn)
117280 +{
117281 + rtx btsq;
117282 + rtvec argvec, constraintvec, labelvec;
117283 + int line;
117284 +
117285 + // create asm volatile("btsq $63,(%%rsp)":::)
117286 + argvec = rtvec_alloc(0);
117287 + constraintvec = rtvec_alloc(0);
117288 + labelvec = rtvec_alloc(0);
117289 + line = expand_location(RTL_LOCATION(insn)).line;
117290 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
117291 + MEM_VOLATILE_P(btsq) = 1;
117292 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
117293 + emit_insn_before(btsq, insn);
117294 +}
117295 +
117296 +// add special KERNEXEC instrumentation: orq %r12,(%rsp) just before retn
117297 +static void kernexec_instrument_retaddr_or(rtx insn)
117298 +{
117299 + rtx orq;
117300 + rtvec argvec, constraintvec, labelvec;
117301 + int line;
117302 +
117303 + // create asm volatile("orq %%r12,(%%rsp)":::)
117304 + argvec = rtvec_alloc(0);
117305 + constraintvec = rtvec_alloc(0);
117306 + labelvec = rtvec_alloc(0);
117307 + line = expand_location(RTL_LOCATION(insn)).line;
117308 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r12,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
117309 + MEM_VOLATILE_P(orq) = 1;
117310 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
117311 + emit_insn_before(orq, insn);
117312 +}
117313 +
117314 +/*
117315 + * find all asm level function returns and forcibly set the highest bit of the return address
117316 + */
117317 +static unsigned int execute_kernexec_retaddr(void)
117318 +{
117319 + rtx insn;
117320 +
117321 +// if (stack_realign_drap)
117322 +// inform(DECL_SOURCE_LOCATION(current_function_decl), "drap detected in %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
117323 +
117324 + // 1. find function returns
117325 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
117326 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
117327 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
117328 + // (jump_insn 97 96 98 6 (simple_return) fptr.c:50 -1 (nil) -> simple_return)
117329 + rtx body;
117330 +
117331 + // is it a retn
117332 + if (!JUMP_P(insn))
117333 + continue;
117334 + body = PATTERN(insn);
117335 + if (GET_CODE(body) == PARALLEL)
117336 + body = XVECEXP(body, 0, 0);
117337 + if (!ANY_RETURN_P(body))
117338 + continue;
117339 + kernexec_instrument_retaddr(insn);
117340 + }
117341 +
117342 +// print_simple_rtl(stderr, get_insns());
117343 +// print_rtl(stderr, get_insns());
117344 +
117345 + return 0;
117346 +}
117347 +
117348 +static bool kernexec_cmodel_check(void)
117349 +{
117350 + tree section;
117351 +
117352 + if (ix86_cmodel != CM_KERNEL)
117353 + return false;
117354 +
117355 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
117356 + if (!section || !TREE_VALUE(section))
117357 + return true;
117358 +
117359 + section = TREE_VALUE(TREE_VALUE(section));
117360 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
117361 + return true;
117362 +
117363 + return false;
117364 +}
117365 +
117366 +#if BUILDING_GCC_VERSION >= 4009
117367 +static const struct pass_data kernexec_reload_pass_data = {
117368 +#else
117369 +static struct gimple_opt_pass kernexec_reload_pass = {
117370 + .pass = {
117371 +#endif
117372 + .type = GIMPLE_PASS,
117373 + .name = "kernexec_reload",
117374 +#if BUILDING_GCC_VERSION >= 4008
117375 + .optinfo_flags = OPTGROUP_NONE,
117376 +#endif
117377 +#if BUILDING_GCC_VERSION >= 4009
117378 + .has_gate = true,
117379 + .has_execute = true,
117380 +#else
117381 + .gate = kernexec_cmodel_check,
117382 + .execute = execute_kernexec_reload,
117383 + .sub = NULL,
117384 + .next = NULL,
117385 + .static_pass_number = 0,
117386 +#endif
117387 + .tv_id = TV_NONE,
117388 + .properties_required = 0,
117389 + .properties_provided = 0,
117390 + .properties_destroyed = 0,
117391 + .todo_flags_start = 0,
117392 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
117393 +#if BUILDING_GCC_VERSION < 4009
117394 + }
117395 +#endif
117396 +};
117397 +
117398 +#if BUILDING_GCC_VERSION >= 4009
117399 +static const struct pass_data kernexec_fptr_pass_data = {
117400 +#else
117401 +static struct gimple_opt_pass kernexec_fptr_pass = {
117402 + .pass = {
117403 +#endif
117404 + .type = GIMPLE_PASS,
117405 + .name = "kernexec_fptr",
117406 +#if BUILDING_GCC_VERSION >= 4008
117407 + .optinfo_flags = OPTGROUP_NONE,
117408 +#endif
117409 +#if BUILDING_GCC_VERSION >= 4009
117410 + .has_gate = true,
117411 + .has_execute = true,
117412 +#else
117413 + .gate = kernexec_cmodel_check,
117414 + .execute = execute_kernexec_fptr,
117415 + .sub = NULL,
117416 + .next = NULL,
117417 + .static_pass_number = 0,
117418 +#endif
117419 + .tv_id = TV_NONE,
117420 + .properties_required = 0,
117421 + .properties_provided = 0,
117422 + .properties_destroyed = 0,
117423 + .todo_flags_start = 0,
117424 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
117425 +#if BUILDING_GCC_VERSION < 4009
117426 + }
117427 +#endif
117428 +};
117429 +
117430 +#if BUILDING_GCC_VERSION >= 4009
117431 +static const struct pass_data kernexec_retaddr_pass_data = {
117432 +#else
117433 +static struct rtl_opt_pass kernexec_retaddr_pass = {
117434 + .pass = {
117435 +#endif
117436 + .type = RTL_PASS,
117437 + .name = "kernexec_retaddr",
117438 +#if BUILDING_GCC_VERSION >= 4008
117439 + .optinfo_flags = OPTGROUP_NONE,
117440 +#endif
117441 +#if BUILDING_GCC_VERSION >= 4009
117442 + .has_gate = true,
117443 + .has_execute = true,
117444 +#else
117445 + .gate = kernexec_cmodel_check,
117446 + .execute = execute_kernexec_retaddr,
117447 + .sub = NULL,
117448 + .next = NULL,
117449 + .static_pass_number = 0,
117450 +#endif
117451 + .tv_id = TV_NONE,
117452 + .properties_required = 0,
117453 + .properties_provided = 0,
117454 + .properties_destroyed = 0,
117455 + .todo_flags_start = 0,
117456 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
117457 +#if BUILDING_GCC_VERSION < 4009
117458 + }
117459 +#endif
117460 +};
117461 +
117462 +#if BUILDING_GCC_VERSION >= 4009
117463 +namespace {
117464 +class kernexec_reload_pass : public gimple_opt_pass {
117465 +public:
117466 + kernexec_reload_pass() : gimple_opt_pass(kernexec_reload_pass_data, g) {}
117467 + bool gate() { return kernexec_cmodel_check(); }
117468 + unsigned int execute() { return execute_kernexec_reload(); }
117469 +};
117470 +
117471 +class kernexec_fptr_pass : public gimple_opt_pass {
117472 +public:
117473 + kernexec_fptr_pass() : gimple_opt_pass(kernexec_fptr_pass_data, g) {}
117474 + bool gate() { return kernexec_cmodel_check(); }
117475 + unsigned int execute() { return execute_kernexec_fptr(); }
117476 +};
117477 +
117478 +class kernexec_retaddr_pass : public rtl_opt_pass {
117479 +public:
117480 + kernexec_retaddr_pass() : rtl_opt_pass(kernexec_retaddr_pass_data, g) {}
117481 + bool gate() { return kernexec_cmodel_check(); }
117482 + unsigned int execute() { return execute_kernexec_retaddr(); }
117483 +};
117484 +}
117485 +
117486 +static opt_pass *make_kernexec_reload_pass(void)
117487 +{
117488 + return new kernexec_reload_pass();
117489 +}
117490 +
117491 +static opt_pass *make_kernexec_fptr_pass(void)
117492 +{
117493 + return new kernexec_fptr_pass();
117494 +}
117495 +
117496 +static opt_pass *make_kernexec_retaddr_pass(void)
117497 +{
117498 + return new kernexec_retaddr_pass();
117499 +}
117500 +#else
117501 +static struct opt_pass *make_kernexec_reload_pass(void)
117502 +{
117503 + return &kernexec_reload_pass.pass;
117504 +}
117505 +
117506 +static struct opt_pass *make_kernexec_fptr_pass(void)
117507 +{
117508 + return &kernexec_fptr_pass.pass;
117509 +}
117510 +
117511 +static struct opt_pass *make_kernexec_retaddr_pass(void)
117512 +{
117513 + return &kernexec_retaddr_pass.pass;
117514 +}
117515 +#endif
117516 +
117517 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
117518 +{
117519 + const char * const plugin_name = plugin_info->base_name;
117520 + const int argc = plugin_info->argc;
117521 + const struct plugin_argument * const argv = plugin_info->argv;
117522 + int i;
117523 + struct register_pass_info kernexec_reload_pass_info;
117524 + struct register_pass_info kernexec_fptr_pass_info;
117525 + struct register_pass_info kernexec_retaddr_pass_info;
117526 +
117527 + kernexec_reload_pass_info.pass = make_kernexec_reload_pass();
117528 + kernexec_reload_pass_info.reference_pass_name = "ssa";
117529 + kernexec_reload_pass_info.ref_pass_instance_number = 1;
117530 + kernexec_reload_pass_info.pos_op = PASS_POS_INSERT_AFTER;
117531 +
117532 + kernexec_fptr_pass_info.pass = make_kernexec_fptr_pass();
117533 + kernexec_fptr_pass_info.reference_pass_name = "ssa";
117534 + kernexec_fptr_pass_info.ref_pass_instance_number = 1;
117535 + kernexec_fptr_pass_info.pos_op = PASS_POS_INSERT_AFTER;
117536 +
117537 + kernexec_retaddr_pass_info.pass = make_kernexec_retaddr_pass();
117538 + kernexec_retaddr_pass_info.reference_pass_name = "pro_and_epilogue";
117539 + kernexec_retaddr_pass_info.ref_pass_instance_number = 1;
117540 + kernexec_retaddr_pass_info.pos_op = PASS_POS_INSERT_AFTER;
117541 +
117542 + if (!plugin_default_version_check(version, &gcc_version)) {
117543 + error(G_("incompatible gcc/plugin versions"));
117544 + return 1;
117545 + }
117546 +
117547 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
117548 +
117549 + if (TARGET_64BIT == 0)
117550 + return 0;
117551 +
117552 + for (i = 0; i < argc; ++i) {
117553 + if (!strcmp(argv[i].key, "method")) {
117554 + if (!argv[i].value) {
117555 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
117556 + continue;
117557 + }
117558 + if (!strcmp(argv[i].value, "bts")) {
117559 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
117560 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
117561 + } else if (!strcmp(argv[i].value, "or")) {
117562 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
117563 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
117564 + fix_register("r12", 1, 1);
117565 + } else
117566 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
117567 + continue;
117568 + }
117569 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
117570 + }
117571 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
117572 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
117573 +
117574 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
117575 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
117576 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
117577 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
117578 +
117579 + return 0;
117580 +}
117581 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
117582 new file mode 100644
117583 index 0000000..39d7cc7
117584 --- /dev/null
117585 +++ b/tools/gcc/latent_entropy_plugin.c
117586 @@ -0,0 +1,462 @@
117587 +/*
117588 + * Copyright 2012-2014 by the PaX Team <pageexec@freemail.hu>
117589 + * Licensed under the GPL v2
117590 + *
117591 + * Note: the choice of the license means that the compilation process is
117592 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
117593 + * but for the kernel it doesn't matter since it doesn't link against
117594 + * any of the gcc libraries
117595 + *
117596 + * gcc plugin to help generate a little bit of entropy from program state,
117597 + * used throughout the uptime of the kernel
117598 + *
117599 + * TODO:
117600 + * - add ipa pass to identify not explicitly marked candidate functions
117601 + * - mix in more program state (function arguments/return values, loop variables, etc)
117602 + * - more instrumentation control via attribute parameters
117603 + *
117604 + * BUGS:
117605 + * - LTO needs -flto-partition=none for now
117606 + */
117607 +
117608 +#include "gcc-common.h"
117609 +
117610 +int plugin_is_GPL_compatible;
117611 +
117612 +static tree latent_entropy_decl;
117613 +
117614 +static struct plugin_info latent_entropy_plugin_info = {
117615 + .version = "201403280150",
117616 + .help = NULL
117617 +};
117618 +
117619 +static unsigned HOST_WIDE_INT seed;
117620 +static unsigned HOST_WIDE_INT get_random_const(void)
117621 +{
117622 + unsigned int i;
117623 + unsigned HOST_WIDE_INT ret = 0;
117624 +
117625 + for (i = 0; i < 8 * sizeof ret; i++) {
117626 + ret = (ret << 1) | (seed & 1);
117627 + seed >>= 1;
117628 + if (ret & 1)
117629 + seed ^= 0xD800000000000000ULL;
117630 + }
117631 +
117632 + return ret;
117633 +}
117634 +
117635 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
117636 +{
117637 + tree type;
117638 + unsigned long long mask;
117639 +#if BUILDING_GCC_VERSION <= 4007
117640 + VEC(constructor_elt, gc) *vals;
117641 +#else
117642 + vec<constructor_elt, va_gc> *vals;
117643 +#endif
117644 +
117645 + switch (TREE_CODE(*node)) {
117646 + default:
117647 + *no_add_attrs = true;
117648 + error("%qE attribute only applies to functions and variables", name);
117649 + break;
117650 +
117651 + case VAR_DECL:
117652 + if (DECL_INITIAL(*node)) {
117653 + *no_add_attrs = true;
117654 + error("variable %qD with %qE attribute must not be initialized", *node, name);
117655 + break;
117656 + }
117657 +
117658 + if (!TREE_STATIC(*node)) {
117659 + *no_add_attrs = true;
117660 + error("variable %qD with %qE attribute must not be local", *node, name);
117661 + break;
117662 + }
117663 +
117664 + type = TREE_TYPE(*node);
117665 + switch (TREE_CODE(type)) {
117666 + default:
117667 + *no_add_attrs = true;
117668 + 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);
117669 + break;
117670 +
117671 + case RECORD_TYPE: {
117672 + tree field;
117673 + unsigned int nelt = 0;
117674 +
117675 + for (field = TYPE_FIELDS(type); field; nelt++, field = TREE_CHAIN(field)) {
117676 + tree fieldtype;
117677 +
117678 + fieldtype = TREE_TYPE(field);
117679 + if (TREE_CODE(fieldtype) != INTEGER_TYPE) {
117680 + *no_add_attrs = true;
117681 + error("structure variable %qD with %qE attribute has a non-integer field %qE", *node, name, field);
117682 + break;
117683 + }
117684 + }
117685 +
117686 + if (field)
117687 + break;
117688 +
117689 +#if BUILDING_GCC_VERSION <= 4007
117690 + vals = VEC_alloc(constructor_elt, gc, nelt);
117691 +#else
117692 + vec_alloc(vals, nelt);
117693 +#endif
117694 +
117695 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
117696 + tree fieldtype;
117697 +
117698 + fieldtype = TREE_TYPE(field);
117699 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(fieldtype)) - 1);
117700 + mask = 2 * (mask - 1) + 1;
117701 +
117702 + if (TYPE_UNSIGNED(fieldtype))
117703 + CONSTRUCTOR_APPEND_ELT(vals, field, build_int_cstu(fieldtype, mask & get_random_const()));
117704 + else
117705 + CONSTRUCTOR_APPEND_ELT(vals, field, build_int_cst(fieldtype, mask & get_random_const()));
117706 + }
117707 +
117708 + DECL_INITIAL(*node) = build_constructor(type, vals);
117709 +//debug_tree(DECL_INITIAL(*node));
117710 + break;
117711 + }
117712 +
117713 + case INTEGER_TYPE:
117714 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(type)) - 1);
117715 + mask = 2 * (mask - 1) + 1;
117716 +
117717 + if (TYPE_UNSIGNED(type))
117718 + DECL_INITIAL(*node) = build_int_cstu(type, mask & get_random_const());
117719 + else
117720 + DECL_INITIAL(*node) = build_int_cst(type, mask & get_random_const());
117721 + break;
117722 +
117723 + case ARRAY_TYPE: {
117724 + tree elt_type, array_size, elt_size;
117725 + unsigned int i, nelt;
117726 +
117727 + elt_type = TREE_TYPE(type);
117728 + elt_size = TYPE_SIZE_UNIT(TREE_TYPE(type));
117729 + array_size = TYPE_SIZE_UNIT(type);
117730 +
117731 + if (TREE_CODE(elt_type) != INTEGER_TYPE || !array_size || TREE_CODE(array_size) != INTEGER_CST) {
117732 + *no_add_attrs = true;
117733 + error("array variable %qD with %qE attribute must be a fixed length integer array type", *node, name);
117734 + break;
117735 + }
117736 +
117737 + nelt = TREE_INT_CST_LOW(array_size) / TREE_INT_CST_LOW(elt_size);
117738 +#if BUILDING_GCC_VERSION <= 4007
117739 + vals = VEC_alloc(constructor_elt, gc, nelt);
117740 +#else
117741 + vec_alloc(vals, nelt);
117742 +#endif
117743 +
117744 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(elt_type)) - 1);
117745 + mask = 2 * (mask - 1) + 1;
117746 +
117747 + for (i = 0; i < nelt; i++)
117748 + if (TYPE_UNSIGNED(elt_type))
117749 + CONSTRUCTOR_APPEND_ELT(vals, size_int(i), build_int_cstu(elt_type, mask & get_random_const()));
117750 + else
117751 + CONSTRUCTOR_APPEND_ELT(vals, size_int(i), build_int_cst(elt_type, mask & get_random_const()));
117752 +
117753 + DECL_INITIAL(*node) = build_constructor(type, vals);
117754 +//debug_tree(DECL_INITIAL(*node));
117755 + break;
117756 + }
117757 + }
117758 + break;
117759 +
117760 + case FUNCTION_DECL:
117761 + break;
117762 + }
117763 +
117764 + return NULL_TREE;
117765 +}
117766 +
117767 +static struct attribute_spec latent_entropy_attr = {
117768 + .name = "latent_entropy",
117769 + .min_length = 0,
117770 + .max_length = 0,
117771 + .decl_required = true,
117772 + .type_required = false,
117773 + .function_type_required = false,
117774 + .handler = handle_latent_entropy_attribute,
117775 +#if BUILDING_GCC_VERSION >= 4007
117776 + .affects_type_identity = false
117777 +#endif
117778 +};
117779 +
117780 +static void register_attributes(void *event_data, void *data)
117781 +{
117782 + register_attribute(&latent_entropy_attr);
117783 +}
117784 +
117785 +static bool gate_latent_entropy(void)
117786 +{
117787 + // don't bother with noreturn functions for now
117788 + if (TREE_THIS_VOLATILE(current_function_decl))
117789 + return false;
117790 +
117791 + return lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl)) != NULL_TREE;
117792 +}
117793 +
117794 +static enum tree_code get_op(tree *rhs)
117795 +{
117796 + static enum tree_code op;
117797 + unsigned HOST_WIDE_INT random_const;
117798 +
117799 + random_const = get_random_const();
117800 +
117801 + switch (op) {
117802 + case BIT_XOR_EXPR:
117803 + op = PLUS_EXPR;
117804 + break;
117805 +
117806 + case PLUS_EXPR:
117807 + if (rhs) {
117808 + op = LROTATE_EXPR;
117809 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
117810 + break;
117811 + }
117812 +
117813 + case LROTATE_EXPR:
117814 + default:
117815 + op = BIT_XOR_EXPR;
117816 + break;
117817 + }
117818 + if (rhs)
117819 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
117820 + return op;
117821 +}
117822 +
117823 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
117824 +{
117825 + gimple_stmt_iterator gsi;
117826 + gimple assign;
117827 + tree addxorrol, rhs;
117828 + enum tree_code op;
117829 +
117830 + op = get_op(&rhs);
117831 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
117832 + assign = gimple_build_assign(local_entropy, addxorrol);
117833 + gsi = gsi_after_labels(bb);
117834 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
117835 + update_stmt(assign);
117836 +//debug_bb(bb);
117837 +}
117838 +
117839 +static void perturb_latent_entropy(basic_block bb, tree rhs)
117840 +{
117841 + gimple_stmt_iterator gsi;
117842 + gimple assign;
117843 + tree addxorrol, temp;
117844 +
117845 + // 1. create temporary copy of latent_entropy
117846 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
117847 + add_referenced_var(temp);
117848 +
117849 + // 2. read...
117850 + temp = make_ssa_name(temp, NULL);
117851 + assign = gimple_build_assign(temp, latent_entropy_decl);
117852 + SSA_NAME_DEF_STMT(temp) = assign;
117853 + add_referenced_var(latent_entropy_decl);
117854 + gsi = gsi_after_labels(bb);
117855 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
117856 + update_stmt(assign);
117857 +
117858 + // 3. ...modify...
117859 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
117860 + temp = make_ssa_name(SSA_NAME_VAR(temp), NULL);
117861 + assign = gimple_build_assign(temp, addxorrol);
117862 + SSA_NAME_DEF_STMT(temp) = assign;
117863 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
117864 + update_stmt(assign);
117865 +
117866 + // 4. ...write latent_entropy
117867 + assign = gimple_build_assign(latent_entropy_decl, temp);
117868 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
117869 + update_stmt(assign);
117870 +}
117871 +
117872 +static unsigned int execute_latent_entropy(void)
117873 +{
117874 + basic_block bb;
117875 + gimple assign;
117876 + gimple_stmt_iterator gsi;
117877 + tree local_entropy;
117878 +
117879 + if (!latent_entropy_decl) {
117880 +#if BUILDING_GCC_VERSION >= 4009
117881 + varpool_node *node;
117882 +#else
117883 + struct varpool_node *node;
117884 +#endif
117885 +
117886 + FOR_EACH_VARIABLE(node) {
117887 + tree var = NODE_DECL(node);
117888 +
117889 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
117890 + continue;
117891 + latent_entropy_decl = var;
117892 +// debug_tree(var);
117893 + break;
117894 + }
117895 + if (!latent_entropy_decl) {
117896 +// debug_tree(current_function_decl);
117897 + return 0;
117898 + }
117899 + }
117900 +
117901 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
117902 +
117903 + // 1. create local entropy variable
117904 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
117905 + add_referenced_var(local_entropy);
117906 + mark_sym_for_renaming(local_entropy);
117907 +
117908 + // 2. initialize local entropy variable
117909 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
117910 + if (dom_info_available_p(CDI_DOMINATORS))
117911 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
117912 + gsi = gsi_start_bb(bb);
117913 +
117914 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
117915 +// gimple_set_location(assign, loc);
117916 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
117917 + update_stmt(assign);
117918 +//debug_bb(bb);
117919 + gcc_assert(single_succ_p(bb));
117920 + bb = single_succ(bb);
117921 +
117922 + // 3. instrument each BB with an operation on the local entropy variable
117923 + while (bb != EXIT_BLOCK_PTR_FOR_FN(cfun)) {
117924 + perturb_local_entropy(bb, local_entropy);
117925 +//debug_bb(bb);
117926 + bb = bb->next_bb;
117927 + };
117928 +
117929 + // 4. mix local entropy into the global entropy variable
117930 + gcc_assert(single_pred_p(EXIT_BLOCK_PTR_FOR_FN(cfun)));
117931 + perturb_latent_entropy(single_pred(EXIT_BLOCK_PTR_FOR_FN(cfun)), local_entropy);
117932 +//debug_bb(single_pred(EXIT_BLOCK_PTR_FOR_FN(cfun)));
117933 + return 0;
117934 +}
117935 +
117936 +static void latent_entropy_start_unit(void *gcc_data, void *user_data)
117937 +{
117938 + tree latent_entropy_type;
117939 +
117940 + seed = get_random_seed(false);
117941 +
117942 + if (in_lto_p)
117943 + return;
117944 +
117945 + // extern volatile u64 latent_entropy
117946 + gcc_assert(TYPE_PRECISION(long_long_unsigned_type_node) == 64);
117947 + latent_entropy_type = build_qualified_type(long_long_unsigned_type_node, TYPE_QUALS(long_long_unsigned_type_node) | TYPE_QUAL_VOLATILE);
117948 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), latent_entropy_type);
117949 +
117950 + TREE_STATIC(latent_entropy_decl) = 1;
117951 + TREE_PUBLIC(latent_entropy_decl) = 1;
117952 + TREE_USED(latent_entropy_decl) = 1;
117953 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
117954 + DECL_EXTERNAL(latent_entropy_decl) = 1;
117955 + DECL_ARTIFICIAL(latent_entropy_decl) = 1;
117956 + lang_hooks.decls.pushdecl(latent_entropy_decl);
117957 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
117958 +// varpool_finalize_decl(latent_entropy_decl);
117959 +// varpool_mark_needed_node(latent_entropy_decl);
117960 +}
117961 +
117962 +#if BUILDING_GCC_VERSION >= 4009
117963 +static const struct pass_data latent_entropy_pass_data = {
117964 +#else
117965 +static struct gimple_opt_pass latent_entropy_pass = {
117966 + .pass = {
117967 +#endif
117968 + .type = GIMPLE_PASS,
117969 + .name = "latent_entropy",
117970 +#if BUILDING_GCC_VERSION >= 4008
117971 + .optinfo_flags = OPTGROUP_NONE,
117972 +#endif
117973 +#if BUILDING_GCC_VERSION >= 4009
117974 + .has_gate = true,
117975 + .has_execute = true,
117976 +#else
117977 + .gate = gate_latent_entropy,
117978 + .execute = execute_latent_entropy,
117979 + .sub = NULL,
117980 + .next = NULL,
117981 + .static_pass_number = 0,
117982 +#endif
117983 + .tv_id = TV_NONE,
117984 + .properties_required = PROP_gimple_leh | PROP_cfg,
117985 + .properties_provided = 0,
117986 + .properties_destroyed = 0,
117987 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
117988 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
117989 +#if BUILDING_GCC_VERSION < 4009
117990 + }
117991 +#endif
117992 +};
117993 +
117994 +#if BUILDING_GCC_VERSION >= 4009
117995 +namespace {
117996 +class latent_entropy_pass : public gimple_opt_pass {
117997 +public:
117998 + latent_entropy_pass() : gimple_opt_pass(latent_entropy_pass_data, g) {}
117999 + bool gate() { return gate_latent_entropy(); }
118000 + unsigned int execute() { return execute_latent_entropy(); }
118001 +};
118002 +}
118003 +
118004 +static opt_pass *make_latent_entropy_pass(void)
118005 +{
118006 + return new latent_entropy_pass();
118007 +}
118008 +#else
118009 +static struct opt_pass *make_latent_entropy_pass(void)
118010 +{
118011 + return &latent_entropy_pass.pass;
118012 +}
118013 +#endif
118014 +
118015 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
118016 +{
118017 + const char * const plugin_name = plugin_info->base_name;
118018 + struct register_pass_info latent_entropy_pass_info;
118019 +
118020 + latent_entropy_pass_info.pass = make_latent_entropy_pass();
118021 + latent_entropy_pass_info.reference_pass_name = "optimized";
118022 + latent_entropy_pass_info.ref_pass_instance_number = 1;
118023 + latent_entropy_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
118024 + static const struct ggc_root_tab gt_ggc_r_gt_latent_entropy[] = {
118025 + {
118026 + .base = &latent_entropy_decl,
118027 + .nelt = 1,
118028 + .stride = sizeof(latent_entropy_decl),
118029 + .cb = &gt_ggc_mx_tree_node,
118030 + .pchw = &gt_pch_nx_tree_node
118031 + },
118032 + LAST_GGC_ROOT_TAB
118033 + };
118034 +
118035 + if (!plugin_default_version_check(version, &gcc_version)) {
118036 + error(G_("incompatible gcc/plugin versions"));
118037 + return 1;
118038 + }
118039 +
118040 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
118041 + register_callback(plugin_name, PLUGIN_START_UNIT, &latent_entropy_start_unit, NULL);
118042 + if (!in_lto_p)
118043 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_latent_entropy);
118044 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
118045 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
118046 +
118047 + return 0;
118048 +}
118049 diff --git a/tools/gcc/randomize_layout_plugin.c b/tools/gcc/randomize_layout_plugin.c
118050 new file mode 100644
118051 index 0000000..a5cb46b
118052 --- /dev/null
118053 +++ b/tools/gcc/randomize_layout_plugin.c
118054 @@ -0,0 +1,915 @@
118055 +/*
118056 + * Copyright 2014 by Open Source Security, Inc., Brad Spengler <spender@grsecurity.net>
118057 + * and PaX Team <pageexec@freemail.hu>
118058 + * Licensed under the GPL v2
118059 + *
118060 + * Usage:
118061 + * $ # for 4.5/4.6/C based 4.7
118062 + * $ 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
118063 + * $ # for C++ based 4.7/4.8+
118064 + * $ 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
118065 + * $ gcc -fplugin=./randomize_layout_plugin.so test.c -O2
118066 + */
118067 +
118068 +#include "gcc-common.h"
118069 +#include "randomize_layout_seed.h"
118070 +
118071 +#if BUILDING_GCC_MAJOR < 4 || BUILDING_GCC_MINOR < 6 || (BUILDING_GCC_MINOR == 6 && BUILDING_GCC_PATCHLEVEL < 4)
118072 +#error "The RANDSTRUCT plugin requires GCC 4.6.4 or newer."
118073 +#endif
118074 +
118075 +#define ORIG_TYPE_NAME(node) \
118076 + (TYPE_NAME(TYPE_MAIN_VARIANT(node)) != NULL_TREE ? ((const unsigned char *)IDENTIFIER_POINTER(TYPE_NAME(TYPE_MAIN_VARIANT(node)))) : (const unsigned char *)"anonymous")
118077 +
118078 +int plugin_is_GPL_compatible;
118079 +
118080 +static int performance_mode;
118081 +
118082 +static struct plugin_info randomize_layout_plugin_info = {
118083 + .version = "201402201816",
118084 + .help = "disable\t\t\tdo not activate plugin\n"
118085 + "performance-mode\tenable cacheline-aware layout randomization\n"
118086 +};
118087 +
118088 +/* from old Linux dcache.h */
118089 +static inline unsigned long
118090 +partial_name_hash(unsigned long c, unsigned long prevhash)
118091 +{
118092 + return (prevhash + (c << 4) + (c >> 4)) * 11;
118093 +}
118094 +static inline unsigned int
118095 +name_hash(const unsigned char *name)
118096 +{
118097 + unsigned long hash = 0;
118098 + unsigned int len = strlen((const char *)name);
118099 + while (len--)
118100 + hash = partial_name_hash(*name++, hash);
118101 + return (unsigned int)hash;
118102 +}
118103 +
118104 +static tree handle_randomize_layout_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
118105 +{
118106 + tree type;
118107 +
118108 + *no_add_attrs = true;
118109 + if (TREE_CODE(*node) == FUNCTION_DECL) {
118110 + error("%qE attribute does not apply to functions (%qF)", name, *node);
118111 + return NULL_TREE;
118112 + }
118113 +
118114 + if (TREE_CODE(*node) == PARM_DECL) {
118115 + error("%qE attribute does not apply to function parameters (%qD)", name, *node);
118116 + return NULL_TREE;
118117 + }
118118 +
118119 + if (TREE_CODE(*node) == VAR_DECL) {
118120 + error("%qE attribute does not apply to variables (%qD)", name, *node);
118121 + return NULL_TREE;
118122 + }
118123 +
118124 + if (TYPE_P(*node)) {
118125 + type = *node;
118126 + } else {
118127 + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
118128 + type = TREE_TYPE(*node);
118129 + }
118130 +
118131 + if (TREE_CODE(type) != RECORD_TYPE) {
118132 + error("%qE attribute used on %qT applies to struct types only", name, type);
118133 + return NULL_TREE;
118134 + }
118135 +
118136 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
118137 + error("%qE attribute is already applied to the type %qT", name, type);
118138 + return NULL_TREE;
118139 + }
118140 +
118141 + *no_add_attrs = false;
118142 +
118143 + return NULL_TREE;
118144 +}
118145 +
118146 +/* set on complete types that we don't need to inspect further at all */
118147 +static tree handle_randomize_considered_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
118148 +{
118149 + *no_add_attrs = false;
118150 + return NULL_TREE;
118151 +}
118152 +
118153 +/*
118154 + * set on types that we've performed a shuffle on, to prevent re-shuffling
118155 + * this does not preclude us from inspecting its fields for potential shuffles
118156 + */
118157 +static tree handle_randomize_performed_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
118158 +{
118159 + *no_add_attrs = false;
118160 + return NULL_TREE;
118161 +}
118162 +
118163 +/*
118164 + * 64bit variant of Bob Jenkins' public domain PRNG
118165 + * 256 bits of internal state
118166 + */
118167 +
118168 +typedef unsigned long long u64;
118169 +
118170 +typedef struct ranctx { u64 a; u64 b; u64 c; u64 d; } ranctx;
118171 +
118172 +#define rot(x,k) (((x)<<(k))|((x)>>(64-(k))))
118173 +static u64 ranval(ranctx *x) {
118174 + u64 e = x->a - rot(x->b, 7);
118175 + x->a = x->b ^ rot(x->c, 13);
118176 + x->b = x->c + rot(x->d, 37);
118177 + x->c = x->d + e;
118178 + x->d = e + x->a;
118179 + return x->d;
118180 +}
118181 +
118182 +static void raninit(ranctx *x, u64 *seed) {
118183 + int i;
118184 +
118185 + x->a = seed[0];
118186 + x->b = seed[1];
118187 + x->c = seed[2];
118188 + x->d = seed[3];
118189 +
118190 + for (i=0; i < 30; ++i)
118191 + (void)ranval(x);
118192 +}
118193 +
118194 +static u64 shuffle_seed[4];
118195 +
118196 +struct partition_group {
118197 + tree tree_start;
118198 + unsigned long start;
118199 + unsigned long length;
118200 +};
118201 +
118202 +static void partition_struct(tree *fields, unsigned long length, struct partition_group *size_groups, unsigned long *num_groups)
118203 +{
118204 + unsigned long i;
118205 + unsigned long accum_size = 0;
118206 + unsigned long accum_length = 0;
118207 + unsigned long group_idx = 0;
118208 +
118209 + gcc_assert(length < INT_MAX);
118210 +
118211 + memset(size_groups, 0, sizeof(struct partition_group) * length);
118212 +
118213 + for (i = 0; i < length; i++) {
118214 + if (size_groups[group_idx].tree_start == NULL_TREE) {
118215 + size_groups[group_idx].tree_start = fields[i];
118216 + size_groups[group_idx].start = i;
118217 + accum_length = 0;
118218 + accum_size = 0;
118219 + }
118220 + accum_size += (unsigned long)int_size_in_bytes(TREE_TYPE(fields[i]));
118221 + accum_length++;
118222 + if (accum_size >= 64) {
118223 + size_groups[group_idx].length = accum_length;
118224 + accum_length = 0;
118225 + group_idx++;
118226 + }
118227 + }
118228 +
118229 + if (size_groups[group_idx].tree_start != NULL_TREE &&
118230 + !size_groups[group_idx].length) {
118231 + size_groups[group_idx].length = accum_length;
118232 + group_idx++;
118233 + }
118234 +
118235 + *num_groups = group_idx;
118236 +}
118237 +
118238 +static void performance_shuffle(tree *newtree, unsigned long length, ranctx *prng_state)
118239 +{
118240 + unsigned long i, x;
118241 + struct partition_group size_group[length];
118242 + unsigned long num_groups = 0;
118243 + unsigned long randnum;
118244 +
118245 + partition_struct(newtree, length, (struct partition_group *)&size_group, &num_groups);
118246 + for (i = num_groups - 1; i > 0; i--) {
118247 + struct partition_group tmp;
118248 + randnum = ranval(prng_state) % (i + 1);
118249 + tmp = size_group[i];
118250 + size_group[i] = size_group[randnum];
118251 + size_group[randnum] = tmp;
118252 + }
118253 +
118254 + for (x = 0; x < num_groups; x++) {
118255 + for (i = size_group[x].start + size_group[x].length - 1; i > size_group[x].start; i--) {
118256 + tree tmp;
118257 + if (DECL_BIT_FIELD_TYPE(newtree[i]))
118258 + continue;
118259 + randnum = ranval(prng_state) % (i + 1);
118260 + // we could handle this case differently if desired
118261 + if (DECL_BIT_FIELD_TYPE(newtree[randnum]))
118262 + continue;
118263 + tmp = newtree[i];
118264 + newtree[i] = newtree[randnum];
118265 + newtree[randnum] = tmp;
118266 + }
118267 + }
118268 +}
118269 +
118270 +static void full_shuffle(tree *newtree, unsigned long length, ranctx *prng_state)
118271 +{
118272 + unsigned long i, randnum;
118273 +
118274 + for (i = length - 1; i > 0; i--) {
118275 + tree tmp;
118276 + randnum = ranval(prng_state) % (i + 1);
118277 + tmp = newtree[i];
118278 + newtree[i] = newtree[randnum];
118279 + newtree[randnum] = tmp;
118280 + }
118281 +}
118282 +
118283 +/* modern in-place Fisher-Yates shuffle */
118284 +static void shuffle(const_tree type, tree *newtree, unsigned long length)
118285 +{
118286 + unsigned long i;
118287 + u64 seed[4];
118288 + ranctx prng_state;
118289 + const unsigned char *structname;
118290 +
118291 + if (length == 0)
118292 + return;
118293 +
118294 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
118295 +
118296 + structname = ORIG_TYPE_NAME(type);
118297 +
118298 +#ifdef __DEBUG_PLUGIN
118299 + fprintf(stderr, "Shuffling struct %s %p\n", (const char *)structname, type);
118300 +#ifdef __DEBUG_VERBOSE
118301 + debug_tree((tree)type);
118302 +#endif
118303 +#endif
118304 +
118305 + for (i = 0; i < 4; i++) {
118306 + seed[i] = shuffle_seed[i];
118307 + seed[i] ^= name_hash(structname);
118308 + }
118309 +
118310 + raninit(&prng_state, (u64 *)&seed);
118311 +
118312 + if (performance_mode)
118313 + performance_shuffle(newtree, length, &prng_state);
118314 + else
118315 + full_shuffle(newtree, length, &prng_state);
118316 +}
118317 +
118318 +static bool is_flexible_array(const_tree field)
118319 +{
118320 + const_tree fieldtype;
118321 + const_tree typesize;
118322 + const_tree elemtype;
118323 + const_tree elemsize;
118324 +
118325 + fieldtype = TREE_TYPE(field);
118326 + typesize = TYPE_SIZE(fieldtype);
118327 +
118328 + if (TREE_CODE(fieldtype) != ARRAY_TYPE)
118329 + return false;
118330 +
118331 + elemtype = TREE_TYPE(fieldtype);
118332 + elemsize = TYPE_SIZE(elemtype);
118333 +
118334 + /* size of type is represented in bits */
118335 +
118336 + if (typesize == NULL_TREE && TYPE_DOMAIN(fieldtype) != NULL_TREE &&
118337 + TYPE_MAX_VALUE(TYPE_DOMAIN(fieldtype)) == NULL_TREE)
118338 + return true;
118339 +
118340 + if (typesize != NULL_TREE &&
118341 + (TREE_CONSTANT(typesize) && (!TREE_INT_CST_LOW(typesize) ||
118342 + TREE_INT_CST_LOW(typesize) == TREE_INT_CST_LOW(elemsize))))
118343 + return true;
118344 +
118345 + return false;
118346 +}
118347 +
118348 +static int relayout_struct(tree type)
118349 +{
118350 + unsigned long num_fields = (unsigned long)list_length(TYPE_FIELDS(type));
118351 + unsigned long shuffle_length = num_fields;
118352 + tree field;
118353 + tree newtree[num_fields];
118354 + unsigned long i;
118355 + tree list;
118356 + tree variant;
118357 + expanded_location xloc;
118358 +
118359 + if (TYPE_FIELDS(type) == NULL_TREE)
118360 + return 0;
118361 +
118362 + if (num_fields < 2)
118363 + return 0;
118364 +
118365 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
118366 +
118367 + gcc_assert(num_fields < INT_MAX);
118368 +
118369 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(type)) ||
118370 + lookup_attribute("no_randomize_layout", TYPE_ATTRIBUTES(TYPE_MAIN_VARIANT(type))))
118371 + return 0;
118372 +
118373 + /* Workaround for 3rd-party VirtualBox source that we can't modify ourselves */
118374 + if (!strcmp((const char *)ORIG_TYPE_NAME(type), "INTNETTRUNKFACTORY") ||
118375 + !strcmp((const char *)ORIG_TYPE_NAME(type), "RAWPCIFACTORY"))
118376 + return 0;
118377 +
118378 + /* throw out any structs in uapi */
118379 + xloc = expand_location(DECL_SOURCE_LOCATION(TYPE_FIELDS(type)));
118380 +
118381 + if (strstr(xloc.file, "/uapi/"))
118382 + error(G_("attempted to randomize userland API struct %s"), ORIG_TYPE_NAME(type));
118383 +
118384 + for (field = TYPE_FIELDS(type), i = 0; field; field = TREE_CHAIN(field), i++) {
118385 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
118386 + newtree[i] = field;
118387 + }
118388 +
118389 + /*
118390 + * enforce that we don't randomize the layout of the last
118391 + * element of a struct if it's a 0 or 1-length array
118392 + * or a proper flexible array
118393 + */
118394 + if (is_flexible_array(newtree[num_fields - 1]))
118395 + shuffle_length--;
118396 +
118397 + shuffle(type, (tree *)newtree, shuffle_length);
118398 +
118399 + /*
118400 + * set up a bogus anonymous struct field designed to error out on unnamed struct initializers
118401 + * as gcc provides no other way to detect such code
118402 + */
118403 + list = make_node(FIELD_DECL);
118404 + TREE_CHAIN(list) = newtree[0];
118405 + TREE_TYPE(list) = void_type_node;
118406 + DECL_SIZE(list) = bitsize_zero_node;
118407 + DECL_NONADDRESSABLE_P(list) = 1;
118408 + DECL_FIELD_BIT_OFFSET(list) = bitsize_zero_node;
118409 + DECL_SIZE_UNIT(list) = size_zero_node;
118410 + DECL_FIELD_OFFSET(list) = size_zero_node;
118411 + // to satisfy the constify plugin
118412 + TREE_READONLY(list) = 1;
118413 +
118414 + for (i = 0; i < num_fields - 1; i++)
118415 + TREE_CHAIN(newtree[i]) = newtree[i+1];
118416 + TREE_CHAIN(newtree[num_fields - 1]) = NULL_TREE;
118417 +
118418 + for (variant = TYPE_MAIN_VARIANT(type); variant; variant = TYPE_NEXT_VARIANT(variant)) {
118419 + TYPE_FIELDS(variant) = list;
118420 + TYPE_ATTRIBUTES(variant) = copy_list(TYPE_ATTRIBUTES(variant));
118421 + TYPE_ATTRIBUTES(variant) = tree_cons(get_identifier("randomize_performed"), NULL_TREE, TYPE_ATTRIBUTES(variant));
118422 + // force a re-layout
118423 + TYPE_SIZE(variant) = NULL_TREE;
118424 + layout_type(variant);
118425 + }
118426 +
118427 + return 1;
118428 +}
118429 +
118430 +/* from constify plugin */
118431 +static const_tree get_field_type(const_tree field)
118432 +{
118433 + return strip_array_types(TREE_TYPE(field));
118434 +}
118435 +
118436 +/* from constify plugin */
118437 +static bool is_fptr(const_tree fieldtype)
118438 +{
118439 + if (TREE_CODE(fieldtype) != POINTER_TYPE)
118440 + return false;
118441 +
118442 + return TREE_CODE(TREE_TYPE(fieldtype)) == FUNCTION_TYPE;
118443 +}
118444 +
118445 +/* derived from constify plugin */
118446 +static int is_pure_ops_struct(const_tree node)
118447 +{
118448 + const_tree field;
118449 +
118450 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
118451 +
118452 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
118453 + const_tree fieldtype = get_field_type(field);
118454 + enum tree_code code = TREE_CODE(fieldtype);
118455 +
118456 + if (node == fieldtype)
118457 + continue;
118458 +
118459 + if (!is_fptr(fieldtype))
118460 + return 0;
118461 +
118462 + if (code != RECORD_TYPE && code != UNION_TYPE)
118463 + continue;
118464 +
118465 + if (!is_pure_ops_struct(fieldtype))
118466 + return 0;
118467 + }
118468 +
118469 + return 1;
118470 +}
118471 +
118472 +static void randomize_type(tree type)
118473 +{
118474 + tree variant;
118475 +
118476 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
118477 +
118478 + if (lookup_attribute("randomize_considered", TYPE_ATTRIBUTES(type)))
118479 + return;
118480 +
118481 + if (lookup_attribute("randomize_layout", TYPE_ATTRIBUTES(TYPE_MAIN_VARIANT(type))) || is_pure_ops_struct(type))
118482 + relayout_struct(type);
118483 +
118484 + for (variant = TYPE_MAIN_VARIANT(type); variant; variant = TYPE_NEXT_VARIANT(variant)) {
118485 + TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
118486 + TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("randomize_considered"), NULL_TREE, TYPE_ATTRIBUTES(type));
118487 + }
118488 +#ifdef __DEBUG_PLUGIN
118489 + fprintf(stderr, "Marking randomize_considered on struct %s\n", ORIG_TYPE_NAME(type));
118490 +#ifdef __DEBUG_VERBOSE
118491 + debug_tree(type);
118492 +#endif
118493 +#endif
118494 +}
118495 +
118496 +static void randomize_layout_finish_decl(void *event_data, void *data)
118497 +{
118498 + tree decl = (tree)event_data;
118499 + tree type;
118500 +
118501 + if (decl == NULL_TREE || decl == error_mark_node)
118502 + return;
118503 +
118504 + type = TREE_TYPE(decl);
118505 +
118506 + if (TREE_CODE(decl) != VAR_DECL)
118507 + return;
118508 +
118509 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
118510 + return;
118511 +
118512 + if (!lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(type)))
118513 + return;
118514 +
118515 + relayout_decl(decl);
118516 +}
118517 +
118518 +static void finish_type(void *event_data, void *data)
118519 +{
118520 + tree type = (tree)event_data;
118521 +
118522 + if (type == NULL_TREE || type == error_mark_node)
118523 + return;
118524 +
118525 + if (TREE_CODE(type) != RECORD_TYPE)
118526 + return;
118527 +
118528 + if (TYPE_FIELDS(type) == NULL_TREE)
118529 + return;
118530 +
118531 + if (lookup_attribute("randomize_considered", TYPE_ATTRIBUTES(type)))
118532 + return;
118533 +
118534 +#ifdef __DEBUG_PLUGIN
118535 + fprintf(stderr, "Calling randomize_type on %s\n", ORIG_TYPE_NAME(type));
118536 +#endif
118537 +#ifdef __DEBUG_VERBOSE
118538 + debug_tree(type);
118539 +#endif
118540 + randomize_type(type);
118541 +
118542 + return;
118543 +}
118544 +
118545 +static struct attribute_spec randomize_layout_attr = {
118546 + .name = "randomize_layout",
118547 + // related to args
118548 + .min_length = 0,
118549 + .max_length = 0,
118550 + .decl_required = false,
118551 + // need type declaration
118552 + .type_required = true,
118553 + .function_type_required = false,
118554 + .handler = handle_randomize_layout_attr,
118555 +#if BUILDING_GCC_VERSION >= 4007
118556 + .affects_type_identity = true
118557 +#endif
118558 +};
118559 +
118560 +static struct attribute_spec no_randomize_layout_attr = {
118561 + .name = "no_randomize_layout",
118562 + // related to args
118563 + .min_length = 0,
118564 + .max_length = 0,
118565 + .decl_required = false,
118566 + // need type declaration
118567 + .type_required = true,
118568 + .function_type_required = false,
118569 + .handler = handle_randomize_layout_attr,
118570 +#if BUILDING_GCC_VERSION >= 4007
118571 + .affects_type_identity = true
118572 +#endif
118573 +};
118574 +
118575 +static struct attribute_spec randomize_considered_attr = {
118576 + .name = "randomize_considered",
118577 + // related to args
118578 + .min_length = 0,
118579 + .max_length = 0,
118580 + .decl_required = false,
118581 + // need type declaration
118582 + .type_required = true,
118583 + .function_type_required = false,
118584 + .handler = handle_randomize_considered_attr,
118585 +#if BUILDING_GCC_VERSION >= 4007
118586 + .affects_type_identity = false
118587 +#endif
118588 +};
118589 +
118590 +static struct attribute_spec randomize_performed_attr = {
118591 + .name = "randomize_performed",
118592 + // related to args
118593 + .min_length = 0,
118594 + .max_length = 0,
118595 + .decl_required = false,
118596 + // need type declaration
118597 + .type_required = true,
118598 + .function_type_required = false,
118599 + .handler = handle_randomize_performed_attr,
118600 +#if BUILDING_GCC_VERSION >= 4007
118601 + .affects_type_identity = false
118602 +#endif
118603 +};
118604 +
118605 +static void register_attributes(void *event_data, void *data)
118606 +{
118607 + register_attribute(&randomize_layout_attr);
118608 + register_attribute(&no_randomize_layout_attr);
118609 + register_attribute(&randomize_considered_attr);
118610 + register_attribute(&randomize_performed_attr);
118611 +}
118612 +
118613 +static void check_bad_casts_in_constructor(tree var, tree init)
118614 +{
118615 + unsigned HOST_WIDE_INT idx;
118616 + tree field, val;
118617 + tree field_type, val_type;
118618 +
118619 + FOR_EACH_CONSTRUCTOR_ELT(CONSTRUCTOR_ELTS(init), idx, field, val) {
118620 + if (TREE_CODE(val) == CONSTRUCTOR) {
118621 + check_bad_casts_in_constructor(var, val);
118622 + continue;
118623 + }
118624 +
118625 + /* pipacs' plugin creates franken-arrays that differ from those produced by
118626 + normal code which all have valid 'field' trees. work around this */
118627 + if (field == NULL_TREE)
118628 + continue;
118629 + field_type = TREE_TYPE(field);
118630 + val_type = TREE_TYPE(val);
118631 +
118632 + if (TREE_CODE(field_type) != POINTER_TYPE || TREE_CODE(val_type) != POINTER_TYPE)
118633 + continue;
118634 +
118635 + if (field_type == val_type)
118636 + continue;
118637 +
118638 + field_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(field_type))));
118639 + val_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(val_type))));
118640 +
118641 + if (field_type == void_type_node)
118642 + continue;
118643 + if (field_type == val_type)
118644 + continue;
118645 + if (TREE_CODE(val_type) != RECORD_TYPE)
118646 + continue;
118647 +
118648 + if (!lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(val_type)))
118649 + continue;
118650 + inform(DECL_SOURCE_LOCATION(var), "found mismatched struct pointer types: %qT and %qT\n", TYPE_MAIN_VARIANT(field_type), TYPE_MAIN_VARIANT(val_type));
118651 + }
118652 +}
118653 +
118654 +/* derived from the constify plugin */
118655 +static void check_global_variables(void *event_data, void *data)
118656 +{
118657 + struct varpool_node *node;
118658 + tree init;
118659 +
118660 + FOR_EACH_VARIABLE(node) {
118661 + tree var = NODE_DECL(node);
118662 + init = DECL_INITIAL(var);
118663 + if (init == NULL_TREE)
118664 + continue;
118665 +
118666 + if (TREE_CODE(init) != CONSTRUCTOR)
118667 + continue;
118668 +
118669 + check_bad_casts_in_constructor(var, init);
118670 + }
118671 +}
118672 +
118673 +static bool dominated_by_is_err(const_tree rhs, basic_block bb)
118674 +{
118675 + basic_block dom;
118676 + gimple dom_stmt;
118677 + gimple call_stmt;
118678 + const_tree dom_lhs;
118679 + const_tree poss_is_err_cond;
118680 + const_tree poss_is_err_func;
118681 + const_tree is_err_arg;
118682 +
118683 + dom = get_immediate_dominator(CDI_DOMINATORS, bb);
118684 + if (!dom)
118685 + return false;
118686 +
118687 + dom_stmt = last_stmt(dom);
118688 + if (!dom_stmt)
118689 + return false;
118690 +
118691 + if (gimple_code(dom_stmt) != GIMPLE_COND)
118692 + return false;
118693 +
118694 + if (gimple_cond_code(dom_stmt) != NE_EXPR)
118695 + return false;
118696 +
118697 + if (!integer_zerop(gimple_cond_rhs(dom_stmt)))
118698 + return false;
118699 +
118700 + poss_is_err_cond = gimple_cond_lhs(dom_stmt);
118701 +
118702 + if (TREE_CODE(poss_is_err_cond) != SSA_NAME)
118703 + return false;
118704 +
118705 + call_stmt = SSA_NAME_DEF_STMT(poss_is_err_cond);
118706 +
118707 + if (gimple_code(call_stmt) != GIMPLE_CALL)
118708 + return false;
118709 +
118710 + dom_lhs = gimple_get_lhs(call_stmt);
118711 + poss_is_err_func = gimple_call_fndecl(call_stmt);
118712 + if (!poss_is_err_func)
118713 + return false;
118714 + if (dom_lhs != poss_is_err_cond)
118715 + return false;
118716 + if (strcmp(DECL_NAME_POINTER(poss_is_err_func), "IS_ERR"))
118717 + return false;
118718 +
118719 + is_err_arg = gimple_call_arg(call_stmt, 0);
118720 + if (!is_err_arg)
118721 + return false;
118722 +
118723 + if (is_err_arg != rhs)
118724 + return false;
118725 +
118726 + return true;
118727 +}
118728 +
118729 +static void handle_local_var_initializers(void)
118730 +{
118731 + tree var;
118732 + unsigned int i;
118733 +
118734 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
118735 + tree init = DECL_INITIAL(var);
118736 + if (!init)
118737 + continue;
118738 + if (TREE_CODE(init) != CONSTRUCTOR)
118739 + continue;
118740 + check_bad_casts_in_constructor(var, init);
118741 + }
118742 +}
118743 +
118744 +/*
118745 + * iterate over all statements to find "bad" casts:
118746 + * those where the address of the start of a structure is cast
118747 + * to a pointer of a structure of a different type, or a
118748 + * structure pointer type is cast to a different structure pointer type
118749 + */
118750 +static unsigned int find_bad_casts(void)
118751 +{
118752 + basic_block bb;
118753 +
118754 + handle_local_var_initializers();
118755 +
118756 + FOR_ALL_BB_FN(bb, cfun) {
118757 + gimple_stmt_iterator gsi;
118758 +
118759 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
118760 + gimple stmt;
118761 + const_tree lhs;
118762 + const_tree lhs_type;
118763 + const_tree rhs1;
118764 + const_tree rhs_type;
118765 + const_tree ptr_lhs_type;
118766 + const_tree ptr_rhs_type;
118767 + const_tree op0;
118768 + const_tree op0_type;
118769 + enum tree_code rhs_code;
118770 +
118771 + stmt = gsi_stmt(gsi);
118772 +
118773 +#ifdef __DEBUG_PLUGIN
118774 +#ifdef __DEBUG_VERBOSE
118775 + debug_gimple_stmt(stmt);
118776 + debug_tree(gimple_get_lhs(stmt));
118777 +#endif
118778 +#endif
118779 +
118780 + if (gimple_code(stmt) != GIMPLE_ASSIGN)
118781 + continue;
118782 +
118783 +#ifdef __DEBUG_PLUGIN
118784 +#ifdef __DEBUG_VERBOSE
118785 + debug_tree(gimple_assign_rhs1(stmt));
118786 +#endif
118787 +#endif
118788 +
118789 + rhs_code = gimple_assign_rhs_code(stmt);
118790 +
118791 + if (rhs_code != ADDR_EXPR && rhs_code != SSA_NAME)
118792 + continue;
118793 +
118794 + lhs = gimple_get_lhs(stmt);
118795 + lhs_type = TREE_TYPE(lhs);
118796 + rhs1 = gimple_assign_rhs1(stmt);
118797 + rhs_type = TREE_TYPE(rhs1);
118798 +
118799 + if (TREE_CODE(rhs_type) != POINTER_TYPE ||
118800 + TREE_CODE(lhs_type) != POINTER_TYPE)
118801 + continue;
118802 +
118803 + ptr_lhs_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(lhs_type))));
118804 + ptr_rhs_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(rhs_type))));
118805 +
118806 + if (ptr_rhs_type == void_type_node)
118807 + continue;
118808 +
118809 + if (ptr_lhs_type == void_type_node)
118810 + continue;
118811 +
118812 + if (dominated_by_is_err(rhs1, bb))
118813 + continue;
118814 +
118815 + if (TREE_CODE(ptr_rhs_type) != RECORD_TYPE) {
118816 +#ifndef __DEBUG_PLUGIN
118817 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(ptr_lhs_type)))
118818 +#endif
118819 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, ptr_rhs_type);
118820 + continue;
118821 + }
118822 +
118823 + if (rhs_code == SSA_NAME && ptr_lhs_type == ptr_rhs_type)
118824 + continue;
118825 +
118826 + if (rhs_code == ADDR_EXPR) {
118827 + op0 = TREE_OPERAND(rhs1, 0);
118828 +
118829 + if (op0 == NULL_TREE)
118830 + continue;
118831 +
118832 + if (TREE_CODE(op0) != VAR_DECL)
118833 + continue;
118834 +
118835 + op0_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(op0))));
118836 + if (op0_type == ptr_lhs_type)
118837 + continue;
118838 +
118839 +#ifndef __DEBUG_PLUGIN
118840 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(op0_type)))
118841 +#endif
118842 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, op0_type);
118843 + } else {
118844 + const_tree ssa_name_var = SSA_NAME_VAR(rhs1);
118845 + /* skip bogus type casts introduced by container_of */
118846 + if (ssa_name_var != NULL_TREE && DECL_NAME(ssa_name_var) &&
118847 + !strcmp((const char *)DECL_NAME_POINTER(ssa_name_var), "__mptr"))
118848 + continue;
118849 +#ifndef __DEBUG_PLUGIN
118850 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(ptr_rhs_type)))
118851 +#endif
118852 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, ptr_rhs_type);
118853 + }
118854 +
118855 + }
118856 + }
118857 + return 0;
118858 +}
118859 +
118860 +#if BUILDING_GCC_VERSION >= 4009
118861 +static const struct pass_data randomize_layout_bad_cast_data = {
118862 +#else
118863 +static struct gimple_opt_pass randomize_layout_bad_cast = {
118864 + .pass = {
118865 +#endif
118866 + .type = GIMPLE_PASS,
118867 + .name = "randomize_layout_bad_cast",
118868 +#if BUILDING_GCC_VERSION >= 4008
118869 + .optinfo_flags = OPTGROUP_NONE,
118870 +#endif
118871 +#if BUILDING_GCC_VERSION >= 4009
118872 + .has_gate = false,
118873 + .has_execute = true,
118874 +#else
118875 + .gate = NULL,
118876 + .execute = find_bad_casts,
118877 + .sub = NULL,
118878 + .next = NULL,
118879 + .static_pass_number = 0,
118880 +#endif
118881 + .tv_id = TV_NONE,
118882 + .properties_required = PROP_cfg,
118883 + .properties_provided = 0,
118884 + .properties_destroyed = 0,
118885 + .todo_flags_start = 0,
118886 + .todo_flags_finish = TODO_dump_func
118887 +#if BUILDING_GCC_VERSION < 4009
118888 + }
118889 +#endif
118890 +};
118891 +
118892 +#if BUILDING_GCC_VERSION >= 4009
118893 +namespace {
118894 +class randomize_layout_bad_cast : public gimple_opt_pass {
118895 +public:
118896 + randomize_layout_bad_cast() : gimple_opt_pass(randomize_layout_bad_cast_data, g) {}
118897 + unsigned int execute() { return find_bad_casts(); }
118898 +};
118899 +}
118900 +#endif
118901 +
118902 +static struct opt_pass *make_randomize_layout_bad_cast(void)
118903 +{
118904 +#if BUILDING_GCC_VERSION >= 4009
118905 + return new randomize_layout_bad_cast();
118906 +#else
118907 + return &randomize_layout_bad_cast.pass;
118908 +#endif
118909 +}
118910 +
118911 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
118912 +{
118913 + int i;
118914 + const char * const plugin_name = plugin_info->base_name;
118915 + const int argc = plugin_info->argc;
118916 + const struct plugin_argument * const argv = plugin_info->argv;
118917 + bool enable = true;
118918 + int obtained_seed = 0;
118919 + struct register_pass_info randomize_layout_bad_cast_info;
118920 +
118921 + randomize_layout_bad_cast_info.pass = make_randomize_layout_bad_cast();
118922 + randomize_layout_bad_cast_info.reference_pass_name = "ssa";
118923 + randomize_layout_bad_cast_info.ref_pass_instance_number = 1;
118924 + randomize_layout_bad_cast_info.pos_op = PASS_POS_INSERT_AFTER;
118925 +
118926 + if (!plugin_default_version_check(version, &gcc_version)) {
118927 + error(G_("incompatible gcc/plugin versions"));
118928 + return 1;
118929 + }
118930 +
118931 + if (strcmp(lang_hooks.name, "GNU C")) {
118932 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
118933 + enable = false;
118934 + }
118935 +
118936 + for (i = 0; i < argc; ++i) {
118937 + if (!strcmp(argv[i].key, "disable")) {
118938 + enable = false;
118939 + continue;
118940 + }
118941 + if (!strcmp(argv[i].key, "performance-mode")) {
118942 + performance_mode = 1;
118943 + continue;
118944 + }
118945 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
118946 + }
118947 +
118948 + if (strlen(randstruct_seed) != 64) {
118949 + error(G_("invalid seed value supplied for %s plugin"), plugin_name);
118950 + return 1;
118951 + }
118952 + obtained_seed = sscanf(randstruct_seed, "%016llx%016llx%016llx%016llx",
118953 + &shuffle_seed[0], &shuffle_seed[1], &shuffle_seed[2], &shuffle_seed[3]);
118954 + if (obtained_seed != 4) {
118955 + error(G_("Invalid seed supplied for %s plugin"), plugin_name);
118956 + return 1;
118957 + }
118958 +
118959 + register_callback(plugin_name, PLUGIN_INFO, NULL, &randomize_layout_plugin_info);
118960 + if (enable) {
118961 + register_callback(plugin_name, PLUGIN_ALL_IPA_PASSES_START, check_global_variables, NULL);
118962 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &randomize_layout_bad_cast_info);
118963 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
118964 + register_callback(plugin_name, PLUGIN_FINISH_DECL, randomize_layout_finish_decl, NULL);
118965 + }
118966 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
118967 +
118968 + return 0;
118969 +}
118970 diff --git a/tools/gcc/size_overflow_plugin/.gitignore b/tools/gcc/size_overflow_plugin/.gitignore
118971 new file mode 100644
118972 index 0000000..1f0214f
118973 --- /dev/null
118974 +++ b/tools/gcc/size_overflow_plugin/.gitignore
118975 @@ -0,0 +1,3 @@
118976 +randomize_layout_seed.h
118977 +size_overflow_hash.h
118978 +size_overflow_hash_aux.h
118979 diff --git a/tools/gcc/size_overflow_plugin/Makefile b/tools/gcc/size_overflow_plugin/Makefile
118980 new file mode 100644
118981 index 0000000..1ae2ed5
118982 --- /dev/null
118983 +++ b/tools/gcc/size_overflow_plugin/Makefile
118984 @@ -0,0 +1,20 @@
118985 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
118986 +always := $($(HOSTLIBS)-y)
118987 +
118988 +size_overflow_plugin-objs := $(patsubst $(srctree)/$(src)/%.c,%.o,$(wildcard $(srctree)/$(src)/*.c))
118989 +
118990 +$(patsubst $(srctree)/$(src)/%.c,$(obj)/%.o,$(wildcard $(srctree)/$(src)/*.c)): $(objtree)/$(obj)/size_overflow_hash.h $(objtree)/$(obj)/size_overflow_hash_aux.h
118991 +
118992 +quiet_cmd_build_size_overflow_hash = GENHASH $@
118993 + cmd_build_size_overflow_hash = \
118994 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -s size_overflow_hash -d $< -o $@
118995 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
118996 + $(call if_changed,build_size_overflow_hash)
118997 +
118998 +quiet_cmd_build_size_overflow_hash_aux = GENHASH $@
118999 + cmd_build_size_overflow_hash_aux = \
119000 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -s size_overflow_hash_aux -d $< -o $@
119001 +$(objtree)/$(obj)/size_overflow_hash_aux.h: $(src)/size_overflow_hash_aux.data FORCE
119002 + $(call if_changed,build_size_overflow_hash_aux)
119003 +
119004 +targets += size_overflow_hash.h size_overflow_hash_aux.h
119005 diff --git a/tools/gcc/size_overflow_plugin/generate_size_overflow_hash.sh b/tools/gcc/size_overflow_plugin/generate_size_overflow_hash.sh
119006 new file mode 100644
119007 index 0000000..12b1e3b
119008 --- /dev/null
119009 +++ b/tools/gcc/size_overflow_plugin/generate_size_overflow_hash.sh
119010 @@ -0,0 +1,102 @@
119011 +#!/bin/bash
119012 +
119013 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
119014 +
119015 +header1="size_overflow_hash.h"
119016 +database="size_overflow_hash.data"
119017 +n=65536
119018 +hashtable_name="size_overflow_hash"
119019 +
119020 +usage() {
119021 +cat <<EOF
119022 +usage: $0 options
119023 +OPTIONS:
119024 + -h|--help help
119025 + -o header file
119026 + -d database file
119027 + -n hash array size
119028 + -s name of the hash table
119029 +EOF
119030 + return 0
119031 +}
119032 +
119033 +while true
119034 +do
119035 + case "$1" in
119036 + -h|--help) usage && exit 0;;
119037 + -n) n=$2; shift 2;;
119038 + -o) header1="$2"; shift 2;;
119039 + -d) database="$2"; shift 2;;
119040 + -s) hashtable_name="$2"; shift 2;;
119041 + --) shift 1; break ;;
119042 + *) break ;;
119043 + esac
119044 +done
119045 +
119046 +create_defines() {
119047 + for i in `seq 0 31`
119048 + do
119049 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
119050 + done
119051 + echo >> "$header1"
119052 +}
119053 +
119054 +create_structs() {
119055 + rm -f "$header1"
119056 +
119057 + create_defines
119058 +
119059 + cat "$database" | while read data
119060 + do
119061 + data_array=($data)
119062 + struct_hash_name="${data_array[0]}"
119063 + funcn="${data_array[1]}"
119064 + params="${data_array[2]}"
119065 + next="${data_array[4]}"
119066 +
119067 + echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
119068 +
119069 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
119070 + echo -en "\t.param\t= " >> "$header1"
119071 + line=
119072 + for param_num in ${params//-/ };
119073 + do
119074 + line="${line}PARAM"$param_num"|"
119075 + done
119076 +
119077 + echo -e "${line%?},\n};\n" >> "$header1"
119078 + done
119079 +}
119080 +
119081 +create_headers() {
119082 + echo "const struct size_overflow_hash * const $hashtable_name[$n] = {" >> "$header1"
119083 +}
119084 +
119085 +create_array_elements() {
119086 + index=0
119087 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
119088 + do
119089 + data_array=($data)
119090 + i="${data_array[3]}"
119091 + hash="${data_array[0]}"
119092 + while [[ $index -lt $i ]]
119093 + do
119094 + echo -e "\t["$index"]\t= NULL," >> "$header1"
119095 + index=$(($index + 1))
119096 + done
119097 + index=$(($index + 1))
119098 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
119099 + done
119100 + echo '};' >> $header1
119101 +}
119102 +
119103 +size_overflow_plugin_dir=`dirname $header1`
119104 +if [ "$size_overflow_plugin_dir" != '.' ]; then
119105 + mkdir -p "$size_overflow_plugin_dir" 2> /dev/null
119106 +fi
119107 +
119108 +create_structs
119109 +create_headers
119110 +create_array_elements
119111 +
119112 +exit 0
119113 diff --git a/tools/gcc/size_overflow_plugin/insert_size_overflow_asm.c b/tools/gcc/size_overflow_plugin/insert_size_overflow_asm.c
119114 new file mode 100644
119115 index 0000000..c43901f
119116 --- /dev/null
119117 +++ b/tools/gcc/size_overflow_plugin/insert_size_overflow_asm.c
119118 @@ -0,0 +1,748 @@
119119 +/*
119120 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
119121 + * Licensed under the GPL v2, or (at your option) v3
119122 + *
119123 + * Homepage:
119124 + * http://www.grsecurity.net/~ephox/overflow_plugin/
119125 + *
119126 + * Documentation:
119127 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
119128 + *
119129 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
119130 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
119131 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
119132 + *
119133 + * Usage:
119134 + * $ make
119135 + * $ make run
119136 + */
119137 +
119138 +#include "gcc-common.h"
119139 +#include "size_overflow.h"
119140 +
119141 +static void search_size_overflow_attribute(struct pointer_set_t *visited, tree lhs);
119142 +static enum mark search_intentional(struct pointer_set_t *visited, const_tree lhs);
119143 +
119144 +// data for the size_overflow asm stmt
119145 +struct asm_data {
119146 + gimple def_stmt;
119147 + tree input;
119148 + tree output;
119149 +};
119150 +
119151 +#if BUILDING_GCC_VERSION <= 4007
119152 +static VEC(tree, gc) *create_asm_io_list(tree string, tree io)
119153 +#else
119154 +static vec<tree, va_gc> *create_asm_io_list(tree string, tree io)
119155 +#endif
119156 +{
119157 + tree list;
119158 +#if BUILDING_GCC_VERSION <= 4007
119159 + VEC(tree, gc) *vec_list = NULL;
119160 +#else
119161 + vec<tree, va_gc> *vec_list = NULL;
119162 +#endif
119163 +
119164 + list = build_tree_list(NULL_TREE, string);
119165 + list = chainon(NULL_TREE, build_tree_list(list, io));
119166 +#if BUILDING_GCC_VERSION <= 4007
119167 + VEC_safe_push(tree, gc, vec_list, list);
119168 +#else
119169 + vec_safe_push(vec_list, list);
119170 +#endif
119171 + return vec_list;
119172 +}
119173 +
119174 +static void create_asm_stmt(const char *str, tree str_input, tree str_output, struct asm_data *asm_data)
119175 +{
119176 + gimple asm_stmt;
119177 + gimple_stmt_iterator gsi;
119178 +#if BUILDING_GCC_VERSION <= 4007
119179 + VEC(tree, gc) *input, *output = NULL;
119180 +#else
119181 + vec<tree, va_gc> *input, *output = NULL;
119182 +#endif
119183 +
119184 + input = create_asm_io_list(str_input, asm_data->input);
119185 +
119186 + if (asm_data->output)
119187 + output = create_asm_io_list(str_output, asm_data->output);
119188 +
119189 + asm_stmt = gimple_build_asm_vec(str, input, output, NULL, NULL);
119190 + gsi = gsi_for_stmt(asm_data->def_stmt);
119191 + gsi_insert_after(&gsi, asm_stmt, GSI_NEW_STMT);
119192 +
119193 + if (asm_data->output)
119194 + SSA_NAME_DEF_STMT(asm_data->output) = asm_stmt;
119195 +}
119196 +
119197 +static void replace_call_lhs(const struct asm_data *asm_data)
119198 +{
119199 + gimple_set_lhs(asm_data->def_stmt, asm_data->input);
119200 + update_stmt(asm_data->def_stmt);
119201 + SSA_NAME_DEF_STMT(asm_data->input) = asm_data->def_stmt;
119202 +}
119203 +
119204 +static enum mark search_intentional_phi(struct pointer_set_t *visited, const_tree result)
119205 +{
119206 + enum mark cur_fndecl_attr;
119207 + gimple phi = get_def_stmt(result);
119208 + unsigned int i, n = gimple_phi_num_args(phi);
119209 +
119210 + pointer_set_insert(visited, phi);
119211 + for (i = 0; i < n; i++) {
119212 + tree arg = gimple_phi_arg_def(phi, i);
119213 +
119214 + cur_fndecl_attr = search_intentional(visited, arg);
119215 + if (cur_fndecl_attr != MARK_NO)
119216 + return cur_fndecl_attr;
119217 + }
119218 + return MARK_NO;
119219 +}
119220 +
119221 +static enum mark search_intentional_binary(struct pointer_set_t *visited, const_tree lhs)
119222 +{
119223 + enum mark cur_fndecl_attr;
119224 + const_tree rhs1, rhs2;
119225 + gimple def_stmt = get_def_stmt(lhs);
119226 +
119227 + rhs1 = gimple_assign_rhs1(def_stmt);
119228 + rhs2 = gimple_assign_rhs2(def_stmt);
119229 +
119230 + cur_fndecl_attr = search_intentional(visited, rhs1);
119231 + if (cur_fndecl_attr != MARK_NO)
119232 + return cur_fndecl_attr;
119233 + return search_intentional(visited, rhs2);
119234 +}
119235 +
119236 +// Look up the intentional_overflow attribute on the caller and the callee functions.
119237 +static enum mark search_intentional(struct pointer_set_t *visited, const_tree lhs)
119238 +{
119239 + const_gimple def_stmt;
119240 +
119241 + if (TREE_CODE(lhs) != SSA_NAME)
119242 + return get_intentional_attr_type(lhs);
119243 +
119244 + def_stmt = get_def_stmt(lhs);
119245 + if (!def_stmt)
119246 + return MARK_NO;
119247 +
119248 + if (pointer_set_contains(visited, def_stmt))
119249 + return MARK_NO;
119250 +
119251 + switch (gimple_code(def_stmt)) {
119252 + case GIMPLE_NOP:
119253 + return search_intentional(visited, SSA_NAME_VAR(lhs));
119254 + case GIMPLE_ASM:
119255 + if (is_size_overflow_intentional_asm_turn_off(def_stmt))
119256 + return MARK_TURN_OFF;
119257 + return MARK_NO;
119258 + case GIMPLE_CALL:
119259 + return MARK_NO;
119260 + case GIMPLE_PHI:
119261 + return search_intentional_phi(visited, lhs);
119262 + case GIMPLE_ASSIGN:
119263 + switch (gimple_num_ops(def_stmt)) {
119264 + case 2:
119265 + return search_intentional(visited, gimple_assign_rhs1(def_stmt));
119266 + case 3:
119267 + return search_intentional_binary(visited, lhs);
119268 + }
119269 + case GIMPLE_RETURN:
119270 + return MARK_NO;
119271 + default:
119272 + debug_gimple_stmt((gimple)def_stmt);
119273 + error("%s: unknown gimple code", __func__);
119274 + gcc_unreachable();
119275 + }
119276 +}
119277 +
119278 +// Check the intentional_overflow attribute and create the asm comment string for the size_overflow asm stmt.
119279 +static enum mark check_intentional_attribute_gimple(const_tree arg, const_gimple stmt, unsigned int argnum)
119280 +{
119281 + const_tree fndecl;
119282 + struct pointer_set_t *visited;
119283 + enum mark cur_fndecl_attr, decl_attr = MARK_NO;
119284 +
119285 + fndecl = get_interesting_orig_fndecl(stmt, argnum);
119286 + if (is_end_intentional_intentional_attr(fndecl, argnum))
119287 + decl_attr = MARK_NOT_INTENTIONAL;
119288 + else if (is_yes_intentional_attr(fndecl, argnum))
119289 + decl_attr = MARK_YES;
119290 + else if (is_turn_off_intentional_attr(fndecl) || is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl))) {
119291 + return MARK_TURN_OFF;
119292 + }
119293 +
119294 + visited = pointer_set_create();
119295 + cur_fndecl_attr = search_intentional(visited, arg);
119296 + pointer_set_destroy(visited);
119297 +
119298 + switch (cur_fndecl_attr) {
119299 + case MARK_NO:
119300 + case MARK_TURN_OFF:
119301 + return cur_fndecl_attr;
119302 + default:
119303 + print_missing_intentional(decl_attr, cur_fndecl_attr, fndecl, argnum);
119304 + return MARK_YES;
119305 + }
119306 +}
119307 +
119308 +static void check_missing_size_overflow_attribute(tree var)
119309 +{
119310 + tree orig_fndecl;
119311 + unsigned int num;
119312 +
119313 + if (is_a_return_check(var))
119314 + orig_fndecl = DECL_ORIGIN(var);
119315 + else
119316 + orig_fndecl = DECL_ORIGIN(current_function_decl);
119317 +
119318 + num = get_function_num(var, orig_fndecl);
119319 + if (num == CANNOT_FIND_ARG)
119320 + return;
119321 +
119322 + is_missing_function(orig_fndecl, num);
119323 +}
119324 +
119325 +static void search_size_overflow_attribute_phi(struct pointer_set_t *visited, const_tree result)
119326 +{
119327 + gimple phi = get_def_stmt(result);
119328 + unsigned int i, n = gimple_phi_num_args(phi);
119329 +
119330 + pointer_set_insert(visited, phi);
119331 + for (i = 0; i < n; i++) {
119332 + tree arg = gimple_phi_arg_def(phi, i);
119333 +
119334 + search_size_overflow_attribute(visited, arg);
119335 + }
119336 +}
119337 +
119338 +static void search_size_overflow_attribute_binary(struct pointer_set_t *visited, const_tree lhs)
119339 +{
119340 + const_gimple def_stmt = get_def_stmt(lhs);
119341 + tree rhs1, rhs2;
119342 +
119343 + rhs1 = gimple_assign_rhs1(def_stmt);
119344 + rhs2 = gimple_assign_rhs2(def_stmt);
119345 +
119346 + search_size_overflow_attribute(visited, rhs1);
119347 + search_size_overflow_attribute(visited, rhs2);
119348 +}
119349 +
119350 +static void search_size_overflow_attribute(struct pointer_set_t *visited, tree lhs)
119351 +{
119352 + const_gimple def_stmt;
119353 +
119354 + if (TREE_CODE(lhs) == PARM_DECL) {
119355 + check_missing_size_overflow_attribute(lhs);
119356 + return;
119357 + }
119358 +
119359 + def_stmt = get_def_stmt(lhs);
119360 + if (!def_stmt)
119361 + return;
119362 +
119363 + if (pointer_set_insert(visited, def_stmt))
119364 + return;
119365 +
119366 + switch (gimple_code(def_stmt)) {
119367 + case GIMPLE_NOP:
119368 + return search_size_overflow_attribute(visited, SSA_NAME_VAR(lhs));
119369 + case GIMPLE_ASM:
119370 + return;
119371 + case GIMPLE_CALL: {
119372 + tree fndecl = gimple_call_fndecl(def_stmt);
119373 +
119374 + if (fndecl == NULL_TREE)
119375 + return;
119376 + check_missing_size_overflow_attribute(fndecl);
119377 + return;
119378 + }
119379 + case GIMPLE_PHI:
119380 + return search_size_overflow_attribute_phi(visited, lhs);
119381 + case GIMPLE_ASSIGN:
119382 + switch (gimple_num_ops(def_stmt)) {
119383 + case 2:
119384 + return search_size_overflow_attribute(visited, gimple_assign_rhs1(def_stmt));
119385 + case 3:
119386 + return search_size_overflow_attribute_binary(visited, lhs);
119387 + }
119388 + default:
119389 + debug_gimple_stmt((gimple)def_stmt);
119390 + error("%s: unknown gimple code", __func__);
119391 + gcc_unreachable();
119392 + }
119393 +}
119394 +
119395 +// Search missing entries in the hash table (invoked from the gimple pass)
119396 +static void search_missing_size_overflow_attribute_gimple(const_gimple stmt, unsigned int num)
119397 +{
119398 + tree fndecl = NULL_TREE;
119399 + tree lhs;
119400 + struct pointer_set_t *visited;
119401 +
119402 + if (is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl)))
119403 + return;
119404 +
119405 + if (num == 0) {
119406 + gcc_assert(gimple_code(stmt) == GIMPLE_RETURN);
119407 + lhs = gimple_return_retval(stmt);
119408 + } else {
119409 + gcc_assert(is_gimple_call(stmt));
119410 + lhs = gimple_call_arg(stmt, num - 1);
119411 + fndecl = gimple_call_fndecl(stmt);
119412 + }
119413 +
119414 + if (fndecl != NULL_TREE && is_turn_off_intentional_attr(DECL_ORIGIN(fndecl)))
119415 + return;
119416 +
119417 + visited = pointer_set_create();
119418 + search_size_overflow_attribute(visited, lhs);
119419 + pointer_set_destroy(visited);
119420 +}
119421 +
119422 +static void create_output_from_phi(gimple stmt, unsigned int argnum, struct asm_data *asm_data)
119423 +{
119424 + gimple_stmt_iterator gsi;
119425 + gimple assign;
119426 +
119427 + assign = gimple_build_assign(asm_data->input, asm_data->output);
119428 + gsi = gsi_for_stmt(stmt);
119429 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
119430 + asm_data->def_stmt = assign;
119431 +
119432 + asm_data->output = create_new_var(TREE_TYPE(asm_data->output));
119433 + asm_data->output = make_ssa_name(asm_data->output, stmt);
119434 + if (gimple_code(stmt) == GIMPLE_RETURN)
119435 + gimple_return_set_retval(stmt, asm_data->output);
119436 + else
119437 + gimple_call_set_arg(stmt, argnum - 1, asm_data->output);
119438 + update_stmt(stmt);
119439 +}
119440 +
119441 +static char *create_asm_comment(unsigned int argnum, const_gimple stmt , const char *mark_str)
119442 +{
119443 + const char *fn_name;
119444 + char *asm_comment;
119445 + unsigned int len;
119446 +
119447 + if (argnum == 0)
119448 + fn_name = DECL_NAME_POINTER(current_function_decl);
119449 + else
119450 + fn_name = DECL_NAME_POINTER(gimple_call_fndecl(stmt));
119451 +
119452 + len = asprintf(&asm_comment, "%s %s %u", mark_str, fn_name, argnum);
119453 + gcc_assert(len > 0);
119454 +
119455 + return asm_comment;
119456 +}
119457 +
119458 +static const char *convert_mark_to_str(enum mark mark)
119459 +{
119460 + switch (mark) {
119461 + case MARK_NO:
119462 + return OK_ASM_STR;
119463 + case MARK_YES:
119464 + case MARK_NOT_INTENTIONAL:
119465 + return YES_ASM_STR;
119466 + case MARK_TURN_OFF:
119467 + return TURN_OFF_ASM_STR;
119468 + }
119469 +
119470 + gcc_unreachable();
119471 +}
119472 +
119473 +/* Create the input of the size_overflow asm stmt.
119474 + * When the arg of the callee function is a parm_decl it creates this kind of size_overflow asm stmt:
119475 + * __asm__("# size_overflow MARK_YES" : : "rm" size_1(D));
119476 + * The input field in asm_data will be empty if there is no need for further size_overflow asm stmt insertion.
119477 + * otherwise create the input (for a phi stmt the output too) of the asm stmt.
119478 + */
119479 +static void create_asm_input(gimple stmt, unsigned int argnum, struct asm_data *asm_data)
119480 +{
119481 + if (!asm_data->def_stmt) {
119482 + asm_data->input = NULL_TREE;
119483 + return;
119484 + }
119485 +
119486 + asm_data->input = create_new_var(TREE_TYPE(asm_data->output));
119487 + asm_data->input = make_ssa_name(asm_data->input, asm_data->def_stmt);
119488 +
119489 + switch (gimple_code(asm_data->def_stmt)) {
119490 + case GIMPLE_ASSIGN:
119491 + case GIMPLE_CALL:
119492 + replace_call_lhs(asm_data);
119493 + break;
119494 + case GIMPLE_PHI:
119495 + create_output_from_phi(stmt, argnum, asm_data);
119496 + break;
119497 + case GIMPLE_NOP: {
119498 + enum mark mark;
119499 + const char *mark_str;
119500 + char *asm_comment;
119501 +
119502 + mark = check_intentional_attribute_gimple(asm_data->output, stmt, argnum);
119503 +
119504 + asm_data->input = asm_data->output;
119505 + asm_data->output = NULL;
119506 + asm_data->def_stmt = stmt;
119507 +
119508 + mark_str = convert_mark_to_str(mark);
119509 + asm_comment = create_asm_comment(argnum, stmt, mark_str);
119510 +
119511 + create_asm_stmt(asm_comment, build_string(3, "rm"), NULL, asm_data);
119512 + free(asm_comment);
119513 + asm_data->input = NULL_TREE;
119514 + break;
119515 + }
119516 + case GIMPLE_ASM:
119517 + if (is_size_overflow_asm(asm_data->def_stmt)) {
119518 + asm_data->input = NULL_TREE;
119519 + break;
119520 + }
119521 + default:
119522 + debug_gimple_stmt(asm_data->def_stmt);
119523 + gcc_unreachable();
119524 + }
119525 +}
119526 +
119527 +/* This is the gimple part of searching for a missing size_overflow attribute. If the intentional_overflow attribute type
119528 + * is of the right kind create the appropriate size_overflow asm stmts:
119529 + * __asm__("# size_overflow" : =rm" D.3344_8 : "0" cicus.4_16);
119530 + * __asm__("# size_overflow MARK_YES" : : "rm" size_1(D));
119531 + */
119532 +static void create_size_overflow_asm(gimple stmt, tree output_node, unsigned int argnum)
119533 +{
119534 + struct asm_data asm_data;
119535 + const char *mark_str;
119536 + char *asm_comment;
119537 + enum mark mark;
119538 +
119539 + if (is_gimple_constant(output_node))
119540 + return;
119541 +
119542 + asm_data.output = output_node;
119543 + mark = check_intentional_attribute_gimple(asm_data.output, stmt, argnum);
119544 + if (mark != MARK_TURN_OFF)
119545 + search_missing_size_overflow_attribute_gimple(stmt, argnum);
119546 +
119547 + asm_data.def_stmt = get_def_stmt(asm_data.output);
119548 + if (is_size_overflow_intentional_asm_turn_off(asm_data.def_stmt))
119549 + return;
119550 +
119551 + create_asm_input(stmt, argnum, &asm_data);
119552 + if (asm_data.input == NULL_TREE)
119553 + return;
119554 +
119555 + mark_str = convert_mark_to_str(mark);
119556 + asm_comment = create_asm_comment(argnum, stmt, mark_str);
119557 + create_asm_stmt(asm_comment, build_string(2, "0"), build_string(4, "=rm"), &asm_data);
119558 + free(asm_comment);
119559 +}
119560 +
119561 +// Insert an asm stmt with "MARK_TURN_OFF", "MARK_YES" or "MARK_NOT_INTENTIONAL".
119562 +static bool create_mark_asm(gimple stmt, enum mark mark)
119563 +{
119564 + struct asm_data asm_data;
119565 + const char *asm_str;
119566 +
119567 + switch (mark) {
119568 + case MARK_TURN_OFF:
119569 + asm_str = TURN_OFF_ASM_STR;
119570 + break;
119571 + case MARK_NOT_INTENTIONAL:
119572 + case MARK_YES:
119573 + asm_str = YES_ASM_STR;
119574 + break;
119575 + default:
119576 + gcc_unreachable();
119577 + }
119578 +
119579 + asm_data.def_stmt = stmt;
119580 + asm_data.output = gimple_call_lhs(stmt);
119581 +
119582 + if (asm_data.output == NULL_TREE) {
119583 + asm_data.input = gimple_call_arg(stmt, 0);
119584 + if (is_gimple_constant(asm_data.input))
119585 + return false;
119586 + asm_data.output = NULL;
119587 + create_asm_stmt(asm_str, build_string(3, "rm"), NULL, &asm_data);
119588 + return true;
119589 + }
119590 +
119591 + create_asm_input(stmt, 0, &asm_data);
119592 + gcc_assert(asm_data.input != NULL_TREE);
119593 +
119594 + create_asm_stmt(asm_str, build_string(2, "0"), build_string(4, "=rm"), &asm_data);
119595 + return true;
119596 +}
119597 +
119598 +static void walk_use_def_ptr(struct pointer_set_t *visited, const_tree lhs)
119599 +{
119600 + gimple def_stmt;
119601 +
119602 + def_stmt = get_def_stmt(lhs);
119603 + if (!def_stmt)
119604 + return;
119605 +
119606 + if (pointer_set_insert(visited, def_stmt))
119607 + return;
119608 +
119609 + switch (gimple_code(def_stmt)) {
119610 + case GIMPLE_NOP:
119611 + case GIMPLE_ASM:
119612 + case GIMPLE_CALL:
119613 + break;
119614 + case GIMPLE_PHI: {
119615 + unsigned int i, n = gimple_phi_num_args(def_stmt);
119616 +
119617 + pointer_set_insert(visited, def_stmt);
119618 +
119619 + for (i = 0; i < n; i++) {
119620 + tree arg = gimple_phi_arg_def(def_stmt, i);
119621 +
119622 + walk_use_def_ptr(visited, arg);
119623 + }
119624 + }
119625 + case GIMPLE_ASSIGN:
119626 + switch (gimple_num_ops(def_stmt)) {
119627 + case 2:
119628 + walk_use_def_ptr(visited, gimple_assign_rhs1(def_stmt));
119629 + return;
119630 + case 3:
119631 + walk_use_def_ptr(visited, gimple_assign_rhs1(def_stmt));
119632 + walk_use_def_ptr(visited, gimple_assign_rhs2(def_stmt));
119633 + return;
119634 + default:
119635 + return;
119636 + }
119637 + default:
119638 + debug_gimple_stmt((gimple)def_stmt);
119639 + error("%s: unknown gimple code", __func__);
119640 + gcc_unreachable();
119641 + }
119642 +}
119643 +
119644 +// Look for a ptr - ptr expression (e.g., cpuset_common_file_read() s - page)
119645 +static void insert_mark_not_intentional_asm_at_ptr(const_tree arg)
119646 +{
119647 + struct pointer_set_t *visited;
119648 +
119649 + visited = pointer_set_create();
119650 + walk_use_def_ptr(visited, arg);
119651 + pointer_set_destroy(visited);
119652 +}
119653 +
119654 +// Determine the return value and insert the asm stmt to mark the return stmt.
119655 +static void insert_asm_ret(gimple stmt)
119656 +{
119657 + tree ret;
119658 +
119659 + ret = gimple_return_retval(stmt);
119660 + create_size_overflow_asm(stmt, ret, 0);
119661 +}
119662 +
119663 +// Determine the correct arg index and arg and insert the asm stmt to mark the stmt.
119664 +static void insert_asm_arg(gimple stmt, unsigned int orig_argnum)
119665 +{
119666 + tree arg;
119667 + unsigned int argnum;
119668 +
119669 + argnum = get_correct_arg_count(orig_argnum, gimple_call_fndecl(stmt));
119670 + gcc_assert(argnum != 0);
119671 + if (argnum == CANNOT_FIND_ARG)
119672 + return;
119673 +
119674 + arg = gimple_call_arg(stmt, argnum - 1);
119675 + gcc_assert(arg != NULL_TREE);
119676 +
119677 + // skip all ptr - ptr expressions
119678 + insert_mark_not_intentional_asm_at_ptr(arg);
119679 +
119680 + create_size_overflow_asm(stmt, arg, argnum);
119681 +}
119682 +
119683 +// If a function arg or the return value is marked by the size_overflow attribute then set its index in the array.
119684 +static void set_argnum_attribute(const_tree attr, bool *argnums)
119685 +{
119686 + unsigned int argnum;
119687 + tree attr_value;
119688 +
119689 + for (attr_value = TREE_VALUE(attr); attr_value; attr_value = TREE_CHAIN(attr_value)) {
119690 + argnum = TREE_INT_CST_LOW(TREE_VALUE(attr_value));
119691 + argnums[argnum] = true;
119692 + }
119693 +}
119694 +
119695 +// If a function arg or the return value is in the hash table then set its index in the array.
119696 +static void set_argnum_hash(tree fndecl, bool *argnums)
119697 +{
119698 + unsigned int num;
119699 + const struct size_overflow_hash *hash;
119700 +
119701 + hash = get_function_hash(DECL_ORIGIN(fndecl));
119702 + if (!hash)
119703 + return;
119704 +
119705 + for (num = 0; num <= MAX_PARAM; num++) {
119706 + if (!(hash->param & (1U << num)))
119707 + continue;
119708 +
119709 + argnums[num] = true;
119710 + }
119711 +}
119712 +
119713 +static bool is_all_the_argnums_empty(bool *argnums)
119714 +{
119715 + unsigned int i;
119716 +
119717 + for (i = 0; i <= MAX_PARAM; i++)
119718 + if (argnums[i])
119719 + return false;
119720 + return true;
119721 +}
119722 +
119723 +// Check whether the arguments or the return value of the function are in the hash table or are marked by the size_overflow attribute.
119724 +static void search_interesting_args(tree fndecl, bool *argnums)
119725 +{
119726 + const_tree attr;
119727 +
119728 + set_argnum_hash(fndecl, argnums);
119729 + if (!is_all_the_argnums_empty(argnums))
119730 + return;
119731 +
119732 + attr = lookup_attribute("size_overflow", DECL_ATTRIBUTES(fndecl));
119733 + if (attr && TREE_VALUE(attr))
119734 + set_argnum_attribute(attr, argnums);
119735 +}
119736 +
119737 +/*
119738 + * Look up the intentional_overflow attribute that turns off ipa based duplication
119739 + * on the callee function.
119740 + */
119741 +static bool is_mark_turn_off_attribute(gimple stmt)
119742 +{
119743 + enum mark mark;
119744 + const_tree fndecl = gimple_call_fndecl(stmt);
119745 +
119746 + mark = get_intentional_attr_type(DECL_ORIGIN(fndecl));
119747 + if (mark == MARK_TURN_OFF)
119748 + return true;
119749 + return false;
119750 +}
119751 +
119752 +// 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
119753 +static void handle_interesting_function(gimple stmt)
119754 +{
119755 + unsigned int argnum;
119756 + tree fndecl;
119757 + bool orig_argnums[MAX_PARAM + 1] = {false};
119758 +
119759 + if (gimple_call_num_args(stmt) == 0)
119760 + return;
119761 + fndecl = gimple_call_fndecl(stmt);
119762 + if (fndecl == NULL_TREE)
119763 + return;
119764 + fndecl = DECL_ORIGIN(fndecl);
119765 +
119766 + if (is_mark_turn_off_attribute(stmt)) {
119767 + create_mark_asm(stmt, MARK_TURN_OFF);
119768 + return;
119769 + }
119770 +
119771 + search_interesting_args(fndecl, orig_argnums);
119772 +
119773 + for (argnum = 1; argnum < MAX_PARAM; argnum++)
119774 + if (orig_argnums[argnum])
119775 + insert_asm_arg(stmt, argnum);
119776 +}
119777 +
119778 +// 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
119779 +static void handle_interesting_ret(gimple stmt)
119780 +{
119781 + bool orig_argnums[MAX_PARAM + 1] = {false};
119782 +
119783 + search_interesting_args(current_function_decl, orig_argnums);
119784 +
119785 + if (orig_argnums[0])
119786 + insert_asm_ret(stmt);
119787 +}
119788 +
119789 +// Iterate over all the stmts and search for call and return stmts and mark them if they're in the hash table
119790 +static unsigned int search_interesting_functions(void)
119791 +{
119792 + basic_block bb;
119793 +
119794 + FOR_ALL_BB_FN(bb, cfun) {
119795 + gimple_stmt_iterator gsi;
119796 +
119797 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
119798 + gimple stmt = gsi_stmt(gsi);
119799 +
119800 + if (is_size_overflow_asm(stmt))
119801 + continue;
119802 +
119803 + if (is_gimple_call(stmt))
119804 + handle_interesting_function(stmt);
119805 + else if (gimple_code(stmt) == GIMPLE_RETURN)
119806 + handle_interesting_ret(stmt);
119807 + }
119808 + }
119809 + return 0;
119810 +}
119811 +
119812 +/*
119813 + * A lot of functions get inlined before the ipa passes so after the build_ssa gimple pass
119814 + * this pass inserts asm stmts to mark the interesting args
119815 + * that the ipa pass will detect and insert the size overflow checks for.
119816 + */
119817 +#if BUILDING_GCC_VERSION >= 4009
119818 +static const struct pass_data insert_size_overflow_asm_pass_data = {
119819 +#else
119820 +static struct gimple_opt_pass insert_size_overflow_asm_pass = {
119821 + .pass = {
119822 +#endif
119823 + .type = GIMPLE_PASS,
119824 + .name = "insert_size_overflow_asm",
119825 +#if BUILDING_GCC_VERSION >= 4008
119826 + .optinfo_flags = OPTGROUP_NONE,
119827 +#endif
119828 +#if BUILDING_GCC_VERSION >= 4009
119829 + .has_gate = false,
119830 + .has_execute = true,
119831 +#else
119832 + .gate = NULL,
119833 + .execute = search_interesting_functions,
119834 + .sub = NULL,
119835 + .next = NULL,
119836 + .static_pass_number = 0,
119837 +#endif
119838 + .tv_id = TV_NONE,
119839 + .properties_required = PROP_cfg,
119840 + .properties_provided = 0,
119841 + .properties_destroyed = 0,
119842 + .todo_flags_start = 0,
119843 + .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
119844 +#if BUILDING_GCC_VERSION < 4009
119845 + }
119846 +#endif
119847 +};
119848 +
119849 +#if BUILDING_GCC_VERSION >= 4009
119850 +namespace {
119851 +class insert_size_overflow_asm_pass : public gimple_opt_pass {
119852 +public:
119853 + insert_size_overflow_asm_pass() : gimple_opt_pass(insert_size_overflow_asm_pass_data, g) {}
119854 + unsigned int execute() { return search_interesting_functions(); }
119855 +};
119856 +}
119857 +#endif
119858 +
119859 +struct opt_pass *make_insert_size_overflow_asm_pass(void)
119860 +{
119861 +#if BUILDING_GCC_VERSION >= 4009
119862 + return new insert_size_overflow_asm_pass();
119863 +#else
119864 + return &insert_size_overflow_asm_pass.pass;
119865 +#endif
119866 +}
119867 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
119868 new file mode 100644
119869 index 0000000..73f0a12
119870 --- /dev/null
119871 +++ b/tools/gcc/size_overflow_plugin/insert_size_overflow_check_core.c
119872 @@ -0,0 +1,943 @@
119873 +/*
119874 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
119875 + * Licensed under the GPL v2, or (at your option) v3
119876 + *
119877 + * Homepage:
119878 + * http://www.grsecurity.net/~ephox/overflow_plugin/
119879 + *
119880 + * Documentation:
119881 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
119882 + *
119883 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
119884 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
119885 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
119886 + *
119887 + * Usage:
119888 + * $ make
119889 + * $ make run
119890 + */
119891 +
119892 +#include "gcc-common.h"
119893 +#include "size_overflow.h"
119894 +
119895 +#define MIN_CHECK true
119896 +#define MAX_CHECK false
119897 +
119898 +static tree get_size_overflow_type(struct visited *visited, const_gimple stmt, const_tree node)
119899 +{
119900 + const_tree type;
119901 + tree new_type;
119902 +
119903 + gcc_assert(node != NULL_TREE);
119904 +
119905 + type = TREE_TYPE(node);
119906 +
119907 + if (pointer_set_contains(visited->my_stmts, stmt))
119908 + return TREE_TYPE(node);
119909 +
119910 + switch (TYPE_MODE(type)) {
119911 + case QImode:
119912 + new_type = size_overflow_type_HI;
119913 + break;
119914 + case HImode:
119915 + new_type = size_overflow_type_SI;
119916 + break;
119917 + case SImode:
119918 + new_type = size_overflow_type_DI;
119919 + break;
119920 + case DImode:
119921 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
119922 + new_type = TYPE_UNSIGNED(type) ? unsigned_intDI_type_node : intDI_type_node;
119923 + else
119924 + new_type = size_overflow_type_TI;
119925 + break;
119926 + case TImode:
119927 + gcc_assert(!TYPE_UNSIGNED(type));
119928 + new_type = size_overflow_type_TI;
119929 + break;
119930 + default:
119931 + debug_tree((tree)node);
119932 + error("%s: unsupported gcc configuration (%qE).", __func__, current_function_decl);
119933 + gcc_unreachable();
119934 + }
119935 +
119936 + if (TYPE_QUALS(type) != 0)
119937 + return build_qualified_type(new_type, TYPE_QUALS(type));
119938 + return new_type;
119939 +}
119940 +
119941 +static tree get_lhs(const_gimple stmt)
119942 +{
119943 + switch (gimple_code(stmt)) {
119944 + case GIMPLE_ASSIGN:
119945 + case GIMPLE_CALL:
119946 + return gimple_get_lhs(stmt);
119947 + case GIMPLE_PHI:
119948 + return gimple_phi_result(stmt);
119949 + default:
119950 + return NULL_TREE;
119951 + }
119952 +}
119953 +
119954 +static tree cast_to_new_size_overflow_type(struct visited *visited, gimple stmt, tree rhs, tree size_overflow_type, bool before)
119955 +{
119956 + gimple_stmt_iterator gsi;
119957 + tree lhs;
119958 + gimple new_stmt;
119959 +
119960 + if (rhs == NULL_TREE)
119961 + return NULL_TREE;
119962 +
119963 + gsi = gsi_for_stmt(stmt);
119964 + new_stmt = build_cast_stmt(visited, size_overflow_type, rhs, CREATE_NEW_VAR, &gsi, before, false);
119965 + pointer_set_insert(visited->my_stmts, new_stmt);
119966 +
119967 + lhs = get_lhs(new_stmt);
119968 + gcc_assert(lhs != NULL_TREE);
119969 + return lhs;
119970 +}
119971 +
119972 +tree create_assign(struct visited *visited, gimple oldstmt, tree rhs1, bool before)
119973 +{
119974 + tree lhs, dst_type;
119975 + gimple_stmt_iterator gsi;
119976 +
119977 + if (rhs1 == NULL_TREE) {
119978 + debug_gimple_stmt(oldstmt);
119979 + error("%s: rhs1 is NULL_TREE", __func__);
119980 + gcc_unreachable();
119981 + }
119982 +
119983 + switch (gimple_code(oldstmt)) {
119984 + case GIMPLE_ASM:
119985 + lhs = rhs1;
119986 + break;
119987 + case GIMPLE_CALL:
119988 + case GIMPLE_ASSIGN:
119989 + lhs = gimple_get_lhs(oldstmt);
119990 + break;
119991 + default:
119992 + debug_gimple_stmt(oldstmt);
119993 + gcc_unreachable();
119994 + }
119995 +
119996 + gsi = gsi_for_stmt(oldstmt);
119997 + pointer_set_insert(visited->stmts, oldstmt);
119998 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
119999 + basic_block next_bb, cur_bb;
120000 + const_edge e;
120001 +
120002 + gcc_assert(before == false);
120003 + gcc_assert(stmt_can_throw_internal(oldstmt));
120004 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
120005 + gcc_assert(!gsi_end_p(gsi));
120006 +
120007 + cur_bb = gimple_bb(oldstmt);
120008 + next_bb = cur_bb->next_bb;
120009 + e = find_edge(cur_bb, next_bb);
120010 + gcc_assert(e != NULL);
120011 + gcc_assert(e->flags & EDGE_FALLTHRU);
120012 +
120013 + gsi = gsi_after_labels(next_bb);
120014 + gcc_assert(!gsi_end_p(gsi));
120015 +
120016 + before = true;
120017 + oldstmt = gsi_stmt(gsi);
120018 + }
120019 +
120020 + dst_type = get_size_overflow_type(visited, oldstmt, lhs);
120021 +
120022 + if (is_gimple_constant(rhs1))
120023 + return cast_a_tree(dst_type, rhs1);
120024 + return cast_to_new_size_overflow_type(visited, oldstmt, rhs1, dst_type, before);
120025 +}
120026 +
120027 +tree dup_assign(struct visited *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3)
120028 +{
120029 + gimple stmt;
120030 + gimple_stmt_iterator gsi;
120031 + tree size_overflow_type, new_var, lhs = gimple_assign_lhs(oldstmt);
120032 +
120033 + if (pointer_set_contains(visited->my_stmts, oldstmt))
120034 + return lhs;
120035 +
120036 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
120037 + rhs1 = gimple_assign_rhs1(oldstmt);
120038 + rhs1 = create_assign(visited, oldstmt, rhs1, BEFORE_STMT);
120039 + }
120040 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
120041 + rhs2 = gimple_assign_rhs2(oldstmt);
120042 + rhs2 = create_assign(visited, oldstmt, rhs2, BEFORE_STMT);
120043 + }
120044 +
120045 + stmt = gimple_copy(oldstmt);
120046 + gimple_set_location(stmt, gimple_location(oldstmt));
120047 + pointer_set_insert(visited->my_stmts, stmt);
120048 +
120049 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
120050 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
120051 +
120052 + size_overflow_type = get_size_overflow_type(visited, oldstmt, node);
120053 +
120054 + new_var = create_new_var(size_overflow_type);
120055 + new_var = make_ssa_name(new_var, stmt);
120056 + gimple_assign_set_lhs(stmt, new_var);
120057 +
120058 + if (rhs1 != NULL_TREE)
120059 + gimple_assign_set_rhs1(stmt, rhs1);
120060 +
120061 + if (rhs2 != NULL_TREE)
120062 + gimple_assign_set_rhs2(stmt, rhs2);
120063 +#if BUILDING_GCC_VERSION >= 4006
120064 + if (rhs3 != NULL_TREE)
120065 + gimple_assign_set_rhs3(stmt, rhs3);
120066 +#endif
120067 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
120068 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
120069 +
120070 + gsi = gsi_for_stmt(oldstmt);
120071 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
120072 + update_stmt(stmt);
120073 + pointer_set_insert(visited->stmts, oldstmt);
120074 + return gimple_assign_lhs(stmt);
120075 +}
120076 +
120077 +static tree cast_parm_decl(struct visited *visited, tree phi_ssa_name, tree arg, tree size_overflow_type, basic_block bb)
120078 +{
120079 + gimple assign;
120080 + gimple_stmt_iterator gsi;
120081 + basic_block first_bb;
120082 +
120083 + gcc_assert(SSA_NAME_IS_DEFAULT_DEF(arg));
120084 +
120085 + if (bb->index == 0) {
120086 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
120087 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
120088 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
120089 + bb = first_bb;
120090 + }
120091 +
120092 + gsi = gsi_after_labels(bb);
120093 + assign = build_cast_stmt(visited, size_overflow_type, arg, phi_ssa_name, &gsi, BEFORE_STMT, false);
120094 + pointer_set_insert(visited->my_stmts, assign);
120095 +
120096 + return gimple_assign_lhs(assign);
120097 +}
120098 +
120099 +static tree use_phi_ssa_name(struct visited *visited, tree ssa_name_var, tree new_arg)
120100 +{
120101 + gimple_stmt_iterator gsi;
120102 + gimple assign, def_stmt = get_def_stmt(new_arg);
120103 +
120104 + if (gimple_code(def_stmt) == GIMPLE_PHI) {
120105 + gsi = gsi_after_labels(gimple_bb(def_stmt));
120106 + assign = build_cast_stmt(visited, TREE_TYPE(new_arg), new_arg, ssa_name_var, &gsi, BEFORE_STMT, true);
120107 + } else {
120108 + gsi = gsi_for_stmt(def_stmt);
120109 + assign = build_cast_stmt(visited, TREE_TYPE(new_arg), new_arg, ssa_name_var, &gsi, AFTER_STMT, true);
120110 + }
120111 +
120112 + pointer_set_insert(visited->my_stmts, assign);
120113 + return gimple_assign_lhs(assign);
120114 +}
120115 +
120116 +static tree cast_visited_phi_arg(struct visited *visited, tree ssa_name_var, tree arg, tree size_overflow_type)
120117 +{
120118 + basic_block bb;
120119 + gimple_stmt_iterator gsi;
120120 + const_gimple def_stmt;
120121 + gimple assign;
120122 +
120123 + def_stmt = get_def_stmt(arg);
120124 + bb = gimple_bb(def_stmt);
120125 + gcc_assert(bb->index != 0);
120126 + gsi = gsi_after_labels(bb);
120127 +
120128 + assign = build_cast_stmt(visited, size_overflow_type, arg, ssa_name_var, &gsi, BEFORE_STMT, false);
120129 + pointer_set_insert(visited->my_stmts, assign);
120130 + return gimple_assign_lhs(assign);
120131 +}
120132 +
120133 +static tree create_new_phi_arg(struct visited *visited, tree ssa_name_var, tree new_arg, gimple oldstmt, unsigned int i)
120134 +{
120135 + tree size_overflow_type;
120136 + tree arg;
120137 + const_gimple def_stmt;
120138 +
120139 + if (new_arg != NULL_TREE && is_gimple_constant(new_arg))
120140 + return new_arg;
120141 +
120142 + arg = gimple_phi_arg_def(oldstmt, i);
120143 + def_stmt = get_def_stmt(arg);
120144 + gcc_assert(def_stmt != NULL);
120145 + size_overflow_type = get_size_overflow_type(visited, oldstmt, arg);
120146 +
120147 + switch (gimple_code(def_stmt)) {
120148 + case GIMPLE_PHI:
120149 + return cast_visited_phi_arg(visited, ssa_name_var, arg, size_overflow_type);
120150 + case GIMPLE_NOP: {
120151 + basic_block bb;
120152 +
120153 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
120154 + return cast_parm_decl(visited, ssa_name_var, arg, size_overflow_type, bb);
120155 + }
120156 + case GIMPLE_ASM: {
120157 + gimple_stmt_iterator gsi;
120158 + gimple assign, stmt = get_def_stmt(arg);
120159 +
120160 + gsi = gsi_for_stmt(stmt);
120161 + assign = build_cast_stmt(visited, size_overflow_type, arg, ssa_name_var, &gsi, AFTER_STMT, false);
120162 + pointer_set_insert(visited->my_stmts, assign);
120163 + return gimple_assign_lhs(assign);
120164 + }
120165 + default:
120166 + gcc_assert(new_arg != NULL_TREE);
120167 + gcc_assert(types_compatible_p(TREE_TYPE(new_arg), size_overflow_type));
120168 + return use_phi_ssa_name(visited, ssa_name_var, new_arg);
120169 + }
120170 +}
120171 +
120172 +static gimple overflow_create_phi_node(struct visited *visited, gimple oldstmt, tree result)
120173 +{
120174 + basic_block bb;
120175 + gimple phi;
120176 + gimple_seq seq;
120177 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
120178 +
120179 + bb = gsi_bb(gsi);
120180 +
120181 + if (result == NULL_TREE) {
120182 + tree old_result = gimple_phi_result(oldstmt);
120183 + tree size_overflow_type = get_size_overflow_type(visited, oldstmt, old_result);
120184 +
120185 + result = create_new_var(size_overflow_type);
120186 + }
120187 +
120188 + phi = create_phi_node(result, bb);
120189 + gimple_phi_set_result(phi, make_ssa_name(result, phi));
120190 + seq = phi_nodes(bb);
120191 + gsi = gsi_last(seq);
120192 + gsi_remove(&gsi, false);
120193 +
120194 + gsi = gsi_for_stmt(oldstmt);
120195 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
120196 + gimple_set_bb(phi, bb);
120197 + return phi;
120198 +}
120199 +
120200 +#if BUILDING_GCC_VERSION <= 4007
120201 +static tree create_new_phi_node(struct visited *visited, VEC(tree, heap) **args, tree ssa_name_var, gimple oldstmt)
120202 +#else
120203 +static tree create_new_phi_node(struct visited *visited, vec<tree, va_heap, vl_embed> *&args, tree ssa_name_var, gimple oldstmt)
120204 +#endif
120205 +{
120206 + gimple new_phi;
120207 + unsigned int i;
120208 + tree arg, result;
120209 + location_t loc = gimple_location(oldstmt);
120210 +
120211 +#if BUILDING_GCC_VERSION <= 4007
120212 + gcc_assert(!VEC_empty(tree, *args));
120213 +#else
120214 + gcc_assert(!args->is_empty());
120215 +#endif
120216 +
120217 + new_phi = overflow_create_phi_node(visited, oldstmt, ssa_name_var);
120218 + result = gimple_phi_result(new_phi);
120219 + ssa_name_var = SSA_NAME_VAR(result);
120220 +
120221 +#if BUILDING_GCC_VERSION <= 4007
120222 + FOR_EACH_VEC_ELT(tree, *args, i, arg) {
120223 +#else
120224 + FOR_EACH_VEC_SAFE_ELT(args, i, arg) {
120225 +#endif
120226 + arg = create_new_phi_arg(visited, ssa_name_var, arg, oldstmt, i);
120227 + add_phi_arg(new_phi, arg, gimple_phi_arg_edge(oldstmt, i), loc);
120228 + }
120229 +
120230 +#if BUILDING_GCC_VERSION <= 4007
120231 + VEC_free(tree, heap, *args);
120232 +#else
120233 + vec_free(args);
120234 +#endif
120235 + update_stmt(new_phi);
120236 + pointer_set_insert(visited->my_stmts, new_phi);
120237 + return result;
120238 +}
120239 +
120240 +static tree handle_phi(struct visited *visited, struct cgraph_node *caller_node, tree orig_result)
120241 +{
120242 + tree ssa_name_var = NULL_TREE;
120243 +#if BUILDING_GCC_VERSION <= 4007
120244 + VEC(tree, heap) *args = NULL;
120245 +#else
120246 + vec<tree, va_heap, vl_embed> *args = NULL;
120247 +#endif
120248 + gimple oldstmt = get_def_stmt(orig_result);
120249 + unsigned int i, len = gimple_phi_num_args(oldstmt);
120250 +
120251 + pointer_set_insert(visited->stmts, oldstmt);
120252 + for (i = 0; i < len; i++) {
120253 + tree arg, new_arg;
120254 +
120255 + arg = gimple_phi_arg_def(oldstmt, i);
120256 + new_arg = expand(visited, caller_node, arg);
120257 +
120258 + if (ssa_name_var == NULL_TREE && new_arg != NULL_TREE)
120259 + ssa_name_var = SSA_NAME_VAR(new_arg);
120260 +
120261 + if (is_gimple_constant(arg)) {
120262 + tree size_overflow_type = get_size_overflow_type(visited, oldstmt, arg);
120263 +
120264 + new_arg = cast_a_tree(size_overflow_type, arg);
120265 + }
120266 +
120267 +#if BUILDING_GCC_VERSION <= 4007
120268 + VEC_safe_push(tree, heap, args, new_arg);
120269 +#else
120270 + vec_safe_push(args, new_arg);
120271 +#endif
120272 + }
120273 +
120274 +#if BUILDING_GCC_VERSION <= 4007
120275 + return create_new_phi_node(visited, &args, ssa_name_var, oldstmt);
120276 +#else
120277 + return create_new_phi_node(visited, args, ssa_name_var, oldstmt);
120278 +#endif
120279 +}
120280 +
120281 +static tree create_cast_assign(struct visited *visited, gimple stmt)
120282 +{
120283 + tree rhs1 = gimple_assign_rhs1(stmt);
120284 + tree lhs = gimple_assign_lhs(stmt);
120285 + const_tree rhs1_type = TREE_TYPE(rhs1);
120286 + const_tree lhs_type = TREE_TYPE(lhs);
120287 +
120288 + if (TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
120289 + return create_assign(visited, stmt, lhs, AFTER_STMT);
120290 +
120291 + return create_assign(visited, stmt, rhs1, AFTER_STMT);
120292 +}
120293 +
120294 +static bool skip_lhs_cast_check(const_gimple stmt)
120295 +{
120296 + const_tree rhs = gimple_assign_rhs1(stmt);
120297 + const_gimple def_stmt = get_def_stmt(rhs);
120298 +
120299 + // 3.8.2 kernel/futex_compat.c compat_exit_robust_list(): get_user() 64 ulong -> int (compat_long_t), int max
120300 + if (gimple_code(def_stmt) == GIMPLE_ASM)
120301 + return true;
120302 +
120303 + if (is_const_plus_unsigned_signed_truncation(rhs))
120304 + return true;
120305 +
120306 + return false;
120307 +}
120308 +
120309 +static tree create_string_param(tree string)
120310 +{
120311 + tree i_type, a_type;
120312 + const int length = TREE_STRING_LENGTH(string);
120313 +
120314 + gcc_assert(length > 0);
120315 +
120316 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
120317 + a_type = build_array_type(char_type_node, i_type);
120318 +
120319 + TREE_TYPE(string) = a_type;
120320 + TREE_CONSTANT(string) = 1;
120321 + TREE_READONLY(string) = 1;
120322 +
120323 + return build1(ADDR_EXPR, ptr_type_node, string);
120324 +}
120325 +
120326 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
120327 +{
120328 + gimple cond_stmt;
120329 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
120330 +
120331 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
120332 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
120333 + update_stmt(cond_stmt);
120334 +}
120335 +
120336 +static void insert_cond_result(struct cgraph_node *caller_node, basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
120337 +{
120338 + gimple func_stmt;
120339 + const_gimple def_stmt;
120340 + const_tree loc_line;
120341 + tree loc_file, ssa_name, current_func;
120342 + expanded_location xloc;
120343 + char *ssa_name_buf;
120344 + int len;
120345 + struct cgraph_edge *edge;
120346 + struct cgraph_node *callee_node;
120347 + int frequency;
120348 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
120349 +
120350 + def_stmt = get_def_stmt(arg);
120351 + xloc = expand_location(gimple_location(def_stmt));
120352 +
120353 + if (!gimple_has_location(def_stmt)) {
120354 + xloc = expand_location(gimple_location(stmt));
120355 + if (!gimple_has_location(stmt))
120356 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
120357 + }
120358 +
120359 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
120360 +
120361 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
120362 + loc_file = create_string_param(loc_file);
120363 +
120364 + current_func = build_string(DECL_NAME_LENGTH(current_function_decl) + 1, DECL_NAME_POINTER(current_function_decl));
120365 + current_func = create_string_param(current_func);
120366 +
120367 + gcc_assert(DECL_NAME(SSA_NAME_VAR(arg)) != NULL);
120368 + call_count++;
120369 + 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);
120370 + gcc_assert(len > 0);
120371 + ssa_name = build_string(len + 1, ssa_name_buf);
120372 + free(ssa_name_buf);
120373 + ssa_name = create_string_param(ssa_name);
120374 +
120375 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
120376 + func_stmt = gimple_build_call(report_size_overflow_decl, 4, loc_file, loc_line, current_func, ssa_name);
120377 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
120378 +
120379 + callee_node = cgraph_get_create_node(report_size_overflow_decl);
120380 + frequency = compute_call_stmt_bb_frequency(current_function_decl, bb_true);
120381 +
120382 + edge = cgraph_create_edge(caller_node, callee_node, func_stmt, bb_true->count, frequency, bb_true->loop_depth);
120383 + gcc_assert(edge != NULL);
120384 +}
120385 +
120386 +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)
120387 +{
120388 + basic_block cond_bb, join_bb, bb_true;
120389 + edge e;
120390 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
120391 +
120392 + cond_bb = gimple_bb(stmt);
120393 + if (before)
120394 + gsi_prev(&gsi);
120395 + if (gsi_end_p(gsi))
120396 + e = split_block_after_labels(cond_bb);
120397 + else
120398 + e = split_block(cond_bb, gsi_stmt(gsi));
120399 + cond_bb = e->src;
120400 + join_bb = e->dest;
120401 + e->flags = EDGE_FALSE_VALUE;
120402 + e->probability = REG_BR_PROB_BASE;
120403 +
120404 + bb_true = create_empty_bb(cond_bb);
120405 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
120406 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
120407 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
120408 +
120409 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
120410 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
120411 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
120412 +
120413 + if (current_loops != NULL) {
120414 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
120415 + add_bb_to_loop(bb_true, cond_bb->loop_father);
120416 + }
120417 +
120418 + insert_cond(cond_bb, arg, cond_code, type_value);
120419 + insert_cond_result(caller_node, bb_true, stmt, arg, min);
120420 +
120421 +// print_the_code_insertions(stmt);
120422 +}
120423 +
120424 +void check_size_overflow(struct cgraph_node *caller_node, gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before)
120425 +{
120426 + const_tree rhs_type = TREE_TYPE(rhs);
120427 + tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
120428 +
120429 + gcc_assert(rhs_type != NULL_TREE);
120430 + if (TREE_CODE(rhs_type) == POINTER_TYPE)
120431 + return;
120432 +
120433 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
120434 +
120435 + if (is_const_plus_unsigned_signed_truncation(rhs))
120436 + return;
120437 +
120438 + type_max = cast_a_tree(size_overflow_type, TYPE_MAX_VALUE(rhs_type));
120439 + // typemax (-1) < typemin (0)
120440 + if (TREE_OVERFLOW(type_max))
120441 + return;
120442 +
120443 + type_min = cast_a_tree(size_overflow_type, TYPE_MIN_VALUE(rhs_type));
120444 +
120445 + cast_rhs_type = TREE_TYPE(cast_rhs);
120446 + type_max_type = TREE_TYPE(type_max);
120447 + gcc_assert(types_compatible_p(cast_rhs_type, type_max_type));
120448 +
120449 + insert_check_size_overflow(caller_node, stmt, GT_EXPR, cast_rhs, type_max, before, MAX_CHECK);
120450 +
120451 + // special case: get_size_overflow_type(), 32, u64->s
120452 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode) && TYPE_UNSIGNED(size_overflow_type) && !TYPE_UNSIGNED(rhs_type))
120453 + return;
120454 +
120455 + type_min_type = TREE_TYPE(type_min);
120456 + gcc_assert(types_compatible_p(type_max_type, type_min_type));
120457 + insert_check_size_overflow(caller_node, stmt, LT_EXPR, cast_rhs, type_min, before, MIN_CHECK);
120458 +}
120459 +
120460 +static tree create_cast_overflow_check(struct visited *visited, struct cgraph_node *caller_node, tree new_rhs1, gimple stmt)
120461 +{
120462 + bool cast_lhs, cast_rhs;
120463 + tree lhs = gimple_assign_lhs(stmt);
120464 + tree rhs = gimple_assign_rhs1(stmt);
120465 + const_tree lhs_type = TREE_TYPE(lhs);
120466 + const_tree rhs_type = TREE_TYPE(rhs);
120467 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
120468 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
120469 + unsigned int lhs_size = GET_MODE_BITSIZE(lhs_mode);
120470 + unsigned int rhs_size = GET_MODE_BITSIZE(rhs_mode);
120471 +
120472 + static bool check_lhs[3][4] = {
120473 + // ss su us uu
120474 + { false, true, true, false }, // lhs > rhs
120475 + { false, false, false, false }, // lhs = rhs
120476 + { true, true, true, true }, // lhs < rhs
120477 + };
120478 +
120479 + static bool check_rhs[3][4] = {
120480 + // ss su us uu
120481 + { true, false, true, true }, // lhs > rhs
120482 + { true, false, true, true }, // lhs = rhs
120483 + { true, false, true, true }, // lhs < rhs
120484 + };
120485 +
120486 + // skip lhs check on signed SI -> HI cast or signed SI -> QI cast !!!!
120487 + if (rhs_mode == SImode && !TYPE_UNSIGNED(rhs_type) && (lhs_mode == HImode || lhs_mode == QImode))
120488 + return create_assign(visited, stmt, lhs, AFTER_STMT);
120489 +
120490 + if (lhs_size > rhs_size) {
120491 + cast_lhs = check_lhs[0][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
120492 + cast_rhs = check_rhs[0][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
120493 + } else if (lhs_size == rhs_size) {
120494 + cast_lhs = check_lhs[1][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
120495 + cast_rhs = check_rhs[1][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
120496 + } else {
120497 + cast_lhs = check_lhs[2][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
120498 + cast_rhs = check_rhs[2][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
120499 + }
120500 +
120501 + if (!cast_lhs && !cast_rhs)
120502 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
120503 +
120504 + if (cast_lhs && !skip_lhs_cast_check(stmt))
120505 + check_size_overflow(caller_node, stmt, TREE_TYPE(new_rhs1), new_rhs1, lhs, BEFORE_STMT);
120506 +
120507 + if (cast_rhs)
120508 + check_size_overflow(caller_node, stmt, TREE_TYPE(new_rhs1), new_rhs1, rhs, BEFORE_STMT);
120509 +
120510 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
120511 +}
120512 +
120513 +static tree handle_unary_rhs(struct visited *visited, struct cgraph_node *caller_node, gimple stmt)
120514 +{
120515 + enum tree_code rhs_code;
120516 + tree rhs1, new_rhs1, lhs = gimple_assign_lhs(stmt);
120517 +
120518 + if (pointer_set_contains(visited->my_stmts, stmt))
120519 + return lhs;
120520 +
120521 + rhs1 = gimple_assign_rhs1(stmt);
120522 + if (TREE_CODE(TREE_TYPE(rhs1)) == POINTER_TYPE)
120523 + return create_assign(visited, stmt, lhs, AFTER_STMT);
120524 +
120525 + new_rhs1 = expand(visited, caller_node, rhs1);
120526 +
120527 + if (new_rhs1 == NULL_TREE)
120528 + return create_cast_assign(visited, stmt);
120529 +
120530 + if (pointer_set_contains(visited->no_cast_check, stmt))
120531 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
120532 +
120533 + rhs_code = gimple_assign_rhs_code(stmt);
120534 + if (rhs_code == BIT_NOT_EXPR || rhs_code == NEGATE_EXPR) {
120535 + tree size_overflow_type = get_size_overflow_type(visited, stmt, rhs1);
120536 +
120537 + new_rhs1 = cast_to_new_size_overflow_type(visited, stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
120538 + check_size_overflow(caller_node, stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
120539 + return create_assign(visited, stmt, lhs, AFTER_STMT);
120540 + }
120541 +
120542 + if (!gimple_assign_cast_p(stmt))
120543 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
120544 +
120545 + return create_cast_overflow_check(visited, caller_node, new_rhs1, stmt);
120546 +}
120547 +
120548 +static tree handle_unary_ops(struct visited *visited, struct cgraph_node *caller_node, gimple stmt)
120549 +{
120550 + tree rhs1, lhs = gimple_assign_lhs(stmt);
120551 + gimple def_stmt = get_def_stmt(lhs);
120552 +
120553 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP);
120554 + rhs1 = gimple_assign_rhs1(def_stmt);
120555 +
120556 + if (is_gimple_constant(rhs1))
120557 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
120558 +
120559 + switch (TREE_CODE(rhs1)) {
120560 + case SSA_NAME: {
120561 + tree ret = handle_unary_rhs(visited, caller_node, def_stmt);
120562 +
120563 + if (gimple_assign_cast_p(stmt))
120564 + unsigned_signed_cast_intentional_overflow(visited, stmt);
120565 + return ret;
120566 + }
120567 + case ARRAY_REF:
120568 + case BIT_FIELD_REF:
120569 + case ADDR_EXPR:
120570 + case COMPONENT_REF:
120571 + case INDIRECT_REF:
120572 +#if BUILDING_GCC_VERSION >= 4006
120573 + case MEM_REF:
120574 +#endif
120575 + case TARGET_MEM_REF:
120576 + case VIEW_CONVERT_EXPR:
120577 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
120578 + case PARM_DECL:
120579 + case VAR_DECL:
120580 + return create_assign(visited, stmt, lhs, AFTER_STMT);
120581 +
120582 + default:
120583 + debug_gimple_stmt(def_stmt);
120584 + debug_tree(rhs1);
120585 + gcc_unreachable();
120586 + }
120587 +}
120588 +
120589 +static void __unused print_the_code_insertions(const_gimple stmt)
120590 +{
120591 + location_t loc = gimple_location(stmt);
120592 +
120593 + inform(loc, "Integer size_overflow check applied here.");
120594 +}
120595 +
120596 +static bool is_from_cast(const_tree node)
120597 +{
120598 + gimple def_stmt = get_def_stmt(node);
120599 +
120600 + if (!def_stmt)
120601 + return false;
120602 +
120603 + if (gimple_assign_cast_p(def_stmt))
120604 + return true;
120605 +
120606 + return false;
120607 +}
120608 +
120609 +// Skip duplication when there is a minus expr and the type of rhs1 or rhs2 is a pointer_type.
120610 +static bool is_a_ptr_minus(gimple stmt)
120611 +{
120612 + const_tree rhs1, rhs2, ptr1_rhs, ptr2_rhs;
120613 +
120614 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
120615 + return false;
120616 +
120617 + rhs1 = gimple_assign_rhs1(stmt);
120618 + if (!is_from_cast(rhs1))
120619 + return false;
120620 +
120621 + rhs2 = gimple_assign_rhs2(stmt);
120622 + if (!is_from_cast(rhs2))
120623 + return false;
120624 +
120625 + ptr1_rhs = gimple_assign_rhs1(get_def_stmt(rhs1));
120626 + ptr2_rhs = gimple_assign_rhs1(get_def_stmt(rhs2));
120627 +
120628 + if (TREE_CODE(TREE_TYPE(ptr1_rhs)) != POINTER_TYPE && TREE_CODE(TREE_TYPE(ptr2_rhs)) != POINTER_TYPE)
120629 + return false;
120630 +
120631 + return true;
120632 +}
120633 +
120634 +static tree handle_binary_ops(struct visited *visited, struct cgraph_node *caller_node, tree lhs)
120635 +{
120636 + enum intentional_overflow_type res;
120637 + tree rhs1, rhs2, new_lhs;
120638 + gimple def_stmt = get_def_stmt(lhs);
120639 + tree new_rhs1 = NULL_TREE;
120640 + tree new_rhs2 = NULL_TREE;
120641 +
120642 + if (is_a_ptr_minus(def_stmt))
120643 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
120644 +
120645 + rhs1 = gimple_assign_rhs1(def_stmt);
120646 + rhs2 = gimple_assign_rhs2(def_stmt);
120647 +
120648 + /* no DImode/TImode division in the 32/64 bit kernel */
120649 + switch (gimple_assign_rhs_code(def_stmt)) {
120650 + case RDIV_EXPR:
120651 + case TRUNC_DIV_EXPR:
120652 + case CEIL_DIV_EXPR:
120653 + case FLOOR_DIV_EXPR:
120654 + case ROUND_DIV_EXPR:
120655 + case TRUNC_MOD_EXPR:
120656 + case CEIL_MOD_EXPR:
120657 + case FLOOR_MOD_EXPR:
120658 + case ROUND_MOD_EXPR:
120659 + case EXACT_DIV_EXPR:
120660 + case POINTER_PLUS_EXPR:
120661 + case BIT_AND_EXPR:
120662 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
120663 + default:
120664 + break;
120665 + }
120666 +
120667 + new_lhs = handle_integer_truncation(visited, caller_node, lhs);
120668 + if (new_lhs != NULL_TREE)
120669 + return new_lhs;
120670 +
120671 + if (TREE_CODE(rhs1) == SSA_NAME)
120672 + new_rhs1 = expand(visited, caller_node, rhs1);
120673 + if (TREE_CODE(rhs2) == SSA_NAME)
120674 + new_rhs2 = expand(visited, caller_node, rhs2);
120675 +
120676 + res = add_mul_intentional_overflow(def_stmt);
120677 + if (res != NO_INTENTIONAL_OVERFLOW) {
120678 + new_lhs = dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
120679 + insert_cast_expr(visited, get_def_stmt(new_lhs), res);
120680 + return new_lhs;
120681 + }
120682 +
120683 + if (skip_expr_on_double_type(def_stmt)) {
120684 + new_lhs = dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
120685 + insert_cast_expr(visited, get_def_stmt(new_lhs), NO_INTENTIONAL_OVERFLOW);
120686 + return new_lhs;
120687 + }
120688 +
120689 + if (is_a_neg_overflow(def_stmt, rhs2))
120690 + return handle_intentional_overflow(visited, caller_node, true, def_stmt, new_rhs1, NULL_TREE);
120691 + if (is_a_neg_overflow(def_stmt, rhs1))
120692 + return handle_intentional_overflow(visited, caller_node, true, def_stmt, new_rhs2, new_rhs2);
120693 +
120694 +
120695 + if (is_a_constant_overflow(def_stmt, rhs2))
120696 + return handle_intentional_overflow(visited, caller_node, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, NULL_TREE);
120697 + if (is_a_constant_overflow(def_stmt, rhs1))
120698 + return handle_intentional_overflow(visited, caller_node, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, new_rhs2);
120699 +
120700 + // the const is between 0 and (signed) MAX
120701 + if (is_gimple_constant(rhs1))
120702 + new_rhs1 = create_assign(visited, def_stmt, rhs1, BEFORE_STMT);
120703 + if (is_gimple_constant(rhs2))
120704 + new_rhs2 = create_assign(visited, def_stmt, rhs2, BEFORE_STMT);
120705 +
120706 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
120707 +}
120708 +
120709 +#if BUILDING_GCC_VERSION >= 4006
120710 +static tree get_new_rhs(struct visited *visited, struct cgraph_node *caller_node, tree size_overflow_type, tree rhs)
120711 +{
120712 + if (is_gimple_constant(rhs))
120713 + return cast_a_tree(size_overflow_type, rhs);
120714 + if (TREE_CODE(rhs) != SSA_NAME)
120715 + return NULL_TREE;
120716 + return expand(visited, caller_node, rhs);
120717 +}
120718 +
120719 +static tree handle_ternary_ops(struct visited *visited, struct cgraph_node *caller_node, tree lhs)
120720 +{
120721 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
120722 + gimple def_stmt = get_def_stmt(lhs);
120723 +
120724 + size_overflow_type = get_size_overflow_type(visited, def_stmt, lhs);
120725 +
120726 + rhs1 = gimple_assign_rhs1(def_stmt);
120727 + rhs2 = gimple_assign_rhs2(def_stmt);
120728 + rhs3 = gimple_assign_rhs3(def_stmt);
120729 + new_rhs1 = get_new_rhs(visited, caller_node, size_overflow_type, rhs1);
120730 + new_rhs2 = get_new_rhs(visited, caller_node, size_overflow_type, rhs2);
120731 + new_rhs3 = get_new_rhs(visited, caller_node, size_overflow_type, rhs3);
120732 +
120733 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
120734 +}
120735 +#endif
120736 +
120737 +static tree get_my_stmt_lhs(struct visited *visited, gimple stmt)
120738 +{
120739 + gimple_stmt_iterator gsi;
120740 + gimple next_stmt = NULL;
120741 +
120742 + gsi = gsi_for_stmt(stmt);
120743 +
120744 + do {
120745 + gsi_next(&gsi);
120746 + next_stmt = gsi_stmt(gsi);
120747 +
120748 + if (gimple_code(stmt) == GIMPLE_PHI && !pointer_set_contains(visited->my_stmts, next_stmt))
120749 + return NULL_TREE;
120750 +
120751 + if (pointer_set_contains(visited->my_stmts, next_stmt) && !pointer_set_contains(visited->skip_expr_casts, next_stmt))
120752 + break;
120753 +
120754 + gcc_assert(pointer_set_contains(visited->my_stmts, next_stmt));
120755 + } while (!gsi_end_p(gsi));
120756 +
120757 + gcc_assert(next_stmt);
120758 + return get_lhs(next_stmt);
120759 +}
120760 +
120761 +static tree expand_visited(struct visited *visited, gimple def_stmt)
120762 +{
120763 + gimple_stmt_iterator gsi;
120764 + enum gimple_code code = gimple_code(def_stmt);
120765 +
120766 + if (code == GIMPLE_ASM)
120767 + return NULL_TREE;
120768 +
120769 + gsi = gsi_for_stmt(def_stmt);
120770 + gsi_next(&gsi);
120771 +
120772 + if (gimple_code(def_stmt) == GIMPLE_PHI && gsi_end_p(gsi))
120773 + return NULL_TREE;
120774 + return get_my_stmt_lhs(visited, def_stmt);
120775 +}
120776 +
120777 +tree expand(struct visited *visited, struct cgraph_node *caller_node, tree lhs)
120778 +{
120779 + gimple def_stmt;
120780 +
120781 + def_stmt = get_def_stmt(lhs);
120782 +
120783 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
120784 + return NULL_TREE;
120785 +
120786 + if (pointer_set_contains(visited->my_stmts, def_stmt))
120787 + return lhs;
120788 +
120789 + if (pointer_set_contains(visited->stmts, def_stmt))
120790 + return expand_visited(visited, def_stmt);
120791 +
120792 + switch (gimple_code(def_stmt)) {
120793 + case GIMPLE_PHI:
120794 + return handle_phi(visited, caller_node, lhs);
120795 + case GIMPLE_CALL:
120796 + case GIMPLE_ASM:
120797 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
120798 + case GIMPLE_ASSIGN:
120799 + switch (gimple_num_ops(def_stmt)) {
120800 + case 2:
120801 + return handle_unary_ops(visited, caller_node, def_stmt);
120802 + case 3:
120803 + return handle_binary_ops(visited, caller_node, lhs);
120804 +#if BUILDING_GCC_VERSION >= 4006
120805 + case 4:
120806 + return handle_ternary_ops(visited, caller_node, lhs);
120807 +#endif
120808 + }
120809 + default:
120810 + debug_gimple_stmt(def_stmt);
120811 + error("%s: unknown gimple code", __func__);
120812 + gcc_unreachable();
120813 + }
120814 +}
120815 +
120816 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
120817 new file mode 100644
120818 index 0000000..df50164
120819 --- /dev/null
120820 +++ b/tools/gcc/size_overflow_plugin/insert_size_overflow_check_ipa.c
120821 @@ -0,0 +1,1141 @@
120822 +/*
120823 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
120824 + * Licensed under the GPL v2, or (at your option) v3
120825 + *
120826 + * Homepage:
120827 + * http://www.grsecurity.net/~ephox/overflow_plugin/
120828 + *
120829 + * Documentation:
120830 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
120831 + *
120832 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
120833 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
120834 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
120835 + *
120836 + * Usage:
120837 + * $ make
120838 + * $ make run
120839 + */
120840 +
120841 +#include "gcc-common.h"
120842 +#include "size_overflow.h"
120843 +
120844 +#define VEC_LEN 128
120845 +#define RET_CHECK NULL_TREE
120846 +#define WRONG_NODE 32
120847 +#define NOT_INTENTIONAL_ASM NULL
120848 +
120849 +unsigned int call_count;
120850 +
120851 +static void set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree lhs);
120852 +static void walk_use_def(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs);
120853 +
120854 +struct visited_fns {
120855 + struct visited_fns *next;
120856 + const_tree fndecl;
120857 + unsigned int num;
120858 + const_gimple first_stmt;
120859 +};
120860 +
120861 +struct next_cgraph_node {
120862 + struct next_cgraph_node *next;
120863 + struct cgraph_node *current_function;
120864 + tree callee_fndecl;
120865 + unsigned int num;
120866 +};
120867 +
120868 +// Don't want to duplicate entries in next_cgraph_node
120869 +static bool is_in_next_cgraph_node(struct next_cgraph_node *head, struct cgraph_node *node, const_tree fndecl, unsigned int num)
120870 +{
120871 + const_tree new_callee_fndecl;
120872 + struct next_cgraph_node *cur_node;
120873 +
120874 + if (fndecl == RET_CHECK)
120875 + new_callee_fndecl = NODE_DECL(node);
120876 + else
120877 + new_callee_fndecl = fndecl;
120878 +
120879 + for (cur_node = head; cur_node; cur_node = cur_node->next) {
120880 + if (!operand_equal_p(NODE_DECL(cur_node->current_function), NODE_DECL(node), 0))
120881 + continue;
120882 + if (!operand_equal_p(cur_node->callee_fndecl, new_callee_fndecl, 0))
120883 + continue;
120884 + if (num == cur_node->num)
120885 + return true;
120886 + }
120887 + return false;
120888 +}
120889 +
120890 +/* Add a next_cgraph_node into the list for handle_function().
120891 + * handle_function() iterates over all the next cgraph nodes and
120892 + * starts the overflow check insertion process.
120893 + */
120894 +static struct next_cgraph_node *create_new_next_cgraph_node(struct next_cgraph_node *head, struct cgraph_node *node, tree fndecl, unsigned int num)
120895 +{
120896 + struct next_cgraph_node *new_node;
120897 +
120898 + if (is_in_next_cgraph_node(head, node, fndecl, num))
120899 + return head;
120900 +
120901 + new_node = (struct next_cgraph_node *)xmalloc(sizeof(*new_node));
120902 + new_node->current_function = node;
120903 + new_node->next = NULL;
120904 + new_node->num = num;
120905 + if (fndecl == RET_CHECK)
120906 + new_node->callee_fndecl = NODE_DECL(node);
120907 + else
120908 + new_node->callee_fndecl = fndecl;
120909 +
120910 + if (!head)
120911 + return new_node;
120912 +
120913 + new_node->next = head;
120914 + return new_node;
120915 +}
120916 +
120917 +static struct next_cgraph_node *create_new_next_cgraph_nodes(struct next_cgraph_node *head, struct cgraph_node *node, unsigned int num)
120918 +{
120919 + struct cgraph_edge *e;
120920 +
120921 + if (num == 0)
120922 + return create_new_next_cgraph_node(head, node, RET_CHECK, num);
120923 +
120924 + for (e = node->callers; e; e = e->next_caller) {
120925 + tree fndecl = gimple_call_fndecl(e->call_stmt);
120926 +
120927 + gcc_assert(fndecl != NULL_TREE);
120928 + head = create_new_next_cgraph_node(head, e->caller, fndecl, num);
120929 + }
120930 +
120931 + return head;
120932 +}
120933 +
120934 +struct missing_functions {
120935 + struct missing_functions *next;
120936 + const_tree node;
120937 + tree fndecl;
120938 +};
120939 +
120940 +static struct missing_functions *create_new_missing_function(struct missing_functions *missing_fn_head, tree node)
120941 +{
120942 + struct missing_functions *new_function;
120943 +
120944 + new_function = (struct missing_functions *)xmalloc(sizeof(*new_function));
120945 + new_function->node = node;
120946 + new_function->next = NULL;
120947 +
120948 + if (TREE_CODE(node) == FUNCTION_DECL)
120949 + new_function->fndecl = node;
120950 + else
120951 + new_function->fndecl = current_function_decl;
120952 + gcc_assert(new_function->fndecl);
120953 +
120954 + if (!missing_fn_head)
120955 + return new_function;
120956 +
120957 + new_function->next = missing_fn_head;
120958 + return new_function;
120959 +}
120960 +
120961 +/* If the function is missing from the hash table and it is a static function
120962 + * then create a next_cgraph_node from it for handle_function()
120963 + */
120964 +static struct next_cgraph_node *check_missing_overflow_attribute_and_create_next_node(struct next_cgraph_node *cnodes, struct missing_functions *missing_fn_head)
120965 +{
120966 + unsigned int num;
120967 + const_tree orig_fndecl;
120968 + struct cgraph_node *next_node = NULL;
120969 +
120970 + orig_fndecl = DECL_ORIGIN(missing_fn_head->fndecl);
120971 +
120972 + num = get_function_num(missing_fn_head->node, orig_fndecl);
120973 + if (num == CANNOT_FIND_ARG)
120974 + return cnodes;
120975 +
120976 + if (!is_missing_function(orig_fndecl, num))
120977 + return cnodes;
120978 +
120979 + next_node = cgraph_get_node(missing_fn_head->fndecl);
120980 + if (next_node && next_node->local.local)
120981 + cnodes = create_new_next_cgraph_nodes(cnodes, next_node, num);
120982 + return cnodes;
120983 +}
120984 +
120985 +/* Search for missing size_overflow attributes on the last nodes in ipa and collect them
120986 + * into the next_cgraph_node list. They will be the next interesting returns or callees.
120987 + */
120988 +static struct next_cgraph_node *search_overflow_attribute(struct next_cgraph_node *cnodes, struct interesting_node *cur_node)
120989 +{
120990 + unsigned int i;
120991 + tree node;
120992 + struct missing_functions *cur, *missing_fn_head = NULL;
120993 +
120994 +#if BUILDING_GCC_VERSION <= 4007
120995 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, node) {
120996 +#else
120997 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, node) {
120998 +#endif
120999 + switch (TREE_CODE(node)) {
121000 + case PARM_DECL:
121001 + if (TREE_CODE(TREE_TYPE(node)) != INTEGER_TYPE)
121002 + break;
121003 + case FUNCTION_DECL:
121004 + missing_fn_head = create_new_missing_function(missing_fn_head, node);
121005 + break;
121006 + default:
121007 + break;
121008 + }
121009 + }
121010 +
121011 + while (missing_fn_head) {
121012 + cnodes = check_missing_overflow_attribute_and_create_next_node(cnodes, missing_fn_head);
121013 +
121014 + cur = missing_fn_head->next;
121015 + free(missing_fn_head);
121016 + missing_fn_head = cur;
121017 + }
121018 +
121019 + return cnodes;
121020 +}
121021 +
121022 +static void walk_phi_set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree result)
121023 +{
121024 + gimple phi = get_def_stmt(result);
121025 + unsigned int i, n = gimple_phi_num_args(phi);
121026 +
121027 + pointer_set_insert(visited, phi);
121028 + for (i = 0; i < n; i++) {
121029 + const_tree arg = gimple_phi_arg_def(phi, i);
121030 +
121031 + set_conditions(visited, interesting_conditions, arg);
121032 + }
121033 +}
121034 +
121035 +enum conditions {
121036 + FROM_CONST, NOT_UNARY, CAST, RET, PHI
121037 +};
121038 +
121039 +// Search for constants, cast assignments and binary/ternary assignments
121040 +static void set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree lhs)
121041 +{
121042 + gimple def_stmt = get_def_stmt(lhs);
121043 +
121044 + if (is_gimple_constant(lhs)) {
121045 + interesting_conditions[FROM_CONST] = true;
121046 + return;
121047 + }
121048 +
121049 + if (!def_stmt)
121050 + return;
121051 +
121052 + if (pointer_set_contains(visited, def_stmt))
121053 + return;
121054 +
121055 + switch (gimple_code(def_stmt)) {
121056 + case GIMPLE_CALL:
121057 + if (lhs == gimple_call_lhs(def_stmt))
121058 + interesting_conditions[RET] = true;
121059 + return;
121060 + case GIMPLE_NOP:
121061 + case GIMPLE_ASM:
121062 + return;
121063 + case GIMPLE_PHI:
121064 + interesting_conditions[PHI] = true;
121065 + return walk_phi_set_conditions(visited, interesting_conditions, lhs);
121066 + case GIMPLE_ASSIGN:
121067 + if (gimple_num_ops(def_stmt) == 2) {
121068 + const_tree rhs = gimple_assign_rhs1(def_stmt);
121069 +
121070 + if (gimple_assign_cast_p(def_stmt))
121071 + interesting_conditions[CAST] = true;
121072 +
121073 + return set_conditions(visited, interesting_conditions, rhs);
121074 + } else {
121075 + interesting_conditions[NOT_UNARY] = true;
121076 + return;
121077 + }
121078 + default:
121079 + debug_gimple_stmt(def_stmt);
121080 + gcc_unreachable();
121081 + }
121082 +}
121083 +
121084 +// determine whether duplication will be necessary or not.
121085 +static void search_interesting_conditions(struct interesting_node *cur_node, bool *interesting_conditions)
121086 +{
121087 + struct pointer_set_t *visited;
121088 +
121089 + if (gimple_assign_cast_p(cur_node->first_stmt))
121090 + interesting_conditions[CAST] = true;
121091 + else if (is_gimple_assign(cur_node->first_stmt) && gimple_num_ops(cur_node->first_stmt) > 2)
121092 + interesting_conditions[NOT_UNARY] = true;
121093 +
121094 + visited = pointer_set_create();
121095 + set_conditions(visited, interesting_conditions, cur_node->node);
121096 + pointer_set_destroy(visited);
121097 +}
121098 +
121099 +// Remove the size_overflow asm stmt and create an assignment from the input and output of the asm
121100 +static void replace_size_overflow_asm_with_assign(gimple asm_stmt, tree lhs, tree rhs)
121101 +{
121102 + gimple assign;
121103 + gimple_stmt_iterator gsi;
121104 +
121105 + // already removed
121106 + if (gimple_bb(asm_stmt) == NULL)
121107 + return;
121108 + gsi = gsi_for_stmt(asm_stmt);
121109 +
121110 + assign = gimple_build_assign(lhs, rhs);
121111 + gsi_insert_before(&gsi, assign, GSI_SAME_STMT);
121112 + SSA_NAME_DEF_STMT(lhs) = assign;
121113 +
121114 + gsi_remove(&gsi, true);
121115 +}
121116 +
121117 +/* Get the fndecl of an interesting stmt, the fndecl is the caller function if the interesting
121118 + * stmt is a return otherwise it is the callee function.
121119 + */
121120 +const_tree get_interesting_orig_fndecl(const_gimple stmt, unsigned int argnum)
121121 +{
121122 + const_tree fndecl;
121123 +
121124 + if (argnum == 0)
121125 + fndecl = current_function_decl;
121126 + else
121127 + fndecl = gimple_call_fndecl(stmt);
121128 +
121129 + if (fndecl == NULL_TREE)
121130 + return NULL_TREE;
121131 +
121132 + return DECL_ORIGIN(fndecl);
121133 +}
121134 +
121135 +// e.g., 3.8.2, 64, arch/x86/ia32/ia32_signal.c copy_siginfo_from_user32(): compat_ptr() u32 max
121136 +static bool skip_asm(const_tree arg)
121137 +{
121138 + gimple def_stmt = get_def_stmt(arg);
121139 +
121140 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
121141 + return false;
121142 +
121143 + def_stmt = get_def_stmt(gimple_assign_rhs1(def_stmt));
121144 + return def_stmt && gimple_code(def_stmt) == GIMPLE_ASM;
121145 +}
121146 +
121147 +static void walk_use_def_phi(struct pointer_set_t *visited, struct interesting_node *cur_node, tree result)
121148 +{
121149 + gimple phi = get_def_stmt(result);
121150 + unsigned int i, n = gimple_phi_num_args(phi);
121151 +
121152 + pointer_set_insert(visited, phi);
121153 + for (i = 0; i < n; i++) {
121154 + tree arg = gimple_phi_arg_def(phi, i);
121155 +
121156 + walk_use_def(visited, cur_node, arg);
121157 + }
121158 +}
121159 +
121160 +static void walk_use_def_binary(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs)
121161 +{
121162 + gimple def_stmt = get_def_stmt(lhs);
121163 + tree rhs1, rhs2;
121164 +
121165 + rhs1 = gimple_assign_rhs1(def_stmt);
121166 + rhs2 = gimple_assign_rhs2(def_stmt);
121167 +
121168 + walk_use_def(visited, cur_node, rhs1);
121169 + walk_use_def(visited, cur_node, rhs2);
121170 +}
121171 +
121172 +static void insert_last_node(struct interesting_node *cur_node, tree node)
121173 +{
121174 + unsigned int i;
121175 + tree element;
121176 + enum tree_code code;
121177 +
121178 + gcc_assert(node != NULL_TREE);
121179 +
121180 + if (is_gimple_constant(node))
121181 + return;
121182 +
121183 + code = TREE_CODE(node);
121184 + if (code == VAR_DECL) {
121185 + node = DECL_ORIGIN(node);
121186 + code = TREE_CODE(node);
121187 + }
121188 +
121189 + if (code != PARM_DECL && code != FUNCTION_DECL && code != COMPONENT_REF)
121190 + return;
121191 +
121192 +#if BUILDING_GCC_VERSION <= 4007
121193 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, element) {
121194 +#else
121195 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, element) {
121196 +#endif
121197 + if (operand_equal_p(node, element, 0))
121198 + return;
121199 + }
121200 +
121201 +#if BUILDING_GCC_VERSION <= 4007
121202 + gcc_assert(VEC_length(tree, cur_node->last_nodes) < VEC_LEN);
121203 + VEC_safe_push(tree, gc, cur_node->last_nodes, node);
121204 +#else
121205 + gcc_assert(cur_node->last_nodes->length() < VEC_LEN);
121206 + vec_safe_push(cur_node->last_nodes, node);
121207 +#endif
121208 +}
121209 +
121210 +// a size_overflow asm stmt in the control flow doesn't stop the recursion
121211 +static void handle_asm_stmt(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs, const_gimple stmt)
121212 +{
121213 + if (!is_size_overflow_asm(stmt))
121214 + walk_use_def(visited, cur_node, SSA_NAME_VAR(lhs));
121215 +}
121216 +
121217 +/* collect the parm_decls and fndecls (for checking a missing size_overflow attribute (ret or arg) or intentional_overflow)
121218 + * and component refs (for checking the intentional_overflow attribute).
121219 + */
121220 +static void walk_use_def(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs)
121221 +{
121222 + const_gimple def_stmt;
121223 +
121224 + if (TREE_CODE(lhs) != SSA_NAME) {
121225 + insert_last_node(cur_node, lhs);
121226 + return;
121227 + }
121228 +
121229 + def_stmt = get_def_stmt(lhs);
121230 + if (!def_stmt)
121231 + return;
121232 +
121233 + if (pointer_set_insert(visited, def_stmt))
121234 + return;
121235 +
121236 + switch (gimple_code(def_stmt)) {
121237 + case GIMPLE_NOP:
121238 + return walk_use_def(visited, cur_node, SSA_NAME_VAR(lhs));
121239 + case GIMPLE_ASM:
121240 + return handle_asm_stmt(visited, cur_node, lhs, def_stmt);
121241 + case GIMPLE_CALL: {
121242 + tree fndecl = gimple_call_fndecl(def_stmt);
121243 +
121244 + if (fndecl == NULL_TREE)
121245 + return;
121246 + insert_last_node(cur_node, fndecl);
121247 + return;
121248 + }
121249 + case GIMPLE_PHI:
121250 + return walk_use_def_phi(visited, cur_node, lhs);
121251 + case GIMPLE_ASSIGN:
121252 + switch (gimple_num_ops(def_stmt)) {
121253 + case 2:
121254 + return walk_use_def(visited, cur_node, gimple_assign_rhs1(def_stmt));
121255 + case 3:
121256 + return walk_use_def_binary(visited, cur_node, lhs);
121257 + }
121258 + default:
121259 + debug_gimple_stmt((gimple)def_stmt);
121260 + error("%s: unknown gimple code", __func__);
121261 + gcc_unreachable();
121262 + }
121263 +}
121264 +
121265 +// Collect all the last nodes for checking the intentional_overflow and size_overflow attributes
121266 +static void set_last_nodes(struct interesting_node *cur_node)
121267 +{
121268 + struct pointer_set_t *visited;
121269 +
121270 + visited = pointer_set_create();
121271 + walk_use_def(visited, cur_node, cur_node->node);
121272 + pointer_set_destroy(visited);
121273 +}
121274 +
121275 +enum precond {
121276 + NO_ATTRIBUTE_SEARCH, NO_CHECK_INSERT, NONE
121277 +};
121278 +
121279 +/* 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.
121280 + * There is only missing size_overflow attribute checking if the intentional_overflow attribute is the mark_no type.
121281 + * Stmt duplication is unnecessary if there are no binary/ternary assignements or if the unary assignment isn't a cast.
121282 + * It skips the possible error codes too.
121283 + */
121284 +static enum precond check_preconditions(struct interesting_node *cur_node)
121285 +{
121286 + bool interesting_conditions[5] = {false, false, false, false, false};
121287 +
121288 + set_last_nodes(cur_node);
121289 +
121290 + check_intentional_attribute_ipa(cur_node);
121291 + if (cur_node->intentional_attr_decl == MARK_TURN_OFF || cur_node->intentional_attr_cur_fndecl == MARK_TURN_OFF)
121292 + return NO_ATTRIBUTE_SEARCH;
121293 +
121294 + search_interesting_conditions(cur_node, interesting_conditions);
121295 +
121296 + // error code: a phi, unary assign (not cast) and returns only
121297 + if (!interesting_conditions[NOT_UNARY] && interesting_conditions[PHI] && interesting_conditions[RET] && !interesting_conditions[CAST])
121298 + return NO_ATTRIBUTE_SEARCH;
121299 +
121300 + // error code: def_stmts trace back to a constant and there are no binary/ternary assigments
121301 + if (interesting_conditions[CAST] && interesting_conditions[FROM_CONST] && !interesting_conditions[NOT_UNARY])
121302 + return NO_ATTRIBUTE_SEARCH;
121303 +
121304 + // unnecessary overflow check
121305 + if (!interesting_conditions[CAST] && !interesting_conditions[NOT_UNARY])
121306 + return NO_CHECK_INSERT;
121307 +
121308 + if (cur_node->intentional_attr_cur_fndecl != MARK_NO)
121309 + return NO_CHECK_INSERT;
121310 +
121311 + return NONE;
121312 +}
121313 +
121314 +static tree cast_to_orig_type(struct visited *visited, gimple stmt, const_tree orig_node, tree new_node)
121315 +{
121316 + const_gimple assign;
121317 + tree orig_type = TREE_TYPE(orig_node);
121318 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
121319 +
121320 + assign = build_cast_stmt(visited, orig_type, new_node, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
121321 + return gimple_assign_lhs(assign);
121322 +}
121323 +
121324 +static void change_orig_node(struct visited *visited, struct interesting_node *cur_node, tree new_node)
121325 +{
121326 + void (*set_rhs)(gimple, tree);
121327 + gimple stmt = cur_node->first_stmt;
121328 + const_tree orig_node = cur_node->node;
121329 +
121330 + switch (gimple_code(stmt)) {
121331 + case GIMPLE_RETURN:
121332 + gimple_return_set_retval(stmt, cast_to_orig_type(visited, stmt, orig_node, new_node));
121333 + break;
121334 + case GIMPLE_CALL:
121335 + gimple_call_set_arg(stmt, cur_node->num - 1, cast_to_orig_type(visited, stmt, orig_node, new_node));
121336 + break;
121337 + case GIMPLE_ASSIGN:
121338 + switch (cur_node->num) {
121339 + case 1:
121340 + set_rhs = &gimple_assign_set_rhs1;
121341 + break;
121342 + case 2:
121343 + set_rhs = &gimple_assign_set_rhs2;
121344 + break;
121345 +#if BUILDING_GCC_VERSION >= 4006
121346 + case 3:
121347 + set_rhs = &gimple_assign_set_rhs3;
121348 + break;
121349 +#endif
121350 + default:
121351 + gcc_unreachable();
121352 + }
121353 +
121354 + set_rhs(stmt, cast_to_orig_type(visited, stmt, orig_node, new_node));
121355 + break;
121356 + default:
121357 + debug_gimple_stmt(stmt);
121358 + gcc_unreachable();
121359 + }
121360 +
121361 + update_stmt(stmt);
121362 +}
121363 +
121364 +static struct visited *create_visited(void)
121365 +{
121366 + struct visited *new_node;
121367 +
121368 + new_node = (struct visited *)xmalloc(sizeof(*new_node));
121369 + new_node->stmts = pointer_set_create();
121370 + new_node->my_stmts = pointer_set_create();
121371 + new_node->skip_expr_casts = pointer_set_create();
121372 + new_node->no_cast_check = pointer_set_create();
121373 + return new_node;
121374 +}
121375 +
121376 +static void free_visited(struct visited *visited)
121377 +{
121378 + pointer_set_destroy(visited->stmts);
121379 + pointer_set_destroy(visited->my_stmts);
121380 + pointer_set_destroy(visited->skip_expr_casts);
121381 + pointer_set_destroy(visited->no_cast_check);
121382 +
121383 + free(visited);
121384 +}
121385 +
121386 +/* This function calls the main recursion function (expand) that duplicates the stmts. Before that it checks the intentional_overflow attribute and asm stmts,
121387 + * 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
121388 + * in the original stmt (first stmt) and it inserts the overflow check for the arg of the callee or for the return value.
121389 + */
121390 +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)
121391 +{
121392 + enum precond ret;
121393 + tree new_node, orig_node = cur_node->node;
121394 +
121395 + ret = check_preconditions(cur_node);
121396 + if (ret == NO_ATTRIBUTE_SEARCH)
121397 + return cnodes;
121398 +
121399 + cnodes = search_overflow_attribute(cnodes, cur_node);
121400 +
121401 + if (ret == NO_CHECK_INSERT)
121402 + return cnodes;
121403 +
121404 + new_node = expand(visited, caller_node, orig_node);
121405 + if (new_node == NULL_TREE)
121406 + return cnodes;
121407 +
121408 + change_orig_node(visited, cur_node, new_node);
121409 + check_size_overflow(caller_node, cur_node->first_stmt, TREE_TYPE(new_node), new_node, orig_node, BEFORE_STMT);
121410 +
121411 + return cnodes;
121412 +}
121413 +
121414 +// Check visited_fns interesting nodes.
121415 +static bool is_in_interesting_node(struct interesting_node *head, const_gimple first_stmt, const_tree node, unsigned int num)
121416 +{
121417 + struct interesting_node *cur;
121418 +
121419 + for (cur = head; cur; cur = cur->next) {
121420 + if (!operand_equal_p(node, cur->node, 0))
121421 + continue;
121422 + if (num != cur->num)
121423 + continue;
121424 + if (first_stmt == cur->first_stmt)
121425 + return true;
121426 + }
121427 + return false;
121428 +}
121429 +
121430 +/* Create an interesting node. The ipa pass starts to duplicate from these stmts.
121431 + 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
121432 + 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
121433 + the intentional_overflow attribute check. They are collected by set_last_nodes().
121434 + num: arg count of a call stmt or 0 when it is a ret
121435 + node: the recursion starts from here, it is a call arg or a return value
121436 + 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.
121437 + intentional_attr_decl: intentional_overflow attribute of the callee function
121438 + intentional_attr_cur_fndecl: intentional_overflow attribute of the caller function
121439 + intentional_mark_from_gimple: the intentional overflow type of size_overflow asm stmt from gimple if it exists
121440 + */
121441 +static struct interesting_node *create_new_interesting_node(struct interesting_node *head, gimple first_stmt, tree node, unsigned int num, gimple asm_stmt)
121442 +{
121443 + struct interesting_node *new_node;
121444 + tree fndecl;
121445 + enum gimple_code code;
121446 +
121447 + gcc_assert(node != NULL_TREE);
121448 + code = gimple_code(first_stmt);
121449 + gcc_assert(code == GIMPLE_CALL || code == GIMPLE_ASM || code == GIMPLE_ASSIGN || code == GIMPLE_RETURN);
121450 +
121451 + if (num == CANNOT_FIND_ARG)
121452 + return head;
121453 +
121454 + if (skip_types(node))
121455 + return head;
121456 +
121457 + if (skip_asm(node))
121458 + return head;
121459 +
121460 + if (is_gimple_call(first_stmt))
121461 + fndecl = gimple_call_fndecl(first_stmt);
121462 + else
121463 + fndecl = current_function_decl;
121464 +
121465 + if (fndecl == NULL_TREE)
121466 + return head;
121467 +
121468 + if (is_in_interesting_node(head, first_stmt, node, num))
121469 + return head;
121470 +
121471 + new_node = (struct interesting_node *)xmalloc(sizeof(*new_node));
121472 +
121473 + new_node->next = NULL;
121474 + new_node->first_stmt = first_stmt;
121475 +#if BUILDING_GCC_VERSION <= 4007
121476 + new_node->last_nodes = VEC_alloc(tree, gc, VEC_LEN);
121477 +#else
121478 + vec_alloc(new_node->last_nodes, VEC_LEN);
121479 +#endif
121480 + new_node->num = num;
121481 + new_node->node = node;
121482 + new_node->fndecl = fndecl;
121483 + new_node->intentional_attr_decl = MARK_NO;
121484 + new_node->intentional_attr_cur_fndecl = MARK_NO;
121485 + new_node->intentional_mark_from_gimple = asm_stmt;
121486 +
121487 + if (!head)
121488 + return new_node;
121489 +
121490 + new_node->next = head;
121491 + return new_node;
121492 +}
121493 +
121494 +/* 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).
121495 + * If the ret stmt is in the next cgraph node list then it's an interesting ret.
121496 + */
121497 +static struct interesting_node *handle_stmt_by_cgraph_nodes_ret(struct interesting_node *head, gimple stmt, struct next_cgraph_node *next_node)
121498 +{
121499 + struct next_cgraph_node *cur_node;
121500 + tree ret = gimple_return_retval(stmt);
121501 +
121502 + if (ret == NULL_TREE)
121503 + return head;
121504 +
121505 + for (cur_node = next_node; cur_node; cur_node = cur_node->next) {
121506 + if (!operand_equal_p(cur_node->callee_fndecl, DECL_ORIGIN(current_function_decl), 0))
121507 + continue;
121508 + if (cur_node->num == 0)
121509 + head = create_new_interesting_node(head, stmt, ret, 0, NOT_INTENTIONAL_ASM);
121510 + }
121511 +
121512 + return head;
121513 +}
121514 +
121515 +/* 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).
121516 + * If the call stmt is in the next cgraph node list then it's an interesting call.
121517 + */
121518 +static struct interesting_node *handle_stmt_by_cgraph_nodes_call(struct interesting_node *head, gimple stmt, struct next_cgraph_node *next_node)
121519 +{
121520 + unsigned int argnum;
121521 + tree arg;
121522 + const_tree fndecl;
121523 + struct next_cgraph_node *cur_node;
121524 +
121525 + fndecl = gimple_call_fndecl(stmt);
121526 + if (fndecl == NULL_TREE)
121527 + return head;
121528 +
121529 + for (cur_node = next_node; cur_node; cur_node = cur_node->next) {
121530 + if (!operand_equal_p(cur_node->callee_fndecl, fndecl, 0))
121531 + continue;
121532 + argnum = get_correct_arg_count(cur_node->num, fndecl);
121533 + gcc_assert(argnum != CANNOT_FIND_ARG);
121534 + if (argnum == 0)
121535 + continue;
121536 +
121537 + arg = gimple_call_arg(stmt, argnum - 1);
121538 + head = create_new_interesting_node(head, stmt, arg, argnum, NOT_INTENTIONAL_ASM);
121539 + }
121540 +
121541 + return head;
121542 +}
121543 +
121544 +static unsigned int check_ops(const_tree orig_node, const_tree node, unsigned int ret_count)
121545 +{
121546 + if (!operand_equal_p(orig_node, node, 0))
121547 + return WRONG_NODE;
121548 + if (skip_types(node))
121549 + return WRONG_NODE;
121550 + return ret_count;
121551 +}
121552 +
121553 +// Get the index of the rhs node in an assignment
121554 +static unsigned int get_assign_ops_count(const_gimple stmt, tree node)
121555 +{
121556 + const_tree rhs1, rhs2;
121557 + unsigned int ret;
121558 +
121559 + gcc_assert(stmt);
121560 + gcc_assert(is_gimple_assign(stmt));
121561 +
121562 + rhs1 = gimple_assign_rhs1(stmt);
121563 + gcc_assert(rhs1 != NULL_TREE);
121564 +
121565 + switch (gimple_num_ops(stmt)) {
121566 + case 2:
121567 + return check_ops(node, rhs1, 1);
121568 + case 3:
121569 + ret = check_ops(node, rhs1, 1);
121570 + if (ret != WRONG_NODE)
121571 + return ret;
121572 +
121573 + rhs2 = gimple_assign_rhs2(stmt);
121574 + gcc_assert(rhs2 != NULL_TREE);
121575 + return check_ops(node, rhs2, 2);
121576 + default:
121577 + gcc_unreachable();
121578 + }
121579 +}
121580 +
121581 +// Find the correct arg number of a call stmt. It is needed when the interesting function is a cloned function.
121582 +static unsigned int find_arg_number_gimple(const_tree arg, const_gimple stmt)
121583 +{
121584 + unsigned int i;
121585 +
121586 + if (gimple_call_fndecl(stmt) == NULL_TREE)
121587 + return CANNOT_FIND_ARG;
121588 +
121589 + for (i = 0; i < gimple_call_num_args(stmt); i++) {
121590 + tree node;
121591 +
121592 + node = gimple_call_arg(stmt, i);
121593 + if (!operand_equal_p(arg, node, 0))
121594 + continue;
121595 + if (!skip_types(node))
121596 + return i + 1;
121597 + }
121598 +
121599 + return CANNOT_FIND_ARG;
121600 +}
121601 +
121602 +/* starting from the size_overflow asm stmt collect interesting stmts. They can be
121603 + * any of return, call or assignment stmts (because of inlining).
121604 + */
121605 +static struct interesting_node *get_interesting_ret_or_call(struct pointer_set_t *visited, struct interesting_node *head, tree node, gimple intentional_asm)
121606 +{
121607 + use_operand_p use_p;
121608 + imm_use_iterator imm_iter;
121609 + unsigned int argnum;
121610 +
121611 + gcc_assert(TREE_CODE(node) == SSA_NAME);
121612 +
121613 + if (pointer_set_insert(visited, node))
121614 + return head;
121615 +
121616 + FOR_EACH_IMM_USE_FAST(use_p, imm_iter, node) {
121617 + gimple stmt = USE_STMT(use_p);
121618 +
121619 + if (stmt == NULL)
121620 + return head;
121621 + if (is_gimple_debug(stmt))
121622 + continue;
121623 +
121624 + switch (gimple_code(stmt)) {
121625 + case GIMPLE_CALL:
121626 + argnum = find_arg_number_gimple(node, stmt);
121627 + head = create_new_interesting_node(head, stmt, node, argnum, intentional_asm);
121628 + break;
121629 + case GIMPLE_RETURN:
121630 + head = create_new_interesting_node(head, stmt, node, 0, intentional_asm);
121631 + break;
121632 + case GIMPLE_ASSIGN:
121633 + argnum = get_assign_ops_count(stmt, node);
121634 + head = create_new_interesting_node(head, stmt, node, argnum, intentional_asm);
121635 + break;
121636 + case GIMPLE_PHI: {
121637 + tree result = gimple_phi_result(stmt);
121638 + head = get_interesting_ret_or_call(visited, head, result, intentional_asm);
121639 + break;
121640 + }
121641 + case GIMPLE_ASM:
121642 + if (gimple_asm_noutputs(stmt) != 0)
121643 + break;
121644 + if (!is_size_overflow_asm(stmt))
121645 + break;
121646 + head = create_new_interesting_node(head, stmt, node, 1, intentional_asm);
121647 + break;
121648 + case GIMPLE_COND:
121649 + case GIMPLE_SWITCH:
121650 + break;
121651 + default:
121652 + debug_gimple_stmt(stmt);
121653 + gcc_unreachable();
121654 + break;
121655 + }
121656 + }
121657 + return head;
121658 +}
121659 +
121660 +static void remove_size_overflow_asm(gimple stmt)
121661 +{
121662 + gimple_stmt_iterator gsi;
121663 + tree input, output;
121664 +
121665 + if (!is_size_overflow_asm(stmt))
121666 + return;
121667 +
121668 + if (gimple_asm_noutputs(stmt) == 0) {
121669 + gsi = gsi_for_stmt(stmt);
121670 + ipa_remove_stmt_references(cgraph_get_create_node(current_function_decl), stmt);
121671 + gsi_remove(&gsi, true);
121672 + return;
121673 + }
121674 +
121675 + input = gimple_asm_input_op(stmt, 0);
121676 + output = gimple_asm_output_op(stmt, 0);
121677 + replace_size_overflow_asm_with_assign(stmt, TREE_VALUE(output), TREE_VALUE(input));
121678 +}
121679 +
121680 +/* handle the size_overflow asm stmts from the gimple pass and collect the interesting stmts.
121681 + * If the asm stmt is a parm_decl kind (noutputs == 0) then remove it.
121682 + * If it is a simple asm stmt then replace it with an assignment from the asm input to the asm output.
121683 + */
121684 +static struct interesting_node *handle_stmt_by_size_overflow_asm(gimple stmt, struct interesting_node *head)
121685 +{
121686 + const_tree output;
121687 + struct pointer_set_t *visited;
121688 + gimple intentional_asm = NOT_INTENTIONAL_ASM;
121689 +
121690 + if (!is_size_overflow_asm(stmt))
121691 + return head;
121692 +
121693 + if (is_size_overflow_intentional_asm_yes(stmt) || is_size_overflow_intentional_asm_turn_off(stmt))
121694 + intentional_asm = stmt;
121695 +
121696 + gcc_assert(gimple_asm_ninputs(stmt) == 1);
121697 +
121698 + if (gimple_asm_noutputs(stmt) == 0 && is_size_overflow_intentional_asm_turn_off(stmt))
121699 + return head;
121700 +
121701 + if (gimple_asm_noutputs(stmt) == 0) {
121702 + const_tree input;
121703 +
121704 + if (!is_size_overflow_intentional_asm_turn_off(stmt))
121705 + return head;
121706 +
121707 + input = gimple_asm_input_op(stmt, 0);
121708 + remove_size_overflow_asm(stmt);
121709 + if (is_gimple_constant(TREE_VALUE(input)))
121710 + return head;
121711 + visited = pointer_set_create();
121712 + head = get_interesting_ret_or_call(visited, head, TREE_VALUE(input), intentional_asm);
121713 + pointer_set_destroy(visited);
121714 + return head;
121715 + }
121716 +
121717 + if (!is_size_overflow_intentional_asm_yes(stmt) && !is_size_overflow_intentional_asm_turn_off(stmt))
121718 + remove_size_overflow_asm(stmt);
121719 +
121720 + visited = pointer_set_create();
121721 + output = gimple_asm_output_op(stmt, 0);
121722 + head = get_interesting_ret_or_call(visited, head, TREE_VALUE(output), intentional_asm);
121723 + pointer_set_destroy(visited);
121724 + return head;
121725 +}
121726 +
121727 +/* Iterate over all the stmts of a function and look for the size_overflow asm stmts (they were created in the gimple pass)
121728 + * or a call stmt or a return stmt and store them in the interesting_node list
121729 + */
121730 +static struct interesting_node *collect_interesting_stmts(struct next_cgraph_node *next_node)
121731 +{
121732 + basic_block bb;
121733 + struct interesting_node *head = NULL;
121734 +
121735 + FOR_ALL_BB_FN(bb, cfun) {
121736 + gimple_stmt_iterator gsi;
121737 +
121738 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
121739 + enum gimple_code code;
121740 + gimple stmt = gsi_stmt(gsi);
121741 +
121742 + code = gimple_code(stmt);
121743 +
121744 + if (code == GIMPLE_ASM)
121745 + head = handle_stmt_by_size_overflow_asm(stmt, head);
121746 +
121747 + if (!next_node)
121748 + continue;
121749 + if (code == GIMPLE_CALL)
121750 + head = handle_stmt_by_cgraph_nodes_call(head, stmt, next_node);
121751 + if (code == GIMPLE_RETURN)
121752 + head = handle_stmt_by_cgraph_nodes_ret(head, stmt, next_node);
121753 + }
121754 + }
121755 + return head;
121756 +}
121757 +
121758 +static void free_interesting_node(struct interesting_node *head)
121759 +{
121760 + struct interesting_node *cur;
121761 +
121762 + while (head) {
121763 + cur = head->next;
121764 +#if BUILDING_GCC_VERSION <= 4007
121765 + VEC_free(tree, gc, head->last_nodes);
121766 +#else
121767 + vec_free(head->last_nodes);
121768 +#endif
121769 + free(head);
121770 + head = cur;
121771 + }
121772 +}
121773 +
121774 +static struct visited_fns *insert_visited_fns_function(struct visited_fns *head, struct interesting_node *cur_node)
121775 +{
121776 + struct visited_fns *new_visited_fns;
121777 +
121778 + new_visited_fns = (struct visited_fns *)xmalloc(sizeof(*new_visited_fns));
121779 + new_visited_fns->fndecl = cur_node->fndecl;
121780 + new_visited_fns->num = cur_node->num;
121781 + new_visited_fns->first_stmt = cur_node->first_stmt;
121782 + new_visited_fns->next = NULL;
121783 +
121784 + if (!head)
121785 + return new_visited_fns;
121786 +
121787 + new_visited_fns->next = head;
121788 + return new_visited_fns;
121789 +}
121790 +
121791 +/* 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
121792 + * it is a visited_fns function.
121793 + */
121794 +static bool is_visited_fns_function(struct visited_fns *head, struct interesting_node *cur_node)
121795 +{
121796 + struct visited_fns *cur;
121797 +
121798 + if (!head)
121799 + return false;
121800 +
121801 + for (cur = head; cur; cur = cur->next) {
121802 + if (cur_node->first_stmt != cur->first_stmt)
121803 + continue;
121804 + if (!operand_equal_p(cur_node->fndecl, cur->fndecl, 0))
121805 + continue;
121806 + if (cur_node->num == cur->num)
121807 + return true;
121808 + }
121809 + return false;
121810 +}
121811 +
121812 +static void free_next_cgraph_node(struct next_cgraph_node *head)
121813 +{
121814 + struct next_cgraph_node *cur;
121815 +
121816 + while (head) {
121817 + cur = head->next;
121818 + free(head);
121819 + head = cur;
121820 + }
121821 +}
121822 +
121823 +static void remove_all_size_overflow_asm(void)
121824 +{
121825 + basic_block bb;
121826 +
121827 + FOR_ALL_BB_FN(bb, cfun) {
121828 + gimple_stmt_iterator si;
121829 +
121830 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
121831 + remove_size_overflow_asm(gsi_stmt(si));
121832 + }
121833 +}
121834 +
121835 +/* Main recursive walk of the ipa pass: iterate over the collected interesting stmts in a function
121836 + * (they are interesting if they have an associated size_overflow asm stmt) and recursively walk
121837 + * the newly collected interesting functions (they are interesting if there is control flow between
121838 + * the interesting stmts and them).
121839 + */
121840 +static struct visited_fns *handle_function(struct cgraph_node *node, struct next_cgraph_node *next_node, struct visited_fns *visited_fns)
121841 +{
121842 + struct visited *visited;
121843 + struct interesting_node *head, *cur_node;
121844 + struct next_cgraph_node *cur_cnodes, *cnodes_head = NULL;
121845 +
121846 + set_current_function_decl(NODE_DECL(node));
121847 + call_count = 0;
121848 +
121849 + head = collect_interesting_stmts(next_node);
121850 +
121851 + visited = create_visited();
121852 + for (cur_node = head; cur_node; cur_node = cur_node->next) {
121853 + if (is_visited_fns_function(visited_fns, cur_node))
121854 + continue;
121855 + cnodes_head = handle_interesting_stmt(visited, cnodes_head, cur_node, node);
121856 + visited_fns = insert_visited_fns_function(visited_fns, cur_node);
121857 + }
121858 +
121859 + free_visited(visited);
121860 + free_interesting_node(head);
121861 + remove_all_size_overflow_asm();
121862 + unset_current_function_decl();
121863 +
121864 + for (cur_cnodes = cnodes_head; cur_cnodes; cur_cnodes = cur_cnodes->next)
121865 + visited_fns = handle_function(cur_cnodes->current_function, cur_cnodes, visited_fns);
121866 +
121867 + free_next_cgraph_node(cnodes_head);
121868 + return visited_fns;
121869 +}
121870 +
121871 +static void free_visited_fns(struct visited_fns *head)
121872 +{
121873 + struct visited_fns *cur;
121874 +
121875 + while (head) {
121876 + cur = head->next;
121877 + free(head);
121878 + head = cur;
121879 + }
121880 +}
121881 +
121882 +// Main entry point of the ipa pass: erases the plf flag of all stmts and iterates over all the functions
121883 +unsigned int search_function(void)
121884 +{
121885 + struct cgraph_node *node;
121886 + struct visited_fns *visited_fns = NULL;
121887 +
121888 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
121889 + gcc_assert(cgraph_function_flags_ready);
121890 +#if BUILDING_GCC_VERSION <= 4007
121891 + gcc_assert(node->reachable);
121892 +#endif
121893 +
121894 + visited_fns = handle_function(node, NULL, visited_fns);
121895 + }
121896 +
121897 + free_visited_fns(visited_fns);
121898 + return 0;
121899 +}
121900 +
121901 +#if BUILDING_GCC_VERSION >= 4009
121902 +static const struct pass_data insert_size_overflow_check_data = {
121903 +#else
121904 +static struct ipa_opt_pass_d insert_size_overflow_check = {
121905 + .pass = {
121906 +#endif
121907 + .type = SIMPLE_IPA_PASS,
121908 + .name = "size_overflow",
121909 +#if BUILDING_GCC_VERSION >= 4008
121910 + .optinfo_flags = OPTGROUP_NONE,
121911 +#endif
121912 +#if BUILDING_GCC_VERSION >= 4009
121913 + .has_gate = false,
121914 + .has_execute = true,
121915 +#else
121916 + .gate = NULL,
121917 + .execute = search_function,
121918 + .sub = NULL,
121919 + .next = NULL,
121920 + .static_pass_number = 0,
121921 +#endif
121922 + .tv_id = TV_NONE,
121923 + .properties_required = 0,
121924 + .properties_provided = 0,
121925 + .properties_destroyed = 0,
121926 + .todo_flags_start = 0,
121927 + .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,
121928 +#if BUILDING_GCC_VERSION < 4009
121929 + },
121930 + .generate_summary = NULL,
121931 + .write_summary = NULL,
121932 + .read_summary = NULL,
121933 +#if BUILDING_GCC_VERSION >= 4006
121934 + .write_optimization_summary = NULL,
121935 + .read_optimization_summary = NULL,
121936 +#endif
121937 + .stmt_fixup = NULL,
121938 + .function_transform_todo_flags_start = 0,
121939 + .function_transform = NULL,
121940 + .variable_transform = NULL,
121941 +#endif
121942 +};
121943 +
121944 +#if BUILDING_GCC_VERSION >= 4009
121945 +namespace {
121946 +class insert_size_overflow_check : public ipa_opt_pass_d {
121947 +public:
121948 + insert_size_overflow_check() : ipa_opt_pass_d(insert_size_overflow_check_data, g, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL) {}
121949 + unsigned int execute() { return search_function(); }
121950 +};
121951 +}
121952 +#endif
121953 +
121954 +struct opt_pass *make_insert_size_overflow_check(void)
121955 +{
121956 +#if BUILDING_GCC_VERSION >= 4009
121957 + return new insert_size_overflow_check();
121958 +#else
121959 + return &insert_size_overflow_check.pass;
121960 +#endif
121961 +}
121962 +
121963 diff --git a/tools/gcc/size_overflow_plugin/intentional_overflow.c b/tools/gcc/size_overflow_plugin/intentional_overflow.c
121964 new file mode 100644
121965 index 0000000..d71d72a
121966 --- /dev/null
121967 +++ b/tools/gcc/size_overflow_plugin/intentional_overflow.c
121968 @@ -0,0 +1,736 @@
121969 +/*
121970 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
121971 + * Licensed under the GPL v2, or (at your option) v3
121972 + *
121973 + * Homepage:
121974 + * http://www.grsecurity.net/~ephox/overflow_plugin/
121975 + *
121976 + * Documentation:
121977 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
121978 + *
121979 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
121980 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
121981 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
121982 + *
121983 + * Usage:
121984 + * $ make
121985 + * $ make run
121986 + */
121987 +
121988 +#include "gcc-common.h"
121989 +#include "size_overflow.h"
121990 +
121991 +/* Get the param of the intentional_overflow attribute.
121992 + * * 0: MARK_NOT_INTENTIONAL
121993 + * * 1..MAX_PARAM: MARK_YES
121994 + * * -1: MARK_TURN_OFF
121995 + */
121996 +static tree get_attribute_param(const_tree decl)
121997 +{
121998 + const_tree attr;
121999 +
122000 + if (decl == NULL_TREE)
122001 + return NULL_TREE;
122002 +
122003 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(decl));
122004 + if (!attr || !TREE_VALUE(attr))
122005 + return NULL_TREE;
122006 +
122007 + return TREE_VALUE(attr);
122008 +}
122009 +
122010 +// MARK_TURN_OFF
122011 +bool is_turn_off_intentional_attr(const_tree decl)
122012 +{
122013 + const_tree param_head;
122014 +
122015 + param_head = get_attribute_param(decl);
122016 + if (param_head == NULL_TREE)
122017 + return false;
122018 +
122019 + if (TREE_INT_CST_HIGH(TREE_VALUE(param_head)) == -1)
122020 + return true;
122021 + return false;
122022 +}
122023 +
122024 +// MARK_NOT_INTENTIONAL
122025 +bool is_end_intentional_intentional_attr(const_tree decl, unsigned int argnum)
122026 +{
122027 + const_tree param_head;
122028 +
122029 + if (argnum == 0)
122030 + return false;
122031 +
122032 + param_head = get_attribute_param(decl);
122033 + if (param_head == NULL_TREE)
122034 + return false;
122035 +
122036 + if (!TREE_INT_CST_LOW(TREE_VALUE(param_head)))
122037 + return true;
122038 + return false;
122039 +}
122040 +
122041 +// MARK_YES
122042 +bool is_yes_intentional_attr(const_tree decl, unsigned int argnum)
122043 +{
122044 + tree param, param_head;
122045 +
122046 + if (argnum == 0)
122047 + return false;
122048 +
122049 + param_head = get_attribute_param(decl);
122050 + for (param = param_head; param; param = TREE_CHAIN(param))
122051 + if (argnum == TREE_INT_CST_LOW(TREE_VALUE(param)))
122052 + return true;
122053 + return false;
122054 +}
122055 +
122056 +void print_missing_intentional(enum mark callee_attr, enum mark caller_attr, const_tree decl, unsigned int argnum)
122057 +{
122058 + location_t loc;
122059 +
122060 + if (caller_attr == MARK_NO || caller_attr == MARK_NOT_INTENTIONAL || caller_attr == MARK_TURN_OFF)
122061 + return;
122062 +
122063 + if (callee_attr == MARK_NOT_INTENTIONAL || callee_attr == MARK_YES)
122064 + return;
122065 +
122066 + loc = DECL_SOURCE_LOCATION(decl);
122067 + inform(loc, "The intentional_overflow attribute is missing from +%s+%u+", DECL_NAME_POINTER(decl), argnum);
122068 +}
122069 +
122070 +// Get the field decl of a component ref for intentional_overflow checking
122071 +static const_tree search_field_decl(const_tree comp_ref)
122072 +{
122073 + const_tree field = NULL_TREE;
122074 + unsigned int i, len = TREE_OPERAND_LENGTH(comp_ref);
122075 +
122076 + for (i = 0; i < len; i++) {
122077 + field = TREE_OPERAND(comp_ref, i);
122078 + if (TREE_CODE(field) == FIELD_DECL)
122079 + break;
122080 + }
122081 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
122082 + return field;
122083 +}
122084 +
122085 +/* Get the type of the intentional_overflow attribute of a node
122086 + * * MARK_TURN_OFF
122087 + * * MARK_YES
122088 + * * MARK_NO
122089 + * * MARK_NOT_INTENTIONAL
122090 + */
122091 +enum mark get_intentional_attr_type(const_tree node)
122092 +{
122093 + const_tree cur_decl;
122094 +
122095 + if (node == NULL_TREE)
122096 + return MARK_NO;
122097 +
122098 + switch (TREE_CODE(node)) {
122099 + case COMPONENT_REF:
122100 + cur_decl = search_field_decl(node);
122101 + if (is_turn_off_intentional_attr(cur_decl))
122102 + return MARK_TURN_OFF;
122103 + if (is_end_intentional_intentional_attr(cur_decl, 1))
122104 + return MARK_YES;
122105 + break;
122106 + case PARM_DECL: {
122107 + unsigned int argnum;
122108 +
122109 + cur_decl = DECL_ORIGIN(current_function_decl);
122110 + argnum = find_arg_number_tree(node, cur_decl);
122111 + if (argnum == CANNOT_FIND_ARG)
122112 + return MARK_NO;
122113 + if (is_yes_intentional_attr(cur_decl, argnum))
122114 + return MARK_YES;
122115 + if (is_end_intentional_intentional_attr(cur_decl, argnum))
122116 + return MARK_NOT_INTENTIONAL;
122117 + break;
122118 + }
122119 + case FUNCTION_DECL:
122120 + if (is_turn_off_intentional_attr(DECL_ORIGIN(node)))
122121 + return MARK_TURN_OFF;
122122 + break;
122123 + default:
122124 + break;
122125 + }
122126 + return MARK_NO;
122127 +}
122128 +
122129 +// Search for the intentional_overflow attribute on the last nodes
122130 +static enum mark search_last_nodes_intentional(struct interesting_node *cur_node)
122131 +{
122132 + unsigned int i;
122133 + tree last_node;
122134 + enum mark mark = MARK_NO;
122135 +
122136 +#if BUILDING_GCC_VERSION <= 4007
122137 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, last_node) {
122138 +#else
122139 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, last_node) {
122140 +#endif
122141 + mark = get_intentional_attr_type(last_node);
122142 + if (mark != MARK_NO)
122143 + break;
122144 + }
122145 + return mark;
122146 +}
122147 +
122148 +/* Check the intentional kind of size_overflow asm stmt (created by the gimple pass) and
122149 + * set the appropriate intentional_overflow type. Delete the asm stmt in the end.
122150 + */
122151 +static bool is_intentional_attribute_from_gimple(struct interesting_node *cur_node)
122152 +{
122153 + if (!cur_node->intentional_mark_from_gimple)
122154 + return false;
122155 +
122156 + if (is_size_overflow_intentional_asm_yes(cur_node->intentional_mark_from_gimple))
122157 + cur_node->intentional_attr_cur_fndecl = MARK_YES;
122158 + else
122159 + cur_node->intentional_attr_cur_fndecl = MARK_TURN_OFF;
122160 +
122161 + // skip param decls
122162 + if (gimple_asm_noutputs(cur_node->intentional_mark_from_gimple) == 0)
122163 + return true;
122164 + return true;
122165 +}
122166 +
122167 +/* Search intentional_overflow attribute on caller and on callee too.
122168 + * 0</MARK_YES: no dup, search size_overflow and intentional_overflow attributes
122169 + * 0/MARK_NOT_INTENTIONAL: no dup, search size_overflow attribute (int)
122170 + * -1/MARK_TURN_OFF: no dup, no search, current_function_decl -> no dup
122171 +*/
122172 +void check_intentional_attribute_ipa(struct interesting_node *cur_node)
122173 +{
122174 + const_tree fndecl;
122175 +
122176 + if (is_intentional_attribute_from_gimple(cur_node))
122177 + return;
122178 +
122179 + if (is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl))) {
122180 + cur_node->intentional_attr_cur_fndecl = MARK_TURN_OFF;
122181 + return;
122182 + }
122183 +
122184 + if (gimple_code(cur_node->first_stmt) == GIMPLE_ASM) {
122185 + cur_node->intentional_attr_cur_fndecl = MARK_NOT_INTENTIONAL;
122186 + return;
122187 + }
122188 +
122189 + if (gimple_code(cur_node->first_stmt) == GIMPLE_ASSIGN)
122190 + return;
122191 +
122192 + fndecl = get_interesting_orig_fndecl(cur_node->first_stmt, cur_node->num);
122193 + if (is_turn_off_intentional_attr(fndecl)) {
122194 + cur_node->intentional_attr_decl = MARK_TURN_OFF;
122195 + return;
122196 + }
122197 +
122198 + if (is_end_intentional_intentional_attr(fndecl, cur_node->num))
122199 + cur_node->intentional_attr_decl = MARK_NOT_INTENTIONAL;
122200 + else if (is_yes_intentional_attr(fndecl, cur_node->num))
122201 + cur_node->intentional_attr_decl = MARK_YES;
122202 +
122203 + cur_node->intentional_attr_cur_fndecl = search_last_nodes_intentional(cur_node);
122204 + print_missing_intentional(cur_node->intentional_attr_decl, cur_node->intentional_attr_cur_fndecl, cur_node->fndecl, cur_node->num);
122205 +}
122206 +
122207 +bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
122208 +{
122209 + const_tree rhs1, lhs, rhs1_type, lhs_type;
122210 + enum machine_mode lhs_mode, rhs_mode;
122211 + gimple def_stmt = get_def_stmt(no_const_rhs);
122212 +
122213 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
122214 + return false;
122215 +
122216 + rhs1 = gimple_assign_rhs1(def_stmt);
122217 + lhs = gimple_assign_lhs(def_stmt);
122218 + rhs1_type = TREE_TYPE(rhs1);
122219 + lhs_type = TREE_TYPE(lhs);
122220 + rhs_mode = TYPE_MODE(rhs1_type);
122221 + lhs_mode = TYPE_MODE(lhs_type);
122222 + if (TYPE_UNSIGNED(lhs_type) == TYPE_UNSIGNED(rhs1_type) || lhs_mode != rhs_mode)
122223 + return false;
122224 +
122225 + return true;
122226 +}
122227 +
122228 +static unsigned int uses_num(tree node)
122229 +{
122230 + imm_use_iterator imm_iter;
122231 + use_operand_p use_p;
122232 + unsigned int num = 0;
122233 +
122234 + FOR_EACH_IMM_USE_FAST(use_p, imm_iter, node) {
122235 + gimple use_stmt = USE_STMT(use_p);
122236 +
122237 + if (use_stmt == NULL)
122238 + return num;
122239 + if (is_gimple_debug(use_stmt))
122240 + continue;
122241 + if (gimple_assign_cast_p(use_stmt) && is_size_overflow_type(gimple_assign_lhs(use_stmt)))
122242 + continue;
122243 + num++;
122244 + }
122245 + return num;
122246 +}
122247 +
122248 +static bool no_uses(tree node)
122249 +{
122250 + return !uses_num(node);
122251 +}
122252 +
122253 +// 3.8.5 mm/page-writeback.c __ilog2_u64(): ret, uint + uintmax; uint -> int; int max
122254 +bool is_const_plus_unsigned_signed_truncation(const_tree lhs)
122255 +{
122256 + tree rhs1, lhs_type, rhs_type, rhs2, not_const_rhs;
122257 + gimple def_stmt = get_def_stmt(lhs);
122258 +
122259 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
122260 + return false;
122261 +
122262 + rhs1 = gimple_assign_rhs1(def_stmt);
122263 + rhs_type = TREE_TYPE(rhs1);
122264 + lhs_type = TREE_TYPE(lhs);
122265 + if (TYPE_UNSIGNED(lhs_type) || !TYPE_UNSIGNED(rhs_type))
122266 + return false;
122267 + if (TYPE_MODE(lhs_type) != TYPE_MODE(rhs_type))
122268 + return false;
122269 +
122270 + def_stmt = get_def_stmt(rhs1);
122271 + if (!def_stmt || !is_gimple_assign(def_stmt) || gimple_num_ops(def_stmt) != 3)
122272 + return false;
122273 +
122274 + if (gimple_assign_rhs_code(def_stmt) != PLUS_EXPR)
122275 + return false;
122276 +
122277 + rhs1 = gimple_assign_rhs1(def_stmt);
122278 + rhs2 = gimple_assign_rhs2(def_stmt);
122279 + if (!is_gimple_constant(rhs1) && !is_gimple_constant(rhs2))
122280 + return false;
122281 +
122282 + if (is_gimple_constant(rhs2))
122283 + not_const_rhs = rhs1;
122284 + else
122285 + not_const_rhs = rhs2;
122286 +
122287 + return no_uses(not_const_rhs);
122288 +}
122289 +
122290 +static bool is_lt_signed_type_max(const_tree rhs)
122291 +{
122292 + const_tree new_type, type_max, type = TREE_TYPE(rhs);
122293 +
122294 + if (!TYPE_UNSIGNED(type))
122295 + return true;
122296 +
122297 + switch (TYPE_MODE(type)) {
122298 + case QImode:
122299 + new_type = intQI_type_node;
122300 + break;
122301 + case HImode:
122302 + new_type = intHI_type_node;
122303 + break;
122304 + case SImode:
122305 + new_type = intSI_type_node;
122306 + break;
122307 + case DImode:
122308 + new_type = intDI_type_node;
122309 + break;
122310 + default:
122311 + debug_tree((tree)type);
122312 + gcc_unreachable();
122313 + }
122314 +
122315 + type_max = TYPE_MAX_VALUE(new_type);
122316 + if (!tree_int_cst_lt(type_max, rhs))
122317 + return true;
122318 +
122319 + return false;
122320 +}
122321 +
122322 +static bool is_gt_zero(const_tree rhs)
122323 +{
122324 + const_tree type = TREE_TYPE(rhs);
122325 +
122326 + if (TYPE_UNSIGNED(type))
122327 + return true;
122328 +
122329 + if (!tree_int_cst_lt(rhs, integer_zero_node))
122330 + return true;
122331 +
122332 + return false;
122333 +}
122334 +
122335 +bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
122336 +{
122337 + if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
122338 + return false;
122339 + if (!is_gimple_constant(rhs))
122340 + return false;
122341 +
122342 + // If the const is between 0 and the max value of the signed type of the same bitsize then there is no intentional overflow
122343 + if (is_lt_signed_type_max(rhs) && is_gt_zero(rhs))
122344 + return false;
122345 +
122346 + return true;
122347 +}
122348 +
122349 +static tree change_assign_rhs(struct visited *visited, gimple stmt, const_tree orig_rhs, tree new_rhs)
122350 +{
122351 + gimple assign;
122352 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
122353 + tree origtype = TREE_TYPE(orig_rhs);
122354 +
122355 + gcc_assert(is_gimple_assign(stmt));
122356 +
122357 + assign = build_cast_stmt(visited, origtype, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
122358 + pointer_set_insert(visited->my_stmts, assign);
122359 + return gimple_assign_lhs(assign);
122360 +}
122361 +
122362 +tree handle_intentional_overflow(struct visited *visited, struct cgraph_node *caller_node, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs2)
122363 +{
122364 + tree new_rhs, orig_rhs;
122365 + void (*gimple_assign_set_rhs)(gimple, tree);
122366 + tree rhs1 = gimple_assign_rhs1(stmt);
122367 + tree rhs2 = gimple_assign_rhs2(stmt);
122368 + tree lhs = gimple_assign_lhs(stmt);
122369 +
122370 + if (!check_overflow)
122371 + return create_assign(visited, stmt, lhs, AFTER_STMT);
122372 +
122373 + if (change_rhs == NULL_TREE)
122374 + return create_assign(visited, stmt, lhs, AFTER_STMT);
122375 +
122376 + if (new_rhs2 == NULL_TREE) {
122377 + orig_rhs = rhs1;
122378 + gimple_assign_set_rhs = &gimple_assign_set_rhs1;
122379 + } else {
122380 + orig_rhs = rhs2;
122381 + gimple_assign_set_rhs = &gimple_assign_set_rhs2;
122382 + }
122383 +
122384 + check_size_overflow(caller_node, stmt, TREE_TYPE(change_rhs), change_rhs, orig_rhs, BEFORE_STMT);
122385 +
122386 + new_rhs = change_assign_rhs(visited, stmt, orig_rhs, change_rhs);
122387 + gimple_assign_set_rhs(stmt, new_rhs);
122388 + update_stmt(stmt);
122389 +
122390 + return create_assign(visited, stmt, lhs, AFTER_STMT);
122391 +}
122392 +
122393 +static bool is_subtraction_special(struct visited *visited, const_gimple stmt)
122394 +{
122395 + gimple rhs1_def_stmt, rhs2_def_stmt;
122396 + const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1, rhs1_def_stmt_lhs, rhs2_def_stmt_lhs;
122397 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode, rhs1_def_stmt_lhs_mode, rhs2_def_stmt_lhs_mode;
122398 + const_tree rhs1 = gimple_assign_rhs1(stmt);
122399 + const_tree rhs2 = gimple_assign_rhs2(stmt);
122400 +
122401 + if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
122402 + return false;
122403 +
122404 + gcc_assert(TREE_CODE(rhs1) == SSA_NAME && TREE_CODE(rhs2) == SSA_NAME);
122405 +
122406 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
122407 + return false;
122408 +
122409 + rhs1_def_stmt = get_def_stmt(rhs1);
122410 + rhs2_def_stmt = get_def_stmt(rhs2);
122411 + if (!gimple_assign_cast_p(rhs1_def_stmt) || !gimple_assign_cast_p(rhs2_def_stmt))
122412 + return false;
122413 +
122414 + rhs1_def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
122415 + rhs2_def_stmt_rhs1 = gimple_assign_rhs1(rhs2_def_stmt);
122416 + rhs1_def_stmt_lhs = gimple_assign_lhs(rhs1_def_stmt);
122417 + rhs2_def_stmt_lhs = gimple_assign_lhs(rhs2_def_stmt);
122418 + rhs1_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_rhs1));
122419 + rhs2_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_rhs1));
122420 + rhs1_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_lhs));
122421 + rhs2_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_lhs));
122422 + if (GET_MODE_BITSIZE(rhs1_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs1_def_stmt_lhs_mode))
122423 + return false;
122424 + if (GET_MODE_BITSIZE(rhs2_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs2_def_stmt_lhs_mode))
122425 + return false;
122426 +
122427 + pointer_set_insert(visited->no_cast_check, rhs1_def_stmt);
122428 + pointer_set_insert(visited->no_cast_check, rhs2_def_stmt);
122429 + return true;
122430 +}
122431 +
122432 +static gimple create_binary_assign(struct visited *visited, enum tree_code code, gimple stmt, tree rhs1, tree rhs2)
122433 +{
122434 + gimple assign;
122435 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
122436 + tree type = TREE_TYPE(rhs1);
122437 + tree lhs = create_new_var(type);
122438 +
122439 + gcc_assert(types_compatible_p(type, TREE_TYPE(rhs2)));
122440 + assign = gimple_build_assign_with_ops(code, lhs, rhs1, rhs2);
122441 + gimple_assign_set_lhs(assign, make_ssa_name(lhs, assign));
122442 +
122443 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
122444 + update_stmt(assign);
122445 + pointer_set_insert(visited->my_stmts, assign);
122446 + return assign;
122447 +}
122448 +
122449 +static tree cast_to_TI_type(struct visited *visited, gimple stmt, tree node)
122450 +{
122451 + gimple_stmt_iterator gsi;
122452 + gimple cast_stmt;
122453 + tree type = TREE_TYPE(node);
122454 +
122455 + if (types_compatible_p(type, intTI_type_node))
122456 + return node;
122457 +
122458 + gsi = gsi_for_stmt(stmt);
122459 + cast_stmt = build_cast_stmt(visited, intTI_type_node, node, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
122460 + pointer_set_insert(visited->my_stmts, cast_stmt);
122461 + return gimple_assign_lhs(cast_stmt);
122462 +}
122463 +
122464 +static tree get_def_stmt_rhs(struct visited *visited, const_tree var)
122465 +{
122466 + tree rhs1, def_stmt_rhs1;
122467 + gimple rhs1_def_stmt, def_stmt_rhs1_def_stmt, def_stmt;
122468 +
122469 + def_stmt = get_def_stmt(var);
122470 + if (!gimple_assign_cast_p(def_stmt))
122471 + return NULL_TREE;
122472 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP && pointer_set_contains(visited->my_stmts, def_stmt) && gimple_assign_cast_p(def_stmt));
122473 +
122474 + rhs1 = gimple_assign_rhs1(def_stmt);
122475 + rhs1_def_stmt = get_def_stmt(rhs1);
122476 + if (!gimple_assign_cast_p(rhs1_def_stmt))
122477 + return rhs1;
122478 +
122479 + def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
122480 + def_stmt_rhs1_def_stmt = get_def_stmt(def_stmt_rhs1);
122481 +
122482 + switch (gimple_code(def_stmt_rhs1_def_stmt)) {
122483 + case GIMPLE_CALL:
122484 + case GIMPLE_NOP:
122485 + case GIMPLE_ASM:
122486 + case GIMPLE_PHI:
122487 + return def_stmt_rhs1;
122488 + case GIMPLE_ASSIGN:
122489 + return rhs1;
122490 + default:
122491 + debug_gimple_stmt(def_stmt_rhs1_def_stmt);
122492 + gcc_unreachable();
122493 + }
122494 +}
122495 +
122496 +tree handle_integer_truncation(struct visited *visited, struct cgraph_node *caller_node, const_tree lhs)
122497 +{
122498 + tree new_rhs1, new_rhs2;
122499 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
122500 + gimple assign, stmt = get_def_stmt(lhs);
122501 + tree rhs1 = gimple_assign_rhs1(stmt);
122502 + tree rhs2 = gimple_assign_rhs2(stmt);
122503 +
122504 + if (!is_subtraction_special(visited, stmt))
122505 + return NULL_TREE;
122506 +
122507 + new_rhs1 = expand(visited, caller_node, rhs1);
122508 + new_rhs2 = expand(visited, caller_node, rhs2);
122509 +
122510 + new_rhs1_def_stmt_rhs1 = get_def_stmt_rhs(visited, new_rhs1);
122511 + new_rhs2_def_stmt_rhs1 = get_def_stmt_rhs(visited, new_rhs2);
122512 +
122513 + if (new_rhs1_def_stmt_rhs1 == NULL_TREE || new_rhs2_def_stmt_rhs1 == NULL_TREE)
122514 + return NULL_TREE;
122515 +
122516 + if (!types_compatible_p(TREE_TYPE(new_rhs1_def_stmt_rhs1), TREE_TYPE(new_rhs2_def_stmt_rhs1))) {
122517 + new_rhs1_def_stmt_rhs1 = cast_to_TI_type(visited, stmt, new_rhs1_def_stmt_rhs1);
122518 + new_rhs2_def_stmt_rhs1 = cast_to_TI_type(visited, stmt, new_rhs2_def_stmt_rhs1);
122519 + }
122520 +
122521 + assign = create_binary_assign(visited, MINUS_EXPR, stmt, new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1);
122522 + new_lhs = gimple_assign_lhs(assign);
122523 + check_size_overflow(caller_node, assign, TREE_TYPE(new_lhs), new_lhs, rhs1, AFTER_STMT);
122524 +
122525 + return dup_assign(visited, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
122526 +}
122527 +
122528 +bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
122529 +{
122530 + const_gimple def_stmt;
122531 +
122532 + if (TREE_CODE(rhs) != SSA_NAME)
122533 + return false;
122534 +
122535 + if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
122536 + return false;
122537 +
122538 + def_stmt = get_def_stmt(rhs);
122539 + if (!is_gimple_assign(def_stmt) || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
122540 + return false;
122541 +
122542 + return true;
122543 +}
122544 +
122545 +/* e.g., drivers/acpi/acpica/utids.c acpi_ut_execute_CID()
122546 + * ((count - 1) * sizeof(struct acpi_pnp_dee_id_list) -> (count + fffffff) * 16
122547 + * fffffff * 16 > signed max -> truncate
122548 + */
122549 +static bool look_for_mult_and_add(const_gimple stmt)
122550 +{
122551 + const_tree res;
122552 + tree rhs1, rhs2, def_rhs1, def_rhs2, const_rhs, def_const_rhs;
122553 + const_gimple def_stmt;
122554 +
122555 + if (!stmt || gimple_code(stmt) == GIMPLE_NOP)
122556 + return false;
122557 + if (!is_gimple_assign(stmt))
122558 + return false;
122559 + if (gimple_assign_rhs_code(stmt) != MULT_EXPR)
122560 + return false;
122561 +
122562 + rhs1 = gimple_assign_rhs1(stmt);
122563 + rhs2 = gimple_assign_rhs2(stmt);
122564 + if (is_gimple_constant(rhs1)) {
122565 + const_rhs = rhs1;
122566 + def_stmt = get_def_stmt(rhs2);
122567 + } else if (is_gimple_constant(rhs2)) {
122568 + const_rhs = rhs2;
122569 + def_stmt = get_def_stmt(rhs1);
122570 + } else
122571 + return false;
122572 +
122573 + if (!is_gimple_assign(def_stmt))
122574 + return false;
122575 +
122576 + if (gimple_assign_rhs_code(def_stmt) != PLUS_EXPR && gimple_assign_rhs_code(def_stmt) != MINUS_EXPR)
122577 + return false;
122578 +
122579 + def_rhs1 = gimple_assign_rhs1(def_stmt);
122580 + def_rhs2 = gimple_assign_rhs2(def_stmt);
122581 + if (is_gimple_constant(def_rhs1))
122582 + def_const_rhs = def_rhs1;
122583 + else if (is_gimple_constant(def_rhs2))
122584 + def_const_rhs = def_rhs2;
122585 + else
122586 + return false;
122587 +
122588 + res = fold_binary_loc(gimple_location(def_stmt), MULT_EXPR, TREE_TYPE(const_rhs), const_rhs, def_const_rhs);
122589 + if (is_lt_signed_type_max(res) && is_gt_zero(res))
122590 + return false;
122591 + return true;
122592 +}
122593 +
122594 +enum intentional_overflow_type add_mul_intentional_overflow(const_gimple stmt)
122595 +{
122596 + const_gimple def_stmt_1, def_stmt_2;
122597 + const_tree rhs1, rhs2;
122598 + bool add_mul_rhs1, add_mul_rhs2;
122599 +
122600 + rhs1 = gimple_assign_rhs1(stmt);
122601 + def_stmt_1 = get_def_stmt(rhs1);
122602 + add_mul_rhs1 = look_for_mult_and_add(def_stmt_1);
122603 +
122604 + rhs2 = gimple_assign_rhs2(stmt);
122605 + def_stmt_2 = get_def_stmt(rhs2);
122606 + add_mul_rhs2 = look_for_mult_and_add(def_stmt_2);
122607 +
122608 + if (add_mul_rhs1)
122609 + return RHS1_INTENTIONAL_OVERFLOW;
122610 + if (add_mul_rhs2)
122611 + return RHS2_INTENTIONAL_OVERFLOW;
122612 + return NO_INTENTIONAL_OVERFLOW;
122613 +}
122614 +
122615 +static gimple get_dup_stmt(struct visited *visited, gimple stmt)
122616 +{
122617 + gimple my_stmt;
122618 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
122619 +
122620 + gsi_next(&gsi);
122621 + my_stmt = gsi_stmt(gsi);
122622 +
122623 + gcc_assert(pointer_set_contains(visited->my_stmts, my_stmt));
122624 + gcc_assert(gimple_assign_rhs_code(stmt) == gimple_assign_rhs_code(my_stmt));
122625 +
122626 + return my_stmt;
122627 +}
122628 +
122629 +/* unsigned type -> unary or binary assign (rhs1 or rhs2 is constant)
122630 + * unsigned type cast to signed type, unsigned type: no more uses
122631 + * e.g., lib/vsprintf.c:simple_strtol()
122632 + * _10 = (unsigned long int) _9
122633 + * _11 = -_10;
122634 + * _12 = (long int) _11; (_11_ no more uses)
122635 + */
122636 +static bool is_call_or_cast(gimple stmt)
122637 +{
122638 + return gimple_assign_cast_p(stmt) || is_gimple_call(stmt);
122639 +}
122640 +
122641 +static bool is_unsigned_cast_or_call_def_stmt(const_tree node)
122642 +{
122643 + const_tree rhs;
122644 + gimple def_stmt;
122645 +
122646 + if (node == NULL_TREE)
122647 + return true;
122648 + if (is_gimple_constant(node))
122649 + return true;
122650 +
122651 + def_stmt = get_def_stmt(node);
122652 + if (!def_stmt)
122653 + return false;
122654 +
122655 + if (is_call_or_cast(def_stmt))
122656 + return true;
122657 +
122658 + if (!is_gimple_assign(def_stmt) || gimple_num_ops(def_stmt) != 2)
122659 + return false;
122660 + rhs = gimple_assign_rhs1(def_stmt);
122661 + def_stmt = get_def_stmt(rhs);
122662 + if (!def_stmt)
122663 + return false;
122664 + return is_call_or_cast(def_stmt);
122665 +}
122666 +
122667 +void unsigned_signed_cast_intentional_overflow(struct visited *visited, gimple stmt)
122668 +{
122669 + unsigned int use_num;
122670 + gimple so_stmt;
122671 + const_gimple def_stmt;
122672 + const_tree rhs1, rhs2;
122673 + tree rhs = gimple_assign_rhs1(stmt);
122674 + tree lhs_type = TREE_TYPE(gimple_assign_lhs(stmt));
122675 + const_tree rhs_type = TREE_TYPE(rhs);
122676 +
122677 + if (!(TYPE_UNSIGNED(rhs_type) && !TYPE_UNSIGNED(lhs_type)))
122678 + return;
122679 + if (GET_MODE_BITSIZE(TYPE_MODE(rhs_type)) != GET_MODE_BITSIZE(TYPE_MODE(lhs_type)))
122680 + return;
122681 + use_num = uses_num(rhs);
122682 + if (use_num != 1)
122683 + return;
122684 +
122685 + def_stmt = get_def_stmt(rhs);
122686 + if (!def_stmt)
122687 + return;
122688 + if (!is_gimple_assign(def_stmt))
122689 + return;
122690 +
122691 + rhs1 = gimple_assign_rhs1(def_stmt);
122692 + if (!is_unsigned_cast_or_call_def_stmt(rhs1))
122693 + return;
122694 +
122695 + rhs2 = gimple_assign_rhs2(def_stmt);
122696 + if (!is_unsigned_cast_or_call_def_stmt(rhs2))
122697 + return;
122698 + if (gimple_num_ops(def_stmt) == 3 && !is_gimple_constant(rhs1) && !is_gimple_constant(rhs2))
122699 + return;
122700 +
122701 + so_stmt = get_dup_stmt(visited, stmt);
122702 + create_up_and_down_cast(visited, so_stmt, lhs_type, gimple_assign_rhs1(so_stmt));
122703 +}
122704 +
122705 diff --git a/tools/gcc/size_overflow_plugin/misc.c b/tools/gcc/size_overflow_plugin/misc.c
122706 new file mode 100644
122707 index 0000000..4bddad2
122708 --- /dev/null
122709 +++ b/tools/gcc/size_overflow_plugin/misc.c
122710 @@ -0,0 +1,203 @@
122711 +/*
122712 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
122713 + * Licensed under the GPL v2, or (at your option) v3
122714 + *
122715 + * Homepage:
122716 + * http://www.grsecurity.net/~ephox/overflow_plugin/
122717 + *
122718 + * Documentation:
122719 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
122720 + *
122721 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
122722 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
122723 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
122724 + *
122725 + * Usage:
122726 + * $ make
122727 + * $ make run
122728 + */
122729 +
122730 +#include "gcc-common.h"
122731 +#include "size_overflow.h"
122732 +
122733 +void set_current_function_decl(tree fndecl)
122734 +{
122735 + gcc_assert(fndecl != NULL_TREE);
122736 +
122737 + push_cfun(DECL_STRUCT_FUNCTION(fndecl));
122738 + calculate_dominance_info(CDI_DOMINATORS);
122739 + current_function_decl = fndecl;
122740 +}
122741 +
122742 +void unset_current_function_decl(void)
122743 +{
122744 + free_dominance_info(CDI_DOMINATORS);
122745 + pop_cfun();
122746 + current_function_decl = NULL_TREE;
122747 +}
122748 +
122749 +static bool is_bool(const_tree node)
122750 +{
122751 + const_tree type;
122752 +
122753 + if (node == NULL_TREE)
122754 + return false;
122755 +
122756 + type = TREE_TYPE(node);
122757 + if (!INTEGRAL_TYPE_P(type))
122758 + return false;
122759 + if (TREE_CODE(type) == BOOLEAN_TYPE)
122760 + return true;
122761 + if (TYPE_PRECISION(type) == 1)
122762 + return true;
122763 + return false;
122764 +}
122765 +
122766 +bool skip_types(const_tree var)
122767 +{
122768 + tree type;
122769 + enum tree_code code;
122770 +
122771 + if (is_gimple_constant(var))
122772 + return true;
122773 +
122774 + switch (TREE_CODE(var)) {
122775 + case ADDR_EXPR:
122776 +#if BUILDING_GCC_VERSION >= 4006
122777 + case MEM_REF:
122778 +#endif
122779 + case ARRAY_REF:
122780 + case BIT_FIELD_REF:
122781 + case INDIRECT_REF:
122782 + case TARGET_MEM_REF:
122783 + case COMPONENT_REF:
122784 + case VAR_DECL:
122785 + case VIEW_CONVERT_EXPR:
122786 + return true;
122787 + default:
122788 + break;
122789 + }
122790 +
122791 + code = TREE_CODE(var);
122792 + gcc_assert(code == SSA_NAME || code == PARM_DECL);
122793 +
122794 + type = TREE_TYPE(var);
122795 + switch (TREE_CODE(type)) {
122796 + case INTEGER_TYPE:
122797 + case ENUMERAL_TYPE:
122798 + return false;
122799 + case BOOLEAN_TYPE:
122800 + return is_bool(var);
122801 + default:
122802 + return true;
122803 + }
122804 +}
122805 +
122806 +gimple get_def_stmt(const_tree node)
122807 +{
122808 + gcc_assert(node != NULL_TREE);
122809 +
122810 + if (skip_types(node))
122811 + return NULL;
122812 +
122813 + if (TREE_CODE(node) != SSA_NAME)
122814 + return NULL;
122815 + return SSA_NAME_DEF_STMT(node);
122816 +}
122817 +
122818 +tree create_new_var(tree type)
122819 +{
122820 + tree new_var = create_tmp_var(type, "cicus");
122821 +
122822 + add_referenced_var(new_var);
122823 + return new_var;
122824 +}
122825 +
122826 +static bool skip_cast(tree dst_type, const_tree rhs, bool force)
122827 +{
122828 + const_gimple def_stmt = get_def_stmt(rhs);
122829 +
122830 + if (force)
122831 + return false;
122832 +
122833 + if (is_gimple_constant(rhs))
122834 + return false;
122835 +
122836 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
122837 + return false;
122838 +
122839 + if (!types_compatible_p(dst_type, TREE_TYPE(rhs)))
122840 + return false;
122841 +
122842 + // DI type can be on 32 bit (from create_assign) but overflow type stays DI
122843 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
122844 + return false;
122845 +
122846 + return true;
122847 +}
122848 +
122849 +tree cast_a_tree(tree type, tree var)
122850 +{
122851 + gcc_assert(type != NULL_TREE);
122852 + gcc_assert(var != NULL_TREE);
122853 + gcc_assert(fold_convertible_p(type, var));
122854 +
122855 + return fold_convert(type, var);
122856 +}
122857 +
122858 +gimple build_cast_stmt(struct visited *visited, tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before, bool force)
122859 +{
122860 + gimple assign, def_stmt;
122861 +
122862 + gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
122863 + gcc_assert(!is_gimple_constant(rhs));
122864 + if (gsi_end_p(*gsi) && before == AFTER_STMT)
122865 + gcc_unreachable();
122866 +
122867 + def_stmt = get_def_stmt(rhs);
122868 + if (def_stmt && gimple_code(def_stmt) != GIMPLE_NOP && skip_cast(dst_type, rhs, force) && pointer_set_contains(visited->my_stmts, def_stmt))
122869 + return def_stmt;
122870 +
122871 + if (lhs == CREATE_NEW_VAR)
122872 + lhs = create_new_var(dst_type);
122873 +
122874 + assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
122875 +
122876 + if (!gsi_end_p(*gsi)) {
122877 + location_t loc = gimple_location(gsi_stmt(*gsi));
122878 + gimple_set_location(assign, loc);
122879 + }
122880 +
122881 + gimple_assign_set_lhs(assign, make_ssa_name(lhs, assign));
122882 +
122883 + if (before)
122884 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
122885 + else
122886 + gsi_insert_after(gsi, assign, GSI_NEW_STMT);
122887 + update_stmt(assign);
122888 + return assign;
122889 +}
122890 +
122891 +bool is_size_overflow_type(const_tree var)
122892 +{
122893 + const char *name;
122894 + const_tree type_name, type;
122895 +
122896 + if (var == NULL_TREE)
122897 + return false;
122898 +
122899 + type = TREE_TYPE(var);
122900 + type_name = TYPE_NAME(type);
122901 + if (type_name == NULL_TREE)
122902 + return false;
122903 +
122904 + if (DECL_P(type_name))
122905 + name = DECL_NAME_POINTER(type_name);
122906 + else
122907 + name = IDENTIFIER_POINTER(type_name);
122908 +
122909 + if (!strncmp(name, "size_overflow_type", 18))
122910 + return true;
122911 + return false;
122912 +}
122913 +
122914 diff --git a/tools/gcc/size_overflow_plugin/remove_unnecessary_dup.c b/tools/gcc/size_overflow_plugin/remove_unnecessary_dup.c
122915 new file mode 100644
122916 index 0000000..7c9e6d1
122917 --- /dev/null
122918 +++ b/tools/gcc/size_overflow_plugin/remove_unnecessary_dup.c
122919 @@ -0,0 +1,138 @@
122920 +/*
122921 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
122922 + * Licensed under the GPL v2, or (at your option) v3
122923 + *
122924 + * Homepage:
122925 + * http://www.grsecurity.net/~ephox/overflow_plugin/
122926 + *
122927 + * Documentation:
122928 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
122929 + *
122930 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
122931 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
122932 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
122933 + *
122934 + * Usage:
122935 + * $ make
122936 + * $ make run
122937 + */
122938 +
122939 +#include "gcc-common.h"
122940 +#include "size_overflow.h"
122941 +
122942 +bool skip_expr_on_double_type(const_gimple stmt)
122943 +{
122944 + enum tree_code code = gimple_assign_rhs_code(stmt);
122945 +
122946 + switch (code) {
122947 + case RSHIFT_EXPR:
122948 + case TRUNC_DIV_EXPR:
122949 + case CEIL_DIV_EXPR:
122950 + case FLOOR_DIV_EXPR:
122951 + case ROUND_DIV_EXPR:
122952 + case EXACT_DIV_EXPR:
122953 + case RDIV_EXPR:
122954 + case TRUNC_MOD_EXPR:
122955 + case CEIL_MOD_EXPR:
122956 + case FLOOR_MOD_EXPR:
122957 + case ROUND_MOD_EXPR:
122958 + return true;
122959 + default:
122960 + return false;
122961 + }
122962 +}
122963 +
122964 +void create_up_and_down_cast(struct visited *visited, gimple use_stmt, tree orig_type, tree rhs)
122965 +{
122966 + const_tree orig_rhs1;
122967 + tree down_lhs, new_lhs, dup_type = TREE_TYPE(rhs);
122968 + gimple down_cast, up_cast;
122969 + gimple_stmt_iterator gsi = gsi_for_stmt(use_stmt);
122970 +
122971 + down_cast = build_cast_stmt(visited, orig_type, rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
122972 + down_lhs = gimple_assign_lhs(down_cast);
122973 +
122974 + gsi = gsi_for_stmt(use_stmt);
122975 + up_cast = build_cast_stmt(visited, dup_type, down_lhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
122976 + new_lhs = gimple_assign_lhs(up_cast);
122977 +
122978 + orig_rhs1 = gimple_assign_rhs1(use_stmt);
122979 + if (operand_equal_p(orig_rhs1, rhs, 0))
122980 + gimple_assign_set_rhs1(use_stmt, new_lhs);
122981 + else
122982 + gimple_assign_set_rhs2(use_stmt, new_lhs);
122983 + update_stmt(use_stmt);
122984 +
122985 + pointer_set_insert(visited->my_stmts, up_cast);
122986 + pointer_set_insert(visited->my_stmts, down_cast);
122987 + pointer_set_insert(visited->skip_expr_casts, up_cast);
122988 + pointer_set_insert(visited->skip_expr_casts, down_cast);
122989 +}
122990 +
122991 +static tree get_proper_unsigned_half_type(const_tree node)
122992 +{
122993 + tree new_type, type;
122994 +
122995 + gcc_assert(is_size_overflow_type(node));
122996 +
122997 + type = TREE_TYPE(node);
122998 + switch (TYPE_MODE(type)) {
122999 + case HImode:
123000 + new_type = unsigned_intQI_type_node;
123001 + break;
123002 + case SImode:
123003 + new_type = unsigned_intHI_type_node;
123004 + break;
123005 + case DImode:
123006 + new_type = unsigned_intSI_type_node;
123007 + break;
123008 + case TImode:
123009 + new_type = unsigned_intDI_type_node;
123010 + break;
123011 + default:
123012 + gcc_unreachable();
123013 + }
123014 +
123015 + if (TYPE_QUALS(type) != 0)
123016 + return build_qualified_type(new_type, TYPE_QUALS(type));
123017 + return new_type;
123018 +}
123019 +
123020 +static void insert_cast_rhs(struct visited *visited, gimple stmt, tree rhs)
123021 +{
123022 + tree type;
123023 +
123024 + if (rhs == NULL_TREE)
123025 + return;
123026 + if (!is_size_overflow_type(rhs))
123027 + return;
123028 +
123029 + type = get_proper_unsigned_half_type(rhs);
123030 + if (is_gimple_constant(rhs))
123031 + return;
123032 + create_up_and_down_cast(visited, stmt, type, rhs);
123033 +}
123034 +
123035 +static void insert_cast(struct visited *visited, gimple stmt, tree rhs)
123036 +{
123037 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode) && !is_size_overflow_type(rhs))
123038 + return;
123039 + gcc_assert(is_size_overflow_type(rhs));
123040 + insert_cast_rhs(visited, stmt, rhs);
123041 +}
123042 +
123043 +void insert_cast_expr(struct visited *visited, gimple stmt, enum intentional_overflow_type type)
123044 +{
123045 + tree rhs1, rhs2;
123046 +
123047 + if (type == NO_INTENTIONAL_OVERFLOW || type == RHS1_INTENTIONAL_OVERFLOW) {
123048 + rhs1 = gimple_assign_rhs1(stmt);
123049 + insert_cast(visited, stmt, rhs1);
123050 + }
123051 +
123052 + if (type == NO_INTENTIONAL_OVERFLOW || type == RHS2_INTENTIONAL_OVERFLOW) {
123053 + rhs2 = gimple_assign_rhs2(stmt);
123054 + insert_cast(visited, stmt, rhs2);
123055 + }
123056 +}
123057 +
123058 diff --git a/tools/gcc/size_overflow_plugin/size_overflow.h b/tools/gcc/size_overflow_plugin/size_overflow.h
123059 new file mode 100644
123060 index 0000000..e5b4e50
123061 --- /dev/null
123062 +++ b/tools/gcc/size_overflow_plugin/size_overflow.h
123063 @@ -0,0 +1,127 @@
123064 +#ifndef SIZE_OVERFLOW_H
123065 +#define SIZE_OVERFLOW_H
123066 +
123067 +#define CREATE_NEW_VAR NULL_TREE
123068 +#define CANNOT_FIND_ARG 32
123069 +#define MAX_PARAM 31
123070 +#define BEFORE_STMT true
123071 +#define AFTER_STMT false
123072 +
123073 +#define TURN_OFF_ASM_STR "# size_overflow MARK_TURN_OFF "
123074 +#define YES_ASM_STR "# size_overflow MARK_YES "
123075 +#define OK_ASM_STR "# size_overflow "
123076 +
123077 +enum mark {
123078 + MARK_NO, MARK_YES, MARK_NOT_INTENTIONAL, MARK_TURN_OFF
123079 +};
123080 +
123081 +enum intentional_overflow_type {
123082 + NO_INTENTIONAL_OVERFLOW, RHS1_INTENTIONAL_OVERFLOW, RHS2_INTENTIONAL_OVERFLOW
123083 +};
123084 +
123085 +struct visited {
123086 + struct pointer_set_t *stmts;
123087 + struct pointer_set_t *my_stmts;
123088 + struct pointer_set_t *skip_expr_casts;
123089 + struct pointer_set_t *no_cast_check;
123090 +};
123091 +
123092 +// size_overflow_plugin.c
123093 +extern tree report_size_overflow_decl;
123094 +extern tree size_overflow_type_HI;
123095 +extern tree size_overflow_type_SI;
123096 +extern tree size_overflow_type_DI;
123097 +extern tree size_overflow_type_TI;
123098 +
123099 +
123100 +// size_overflow_plugin_hash.c
123101 +struct size_overflow_hash {
123102 + const struct size_overflow_hash * const next;
123103 + const char * const name;
123104 + const unsigned int param;
123105 +};
123106 +
123107 +struct interesting_node {
123108 + struct interesting_node *next;
123109 + gimple first_stmt;
123110 + const_tree fndecl;
123111 + tree node;
123112 +#if BUILDING_GCC_VERSION <= 4007
123113 + VEC(tree, gc) *last_nodes;
123114 +#else
123115 + vec<tree, va_gc> *last_nodes;
123116 +#endif
123117 + unsigned int num;
123118 + enum mark intentional_attr_decl;
123119 + enum mark intentional_attr_cur_fndecl;
123120 + gimple intentional_mark_from_gimple;
123121 +};
123122 +
123123 +extern bool is_size_overflow_asm(const_gimple stmt);
123124 +extern unsigned int get_function_num(const_tree node, const_tree orig_fndecl);
123125 +extern unsigned int get_correct_arg_count(unsigned int argnum, const_tree fndecl);
123126 +extern bool is_missing_function(const_tree orig_fndecl, unsigned int num);
123127 +extern bool is_a_return_check(const_tree node);
123128 +extern const struct size_overflow_hash *get_function_hash(const_tree fndecl);
123129 +extern unsigned int find_arg_number_tree(const_tree arg, const_tree func);
123130 +
123131 +
123132 +// size_overflow_debug.c
123133 +extern struct opt_pass *make_dump_pass(void);
123134 +
123135 +
123136 +// intentional_overflow.c
123137 +extern enum mark get_intentional_attr_type(const_tree node);
123138 +extern bool is_size_overflow_intentional_asm_yes(const_gimple stmt);
123139 +extern bool is_size_overflow_intentional_asm_turn_off(const_gimple stmt);
123140 +extern bool is_end_intentional_intentional_attr(const_tree decl, unsigned int argnum);
123141 +extern bool is_yes_intentional_attr(const_tree decl, unsigned int argnum);
123142 +extern bool is_turn_off_intentional_attr(const_tree decl);
123143 +extern void print_missing_intentional(enum mark callee_attr, enum mark caller_attr, const_tree decl, unsigned int argnum);
123144 +extern void check_intentional_attribute_ipa(struct interesting_node *cur_node);
123145 +extern bool is_a_cast_and_const_overflow(const_tree no_const_rhs);
123146 +extern bool is_const_plus_unsigned_signed_truncation(const_tree lhs);
123147 +extern bool is_a_constant_overflow(const_gimple stmt, const_tree rhs);
123148 +extern tree handle_intentional_overflow(struct visited *visited, struct cgraph_node *caller_node, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs2);
123149 +extern tree handle_integer_truncation(struct visited *visited, struct cgraph_node *caller_node, const_tree lhs);
123150 +extern bool is_a_neg_overflow(const_gimple stmt, const_tree rhs);
123151 +extern enum intentional_overflow_type add_mul_intentional_overflow(const_gimple def_stmt);
123152 +extern void unsigned_signed_cast_intentional_overflow(struct visited *visited, gimple stmt);
123153 +
123154 +
123155 +// insert_size_overflow_check_ipa.c
123156 +extern unsigned int search_function(void);
123157 +extern unsigned int call_count;
123158 +extern struct opt_pass *make_insert_size_overflow_check(void);
123159 +extern const_tree get_interesting_orig_fndecl(const_gimple stmt, unsigned int argnum);
123160 +
123161 +
123162 +// insert_size_overflow_asm.c
123163 +extern struct opt_pass *make_insert_size_overflow_asm_pass(void);
123164 +
123165 +
123166 +// misc.c
123167 +extern void set_current_function_decl(tree fndecl);
123168 +extern void unset_current_function_decl(void);
123169 +extern gimple get_def_stmt(const_tree node);
123170 +extern tree create_new_var(tree type);
123171 +extern gimple build_cast_stmt(struct visited *visited, tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before, bool force);
123172 +extern bool skip_types(const_tree var);
123173 +extern tree cast_a_tree(tree type, tree var);
123174 +extern bool is_size_overflow_type(const_tree var);
123175 +
123176 +
123177 +// insert_size_overflow_check_core.c
123178 +extern tree expand(struct visited *visited, struct cgraph_node *caller_node, tree lhs);
123179 +extern void check_size_overflow(struct cgraph_node *caller_node, gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before);
123180 +extern tree dup_assign(struct visited *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3);
123181 +extern tree create_assign(struct visited *visited, gimple oldstmt, tree rhs1, bool before);
123182 +
123183 +
123184 +// remove_unnecessary_dup.c
123185 +extern struct opt_pass *make_remove_unnecessary_dup_pass(void);
123186 +extern void insert_cast_expr(struct visited *visited, gimple stmt, enum intentional_overflow_type type);
123187 +extern bool skip_expr_on_double_type(const_gimple stmt);
123188 +extern void create_up_and_down_cast(struct visited *visited, gimple use_stmt, tree orig_type, tree rhs);
123189 +
123190 +#endif
123191 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_debug.c b/tools/gcc/size_overflow_plugin/size_overflow_debug.c
123192 new file mode 100644
123193 index 0000000..4378111
123194 --- /dev/null
123195 +++ b/tools/gcc/size_overflow_plugin/size_overflow_debug.c
123196 @@ -0,0 +1,116 @@
123197 +/*
123198 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
123199 + * Licensed under the GPL v2, or (at your option) v3
123200 + *
123201 + * Homepage:
123202 + * http://www.grsecurity.net/~ephox/overflow_plugin/
123203 + *
123204 + * Documentation:
123205 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
123206 + *
123207 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
123208 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
123209 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
123210 + *
123211 + * Usage:
123212 + * $ make
123213 + * $ make run
123214 + */
123215 +
123216 +#include "gcc-common.h"
123217 +
123218 +static unsigned int dump_functions(void)
123219 +{
123220 + struct cgraph_node *node;
123221 +
123222 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
123223 + basic_block bb;
123224 +
123225 + push_cfun(DECL_STRUCT_FUNCTION(NODE_DECL(node)));
123226 + current_function_decl = NODE_DECL(node);
123227 +
123228 + fprintf(stderr, "-----------------------------------------\n%s\n-----------------------------------------\n", DECL_NAME_POINTER(current_function_decl));
123229 +
123230 + FOR_ALL_BB_FN(bb, cfun) {
123231 + gimple_stmt_iterator si;
123232 +
123233 + fprintf(stderr, "<bb %u>:\n", bb->index);
123234 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
123235 + debug_gimple_stmt(gsi_stmt(si));
123236 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
123237 + debug_gimple_stmt(gsi_stmt(si));
123238 + fprintf(stderr, "\n");
123239 + }
123240 +
123241 + fprintf(stderr, "-------------------------------------------------------------------------\n");
123242 +
123243 + pop_cfun();
123244 + current_function_decl = NULL_TREE;
123245 + }
123246 +
123247 + fprintf(stderr, "###############################################################################\n");
123248 +
123249 + return 0;
123250 +}
123251 +
123252 +#if BUILDING_GCC_VERSION >= 4009
123253 +static const struct pass_data dump_pass_data = {
123254 +#else
123255 +static struct ipa_opt_pass_d dump_pass = {
123256 + .pass = {
123257 +#endif
123258 + .type = SIMPLE_IPA_PASS,
123259 + .name = "dump",
123260 +#if BUILDING_GCC_VERSION >= 4008
123261 + .optinfo_flags = OPTGROUP_NONE,
123262 +#endif
123263 +#if BUILDING_GCC_VERSION >= 4009
123264 + .has_gate = false,
123265 + .has_execute = true,
123266 +#else
123267 + .gate = NULL,
123268 + .execute = dump_functions,
123269 + .sub = NULL,
123270 + .next = NULL,
123271 + .static_pass_number = 0,
123272 +#endif
123273 + .tv_id = TV_NONE,
123274 + .properties_required = 0,
123275 + .properties_provided = 0,
123276 + .properties_destroyed = 0,
123277 + .todo_flags_start = 0,
123278 + .todo_flags_finish = 0,
123279 +#if BUILDING_GCC_VERSION < 4009
123280 + },
123281 + .generate_summary = NULL,
123282 + .write_summary = NULL,
123283 + .read_summary = NULL,
123284 +#if BUILDING_GCC_VERSION >= 4006
123285 + .write_optimization_summary = NULL,
123286 + .read_optimization_summary = NULL,
123287 +#endif
123288 + .stmt_fixup = NULL,
123289 + .function_transform_todo_flags_start = 0,
123290 + .function_transform = NULL,
123291 + .variable_transform = NULL,
123292 +#endif
123293 +};
123294 +
123295 +#if BUILDING_GCC_VERSION >= 4009
123296 +namespace {
123297 +class dump_pass : public ipa_opt_pass_d {
123298 +public:
123299 + dump_pass() : ipa_opt_pass_d(dump_pass_data, g, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL) {}
123300 + unsigned int execute() { return dump_functions(); }
123301 +};
123302 +}
123303 +#endif
123304 +
123305 +struct opt_pass *make_dump_pass(void)
123306 +{
123307 +#if BUILDING_GCC_VERSION >= 4009
123308 + return new dump_pass();
123309 +#else
123310 + return &dump_pass.pass;
123311 +#endif
123312 +}
123313 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_hash.data b/tools/gcc/size_overflow_plugin/size_overflow_hash.data
123314 new file mode 100644
123315 index 0000000..b565921
123316 --- /dev/null
123317 +++ b/tools/gcc/size_overflow_plugin/size_overflow_hash.data
123318 @@ -0,0 +1,5510 @@
123319 +intel_fake_agp_alloc_by_type_1 intel_fake_agp_alloc_by_type 1 1 NULL
123320 +storvsc_connect_to_vsp_22 storvsc_connect_to_vsp 2 22 NULL
123321 +compat_sock_setsockopt_23 compat_sock_setsockopt 5 23 NULL
123322 +carl9170_alloc_27 carl9170_alloc 1 27 NULL
123323 +sel_read_policyvers_55 sel_read_policyvers 3 55 NULL nohasharray
123324 +padzero_55 padzero 1 55 &sel_read_policyvers_55
123325 +cfg80211_disconnected_57 cfg80211_disconnected 4 57 NULL
123326 +__skb_to_sgvec_72 __skb_to_sgvec 0 72 NULL
123327 +snd_korg1212_copy_to_92 snd_korg1212_copy_to 6 92 NULL
123328 +load_msg_95 load_msg 2 95 NULL
123329 +ipath_verbs_send_117 ipath_verbs_send 5-3 117 NULL
123330 +init_q_132 init_q 4 132 NULL
123331 +memstick_alloc_host_142 memstick_alloc_host 1 142 NULL
123332 +hva_to_gfn_memslot_149 hva_to_gfn_memslot 0-1 149 NULL
123333 +tracing_trace_options_write_153 tracing_trace_options_write 3 153 NULL nohasharray
123334 +ext4_ext_get_actual_len_153 ext4_ext_get_actual_len 0 153 &tracing_trace_options_write_153
123335 +xfs_buf_item_get_format_189 xfs_buf_item_get_format 2 189 NULL
123336 +iscsi_session_setup_196 iscsi_session_setup 4-5 196 NULL
123337 +obd_proc_jobid_var_seq_write_199 obd_proc_jobid_var_seq_write 3 199 NULL
123338 +ll_xattr_cache_seq_write_250 ll_xattr_cache_seq_write 3 250 NULL
123339 +br_port_info_size_268 br_port_info_size 0 268 NULL
123340 +read_file_war_stats_292 read_file_war_stats 3 292 NULL
123341 +SYSC_connect_304 SYSC_connect 3 304 NULL
123342 +syslog_print_307 syslog_print 2 307 NULL
123343 +dn_setsockopt_314 dn_setsockopt 5 314 NULL
123344 +mlx5_core_access_reg_361 mlx5_core_access_reg 3-5 361 NULL
123345 +aio_read_events_ring_410 aio_read_events_ring 3 410 NULL
123346 +lbs_rdmac_read_418 lbs_rdmac_read 3 418 NULL
123347 +snd_ca0106_ptr_read_467 snd_ca0106_ptr_read 0 467 NULL
123348 +cfs_trace_set_debug_mb_usrstr_486 cfs_trace_set_debug_mb_usrstr 2 486 NULL
123349 +nvme_trans_modesel_data_488 nvme_trans_modesel_data 4 488 NULL
123350 +iwl_dbgfs_protection_mode_write_502 iwl_dbgfs_protection_mode_write 3 502 NULL
123351 +rx_rx_defrag_end_read_505 rx_rx_defrag_end_read 3 505 NULL
123352 +ocfs2_validate_meta_ecc_bhs_527 ocfs2_validate_meta_ecc_bhs 0 527 NULL
123353 +zlib_deflate_workspacesize_537 zlib_deflate_workspacesize 0-1-2 537 NULL
123354 +iwl_dbgfs_wowlan_sram_read_540 iwl_dbgfs_wowlan_sram_read 3 540 NULL
123355 +sco_sock_setsockopt_552 sco_sock_setsockopt 5 552 NULL
123356 +snd_aw2_saa7146_get_hw_ptr_playback_558 snd_aw2_saa7146_get_hw_ptr_playback 0 558 NULL
123357 +dev_hard_header_565 dev_hard_header 0 565 NULL nohasharray
123358 +start_isoc_chain_565 start_isoc_chain 2 565 &dev_hard_header_565
123359 +smk_write_load_self2_591 smk_write_load_self2 3 591 NULL
123360 +btrfs_stack_file_extent_offset_607 btrfs_stack_file_extent_offset 0 607 NULL
123361 +ni_gpct_device_construct_610 ni_gpct_device_construct 5 610 NULL
123362 +fuse_request_alloc_nofs_617 fuse_request_alloc_nofs 1 617 NULL
123363 +ptlrpc_lprocfs_nrs_seq_write_621 ptlrpc_lprocfs_nrs_seq_write 3 621 NULL
123364 +viafb_dfpl_proc_write_627 viafb_dfpl_proc_write 3 627 NULL
123365 +ceph_osdc_new_request_635 ceph_osdc_new_request 6 635 NULL
123366 +cfs_hash_bkt_size_643 cfs_hash_bkt_size 0 643 NULL
123367 +unlink_queued_645 unlink_queued 4 645 NULL
123368 +dtim_interval_read_654 dtim_interval_read 3 654 NULL
123369 +mem_rx_free_mem_blks_read_675 mem_rx_free_mem_blks_read 3 675 NULL
123370 +persistent_ram_vmap_709 persistent_ram_vmap 2-1 709 NULL
123371 +sctp_setsockopt_peer_addr_params_734 sctp_setsockopt_peer_addr_params 3 734 NULL
123372 +dvb_video_write_754 dvb_video_write 3 754 NULL
123373 +cfs_trace_allocate_string_buffer_781 cfs_trace_allocate_string_buffer 2 781 NULL
123374 +ath6kl_disconnect_timeout_write_794 ath6kl_disconnect_timeout_write 3 794 NULL
123375 +if_writecmd_815 if_writecmd 2 815 NULL
123376 +aac_change_queue_depth_825 aac_change_queue_depth 2 825 NULL
123377 +error_state_read_859 error_state_read 6 859 NULL
123378 +o2net_send_message_vec_879 o2net_send_message_vec 4 879 NULL nohasharray
123379 +iwl_dbgfs_fh_reg_read_879 iwl_dbgfs_fh_reg_read 3 879 &o2net_send_message_vec_879
123380 +snd_pcm_action_single_905 snd_pcm_action_single 0 905 NULL
123381 +carl9170_cmd_buf_950 carl9170_cmd_buf 3 950 NULL
123382 +__nodes_weight_956 __nodes_weight 0 956 NULL
123383 +usnic_ib_qp_grp_dump_hdr_989 usnic_ib_qp_grp_dump_hdr 2 989 NULL
123384 +smk_write_cipso2_1021 smk_write_cipso2 3 1021 NULL
123385 +gigaset_initdriver_1060 gigaset_initdriver 2 1060 NULL
123386 +mce_request_packet_1073 mce_request_packet 3 1073 NULL
123387 +agp_create_memory_1075 agp_create_memory 1 1075 NULL
123388 +_scsih_adjust_queue_depth_1083 _scsih_adjust_queue_depth 2 1083 NULL
123389 +llcp_sock_sendmsg_1092 llcp_sock_sendmsg 4 1092 NULL
123390 +nfs4_init_nonuniform_client_string_1097 nfs4_init_nonuniform_client_string 3 1097 NULL
123391 +cfg80211_report_obss_beacon_1133 cfg80211_report_obss_beacon 3 1133 NULL
123392 +i2400m_rx_ctl_1157 i2400m_rx_ctl 4 1157 NULL
123393 +ipc_alloc_1192 ipc_alloc 1 1192 NULL
123394 +ib_create_send_mad_1196 ib_create_send_mad 5 1196 NULL
123395 +pstore_ftrace_knob_write_1198 pstore_ftrace_knob_write 3 1198 NULL
123396 +i2400m_rx_ctl_ack_1199 i2400m_rx_ctl_ack 3 1199 NULL
123397 +dgrp_dpa_read_1204 dgrp_dpa_read 3 1204 NULL
123398 +i2cdev_read_1206 i2cdev_read 3 1206 NULL
123399 +lov_ost_pool_init_1215 lov_ost_pool_init 2 1215 NULL
123400 +kernfs_file_direct_read_1238 kernfs_file_direct_read 3 1238 NULL
123401 +acpi_battery_write_alarm_1240 acpi_battery_write_alarm 3 1240 NULL
123402 +drm_primary_helper_create_plane_1262 drm_primary_helper_create_plane 3 1262 NULL
123403 +ocfs2_extend_file_1266 ocfs2_extend_file 3 1266 NULL
123404 +qla4xxx_change_queue_depth_1268 qla4xxx_change_queue_depth 2 1268 NULL
123405 +ioctl_private_iw_point_1273 ioctl_private_iw_point 7 1273 NULL
123406 +SyS_flistxattr_1287 SyS_flistxattr 3 1287 NULL
123407 +tx_frag_in_process_called_read_1290 tx_frag_in_process_called_read 3 1290 NULL
123408 +posix_acl_xattr_set_1301 posix_acl_xattr_set 4 1301 NULL
123409 +ffs_1322 ffs 0 1322 NULL
123410 +qlcnic_pci_sriov_configure_1327 qlcnic_pci_sriov_configure 2 1327 NULL
123411 +btrfs_submit_compressed_write_1347 btrfs_submit_compressed_write 5 1347 NULL
123412 +snd_pcm_lib_write1_1358 snd_pcm_lib_write1 0-3 1358 NULL
123413 +ipx_sendmsg_1362 ipx_sendmsg 4 1362 NULL
123414 +fw_stats_raw_read_1369 fw_stats_raw_read 3 1369 NULL
123415 +ocfs2_prepare_inode_for_write_1372 ocfs2_prepare_inode_for_write 3 1372 NULL
123416 +xpcs_reg_addr_read_1381 xpcs_reg_addr_read 3 1381 NULL
123417 +sctp_setsockopt_initmsg_1383 sctp_setsockopt_initmsg 3 1383 NULL
123418 +do_msgsnd_1387 do_msgsnd 4 1387 NULL
123419 +SYSC_io_getevents_1392 SYSC_io_getevents 3 1392 NULL
123420 +cfs_trace_copyout_string_1416 cfs_trace_copyout_string 2 1416 NULL
123421 +init_rs_internal_1436 init_rs_internal 1 1436 NULL
123422 +stack_max_size_read_1445 stack_max_size_read 3 1445 NULL
123423 +tx_queue_len_read_1463 tx_queue_len_read 3 1463 NULL
123424 +xprt_alloc_1475 xprt_alloc 2 1475 NULL
123425 +SYSC_syslog_1477 SYSC_syslog 3 1477 NULL
123426 +sta_num_ps_buf_frames_read_1488 sta_num_ps_buf_frames_read 3 1488 NULL
123427 +fpregs_set_1497 fpregs_set 4 1497 NULL
123428 +tomoyo_round2_1518 tomoyo_round2 0 1518 NULL
123429 +alloc_perm_bits_1532 alloc_perm_bits 2 1532 NULL
123430 +ath6kl_init_get_fwcaps_1557 ath6kl_init_get_fwcaps 3 1557 NULL
123431 +ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime_1589 ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 NULL
123432 +packet_buffer_init_1607 packet_buffer_init 2 1607 NULL
123433 +btmrvl_hscmd_read_1614 btmrvl_hscmd_read 3 1614 NULL
123434 +v9fs_fid_xattr_get_1618 v9fs_fid_xattr_get 0 1618 NULL
123435 +ikconfig_read_current_1658 ikconfig_read_current 3 1658 NULL
123436 +mei_cl_recv_1665 mei_cl_recv 3 1665 NULL
123437 +rmap_add_1677 rmap_add 3 1677 NULL
123438 +configfs_read_file_1683 configfs_read_file 3 1683 NULL
123439 +iwl_dbgfs_d0i3_refs_read_1705 iwl_dbgfs_d0i3_refs_read 3 1705 NULL
123440 +pdu_write_u_1710 pdu_write_u 3 1710 NULL
123441 +coda_psdev_write_1711 coda_psdev_write 3 1711 NULL
123442 +btrfs_dir_data_len_1714 btrfs_dir_data_len 0 1714 NULL
123443 +dev_irnet_read_1741 dev_irnet_read 3 1741 NULL
123444 +usb_ep_align_maybe_1743 usb_ep_align_maybe 0-3 1743 NULL
123445 +tx_frag_called_read_1748 tx_frag_called_read 3 1748 NULL
123446 +cosa_write_1774 cosa_write 3 1774 NULL
123447 +fcoe_ctlr_device_add_1793 fcoe_ctlr_device_add 3 1793 NULL
123448 +__nodelist_scnprintf_1815 __nodelist_scnprintf 2 1815 NULL
123449 +sb_issue_zeroout_1884 sb_issue_zeroout 3 1884 NULL
123450 +rx_defrag_called_read_1897 rx_defrag_called_read 3 1897 NULL
123451 +nfs_parse_server_name_1899 nfs_parse_server_name 2 1899 NULL
123452 +SyS_add_key_1900 SyS_add_key 4 1900 NULL
123453 +uhid_char_read_1920 uhid_char_read 3 1920 NULL
123454 +tx_tx_retry_data_read_1926 tx_tx_retry_data_read 3 1926 NULL
123455 +bdev_erase_1933 bdev_erase 3 1933 NULL
123456 +ext3_fiemap_1936 ext3_fiemap 4 1936 NULL
123457 +cyttsp_probe_1940 cyttsp_probe 4 1940 NULL
123458 +ieee80211_if_fmt_dot11MeshConfirmTimeout_1945 ieee80211_if_fmt_dot11MeshConfirmTimeout 3 1945 NULL
123459 +ivtv_v4l2_read_1964 ivtv_v4l2_read 3 1964 NULL
123460 +sel_read_avc_hash_stats_1984 sel_read_avc_hash_stats 3 1984 NULL
123461 +gpio_power_write_1991 gpio_power_write 3 1991 NULL
123462 +__alloc_bootmem_node_1992 __alloc_bootmem_node 2 1992 NULL
123463 +rx_rx_defrag_read_2010 rx_rx_defrag_read 3 2010 NULL
123464 +ocfs2_global_qinit_alloc_2018 ocfs2_global_qinit_alloc 0 2018 NULL
123465 +write_flush_pipefs_2021 write_flush_pipefs 3 2021 NULL
123466 +BcmCopySection_2035 BcmCopySection 5 2035 NULL
123467 +ath6kl_fwlog_mask_read_2050 ath6kl_fwlog_mask_read 3 2050 NULL
123468 +ocfs2_expand_inline_dir_2063 ocfs2_expand_inline_dir 3 2063 NULL
123469 +__generic_copy_from_user_intel_2073 __generic_copy_from_user_intel 0-3 2073 NULL
123470 +diva_set_driver_dbg_mask_2077 diva_set_driver_dbg_mask 0 2077 NULL
123471 +iwl_dbgfs_current_sleep_command_read_2081 iwl_dbgfs_current_sleep_command_read 3 2081 NULL
123472 +xgmac_reg_value_read_2095 xgmac_reg_value_read 3 2095 NULL
123473 +idetape_chrdev_read_2097 idetape_chrdev_read 3 2097 NULL
123474 +__set_print_fmt_2106 __set_print_fmt 0 2106 NULL
123475 +iwl_dbgfs_log_event_read_2107 iwl_dbgfs_log_event_read 3 2107 NULL
123476 +ecryptfs_encrypt_and_encode_filename_2109 ecryptfs_encrypt_and_encode_filename 6 2109 NULL
123477 +btrfs_file_extent_inline_len_2116 btrfs_file_extent_inline_len 0 2116 NULL
123478 +enable_read_2117 enable_read 3 2117 NULL
123479 +pcf50633_write_block_2124 pcf50633_write_block 2-3 2124 NULL
123480 +check_load_and_stores_2143 check_load_and_stores 2 2143 NULL
123481 +iov_iter_count_2152 iov_iter_count 0 2152 NULL
123482 +__copy_to_user_ll_2157 __copy_to_user_ll 0-3 2157 NULL
123483 +_ore_get_io_state_2166 _ore_get_io_state 3-4-5 2166 NULL
123484 +bio_integrity_alloc_2194 bio_integrity_alloc 3 2194 NULL
123485 +picolcd_debug_reset_write_2195 picolcd_debug_reset_write 3 2195 NULL
123486 +u32_array_read_2219 u32_array_read 3 2219 NULL nohasharray
123487 +mei_dbgfs_read_meclients_2219 mei_dbgfs_read_meclients 3 2219 &u32_array_read_2219
123488 +ieee80211_if_read_dot11MeshHWMPRannInterval_2249 ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 NULL
123489 +netlbl_secattr_catmap_walk_2255 netlbl_secattr_catmap_walk 0-2 2255 NULL
123490 +sel_write_avc_cache_threshold_2256 sel_write_avc_cache_threshold 3 2256 NULL
123491 +do_update_counters_2259 do_update_counters 4 2259 NULL
123492 +ath6kl_wmi_bssinfo_event_rx_2275 ath6kl_wmi_bssinfo_event_rx 3 2275 NULL
123493 +debug_debug5_read_2291 debug_debug5_read 3 2291 NULL
123494 +sr_read_cmd_2299 sr_read_cmd 5 2299 NULL
123495 +kvm_clear_guest_page_2308 kvm_clear_guest_page 4 2308 NULL
123496 +intel_sdvo_set_value_2311 intel_sdvo_set_value 4 2311 NULL
123497 +hfsplus_find_init_2318 hfsplus_find_init 0 2318 NULL nohasharray
123498 +picolcd_fb_write_2318 picolcd_fb_write 3 2318 &hfsplus_find_init_2318
123499 +dice_hwdep_read_2326 dice_hwdep_read 3 2326 NULL
123500 +__erst_read_to_erange_2341 __erst_read_to_erange 0 2341 NULL
123501 +zr364xx_read_2354 zr364xx_read 3 2354 NULL
123502 +viafb_iga2_odev_proc_write_2363 viafb_iga2_odev_proc_write 3 2363 NULL
123503 +rose_recvmsg_2368 rose_recvmsg 4 2368 NULL nohasharray
123504 +xfs_buf_map_from_irec_2368 xfs_buf_map_from_irec 5 2368 &rose_recvmsg_2368
123505 +il_dbgfs_sensitivity_read_2370 il_dbgfs_sensitivity_read 3 2370 NULL
123506 +rxpipe_rx_prep_beacon_drop_read_2403 rxpipe_rx_prep_beacon_drop_read 3 2403 NULL
123507 +isdn_v110_open_2418 isdn_v110_open 3 2418 NULL
123508 +raid1_size_2419 raid1_size 0-2 2419 NULL
123509 +b43legacy_debugfs_read_2473 b43legacy_debugfs_read 3 2473 NULL
123510 +wiphy_new_2482 wiphy_new 2 2482 NULL
123511 +bio_alloc_bioset_2484 bio_alloc_bioset 2 2484 NULL
123512 +squashfs_read_fragment_index_table_2506 squashfs_read_fragment_index_table 4 2506 NULL
123513 +v9fs_cached_file_read_2514 v9fs_cached_file_read 3 2514 NULL
123514 +ext4_get_inode_loc_2516 ext4_get_inode_loc 0 2516 NULL
123515 +batadv_tvlv_container_list_size_2524 batadv_tvlv_container_list_size 0 2524 NULL
123516 +smk_write_syslog_2529 smk_write_syslog 3 2529 NULL
123517 +__ceph_setxattr_2532 __ceph_setxattr 4 2532 NULL
123518 +gspca_dev_probe_2570 gspca_dev_probe 4 2570 NULL
123519 +pcm_sanity_check_2574 pcm_sanity_check 0 2574 NULL
123520 +mdc_max_rpcs_in_flight_seq_write_2594 mdc_max_rpcs_in_flight_seq_write 3 2594 NULL
123521 +slot_bytes_2609 slot_bytes 0 2609 NULL
123522 +smk_write_logging_2618 smk_write_logging 3 2618 NULL
123523 +switch_status_2629 switch_status 5 2629 NULL
123524 +_proc_do_string_2632 _proc_do_string 2 2632 NULL
123525 +tcp_xmit_size_goal_2661 tcp_xmit_size_goal 2 2661 NULL
123526 +osc_build_ppga_2670 osc_build_ppga 2 2670 NULL
123527 +ffs_ep0_read_2672 ffs_ep0_read 3 2672 NULL
123528 +oti6858_write_2692 oti6858_write 4 2692 NULL
123529 +nfc_llcp_send_ui_frame_2702 nfc_llcp_send_ui_frame 5 2702 NULL
123530 +memcpy_fromiovecend_2707 memcpy_fromiovecend 3-4 2707 NULL
123531 +lprocfs_stats_counter_size_2708 lprocfs_stats_counter_size 0 2708 NULL
123532 +xfs_readdir_2767 xfs_readdir 3 2767 NULL
123533 +fsl_edma_alloc_desc_2769 fsl_edma_alloc_desc 2 2769 NULL
123534 +mon_bin_ioctl_2771 mon_bin_ioctl 3 2771 NULL
123535 +set_msr_hyperv_pw_2785 set_msr_hyperv_pw 3 2785 NULL
123536 +iwl_dbgfs_clear_ucode_statistics_write_2804 iwl_dbgfs_clear_ucode_statistics_write 3 2804 NULL
123537 +sel_read_enforce_2828 sel_read_enforce 3 2828 NULL
123538 +vb2_dc_get_userptr_2829 vb2_dc_get_userptr 2-3 2829 NULL
123539 +sock_create_2838 sock_create 0 2838 NULL
123540 +wait_for_avail_2847 wait_for_avail 0 2847 NULL
123541 +sfq_alloc_2861 sfq_alloc 1 2861 NULL
123542 +irnet_ctrl_read_2863 irnet_ctrl_read 4 2863 NULL
123543 +move_addr_to_user_2868 move_addr_to_user 2 2868 NULL
123544 +nla_padlen_2883 nla_padlen 1 2883 NULL
123545 +cmm_write_2896 cmm_write 3 2896 NULL
123546 +osc_import_seq_write_2923 osc_import_seq_write 3 2923 NULL
123547 +xfs_trans_get_buf_map_2927 xfs_trans_get_buf_map 4 2927 NULL
123548 +nes_read_indexed_2946 nes_read_indexed 0 2946 NULL
123549 +tm6000_i2c_recv_regs16_2949 tm6000_i2c_recv_regs16 5 2949 NULL
123550 +i40e_dbg_prep_dump_buf_2951 i40e_dbg_prep_dump_buf 2 2951 NULL
123551 +set_fast_connectable_2952 set_fast_connectable 4 2952 NULL
123552 +free_area_init_core_2962 free_area_init_core 2-3 2962 NULL
123553 +bio_setup_sector_2970 bio_setup_sector 3 2970 NULL
123554 +do_strnlen_user_2976 do_strnlen_user 0-2 2976 NULL
123555 +p9_nr_pages_2992 p9_nr_pages 0-2 2992 NULL
123556 +lov_stripetype_seq_write_3013 lov_stripetype_seq_write 3 3013 NULL
123557 +do_dmabuf_dirty_sou_3017 do_dmabuf_dirty_sou 7 3017 NULL
123558 +depth_write_3021 depth_write 3 3021 NULL
123559 +snd_azf3328_codec_inl_3022 snd_azf3328_codec_inl 0 3022 NULL
123560 +nvme_split_and_submit_3027 nvme_split_and_submit 3 3027 NULL
123561 +kvm_unmap_hva_3028 kvm_unmap_hva 2 3028 NULL
123562 +xfrm_dst_alloc_copy_3034 xfrm_dst_alloc_copy 3 3034 NULL
123563 +lpfc_idiag_mbxacc_write_3038 lpfc_idiag_mbxacc_write 3 3038 NULL nohasharray
123564 +iwl_dbgfs_sleep_level_override_read_3038 iwl_dbgfs_sleep_level_override_read 3 3038 &lpfc_idiag_mbxacc_write_3038
123565 +nr_free_buffer_pages_3044 nr_free_buffer_pages 0 3044 NULL
123566 +il3945_ucode_rx_stats_read_3048 il3945_ucode_rx_stats_read 3 3048 NULL
123567 +qp_alloc_ppn_set_3068 qp_alloc_ppn_set 2-4 3068 NULL
123568 +__blk_end_bidi_request_3070 __blk_end_bidi_request 3-4 3070 NULL
123569 +dac960_user_command_proc_write_3071 dac960_user_command_proc_write 3 3071 NULL nohasharray
123570 +hfsplus_asc2uni_3071 hfsplus_asc2uni 0 3071 &dac960_user_command_proc_write_3071
123571 +read_file_antenna_diversity_3077 read_file_antenna_diversity 3 3077 NULL
123572 +ttusb2_msg_3100 ttusb2_msg 4 3100 NULL
123573 +rb_alloc_3102 rb_alloc 1 3102 NULL
123574 +simple_write_to_buffer_3122 simple_write_to_buffer 2-5 3122 NULL
123575 +print_time_3132 print_time 0 3132 NULL
123576 +fill_write_buffer_3142 fill_write_buffer 3 3142 NULL
123577 +CIFSSMBSetPosixACL_3154 CIFSSMBSetPosixACL 5 3154 NULL
123578 +uv_num_possible_blades_3177 uv_num_possible_blades 0 3177 NULL
123579 +uinput_ioctl_handler_3181 uinput_ioctl_handler 2 3181 NULL nohasharray
123580 +uvc_video_stats_dump_3181 uvc_video_stats_dump 3 3181 &uinput_ioctl_handler_3181
123581 +compat_do_ip6t_set_ctl_3184 compat_do_ip6t_set_ctl 4 3184 NULL
123582 +mempool_create_node_3191 mempool_create_node 1 3191 NULL
123583 +alloc_context_3194 alloc_context 1 3194 NULL
123584 +shmem_pread_slow_3198 shmem_pread_slow 3-2 3198 NULL
123585 +codec_reg_write_file_3204 codec_reg_write_file 3 3204 NULL
123586 +SyS_sendto_3219 SyS_sendto 6 3219 NULL
123587 +btrfs_prealloc_file_range_3227 btrfs_prealloc_file_range 3 3227 NULL
123588 +do_read_log_to_user_3236 do_read_log_to_user 4 3236 NULL
123589 +ext3_xattr_find_entry_3237 ext3_xattr_find_entry 0 3237 NULL
123590 +key_key_read_3241 key_key_read 3 3241 NULL
123591 +__ilog2_u64_3284 __ilog2_u64 0 3284 NULL
123592 +ieee80211_if_write_beacon_loss_3296 ieee80211_if_write_beacon_loss 3 3296 NULL
123593 +__iovec_copy_from_user_inatomic_3314 __iovec_copy_from_user_inatomic 0-4-3 3314 NULL
123594 +_iwl_dbgfs_d3_sram_write_3315 _iwl_dbgfs_d3_sram_write 3 3315 NULL
123595 +dbDiscardAG_3322 dbDiscardAG 3 3322 NULL
123596 +tty_port_register_device_attr_3341 tty_port_register_device_attr 3 3341 NULL
123597 +il_dbgfs_interrupt_read_3351 il_dbgfs_interrupt_read 3 3351 NULL
123598 +gsm_control_rls_3353 gsm_control_rls 3 3353 NULL
123599 +scnprintf_3360 scnprintf 0-2 3360 NULL
123600 +sr_read_3366 sr_read 3 3366 NULL
123601 +mtdchar_writeoob_3393 mtdchar_writeoob 4 3393 NULL
123602 +isdn_readbchan_3401 isdn_readbchan 0-5 3401 NULL
123603 +mei_io_cb_alloc_resp_buf_3414 mei_io_cb_alloc_resp_buf 2 3414 NULL
123604 +pci_add_cap_save_buffer_3426 pci_add_cap_save_buffer 3 3426 NULL
123605 +crystalhd_create_dio_pool_3427 crystalhd_create_dio_pool 2 3427 NULL
123606 +SyS_msgsnd_3436 SyS_msgsnd 3 3436 NULL
123607 +softsynth_write_3455 softsynth_write 3 3455 NULL
123608 +snd_pcm_lib_readv_transfer_3464 snd_pcm_lib_readv_transfer 5-4-2 3464 NULL
123609 +security_context_to_sid_default_3492 security_context_to_sid_default 2 3492 NULL
123610 +xfrm_migrate_msgsize_3496 xfrm_migrate_msgsize 1 3496 NULL
123611 +mem_tx_free_mem_blks_read_3521 mem_tx_free_mem_blks_read 3 3521 NULL
123612 +SyS_semtimedop_3532 SyS_semtimedop 3 3532 NULL
123613 +SyS_readv_3539 SyS_readv 3 3539 NULL
123614 +btrfs_dir_name_len_3549 btrfs_dir_name_len 0 3549 NULL
123615 +alloc_smp_resp_3566 alloc_smp_resp 1 3566 NULL
123616 +evtchn_read_3569 evtchn_read 3 3569 NULL
123617 +ll_track_ppid_seq_write_3582 ll_track_ppid_seq_write 3 3582 NULL
123618 +vc_resize_3585 vc_resize 3-2 3585 NULL
123619 +kvm_mmu_notifier_change_pte_3596 kvm_mmu_notifier_change_pte 3 3596 NULL
123620 +sctp_getsockopt_events_3607 sctp_getsockopt_events 2 3607 NULL
123621 +edac_mc_alloc_3611 edac_mc_alloc 4 3611 NULL
123622 +tx_tx_starts_read_3617 tx_tx_starts_read 3 3617 NULL
123623 +aligned_kmalloc_3628 aligned_kmalloc 1 3628 NULL
123624 +ath6kl_disconnect_timeout_read_3650 ath6kl_disconnect_timeout_read 3 3650 NULL
123625 +i915_compat_ioctl_3656 i915_compat_ioctl 2 3656 NULL
123626 +_iwl_dbgfs_tx_flush_write_3675 _iwl_dbgfs_tx_flush_write 3 3675 NULL
123627 +snd_m3_assp_read_3703 snd_m3_assp_read 0 3703 NULL
123628 +ci_ll_write_3740 ci_ll_write 4 3740 NULL
123629 +msm_otg_mode_write_3788 msm_otg_mode_write 3 3788 NULL
123630 +sctp_setsockopt_auth_key_3793 sctp_setsockopt_auth_key 3 3793 NULL
123631 +ncp_file_write_3813 ncp_file_write 3 3813 NULL
123632 +llc_ui_recvmsg_3826 llc_ui_recvmsg 4 3826 NULL
123633 +create_one_cdev_3852 create_one_cdev 2 3852 NULL
123634 +smk_read_onlycap_3855 smk_read_onlycap 3 3855 NULL
123635 +get_fd_set_3866 get_fd_set 1 3866 NULL
123636 +garp_attr_create_3883 garp_attr_create 3 3883 NULL
123637 +efivarfs_file_read_3893 efivarfs_file_read 3 3893 NULL
123638 +nvram_write_3894 nvram_write 3 3894 NULL
123639 +pipeline_pre_proc_swi_read_3898 pipeline_pre_proc_swi_read 3 3898 NULL
123640 +comedi_buf_read_n_available_3899 comedi_buf_read_n_available 0 3899 NULL
123641 +vcs_write_3910 vcs_write 3 3910 NULL
123642 +SyS_move_pages_3920 SyS_move_pages 2 3920 NULL
123643 +brcmf_debugfs_fws_stats_read_3947 brcmf_debugfs_fws_stats_read 3 3947 NULL
123644 +copy_from_user_atomic_iovec_3990 copy_from_user_atomic_iovec 0-4 3990 NULL
123645 +do_add_counters_3992 do_add_counters 3 3992 NULL
123646 +userspace_status_4004 userspace_status 4 4004 NULL
123647 +mei_write_4005 mei_write 3 4005 NULL nohasharray
123648 +xfs_check_block_4005 xfs_check_block 4 4005 &mei_write_4005
123649 +snd_hdsp_capture_copy_4011 snd_hdsp_capture_copy 5 4011 NULL
123650 +blk_end_request_4024 blk_end_request 3 4024 NULL
123651 +ext4_xattr_find_entry_4025 ext4_xattr_find_entry 0 4025 NULL
123652 +mtip_hw_read_registers_4037 mtip_hw_read_registers 3 4037 NULL
123653 +read_file_queues_4078 read_file_queues 3 4078 NULL
123654 +fbcon_do_set_font_4079 fbcon_do_set_font 2-3 4079 NULL
123655 +tm6000_read_4151 tm6000_read 3 4151 NULL
123656 +mpt_raid_phys_disk_get_num_paths_4155 mpt_raid_phys_disk_get_num_paths 0 4155 NULL
123657 +msg_bits_4158 msg_bits 0-3-4 4158 NULL
123658 +get_alua_req_4166 get_alua_req 3 4166 NULL
123659 +blk_dropped_read_4168 blk_dropped_read 3 4168 NULL
123660 +read_file_bool_4180 read_file_bool 3 4180 NULL
123661 +vring_new_virtqueue_4199 vring_new_virtqueue 2 4199 NULL
123662 +_osd_req_list_objects_4204 _osd_req_list_objects 6 4204 NULL
123663 +__snd_gf1_read_addr_4210 __snd_gf1_read_addr 0 4210 NULL
123664 +ath6kl_force_roam_write_4282 ath6kl_force_roam_write 3 4282 NULL
123665 +goldfish_audio_write_4284 goldfish_audio_write 3 4284 NULL
123666 +get_connectors_for_crtc_4291 get_connectors_for_crtc 0 4291 NULL
123667 +__usbnet_read_cmd_4299 __usbnet_read_cmd 7 4299 NULL
123668 +dvb_ringbuffer_pkt_read_user_4303 dvb_ringbuffer_pkt_read_user 2-3-5 4303 NULL
123669 +count_strings_4315 count_strings 0 4315 NULL
123670 +nouveau_fifo_create__4327 nouveau_fifo_create_ 5-6 4327 NULL
123671 +snd_rawmidi_kernel_read_4328 snd_rawmidi_kernel_read 3 4328 NULL
123672 +ima_eventdigest_init_common_4338 ima_eventdigest_init_common 2 4338 NULL
123673 +__copy_from_user_inatomic_4365 __copy_from_user_inatomic 0-3 4365 NULL
123674 +irda_sendmsg_4388 irda_sendmsg 4 4388 NULL
123675 +access_process_vm_4412 access_process_vm 0 4412 NULL nohasharray
123676 +cxacru_cm_get_array_4412 cxacru_cm_get_array 4 4412 &access_process_vm_4412
123677 +libfc_vport_create_4415 libfc_vport_create 2 4415 NULL
123678 +rtw_android_get_rssi_4421 rtw_android_get_rssi 0 4421 NULL
123679 +do_pages_stat_4437 do_pages_stat 2 4437 NULL
123680 +at76_set_card_command_4471 at76_set_card_command 4 4471 NULL
123681 +snd_seq_expand_var_event_4481 snd_seq_expand_var_event 0-5 4481 NULL
123682 +vmbus_establish_gpadl_4495 vmbus_establish_gpadl 3 4495 NULL
123683 +set_link_security_4502 set_link_security 4 4502 NULL
123684 +ll_max_readahead_per_file_mb_seq_write_4531 ll_max_readahead_per_file_mb_seq_write 3 4531 NULL
123685 +tty_register_device_4544 tty_register_device 2 4544 NULL
123686 +fsl_edma_prep_slave_sg_4555 fsl_edma_prep_slave_sg 3 4555 NULL
123687 +btrfs_file_extent_inline_item_len_4575 btrfs_file_extent_inline_item_len 0 4575 NULL
123688 +xfs_buf_get_maps_4581 xfs_buf_get_maps 2 4581 NULL
123689 +bch_alloc_4593 bch_alloc 1 4593 NULL
123690 +ll_rw_extents_stats_seq_write_4633 ll_rw_extents_stats_seq_write 3 4633 NULL
123691 +iwl_dbgfs_tx_queue_read_4635 iwl_dbgfs_tx_queue_read 3 4635 NULL
123692 +skb_add_data_nocache_4682 skb_add_data_nocache 4 4682 NULL
123693 +cx18_read_pos_4683 cx18_read_pos 3 4683 NULL
123694 +short_retry_limit_read_4687 short_retry_limit_read 3 4687 NULL
123695 +kone_receive_4690 kone_receive 4 4690 NULL
123696 +hash_netportnet6_expire_4702 hash_netportnet6_expire 4 4702 NULL
123697 +cxgbi_alloc_big_mem_4707 cxgbi_alloc_big_mem 1 4707 NULL
123698 +show_header_4722 show_header 3 4722 NULL nohasharray
123699 +ati_create_gatt_pages_4722 ati_create_gatt_pages 1 4722 &show_header_4722
123700 +ll_rw_offset_stats_seq_write_4736 ll_rw_offset_stats_seq_write 3 4736 NULL nohasharray
123701 +bitmap_startwrite_4736 bitmap_startwrite 2 4736 &ll_rw_offset_stats_seq_write_4736
123702 +lu_buf_alloc_4753 lu_buf_alloc 2 4753 NULL
123703 +pwr_rcvd_bcns_cnt_read_4774 pwr_rcvd_bcns_cnt_read 3 4774 NULL
123704 +create_subvol_4791 create_subvol 4 4791 NULL
123705 +ncp__vol2io_4804 ncp__vol2io 5 4804 NULL
123706 +C_SYSC_setsockopt_4806 C_SYSC_setsockopt 5 4806 NULL
123707 +repair_io_failure_4815 repair_io_failure 4-3 4815 NULL
123708 +gigaset_if_receive_4861 gigaset_if_receive 3 4861 NULL
123709 +key_tx_spec_read_4862 key_tx_spec_read 3 4862 NULL
123710 +ocfs2_defrag_extent_4873 ocfs2_defrag_extent 2 4873 NULL
123711 +hid_register_field_4874 hid_register_field 2-3 4874 NULL
123712 +vga_arb_read_4886 vga_arb_read 3 4886 NULL
123713 +ieee80211_if_fmt_ave_beacon_4941 ieee80211_if_fmt_ave_beacon 3 4941 NULL
123714 +compat_rawv6_setsockopt_4967 compat_rawv6_setsockopt 5 4967 NULL
123715 +ath10k_read_chip_id_4969 ath10k_read_chip_id 3 4969 NULL
123716 +skb_network_header_len_4971 skb_network_header_len 0 4971 NULL
123717 +ieee80211_if_fmt_dot11MeshHWMPconfirmationInterval_4976 ieee80211_if_fmt_dot11MeshHWMPconfirmationInterval 3 4976 NULL
123718 +compat_SyS_ipc_5000 compat_SyS_ipc 3 5000 NULL
123719 +do_mincore_5018 do_mincore 0-2-1 5018 NULL
123720 +cfg80211_rx_mgmt_5056 cfg80211_rx_mgmt 5 5056 NULL
123721 +ocfs2_check_range_for_holes_5066 ocfs2_check_range_for_holes 2-3 5066 NULL
123722 +snd_mixart_BA1_read_5082 snd_mixart_BA1_read 5 5082 NULL
123723 +snd_emu10k1_ptr20_read_5087 snd_emu10k1_ptr20_read 0 5087 NULL
123724 +kfifo_copy_from_user_5091 kfifo_copy_from_user 4-3-0 5091 NULL nohasharray
123725 +get_random_bytes_5091 get_random_bytes 2 5091 &kfifo_copy_from_user_5091 nohasharray
123726 +blk_rq_sectors_5091 blk_rq_sectors 0 5091 &get_random_bytes_5091
123727 +sound_write_5102 sound_write 3 5102 NULL
123728 +i40e_dbg_netdev_ops_write_5117 i40e_dbg_netdev_ops_write 3 5117 NULL
123729 +__uwb_addr_print_5161 __uwb_addr_print 2 5161 NULL
123730 +iwl_dbgfs_status_read_5171 iwl_dbgfs_status_read 3 5171 NULL
123731 +acpi_pcc_get_sqty_5176 acpi_pcc_get_sqty 0 5176 NULL
123732 +trf7970a_read_cont_5179 trf7970a_read_cont 4 5179 NULL
123733 +ppp_cp_parse_cr_5214 ppp_cp_parse_cr 4 5214 NULL
123734 +dwc2_hcd_urb_alloc_5217 dwc2_hcd_urb_alloc 2 5217 NULL
123735 +ath6kl_debug_roam_tbl_event_5224 ath6kl_debug_roam_tbl_event 3 5224 NULL
123736 +xgmac_reg_addr_read_5278 xgmac_reg_addr_read 3 5278 NULL
123737 +r592_write_fifo_pio_5315 r592_write_fifo_pio 3 5315 NULL
123738 +sbc_get_write_same_sectors_5317 sbc_get_write_same_sectors 0 5317 NULL
123739 +pwr_elp_enter_read_5324 pwr_elp_enter_read 3 5324 NULL
123740 +uinput_ioctl_5342 uinput_ioctl 2 5342 NULL
123741 +cq_free_res_5355 cq_free_res 5 5355 NULL
123742 +ps_pspoll_utilization_read_5361 ps_pspoll_utilization_read 3 5361 NULL
123743 +cciss_allocate_sg_chain_blocks_5368 cciss_allocate_sg_chain_blocks 3-2 5368 NULL
123744 +xfs_efd_init_5463 xfs_efd_init 3 5463 NULL
123745 +ll_xattr_cache_refill_5468 ll_xattr_cache_refill 0 5468 NULL
123746 +kernfs_fop_write_5471 kernfs_fop_write 3 5471 NULL
123747 +xfs_efi_init_5476 xfs_efi_init 2 5476 NULL
123748 +cifs_security_flags_proc_write_5484 cifs_security_flags_proc_write 3 5484 NULL
123749 +tty_write_5494 tty_write 3 5494 NULL
123750 +ieee80211_if_fmt_last_beacon_5498 ieee80211_if_fmt_last_beacon 3 5498 NULL nohasharray
123751 +tomoyo_update_domain_5498 tomoyo_update_domain 2 5498 &ieee80211_if_fmt_last_beacon_5498
123752 +__max_nr_grant_frames_5505 __max_nr_grant_frames 0 5505 NULL
123753 +ieee80211_if_fmt_auto_open_plinks_5534 ieee80211_if_fmt_auto_open_plinks 3 5534 NULL
123754 +get_entry_msg_len_5552 get_entry_msg_len 0 5552 NULL
123755 +le_readq_5557 le_readq 0 5557 NULL
123756 +inw_5558 inw 0 5558 NULL
123757 +bioset_create_5580 bioset_create 1 5580 NULL
123758 +oz_ep_alloc_5587 oz_ep_alloc 1 5587 NULL
123759 +SYSC_fsetxattr_5639 SYSC_fsetxattr 4 5639 NULL
123760 +ext4_xattr_get_5661 ext4_xattr_get 0 5661 NULL
123761 +posix_clock_register_5662 posix_clock_register 2 5662 NULL
123762 +get_arg_5694 get_arg 3 5694 NULL
123763 +subbuf_read_actor_5708 subbuf_read_actor 3 5708 NULL
123764 +vmw_kms_readback_5727 vmw_kms_readback 6 5727 NULL
123765 +sctp_setsockopt_autoclose_5775 sctp_setsockopt_autoclose 3 5775 NULL
123766 +__vxge_hw_blockpool_malloc_5786 __vxge_hw_blockpool_malloc 2 5786 NULL
123767 +nvme_trans_bdev_char_page_5797 nvme_trans_bdev_char_page 3 5797 NULL
123768 +skb_copy_datagram_iovec_5806 skb_copy_datagram_iovec 2-4 5806 NULL
123769 +nv50_disp_pioc_create__5812 nv50_disp_pioc_create_ 5 5812 NULL
123770 +ceph_x_encrypt_buflen_5829 ceph_x_encrypt_buflen 0-1 5829 NULL
123771 +ceph_msg_new_5846 ceph_msg_new 2 5846 NULL
123772 +setup_req_5848 setup_req 3 5848 NULL
123773 +ria_page_count_5849 ria_page_count 0 5849 NULL
123774 +rx_filter_max_arp_queue_dep_read_5851 rx_filter_max_arp_queue_dep_read 3 5851 NULL
123775 +uinput_compat_ioctl_5861 uinput_compat_ioctl 2 5861 NULL
123776 +lprocfs_fid_width_seq_write_5889 lprocfs_fid_width_seq_write 3 5889 NULL
123777 +port_show_regs_5904 port_show_regs 3 5904 NULL
123778 +rbd_segment_length_5907 rbd_segment_length 0-3-2 5907 NULL
123779 +uhci_debug_read_5911 uhci_debug_read 3 5911 NULL
123780 +lbs_highsnr_read_5931 lbs_highsnr_read 3 5931 NULL
123781 +ps_poll_ps_poll_timeouts_read_5934 ps_poll_ps_poll_timeouts_read 3 5934 NULL
123782 +edac_device_alloc_ctl_info_5941 edac_device_alloc_ctl_info 1 5941 NULL
123783 +ll_statahead_one_5962 ll_statahead_one 3 5962 NULL
123784 +__apu_get_register_5967 __apu_get_register 0 5967 NULL
123785 +ieee80211_if_fmt_rc_rateidx_mask_5ghz_5971 ieee80211_if_fmt_rc_rateidx_mask_5ghz 3 5971 NULL
123786 +btrfs_item_offset_6019 btrfs_item_offset 0 6019 NULL
123787 +alloc_msg_6072 alloc_msg 1 6072 NULL
123788 +sctp_setsockopt_connectx_6073 sctp_setsockopt_connectx 3 6073 NULL
123789 +force_static_address_read_6110 force_static_address_read 3 6110 NULL nohasharray
123790 +ipmi_addr_length_6110 ipmi_addr_length 0 6110 &force_static_address_read_6110
123791 +dfs_global_file_write_6112 dfs_global_file_write 3 6112 NULL
123792 +nouveau_parent_create__6131 nouveau_parent_create_ 7 6131 NULL
123793 +ieee80211_if_fmt_beacon_timeout_6153 ieee80211_if_fmt_beacon_timeout 3 6153 NULL
123794 +ivtv_copy_buf_to_user_6159 ivtv_copy_buf_to_user 4 6159 NULL
123795 +maybe_insert_hole_6167 maybe_insert_hole 3 6167 NULL
123796 +wl1251_cmd_template_set_6172 wl1251_cmd_template_set 4 6172 NULL
123797 +SyS_setgroups_6182 SyS_setgroups 1 6182 NULL
123798 +snd_efw_command_get_phys_meters_6190 snd_efw_command_get_phys_meters 3 6190 NULL
123799 +mxt_show_instance_6207 mxt_show_instance 2-0 6207 NULL
123800 +v4l2_ctrl_new_std_menu_6221 v4l2_ctrl_new_std_menu 4 6221 NULL
123801 +mqueue_read_file_6228 mqueue_read_file 3 6228 NULL
123802 +f_hidg_read_6238 f_hidg_read 3 6238 NULL
123803 +fbcon_prepare_logo_6246 fbcon_prepare_logo 5 6246 NULL
123804 +of_gpio_count_6270 of_gpio_count 0 6270 NULL
123805 +tx_tx_start_null_frame_read_6281 tx_tx_start_null_frame_read 3 6281 NULL
123806 +snd_hda_override_conn_list_6282 snd_hda_override_conn_list 3-0 6282 NULL nohasharray
123807 +xenbus_file_write_6282 xenbus_file_write 3 6282 &snd_hda_override_conn_list_6282
123808 +posix_acl_fix_xattr_to_user_6283 posix_acl_fix_xattr_to_user 2 6283 NULL
123809 +serial_port_in_6291 serial_port_in 0 6291 NULL
123810 +qlcnic_sriov_alloc_bc_msg_6309 qlcnic_sriov_alloc_bc_msg 2 6309 NULL
123811 +hfsplus_direct_IO_6313 hfsplus_direct_IO 4 6313 NULL
123812 +hfa384x_inw_6329 hfa384x_inw 0 6329 NULL nohasharray
123813 +SyS_mincore_6329 SyS_mincore 1-2 6329 &hfa384x_inw_6329
123814 +fuse_get_req_for_background_6337 fuse_get_req_for_background 2 6337 NULL
123815 +ucs2_strnlen_6342 ucs2_strnlen 0 6342 NULL
123816 +regcache_sync_block_raw_6350 regcache_sync_block_raw 5-4 6350 NULL
123817 +mei_dbgfs_read_devstate_6352 mei_dbgfs_read_devstate 3 6352 NULL
123818 +arch_gnttab_valloc_6372 arch_gnttab_valloc 2 6372 NULL
123819 +osd_req_read_sg_kern_6378 osd_req_read_sg_kern 5 6378 NULL
123820 +posix_acl_fix_xattr_userns_6420 posix_acl_fix_xattr_userns 4 6420 NULL
123821 +add_transaction_credits_6422 add_transaction_credits 2-3 6422 NULL
123822 +ipr_change_queue_depth_6431 ipr_change_queue_depth 2 6431 NULL
123823 +__alloc_bootmem_node_nopanic_6432 __alloc_bootmem_node_nopanic 2 6432 NULL
123824 +ieee80211_if_fmt_dot11MeshMaxRetries_6476 ieee80211_if_fmt_dot11MeshMaxRetries 3 6476 NULL
123825 +qp_memcpy_from_queue_6479 qp_memcpy_from_queue 5-4 6479 NULL
123826 +cipso_v4_map_lvl_hton_6490 cipso_v4_map_lvl_hton 0 6490 NULL
123827 +dbg_intr_buf_6501 dbg_intr_buf 2 6501 NULL
123828 +mei_read_6507 mei_read 3 6507 NULL
123829 +rndis_set_oid_6547 rndis_set_oid 4 6547 NULL
123830 +wdm_read_6549 wdm_read 3 6549 NULL
123831 +dm_stats_create_6551 dm_stats_create 4-2-3 6551 NULL
123832 +fb_alloc_cmap_6554 fb_alloc_cmap 2 6554 NULL
123833 +SyS_semtimedop_6563 SyS_semtimedop 3 6563 NULL
123834 +ecryptfs_filldir_6622 ecryptfs_filldir 3 6622 NULL
123835 +process_rcvd_data_6679 process_rcvd_data 3 6679 NULL
123836 +btrfs_lookup_csums_range_6696 btrfs_lookup_csums_range 2-3 6696 NULL
123837 +ps_pspoll_max_apturn_read_6699 ps_pspoll_max_apturn_read 3 6699 NULL
123838 +bnad_debugfs_write_regrd_6706 bnad_debugfs_write_regrd 3 6706 NULL
123839 +mpeg_read_6708 mpeg_read 3 6708 NULL
123840 +ibmpex_query_sensor_count_6709 ibmpex_query_sensor_count 0 6709 NULL
123841 +check_clk_sync_6717 check_clk_sync 2 6717 NULL
123842 +video_proc_write_6724 video_proc_write 3 6724 NULL
123843 +posix_acl_xattr_count_6725 posix_acl_xattr_count 0-1 6725 NULL
123844 +iwl_dbgfs_channels_read_6784 iwl_dbgfs_channels_read 3 6784 NULL
123845 +ieee80211_if_read_6785 ieee80211_if_read 3 6785 NULL
123846 +zone_spanned_pages_in_node_6787 zone_spanned_pages_in_node 0-3-4 6787 NULL
123847 +hdlcdrv_register_6792 hdlcdrv_register 2 6792 NULL
123848 +ll_xattr_cache_find_6798 ll_xattr_cache_find 0 6798 NULL
123849 +tx_tx_done_data_read_6799 tx_tx_done_data_read 3 6799 NULL
123850 +lbs_rdrf_write_6826 lbs_rdrf_write 3 6826 NULL
123851 +calc_pages_for_6838 calc_pages_for 0-2-1 6838 NULL
123852 +mon_bin_read_6841 mon_bin_read 3 6841 NULL
123853 +snd_cs4281_BA0_read_6847 snd_cs4281_BA0_read 5 6847 NULL
123854 +perf_output_sample_ustack_6868 perf_output_sample_ustack 2 6868 NULL
123855 +dio_complete_6879 dio_complete 0-3-2 6879 NULL
123856 +raw_seticmpfilter_6888 raw_seticmpfilter 3 6888 NULL nohasharray
123857 +ieee80211_if_fmt_path_refresh_time_6888 ieee80211_if_fmt_path_refresh_time 3 6888 &raw_seticmpfilter_6888
123858 +dlmfs_file_write_6892 dlmfs_file_write 3 6892 NULL
123859 +proc_sessionid_read_6911 proc_sessionid_read 3 6911 NULL nohasharray
123860 +spi_show_regs_6911 spi_show_regs 3 6911 &proc_sessionid_read_6911 nohasharray
123861 +acm_alloc_minor_6911 acm_alloc_minor 0 6911 &spi_show_regs_6911
123862 +__kfifo_dma_in_finish_r_6913 __kfifo_dma_in_finish_r 2-3 6913 NULL
123863 +cache_do_downcall_6926 cache_do_downcall 3 6926 NULL
123864 +ipath_verbs_send_dma_6929 ipath_verbs_send_dma 6 6929 NULL
123865 +qsfp_cks_6945 qsfp_cks 2-0 6945 NULL
123866 +tg3_nvram_write_block_unbuffered_6955 tg3_nvram_write_block_unbuffered 3 6955 NULL
123867 +pch_uart_hal_read_6961 pch_uart_hal_read 0 6961 NULL
123868 +i40e_dbg_dump_write_6973 i40e_dbg_dump_write 3 6973 NULL nohasharray
123869 +rsa_extract_mpi_6973 rsa_extract_mpi 5 6973 &i40e_dbg_dump_write_6973
123870 +request_key_async_6990 request_key_async 4 6990 NULL
123871 +tpl_write_6998 tpl_write 3 6998 NULL
123872 +cipso_v4_gentag_enum_7006 cipso_v4_gentag_enum 0 7006 NULL
123873 +tracing_cpumask_read_7010 tracing_cpumask_read 3 7010 NULL
123874 +ld_usb_write_7022 ld_usb_write 3 7022 NULL
123875 +wimax_msg_7030 wimax_msg 4 7030 NULL
123876 +ceph_kvmalloc_7033 ceph_kvmalloc 1 7033 NULL
123877 +ipath_get_base_info_7043 ipath_get_base_info 3 7043 NULL
123878 +snd_pcm_oss_bytes_7051 snd_pcm_oss_bytes 2 7051 NULL
123879 +nouveau_device_create__7063 nouveau_device_create_ 7 7063 NULL
123880 +hci_sock_recvmsg_7072 hci_sock_recvmsg 4 7072 NULL
123881 +event_enable_read_7074 event_enable_read 3 7074 NULL
123882 +beacon_interval_read_7091 beacon_interval_read 3 7091 NULL nohasharray
123883 +tipc_send_packet_7091 tipc_send_packet 4 7091 &beacon_interval_read_7091
123884 +pipeline_enc_rx_stat_fifo_int_read_7107 pipeline_enc_rx_stat_fifo_int_read 3 7107 NULL
123885 +osc_resend_count_seq_write_7120 osc_resend_count_seq_write 3 7120 NULL
123886 +kvm_mmu_notifier_test_young_7139 kvm_mmu_notifier_test_young 3 7139 NULL
123887 +__alloc_objio_seg_7203 __alloc_objio_seg 1 7203 NULL
123888 +rx_rate_rx_frames_per_rates_read_7282 rx_rate_rx_frames_per_rates_read 3 7282 NULL
123889 +pci_vpd_info_field_size_7324 pci_vpd_info_field_size 0 7324 NULL
123890 +mgmt_control_7349 mgmt_control 3 7349 NULL
123891 +at_est2timeout_7365 at_est2timeout 0-1 7365 NULL
123892 +ieee80211_if_read_dot11MeshHWMPactivePathTimeout_7368 ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 NULL
123893 +ath10k_read_fw_stats_7387 ath10k_read_fw_stats 3 7387 NULL
123894 +hweight_long_7388 hweight_long 0 7388 NULL
123895 +sl_change_mtu_7396 sl_change_mtu 2 7396 NULL
123896 +_ore_add_stripe_unit_7399 _ore_add_stripe_unit 6-3 7399 NULL
123897 +audmux_read_file_7400 audmux_read_file 3 7400 NULL
123898 +readb_7401 readb 0 7401 NULL
123899 +tipc_recvmsg_7402 tipc_recvmsg 4 7402 NULL
123900 +drm_property_create_blob_7414 drm_property_create_blob 2 7414 NULL
123901 +__copy_to_user_nocheck_7443 __copy_to_user_nocheck 0-3 7443 NULL
123902 +ip_options_get_alloc_7448 ip_options_get_alloc 1 7448 NULL
123903 +SYSC_setgroups_7454 SYSC_setgroups 1 7454 NULL
123904 +rt2x00debug_read_queue_stats_7455 rt2x00debug_read_queue_stats 3 7455 NULL
123905 +garp_request_join_7471 garp_request_join 4 7471 NULL
123906 +snd_pcm_lib_read1_7491 snd_pcm_lib_read1 0-3 7491 NULL
123907 +ahash_instance_headroom_7509 ahash_instance_headroom 0 7509 NULL nohasharray
123908 +sdhci_alloc_host_7509 sdhci_alloc_host 2 7509 &ahash_instance_headroom_7509
123909 +array_zalloc_7519 array_zalloc 1-2 7519 NULL
123910 +ath10k_read_htt_stats_mask_7557 ath10k_read_htt_stats_mask 3 7557 NULL
123911 +smk_read_mapped_7562 smk_read_mapped 3 7562 NULL
123912 +netvsc_get_slots_7565 netvsc_get_slots 0 7565 NULL
123913 +cfs_cpt_num_estimate_7571 cfs_cpt_num_estimate 0 7571 NULL
123914 +groups_alloc_7614 groups_alloc 1 7614 NULL
123915 +_rtw_zmalloc_7636 _rtw_zmalloc 1 7636 NULL
123916 +fault_inject_write_7662 fault_inject_write 3 7662 NULL
123917 +acpi_ex_allocate_name_string_7685 acpi_ex_allocate_name_string 2-1 7685 NULL
123918 +acpi_ns_get_pathname_length_7699 acpi_ns_get_pathname_length 0 7699 NULL
123919 +dev_write_7708 dev_write 3 7708 NULL
123920 +vxge_device_register_7752 vxge_device_register 4 7752 NULL
123921 +ubi_io_read_vid_hdr_7766 ubi_io_read_vid_hdr 0 7766 NULL
123922 +iwl_dbgfs_bt_cmd_read_7770 iwl_dbgfs_bt_cmd_read 3 7770 NULL
123923 +alloc_candev_7776 alloc_candev 1-2 7776 NULL
123924 +dfs_global_file_read_7787 dfs_global_file_read 3 7787 NULL
123925 +bnx2_nvram_write_7790 bnx2_nvram_write 4-2 7790 NULL
123926 +diva_os_copy_from_user_7792 diva_os_copy_from_user 4 7792 NULL nohasharray
123927 +lustre_packed_msg_size_7792 lustre_packed_msg_size 0 7792 &diva_os_copy_from_user_7792
123928 +seq_buf_alloc_7828 seq_buf_alloc 1 7828 NULL
123929 +cfs_trace_dump_debug_buffer_usrstr_7861 cfs_trace_dump_debug_buffer_usrstr 2 7861 NULL
123930 +tipc_alloc_entry_7875 tipc_alloc_entry 2 7875 NULL
123931 +dvb_dmxdev_read_sec_7892 dvb_dmxdev_read_sec 4 7892 NULL
123932 +xfs_trans_get_efi_7898 xfs_trans_get_efi 2 7898 NULL
123933 +libfc_host_alloc_7917 libfc_host_alloc 2 7917 NULL
123934 +f_hidg_write_7932 f_hidg_write 3 7932 NULL
123935 +integrity_digsig_verify_7956 integrity_digsig_verify 3 7956 NULL
123936 +smk_write_load_self_7958 smk_write_load_self 3 7958 NULL
123937 +tt3650_ci_msg_locked_8013 tt3650_ci_msg_locked 4 8013 NULL
123938 +vcs_read_8017 vcs_read 3 8017 NULL
123939 +vhost_add_used_and_signal_n_8038 vhost_add_used_and_signal_n 4 8038 NULL
123940 +dgrp_mon_read_8065 dgrp_mon_read 3 8065 NULL
123941 +spi_write_then_read_8073 spi_write_then_read 5-3 8073 NULL
123942 +qla4xxx_post_ping_evt_work_8074 qla4xxx_post_ping_evt_work 4 8074 NULL
123943 +venus_lookup_8121 venus_lookup 4 8121 NULL
123944 +ieee80211_if_fmt_num_buffered_multicast_8127 ieee80211_if_fmt_num_buffered_multicast 3 8127 NULL
123945 +__sk_mem_schedule_8185 __sk_mem_schedule 2 8185 NULL
123946 +ieee80211_if_fmt_dot11MeshHoldingTimeout_8187 ieee80211_if_fmt_dot11MeshHoldingTimeout 3 8187 NULL
123947 +recent_mt_proc_write_8206 recent_mt_proc_write 3 8206 NULL
123948 +rt2x00debug_write_bbp_8212 rt2x00debug_write_bbp 3 8212 NULL
123949 +ad7879_spi_multi_read_8218 ad7879_spi_multi_read 3 8218 NULL
123950 +play_iframe_8219 play_iframe 3 8219 NULL
123951 +kvm_mmu_page_set_gfn_8225 kvm_mmu_page_set_gfn 2 8225 NULL
123952 +sctp_ssnmap_size_8228 sctp_ssnmap_size 0-1-2 8228 NULL
123953 +check_xattr_ref_inode_8244 check_xattr_ref_inode 0 8244 NULL
123954 +t3_init_l2t_8261 t3_init_l2t 1 8261 NULL
123955 +init_cdev_8274 init_cdev 1 8274 NULL
123956 +rproc_recovery_write_8281 rproc_recovery_write 3 8281 NULL
123957 +qib_decode_7220_err_8315 qib_decode_7220_err 3 8315 NULL
123958 +ipwireless_send_packet_8328 ipwireless_send_packet 4 8328 NULL
123959 +rtw_cfg80211_rx_action_8329 rtw_cfg80211_rx_action 3 8329 NULL
123960 +tracing_entries_read_8345 tracing_entries_read 3 8345 NULL
123961 +ieee80211_if_fmt_ht_opmode_8347 ieee80211_if_fmt_ht_opmode 3 8347 NULL
123962 +generic_write_sync_8358 generic_write_sync 0 8358 NULL
123963 +ping_getfrag_8360 ping_getfrag 4-3 8360 NULL
123964 +ath6kl_lrssi_roam_write_8362 ath6kl_lrssi_roam_write 3 8362 NULL
123965 +xdi_copy_from_user_8395 xdi_copy_from_user 4 8395 NULL
123966 +zd_rf_scnprint_id_8406 zd_rf_scnprint_id 0-3 8406 NULL
123967 +smk_write_change_rule_8411 smk_write_change_rule 3 8411 NULL nohasharray
123968 +uvc_v4l2_ioctl_8411 uvc_v4l2_ioctl 2 8411 &smk_write_change_rule_8411
123969 +roccat_common2_sysfs_read_8431 roccat_common2_sysfs_read 6 8431 NULL
123970 +afs_cell_lookup_8482 afs_cell_lookup 2 8482 NULL
123971 +fore200e_chunk_alloc_8501 fore200e_chunk_alloc 4-3 8501 NULL
123972 +batadv_tt_len_8502 batadv_tt_len 0-1 8502 NULL
123973 +dev_config_8506 dev_config 3 8506 NULL
123974 +ACL_to_cifs_posix_8509 ACL_to_cifs_posix 3 8509 NULL
123975 +opticon_process_data_packet_8524 opticon_process_data_packet 3 8524 NULL
123976 +user_on_off_8552 user_on_off 2 8552 NULL
123977 +profile_remove_8556 profile_remove 3 8556 NULL
123978 +cache_slow_downcall_8570 cache_slow_downcall 2 8570 NULL
123979 +isr_dma0_done_read_8574 isr_dma0_done_read 3 8574 NULL
123980 +tower_write_8580 tower_write 3 8580 NULL
123981 +cfs_cpt_number_8618 cfs_cpt_number 0 8618 NULL
123982 +shash_setkey_unaligned_8620 shash_setkey_unaligned 3 8620 NULL
123983 +it821x_firmware_command_8628 it821x_firmware_command 3 8628 NULL
123984 +scsi_dma_map_8632 scsi_dma_map 0 8632 NULL
123985 +fuse_send_write_pages_8636 fuse_send_write_pages 0-5 8636 NULL
123986 +mlx5_vzalloc_8663 mlx5_vzalloc 1 8663 NULL
123987 +dio_bio_alloc_8677 dio_bio_alloc 5 8677 NULL
123988 +lbs_bcnmiss_read_8678 lbs_bcnmiss_read 3 8678 NULL
123989 +rproc_trace_read_8686 rproc_trace_read 3 8686 NULL
123990 +skb_frag_size_8695 skb_frag_size 0 8695 NULL
123991 +arcfb_write_8702 arcfb_write 3 8702 NULL
123992 +i_size_read_8703 i_size_read 0 8703 NULL
123993 +ctrl_out_8712 ctrl_out 3-5 8712 NULL
123994 +tracing_max_lat_write_8728 tracing_max_lat_write 3 8728 NULL
123995 +jffs2_acl_count_8729 jffs2_acl_count 0-1 8729 NULL
123996 +tx_tx_exch_expiry_read_8749 tx_tx_exch_expiry_read 3 8749 NULL
123997 +compound_order_8750 compound_order 0 8750 NULL
123998 +yurex_write_8761 yurex_write 3 8761 NULL
123999 +joydev_compat_ioctl_8765 joydev_compat_ioctl 2 8765 NULL
124000 +kstrtoint_from_user_8778 kstrtoint_from_user 2 8778 NULL
124001 +paging32_prefetch_gpte_8783 paging32_prefetch_gpte 4 8783 NULL
124002 +ext4_try_to_write_inline_data_8785 ext4_try_to_write_inline_data 4-3 8785 NULL
124003 +__bitmap_weight_8796 __bitmap_weight 0 8796 NULL
124004 +metronomefb_write_8823 metronomefb_write 3 8823 NULL
124005 +SyS_llistxattr_8824 SyS_llistxattr 3 8824 NULL
124006 +ll_xattr_cache_get_8829 ll_xattr_cache_get 0 8829 NULL
124007 +get_queue_depth_8833 get_queue_depth 0 8833 NULL
124008 +dvb_ringbuffer_pkt_next_8834 dvb_ringbuffer_pkt_next 0-2 8834 NULL
124009 +usb_ep_queue_8839 usb_ep_queue 0 8839 NULL
124010 +iwl_rx_packet_len_8854 iwl_rx_packet_len 0 8854 NULL
124011 +debug_debug1_read_8856 debug_debug1_read 3 8856 NULL
124012 +wa_nep_queue_8858 wa_nep_queue 2 8858 NULL
124013 +xgmac_reg_value_write_8860 xgmac_reg_value_write 3 8860 NULL
124014 +radeon_drm_ioctl_8875 radeon_drm_ioctl 2 8875 NULL
124015 +compressed_bio_size_8887 compressed_bio_size 0-2 8887 NULL
124016 +tracing_max_lat_read_8890 tracing_max_lat_read 3 8890 NULL nohasharray
124017 +ab3100_get_set_reg_8890 ab3100_get_set_reg 3 8890 &tracing_max_lat_read_8890
124018 +sdio_max_byte_size_8907 sdio_max_byte_size 0 8907 NULL
124019 +write_file_ani_8918 write_file_ani 3 8918 NULL
124020 +layout_commit_8926 layout_commit 3 8926 NULL
124021 +cp2112_hid_get_8933 cp2112_hid_get 4 8933 NULL
124022 +adjust_priv_size_8935 adjust_priv_size 0-1 8935 NULL
124023 +driver_stats_read_8944 driver_stats_read 3 8944 NULL
124024 +read_file_tgt_stats_8959 read_file_tgt_stats 3 8959 NULL
124025 +usb_allocate_stream_buffers_8964 usb_allocate_stream_buffers 3 8964 NULL
124026 +qib_qsfp_dump_8966 qib_qsfp_dump 0-3 8966 NULL
124027 +venus_mkdir_8967 venus_mkdir 4 8967 NULL
124028 +seq_open_net_8968 seq_open_net 4 8968 NULL nohasharray
124029 +vol_cdev_read_8968 vol_cdev_read 3 8968 &seq_open_net_8968
124030 +bio_integrity_get_tag_8974 bio_integrity_get_tag 3 8974 NULL
124031 +sony_register_touchpad_8981 sony_register_touchpad 2 8981 NULL
124032 +jbd2_journal_blocks_per_page_9004 jbd2_journal_blocks_per_page 0 9004 NULL
124033 +il_dbgfs_clear_ucode_stats_write_9016 il_dbgfs_clear_ucode_stats_write 3 9016 NULL
124034 +snd_emu10k1_ptr_read_9026 snd_emu10k1_ptr_read 0-2 9026 NULL
124035 +nla_put_9042 nla_put 3 9042 NULL
124036 +sta_tx_latency_stat_header_9050 sta_tx_latency_stat_header 4-3-0 9050 NULL
124037 +snd_emu10k1_synth_copy_from_user_9061 snd_emu10k1_synth_copy_from_user 3-5 9061 NULL
124038 +snd_gus_dram_peek_9062 snd_gus_dram_peek 4 9062 NULL
124039 +fib_info_hash_alloc_9075 fib_info_hash_alloc 1 9075 NULL
124040 +create_queues_9088 create_queues 2-3 9088 NULL
124041 +nvkm_output_create__9091 nvkm_output_create_ 6 9091 NULL
124042 +ftdi_prepare_write_buffer_9093 ftdi_prepare_write_buffer 3 9093 NULL
124043 +adxl34x_spi_read_block_9108 adxl34x_spi_read_block 3 9108 NULL
124044 +gfn_to_rmap_9110 gfn_to_rmap 3-2 9110 NULL nohasharray
124045 +caif_stream_sendmsg_9110 caif_stream_sendmsg 4 9110 &gfn_to_rmap_9110
124046 +pmcraid_change_queue_depth_9116 pmcraid_change_queue_depth 2 9116 NULL
124047 +vb2_dma_sg_alloc_9157 vb2_dma_sg_alloc 2 9157 NULL
124048 +dbg_command_buf_9165 dbg_command_buf 2 9165 NULL
124049 +isr_irqs_read_9181 isr_irqs_read 3 9181 NULL
124050 +count_leading_zeros_9183 count_leading_zeros 0 9183 NULL
124051 +altera_swap_ir_9194 altera_swap_ir 2 9194 NULL
124052 +snd_m3_get_pointer_9206 snd_m3_get_pointer 0 9206 NULL
124053 +iwl_dbgfs_frame_stats_read_9211 iwl_dbgfs_frame_stats_read 3 9211 NULL
124054 +virtqueue_add_9217 virtqueue_add 4-5 9217 NULL
124055 +tx_tx_prepared_descs_read_9221 tx_tx_prepared_descs_read 3 9221 NULL
124056 +sctp_getsockopt_delayed_ack_9232 sctp_getsockopt_delayed_ack 2 9232 NULL
124057 +hfsplus_bnode_read_u16_9262 hfsplus_bnode_read_u16 0 9262 NULL
124058 +hdpvr_read_9273 hdpvr_read 3 9273 NULL
124059 +flakey_status_9274 flakey_status 5 9274 NULL
124060 +iwl_dbgfs_stations_read_9309 iwl_dbgfs_stations_read 3 9309 NULL
124061 +ceph_sync_setxattr_9310 ceph_sync_setxattr 4 9310 NULL
124062 +__blockdev_direct_IO_9321 __blockdev_direct_IO 0-6 9321 NULL
124063 +ieee80211_if_fmt_txpower_9334 ieee80211_if_fmt_txpower 3 9334 NULL
124064 +nvme_trans_fmt_get_parm_header_9340 nvme_trans_fmt_get_parm_header 2 9340 NULL
124065 +ocfs2_orphan_for_truncate_9342 ocfs2_orphan_for_truncate 4 9342 NULL
124066 +ll_direct_rw_pages_9361 ll_direct_rw_pages 0 9361 NULL
124067 +sta_beacon_loss_count_read_9370 sta_beacon_loss_count_read 3 9370 NULL
124068 +virtqueue_add_outbuf_9395 virtqueue_add_outbuf 3 9395 NULL
124069 +read_9397 read 3 9397 NULL
124070 +hash_ipportip4_expire_9415 hash_ipportip4_expire 4 9415 NULL
124071 +btrfs_drop_extents_9423 btrfs_drop_extents 4 9423 NULL
124072 +bm_realloc_pages_9431 bm_realloc_pages 2 9431 NULL
124073 +ffs_ep0_write_9438 ffs_ep0_write 3 9438 NULL
124074 +ieee80211_if_fmt_fwded_unicast_9454 ieee80211_if_fmt_fwded_unicast 3 9454 NULL
124075 +agp_generic_alloc_user_9470 agp_generic_alloc_user 1 9470 NULL nohasharray
124076 +get_registers_9470 get_registers 4 9470 &agp_generic_alloc_user_9470
124077 +crypt_status_9492 crypt_status 5 9492 NULL
124078 +lbs_threshold_write_9502 lbs_threshold_write 5 9502 NULL
124079 +lp_write_9511 lp_write 3 9511 NULL
124080 +scsi_tgt_kspace_exec_9522 scsi_tgt_kspace_exec 8 9522 NULL
124081 +ll_max_read_ahead_whole_mb_seq_write_9528 ll_max_read_ahead_whole_mb_seq_write 3 9528 NULL
124082 +read_file_dma_9530 read_file_dma 3 9530 NULL
124083 +iwl_dbgfs_bf_params_read_9542 iwl_dbgfs_bf_params_read 3 9542 NULL
124084 +il_dbgfs_missed_beacon_write_9546 il_dbgfs_missed_beacon_write 3 9546 NULL
124085 +compat_SyS_pwritev64_9548 compat_SyS_pwritev64 3 9548 NULL
124086 +fw_node_create_9559 fw_node_create 2 9559 NULL
124087 +kobj_map_9566 kobj_map 2-3 9566 NULL
124088 +f2fs_read_data_pages_9574 f2fs_read_data_pages 4 9574 NULL
124089 +snd_emu10k1_fx8010_read_9605 snd_emu10k1_fx8010_read 5-6 9605 NULL
124090 +lov_ost_pool_add_9626 lov_ost_pool_add 3 9626 NULL
124091 +saa7164_buffer_alloc_user_9627 saa7164_buffer_alloc_user 2 9627 NULL
124092 +ceph_copy_user_to_page_vector_9635 ceph_copy_user_to_page_vector 4-3 9635 NULL
124093 +acpi_ex_insert_into_field_9638 acpi_ex_insert_into_field 3 9638 NULL
124094 +ll_checksum_seq_write_9648 ll_checksum_seq_write 3 9648 NULL
124095 +ocfs2_xattr_get_rec_9652 ocfs2_xattr_get_rec 0 9652 NULL
124096 +queue_received_packet_9657 queue_received_packet 5 9657 NULL
124097 +tipc_port_mcast_xmit_9663 tipc_port_mcast_xmit 4 9663 NULL
124098 +snd_opl4_mem_proc_write_9670 snd_opl4_mem_proc_write 5 9670 NULL
124099 +dns_query_9676 dns_query 3 9676 NULL
124100 +qib_7322_handle_hwerrors_9678 qib_7322_handle_hwerrors 3 9678 NULL
124101 +__erst_read_from_storage_9690 __erst_read_from_storage 0 9690 NULL
124102 +vx_transfer_end_9701 vx_transfer_end 0 9701 NULL
124103 +fuse_iter_npages_9705 fuse_iter_npages 0 9705 NULL nohasharray
124104 +ieee80211_if_read_aid_9705 ieee80211_if_read_aid 3 9705 &fuse_iter_npages_9705
124105 +cfg80211_tx_mlme_mgmt_9715 cfg80211_tx_mlme_mgmt 3 9715 NULL
124106 +parse_uac2_sample_rate_range_9718 parse_uac2_sample_rate_range 0 9718 NULL
124107 +btrfs_stack_file_extent_num_bytes_9720 btrfs_stack_file_extent_num_bytes 0 9720 NULL
124108 +SYSC_ppoll_9721 SYSC_ppoll 2 9721 NULL
124109 +nla_get_u8_9736 nla_get_u8 0 9736 NULL
124110 +ieee80211_if_fmt_num_mcast_sta_9738 ieee80211_if_fmt_num_mcast_sta 3 9738 NULL
124111 +ddb_input_read_9743 ddb_input_read 3-0 9743 NULL
124112 +regmap_multi_reg_write_bypassed_9751 regmap_multi_reg_write_bypassed 3 9751 NULL nohasharray
124113 +sta_last_ack_signal_read_9751 sta_last_ack_signal_read 3 9751 &regmap_multi_reg_write_bypassed_9751
124114 +btrfs_super_root_9763 btrfs_super_root 0 9763 NULL
124115 +copy_page_from_iter_bvec_9767 copy_page_from_iter_bvec 0-3 9767 NULL
124116 +__blk_queue_init_tags_9778 __blk_queue_init_tags 2 9778 NULL
124117 +kvm_age_hva_9795 kvm_age_hva 2 9795 NULL
124118 +bio_alloc_map_data_9798 bio_alloc_map_data 1 9798 NULL
124119 +udpv6_recvmsg_9813 udpv6_recvmsg 4 9813 NULL nohasharray
124120 +ieee80211_if_read_state_9813 ieee80211_if_read_state 3 9813 &udpv6_recvmsg_9813
124121 +pmcraid_alloc_sglist_9864 pmcraid_alloc_sglist 1 9864 NULL
124122 +wil_read_file_ioblob_9878 wil_read_file_ioblob 3 9878 NULL
124123 +bm_register_write_9893 bm_register_write 3 9893 NULL nohasharray
124124 +snd_midi_event_new_9893 snd_midi_event_new 1 9893 &bm_register_write_9893
124125 +snd_gf1_pcm_playback_copy_9895 snd_gf1_pcm_playback_copy 3-5 9895 NULL
124126 +nonpaging_page_fault_9908 nonpaging_page_fault 2 9908 NULL
124127 +iwl_dbgfs_prph_reg_read_9928 iwl_dbgfs_prph_reg_read 3 9928 NULL
124128 +pstore_ftrace_knob_read_9947 pstore_ftrace_knob_read 3 9947 NULL
124129 +read_file_misc_9948 read_file_misc 3 9948 NULL
124130 +csum_partial_copy_fromiovecend_9957 csum_partial_copy_fromiovecend 3-4 9957 NULL
124131 +SyS_gethostname_9964 SyS_gethostname 2 9964 NULL
124132 +get_free_serial_index_9969 get_free_serial_index 0 9969 NULL
124133 +btrfs_add_link_9973 btrfs_add_link 5 9973 NULL
124134 +SYSC_move_pages_9986 SYSC_move_pages 2 9986 NULL
124135 +aat2870_dump_reg_10019 aat2870_dump_reg 0 10019 NULL
124136 +ieee80211_set_probe_resp_10077 ieee80211_set_probe_resp 3 10077 NULL
124137 +get_elem_size_10110 get_elem_size 0-2 10110 NULL nohasharray
124138 +dynamic_ps_timeout_read_10110 dynamic_ps_timeout_read 3 10110 &get_elem_size_10110
124139 +gfs2_meta_read_10112 gfs2_meta_read 0 10112 NULL
124140 +SyS_migrate_pages_10134 SyS_migrate_pages 2 10134 NULL
124141 +aes_decrypt_packets_read_10155 aes_decrypt_packets_read 3 10155 NULL
124142 +rx_out_of_mem_read_10157 rx_out_of_mem_read 3 10157 NULL
124143 +hidg_alloc_ep_req_10159 hidg_alloc_ep_req 2 10159 NULL
124144 +asd_store_update_bios_10165 asd_store_update_bios 4 10165 NULL
124145 +kstrtol_from_user_10168 kstrtol_from_user 2 10168 NULL
124146 +proc_pid_attr_read_10173 proc_pid_attr_read 3 10173 NULL
124147 +jffs2_user_setxattr_10182 jffs2_user_setxattr 4 10182 NULL
124148 +cciss_proc_write_10259 cciss_proc_write 3 10259 NULL
124149 +__qlcnic_pci_sriov_enable_10281 __qlcnic_pci_sriov_enable 2 10281 NULL
124150 +snd_rme9652_capture_copy_10287 snd_rme9652_capture_copy 5 10287 NULL
124151 +ubi_leb_change_10289 ubi_leb_change 0 10289 NULL
124152 +read_emulate_10310 read_emulate 2-4 10310 NULL
124153 +read_file_spectral_count_10320 read_file_spectral_count 3 10320 NULL
124154 +compat_SyS_writev_10327 compat_SyS_writev 3 10327 NULL
124155 +tun_sendmsg_10337 tun_sendmsg 4 10337 NULL
124156 +ufx_alloc_urb_list_10349 ufx_alloc_urb_list 3 10349 NULL
124157 +dbAllocAny_10354 dbAllocAny 0 10354 NULL
124158 +ath6kl_listen_int_read_10355 ath6kl_listen_int_read 3 10355 NULL
124159 +sta_ht_capa_read_10366 sta_ht_capa_read 3 10366 NULL
124160 +ecryptfs_decode_and_decrypt_filename_10379 ecryptfs_decode_and_decrypt_filename 5 10379 NULL
124161 +do_compat_pselect_10398 do_compat_pselect 1 10398 NULL
124162 +fwtty_rx_10434 fwtty_rx 3 10434 NULL
124163 +event_phy_transmit_error_read_10471 event_phy_transmit_error_read 3 10471 NULL
124164 +hash_ipportip6_expire_10478 hash_ipportip6_expire 4 10478 NULL
124165 +nouveau_pwr_create__10483 nouveau_pwr_create_ 4 10483 NULL
124166 +ext4_itable_unused_count_10501 ext4_itable_unused_count 0 10501 NULL
124167 +qib_alloc_fast_reg_page_list_10507 qib_alloc_fast_reg_page_list 2 10507 NULL
124168 +sel_write_disable_10511 sel_write_disable 3 10511 NULL
124169 +osd_req_write_sg_kern_10514 osd_req_write_sg_kern 5 10514 NULL
124170 +rds_message_alloc_10517 rds_message_alloc 1 10517 NULL
124171 +qlcnic_pci_sriov_enable_10519 qlcnic_pci_sriov_enable 2 10519 NULL
124172 +kstrtouint_from_user_10536 kstrtouint_from_user 2 10536 NULL nohasharray
124173 +snd_pcm_lib_read_10536 snd_pcm_lib_read 0-3 10536 &kstrtouint_from_user_10536
124174 +ext4_write_begin_10576 ext4_write_begin 3-4 10576 NULL
124175 +scrub_remap_extent_10588 scrub_remap_extent 2 10588 NULL
124176 +otp_read_10594 otp_read 2-4-5 10594 NULL
124177 +supply_map_read_file_10608 supply_map_read_file 3 10608 NULL
124178 +ima_show_htable_violations_10619 ima_show_htable_violations 3 10619 NULL
124179 +fq_alloc_node_10633 fq_alloc_node 1 10633 NULL
124180 +nfs_idmap_lookup_id_10660 nfs_idmap_lookup_id 2 10660 NULL nohasharray
124181 +ubi_io_write_vid_hdr_10660 ubi_io_write_vid_hdr 0 10660 &nfs_idmap_lookup_id_10660
124182 +efx_max_tx_len_10662 efx_max_tx_len 0-2 10662 NULL
124183 +parport_write_10669 parport_write 0 10669 NULL
124184 +edge_write_10692 edge_write 4 10692 NULL
124185 +ubi_wl_get_peb_10699 ubi_wl_get_peb 0 10699 NULL
124186 +selinux_inode_setxattr_10708 selinux_inode_setxattr 4 10708 NULL nohasharray
124187 +inl_10708 inl 0 10708 &selinux_inode_setxattr_10708
124188 +shash_async_setkey_10720 shash_async_setkey 3 10720 NULL nohasharray
124189 +pvr2_ioread_read_10720 pvr2_ioread_read 3 10720 &shash_async_setkey_10720
124190 +spi_sync_10731 spi_sync 0 10731 NULL
124191 +sctp_getsockopt_maxseg_10737 sctp_getsockopt_maxseg 2 10737 NULL nohasharray
124192 +apu_get_register_10737 apu_get_register 0 10737 &sctp_getsockopt_maxseg_10737
124193 +SyS_io_getevents_10756 SyS_io_getevents 3 10756 NULL
124194 +vhost_add_used_n_10760 vhost_add_used_n 3 10760 NULL
124195 +rd_build_prot_space_10761 rd_build_prot_space 2-3 10761 NULL
124196 +kvm_read_guest_atomic_10765 kvm_read_guest_atomic 4 10765 NULL
124197 +__qp_memcpy_to_queue_10779 __qp_memcpy_to_queue 2-4 10779 NULL
124198 +diva_set_trace_filter_10820 diva_set_trace_filter 0-1 10820 NULL
124199 +lbs_sleepparams_read_10840 lbs_sleepparams_read 3 10840 NULL
124200 +ext4_direct_IO_10843 ext4_direct_IO 4 10843 NULL
124201 +ida_get_new_above_10853 ida_get_new_above 0 10853 NULL
124202 +fuse_conn_max_background_read_10855 fuse_conn_max_background_read 3 10855 NULL
124203 +snd_pcm_oss_write1_10872 snd_pcm_oss_write1 3 10872 NULL
124204 +wiidebug_drm_write_10879 wiidebug_drm_write 3 10879 NULL
124205 +get_scq_10897 get_scq 2 10897 NULL
124206 +tifm_alloc_adapter_10903 tifm_alloc_adapter 1 10903 NULL
124207 +lprocfs_wr_atomic_10912 lprocfs_wr_atomic 3 10912 NULL
124208 +__copy_from_user_10918 __copy_from_user 3-0 10918 NULL
124209 +ar9003_dump_modal_eeprom_10959 ar9003_dump_modal_eeprom 3-2-0 10959 NULL
124210 +ci_port_test_write_10962 ci_port_test_write 3 10962 NULL
124211 +bm_entry_read_10976 bm_entry_read 3 10976 NULL
124212 +sched_autogroup_write_10984 sched_autogroup_write 3 10984 NULL
124213 +xfrm_hash_alloc_10997 xfrm_hash_alloc 1 10997 NULL
124214 +rx_filter_accum_arp_pend_requests_read_11003 rx_filter_accum_arp_pend_requests_read 3 11003 NULL
124215 +SetLineNumber_11023 SetLineNumber 0 11023 NULL
124216 +nouveau_gpio_create__11048 nouveau_gpio_create_ 4 11048 NULL
124217 +tda10048_writeregbulk_11050 tda10048_writeregbulk 4 11050 NULL
124218 +insert_inline_extent_backref_11063 insert_inline_extent_backref 8 11063 NULL
124219 +tcp_send_mss_11079 tcp_send_mss 0 11079 NULL
124220 +count_argc_11083 count_argc 0 11083 NULL
124221 +kvm_write_guest_cached_11106 kvm_write_guest_cached 4 11106 NULL
124222 +tw_change_queue_depth_11116 tw_change_queue_depth 2 11116 NULL
124223 +page_offset_11120 page_offset 0 11120 NULL
124224 +tracing_buffers_read_11124 tracing_buffers_read 3 11124 NULL
124225 +snd_gf1_pcm_playback_silence_11172 snd_gf1_pcm_playback_silence 3-4 11172 NULL
124226 +il_dbgfs_rx_queue_read_11221 il_dbgfs_rx_queue_read 3 11221 NULL
124227 +comedi_alloc_spriv_11234 comedi_alloc_spriv 2 11234 NULL
124228 +of_irq_count_11253 of_irq_count 0 11253 NULL
124229 +hugetlbfs_read_11268 hugetlbfs_read 3 11268 NULL
124230 +ath6kl_power_params_write_11274 ath6kl_power_params_write 3 11274 NULL
124231 +__proc_daemon_file_11305 __proc_daemon_file 5 11305 NULL
124232 +ext4_xattr_check_names_11314 ext4_xattr_check_names 0 11314 NULL
124233 +bcache_dev_sectors_dirty_add_11315 bcache_dev_sectors_dirty_add 3-4 11315 NULL
124234 +sk_filter_size_11316 sk_filter_size 0 11316 NULL nohasharray
124235 +tcp_send_rcvq_11316 tcp_send_rcvq 3 11316 &sk_filter_size_11316
124236 +construct_key_11329 construct_key 3 11329 NULL nohasharray
124237 +__kfifo_out_peek_11329 __kfifo_out_peek 0-3 11329 &construct_key_11329
124238 +next_segment_11330 next_segment 0-2-1 11330 NULL
124239 +persistent_ram_buffer_map_11332 persistent_ram_buffer_map 1-2 11332 NULL
124240 +ext4_get_inline_size_11349 ext4_get_inline_size 0 11349 NULL
124241 +sel_write_create_11353 sel_write_create 3 11353 NULL nohasharray
124242 +nl80211_send_mgmt_11353 nl80211_send_mgmt 7 11353 &sel_write_create_11353
124243 +of_get_available_child_count_11361 of_get_available_child_count 0 11361 NULL
124244 +qib_get_base_info_11369 qib_get_base_info 3 11369 NULL
124245 +nft_value_dump_11381 nft_value_dump 3 11381 NULL nohasharray
124246 +tcf_register_action_11381 tcf_register_action 2 11381 &nft_value_dump_11381
124247 +isku_sysfs_read_keys_capslock_11392 isku_sysfs_read_keys_capslock 6 11392 NULL
124248 +dev_irnet_write_11398 dev_irnet_write 3 11398 NULL
124249 +lprocfs_wr_evict_client_11402 lprocfs_wr_evict_client 3 11402 NULL
124250 +___alloc_bootmem_11410 ___alloc_bootmem 1 11410 NULL
124251 +str_to_user_11411 str_to_user 2 11411 NULL
124252 +mem_fw_gen_free_mem_blks_read_11413 mem_fw_gen_free_mem_blks_read 3 11413 NULL
124253 +ath6kl_wmi_test_rx_11414 ath6kl_wmi_test_rx 3 11414 NULL
124254 +adis16480_show_firmware_revision_11417 adis16480_show_firmware_revision 3 11417 NULL
124255 +trace_options_read_11419 trace_options_read 3 11419 NULL
124256 +i40e_dbg_command_write_11421 i40e_dbg_command_write 3 11421 NULL
124257 +bttv_read_11432 bttv_read 3 11432 NULL
124258 +create_zero_mask_11453 create_zero_mask 0-1 11453 NULL
124259 +sca3000_read_first_n_hw_rb_11479 sca3000_read_first_n_hw_rb 2 11479 NULL
124260 +sd_do_mode_sense_11507 sd_do_mode_sense 5 11507 NULL
124261 +kmem_zalloc_11510 kmem_zalloc 1 11510 NULL
124262 +ll_direct_IO_26_seg_11518 ll_direct_IO_26_seg 0 11518 NULL
124263 +twl_direction_in_11527 twl_direction_in 2 11527 NULL
124264 +skb_cow_data_11565 skb_cow_data 0 11565 NULL
124265 +lpfc_idiag_ctlacc_write_11576 lpfc_idiag_ctlacc_write 3 11576 NULL
124266 +oprofilefs_ulong_to_user_11582 oprofilefs_ulong_to_user 3 11582 NULL
124267 +batadv_iv_ogm_orig_add_if_11586 batadv_iv_ogm_orig_add_if 2 11586 NULL
124268 +snd_pcm_action_11589 snd_pcm_action 0 11589 NULL
124269 +fw_device_op_ioctl_11595 fw_device_op_ioctl 2 11595 NULL
124270 +batadv_iv_ogm_orig_del_if_11604 batadv_iv_ogm_orig_del_if 2 11604 NULL
124271 +SYSC_mq_timedsend_11607 SYSC_mq_timedsend 3 11607 NULL
124272 +C_SYSC_migrate_pages_11618 C_SYSC_migrate_pages 2 11618 NULL
124273 +sisusb_send_bridge_packet_11649 sisusb_send_bridge_packet 2 11649 NULL
124274 +nla_total_size_11658 nla_total_size 0-1 11658 NULL
124275 +slab_ksize_11664 slab_ksize 0 11664 NULL
124276 +ide_queue_pc_tail_11673 ide_queue_pc_tail 5 11673 NULL
124277 +compat_SyS_msgsnd_11675 compat_SyS_msgsnd 3 11675 NULL
124278 +btrfs_alloc_delayed_item_11678 btrfs_alloc_delayed_item 1 11678 NULL
124279 +sctp_setsockopt_hmac_ident_11687 sctp_setsockopt_hmac_ident 3 11687 NULL
124280 +split_11691 split 2 11691 NULL
124281 +compat_SyS_keyctl_11695 compat_SyS_keyctl 4 11695 NULL nohasharray
124282 +snd_ctl_elem_user_tlv_11695 snd_ctl_elem_user_tlv 3 11695 &compat_SyS_keyctl_11695
124283 +blk_rq_cur_bytes_11723 blk_rq_cur_bytes 0 11723 NULL
124284 +dm_bio_prison_create_11749 dm_bio_prison_create 1 11749 NULL
124285 +iwl_dbgfs_qos_read_11753 iwl_dbgfs_qos_read 3 11753 NULL
124286 +ieee80211_get_num_supported_channels_11768 ieee80211_get_num_supported_channels 0 11768 NULL
124287 +tipc_sendmsg_11769 tipc_sendmsg 4 11769 NULL
124288 +ps_pspoll_timeouts_read_11776 ps_pspoll_timeouts_read 3 11776 NULL
124289 +btrfs_key_blockptr_11786 btrfs_key_blockptr 0 11786 NULL
124290 +pcpu_fc_alloc_11818 pcpu_fc_alloc 2 11818 NULL
124291 +zerocopy_sg_from_iovec_11828 zerocopy_sg_from_iovec 3 11828 NULL
124292 +sctp_setsockopt_maxseg_11829 sctp_setsockopt_maxseg 3 11829 NULL
124293 +rts51x_read_status_11830 rts51x_read_status 4 11830 NULL
124294 +unix_stream_connect_11844 unix_stream_connect 3 11844 NULL
124295 +ecryptfs_copy_filename_11868 ecryptfs_copy_filename 4 11868 NULL
124296 +ieee80211_rx_bss_info_11887 ieee80211_rx_bss_info 3 11887 NULL
124297 +mdc_rename_11899 mdc_rename 4-6 11899 NULL
124298 +xstateregs_get_11906 xstateregs_get 4 11906 NULL
124299 +ti_write_11916 ti_write 4 11916 NULL
124300 +fs_devrw_entry_11924 fs_devrw_entry 3 11924 NULL
124301 +atomic_sub_return_11939 atomic_sub_return 0-1 11939 NULL
124302 +r1_sync_page_io_11963 r1_sync_page_io 3 11963 NULL
124303 +read_and_add_raw_conns_11987 read_and_add_raw_conns 0 11987 NULL
124304 +ftdi_elan_total_command_size_12045 ftdi_elan_total_command_size 0 12045 NULL
124305 +ieee80211_if_read_user_power_level_12050 ieee80211_if_read_user_power_level 3 12050 NULL
124306 +il4965_ucode_tx_stats_read_12064 il4965_ucode_tx_stats_read 3 12064 NULL
124307 +ptc_proc_write_12076 ptc_proc_write 3 12076 NULL
124308 +batadv_tt_global_size_mod_12085 batadv_tt_global_size_mod 3 12085 NULL
124309 +rtw_malloc2d_12102 rtw_malloc2d 1-2-3 12102 NULL
124310 +alloc_bulk_urbs_generic_12127 alloc_bulk_urbs_generic 5 12127 NULL
124311 +set_powered_12129 set_powered 4 12129 NULL
124312 +ramoops_init_prz_12134 ramoops_init_prz 5 12134 NULL
124313 +xfs_handle_to_dentry_12135 xfs_handle_to_dentry 3 12135 NULL
124314 +rawv6_seticmpfilter_12137 rawv6_seticmpfilter 5 12137 NULL
124315 +rawsock_recvmsg_12144 rawsock_recvmsg 4 12144 NULL
124316 +get_idx_gc_leb_12148 get_idx_gc_leb 0 12148 NULL
124317 +btmrvl_sdio_host_to_card_12152 btmrvl_sdio_host_to_card 3 12152 NULL
124318 +vmbus_open_12154 vmbus_open 2-3 12154 NULL
124319 +fnic_reset_stats_write_12177 fnic_reset_stats_write 3 12177 NULL
124320 +LNetEQAlloc_12178 LNetEQAlloc 1 12178 NULL
124321 +ddp_make_gl_12179 ddp_make_gl 1 12179 NULL
124322 +compat_do_arpt_set_ctl_12184 compat_do_arpt_set_ctl 4 12184 NULL
124323 +ip_generic_getfrag_12187 ip_generic_getfrag 3-4 12187 NULL
124324 +snd_pcm_kernel_ioctl_12219 snd_pcm_kernel_ioctl 0 12219 NULL
124325 +fuse_get_req_12221 fuse_get_req 2 12221 NULL nohasharray
124326 +aat2870_reg_read_file_12221 aat2870_reg_read_file 3 12221 &fuse_get_req_12221
124327 +__alloc_bootmem_low_nopanic_12235 __alloc_bootmem_low_nopanic 1 12235 NULL
124328 +usnic_ib_qp_grp_dump_rows_12239 usnic_ib_qp_grp_dump_rows 3 12239 NULL
124329 +ib_uverbs_unmarshall_recv_12251 ib_uverbs_unmarshall_recv 5 12251 NULL
124330 +shash_compat_setkey_12267 shash_compat_setkey 3 12267 NULL
124331 +add_sctp_bind_addr_12269 add_sctp_bind_addr 3 12269 NULL
124332 +note_last_dentry_12285 note_last_dentry 3 12285 NULL
124333 +roundup_to_multiple_of_64_12288 roundup_to_multiple_of_64 0-1 12288 NULL nohasharray
124334 +il_dbgfs_nvm_read_12288 il_dbgfs_nvm_read 3 12288 &roundup_to_multiple_of_64_12288
124335 +bt_sock_recvmsg_12316 bt_sock_recvmsg 4 12316 NULL
124336 +usnic_transport_sock_to_str_12322 usnic_transport_sock_to_str 2-0 12322 NULL
124337 +pcbit_writecmd_12332 pcbit_writecmd 2 12332 NULL
124338 +mptctl_ioctl_12355 mptctl_ioctl 2 12355 NULL
124339 +__nf_ct_ext_add_length_12364 __nf_ct_ext_add_length 3 12364 NULL
124340 +xfs_iext_inline_to_direct_12384 xfs_iext_inline_to_direct 2 12384 NULL
124341 +btrfs_file_extent_ram_bytes_12391 btrfs_file_extent_ram_bytes 0 12391 NULL nohasharray
124342 +write_file_dump_12391 write_file_dump 3 12391 &btrfs_file_extent_ram_bytes_12391
124343 +hbucket_elem_add_12416 hbucket_elem_add 3 12416 NULL
124344 +ieee80211_if_read_num_mcast_sta_12419 ieee80211_if_read_num_mcast_sta 3 12419 NULL
124345 +cfs_array_alloc_12441 cfs_array_alloc 2 12441 NULL
124346 +skb_do_copy_data_nocache_12465 skb_do_copy_data_nocache 5 12465 NULL
124347 +x25_sendmsg_12487 x25_sendmsg 4 12487 NULL
124348 +fnic_trace_ctrl_read_12497 fnic_trace_ctrl_read 3 12497 NULL
124349 +qib_alloc_fast_reg_mr_12526 qib_alloc_fast_reg_mr 2 12526 NULL
124350 +hvc_alloc_12579 hvc_alloc 4 12579 NULL
124351 +pcpu_extend_area_map_12589 pcpu_extend_area_map 2 12589 NULL
124352 +_iwl_dbgfs_prph_reg_write_12597 _iwl_dbgfs_prph_reg_write 3 12597 NULL
124353 +tlbflush_write_file_12598 tlbflush_write_file 3 12598 NULL
124354 +vhci_put_user_12604 vhci_put_user 4 12604 NULL
124355 +sdhci_pltfm_init_12627 sdhci_pltfm_init 3 12627 NULL
124356 +pwr_rcvd_awake_bcns_cnt_read_12632 pwr_rcvd_awake_bcns_cnt_read 3 12632 NULL
124357 +pn_sendmsg_12640 pn_sendmsg 4 12640 NULL
124358 +dwc3_link_state_write_12641 dwc3_link_state_write 3 12641 NULL
124359 +nr_recvmsg_12649 nr_recvmsg 4 12649 NULL
124360 +rtw_android_get_link_speed_12655 rtw_android_get_link_speed 0 12655 NULL
124361 +ocfs2_read_block_12659 ocfs2_read_block 0 12659 NULL
124362 +sparse_mem_maps_populate_node_12669 sparse_mem_maps_populate_node 4 12669 NULL nohasharray
124363 +sel_read_class_12669 sel_read_class 3 12669 &sparse_mem_maps_populate_node_12669
124364 +ext4_writepage_trans_blocks_12674 ext4_writepage_trans_blocks 0 12674 NULL
124365 +iwl_dbgfs_calib_disabled_write_12707 iwl_dbgfs_calib_disabled_write 3 12707 NULL
124366 +ieee80211_if_read_num_buffered_multicast_12716 ieee80211_if_read_num_buffered_multicast 3 12716 NULL
124367 +ivtv_write_12721 ivtv_write 3 12721 NULL
124368 +key_rx_spec_read_12736 key_rx_spec_read 3 12736 NULL
124369 +__mei_cl_async_send_12737 __mei_cl_async_send 3 12737 NULL
124370 +ieee80211_if_read_dot11MeshMaxRetries_12756 ieee80211_if_read_dot11MeshMaxRetries 3 12756 NULL
124371 +listxattr_12769 listxattr 3 12769 NULL
124372 +sctp_ssnmap_init_12772 sctp_ssnmap_init 3-2 12772 NULL
124373 +scsi_adjust_queue_depth_12802 scsi_adjust_queue_depth 3 12802 NULL
124374 +xfs_inumbers_fmt_12817 xfs_inumbers_fmt 3 12817 NULL
124375 +SyS_add_key_12834 SyS_add_key 4 12834 NULL
124376 +TSS_authhmac_12839 TSS_authhmac 3 12839 NULL
124377 +spidev_sync_12842 spidev_sync 0 12842 NULL
124378 +spidev_ioctl_12846 spidev_ioctl 2 12846 NULL
124379 +ath9k_dump_4k_modal_eeprom_12883 ath9k_dump_4k_modal_eeprom 3-2 12883 NULL
124380 +get_leb_cnt_12892 get_leb_cnt 0-2 12892 NULL
124381 +get_virtual_node_size_12908 get_virtual_node_size 0 12908 NULL
124382 +rds_pages_in_vec_12922 rds_pages_in_vec 0 12922 NULL
124383 +do_inode_permission_12946 do_inode_permission 0 12946 NULL
124384 +bm_status_write_12964 bm_status_write 3 12964 NULL
124385 +raid56_parity_recover_12987 raid56_parity_recover 5 12987 NULL
124386 +TransmitTcb_12989 TransmitTcb 4 12989 NULL
124387 +sk_peek_offset_12991 sk_peek_offset 0 12991 NULL
124388 +bset_prev_bytes_13020 bset_prev_bytes 0 13020 NULL
124389 +subsystem_filter_write_13022 subsystem_filter_write 3 13022 NULL
124390 +ocfs2_write_begin_13045 ocfs2_write_begin 3-4 13045 NULL
124391 +__dn_setsockopt_13060 __dn_setsockopt 5 13060 NULL nohasharray
124392 +ptlrpc_lprocfs_threads_min_seq_write_13060 ptlrpc_lprocfs_threads_min_seq_write 3 13060 &__dn_setsockopt_13060
124393 +xattr_getsecurity_13090 xattr_getsecurity 0 13090 NULL
124394 +ttm_dma_pool_alloc_new_pages_13105 ttm_dma_pool_alloc_new_pages 3 13105 NULL
124395 +snd_rme96_playback_copy_13111 snd_rme96_playback_copy 5 13111 NULL
124396 +bfad_debugfs_read_13119 bfad_debugfs_read 3 13119 NULL
124397 +blk_update_request_13146 blk_update_request 3 13146 NULL
124398 +caif_stream_recvmsg_13173 caif_stream_recvmsg 4 13173 NULL
124399 +pwr_disable_ps_read_13176 pwr_disable_ps_read 3 13176 NULL
124400 +ucs2_strlen_13178 ucs2_strlen 0 13178 NULL
124401 +dgrp_net_ioctl_13183 dgrp_net_ioctl 2 13183 NULL
124402 +create_trace_uprobe_13184 create_trace_uprobe 1 13184 NULL
124403 +comedi_read_13199 comedi_read 3 13199 NULL
124404 +hash_ipport4_expire_13201 hash_ipport4_expire 4 13201 NULL
124405 +mmc_ext_csd_read_13205 mmc_ext_csd_read 3 13205 NULL
124406 +svm_msrpm_offset_13220 svm_msrpm_offset 0-1 13220 NULL
124407 +fnic_trace_ctrl_write_13229 fnic_trace_ctrl_write 3 13229 NULL
124408 +_iwl_dbgfs_disable_power_off_write_13243 _iwl_dbgfs_disable_power_off_write 3 13243 NULL
124409 +asix_read_cmd_13245 asix_read_cmd 5 13245 NULL
124410 +init_tid_tabs_13252 init_tid_tabs 2-3-4 13252 NULL
124411 +bio_integrity_trim_13259 bio_integrity_trim 3-2 13259 NULL
124412 +simple_attr_write_13260 simple_attr_write 3 13260 NULL
124413 +pmcraid_notify_aen_13274 pmcraid_notify_aen 3 13274 NULL
124414 +il4965_stats_flag_13281 il4965_stats_flag 3-0 13281 NULL
124415 +lpfc_idiag_mbxacc_get_setup_13282 lpfc_idiag_mbxacc_get_setup 0 13282 NULL
124416 +nvkm_i2c_pad_create__13292 nvkm_i2c_pad_create_ 5 13292 NULL
124417 +sd_major_13294 sd_major 0-1 13294 NULL
124418 +read_file_phy_err_13318 read_file_phy_err 3 13318 NULL
124419 +kvm_read_nested_guest_page_13337 kvm_read_nested_guest_page 5 13337 NULL
124420 +round_event_name_len_13348 round_event_name_len 0 13348 NULL
124421 +iso_sched_alloc_13377 iso_sched_alloc 1 13377 NULL nohasharray
124422 +wep_key_not_found_read_13377 wep_key_not_found_read 3 13377 &iso_sched_alloc_13377
124423 +ext4_meta_trans_blocks_13380 ext4_meta_trans_blocks 0-3-2 13380 NULL
124424 +lov_mds_md_size_13388 lov_mds_md_size 0-1 13388 NULL nohasharray
124425 +dis_bypass_write_13388 dis_bypass_write 3 13388 &lov_mds_md_size_13388
124426 +netxen_alloc_sds_rings_13417 netxen_alloc_sds_rings 2 13417 NULL
124427 +sctp_setsockopt_peer_primary_addr_13440 sctp_setsockopt_peer_primary_addr 3 13440 NULL
124428 +ath6kl_cfg80211_connect_event_13443 ath6kl_cfg80211_connect_event 7-8-9 13443 NULL
124429 +sb_init_dio_done_wq_13482 sb_init_dio_done_wq 0 13482 NULL
124430 +data_read_13494 data_read 3 13494 NULL nohasharray
124431 +ext_prop_data_store_13494 ext_prop_data_store 3 13494 &data_read_13494
124432 +core_status_13515 core_status 4 13515 NULL
124433 +smk_write_mapped_13519 smk_write_mapped 3 13519 NULL
124434 +bm_init_13529 bm_init 2 13529 NULL
124435 +llcp_sock_recvmsg_13556 llcp_sock_recvmsg 4 13556 NULL
124436 +ieee80211_if_read_ap_power_level_13558 ieee80211_if_read_ap_power_level 3 13558 NULL
124437 +hash_net4_expire_13559 hash_net4_expire 4 13559 NULL
124438 +read_file_antenna_13574 read_file_antenna 3 13574 NULL
124439 +cache_write_13589 cache_write 3 13589 NULL
124440 +Rd_Indx_13602 Rd_Indx 3-2 13602 NULL
124441 +wm8994_bulk_write_13615 wm8994_bulk_write 2-3 13615 NULL
124442 +pmcraid_get_minor_13619 pmcraid_get_minor 0 13619 NULL
124443 +packet_snd_13634 packet_snd 3 13634 NULL
124444 +blk_msg_write_13655 blk_msg_write 3 13655 NULL
124445 +cache_downcall_13666 cache_downcall 3 13666 NULL
124446 +fw_iso_buffer_alloc_13704 fw_iso_buffer_alloc 2 13704 NULL
124447 +audit_unpack_string_13748 audit_unpack_string 3 13748 NULL
124448 +udf_direct_IO_13765 udf_direct_IO 4 13765 NULL
124449 +ieee802154_alloc_device_13767 ieee802154_alloc_device 1 13767 NULL
124450 +fb_sys_read_13778 fb_sys_read 3 13778 NULL
124451 +ath6kl_mgmt_powersave_ap_13791 ath6kl_mgmt_powersave_ap 6 13791 NULL
124452 +random_read_13815 random_read 3 13815 NULL
124453 +mutex_lock_interruptible_nested_13817 mutex_lock_interruptible_nested 0 13817 NULL
124454 +hsi_register_board_info_13820 hsi_register_board_info 2 13820 NULL
124455 +___mei_cl_send_13821 ___mei_cl_send 3 13821 NULL
124456 +enc_pools_insert_13849 enc_pools_insert 3 13849 NULL
124457 +evdev_ioctl_compat_13851 evdev_ioctl_compat 2 13851 NULL
124458 +compat_ip_setsockopt_13870 compat_ip_setsockopt 5 13870 NULL
124459 +qp_memcpy_to_queue_13886 qp_memcpy_to_queue 5-2 13886 NULL
124460 +snd_pcm_aio_read_13900 snd_pcm_aio_read 3 13900 NULL
124461 +cfg80211_inform_bss_width_13933 cfg80211_inform_bss_width 9 13933 NULL
124462 +ext3_xattr_block_get_13936 ext3_xattr_block_get 0 13936 NULL
124463 +ieee80211_if_read_dot11MeshForwarding_13940 ieee80211_if_read_dot11MeshForwarding 3 13940 NULL nohasharray
124464 +ocfs2_xa_value_truncate_13940 ocfs2_xa_value_truncate 2 13940 &ieee80211_if_read_dot11MeshForwarding_13940
124465 +iwl_dbgfs_protection_mode_read_13943 iwl_dbgfs_protection_mode_read 3 13943 NULL
124466 +ieee80211_if_read_min_discovery_timeout_13946 ieee80211_if_read_min_discovery_timeout 3 13946 NULL
124467 +lpfc_idiag_queacc_read_13950 lpfc_idiag_queacc_read 3 13950 NULL
124468 +osc_grant_shrink_interval_seq_write_13952 osc_grant_shrink_interval_seq_write 3 13952 NULL
124469 +snd_pcm_plug_slave_size_13967 snd_pcm_plug_slave_size 0-2 13967 NULL
124470 +qcam_read_13977 qcam_read 3 13977 NULL
124471 +dsp_read_13980 dsp_read 2 13980 NULL
124472 +dvb_demux_read_13981 dvb_demux_read 3 13981 NULL
124473 +sddr09_write_data_14014 sddr09_write_data 3 14014 NULL
124474 +btrfs_get_blocks_direct_14016 btrfs_get_blocks_direct 2 14016 NULL
124475 +dmi_format_ids_14018 dmi_format_ids 2 14018 NULL
124476 +iscsi_create_flashnode_conn_14022 iscsi_create_flashnode_conn 4 14022 NULL
124477 +pci_add_ext_cap_save_buffer_14032 pci_add_ext_cap_save_buffer 3 14032 NULL
124478 +dvb_usercopy_14036 dvb_usercopy 2 14036 NULL
124479 +ieee80211_if_fmt_aid_14055 ieee80211_if_fmt_aid 3 14055 NULL
124480 +ovs_nla_alloc_flow_actions_14056 ovs_nla_alloc_flow_actions 1 14056 NULL
124481 +sta_agg_status_read_14058 sta_agg_status_read 3 14058 NULL
124482 +lov_stripeoffset_seq_write_14078 lov_stripeoffset_seq_write 3 14078 NULL
124483 +do_proc_readlink_14096 do_proc_readlink 3 14096 NULL
124484 +ext4_journal_blocks_per_page_14127 ext4_journal_blocks_per_page 0 14127 NULL
124485 +isku_sysfs_read_light_14140 isku_sysfs_read_light 6 14140 NULL
124486 +em_canid_change_14150 em_canid_change 3 14150 NULL
124487 +gsm_dlci_data_14155 gsm_dlci_data 3 14155 NULL
124488 +midi_alloc_ep_req_14159 midi_alloc_ep_req 2 14159 NULL
124489 +print_input_mask_14168 print_input_mask 3-0 14168 NULL
124490 +ocfs2_xattr_value_truncate_14183 ocfs2_xattr_value_truncate 3 14183 NULL
124491 +datafab_read_data_14186 datafab_read_data 4 14186 NULL
124492 +hfsplus_brec_find_14200 hfsplus_brec_find 0 14200 NULL
124493 +alloc_async_14208 alloc_async 1 14208 NULL
124494 +ath6kl_regread_write_14220 ath6kl_regread_write 3 14220 NULL
124495 +ieee80211_if_write_uapsd_max_sp_len_14233 ieee80211_if_write_uapsd_max_sp_len 3 14233 NULL
124496 +dma_declare_coherent_memory_14244 dma_declare_coherent_memory 4 14244 NULL
124497 +btrfs_token_file_extent_ram_bytes_14247 btrfs_token_file_extent_ram_bytes 0 14247 NULL
124498 +ath6kl_connect_event_14267 ath6kl_connect_event 7-8-9 14267 NULL
124499 +rr_status_14293 rr_status 5 14293 NULL
124500 +read_default_ldt_14302 read_default_ldt 2 14302 NULL
124501 +oo_objects_14319 oo_objects 0 14319 NULL
124502 +p9_client_zc_rpc_14345 p9_client_zc_rpc 7 14345 NULL
124503 +alloc_tx_struct_14349 alloc_tx_struct 1 14349 NULL
124504 +hash_ipportnet4_expire_14354 hash_ipportnet4_expire 4 14354 NULL
124505 +snd_pcm_lib_readv_14363 snd_pcm_lib_readv 0-3 14363 NULL
124506 +lowpan_read_14369 lowpan_read 3 14369 NULL
124507 +ath6kl_regdump_read_14393 ath6kl_regdump_read 3 14393 NULL
124508 +smk_write_onlycap_14400 smk_write_onlycap 3 14400 NULL
124509 +mtd_concat_create_14416 mtd_concat_create 2 14416 NULL
124510 +_iwl_dbgfs_sram_write_14439 _iwl_dbgfs_sram_write 3 14439 NULL
124511 +block_size_14443 block_size 0 14443 NULL
124512 +lmv_user_md_size_14456 lmv_user_md_size 0-1 14456 NULL
124513 +snd_emu10k1_proc_spdif_status_14457 snd_emu10k1_proc_spdif_status 4-5 14457 NULL
124514 +ath10k_write_htt_stats_mask_14458 ath10k_write_htt_stats_mask 3 14458 NULL
124515 +lustre_msg_size_v2_14470 lustre_msg_size_v2 0 14470 NULL
124516 +udplite_getfrag_14479 udplite_getfrag 3-4 14479 NULL
124517 +ieee80211_if_read_dot11MeshGateAnnouncementProtocol_14486 ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 NULL
124518 +ocfs2_debug_read_14507 ocfs2_debug_read 3 14507 NULL
124519 +dataflash_read_user_otp_14536 dataflash_read_user_otp 3-2 14536 NULL nohasharray
124520 +ep0_write_14536 ep0_write 3 14536 &dataflash_read_user_otp_14536
124521 +picolcd_debug_eeprom_read_14549 picolcd_debug_eeprom_read 3 14549 NULL
124522 +qp_host_alloc_queue_14566 qp_host_alloc_queue 1 14566 NULL
124523 +SyS_setdomainname_14569 SyS_setdomainname 2 14569 NULL
124524 +idmap_pipe_downcall_14591 idmap_pipe_downcall 3 14591 NULL
124525 +ceph_osdc_alloc_request_14597 ceph_osdc_alloc_request 3 14597 NULL
124526 +dbJoin_14644 dbJoin 0 14644 NULL
124527 +profile_replace_14652 profile_replace 3 14652 NULL
124528 +usnic_vnic_dump_14662 usnic_vnic_dump 3 14662 NULL
124529 +min_bytes_needed_14675 min_bytes_needed 0 14675 NULL
124530 +nvme_trans_log_info_exceptions_14677 nvme_trans_log_info_exceptions 3 14677 NULL
124531 +pipeline_enc_tx_stat_fifo_int_read_14680 pipeline_enc_tx_stat_fifo_int_read 3 14680 NULL
124532 +ieee80211_if_fmt_rc_rateidx_mask_2ghz_14683 ieee80211_if_fmt_rc_rateidx_mask_2ghz 3 14683 NULL
124533 +SyS_fsetxattr_14702 SyS_fsetxattr 4 14702 NULL
124534 +persistent_ram_ecc_string_14704 persistent_ram_ecc_string 0 14704 NULL
124535 +u_audio_playback_14709 u_audio_playback 3 14709 NULL
124536 +rtw_cbuf_alloc_14710 rtw_cbuf_alloc 1 14710 NULL
124537 +vfd_write_14717 vfd_write 3 14717 NULL
124538 +__blk_end_request_14729 __blk_end_request 3 14729 NULL
124539 +raid1_resize_14740 raid1_resize 2 14740 NULL
124540 +i915_error_state_buf_init_14742 i915_error_state_buf_init 2 14742 NULL
124541 +btrfs_inode_extref_name_len_14752 btrfs_inode_extref_name_len 0 14752 NULL
124542 +rx_rx_cmplt_read_14753 rx_rx_cmplt_read 3 14753 NULL
124543 +regmap_range_read_file_14775 regmap_range_read_file 3 14775 NULL
124544 +sta_dev_read_14782 sta_dev_read 3 14782 NULL
124545 +keys_proc_write_14792 keys_proc_write 3 14792 NULL
124546 +ext4_kvmalloc_14796 ext4_kvmalloc 1 14796 NULL
124547 +__kfifo_in_14797 __kfifo_in 3-0 14797 NULL
124548 +hpet_readl_14801 hpet_readl 0 14801 NULL nohasharray
124549 +snd_als300_gcr_read_14801 snd_als300_gcr_read 0 14801 &hpet_readl_14801
124550 +mrp_attr_create_14853 mrp_attr_create 3 14853 NULL
124551 +lcd_write_14857 lcd_write 3 14857 NULL
124552 +get_user_cpu_mask_14861 get_user_cpu_mask 2 14861 NULL
124553 +acpi_os_allocate_14892 acpi_os_allocate 1 14892 NULL
124554 +SYSC_readv_14901 SYSC_readv 3 14901 NULL
124555 +__arch_hweight64_14923 __arch_hweight64 0 14923 NULL nohasharray
124556 +qp_memcpy_to_queue_iov_14923 qp_memcpy_to_queue_iov 5-2 14923 &__arch_hweight64_14923
124557 +ocfs2_expand_nonsparse_inode_14936 ocfs2_expand_nonsparse_inode 3-4 14936 NULL
124558 +queue_cnt_14951 queue_cnt 0 14951 NULL
124559 +unix_dgram_recvmsg_14952 unix_dgram_recvmsg 4 14952 NULL
124560 +videobuf_read_stream_14956 videobuf_read_stream 3 14956 NULL
124561 +mce_flush_rx_buffer_14976 mce_flush_rx_buffer 2 14976 NULL
124562 +setkey_14987 setkey 3 14987 NULL nohasharray
124563 +gpio_twl4030_write_14987 gpio_twl4030_write 1 14987 &setkey_14987
124564 +blk_integrity_tuple_size_15027 blk_integrity_tuple_size 0 15027 NULL
124565 +read_file_node_aggr_15040 read_file_node_aggr 3 15040 NULL
124566 +cld_pipe_downcall_15058 cld_pipe_downcall 3 15058 NULL
124567 +ieee80211_if_read_uapsd_max_sp_len_15067 ieee80211_if_read_uapsd_max_sp_len 3 15067 NULL
124568 +nfs4_write_cached_acl_15070 nfs4_write_cached_acl 4 15070 NULL
124569 +ntfs_copy_from_user_15072 ntfs_copy_from_user 3-5-0 15072 NULL
124570 +pppoe_recvmsg_15073 pppoe_recvmsg 4 15073 NULL
124571 +smscore_load_firmware_family2_15086 smscore_load_firmware_family2 3 15086 NULL
124572 +compat_SyS_pwritev_15118 compat_SyS_pwritev 3 15118 NULL
124573 +hex_dump_to_buffer_15121 hex_dump_to_buffer 6 15121 NULL
124574 +start_port_15124 start_port 0 15124 NULL
124575 +ipwireless_ppp_mru_15153 ipwireless_ppp_mru 0 15153 NULL
124576 +self_check_not_bad_15175 self_check_not_bad 0 15175 NULL
124577 +SYSC_setdomainname_15180 SYSC_setdomainname 2 15180 NULL
124578 +iscsi_create_endpoint_15193 iscsi_create_endpoint 1 15193 NULL
124579 +mtt_alloc_res_15211 mtt_alloc_res 5 15211 NULL
124580 +bfad_debugfs_write_regrd_15218 bfad_debugfs_write_regrd 3 15218 NULL
124581 +iwl_dbgfs_sram_write_15239 iwl_dbgfs_sram_write 3 15239 NULL
124582 +il_dbgfs_rx_stats_read_15243 il_dbgfs_rx_stats_read 3 15243 NULL
124583 +simple_strtol_15273 simple_strtol 0 15273 NULL
124584 +fw_realloc_buffer_15280 fw_realloc_buffer 2 15280 NULL
124585 +kovaplus_sysfs_read_15337 kovaplus_sysfs_read 6 15337 NULL
124586 +ioread16_15342 ioread16 0 15342 NULL
124587 +ept_prefetch_gpte_15348 ept_prefetch_gpte 4 15348 NULL
124588 +acpi_ut_create_string_object_15360 acpi_ut_create_string_object 1 15360 NULL
124589 +graph_depth_read_15371 graph_depth_read 3 15371 NULL
124590 +fq_codel_zalloc_15378 fq_codel_zalloc 1 15378 NULL
124591 +alloc_fddidev_15382 alloc_fddidev 1 15382 NULL
124592 +pipeline_csum_to_rx_xfer_swi_read_15403 pipeline_csum_to_rx_xfer_swi_read 3 15403 NULL
124593 +get_modalias_15406 get_modalias 2 15406 NULL
124594 +__videobuf_copy_to_user_15423 __videobuf_copy_to_user 4-0 15423 NULL
124595 +tcp_mtu_to_mss_15438 tcp_mtu_to_mss 0-2 15438 NULL
124596 +hpsa_change_queue_depth_15449 hpsa_change_queue_depth 2 15449 NULL
124597 +__clone_and_map_data_bio_15498 __clone_and_map_data_bio 3 15498 NULL
124598 +insert_old_idx_znode_15500 insert_old_idx_znode 0 15500 NULL
124599 +zd_chip_is_zd1211b_15518 zd_chip_is_zd1211b 0 15518 NULL
124600 +ifx_spi_write_15531 ifx_spi_write 3 15531 NULL
124601 +p9_check_zc_errors_15534 p9_check_zc_errors 4 15534 NULL
124602 +xfrm_state_mtu_15548 xfrm_state_mtu 0-2 15548 NULL
124603 +persistent_status_15574 persistent_status 4 15574 NULL
124604 +bnx2fc_process_unsol_compl_15576 bnx2fc_process_unsol_compl 2 15576 NULL
124605 +vme_user_write_15587 vme_user_write 3 15587 NULL
124606 +compat_fillonedir_15620 compat_fillonedir 3 15620 NULL
124607 +proc_loginuid_read_15631 proc_loginuid_read 3 15631 NULL
124608 +tomoyo_scan_bprm_15642 tomoyo_scan_bprm 2-4 15642 NULL nohasharray
124609 +pipeline_hs_tx_stat_fifo_int_read_15642 pipeline_hs_tx_stat_fifo_int_read 3 15642 &tomoyo_scan_bprm_15642 nohasharray
124610 +sk_memory_allocated_add_15642 sk_memory_allocated_add 2 15642 &pipeline_hs_tx_stat_fifo_int_read_15642
124611 +joydev_handle_JSIOCSBTNMAP_15643 joydev_handle_JSIOCSBTNMAP 3 15643 NULL
124612 +fs_path_add_15648 fs_path_add 3 15648 NULL
124613 +xsd_read_15653 xsd_read 3 15653 NULL
124614 +unix_bind_15668 unix_bind 3 15668 NULL
124615 +SyS_connect_15674 SyS_connect 3 15674 NULL nohasharray
124616 +dm_read_15674 dm_read 3 15674 &SyS_connect_15674
124617 +uinput_str_to_user_15695 uinput_str_to_user 3 15695 NULL
124618 +__sk_migrate_realloc_15709 __sk_migrate_realloc 3 15709 NULL
124619 +tracing_snapshot_write_15719 tracing_snapshot_write 3 15719 NULL
124620 +HiSax_readstatus_15752 HiSax_readstatus 2 15752 NULL
124621 +smk_read_direct_15803 smk_read_direct 3 15803 NULL
124622 +gnttab_expand_15817 gnttab_expand 1 15817 NULL nohasharray
124623 +nameseq_list_15817 nameseq_list 3-0 15817 &gnttab_expand_15817
124624 +afs_proc_rootcell_write_15822 afs_proc_rootcell_write 3 15822 NULL
124625 +table_size_15851 table_size 0-1-2 15851 NULL
124626 +write_file_tx99_15856 write_file_tx99 3 15856 NULL
124627 +media_entity_init_15870 media_entity_init 2-4 15870 NULL nohasharray
124628 +ubi_io_write_15870 ubi_io_write 0 15870 &media_entity_init_15870
124629 +__mptctl_ioctl_15875 __mptctl_ioctl 2 15875 NULL
124630 +parse_audio_stream_data_15937 parse_audio_stream_data 3 15937 NULL
124631 +power_read_15939 power_read 3 15939 NULL
124632 +lpfc_idiag_drbacc_read_15948 lpfc_idiag_drbacc_read 3 15948 NULL
124633 +snd_pcm_lib_read_transfer_15952 snd_pcm_lib_read_transfer 5-2-4 15952 NULL
124634 +memblock_virt_alloc_try_nid_15954 memblock_virt_alloc_try_nid 1 15954 NULL
124635 +smk_read_ptrace_15974 smk_read_ptrace 3 15974 NULL
124636 +viafb_vt1636_proc_write_16018 viafb_vt1636_proc_write 3 16018 NULL
124637 +dccp_recvmsg_16056 dccp_recvmsg 4 16056 NULL
124638 +read_file_spectral_period_16057 read_file_spectral_period 3 16057 NULL
124639 +si5351_msynth_params_address_16062 si5351_msynth_params_address 0-1 16062 NULL
124640 +isr_tx_exch_complete_read_16103 isr_tx_exch_complete_read 3 16103 NULL
124641 +isr_hw_pm_mode_changes_read_16110 isr_hw_pm_mode_changes_read 3 16110 NULL nohasharray
124642 +dma_tx_requested_read_16110 dma_tx_requested_read 3 16110 &isr_hw_pm_mode_changes_read_16110
124643 +snd_dma_pointer_16126 snd_dma_pointer 0-2 16126 NULL
124644 +fsm_init_16134 fsm_init 2 16134 NULL
124645 +ext4_xattr_block_get_16148 ext4_xattr_block_get 0 16148 NULL
124646 +optimal_reclaimed_pages_16172 optimal_reclaimed_pages 0 16172 NULL
124647 +mapping_level_16188 mapping_level 0-2 16188 NULL
124648 +i40e_allocate_virt_mem_d_16191 i40e_allocate_virt_mem_d 3 16191 NULL
124649 +ath10k_htt_rx_ring_size_16201 ath10k_htt_rx_ring_size 0 16201 NULL
124650 +cipso_v4_map_cat_rng_hton_16203 cipso_v4_map_cat_rng_hton 0 16203 NULL
124651 +SyS_pselect6_16210 SyS_pselect6 1 16210 NULL
124652 +create_table_16213 create_table 2 16213 NULL
124653 +ath9k_hw_ar9287_dump_eeprom_16224 ath9k_hw_ar9287_dump_eeprom 5-4 16224 NULL
124654 +atomic_read_file_16227 atomic_read_file 3 16227 NULL
124655 +BcmGetSectionValStartOffset_16235 BcmGetSectionValStartOffset 0 16235 NULL
124656 +lov_prep_brw_set_16246 lov_prep_brw_set 3 16246 NULL
124657 +i40e_dbg_dump_read_16247 i40e_dbg_dump_read 3 16247 NULL
124658 +il_dbgfs_disable_ht40_write_16249 il_dbgfs_disable_ht40_write 3 16249 NULL
124659 +SyS_fgetxattr_16254 SyS_fgetxattr 4 16254 NULL
124660 +reiserfs_acl_count_16265 reiserfs_acl_count 0-1 16265 NULL
124661 +ocfs2_xattr_bucket_value_truncate_16279 ocfs2_xattr_bucket_value_truncate 4 16279 NULL
124662 +drbd_setsockopt_16280 drbd_setsockopt 5 16280 NULL nohasharray
124663 +nand_bch_init_16280 nand_bch_init 3-2 16280 &drbd_setsockopt_16280
124664 +account_16283 account 0-4-2 16283 NULL nohasharray
124665 +mirror_status_16283 mirror_status 5 16283 &account_16283
124666 +jumpshot_read_data_16287 jumpshot_read_data 4 16287 NULL
124667 +mo_xattr_get_16288 mo_xattr_get 0 16288 NULL
124668 +stk_allocate_buffers_16291 stk_allocate_buffers 2 16291 NULL
124669 +rbd_segment_offset_16293 rbd_segment_offset 0-2 16293 NULL
124670 +rsc_mgr_init_16299 rsc_mgr_init 3 16299 NULL
124671 +kvm_handle_hva_range_16312 kvm_handle_hva_range 3-2 16312 NULL
124672 +total_ps_buffered_read_16365 total_ps_buffered_read 3 16365 NULL
124673 +iscsi_tcp_conn_setup_16376 iscsi_tcp_conn_setup 2 16376 NULL
124674 +ieee80211_if_read_tsf_16420 ieee80211_if_read_tsf 3 16420 NULL
124675 +rxrpc_server_keyring_16431 rxrpc_server_keyring 3 16431 NULL
124676 +__bio_add_page_16435 __bio_add_page 0-4 16435 NULL
124677 +cmdline_store_16442 cmdline_store 4 16442 NULL
124678 +copy_from_user_bvec_16447 copy_from_user_bvec 0-4 16447 NULL
124679 +btrfs_truncate_inode_items_16452 btrfs_truncate_inode_items 4 16452 NULL
124680 +netlink_change_ngroups_16457 netlink_change_ngroups 2 16457 NULL
124681 +req_capsule_get_size_16467 req_capsule_get_size 0 16467 NULL
124682 +tracing_readme_read_16493 tracing_readme_read 3 16493 NULL
124683 +KEY_OFFSET_16504 KEY_OFFSET 0 16504 NULL
124684 +snd_interval_max_16529 snd_interval_max 0 16529 NULL
124685 +raid10_resize_16537 raid10_resize 2 16537 NULL
124686 +lpfc_debugfs_read_16566 lpfc_debugfs_read 3 16566 NULL
124687 +agp_allocate_memory_wrap_16576 agp_allocate_memory_wrap 1 16576 NULL
124688 +lustre_msg_hdr_size_v2_16589 lustre_msg_hdr_size_v2 0 16589 NULL
124689 +compat_SyS_migrate_pages_16618 compat_SyS_migrate_pages 2 16618 NULL
124690 +rtw_set_wpa_ie_16633 rtw_set_wpa_ie 3 16633 NULL
124691 +btrfs_get_token_32_16651 btrfs_get_token_32 0 16651 NULL
124692 +__wa_populate_dto_urb_16699 __wa_populate_dto_urb 3-4 16699 NULL
124693 +__proc_lnet_buffers_16717 __proc_lnet_buffers 5 16717 NULL
124694 +__copy_to_user_swizzled_16748 __copy_to_user_swizzled 3-4 16748 NULL
124695 +arcmsr_adjust_disk_queue_depth_16756 arcmsr_adjust_disk_queue_depth 2 16756 NULL
124696 +blk_rq_map_user_iov_16772 blk_rq_map_user_iov 5 16772 NULL
124697 +i2o_parm_issue_16790 i2o_parm_issue 0 16790 NULL
124698 +get_server_iovec_16804 get_server_iovec 2 16804 NULL
124699 +drm_malloc_ab_16831 drm_malloc_ab 1-2 16831 NULL
124700 +scsi_mode_sense_16835 scsi_mode_sense 5 16835 NULL
124701 +hfsplus_min_io_size_16859 hfsplus_min_io_size 0 16859 NULL
124702 +alloc_idx_lebs_16872 alloc_idx_lebs 2 16872 NULL
124703 +carl9170_debugfs_ampdu_state_read_16873 carl9170_debugfs_ampdu_state_read 3 16873 NULL
124704 +st_write_16874 st_write 3 16874 NULL
124705 +__kfifo_peek_n_16877 __kfifo_peek_n 0 16877 NULL
124706 +psb_unlocked_ioctl_16926 psb_unlocked_ioctl 2 16926 NULL nohasharray
124707 +snd_gf1_mem_proc_dump_16926 snd_gf1_mem_proc_dump 5 16926 &psb_unlocked_ioctl_16926
124708 +_sp2d_alloc_16944 _sp2d_alloc 1-2-3 16944 NULL
124709 +squashfs_read_table_16945 squashfs_read_table 3 16945 NULL
124710 +keyctl_instantiate_key_iov_16969 keyctl_instantiate_key_iov 3 16969 NULL
124711 +ceph_read_dir_17005 ceph_read_dir 3 17005 NULL
124712 +copy_counters_to_user_17027 copy_counters_to_user 5 17027 NULL
124713 +C_SYSC_keyctl_17041 C_SYSC_keyctl 4 17041 NULL
124714 +jffs2_trusted_setxattr_17048 jffs2_trusted_setxattr 4 17048 NULL
124715 +__arch_hweight32_17060 __arch_hweight32 0 17060 NULL
124716 +sddr55_read_data_17072 sddr55_read_data 4 17072 NULL
124717 +dvb_dvr_read_17073 dvb_dvr_read 3 17073 NULL
124718 +simple_transaction_read_17076 simple_transaction_read 3 17076 NULL
124719 +carl9170_debugfs_mem_usage_read_17084 carl9170_debugfs_mem_usage_read 3 17084 NULL
124720 +entry_length_17093 entry_length 0 17093 NULL
124721 +write_mem_17114 write_mem 3 17114 NULL
124722 +pvr2_hdw_state_report_17121 pvr2_hdw_state_report 3 17121 NULL
124723 +do_blockdev_direct_IO_17143 do_blockdev_direct_IO 0-6 17143 NULL
124724 +nouveau_instobj_create__17144 nouveau_instobj_create_ 4 17144 NULL
124725 +jumpshot_write_data_17151 jumpshot_write_data 4 17151 NULL
124726 +sep_read_17161 sep_read 3 17161 NULL
124727 +befs_nls2utf_17163 befs_nls2utf 3 17163 NULL
124728 +tx_tx_start_templates_read_17164 tx_tx_start_templates_read 3 17164 NULL
124729 +UniStrnlen_17169 UniStrnlen 0 17169 NULL
124730 +access_remote_vm_17189 access_remote_vm 0 17189 NULL nohasharray
124731 +iwl_dbgfs_txfifo_flush_write_17189 iwl_dbgfs_txfifo_flush_write 3 17189 &access_remote_vm_17189
124732 +driver_state_read_17194 driver_state_read 3 17194 NULL nohasharray
124733 +iscsit_find_cmd_from_itt_or_dump_17194 iscsit_find_cmd_from_itt_or_dump 3 17194 &driver_state_read_17194
124734 +sync_request_17208 sync_request 2 17208 NULL
124735 +dn_recvmsg_17213 dn_recvmsg 4 17213 NULL
124736 +lprocfs_read_frac_helper_17261 lprocfs_read_frac_helper 0 17261 NULL
124737 +error_error_frame_cts_nul_flid_read_17262 error_error_frame_cts_nul_flid_read 3 17262 NULL
124738 +alloc_ep_17269 alloc_ep 1 17269 NULL
124739 +pg_read_17276 pg_read 3 17276 NULL
124740 +raw_recvmsg_17277 raw_recvmsg 4 17277 NULL
124741 +hmac_sha256_17278 hmac_sha256 2 17278 NULL
124742 +neigh_hash_grow_17283 neigh_hash_grow 2 17283 NULL
124743 +minstrel_stats_read_17290 minstrel_stats_read 3 17290 NULL
124744 +ieee80211_if_fmt_dot11MeshForwarding_17301 ieee80211_if_fmt_dot11MeshForwarding 3 17301 NULL
124745 +mb_cache_create_17307 mb_cache_create 2 17307 NULL
124746 +gnttab_map_frames_v2_17314 gnttab_map_frames_v2 2 17314 NULL
124747 +ieee80211_if_read_dot11MeshHWMPperrMinInterval_17346 ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 NULL
124748 +ath6kl_wmi_send_mgmt_cmd_17347 ath6kl_wmi_send_mgmt_cmd 7 17347 NULL
124749 +mdc_import_seq_write_17409 mdc_import_seq_write 3 17409 NULL
124750 +lpfc_debugfs_dif_err_write_17424 lpfc_debugfs_dif_err_write 3 17424 NULL
124751 +sta_connected_time_read_17435 sta_connected_time_read 3 17435 NULL
124752 +libcfs_ipif_enumerate_17445 libcfs_ipif_enumerate 0 17445 NULL
124753 +nla_get_u32_17455 nla_get_u32 0 17455 NULL
124754 +__ref_totlen_17461 __ref_totlen 0 17461 NULL
124755 +probe_kernel_write_17481 probe_kernel_write 3 17481 NULL
124756 +TSS_rawhmac_17486 TSS_rawhmac 3 17486 NULL
124757 +copy_page_from_iter_17512 copy_page_from_iter 3-0 17512 NULL
124758 +reiserfs_direct_IO_17513 reiserfs_direct_IO 4 17513 NULL
124759 +lbs_highrssi_write_17515 lbs_highrssi_write 3 17515 NULL
124760 +qp_free_res_17541 qp_free_res 5 17541 NULL
124761 +__copy_to_user_17551 __copy_to_user 0-3 17551 NULL
124762 +copy_from_user_17559 copy_from_user 3-0 17559 NULL
124763 +hash_netport4_expire_17573 hash_netport4_expire 4 17573 NULL
124764 +acpi_ut_create_package_object_17594 acpi_ut_create_package_object 1 17594 NULL
124765 +neigh_hash_alloc_17595 neigh_hash_alloc 1 17595 NULL
124766 +osst_execute_17607 osst_execute 7-6 17607 NULL
124767 +ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout_17618 ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout 3 17618 NULL
124768 +dma_map_page_17628 dma_map_page 0 17628 NULL
124769 +twl4030_set_gpio_direction_17645 twl4030_set_gpio_direction 1 17645 NULL
124770 +SYSC_migrate_pages_17657 SYSC_migrate_pages 2 17657 NULL
124771 +packet_setsockopt_17662 packet_setsockopt 5 17662 NULL nohasharray
124772 +ubi_io_read_data_17662 ubi_io_read_data 0 17662 &packet_setsockopt_17662
124773 +pwr_enable_ps_read_17686 pwr_enable_ps_read 3 17686 NULL
124774 +venus_rename_17707 venus_rename 4-5 17707 NULL
124775 +exofs_read_lookup_dev_table_17733 exofs_read_lookup_dev_table 3 17733 NULL
124776 +sctpprobe_read_17741 sctpprobe_read 3 17741 NULL
124777 +ubifs_leb_change_17789 ubifs_leb_change 0 17789 NULL
124778 +shrink_slab_node_17794 shrink_slab_node 3 17794 NULL
124779 +lpuart_copy_rx_to_tty_17801 lpuart_copy_rx_to_tty 3 17801 NULL
124780 +gnet_stats_copy_app_17821 gnet_stats_copy_app 3 17821 NULL
124781 +cipso_v4_gentag_rbm_17836 cipso_v4_gentag_rbm 0 17836 NULL
124782 +em28xx_audio_ep_packet_size_17844 em28xx_audio_ep_packet_size 0 17844 NULL
124783 +dm_stats_message_17863 dm_stats_message 5 17863 NULL
124784 +sisusb_send_bulk_msg_17864 sisusb_send_bulk_msg 3 17864 NULL
124785 +alloc_sja1000dev_17868 alloc_sja1000dev 1 17868 NULL
124786 +virtio_cread32_17873 virtio_cread32 0 17873 NULL
124787 +ray_cs_essid_proc_write_17875 ray_cs_essid_proc_write 3 17875 NULL
124788 +orinoco_set_key_17878 orinoco_set_key 5-7 17878 NULL nohasharray
124789 +i40e_align_l2obj_base_17878 i40e_align_l2obj_base 0-1 17878 &orinoco_set_key_17878
124790 +init_per_cpu_17880 init_per_cpu 1 17880 NULL
124791 +ieee80211_if_fmt_dot11MeshMaxPeerLinks_17883 ieee80211_if_fmt_dot11MeshMaxPeerLinks 3 17883 NULL
124792 +ieee80211_if_fmt_dot11MeshHWMPRootMode_17890 ieee80211_if_fmt_dot11MeshHWMPRootMode 3 17890 NULL
124793 +dev_pm_opp_get_opp_count_17911 dev_pm_opp_get_opp_count 0 17911 NULL
124794 +xfs_buf_associate_memory_17915 xfs_buf_associate_memory 3 17915 NULL
124795 +tipc_port_iovec_rcv_17921 tipc_port_iovec_rcv 3 17921 NULL
124796 +scsi_bufflen_17933 scsi_bufflen 0 17933 NULL
124797 +__mutex_lock_check_stamp_17947 __mutex_lock_check_stamp 0 17947 NULL
124798 +beacon_interval_write_17952 beacon_interval_write 3 17952 NULL
124799 +calc_nr_buckets_17976 calc_nr_buckets 0 17976 NULL
124800 +ext4_ext_calc_credits_for_single_extent_17983 ext4_ext_calc_credits_for_single_extent 0-2 17983 NULL
124801 +smk_write_cipso_17989 smk_write_cipso 3 17989 NULL
124802 +gnttab_max_grant_frames_17993 gnttab_max_grant_frames 0 17993 NULL
124803 +pvr2_v4l2_read_18006 pvr2_v4l2_read 3 18006 NULL
124804 +o2hb_highest_node_18034 o2hb_highest_node 0 18034 NULL
124805 +cryptd_alloc_instance_18048 cryptd_alloc_instance 2-3 18048 NULL
124806 +__btrfs_drop_extents_18049 __btrfs_drop_extents 5 18049 NULL
124807 +ddebug_proc_write_18055 ddebug_proc_write 3 18055 NULL
124808 +lua_sysfs_read_18062 lua_sysfs_read 6 18062 NULL
124809 +fpregs_get_18066 fpregs_get 4 18066 NULL
124810 +kvm_read_guest_page_18074 kvm_read_guest_page 5 18074 NULL
124811 +SYSC_pselect6_18076 SYSC_pselect6 1 18076 NULL
124812 +SYSC_semtimedop_18091 SYSC_semtimedop 3 18091 NULL
124813 +mpi_alloc_18094 mpi_alloc 1 18094 NULL
124814 +dfs_file_read_18116 dfs_file_read 3 18116 NULL
124815 +svc_getnl_18120 svc_getnl 0 18120 NULL
124816 +paging32_gpte_to_gfn_lvl_18131 paging32_gpte_to_gfn_lvl 0-2-1 18131 NULL
124817 +selinux_inode_setsecurity_18148 selinux_inode_setsecurity 4 18148 NULL
124818 +is_idx_node_in_use_18165 is_idx_node_in_use 0 18165 NULL
124819 +pccard_store_cis_18176 pccard_store_cis 6 18176 NULL
124820 +orinoco_add_extscan_result_18207 orinoco_add_extscan_result 3 18207 NULL
124821 +gsm_control_message_18209 gsm_control_message 4 18209 NULL
124822 +do_ipv6_setsockopt_18215 do_ipv6_setsockopt 5 18215 NULL
124823 +gnttab_alloc_grant_references_18240 gnttab_alloc_grant_references 1 18240 NULL
124824 +alloc_trace_uprobe_18247 alloc_trace_uprobe 3 18247 NULL
124825 +rfcomm_sock_setsockopt_18254 rfcomm_sock_setsockopt 5 18254 NULL
124826 +qdisc_class_hash_alloc_18262 qdisc_class_hash_alloc 1 18262 NULL
124827 +gfs2_alloc_sort_buffer_18275 gfs2_alloc_sort_buffer 1 18275 NULL
124828 +alloc_ring_18278 alloc_ring 2-4 18278 NULL
124829 +find_dirty_idx_leb_18280 find_dirty_idx_leb 0 18280 NULL
124830 +bio_phys_segments_18281 bio_phys_segments 0 18281 NULL nohasharray
124831 +nouveau_subdev_create__18281 nouveau_subdev_create_ 7 18281 &bio_phys_segments_18281
124832 +ext4_readpages_18283 ext4_readpages 4 18283 NULL
124833 +mmc_send_bus_test_18285 mmc_send_bus_test 4 18285 NULL
124834 +um_idi_write_18293 um_idi_write 3 18293 NULL
124835 +nouveau_disp_create__18305 nouveau_disp_create_ 4-7 18305 NULL
124836 +class_add_profile_18315 class_add_profile 1-3-5 18315 NULL
124837 +csio_mem_read_18319 csio_mem_read 3 18319 NULL
124838 +alloc_and_copy_string_18321 alloc_and_copy_string 2 18321 NULL
124839 +ecryptfs_send_message_18322 ecryptfs_send_message 2 18322 NULL
124840 +bio_integrity_advance_18324 bio_integrity_advance 2 18324 NULL
124841 +copy_page_to_iter_18345 copy_page_to_iter 3-0 18345 NULL
124842 +lcd_proc_write_18351 lcd_proc_write 3 18351 NULL
124843 +pwr_power_save_off_read_18355 pwr_power_save_off_read 3 18355 NULL
124844 +SyS_process_vm_readv_18366 SyS_process_vm_readv 3-5 18366 NULL
124845 +ep_io_18367 ep_io 0 18367 NULL
124846 +qib_user_sdma_num_pages_18371 qib_user_sdma_num_pages 0 18371 NULL
124847 +__ceph_getxattr_18386 __ceph_getxattr 0 18386 NULL
124848 +ci_role_write_18388 ci_role_write 3 18388 NULL
124849 +adis16136_show_serial_18402 adis16136_show_serial 3 18402 NULL
124850 +memblock_virt_alloc_node_nopanic_18431 memblock_virt_alloc_node_nopanic 1 18431 NULL
124851 +iscsi_create_flashnode_sess_18433 iscsi_create_flashnode_sess 4 18433 NULL
124852 +snd_hda_get_connections_18437 snd_hda_get_connections 0 18437 NULL
124853 +fuse_perform_write_18457 fuse_perform_write 4 18457 NULL
124854 +regset_tls_set_18459 regset_tls_set 4 18459 NULL
124855 +pci_vpd_lrdt_size_18479 pci_vpd_lrdt_size 0 18479 NULL
124856 +udpv6_setsockopt_18487 udpv6_setsockopt 5 18487 NULL
124857 +btrfs_fiemap_18501 btrfs_fiemap 3 18501 NULL
124858 +__copy_user_zeroing_intel_18510 __copy_user_zeroing_intel 0-3 18510 NULL
124859 +snd_vx_inb_18514 snd_vx_inb 0 18514 NULL
124860 +snd_gus_dram_poke_18525 snd_gus_dram_poke 4 18525 NULL
124861 +nouveau_fifo_channel_create__18530 nouveau_fifo_channel_create_ 9 18530 NULL
124862 +tipc_send2port_18531 tipc_send2port 4 18531 NULL
124863 +seq_copy_in_user_18543 seq_copy_in_user 3 18543 NULL
124864 +sas_change_queue_depth_18555 sas_change_queue_depth 2 18555 NULL
124865 +smk_write_rules_list_18565 smk_write_rules_list 3 18565 NULL
124866 +debug_output_18575 debug_output 3 18575 NULL
124867 +filemap_fdatawait_range_18600 filemap_fdatawait_range 0 18600 NULL
124868 +iowarrior_write_18604 iowarrior_write 3 18604 NULL
124869 +from_buffer_18625 from_buffer 3 18625 NULL
124870 +snd_pcm_oss_write3_18657 snd_pcm_oss_write3 0-3 18657 NULL
124871 +ieee80211_if_fmt_rssi_threshold_18664 ieee80211_if_fmt_rssi_threshold 3 18664 NULL
124872 +xfs_iext_insert_18667 xfs_iext_insert 3 18667 NULL
124873 +fnic_stats_debugfs_read_18688 fnic_stats_debugfs_read 3 18688 NULL
124874 +echo_client_prep_commit_18693 echo_client_prep_commit 8 18693 NULL
124875 +iwl_dbgfs_rx_handlers_read_18708 iwl_dbgfs_rx_handlers_read 3 18708 NULL
124876 +ceph_alloc_page_vector_18710 ceph_alloc_page_vector 1 18710 NULL
124877 +blk_rq_bytes_18715 blk_rq_bytes 0 18715 NULL
124878 +nfs4_init_callback_netid_18717 nfs4_init_callback_netid 3 18717 NULL
124879 +snd_als4k_gcr_read_addr_18741 snd_als4k_gcr_read_addr 0 18741 NULL
124880 +o2hb_debug_create_18744 o2hb_debug_create 4 18744 NULL
124881 +__erst_read_to_erange_from_nvram_18748 __erst_read_to_erange_from_nvram 0 18748 NULL
124882 +wep_packets_read_18751 wep_packets_read 3 18751 NULL
124883 +read_file_dump_nfcal_18766 read_file_dump_nfcal 3 18766 NULL
124884 +SyS_lsetxattr_18776 SyS_lsetxattr 4 18776 NULL
124885 +alloc_fcdev_18780 alloc_fcdev 1 18780 NULL
124886 +dm_stats_print_18815 dm_stats_print 7 18815 NULL
124887 +sys_modify_ldt_18824 sys_modify_ldt 3 18824 NULL
124888 +mtf_test_write_18844 mtf_test_write 3 18844 NULL
124889 +sctp_setsockopt_events_18862 sctp_setsockopt_events 3 18862 NULL
124890 +ieee80211_if_read_element_ttl_18869 ieee80211_if_read_element_ttl 3 18869 NULL
124891 +xlog_find_verify_log_record_18870 xlog_find_verify_log_record 2 18870 NULL
124892 +devm_mdiobus_alloc_size_18902 devm_mdiobus_alloc_size 2 18902 NULL
124893 +ceph_setxattr_18913 ceph_setxattr 4 18913 NULL
124894 +ieee80211_rx_mgmt_disassoc_18927 ieee80211_rx_mgmt_disassoc 3 18927 NULL
124895 +__nla_reserve_18974 __nla_reserve 3 18974 NULL
124896 +find_dirtiest_idx_leb_19001 find_dirtiest_idx_leb 0 19001 NULL
124897 +layout_in_gaps_19006 layout_in_gaps 2 19006 NULL
124898 +huge_page_size_19008 huge_page_size 0 19008 NULL
124899 +hash_netport6_expire_19013 hash_netport6_expire 4 19013 NULL
124900 +revalidate_19043 revalidate 2 19043 NULL
124901 +afs_vnode_store_data_19048 afs_vnode_store_data 2-3-4-5 19048 NULL
124902 +osc_pinger_recov_seq_write_19056 osc_pinger_recov_seq_write 3 19056 NULL
124903 +create_gpadl_header_19064 create_gpadl_header 2 19064 NULL
124904 +ceph_create_snap_context_19082 ceph_create_snap_context 1 19082 NULL
124905 +sta_last_seq_ctrl_read_19106 sta_last_seq_ctrl_read 3 19106 NULL
124906 +cifs_readv_from_socket_19109 cifs_readv_from_socket 3 19109 NULL
124907 +skb_gro_offset_19123 skb_gro_offset 0 19123 NULL
124908 +snd_als4k_iobase_readl_19136 snd_als4k_iobase_readl 0 19136 NULL
124909 +alloc_irdadev_19140 alloc_irdadev 1 19140 NULL
124910 +sleep_auth_read_19159 sleep_auth_read 3 19159 NULL
124911 +smk_write_access2_19170 smk_write_access2 3 19170 NULL
124912 +read_extent_buffer_to_user_19189 read_extent_buffer_to_user 4-3 19189 NULL
124913 +iwl_dbgfs_reply_tx_error_read_19205 iwl_dbgfs_reply_tx_error_read 3 19205 NULL
124914 +__copy_to_user_inatomic_19214 __copy_to_user_inatomic 0-3 19214 NULL
124915 +dev_counters_read_19216 dev_counters_read 3 19216 NULL
124916 +wbcir_tx_19219 wbcir_tx 3 19219 NULL
124917 +snd_mask_max_19224 snd_mask_max 0 19224 NULL
124918 +bio_alloc_mddev_19238 bio_alloc_mddev 2 19238 NULL
124919 +ucma_query_19260 ucma_query 4 19260 NULL
124920 +il_dbgfs_rxon_filter_flags_read_19281 il_dbgfs_rxon_filter_flags_read 3 19281 NULL
124921 +batadv_tt_save_orig_buffer_19288 batadv_tt_save_orig_buffer 4 19288 NULL nohasharray
124922 +cfg80211_rx_unprot_mlme_mgmt_19288 cfg80211_rx_unprot_mlme_mgmt 3 19288 &batadv_tt_save_orig_buffer_19288
124923 +qc_capture_19298 qc_capture 3 19298 NULL
124924 +ocfs2_prepare_inode_for_refcount_19303 ocfs2_prepare_inode_for_refcount 3-4 19303 NULL
124925 +event_tx_stuck_read_19305 event_tx_stuck_read 3 19305 NULL
124926 +debug_read_19322 debug_read 3 19322 NULL
124927 +lbs_host_sleep_write_19332 lbs_host_sleep_write 3 19332 NULL nohasharray
124928 +cfg80211_inform_bss_19332 cfg80211_inform_bss 8 19332 &lbs_host_sleep_write_19332
124929 +closure_sub_19359 closure_sub 2 19359 NULL
124930 +firmware_data_write_19360 firmware_data_write 6-5 19360 NULL
124931 +read_zero_19366 read_zero 3 19366 NULL
124932 +interpret_user_input_19393 interpret_user_input 2 19393 NULL
124933 +sync_fill_pt_info_19397 sync_fill_pt_info 0 19397 NULL
124934 +pep_recvmsg_19402 pep_recvmsg 4 19402 NULL
124935 +hid_hw_raw_request_19408 hid_hw_raw_request 0 19408 NULL
124936 +dvbdmx_write_19423 dvbdmx_write 3 19423 NULL
124937 +SyS_sched_getaffinity_19444 SyS_sched_getaffinity 2 19444 NULL
124938 +xfrm_alg_auth_len_19454 xfrm_alg_auth_len 0 19454 NULL
124939 +gnet_stats_copy_19458 gnet_stats_copy 4 19458 NULL
124940 +gp2ap020a00f_get_thresh_reg_19468 gp2ap020a00f_get_thresh_reg 0 19468 NULL
124941 +sky2_read16_19475 sky2_read16 0 19475 NULL
124942 +kstrtoll_from_user_19500 kstrtoll_from_user 2 19500 NULL
124943 +ext4_add_new_descs_19509 ext4_add_new_descs 3 19509 NULL
124944 +batadv_tvlv_container_register_19520 batadv_tvlv_container_register 5 19520 NULL
124945 +nfc_llcp_build_tlv_19536 nfc_llcp_build_tlv 3 19536 NULL
124946 +gfn_to_index_19558 gfn_to_index 0-1-3-2 19558 NULL
124947 +ocfs2_control_message_19564 ocfs2_control_message 3 19564 NULL
124948 +nfsd_read_19568 nfsd_read 5 19568 NULL
124949 +ieee80211_key_alloc_19575 ieee80211_key_alloc 3 19575 NULL
124950 +bm_status_read_19583 bm_status_read 3 19583 NULL
124951 +load_xattr_datum_19594 load_xattr_datum 0 19594 NULL
124952 +__mei_cl_recv_19636 __mei_cl_recv 3 19636 NULL
124953 +LoadBitmap_19658 LoadBitmap 2 19658 NULL
124954 +memblock_virt_alloc_low_nopanic_19714 memblock_virt_alloc_low_nopanic 1 19714 NULL
124955 +read_reg_19723 read_reg 0 19723 NULL
124956 +wm8350_block_write_19727 wm8350_block_write 2-3 19727 NULL
124957 +memcpy_toiovecend_19736 memcpy_toiovecend 4-3 19736 NULL
124958 +snd_es1968_get_dma_ptr_19747 snd_es1968_get_dma_ptr 0 19747 NULL
124959 +p9_client_read_19750 p9_client_read 5-0 19750 NULL
124960 +pnpbios_proc_write_19758 pnpbios_proc_write 3 19758 NULL
124961 +ocfs2_readpages_19759 ocfs2_readpages 4 19759 NULL
124962 +jffs2_acl_from_medium_19762 jffs2_acl_from_medium 2 19762 NULL
124963 +irda_setsockopt_19824 irda_setsockopt 5 19824 NULL
124964 +vfs_getxattr_19832 vfs_getxattr 0 19832 NULL
124965 +crypt_alloc_buffer_19846 crypt_alloc_buffer 2 19846 NULL
124966 +cfg80211_mlme_register_mgmt_19852 cfg80211_mlme_register_mgmt 5 19852 NULL
124967 +__nla_put_19857 __nla_put 3 19857 NULL
124968 +mrp_request_join_19882 mrp_request_join 4 19882 NULL
124969 +aes_decrypt_interrupt_read_19910 aes_decrypt_interrupt_read 3 19910 NULL
124970 +ps_upsd_max_apturn_read_19918 ps_upsd_max_apturn_read 3 19918 NULL
124971 +mangle_name_19923 mangle_name 0 19923 NULL
124972 +cgroup_task_count_19930 cgroup_task_count 0 19930 NULL
124973 +guest_read_tsc_19931 guest_read_tsc 0 19931 NULL
124974 +iwl_dbgfs_rx_queue_read_19943 iwl_dbgfs_rx_queue_read 3 19943 NULL
124975 +cfg80211_rx_assoc_resp_19944 cfg80211_rx_assoc_resp 4 19944 NULL
124976 +ll_xattr_cache_list_19954 ll_xattr_cache_list 0 19954 NULL
124977 +attach_hdlc_protocol_19986 attach_hdlc_protocol 3 19986 NULL
124978 +rtw_set_wps_probe_resp_19989 rtw_set_wps_probe_resp 3 19989 NULL
124979 +diva_um_idi_read_20003 diva_um_idi_read 0 20003 NULL
124980 +event_trigger_write_20009 event_trigger_write 3 20009 NULL nohasharray
124981 +lov_stripe_md_size_20009 lov_stripe_md_size 0-1 20009 &event_trigger_write_20009
124982 +tree_mod_log_eb_move_20011 tree_mod_log_eb_move 5 20011 NULL
124983 +SYSC_fgetxattr_20027 SYSC_fgetxattr 4 20027 NULL
124984 +split_scan_timeout_read_20029 split_scan_timeout_read 3 20029 NULL
124985 +iwl_mvm_power_mac_dbgfs_read_20067 iwl_mvm_power_mac_dbgfs_read 4-0 20067 NULL
124986 +rawv6_sendmsg_20080 rawv6_sendmsg 4 20080 NULL
124987 +fuse_conn_limit_read_20084 fuse_conn_limit_read 3 20084 NULL
124988 +aat2870_reg_write_file_20086 aat2870_reg_write_file 3 20086 NULL
124989 +team_options_register_20091 team_options_register 3 20091 NULL
124990 +qla2x00_adjust_sdev_qdepth_up_20097 qla2x00_adjust_sdev_qdepth_up 2 20097 NULL
124991 +hptiop_adjust_disk_queue_depth_20122 hptiop_adjust_disk_queue_depth 2 20122 NULL
124992 +self_check_vid_hdr_20131 self_check_vid_hdr 0 20131 NULL
124993 +ext4_ext_direct_IO_20165 ext4_ext_direct_IO 4 20165 NULL
124994 +tomoyo_commit_ok_20167 tomoyo_commit_ok 2 20167 NULL
124995 +read_flush_pipefs_20171 read_flush_pipefs 3 20171 NULL
124996 +wep_addr_key_count_read_20174 wep_addr_key_count_read 3 20174 NULL
124997 +crystalhd_map_dio_20181 crystalhd_map_dio 3 20181 NULL
124998 +pvr2_ctrl_value_to_sym_20229 pvr2_ctrl_value_to_sym 5 20229 NULL
124999 +rose_sendmsg_20249 rose_sendmsg 4 20249 NULL
125000 +tm6000_i2c_send_regs_20250 tm6000_i2c_send_regs 5 20250 NULL
125001 +btrfs_header_nritems_20296 btrfs_header_nritems 0 20296 NULL
125002 +r10_sync_page_io_20307 r10_sync_page_io 3 20307 NULL
125003 +dm_get_reserved_bio_based_ios_20315 dm_get_reserved_bio_based_ios 0 20315 NULL
125004 +tx_tx_burst_programmed_read_20320 tx_tx_burst_programmed_read 3 20320 NULL
125005 +vx_send_msg_nolock_20322 vx_send_msg_nolock 0 20322 NULL
125006 +snd_cs4281_BA1_read_20323 snd_cs4281_BA1_read 5 20323 NULL
125007 +gfs2_glock_nq_m_20347 gfs2_glock_nq_m 1 20347 NULL
125008 +handle_arr_calc_size_20355 handle_arr_calc_size 0-1 20355 NULL
125009 +smk_set_cipso_20379 smk_set_cipso 3 20379 NULL
125010 +snd_nm256_readl_20394 snd_nm256_readl 0 20394 NULL
125011 +__kfifo_from_user_20399 __kfifo_from_user 3 20399 NULL nohasharray
125012 +SyS_get_mempolicy_20399 SyS_get_mempolicy 3 20399 &__kfifo_from_user_20399
125013 +compat_ipv6_setsockopt_20468 compat_ipv6_setsockopt 5 20468 NULL
125014 +read_buf_20469 read_buf 2 20469 NULL
125015 +bio_trim_20472 bio_trim 2 20472 NULL
125016 +btrfs_get_32_20476 btrfs_get_32 0 20476 NULL
125017 +xfs_iext_realloc_direct_20521 xfs_iext_realloc_direct 2 20521 NULL
125018 +drbd_bm_resize_20522 drbd_bm_resize 2 20522 NULL
125019 +amd_create_gatt_pages_20537 amd_create_gatt_pages 1 20537 NULL
125020 +scsi_report_opcode_20551 scsi_report_opcode 3 20551 NULL
125021 +venus_create_20555 venus_create 4 20555 NULL
125022 +btrfs_super_log_root_20565 btrfs_super_log_root 0 20565 NULL
125023 +crypto_ahash_reqsize_20569 crypto_ahash_reqsize 0 20569 NULL
125024 +kvm_test_age_hva_20593 kvm_test_age_hva 2 20593 NULL
125025 +set_secure_conn_20596 set_secure_conn 4 20596 NULL
125026 +sync_timeline_create_20601 sync_timeline_create 2 20601 NULL
125027 +lirc_write_20604 lirc_write 3 20604 NULL
125028 +qib_qsfp_write_20614 qib_qsfp_write 0-4-2 20614 NULL
125029 +snd_pcm_oss_prepare_20641 snd_pcm_oss_prepare 0 20641 NULL
125030 +get_extent_skip_holes_20642 get_extent_skip_holes 2 20642 NULL
125031 +kfifo_copy_to_user_20646 kfifo_copy_to_user 4-3 20646 NULL
125032 +cpulist_scnprintf_20648 cpulist_scnprintf 2 20648 NULL
125033 +oz_add_farewell_20652 oz_add_farewell 5 20652 NULL
125034 +oz_cdev_read_20659 oz_cdev_read 3 20659 NULL
125035 +snd_hdsp_playback_copy_20676 snd_hdsp_playback_copy 5 20676 NULL
125036 +dvb_dmxdev_buffer_read_20682 dvb_dmxdev_buffer_read 0-4 20682 NULL
125037 +cpumask_size_20683 cpumask_size 0 20683 NULL
125038 +btrfs_node_blockptr_20685 btrfs_node_blockptr 0 20685 NULL
125039 +xpcs_reg_addr_write_20694 xpcs_reg_addr_write 3 20694 NULL
125040 +read_file_tgt_int_stats_20697 read_file_tgt_int_stats 3 20697 NULL
125041 +__maestro_read_20700 __maestro_read 0 20700 NULL
125042 +cipso_v4_gentag_rng_20703 cipso_v4_gentag_rng 0 20703 NULL
125043 +pcpu_page_first_chunk_20712 pcpu_page_first_chunk 1 20712 NULL
125044 +hfs_direct_IO_20714 hfs_direct_IO 4 20714 NULL
125045 +ocfs2_read_xattr_bucket_20722 ocfs2_read_xattr_bucket 0 20722 NULL
125046 +security_context_to_sid_force_20724 security_context_to_sid_force 2 20724 NULL
125047 +fb_prepare_logo_20743 fb_prepare_logo 0 20743 NULL
125048 +vol_cdev_direct_write_20751 vol_cdev_direct_write 3 20751 NULL
125049 +ocfs2_align_bytes_to_clusters_20754 ocfs2_align_bytes_to_clusters 2 20754 NULL
125050 +brcmf_p2p_escan_20763 brcmf_p2p_escan 2 20763 NULL
125051 +ubi_io_read_20767 ubi_io_read 0 20767 NULL
125052 +fb_alloc_cmap_gfp_20792 fb_alloc_cmap_gfp 2 20792 NULL
125053 +iwl_dbgfs_rxon_flags_read_20795 iwl_dbgfs_rxon_flags_read 3 20795 NULL
125054 +lowpan_write_20800 lowpan_write 3 20800 NULL
125055 +strndup_user_20819 strndup_user 2 20819 NULL
125056 +tipc_msg_build_20825 tipc_msg_build 3 20825 NULL
125057 +wl1271_format_buffer_20834 wl1271_format_buffer 2 20834 NULL
125058 +uvc_alloc_entity_20836 uvc_alloc_entity 4-3 20836 NULL
125059 +p9_tag_alloc_20845 p9_tag_alloc 3 20845 NULL
125060 +nvme_trans_supported_vpd_pages_20847 nvme_trans_supported_vpd_pages 4 20847 NULL
125061 +iwl_dbgfs_pm_params_read_20866 iwl_dbgfs_pm_params_read 3 20866 NULL
125062 +snd_pcm_capture_avail_20867 snd_pcm_capture_avail 0 20867 NULL
125063 +srq_free_res_20868 srq_free_res 5 20868 NULL
125064 +cfs_cpt_table_create_20884 cfs_cpt_table_create 1 20884 NULL
125065 +rb_simple_write_20890 rb_simple_write 3 20890 NULL
125066 +sisusb_send_packet_20891 sisusb_send_packet 2 20891 NULL
125067 +key_icverrors_read_20895 key_icverrors_read 3 20895 NULL
125068 +vfio_msi_enable_20906 vfio_msi_enable 2 20906 NULL
125069 +lbs_rdbbp_write_20918 lbs_rdbbp_write 3 20918 NULL
125070 +htable_bits_20933 htable_bits 0 20933 NULL
125071 +altera_set_ir_post_20948 altera_set_ir_post 2 20948 NULL
125072 +rx_rx_phy_hdr_read_20950 rx_rx_phy_hdr_read 3 20950 NULL
125073 +rsxx_cram_read_20957 rsxx_cram_read 3 20957 NULL
125074 +nfs_map_name_to_uid_20962 nfs_map_name_to_uid 3 20962 NULL
125075 +snd_rme9652_playback_copy_20970 snd_rme9652_playback_copy 5 20970 NULL
125076 +alg_setsockopt_20985 alg_setsockopt 5 20985 NULL
125077 +qib_verbs_send_20999 qib_verbs_send 5-3 20999 NULL
125078 +btrfs_inode_ref_name_len_21024 btrfs_inode_ref_name_len 0 21024 NULL
125079 +rx_defrag_tkip_called_read_21031 rx_defrag_tkip_called_read 3 21031 NULL
125080 +srp_change_queue_depth_21038 srp_change_queue_depth 2 21038 NULL
125081 +fsl_edma_prep_dma_cyclic_21042 fsl_edma_prep_dma_cyclic 4-3 21042 NULL
125082 +lbs_threshold_read_21046 lbs_threshold_read 5 21046 NULL
125083 +proc_fault_inject_write_21058 proc_fault_inject_write 3 21058 NULL
125084 +event_calibration_read_21083 event_calibration_read 3 21083 NULL
125085 +bl_add_page_to_bio_21094 bl_add_page_to_bio 2 21094 NULL nohasharray
125086 +multipath_status_21094 multipath_status 5 21094 &bl_add_page_to_bio_21094
125087 +rate_control_pid_events_read_21099 rate_control_pid_events_read 3 21099 NULL
125088 +ath6kl_send_go_probe_resp_21113 ath6kl_send_go_probe_resp 3 21113 NULL
125089 +_efx_mcdi_rpc_async_21119 _efx_mcdi_rpc_async 4-5 21119 NULL
125090 +i2400m_rx_trace_21127 i2400m_rx_trace 3 21127 NULL
125091 +mei_dbgfs_read_active_21172 mei_dbgfs_read_active 3 21172 NULL
125092 +cx18_v4l2_read_21196 cx18_v4l2_read 3 21196 NULL
125093 +ipc_rcu_alloc_21208 ipc_rcu_alloc 1 21208 NULL
125094 +scsi_execute_req_flags_21215 scsi_execute_req_flags 5 21215 NULL
125095 +get_numpages_21227 get_numpages 0-1-2 21227 NULL
125096 +input_ff_create_21240 input_ff_create 2 21240 NULL
125097 +cfg80211_notify_new_peer_candidate_21242 cfg80211_notify_new_peer_candidate 4 21242 NULL
125098 +fru_length_21257 fru_length 0 21257 NULL
125099 +rtw_set_wps_beacon_21262 rtw_set_wps_beacon 3 21262 NULL
125100 +drm_universal_plane_init_21296 drm_universal_plane_init 6 21296 NULL
125101 +do_msg_fill_21307 do_msg_fill 3 21307 NULL
125102 +add_res_range_21310 add_res_range 4 21310 NULL
125103 +get_zeroed_page_21322 get_zeroed_page 0 21322 NULL
125104 +ftrace_profile_read_21327 ftrace_profile_read 3 21327 NULL
125105 +read_file_bool_bmps_21344 read_file_bool_bmps 3 21344 NULL
125106 +gfs2_ea_get_copy_21353 gfs2_ea_get_copy 0 21353 NULL
125107 +allocate_cmdlines_buffer_21355 allocate_cmdlines_buffer 1 21355 NULL
125108 +alloc_orinocodev_21371 alloc_orinocodev 1 21371 NULL
125109 +SYSC_rt_sigpending_21379 SYSC_rt_sigpending 2 21379 NULL
125110 +video_ioctl2_21380 video_ioctl2 2 21380 NULL
125111 +insert_ptr_21386 insert_ptr 6 21386 NULL
125112 +diva_get_driver_dbg_mask_21399 diva_get_driver_dbg_mask 0 21399 NULL
125113 +snd_m3_inw_21406 snd_m3_inw 0 21406 NULL
125114 +usnic_ib_dump_vf_hdr_21423 usnic_ib_dump_vf_hdr 3 21423 NULL
125115 +tcp_bound_to_half_wnd_21429 tcp_bound_to_half_wnd 0-2 21429 NULL
125116 +aggr_size_tx_agg_vs_rate_read_21438 aggr_size_tx_agg_vs_rate_read 3 21438 NULL
125117 +__ertm_hdr_size_21450 __ertm_hdr_size 0 21450 NULL
125118 +mei_nfc_send_21477 mei_nfc_send 3 21477 NULL
125119 +read_file_xmit_21487 read_file_xmit 3 21487 NULL
125120 +mmc_alloc_sg_21504 mmc_alloc_sg 1 21504 NULL
125121 +il_dbgfs_stations_read_21532 il_dbgfs_stations_read 3 21532 NULL
125122 +cipso_v4_map_cat_enum_hton_21540 cipso_v4_map_cat_enum_hton 0 21540 NULL
125123 +rxrpc_send_data_21553 rxrpc_send_data 5 21553 NULL
125124 +rx_rx_beacon_early_term_read_21559 rx_rx_beacon_early_term_read 3 21559 NULL
125125 +xfs_buf_read_uncached_21585 xfs_buf_read_uncached 3 21585 NULL
125126 +snd_es18xx_mixer_read_21586 snd_es18xx_mixer_read 0 21586 NULL
125127 +ocfs2_acl_from_xattr_21604 ocfs2_acl_from_xattr 2 21604 NULL
125128 +filemap_get_page_21606 filemap_get_page 2 21606 NULL
125129 +__jfs_getxattr_21631 __jfs_getxattr 0 21631 NULL
125130 +atalk_sendmsg_21677 atalk_sendmsg 4 21677 NULL
125131 +ocfs2_xattr_get_nolock_21678 ocfs2_xattr_get_nolock 0 21678 NULL
125132 +regmap_register_patch_21681 regmap_register_patch 3 21681 NULL
125133 +rtllib_alloc_txb_21687 rtllib_alloc_txb 1 21687 NULL
125134 +evdev_ioctl_handler_21705 evdev_ioctl_handler 2 21705 NULL
125135 +unix_skb_len_21722 unix_skb_len 0 21722 NULL
125136 +lprocfs_wr_import_21728 lprocfs_wr_import 3 21728 NULL
125137 +mthca_alloc_init_21754 mthca_alloc_init 2 21754 NULL
125138 +usbat_flash_read_data_21762 usbat_flash_read_data 4 21762 NULL
125139 +gen_pool_add_21776 gen_pool_add 3 21776 NULL
125140 +xfs_da_grow_inode_int_21785 xfs_da_grow_inode_int 3 21785 NULL
125141 +dvb_generic_ioctl_21810 dvb_generic_ioctl 2 21810 NULL
125142 +_iwl_dbgfs_sta_drain_write_21837 _iwl_dbgfs_sta_drain_write 3 21837 NULL
125143 +oom_adj_read_21847 oom_adj_read 3 21847 NULL
125144 +lpfc_idiag_extacc_avail_get_21865 lpfc_idiag_extacc_avail_get 0-3 21865 NULL
125145 +brcms_debugfs_hardware_read_21867 brcms_debugfs_hardware_read 3 21867 NULL
125146 +sisusbcon_bmove_21873 sisusbcon_bmove 6-5-7 21873 NULL
125147 +ldlm_lock_create_21888 ldlm_lock_create 7 21888 NULL
125148 +__btrfs_direct_write_21894 __btrfs_direct_write 3 21894 NULL
125149 +dbAllocCtl_21911 dbAllocCtl 0 21911 NULL
125150 +qsfp_1_read_21915 qsfp_1_read 3 21915 NULL
125151 +twl_i2c_write_u16_21953 twl_i2c_write_u16 3 21953 NULL
125152 +__build_xattrs_21979 __build_xattrs 0 21979 NULL
125153 +SYSC_prctl_21980 SYSC_prctl 4 21980 NULL
125154 +compat_rw_copy_check_uvector_22001 compat_rw_copy_check_uvector 3-0 22001 NULL nohasharray
125155 +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
125156 +regcache_sync_block_raw_flush_22021 regcache_sync_block_raw_flush 3-4 22021 NULL
125157 +btrfs_get_16_22023 btrfs_get_16 0 22023 NULL
125158 +_sp2d_min_pg_22032 _sp2d_min_pg 0 22032 NULL
125159 +zd_usb_read_fw_22049 zd_usb_read_fw 4 22049 NULL
125160 +ieee80211_if_fmt_dropped_frames_ttl_22054 ieee80211_if_fmt_dropped_frames_ttl 3 22054 NULL
125161 +btrfs_reloc_clone_csums_22077 btrfs_reloc_clone_csums 2-3 22077 NULL
125162 +mem_rw_22085 mem_rw 3 22085 NULL
125163 +kstrtos32_from_user_22087 kstrtos32_from_user 2 22087 NULL
125164 +rt2x00debug_read_crypto_stats_22109 rt2x00debug_read_crypto_stats 3 22109 NULL
125165 +snd_hda_codec_read_22130 snd_hda_codec_read 0 22130 NULL
125166 +SyS_sched_setaffinity_22148 SyS_sched_setaffinity 2 22148 NULL
125167 +do_tcp_sendpages_22155 do_tcp_sendpages 4 22155 NULL
125168 +__kfifo_alloc_22173 __kfifo_alloc 3 22173 NULL
125169 +rfcomm_sock_recvmsg_22227 rfcomm_sock_recvmsg 4 22227 NULL
125170 +mem_write_22232 mem_write 3 22232 NULL
125171 +p9_virtio_zc_request_22240 p9_virtio_zc_request 6-5 22240 NULL
125172 +prepare_to_wait_event_22247 prepare_to_wait_event 0 22247 NULL
125173 +compat_process_vm_rw_22254 compat_process_vm_rw 3-5 22254 NULL
125174 +ping_common_sendmsg_22261 ping_common_sendmsg 5 22261 NULL
125175 +add_res_tree_22263 add_res_tree 7 22263 NULL
125176 +queue_max_sectors_22280 queue_max_sectors 0 22280 NULL
125177 +__tun_chr_ioctl_22300 __tun_chr_ioctl 4 22300 NULL nohasharray
125178 +pci_vpd_srdt_size_22300 pci_vpd_srdt_size 0 22300 &__tun_chr_ioctl_22300
125179 +mesh_table_alloc_22305 mesh_table_alloc 1 22305 NULL
125180 +lov_setstripe_22307 lov_setstripe 2 22307 NULL
125181 +atomic_read_22342 atomic_read 0 22342 NULL
125182 +ll_lazystatfs_seq_write_22353 ll_lazystatfs_seq_write 3 22353 NULL
125183 +snd_pcm_alsa_frames_22363 snd_pcm_alsa_frames 2 22363 NULL
125184 +evdev_ioctl_22371 evdev_ioctl 2 22371 NULL
125185 +alloc_large_system_hash_22391 alloc_large_system_hash 2 22391 NULL
125186 +zoran_write_22404 zoran_write 3 22404 NULL
125187 +queue_reply_22416 queue_reply 3 22416 NULL
125188 +__set_enter_print_fmt_22431 __set_enter_print_fmt 0 22431 NULL
125189 +queue_max_segments_22441 queue_max_segments 0 22441 NULL
125190 +handle_received_packet_22457 handle_received_packet 3 22457 NULL
125191 +ecryptfs_write_22488 ecryptfs_write 4-3 22488 NULL
125192 +qib_user_sdma_alloc_header_22490 qib_user_sdma_alloc_header 2 22490 NULL
125193 +cache_write_procfs_22491 cache_write_procfs 3 22491 NULL
125194 +trim_no_bitmap_22524 trim_no_bitmap 4-3 22524 NULL
125195 +ocfs2_read_extent_block_22550 ocfs2_read_extent_block 0 22550 NULL
125196 +agp_alloc_page_array_22554 agp_alloc_page_array 1 22554 NULL
125197 +dbFindCtl_22587 dbFindCtl 0 22587 NULL
125198 +sctp_setsockopt_connectx_old_22631 sctp_setsockopt_connectx_old 3 22631 NULL
125199 +ide_core_cp_entry_22636 ide_core_cp_entry 3 22636 NULL
125200 +wl1271_rx_filter_get_fields_size_22638 wl1271_rx_filter_get_fields_size 0 22638 NULL
125201 +pwr_wake_on_timer_exp_read_22640 pwr_wake_on_timer_exp_read 3 22640 NULL
125202 +iwl_dbgfs_calib_disabled_read_22649 iwl_dbgfs_calib_disabled_read 3 22649 NULL
125203 +l2tp_ip_recvmsg_22681 l2tp_ip_recvmsg 4 22681 NULL nohasharray
125204 +fill_gap_22681 fill_gap 0 22681 &l2tp_ip_recvmsg_22681
125205 +bch_dump_read_22685 bch_dump_read 3 22685 NULL
125206 +reg_umr_22686 reg_umr 5 22686 NULL
125207 +SYSC_vmsplice_22697 SYSC_vmsplice 3 22697 NULL
125208 +nr_cpusets_22705 nr_cpusets 0 22705 NULL
125209 +alloc_libipw_22708 alloc_libipw 1 22708 NULL
125210 +cx18_copy_buf_to_user_22735 cx18_copy_buf_to_user 4-0 22735 NULL
125211 +ceph_decode_32_22738 ceph_decode_32 0 22738 NULL nohasharray
125212 +__mei_cl_send_22738 __mei_cl_send 3 22738 &ceph_decode_32_22738
125213 +iio_debugfs_write_reg_22742 iio_debugfs_write_reg 3 22742 NULL
125214 +qlcnic_sriov_init_22762 qlcnic_sriov_init 2 22762 NULL
125215 +print_frame_22769 print_frame 0 22769 NULL
125216 +ftrace_arch_read_dyn_info_22773 ftrace_arch_read_dyn_info 0 22773 NULL
125217 +vnic_dev_get_res_count_22791 vnic_dev_get_res_count 0 22791 NULL
125218 +__generic_copy_to_user_intel_22806 __generic_copy_to_user_intel 0-3 22806 NULL
125219 +create_attr_set_22861 create_attr_set 1 22861 NULL
125220 +hash_ip6_expire_22867 hash_ip6_expire 4 22867 NULL
125221 +vmw_execbuf_process_22885 vmw_execbuf_process 5 22885 NULL
125222 +usblp_new_writeurb_22894 usblp_new_writeurb 2 22894 NULL
125223 +mdc800_device_read_22896 mdc800_device_read 3 22896 NULL
125224 +policy_emit_config_values_22900 policy_emit_config_values 3 22900 NULL nohasharray
125225 +ion_handle_test_kernel_22900 ion_handle_test_kernel 4-3 22900 &policy_emit_config_values_22900
125226 +__set_xattr_22923 __set_xattr 0 22923 NULL
125227 +xstateregs_set_22932 xstateregs_set 4 22932 NULL
125228 +pcpu_mem_zalloc_22948 pcpu_mem_zalloc 1 22948 NULL
125229 +alloc_sglist_22960 alloc_sglist 2-3 22960 NULL
125230 +caif_seqpkt_sendmsg_22961 caif_seqpkt_sendmsg 4 22961 NULL
125231 +vme_get_size_22964 vme_get_size 0 22964 NULL
125232 +tx_frag_key_not_found_read_22971 tx_frag_key_not_found_read 3 22971 NULL
125233 +cached_dev_cache_miss_22979 cached_dev_cache_miss 4 22979 NULL
125234 +usb_get_langid_22983 usb_get_langid 0 22983 NULL
125235 +remote_settings_file_write_22987 remote_settings_file_write 3 22987 NULL
125236 +viafb_dvp0_proc_write_23023 viafb_dvp0_proc_write 3 23023 NULL
125237 +cifs_local_to_utf16_bytes_23025 cifs_local_to_utf16_bytes 0 23025 NULL
125238 +st_status_23032 st_status 5 23032 NULL
125239 +nv50_disp_chan_create__23056 nv50_disp_chan_create_ 5 23056 NULL
125240 +unix_seqpacket_recvmsg_23062 unix_seqpacket_recvmsg 4 23062 NULL nohasharray
125241 +reiserfs_add_entry_23062 reiserfs_add_entry 4 23062 &unix_seqpacket_recvmsg_23062
125242 +mei_cl_send_23068 mei_cl_send 3 23068 NULL
125243 +raw_sendmsg_23078 raw_sendmsg 4 23078 NULL
125244 +get_user_hdr_len_23079 get_user_hdr_len 0 23079 NULL
125245 +isr_tx_procs_read_23084 isr_tx_procs_read 3 23084 NULL
125246 +rt2x00debug_write_eeprom_23091 rt2x00debug_write_eeprom 3 23091 NULL
125247 +ntfs_ucstonls_23097 ntfs_ucstonls 3-5 23097 NULL
125248 +dgram_recvmsg_23104 dgram_recvmsg 4 23104 NULL
125249 +mwl8k_cmd_set_beacon_23110 mwl8k_cmd_set_beacon 4 23110 NULL
125250 +bset_tree_bytes_23111 bset_tree_bytes 0 23111 NULL nohasharray
125251 +nl80211_send_rx_auth_23111 nl80211_send_rx_auth 4 23111 &bset_tree_bytes_23111
125252 +__clear_user_23118 __clear_user 0-2 23118 NULL
125253 +drm_mode_create_tv_properties_23122 drm_mode_create_tv_properties 2 23122 NULL
125254 +ata_scsi_change_queue_depth_23126 ata_scsi_change_queue_depth 2 23126 NULL
125255 +read_file_ani_23161 read_file_ani 3 23161 NULL
125256 +usblp_write_23178 usblp_write 3 23178 NULL
125257 +gss_pipe_downcall_23182 gss_pipe_downcall 3 23182 NULL
125258 +mpi_alloc_limb_space_23190 mpi_alloc_limb_space 1 23190 NULL
125259 +nft_hash_tbl_alloc_23224 nft_hash_tbl_alloc 1 23224 NULL
125260 +tty_buffer_request_room_23228 tty_buffer_request_room 2-0 23228 NULL
125261 +xlog_get_bp_23229 xlog_get_bp 2 23229 NULL
125262 +ft1000_read_dpram_mag_32_23232 ft1000_read_dpram_mag_32 0 23232 NULL
125263 +rxrpc_client_sendmsg_23236 rxrpc_client_sendmsg 5 23236 NULL
125264 +__gfn_to_rmap_23240 __gfn_to_rmap 1-2 23240 NULL
125265 +nv50_ram_create__23241 nv50_ram_create_ 4 23241 NULL
125266 +sctp_recvmsg_23265 sctp_recvmsg 4 23265 NULL
125267 +uwb_dev_addr_print_23282 uwb_dev_addr_print 2 23282 NULL
125268 +ec_i2c_count_message_23285 ec_i2c_count_message 0-2 23285 NULL
125269 +diva_get_trace_filter_23286 diva_get_trace_filter 0 23286 NULL
125270 +i2cdev_write_23310 i2cdev_write 3 23310 NULL
125271 +__aa_kvmalloc_23320 __aa_kvmalloc 1 23320 NULL
125272 +page_readlink_23346 page_readlink 3 23346 NULL
125273 +kmem_zalloc_large_23351 kmem_zalloc_large 1 23351 NULL
125274 +get_dst_timing_23358 get_dst_timing 0 23358 NULL
125275 +fd_setup_write_same_buf_23369 fd_setup_write_same_buf 3 23369 NULL
125276 +iscsi_change_queue_depth_23416 iscsi_change_queue_depth 2 23416 NULL
125277 +ocfs2_zero_tail_23447 ocfs2_zero_tail 3 23447 NULL
125278 +hidraw_send_report_23449 hidraw_send_report 3 23449 NULL
125279 +__ata_change_queue_depth_23484 __ata_change_queue_depth 3 23484 NULL
125280 +linear_conf_23485 linear_conf 2 23485 NULL
125281 +event_filter_read_23494 event_filter_read 3 23494 NULL
125282 +lustre_acl_xattr_merge2ext_23502 lustre_acl_xattr_merge2ext 2 23502 NULL
125283 +devm_iio_device_alloc_23511 devm_iio_device_alloc 2 23511 NULL
125284 +__proc_cpt_table_23516 __proc_cpt_table 5 23516 NULL
125285 +hash_ipmark6_expire_23518 hash_ipmark6_expire 4 23518 NULL
125286 +ima_show_measurements_count_23536 ima_show_measurements_count 3 23536 NULL
125287 +tcp_current_mss_23552 tcp_current_mss 0 23552 NULL
125288 +dbg_leb_change_23555 dbg_leb_change 0 23555 NULL
125289 +btrfs_super_bytenr_23561 btrfs_super_bytenr 0 23561 NULL
125290 +venus_symlink_23570 venus_symlink 6-4 23570 NULL
125291 +iwl_dbgfs_interrupt_read_23574 iwl_dbgfs_interrupt_read 3 23574 NULL
125292 +xfpregs_get_23586 xfpregs_get 4 23586 NULL
125293 +snd_interval_min_23590 snd_interval_min 0 23590 NULL
125294 +islpci_mgt_transaction_23610 islpci_mgt_transaction 5 23610 NULL
125295 +__i2400mu_send_barker_23652 __i2400mu_send_barker 3 23652 NULL
125296 +sInW_23663 sInW 0 23663 NULL
125297 +SyS_connect_23669 SyS_connect 3 23669 NULL
125298 +cx18_read_23699 cx18_read 3 23699 NULL
125299 +at_get_23708 at_get 0 23708 NULL
125300 +get_conn_info_23723 get_conn_info 4 23723 NULL
125301 +rx_rx_dropped_frame_read_23748 rx_rx_dropped_frame_read 3 23748 NULL
125302 +__kfifo_max_r_23768 __kfifo_max_r 0-2-1 23768 NULL
125303 +__build_packet_message_23778 __build_packet_message 10-4 23778 NULL
125304 +security_inode_getxattr_23781 security_inode_getxattr 0 23781 NULL
125305 +cfg80211_inform_bss_width_frame_23782 cfg80211_inform_bss_width_frame 5 23782 NULL
125306 +mpt_free_res_23793 mpt_free_res 5 23793 NULL
125307 +map_write_23795 map_write 3 23795 NULL
125308 +rx_path_reset_read_23801 rx_path_reset_read 3 23801 NULL
125309 +__earlyonly_bootmem_alloc_23824 __earlyonly_bootmem_alloc 2 23824 NULL
125310 +lustre_msg_buflen_23827 lustre_msg_buflen 0 23827 NULL
125311 +pgdat_end_pfn_23842 pgdat_end_pfn 0 23842 NULL
125312 +iwl_dbgfs_nvm_read_23845 iwl_dbgfs_nvm_read 3 23845 NULL
125313 +p54_init_common_23850 p54_init_common 1 23850 NULL
125314 +bin_to_hex_dup_23853 bin_to_hex_dup 2 23853 NULL
125315 +ocfs2_xattr_get_clusters_23857 ocfs2_xattr_get_clusters 0 23857 NULL
125316 +ieee80211_if_read_dot11MeshMaxPeerLinks_23878 ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 NULL
125317 +tipc_snprintf_23893 tipc_snprintf 2-0 23893 NULL
125318 +iov_iter_get_pages_alloc_23903 iov_iter_get_pages_alloc 3-0 23903 NULL
125319 +add_new_gdb_meta_bg_23911 add_new_gdb_meta_bg 3 23911 NULL nohasharray
125320 +ieee80211_if_read_hw_queues_23911 ieee80211_if_read_hw_queues 3 23911 &add_new_gdb_meta_bg_23911
125321 +f2fs_getxattr_23917 f2fs_getxattr 0 23917 NULL
125322 +ipath_reg_phys_mr_23918 ipath_reg_phys_mr 3 23918 NULL nohasharray
125323 +mpihelp_mul_karatsuba_case_23918 mpihelp_mul_karatsuba_case 5-3 23918 &ipath_reg_phys_mr_23918
125324 +kvm_read_guest_23928 kvm_read_guest 4-2 23928 NULL
125325 +uvc_endpoint_max_bpi_23944 uvc_endpoint_max_bpi 0 23944 NULL
125326 +cifs_setxattr_23957 cifs_setxattr 4 23957 NULL
125327 +size_roundup_power2_23958 size_roundup_power2 0-1 23958 NULL
125328 +sddr55_write_data_23983 sddr55_write_data 4 23983 NULL
125329 +zd_usb_iowrite16v_async_23984 zd_usb_iowrite16v_async 3 23984 NULL
125330 +cxgb_alloc_mem_24007 cxgb_alloc_mem 1 24007 NULL
125331 +give_pages_24021 give_pages 3 24021 NULL
125332 +adis16400_show_serial_number_24037 adis16400_show_serial_number 3 24037 NULL
125333 +hmac_setkey_24043 hmac_setkey 3 24043 NULL
125334 +afs_cell_alloc_24052 afs_cell_alloc 2 24052 NULL
125335 +iwl_dbgfs_low_latency_read_24062 iwl_dbgfs_low_latency_read 3 24062 NULL
125336 +vb2_fop_read_24080 vb2_fop_read 3 24080 NULL
125337 +C_SYSC_process_vm_writev_24102 C_SYSC_process_vm_writev 3-5 24102 NULL
125338 +pipeline_post_proc_swi_read_24108 pipeline_post_proc_swi_read 3 24108 NULL
125339 +request_key_auth_read_24109 request_key_auth_read 3 24109 NULL
125340 +lov_brw_24122 lov_brw 4 24122 NULL
125341 +mpu401_read_24126 mpu401_read 3 24126 NULL
125342 +_picolcd_flash_write_24134 _picolcd_flash_write 4 24134 NULL
125343 +irnet_ctrl_write_24139 irnet_ctrl_write 3 24139 NULL
125344 +SyS_sethostname_24150 SyS_sethostname 2 24150 NULL
125345 +trim_bitmaps_24158 trim_bitmaps 3 24158 NULL
125346 +adu_read_24177 adu_read 3 24177 NULL
125347 +safe_prepare_write_buffer_24187 safe_prepare_write_buffer 3 24187 NULL
125348 +ieee80211_if_read_dot11MeshHWMPpreqMinInterval_24208 ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 NULL
125349 +tcpprobe_sprint_24222 tcpprobe_sprint 2-0 24222 NULL
125350 +pcpu_embed_first_chunk_24224 pcpu_embed_first_chunk 3-2-1 24224 NULL nohasharray
125351 +mei_amthif_read_24224 mei_amthif_read 4 24224 &pcpu_embed_first_chunk_24224
125352 +pci_num_vf_24235 pci_num_vf 0 24235 NULL
125353 +sel_read_bool_24236 sel_read_bool 3 24236 NULL
125354 +em28xx_alloc_urbs_24260 em28xx_alloc_urbs 4-6 24260 NULL
125355 +calculate_sizes_24273 calculate_sizes 2 24273 NULL
125356 +thin_status_24278 thin_status 5 24278 NULL
125357 +msg_size_24288 msg_size 0 24288 NULL
125358 +btmrvl_pscmd_read_24308 btmrvl_pscmd_read 3 24308 NULL
125359 +ath6kl_add_bss_if_needed_24317 ath6kl_add_bss_if_needed 6 24317 NULL
125360 +si476x_radio_read_acf_blob_24336 si476x_radio_read_acf_blob 3 24336 NULL
125361 +C_SYSC_pwritev_24345 C_SYSC_pwritev 3 24345 NULL
125362 +kzalloc_node_24352 kzalloc_node 1 24352 NULL
125363 +qla2x00_handle_queue_full_24365 qla2x00_handle_queue_full 2 24365 NULL
125364 +cfi_read_pri_24366 cfi_read_pri 3 24366 NULL
125365 +btrfs_item_size_nr_24367 btrfs_item_size_nr 0 24367 NULL
125366 +igetword_24373 igetword 0 24373 NULL
125367 +mpt_alloc_res_24387 mpt_alloc_res 5 24387 NULL
125368 +osc_cur_grant_bytes_seq_write_24396 osc_cur_grant_bytes_seq_write 3 24396 NULL
125369 +getxattr_24398 getxattr 4 24398 NULL nohasharray
125370 +pvr2_v4l2_ioctl_24398 pvr2_v4l2_ioctl 2 24398 &getxattr_24398
125371 +blk_update_bidi_request_24415 blk_update_bidi_request 3-4 24415 NULL
125372 +nvme_trans_log_supp_pages_24418 nvme_trans_log_supp_pages 3 24418 NULL
125373 +b43_debugfs_read_24425 b43_debugfs_read 3 24425 NULL
125374 +xenbus_file_read_24427 xenbus_file_read 3 24427 NULL
125375 +ieee80211_rx_mgmt_beacon_24430 ieee80211_rx_mgmt_beacon 3 24430 NULL
125376 +copy_and_ioctl_24434 copy_and_ioctl 4 24434 NULL
125377 +ixgbe_alloc_q_vector_24439 ixgbe_alloc_q_vector 4-6 24439 NULL
125378 +smk_user_access_24440 smk_user_access 3 24440 NULL nohasharray
125379 +rtw_set_wps_assoc_resp_24440 rtw_set_wps_assoc_resp 3 24440 &smk_user_access_24440
125380 +evdev_do_ioctl_24459 evdev_do_ioctl 2 24459 NULL
125381 +lbs_highsnr_write_24460 lbs_highsnr_write 3 24460 NULL
125382 +skb_copy_and_csum_datagram_iovec_24466 skb_copy_and_csum_datagram_iovec 2 24466 NULL
125383 +dut_mode_read_24489 dut_mode_read 3 24489 NULL
125384 +read_file_spec_scan_ctl_24491 read_file_spec_scan_ctl 3 24491 NULL
125385 +pd_video_read_24510 pd_video_read 3 24510 NULL
125386 +request_key_with_auxdata_24515 request_key_with_auxdata 4 24515 NULL
125387 +xfs_buf_get_map_24522 xfs_buf_get_map 3 24522 NULL
125388 +do_mpage_readpage_24536 do_mpage_readpage 3 24536 NULL
125389 +write_cache_pages_24562 write_cache_pages 0 24562 NULL
125390 +SyS_pselect6_24582 SyS_pselect6 1 24582 NULL
125391 +udf_compute_nr_groups_24594 udf_compute_nr_groups 0 24594 NULL
125392 +sensor_hub_get_physical_device_count_24605 sensor_hub_get_physical_device_count 0 24605 NULL nohasharray
125393 +lov_alloc_memmd_24605 lov_alloc_memmd 2 24605 &sensor_hub_get_physical_device_count_24605
125394 +SyS_poll_24620 SyS_poll 2 24620 NULL
125395 +context_alloc_24645 context_alloc 3 24645 NULL
125396 +blk_rq_err_bytes_24650 blk_rq_err_bytes 0 24650 NULL
125397 +datafab_write_data_24696 datafab_write_data 4 24696 NULL
125398 +intelfbhw_get_p1p2_24703 intelfbhw_get_p1p2 2 24703 NULL
125399 +simple_attr_read_24738 simple_attr_read 3 24738 NULL
125400 +qla2x00_change_queue_depth_24742 qla2x00_change_queue_depth 2 24742 NULL
125401 +get_dma_residue_24749 get_dma_residue 0 24749 NULL
125402 +kgdb_hex2mem_24755 kgdb_hex2mem 3 24755 NULL
125403 +ocfs2_read_blocks_24777 ocfs2_read_blocks 0 24777 NULL
125404 +datablob_hmac_verify_24786 datablob_hmac_verify 4 24786 NULL
125405 +cache_read_24790 cache_read 3 24790 NULL
125406 +user_regset_copyout_24796 user_regset_copyout 7 24796 NULL
125407 +kvm_read_guest_virt_helper_24804 kvm_read_guest_virt_helper 3-1 24804 NULL
125408 +ath6kl_fwlog_mask_write_24810 ath6kl_fwlog_mask_write 3 24810 NULL
125409 +snd_als4k_gcr_read_24840 snd_als4k_gcr_read 0 24840 NULL
125410 +snd_pcm_lib_buffer_bytes_24865 snd_pcm_lib_buffer_bytes 0 24865 NULL
125411 +pnp_alloc_24869 pnp_alloc 1 24869 NULL nohasharray
125412 +l2cap_create_basic_pdu_24869 l2cap_create_basic_pdu 3 24869 &pnp_alloc_24869
125413 +queues_read_24877 queues_read 3 24877 NULL
125414 +iov_iter_npages_bvec_24905 iov_iter_npages_bvec 0-2 24905 NULL
125415 +codec_list_read_file_24910 codec_list_read_file 3 24910 NULL
125416 +xpcs_reg_value_write_24922 xpcs_reg_value_write 3 24922 NULL
125417 +v4l2_ctrl_new_24927 v4l2_ctrl_new 7 24927 NULL
125418 +ocfs2_fiemap_24949 ocfs2_fiemap 3-4 24949 NULL
125419 +packet_sendmsg_24954 packet_sendmsg 4 24954 NULL
125420 +twl_i2c_write_u8_24976 twl_i2c_write_u8 3 24976 NULL
125421 +llc_ui_sendmsg_24987 llc_ui_sendmsg 4 24987 NULL
125422 +key_conf_hw_key_idx_read_25003 key_conf_hw_key_idx_read 3 25003 NULL
125423 +il_dbgfs_channels_read_25005 il_dbgfs_channels_read 3 25005 NULL
125424 +ni_660x_num_counters_25031 ni_660x_num_counters 0 25031 NULL
125425 +nfs_dns_resolve_name_25036 nfs_dns_resolve_name 3 25036 NULL
125426 +btrfs_stack_key_blockptr_25058 btrfs_stack_key_blockptr 0 25058 NULL
125427 +gs_buf_alloc_25067 gs_buf_alloc 2 25067 NULL
125428 +ll_track_pid_seq_write_25068 ll_track_pid_seq_write 3 25068 NULL
125429 +SYSC_listxattr_25072 SYSC_listxattr 3 25072 NULL
125430 +ima_appraise_measurement_25093 ima_appraise_measurement 6 25093 NULL
125431 +snd_rawmidi_kernel_write_25106 snd_rawmidi_kernel_write 3 25106 NULL
125432 +ipath_init_qp_table_25167 ipath_init_qp_table 2 25167 NULL
125433 +kvm_mmu_notifier_change_pte_25169 kvm_mmu_notifier_change_pte 3 25169 NULL
125434 +sctp_getsockopt_local_addrs_25178 sctp_getsockopt_local_addrs 2 25178 NULL
125435 +security_socket_post_create_25221 security_socket_post_create 0 25221 NULL
125436 +mon_stat_read_25238 mon_stat_read 3 25238 NULL
125437 +stripe_status_25259 stripe_status 5 25259 NULL
125438 +snd_pcm_start_25273 snd_pcm_start 0 25273 NULL
125439 +crypto_alloc_instance2_25277 crypto_alloc_instance2 3 25277 NULL
125440 +vfs_writev_25278 vfs_writev 3 25278 NULL
125441 +l2tp_session_create_25286 l2tp_session_create 1 25286 NULL
125442 +ath9k_debugfs_read_buf_25316 ath9k_debugfs_read_buf 3 25316 NULL
125443 +rng_buffer_size_25348 rng_buffer_size 0 25348 NULL
125444 +unix_mkname_25368 unix_mkname 0-2 25368 NULL
125445 +sel_read_mls_25369 sel_read_mls 3 25369 NULL
125446 +vsp1_entity_init_25407 vsp1_entity_init 3 25407 NULL
125447 +mcp795_rtcc_read_25415 mcp795_rtcc_read 4 25415 NULL
125448 +dai_list_read_file_25421 dai_list_read_file 3 25421 NULL
125449 +crypto_hash_digestsize_25469 crypto_hash_digestsize 0 25469 NULL
125450 +ivtv_buf_copy_from_user_25502 ivtv_buf_copy_from_user 4-0 25502 NULL
125451 +snd_pcm_plugin_build_25505 snd_pcm_plugin_build 5 25505 NULL
125452 +mxt_obj_size_25510 mxt_obj_size 0 25510 NULL
125453 +sb_permission_25523 sb_permission 0 25523 NULL
125454 +ext3_get_inode_loc_25542 ext3_get_inode_loc 0 25542 NULL
125455 +ieee80211_if_read_path_refresh_time_25545 ieee80211_if_read_path_refresh_time 3 25545 NULL
125456 +wimax_addr_scnprint_25548 wimax_addr_scnprint 2 25548 NULL
125457 +ht_print_chan_25556 ht_print_chan 3-4-0 25556 NULL
125458 +skb_tailroom_25567 skb_tailroom 0 25567 NULL
125459 +ping_recvmsg_25597 ping_recvmsg 4 25597 NULL
125460 +copy_user_generic_25611 copy_user_generic 0 25611 NULL
125461 +proc_coredump_filter_write_25625 proc_coredump_filter_write 3 25625 NULL
125462 +befs_utf2nls_25628 befs_utf2nls 3 25628 NULL nohasharray
125463 +__get_user_pages_25628 __get_user_pages 0 25628 &befs_utf2nls_25628
125464 +__direct_map_25647 __direct_map 6-5 25647 NULL
125465 +aircable_prepare_write_buffer_25669 aircable_prepare_write_buffer 3 25669 NULL
125466 +lpfc_idiag_cmd_get_25672 lpfc_idiag_cmd_get 2 25672 NULL
125467 +sta_inactive_ms_read_25690 sta_inactive_ms_read 3 25690 NULL
125468 +prom_early_alloc_25692 prom_early_alloc 1 25692 NULL
125469 +rx_filter_mc_filter_read_25712 rx_filter_mc_filter_read 3 25712 NULL
125470 +ibmasm_new_command_25714 ibmasm_new_command 2 25714 NULL
125471 +__alloc_bootmem_low_node_25726 __alloc_bootmem_low_node 2 25726 NULL nohasharray
125472 +sel_write_context_25726 sel_write_context 3 25726 &__alloc_bootmem_low_node_25726
125473 +xgbe_common_read_25743 xgbe_common_read 2 25743 NULL
125474 +cxgbi_device_portmap_create_25747 cxgbi_device_portmap_create 3 25747 NULL
125475 +event_rx_pool_read_25792 event_rx_pool_read 3 25792 NULL
125476 +sg_read_25799 sg_read 3 25799 NULL
125477 +system_enable_read_25815 system_enable_read 3 25815 NULL
125478 +realloc_buffer_25816 realloc_buffer 2 25816 NULL
125479 +pwr_missing_bcns_read_25824 pwr_missing_bcns_read 3 25824 NULL
125480 +parport_read_25855 parport_read 0 25855 NULL
125481 +xfs_dir2_sf_hdr_size_25858 xfs_dir2_sf_hdr_size 0 25858 NULL
125482 +key_attr_size_25865 key_attr_size 0 25865 NULL
125483 +ath6kl_regread_read_25884 ath6kl_regread_read 3 25884 NULL
125484 +run_delalloc_nocow_25896 run_delalloc_nocow 3-4 25896 NULL
125485 +sisusbcon_scroll_area_25899 sisusbcon_scroll_area 4-3 25899 NULL
125486 +lpfc_change_queue_depth_25905 lpfc_change_queue_depth 2 25905 NULL
125487 +nvme_trans_mode_page_create_25908 nvme_trans_mode_page_create 7-4 25908 NULL
125488 +do_jffs2_setxattr_25910 do_jffs2_setxattr 5 25910 NULL
125489 +rcname_read_25919 rcname_read 3 25919 NULL
125490 +snd_es1938_capture_copy_25930 snd_es1938_capture_copy 5 25930 NULL
125491 +key_flags_read_25931 key_flags_read 3 25931 NULL
125492 +copy_play_buf_25932 copy_play_buf 3 25932 NULL
125493 +flush_25957 flush 2 25957 NULL
125494 +_regmap_multi_reg_write_25967 _regmap_multi_reg_write 3 25967 NULL
125495 +udp_setsockopt_25985 udp_setsockopt 5 25985 NULL
125496 +lustre_msg_buflen_v2_25997 lustre_msg_buflen_v2 0 25997 NULL
125497 +SyS_process_vm_readv_26019 SyS_process_vm_readv 3-5 26019 NULL
125498 +mptscsih_change_queue_depth_26036 mptscsih_change_queue_depth 2 26036 NULL
125499 +selinux_inode_post_setxattr_26037 selinux_inode_post_setxattr 4 26037 NULL
125500 +keyctl_update_key_26061 keyctl_update_key 3 26061 NULL
125501 +pri_wm_latency_write_26063 pri_wm_latency_write 3 26063 NULL
125502 +rx_rx_wa_density_dropped_frame_read_26095 rx_rx_wa_density_dropped_frame_read 3 26095 NULL
125503 +read_sb_page_26119 read_sb_page 5 26119 NULL
125504 +ath9k_hw_name_26146 ath9k_hw_name 3 26146 NULL
125505 +copy_oldmem_page_26164 copy_oldmem_page 3 26164 NULL
125506 +gfs2_xattr_acl_get_26166 gfs2_xattr_acl_get 0 26166 NULL nohasharray
125507 +ath6kl_roam_table_read_26166 ath6kl_roam_table_read 3 26166 &gfs2_xattr_acl_get_26166
125508 +disk_devt_26180 disk_devt 0 26180 NULL
125509 +ieee80211_if_fmt_dot11MeshTTL_26198 ieee80211_if_fmt_dot11MeshTTL 3 26198 NULL
125510 +xfs_idata_realloc_26199 xfs_idata_realloc 2 26199 NULL
125511 +mce_write_26201 mce_write 3 26201 NULL
125512 +mwifiex_regrdwr_write_26225 mwifiex_regrdwr_write 3 26225 NULL
125513 +_scsih_change_queue_depth_26230 _scsih_change_queue_depth 2 26230 NULL
125514 +rxrpc_recvmsg_26233 rxrpc_recvmsg 4 26233 NULL
125515 +genwqe_ffdc_buff_size_26263 genwqe_ffdc_buff_size 0 26263 NULL
125516 +crypto_ctxsize_26278 crypto_ctxsize 0 26278 NULL
125517 +wacom_set_device_mode_26280 wacom_set_device_mode 3 26280 NULL
125518 +snd_pcm_plug_client_channels_buf_26309 snd_pcm_plug_client_channels_buf 0-3 26309 NULL
125519 +pwr_wake_on_host_read_26321 pwr_wake_on_host_read 3 26321 NULL
125520 +check_can_nocow_26336 check_can_nocow 2 26336 NULL
125521 +snd_vx_check_reg_bit_26344 snd_vx_check_reg_bit 0 26344 NULL
125522 +ocfs2_duplicate_clusters_by_page_26357 ocfs2_duplicate_clusters_by_page 6-3 26357 NULL
125523 +cifs_readdata_alloc_26360 cifs_readdata_alloc 1 26360 NULL
125524 +invalidate_inode_pages2_range_26403 invalidate_inode_pages2_range 0 26403 NULL
125525 +ntty_write_26404 ntty_write 3 26404 NULL
125526 +firmware_store_26408 firmware_store 4 26408 NULL
125527 +tower_read_26461 tower_read 3 26461 NULL nohasharray
125528 +enc_pools_add_pages_26461 enc_pools_add_pages 1 26461 &tower_read_26461
125529 +ib_alloc_device_26483 ib_alloc_device 1 26483 NULL
125530 +ulong_write_file_26485 ulong_write_file 3 26485 NULL
125531 +dvb_ca_en50221_io_ioctl_26490 dvb_ca_en50221_io_ioctl 2 26490 NULL
125532 +uhid_char_write_26502 uhid_char_write 3 26502 NULL
125533 +vfio_pci_set_msi_trigger_26507 vfio_pci_set_msi_trigger 4-3 26507 NULL
125534 +iwl_dbgfs_rf_reset_read_26512 iwl_dbgfs_rf_reset_read 3 26512 NULL
125535 +alloc_ep_req_26521 alloc_ep_req 3-2 26521 NULL
125536 +SyS_rt_sigpending_26538 SyS_rt_sigpending 2 26538 NULL
125537 +__vhost_add_used_n_26554 __vhost_add_used_n 3 26554 NULL
125538 +dio_new_bio_26562 dio_new_bio 0 26562 NULL
125539 +rts51x_read_mem_26577 rts51x_read_mem 4 26577 NULL
125540 +pwr_fix_tsf_ps_read_26627 pwr_fix_tsf_ps_read 3 26627 NULL
125541 +amdtp_stream_get_max_payload_26645 amdtp_stream_get_max_payload 0 26645 NULL
125542 +irq_alloc_generic_chip_26650 irq_alloc_generic_chip 2 26650 NULL
125543 +nouveau_volt_create__26654 nouveau_volt_create_ 4 26654 NULL
125544 +cipso_v4_map_cat_rbm_hton_26680 cipso_v4_map_cat_rbm_hton 0 26680 NULL
125545 +flowinfo_read_26683 flowinfo_read 3 26683 NULL
125546 +nouveau_namedb_create__26732 nouveau_namedb_create_ 7 26732 NULL
125547 +pipeline_tcp_rx_stat_fifo_int_read_26745 pipeline_tcp_rx_stat_fifo_int_read 3 26745 NULL
125548 +snd_hda_get_raw_connections_26762 snd_hda_get_raw_connections 0 26762 NULL
125549 +dma_map_single_attrs_26779 dma_map_single_attrs 0 26779 NULL
125550 +qlcnic_alloc_sds_rings_26795 qlcnic_alloc_sds_rings 2 26795 NULL
125551 +cipso_v4_genopt_26812 cipso_v4_genopt 0 26812 NULL
125552 +iwl_trans_read_mem32_26825 iwl_trans_read_mem32 0 26825 NULL
125553 +smk_write_load_26829 smk_write_load 3 26829 NULL
125554 +scnprint_id_26842 scnprint_id 3-0 26842 NULL
125555 +ecryptfs_miscdev_write_26847 ecryptfs_miscdev_write 3 26847 NULL
125556 +ss_alloc_ep_req_26848 ss_alloc_ep_req 2 26848 NULL
125557 +tipc_conn_sendmsg_26867 tipc_conn_sendmsg 5 26867 NULL
125558 +ath6kl_create_qos_write_26879 ath6kl_create_qos_write 3 26879 NULL
125559 +svc_print_xprts_26881 svc_print_xprts 0 26881 NULL
125560 +skb_zerocopy_headlen_26910 skb_zerocopy_headlen 0 26910 NULL
125561 +hhf_zalloc_26912 hhf_zalloc 1 26912 NULL
125562 +cfg80211_process_auth_26916 cfg80211_process_auth 3 26916 NULL
125563 +x25_asy_change_mtu_26928 x25_asy_change_mtu 2 26928 NULL
125564 +scsi_tgt_copy_sense_26933 scsi_tgt_copy_sense 3 26933 NULL
125565 +sctp_setsockopt_adaptation_layer_26935 sctp_setsockopt_adaptation_layer 3 26935 NULL nohasharray
125566 +pwr_ps_enter_read_26935 pwr_ps_enter_read 3 26935 &sctp_setsockopt_adaptation_layer_26935
125567 +hecubafb_write_26942 hecubafb_write 3 26942 NULL
125568 +do_trimming_26952 do_trimming 3 26952 NULL nohasharray
125569 +extract_entropy_user_26952 extract_entropy_user 3 26952 &do_trimming_26952
125570 +do_direct_IO_26979 do_direct_IO 0 26979 NULL
125571 +sc16is7xx_port_read_27051 sc16is7xx_port_read 0 27051 NULL
125572 +__videobuf_alloc_vb_27062 __videobuf_alloc_vb 1 27062 NULL
125573 +ext4_convert_unwritten_extents_27064 ext4_convert_unwritten_extents 4-3 27064 NULL
125574 +snd_pcm_lib_period_bytes_27071 snd_pcm_lib_period_bytes 0 27071 NULL
125575 +paravirt_read_msr_27077 paravirt_read_msr 0 27077 NULL
125576 +alloc_fdmem_27083 alloc_fdmem 1 27083 NULL
125577 +btmrvl_hscmd_write_27089 btmrvl_hscmd_write 3 27089 NULL nohasharray
125578 +ath9k_hw_4k_dump_eeprom_27089 ath9k_hw_4k_dump_eeprom 5-4 27089 &btmrvl_hscmd_write_27089
125579 +__devcgroup_inode_permission_27108 __devcgroup_inode_permission 0 27108 NULL
125580 +drbd_get_capacity_27141 drbd_get_capacity 0 27141 NULL
125581 +pms_capture_27142 pms_capture 4 27142 NULL
125582 +btmrvl_hscfgcmd_write_27143 btmrvl_hscfgcmd_write 3 27143 NULL
125583 +snd_compr_calc_avail_27165 snd_compr_calc_avail 0 27165 NULL
125584 +ieee80211_if_read_rc_rateidx_mask_5ghz_27183 ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 NULL
125585 +dbAllocAG_27228 dbAllocAG 0 27228 NULL
125586 +rxrpc_request_key_27235 rxrpc_request_key 3 27235 NULL
125587 +ll_track_gid_seq_write_27267 ll_track_gid_seq_write 3 27267 NULL
125588 +comedi_alloc_devpriv_27272 comedi_alloc_devpriv 2 27272 NULL
125589 +get_rx_fifo_content_27283 get_rx_fifo_content 0 27283 NULL
125590 +copy_from_buf_27308 copy_from_buf 4-2 27308 NULL
125591 +virtqueue_add_inbuf_27312 virtqueue_add_inbuf 3 27312 NULL
125592 +snd_pcm_oss_write2_27332 snd_pcm_oss_write2 3-0 27332 NULL
125593 +afs_cell_create_27346 afs_cell_create 2 27346 NULL
125594 +iwl_dbgfs_csr_write_27363 iwl_dbgfs_csr_write 3 27363 NULL
125595 +pcbit_stat_27364 pcbit_stat 2 27364 NULL
125596 +seq_read_27411 seq_read 3 27411 NULL
125597 +ib_dma_map_sg_27413 ib_dma_map_sg 0 27413 NULL
125598 +ieee80211_if_read_smps_27416 ieee80211_if_read_smps 3 27416 NULL
125599 +cypress_write_27423 cypress_write 4 27423 NULL
125600 +sddr09_read_data_27447 sddr09_read_data 3 27447 NULL
125601 +v4l2_ctrl_new_std_menu_items_27487 v4l2_ctrl_new_std_menu_items 4 27487 NULL
125602 +hcd_buffer_alloc_27495 hcd_buffer_alloc 2 27495 NULL
125603 +ip_set_get_h32_27498 ip_set_get_h32 0 27498 NULL
125604 +btrfs_get_64_27499 btrfs_get_64 0 27499 NULL
125605 +garmin_read_process_27509 garmin_read_process 3 27509 NULL
125606 +oti_alloc_cookies_27510 oti_alloc_cookies 2 27510 NULL
125607 +ib_copy_to_udata_27525 ib_copy_to_udata 3 27525 NULL
125608 +snd_sonicvibes_getdmaa_27552 snd_sonicvibes_getdmaa 0 27552 NULL
125609 +SyS_fgetxattr_27571 SyS_fgetxattr 4 27571 NULL
125610 +sco_sock_recvmsg_27572 sco_sock_recvmsg 4 27572 NULL
125611 +libipw_alloc_txb_27579 libipw_alloc_txb 1 27579 NULL
125612 +C_SYSC_mbind_27636 C_SYSC_mbind 5 27636 NULL
125613 +read_flush_procfs_27642 read_flush_procfs 3 27642 NULL nohasharray
125614 +nl80211_send_connect_result_27642 nl80211_send_connect_result 5-7 27642 &read_flush_procfs_27642 nohasharray
125615 +ocfs2_xattr_ibody_get_27642 ocfs2_xattr_ibody_get 0 27642 &nl80211_send_connect_result_27642
125616 +add_new_gdb_27643 add_new_gdb 3 27643 NULL
125617 +btrfs_fallocate_27647 btrfs_fallocate 3-4 27647 NULL
125618 +qnx6_readpages_27657 qnx6_readpages 4 27657 NULL
125619 +cdrom_read_cdda_old_27664 cdrom_read_cdda_old 4 27664 NULL
125620 +ocfs2_extend_dir_27695 ocfs2_extend_dir 4 27695 NULL
125621 +fs_path_add_from_extent_buffer_27702 fs_path_add_from_extent_buffer 4 27702 NULL
125622 +evm_write_key_27715 evm_write_key 3 27715 NULL
125623 +ieee80211_if_fmt_dot11MeshGateAnnouncementProtocol_27722 ieee80211_if_fmt_dot11MeshGateAnnouncementProtocol 3 27722 NULL
125624 +xfs_dir2_block_sfsize_27727 xfs_dir2_block_sfsize 0 27727 NULL
125625 +SyS_setsockopt_27759 SyS_setsockopt 5 27759 NULL
125626 +transport_init_session_tags_27776 transport_init_session_tags 1-2 27776 NULL
125627 +__lov_setstripe_27782 __lov_setstripe 2 27782 NULL
125628 +twl4030_set_gpio_dataout_27792 twl4030_set_gpio_dataout 1 27792 NULL
125629 +SyS_readv_27804 SyS_readv 3 27804 NULL
125630 +mpihelp_mul_27805 mpihelp_mul 5-3 27805 NULL
125631 +hpt374_read_freq_27828 hpt374_read_freq 0 27828 NULL
125632 +read_profile_27859 read_profile 3 27859 NULL
125633 +sky2_pci_read16_27863 sky2_pci_read16 0 27863 NULL
125634 +ieee80211_if_read_dot11MeshHWMProotInterval_27873 ieee80211_if_read_dot11MeshHWMProotInterval 3 27873 NULL
125635 +unix_seqpacket_sendmsg_27893 unix_seqpacket_sendmsg 4 27893 NULL
125636 +i915_error_object_create_sized_27919 i915_error_object_create_sized 4 27919 NULL
125637 +tracing_clock_write_27961 tracing_clock_write 3 27961 NULL nohasharray
125638 +bio_next_split_27961 bio_next_split 2 27961 &tracing_clock_write_27961
125639 +tipc_media_addr_printf_27971 tipc_media_addr_printf 2 27971 NULL
125640 +mic_rx_pkts_read_27972 mic_rx_pkts_read 3 27972 NULL
125641 +compat_SyS_set_mempolicy_27975 compat_SyS_set_mempolicy 3 27975 NULL
125642 +edt_ft5x06_debugfs_raw_data_read_28002 edt_ft5x06_debugfs_raw_data_read 3 28002 NULL
125643 +seq_get_buf_28006 seq_get_buf 0 28006 NULL
125644 +snd_rawmidi_write_28008 snd_rawmidi_write 3 28008 NULL
125645 +powercap_register_zone_28028 powercap_register_zone 6 28028 NULL
125646 +sctp_setsockopt_maxburst_28041 sctp_setsockopt_maxburst 3 28041 NULL
125647 +cx231xx_init_vbi_isoc_28053 cx231xx_init_vbi_isoc 3-2-4 28053 NULL
125648 +pool_status_28055 pool_status 5 28055 NULL
125649 +init_rs_non_canonical_28059 init_rs_non_canonical 1 28059 NULL
125650 +lpfc_idiag_mbxacc_read_28061 lpfc_idiag_mbxacc_read 3 28061 NULL
125651 +tx_frag_bad_mblk_num_read_28064 tx_frag_bad_mblk_num_read 3 28064 NULL
125652 +mmc_test_alloc_mem_28102 mmc_test_alloc_mem 3-2 28102 NULL
125653 +rx_defrag_need_defrag_read_28117 rx_defrag_need_defrag_read 3 28117 NULL
125654 +vgacon_adjust_height_28124 vgacon_adjust_height 2 28124 NULL
125655 +m25p80_read_reg_28132 m25p80_read_reg 4 28132 NULL
125656 +video_read_28148 video_read 3 28148 NULL
125657 +snd_midi_channel_alloc_set_28153 snd_midi_channel_alloc_set 1 28153 NULL
125658 +stats_dot11FCSErrorCount_read_28154 stats_dot11FCSErrorCount_read 3 28154 NULL
125659 +macvtap_get_user_28185 macvtap_get_user 4 28185 NULL
125660 +counter_free_res_28187 counter_free_res 5 28187 NULL
125661 +read_disk_sb_28188 read_disk_sb 2 28188 NULL
125662 +nvkm_output_dp_create__28192 nvkm_output_dp_create_ 6 28192 NULL
125663 +nouveau_mxm_create__28200 nouveau_mxm_create_ 4 28200 NULL
125664 +__qp_memcpy_from_queue_28220 __qp_memcpy_from_queue 3-4 28220 NULL
125665 +line6_alloc_sysex_buffer_28225 line6_alloc_sysex_buffer 4 28225 NULL
125666 +amd_nb_num_28228 amd_nb_num 0 28228 NULL
125667 +usemap_size_28281 usemap_size 0 28281 NULL
125668 +inline_xattr_size_28285 inline_xattr_size 0 28285 NULL
125669 +dma_map_sg_attrs_28289 dma_map_sg_attrs 0 28289 NULL
125670 +SyS_ppoll_28290 SyS_ppoll 2 28290 NULL
125671 +kstrtos16_from_user_28300 kstrtos16_from_user 2 28300 NULL
125672 +nouveau_compat_ioctl_28305 nouveau_compat_ioctl 2 28305 NULL
125673 +snd_pcm_oss_read_28317 snd_pcm_oss_read 3 28317 NULL
125674 +xpcs_mmd_read_28331 xpcs_mmd_read 3 28331 NULL
125675 +bm_entry_write_28338 bm_entry_write 3 28338 NULL
125676 +tcp_copy_to_iovec_28344 tcp_copy_to_iovec 3 28344 NULL
125677 +xfs_iomap_write_unwritten_28365 xfs_iomap_write_unwritten 3-2 28365 NULL
125678 +batadv_handle_tt_response_28370 batadv_handle_tt_response 4 28370 NULL
125679 +dlmfs_file_read_28385 dlmfs_file_read 3 28385 NULL
125680 +tx_frag_cache_miss_read_28394 tx_frag_cache_miss_read 3 28394 NULL
125681 +bypass_pwup_write_28416 bypass_pwup_write 3 28416 NULL
125682 +subdev_ioctl_28417 subdev_ioctl 2 28417 NULL
125683 +ksocknal_alloc_tx_28426 ksocknal_alloc_tx 2 28426 NULL
125684 +mpage_readpages_28436 mpage_readpages 3 28436 NULL
125685 +snd_emu10k1_efx_read_28452 snd_emu10k1_efx_read 2 28452 NULL
125686 +key_mic_failures_read_28457 key_mic_failures_read 3 28457 NULL
125687 +alloc_irq_cpu_rmap_28459 alloc_irq_cpu_rmap 1 28459 NULL
125688 +ps_poll_upsd_utilization_read_28519 ps_poll_upsd_utilization_read 3 28519 NULL
125689 +sh_irda_init_iobuf_28527 sh_irda_init_iobuf 2 28527 NULL nohasharray
125690 +i2400m_tx_stats_read_28527 i2400m_tx_stats_read 3 28527 &sh_irda_init_iobuf_28527
125691 +early_init_dt_alloc_memory_arch_28528 early_init_dt_alloc_memory_arch 1 28528 NULL
125692 +sel_read_policycap_28544 sel_read_policycap 3 28544 NULL
125693 +mptctl_getiocinfo_28545 mptctl_getiocinfo 2 28545 NULL nohasharray
125694 +run_delalloc_range_28545 run_delalloc_range 3-4 28545 &mptctl_getiocinfo_28545 nohasharray
125695 +aio_read_events_28545 aio_read_events 3 28545 &run_delalloc_range_28545
125696 +b43legacy_debugfs_write_28556 b43legacy_debugfs_write 3 28556 NULL
125697 +asymmetric_verify_28567 asymmetric_verify 3 28567 NULL
125698 +oxygen_read32_28582 oxygen_read32 0 28582 NULL
125699 +extract_entropy_28604 extract_entropy 5-3 28604 NULL
125700 +xgbe_common_write_28609 xgbe_common_write 2 28609 NULL
125701 +kfifo_unused_28612 kfifo_unused 0 28612 NULL
125702 +snd_nm256_capture_copy_28622 snd_nm256_capture_copy 3-5 28622 NULL
125703 +setup_usemap_28636 setup_usemap 3-4 28636 NULL
125704 +p9_fcall_alloc_28652 p9_fcall_alloc 1 28652 NULL
125705 +blk_queue_resize_tags_28670 blk_queue_resize_tags 2 28670 NULL
125706 +SyS_setgroups16_28686 SyS_setgroups16 1 28686 NULL
125707 +kvm_mmu_get_page_28692 kvm_mmu_get_page 2 28692 NULL
125708 +drm_plane_init_28731 drm_plane_init 6 28731 NULL
125709 +spi_execute_28736 spi_execute 5 28736 NULL
125710 +snd_pcm_aio_write_28738 snd_pcm_aio_write 3 28738 NULL
125711 +read_file_btcoex_28743 read_file_btcoex 3 28743 NULL
125712 +max_hw_blocks_28748 max_hw_blocks 0 28748 NULL
125713 +rpc_pipe_generic_upcall_28766 rpc_pipe_generic_upcall 4 28766 NULL
125714 +ath6kl_get_num_reg_28780 ath6kl_get_num_reg 0 28780 NULL
125715 +sel_write_member_28800 sel_write_member 3 28800 NULL
125716 +iwl_dbgfs_rxon_filter_flags_read_28832 iwl_dbgfs_rxon_filter_flags_read 3 28832 NULL
125717 +kernel_tree_alloc_28833 kernel_tree_alloc 1 28833 NULL
125718 +vp_request_msix_vectors_28849 vp_request_msix_vectors 2 28849 NULL
125719 +ipv6_renew_options_28867 ipv6_renew_options 5 28867 NULL
125720 +packet_sendmsg_spkt_28885 packet_sendmsg_spkt 4 28885 NULL
125721 +da9055_group_write_28904 da9055_group_write 2-3 28904 NULL
125722 +ps_upsd_timeouts_read_28924 ps_upsd_timeouts_read 3 28924 NULL
125723 +iwl_dbgfs_sleep_level_override_write_28925 iwl_dbgfs_sleep_level_override_write 3 28925 NULL
125724 +push_rx_28939 push_rx 3 28939 NULL
125725 +mxuport_prepare_write_buffer_28943 mxuport_prepare_write_buffer 3 28943 NULL
125726 +btrfs_trim_block_group_28963 btrfs_trim_block_group 3-4 28963 NULL
125727 +alloc_sched_domains_28972 alloc_sched_domains 1 28972 NULL
125728 +hash_net6_expire_28979 hash_net6_expire 4 28979 NULL
125729 +hci_sock_setsockopt_28993 hci_sock_setsockopt 5 28993 NULL
125730 +bin_uuid_28999 bin_uuid 3 28999 NULL
125731 +fd_execute_rw_29004 fd_execute_rw 3 29004 NULL
125732 +ieee80211_if_read_ht_opmode_29044 ieee80211_if_read_ht_opmode 3 29044 NULL
125733 +rxrpc_sendmsg_29049 rxrpc_sendmsg 4 29049 NULL
125734 +btrfs_root_bytenr_29058 btrfs_root_bytenr 0 29058 NULL
125735 +iso_packets_buffer_init_29061 iso_packets_buffer_init 3-4 29061 NULL
125736 +lpfc_idiag_extacc_drivr_get_29067 lpfc_idiag_extacc_drivr_get 0-3 29067 NULL
125737 +sctp_getsockopt_assoc_stats_29074 sctp_getsockopt_assoc_stats 2 29074 NULL
125738 +iwl_dbgfs_log_event_write_29088 iwl_dbgfs_log_event_write 3 29088 NULL
125739 +ccp_init_dm_workarea_29097 ccp_init_dm_workarea 3 29097 NULL
125740 +__compat_sys_preadv64_29103 __compat_sys_preadv64 3 29103 NULL
125741 +isdn_ppp_write_29109 isdn_ppp_write 4 29109 NULL
125742 +snprintf_29125 snprintf 0 29125 NULL
125743 +iov_shorten_29130 iov_shorten 0 29130 NULL
125744 +proc_scsi_write_29142 proc_scsi_write 3 29142 NULL
125745 +kvm_mmu_notifier_clear_flush_young_29154 kvm_mmu_notifier_clear_flush_young 3 29154 NULL
125746 +drm_property_create_enum_29201 drm_property_create_enum 5 29201 NULL
125747 +wusb_prf_256_29203 wusb_prf_256 7 29203 NULL
125748 +iwl_dbgfs_temperature_read_29224 iwl_dbgfs_temperature_read 3 29224 NULL
125749 +nvme_trans_copy_from_user_29227 nvme_trans_copy_from_user 3 29227 NULL
125750 +irq_domain_add_linear_29236 irq_domain_add_linear 2 29236 NULL
125751 +recover_peb_29238 recover_peb 0 29238 NULL
125752 +evdev_handle_get_val_29242 evdev_handle_get_val 5-6 29242 NULL
125753 +security_context_to_sid_core_29248 security_context_to_sid_core 2 29248 NULL
125754 +rbd_osd_req_create_29260 rbd_osd_req_create 3 29260 NULL
125755 +prism2_set_genericelement_29277 prism2_set_genericelement 3 29277 NULL
125756 +ext4_fiemap_29296 ext4_fiemap 4 29296 NULL
125757 +sn9c102_read_29305 sn9c102_read 3 29305 NULL
125758 +__fuse_get_req_29315 __fuse_get_req 2 29315 NULL
125759 +lprocfs_write_helper_29323 lprocfs_write_helper 2 29323 NULL
125760 +kvm_handle_hva_29326 kvm_handle_hva 2 29326 NULL
125761 +obd_proc_jobid_name_seq_write_29332 obd_proc_jobid_name_seq_write 3 29332 NULL
125762 +tun_put_user_29337 tun_put_user 5 29337 NULL
125763 +__alloc_ei_netdev_29338 __alloc_ei_netdev 1 29338 NULL
125764 +l2cap_sock_setsockopt_old_29346 l2cap_sock_setsockopt_old 4 29346 NULL
125765 +read_file_tx99_power_29405 read_file_tx99_power 3 29405 NULL
125766 +mempool_create_29437 mempool_create 1 29437 NULL
125767 +crypto_ahash_alignmask_29445 crypto_ahash_alignmask 0 29445 NULL
125768 +p9_client_prepare_req_29448 p9_client_prepare_req 3 29448 NULL
125769 +validate_scan_freqs_29462 validate_scan_freqs 0 29462 NULL
125770 +SyS_flistxattr_29474 SyS_flistxattr 3 29474 NULL
125771 +do_register_entry_29478 do_register_entry 4 29478 NULL
125772 +simple_strtoul_29480 simple_strtoul 0 29480 NULL
125773 +btmrvl_pscmd_write_29504 btmrvl_pscmd_write 3 29504 NULL
125774 +btrfs_file_extent_disk_bytenr_29505 btrfs_file_extent_disk_bytenr 0 29505 NULL
125775 +usnic_vnic_spec_dump_29508 usnic_vnic_spec_dump 2 29508 NULL
125776 +write_file_regidx_29517 write_file_regidx 3 29517 NULL
125777 +atk_debugfs_ggrp_read_29522 atk_debugfs_ggrp_read 3 29522 NULL
125778 +ftrace_write_29551 ftrace_write 3 29551 NULL
125779 +idetape_queue_rw_tail_29562 idetape_queue_rw_tail 3 29562 NULL
125780 +leaf_dealloc_29566 leaf_dealloc 3 29566 NULL
125781 +kvm_read_guest_virt_system_29569 kvm_read_guest_virt_system 4-2 29569 NULL
125782 +lbs_lowsnr_read_29571 lbs_lowsnr_read 3 29571 NULL
125783 +iwl_dbgfs_missed_beacon_write_29586 iwl_dbgfs_missed_beacon_write 3 29586 NULL
125784 +pvr2_hdw_report_unlocked_29589 pvr2_hdw_report_unlocked 4-0 29589 NULL
125785 +dio_set_defer_completion_29599 dio_set_defer_completion 0 29599 NULL
125786 +slots_per_page_29601 slots_per_page 0 29601 NULL
125787 +osc_cached_mb_seq_write_29610 osc_cached_mb_seq_write 3 29610 NULL
125788 +nla_get_u16_29624 nla_get_u16 0 29624 NULL
125789 +tx_frag_cache_hit_read_29639 tx_frag_cache_hit_read 3 29639 NULL
125790 +sctp_make_abort_user_29654 sctp_make_abort_user 3 29654 NULL nohasharray
125791 +spmi_controller_alloc_29654 spmi_controller_alloc 2 29654 &sctp_make_abort_user_29654
125792 +sisusb_write_mem_bulk_29678 sisusb_write_mem_bulk 4 29678 NULL
125793 +lustre_posix_acl_xattr_2ext_29693 lustre_posix_acl_xattr_2ext 2 29693 NULL
125794 +posix_acl_from_xattr_29708 posix_acl_from_xattr 3 29708 NULL
125795 +probes_write_29711 probes_write 3 29711 NULL
125796 +read_cis_cache_29735 read_cis_cache 4 29735 NULL
125797 +xfs_new_eof_29737 xfs_new_eof 2 29737 NULL
125798 +std_nic_write_29752 std_nic_write 3 29752 NULL
125799 +static_key_count_29771 static_key_count 0 29771 NULL
125800 +dbAlloc_29794 dbAlloc 0 29794 NULL
125801 +tcp_sendpage_29829 tcp_sendpage 4 29829 NULL
125802 +__probe_kernel_write_29842 __probe_kernel_write 3 29842 NULL
125803 +kvm_read_hva_atomic_29848 kvm_read_hva_atomic 3 29848 NULL
125804 +write_file_bool_bmps_29870 write_file_bool_bmps 3 29870 NULL
125805 +ipv6_setsockopt_29871 ipv6_setsockopt 5 29871 NULL
125806 +crypto_aead_alignmask_29885 crypto_aead_alignmask 0 29885 NULL
125807 +rtw_cfg80211_indicate_sta_assoc_29897 rtw_cfg80211_indicate_sta_assoc 3 29897 NULL
125808 +lov_ost_pool_extend_29914 lov_ost_pool_extend 2 29914 NULL
125809 +write_file_queue_29922 write_file_queue 3 29922 NULL
125810 +__btrfs_getxattr_29947 __btrfs_getxattr 0 29947 NULL nohasharray
125811 +ipv6_recv_error_29947 ipv6_recv_error 3 29947 &__btrfs_getxattr_29947
125812 +dev_mem_write_30028 dev_mem_write 3 30028 NULL
125813 +alloc_netdev_mqs_30030 alloc_netdev_mqs 1 30030 NULL
125814 +scsi_vpd_inquiry_30040 scsi_vpd_inquiry 0-4 30040 NULL
125815 +drp_wmove_30043 drp_wmove 4 30043 NULL
125816 +cxgbi_ddp_reserve_30091 cxgbi_ddp_reserve 4 30091 NULL
125817 +snd_midi_channel_init_set_30092 snd_midi_channel_init_set 1 30092 NULL
125818 +rx_filter_data_filter_read_30098 rx_filter_data_filter_read 3 30098 NULL
125819 +spi_async_locked_30117 spi_async_locked 0 30117 NULL
125820 +u_memcpya_30139 u_memcpya 3-2 30139 NULL
125821 +dbg_port_buf_30145 dbg_port_buf 2 30145 NULL
125822 +alloc_switch_ctx_30165 alloc_switch_ctx 2 30165 NULL
125823 +expand_inode_data_30169 expand_inode_data 3-2 30169 NULL
125824 +mempool_create_page_pool_30189 mempool_create_page_pool 1 30189 NULL
125825 +drm_property_create_bitmask_30195 drm_property_create_bitmask 5 30195 NULL
125826 +__genwqe_readq_30197 __genwqe_readq 0 30197 NULL
125827 +usblp_ioctl_30203 usblp_ioctl 2 30203 NULL
125828 +bitmap_file_set_bit_30228 bitmap_file_set_bit 2 30228 NULL
125829 +rawv6_recvmsg_30265 rawv6_recvmsg 4 30265 NULL
125830 +isr_pci_pm_read_30271 isr_pci_pm_read 3 30271 NULL
125831 +compat_readv_30273 compat_readv 3 30273 NULL
125832 +skcipher_sendmsg_30290 skcipher_sendmsg 4 30290 NULL
125833 +pipeline_sec_frag_swi_read_30294 pipeline_sec_frag_swi_read 3 30294 NULL
125834 +tcp_sendmsg_30296 tcp_sendmsg 4 30296 NULL
125835 +osc_contention_seconds_seq_write_30305 osc_contention_seconds_seq_write 3 30305 NULL
125836 +ext4_acl_from_disk_30320 ext4_acl_from_disk 2 30320 NULL
125837 +resource_from_user_30341 resource_from_user 3 30341 NULL
125838 +o2nm_this_node_30342 o2nm_this_node 0 30342 NULL
125839 +kstrtou32_from_user_30361 kstrtou32_from_user 2 30361 NULL
125840 +pvscsi_change_queue_depth_30365 pvscsi_change_queue_depth 2 30365 NULL
125841 +C_SYSC_readv_30369 C_SYSC_readv 3 30369 NULL
125842 +blkdev_issue_zeroout_30392 blkdev_issue_zeroout 3 30392 NULL
125843 +c4iw_init_resource_30393 c4iw_init_resource 2-3 30393 NULL
125844 +vb2_fop_write_30420 vb2_fop_write 3 30420 NULL
125845 +tx_tx_template_prepared_read_30424 tx_tx_template_prepared_read 3 30424 NULL
125846 +lstcon_session_info_30425 lstcon_session_info 6 30425 NULL
125847 +enable_write_30456 enable_write 3 30456 NULL
125848 +tx_tx_template_programmed_read_30461 tx_tx_template_programmed_read 3 30461 NULL
125849 +urandom_read_30462 urandom_read 3 30462 NULL
125850 +zoran_ioctl_30465 zoran_ioctl 2 30465 NULL
125851 +adu_write_30487 adu_write 3 30487 NULL
125852 +dtim_interval_write_30489 dtim_interval_write 3 30489 NULL
125853 +batadv_send_tt_request_30493 batadv_send_tt_request 5 30493 NULL
125854 +memblock_virt_alloc_node_30515 memblock_virt_alloc_node 1 30515 NULL
125855 +dwc3_testmode_write_30516 dwc3_testmode_write 3 30516 NULL
125856 +debug_debug2_read_30526 debug_debug2_read 3 30526 NULL
125857 +disk_expand_part_tbl_30561 disk_expand_part_tbl 2 30561 NULL
125858 +set_le_30581 set_le 4 30581 NULL
125859 +blk_init_tags_30592 blk_init_tags 1 30592 NULL
125860 +sgl_map_user_pages_30610 sgl_map_user_pages 2 30610 NULL
125861 +macvtap_sendmsg_30629 macvtap_sendmsg 4 30629 NULL
125862 +ieee80211_if_read_dot11MeshAwakeWindowDuration_30631 ieee80211_if_read_dot11MeshAwakeWindowDuration 3 30631 NULL
125863 +compat_raw_setsockopt_30634 compat_raw_setsockopt 5 30634 NULL
125864 +mlx5_ib_alloc_fast_reg_page_list_30638 mlx5_ib_alloc_fast_reg_page_list 2 30638 NULL
125865 +SyS_listxattr_30647 SyS_listxattr 3 30647 NULL
125866 +jffs2_flash_read_30667 jffs2_flash_read 0 30667 NULL
125867 +sst_hsw_get_dsp_position_30691 sst_hsw_get_dsp_position 0 30691 NULL
125868 +get_pages_alloc_iovec_30699 get_pages_alloc_iovec 3-0 30699 NULL
125869 +dccp_setsockopt_ccid_30701 dccp_setsockopt_ccid 4 30701 NULL
125870 +lbs_wrbbp_write_30712 lbs_wrbbp_write 3 30712 NULL
125871 +lbs_debugfs_read_30721 lbs_debugfs_read 3 30721 NULL
125872 +snd_nm256_playback_silence_30727 snd_nm256_playback_silence 3-4 30727 NULL
125873 +snapshot_status_30744 snapshot_status 5 30744 NULL
125874 +fuse_direct_IO_30753 fuse_direct_IO 4 30753 NULL
125875 +fuse_conn_limit_write_30777 fuse_conn_limit_write 3 30777 NULL
125876 +__bio_alloc_30787 __bio_alloc 3 30787 NULL
125877 +smk_read_doi_30813 smk_read_doi 3 30813 NULL
125878 +get_kobj_path_length_30831 get_kobj_path_length 0 30831 NULL
125879 +ath10k_write_fw_dbglog_30835 ath10k_write_fw_dbglog 3 30835 NULL
125880 +of_gpio_named_count_30841 of_gpio_named_count 0 30841 NULL
125881 +sctp_setsockopt_auth_chunk_30843 sctp_setsockopt_auth_chunk 3 30843 NULL
125882 +wd_autoreset_write_30862 wd_autoreset_write 3 30862 NULL
125883 +ieee80211_if_fmt_dropped_frames_no_route_30884 ieee80211_if_fmt_dropped_frames_no_route 3 30884 NULL
125884 +pn_recvmsg_30887 pn_recvmsg 4 30887 NULL
125885 +usnic_debugfs_buildinfo_read_30928 usnic_debugfs_buildinfo_read 3 30928 NULL
125886 +sctp_setsockopt_rtoinfo_30941 sctp_setsockopt_rtoinfo 3 30941 NULL
125887 +tty_insert_flip_string_flags_30969 tty_insert_flip_string_flags 4 30969 NULL
125888 +huge_page_mask_30981 huge_page_mask 0 30981 NULL
125889 +read_file_bt_ant_diversity_30983 read_file_bt_ant_diversity 3 30983 NULL
125890 +lbs_host_sleep_read_31013 lbs_host_sleep_read 3 31013 NULL
125891 +ima_eventsig_init_31022 ima_eventsig_init 5 31022 NULL
125892 +template_fmt_size_31033 template_fmt_size 0 31033 NULL
125893 +stride_pg_count_31053 stride_pg_count 0-3-2-1-4-5 31053 NULL
125894 +lbs_failcount_read_31063 lbs_failcount_read 3 31063 NULL
125895 +sctp_setsockopt_context_31091 sctp_setsockopt_context 3 31091 NULL
125896 +proc_gid_map_write_31093 proc_gid_map_write 3 31093 NULL
125897 +depth_read_31112 depth_read 3 31112 NULL
125898 +hash_ipportnet6_expire_31118 hash_ipportnet6_expire 4 31118 NULL
125899 +size_inside_page_31141 size_inside_page 0 31141 NULL
125900 +w9966_v4l_read_31148 w9966_v4l_read 3 31148 NULL
125901 +ch_do_scsi_31171 ch_do_scsi 4 31171 NULL
125902 +r592_read_fifo_pio_31198 r592_read_fifo_pio 3 31198 NULL
125903 +mtdchar_readoob_31200 mtdchar_readoob 4 31200 NULL
125904 +cpumask_weight_31215 cpumask_weight 0 31215 NULL
125905 +__read_reg_31216 __read_reg 0 31216 NULL
125906 +atm_get_addr_31221 atm_get_addr 3 31221 NULL
125907 +tcp_recvmsg_31238 tcp_recvmsg 4 31238 NULL
125908 +cyy_readb_31240 cyy_readb 0 31240 NULL
125909 +_create_sg_bios_31244 _create_sg_bios 4 31244 NULL
125910 +ieee80211_if_read_last_beacon_31257 ieee80211_if_read_last_beacon 3 31257 NULL
125911 +hash_netportnet4_expire_31290 hash_netportnet4_expire 4 31290 NULL
125912 +uvc_simplify_fraction_31303 uvc_simplify_fraction 3 31303 NULL
125913 +sisusbcon_scroll_31315 sisusbcon_scroll 5-2-3 31315 NULL
125914 +command_file_write_31318 command_file_write 3 31318 NULL
125915 +_regmap_raw_multi_reg_write_31336 _regmap_raw_multi_reg_write 3 31336 NULL
125916 +em28xx_init_usb_xfer_31337 em28xx_init_usb_xfer 4-6 31337 NULL
125917 +outlen_write_31358 outlen_write 3 31358 NULL
125918 +ieee80211_rx_mgmt_auth_31366 ieee80211_rx_mgmt_auth 3 31366 NULL
125919 +xprt_rdma_allocate_31372 xprt_rdma_allocate 2 31372 NULL
125920 +vb2_vmalloc_get_userptr_31374 vb2_vmalloc_get_userptr 3-2 31374 NULL
125921 +trace_parser_get_init_31379 trace_parser_get_init 2 31379 NULL
125922 +inb_31388 inb 0 31388 NULL
125923 +key_ifindex_read_31411 key_ifindex_read 3 31411 NULL
125924 +_sp2d_max_pg_31422 _sp2d_max_pg 0 31422 NULL
125925 +TSS_checkhmac1_31429 TSS_checkhmac1 5 31429 NULL
125926 +snd_aw2_saa7146_get_hw_ptr_capture_31431 snd_aw2_saa7146_get_hw_ptr_capture 0 31431 NULL
125927 +transport_alloc_session_tags_31449 transport_alloc_session_tags 2-3 31449 NULL
125928 +opera1_xilinx_rw_31453 opera1_xilinx_rw 5 31453 NULL
125929 +xfs_btree_get_numrecs_31477 xfs_btree_get_numrecs 0 31477 NULL
125930 +alg_setkey_31485 alg_setkey 3 31485 NULL
125931 +rds_message_map_pages_31487 rds_message_map_pages 2 31487 NULL
125932 +qsfp_2_read_31491 qsfp_2_read 3 31491 NULL
125933 +__alloc_bootmem_31498 __alloc_bootmem 1 31498 NULL
125934 +hidraw_write_31536 hidraw_write 3 31536 NULL
125935 +usbvision_read_31555 usbvision_read 3 31555 NULL
125936 +tx_frag_tkip_called_read_31575 tx_frag_tkip_called_read 3 31575 NULL
125937 +get_max_inline_xattr_value_size_31578 get_max_inline_xattr_value_size 0 31578 NULL
125938 +osst_write_31581 osst_write 3 31581 NULL
125939 +snd_compr_get_avail_31584 snd_compr_get_avail 0 31584 NULL
125940 +iwl_dbgfs_ucode_tx_stats_read_31611 iwl_dbgfs_ucode_tx_stats_read 3 31611 NULL
125941 +memblock_virt_alloc_nopanic_31617 memblock_virt_alloc_nopanic 1 31617 NULL nohasharray
125942 +arvo_sysfs_read_31617 arvo_sysfs_read 6 31617 &memblock_virt_alloc_nopanic_31617
125943 +usnic_ib_dump_vf_31623 usnic_ib_dump_vf 3 31623 NULL
125944 +videobuf_read_one_31637 videobuf_read_one 3 31637 NULL
125945 +pod_alloc_sysex_buffer_31651 pod_alloc_sysex_buffer 3 31651 NULL
125946 +xfer_secondary_pool_31661 xfer_secondary_pool 2 31661 NULL
125947 +__lgread_31668 __lgread 4 31668 NULL
125948 +copy_from_user_nmi_31672 copy_from_user_nmi 3-0 31672 NULL
125949 +forced_ps_read_31685 forced_ps_read 3 31685 NULL
125950 +fst_recover_rx_error_31687 fst_recover_rx_error 3 31687 NULL
125951 +rs_pretty_print_rate_31727 rs_pretty_print_rate 0 31727 NULL
125952 +utf16s_to_utf8s_31735 utf16s_to_utf8s 0 31735 NULL nohasharray
125953 +lu_buf_check_and_grow_31735 lu_buf_check_and_grow 2 31735 &utf16s_to_utf8s_31735
125954 +shmem_pwrite_slow_31741 shmem_pwrite_slow 3-2 31741 NULL
125955 +input_abs_get_max_31742 input_abs_get_max 0 31742 NULL nohasharray
125956 +NCR_700_change_queue_depth_31742 NCR_700_change_queue_depth 2 31742 &input_abs_get_max_31742
125957 +bcm_char_read_31750 bcm_char_read 3 31750 NULL
125958 +snd_seq_device_new_31753 snd_seq_device_new 4 31753 NULL
125959 +SyS_lsetxattr_31766 SyS_lsetxattr 4 31766 NULL
125960 +usblp_cache_device_id_string_31790 usblp_cache_device_id_string 0 31790 NULL
125961 +get_count_order_31800 get_count_order 0 31800 NULL
125962 +ecryptfs_send_message_locked_31801 ecryptfs_send_message_locked 2 31801 NULL
125963 +isr_rx_procs_read_31804 isr_rx_procs_read 3 31804 NULL
125964 +data_write_31805 data_write 3 31805 NULL
125965 +SyS_msgsnd_31814 SyS_msgsnd 3 31814 NULL
125966 +strnlen_user_31815 strnlen_user 0-2 31815 NULL
125967 +sta_last_signal_read_31818 sta_last_signal_read 3 31818 NULL
125968 +clone_bio_31854 clone_bio 4-3 31854 NULL
125969 +SyS_ppoll_31855 SyS_ppoll 2 31855 NULL
125970 +iwl_dbgfs_disable_ht40_write_31876 iwl_dbgfs_disable_ht40_write 3 31876 NULL
125971 +drm_mode_crtc_set_gamma_size_31881 drm_mode_crtc_set_gamma_size 2 31881 NULL
125972 +ddb_output_write_31902 ddb_output_write 3-0 31902 NULL
125973 +xattr_permission_31907 xattr_permission 0 31907 NULL
125974 +lu_buf_realloc_31915 lu_buf_realloc 2 31915 NULL
125975 +new_dir_31919 new_dir 3 31919 NULL
125976 +kmem_alloc_31920 kmem_alloc 1 31920 NULL
125977 +era_status_31934 era_status 5 31934 NULL
125978 +SYSC_sethostname_31940 SYSC_sethostname 2 31940 NULL
125979 +read_mem_31942 read_mem 3 31942 NULL
125980 +ext4_zero_range_31944 ext4_zero_range 3-2 31944 NULL
125981 +vb2_write_31948 vb2_write 3 31948 NULL
125982 +pvr2_ctrl_get_valname_31951 pvr2_ctrl_get_valname 4 31951 NULL
125983 +regcache_rbtree_sync_31964 regcache_rbtree_sync 2 31964 NULL
125984 +iwl_rx_packet_payload_len_31965 iwl_rx_packet_payload_len 0 31965 NULL
125985 +copy_from_user_toio_31966 copy_from_user_toio 3 31966 NULL
125986 +iblock_execute_rw_31982 iblock_execute_rw 3 31982 NULL nohasharray
125987 +vx_read_status_31982 vx_read_status 0 31982 &iblock_execute_rw_31982
125988 +find_next_zero_bit_31990 find_next_zero_bit 0 31990 NULL
125989 +lustre_acl_xattr_merge2posix_31992 lustre_acl_xattr_merge2posix 2 31992 NULL
125990 +calc_hmac_32010 calc_hmac 3 32010 NULL
125991 +aead_len_32021 aead_len 0 32021 NULL
125992 +sci_dma_rx_push_32029 sci_dma_rx_push 2 32029 NULL
125993 +stk_read_32038 stk_read 3 32038 NULL
125994 +SYSC_llistxattr_32061 SYSC_llistxattr 3 32061 NULL
125995 +proc_scsi_devinfo_write_32064 proc_scsi_devinfo_write 3 32064 NULL
125996 +cow_file_range_inline_32091 cow_file_range_inline 3 32091 NULL
125997 +bio_alloc_32095 bio_alloc 2 32095 NULL
125998 +ath6kl_fwlog_read_32101 ath6kl_fwlog_read 3 32101 NULL
125999 +disk_status_32120 disk_status 4 32120 NULL
126000 +venus_link_32165 venus_link 5 32165 NULL
126001 +ocfs2_direct_IO_32168 ocfs2_direct_IO 4 32168 NULL
126002 +do_writepages_32173 do_writepages 0 32173 NULL
126003 +del_ptr_32197 del_ptr 4 32197 NULL
126004 +wusb_ccm_mac_32199 wusb_ccm_mac 7 32199 NULL
126005 +riva_get_cmap_len_32218 riva_get_cmap_len 0 32218 NULL
126006 +caif_seqpkt_recvmsg_32241 caif_seqpkt_recvmsg 4 32241 NULL
126007 +lbs_lowrssi_read_32242 lbs_lowrssi_read 3 32242 NULL
126008 +ocfs2_xattr_find_entry_32260 ocfs2_xattr_find_entry 0 32260 NULL
126009 +kvm_set_spte_hva_32312 kvm_set_spte_hva 2 32312 NULL
126010 +cas_calc_tabort_32316 cas_calc_tabort 0 32316 NULL
126011 +SyS_select_32319 SyS_select 1 32319 NULL
126012 +nouveau_bar_create__32332 nouveau_bar_create_ 4 32332 NULL
126013 +nl80211_send_mlme_event_32337 nl80211_send_mlme_event 4 32337 NULL
126014 +t4_alloc_mem_32342 t4_alloc_mem 1 32342 NULL
126015 +dispatch_ioctl_32357 dispatch_ioctl 2 32357 NULL nohasharray
126016 +rx_streaming_always_write_32357 rx_streaming_always_write 3 32357 &dispatch_ioctl_32357
126017 +sel_read_initcon_32362 sel_read_initcon 3 32362 NULL
126018 +ll_setxattr_common_32398 ll_setxattr_common 4 32398 NULL
126019 +xfs_iext_add_indirect_multi_32400 xfs_iext_add_indirect_multi 3 32400 NULL
126020 +vmci_qp_alloc_32405 vmci_qp_alloc 5-3 32405 NULL
126021 +cache_status_32462 cache_status 5 32462 NULL
126022 +fill_readbuf_32464 fill_readbuf 3 32464 NULL
126023 +ide_driver_proc_write_32493 ide_driver_proc_write 3 32493 NULL
126024 +bypass_pwoff_write_32499 bypass_pwoff_write 3 32499 NULL
126025 +mdc_pinger_recov_seq_write_32510 mdc_pinger_recov_seq_write 3 32510 NULL
126026 +ctrl_std_val_to_sym_32516 ctrl_std_val_to_sym 5 32516 NULL
126027 +disconnect_32521 disconnect 4 32521 NULL
126028 +qsfp_read_32522 qsfp_read 0-2-4 32522 NULL
126029 +ilo_read_32531 ilo_read 3 32531 NULL
126030 +ieee80211_if_read_estab_plinks_32533 ieee80211_if_read_estab_plinks 3 32533 NULL
126031 +format_devstat_counter_32550 format_devstat_counter 3 32550 NULL
126032 +aes_encrypt_fail_read_32562 aes_encrypt_fail_read 3 32562 NULL
126033 +osc_iocontrol_32565 osc_iocontrol 3 32565 NULL
126034 +mem_swapout_entry_32586 mem_swapout_entry 3 32586 NULL
126035 +pipeline_tcp_tx_stat_fifo_int_read_32589 pipeline_tcp_tx_stat_fifo_int_read 3 32589 NULL
126036 +read_file_beacon_32595 read_file_beacon 3 32595 NULL
126037 +ieee80211_if_read_dropped_frames_congestion_32603 ieee80211_if_read_dropped_frames_congestion 3 32603 NULL
126038 +irda_recvmsg_dgram_32631 irda_recvmsg_dgram 4 32631 NULL
126039 +cfg80211_roamed_32632 cfg80211_roamed 5-7 32632 NULL
126040 +xpcs_reg_value_read_32644 xpcs_reg_value_read 3 32644 NULL
126041 +kvmalloc_32646 kvmalloc 1 32646 NULL
126042 +ib_sg_dma_len_32649 ib_sg_dma_len 0 32649 NULL
126043 +generic_readlink_32654 generic_readlink 3 32654 NULL
126044 +move_addr_to_kernel_32673 move_addr_to_kernel 2 32673 NULL
126045 +compat_SyS_preadv_32679 compat_SyS_preadv 3 32679 NULL
126046 +jfs_readpages_32702 jfs_readpages 4 32702 NULL
126047 +rt2x00debug_read_queue_dump_32712 rt2x00debug_read_queue_dump 3 32712 NULL
126048 +_xfs_buf_get_pages_32715 _xfs_buf_get_pages 2 32715 NULL
126049 +megasas_change_queue_depth_32747 megasas_change_queue_depth 2 32747 NULL
126050 +stats_read_ul_32751 stats_read_ul 3 32751 NULL
126051 +vmci_transport_dgram_dequeue_32775 vmci_transport_dgram_dequeue 4 32775 NULL
126052 +sctp_tsnmap_grow_32784 sctp_tsnmap_grow 2 32784 NULL
126053 +rproc_name_read_32805 rproc_name_read 3 32805 NULL
126054 +sta_tx_latency_stat_read_32862 sta_tx_latency_stat_read 3 32862 NULL
126055 +new_tape_buffer_32866 new_tape_buffer 2 32866 NULL
126056 +cifs_writedata_alloc_32880 cifs_writedata_alloc 1 32880 NULL nohasharray
126057 +ath6kl_usb_submit_ctrl_in_32880 ath6kl_usb_submit_ctrl_in 6 32880 &cifs_writedata_alloc_32880
126058 +vp702x_usb_inout_cmd_32884 vp702x_usb_inout_cmd 4-6 32884 NULL
126059 +tipc_link_iovec_xmit_fast_32913 tipc_link_iovec_xmit_fast 3 32913 NULL nohasharray
126060 +il_dbgfs_tx_stats_read_32913 il_dbgfs_tx_stats_read 3 32913 &tipc_link_iovec_xmit_fast_32913
126061 +zlib_inflate_workspacesize_32927 zlib_inflate_workspacesize 0 32927 NULL
126062 +rmap_recycle_32938 rmap_recycle 3 32938 NULL
126063 +compat_filldir_32999 compat_filldir 3 32999 NULL
126064 +SyS_syslog_33007 SyS_syslog 3 33007 NULL
126065 +br_multicast_set_hash_max_33012 br_multicast_set_hash_max 2 33012 NULL
126066 +write_file_bt_ant_diversity_33019 write_file_bt_ant_diversity 3 33019 NULL
126067 +mic_virtio_copy_to_user_33048 mic_virtio_copy_to_user 3 33048 NULL
126068 +SYSC_lgetxattr_33049 SYSC_lgetxattr 4 33049 NULL
126069 +pipeline_dec_packet_in_fifo_full_read_33052 pipeline_dec_packet_in_fifo_full_read 3 33052 NULL
126070 +ebt_compat_match_offset_33053 ebt_compat_match_offset 0-2 33053 NULL
126071 +bitmap_resize_33054 bitmap_resize 2 33054 NULL
126072 +stats_dot11RTSSuccessCount_read_33065 stats_dot11RTSSuccessCount_read 3 33065 NULL
126073 +sel_read_checkreqprot_33068 sel_read_checkreqprot 3 33068 NULL
126074 +alloc_tio_33077 alloc_tio 3 33077 NULL
126075 +acl_permission_check_33083 acl_permission_check 0 33083 NULL
126076 +f2fs_llseek_33098 f2fs_llseek 2 33098 NULL
126077 +fb_sys_write_33130 fb_sys_write 3 33130 NULL
126078 +SyS_poll_33152 SyS_poll 2 33152 NULL
126079 +_pci_add_cap_save_buffer_33153 _pci_add_cap_save_buffer 4 33153 NULL
126080 +debug_debug6_read_33168 debug_debug6_read 3 33168 NULL
126081 +dataflash_read_fact_otp_33204 dataflash_read_fact_otp 3-2 33204 NULL
126082 +pp_read_33210 pp_read 3 33210 NULL
126083 +snd_pcm_plug_client_size_33267 snd_pcm_plug_client_size 0-2 33267 NULL
126084 +cachefiles_cook_key_33274 cachefiles_cook_key 2 33274 NULL
126085 +sync_pt_create_33282 sync_pt_create 2 33282 NULL
126086 +mcs7830_get_reg_33308 mcs7830_get_reg 3 33308 NULL
126087 +isku_sysfs_read_keys_easyzone_33318 isku_sysfs_read_keys_easyzone 6 33318 NULL
126088 +vx_send_irq_dsp_33329 vx_send_irq_dsp 0 33329 NULL
126089 +joydev_ioctl_33343 joydev_ioctl 2 33343 NULL
126090 +lov_stripesize_seq_write_33353 lov_stripesize_seq_write 3 33353 NULL
126091 +create_xattr_datum_33356 create_xattr_datum 5 33356 NULL nohasharray
126092 +irq_pkt_threshold_read_33356 irq_pkt_threshold_read 3 33356 &create_xattr_datum_33356
126093 +read_file_regidx_33370 read_file_regidx 3 33370 NULL
126094 +ieee80211_if_read_dropped_frames_no_route_33383 ieee80211_if_read_dropped_frames_no_route 3 33383 NULL
126095 +scsi_varlen_cdb_length_33385 scsi_varlen_cdb_length 0 33385 NULL
126096 +nvc0_ram_create__33391 nvc0_ram_create_ 5 33391 NULL
126097 +ocfs2_allocate_unwritten_extents_33394 ocfs2_allocate_unwritten_extents 2-3 33394 NULL
126098 +cfs_trace_copyin_string_33396 cfs_trace_copyin_string 4 33396 NULL
126099 +snd_pcm_capture_ioctl1_33408 snd_pcm_capture_ioctl1 0 33408 NULL
126100 +hash_netiface6_expire_33421 hash_netiface6_expire 4 33421 NULL
126101 +dis_tap_write_33426 dis_tap_write 3 33426 NULL
126102 +message_stats_list_33440 message_stats_list 5 33440 NULL
126103 +ovs_vport_alloc_33475 ovs_vport_alloc 1 33475 NULL
126104 +create_entry_33479 create_entry 2 33479 NULL
126105 +ip_setsockopt_33487 ip_setsockopt 5 33487 NULL
126106 +res_counter_read_33499 res_counter_read 4 33499 NULL
126107 +hash_netnet4_expire_33500 hash_netnet4_expire 4 33500 NULL
126108 +fb_read_33506 fb_read 3 33506 NULL
126109 +musb_test_mode_write_33518 musb_test_mode_write 3 33518 NULL
126110 +ahash_setkey_unaligned_33521 ahash_setkey_unaligned 3 33521 NULL
126111 +nes_alloc_fast_reg_page_list_33523 nes_alloc_fast_reg_page_list 2 33523 NULL
126112 +aggr_size_rx_size_read_33526 aggr_size_rx_size_read 3 33526 NULL
126113 +tomoyo_read_self_33539 tomoyo_read_self 3 33539 NULL nohasharray
126114 +osc_max_rpcs_in_flight_seq_write_33539 osc_max_rpcs_in_flight_seq_write 3 33539 &tomoyo_read_self_33539
126115 +count_subheaders_33591 count_subheaders 0 33591 NULL
126116 +scsi_execute_33596 scsi_execute 5 33596 NULL
126117 +comedi_buf_write_n_allocated_33604 comedi_buf_write_n_allocated 0 33604 NULL
126118 +xt_compat_target_offset_33608 xt_compat_target_offset 0 33608 NULL
126119 +il_dbgfs_qos_read_33615 il_dbgfs_qos_read 3 33615 NULL nohasharray
126120 +usb_gstrings_attach_33615 usb_gstrings_attach 3 33615 &il_dbgfs_qos_read_33615
126121 +stride_page_count_33641 stride_page_count 2 33641 NULL
126122 +irq_blk_threshold_read_33666 irq_blk_threshold_read 3 33666 NULL
126123 +inw_p_33668 inw_p 0 33668 NULL
126124 +arp_hdr_len_33671 arp_hdr_len 0 33671 NULL
126125 +i2c_hid_alloc_buffers_33673 i2c_hid_alloc_buffers 2 33673 NULL
126126 +nv50_disp_dmac_create__33696 nv50_disp_dmac_create_ 6 33696 NULL
126127 +netlink_sendmsg_33708 netlink_sendmsg 4 33708 NULL
126128 +tipc_link_stats_33716 tipc_link_stats 3 33716 NULL
126129 +pvr2_stream_buffer_count_33719 pvr2_stream_buffer_count 2 33719 NULL
126130 +write_file_spectral_count_33723 write_file_spectral_count 3 33723 NULL
126131 +read_file_node_recv_33729 read_file_node_recv 3 33729 NULL
126132 +vifs_state_read_33762 vifs_state_read 3 33762 NULL
126133 +hashtab_create_33769 hashtab_create 3 33769 NULL
126134 +__btrfs_free_reserved_extent_33782 __btrfs_free_reserved_extent 2 33782 NULL
126135 +if_sdio_read_rx_len_33800 if_sdio_read_rx_len 0 33800 NULL
126136 +filter_write_33819 filter_write 3 33819 NULL
126137 +sep_create_msgarea_context_33829 sep_create_msgarea_context 4 33829 NULL
126138 +scrub_setup_recheck_block_33831 scrub_setup_recheck_block 5-4 33831 NULL
126139 +ext4_journal_extend_33835 ext4_journal_extend 2 33835 NULL
126140 +oz_cdev_write_33852 oz_cdev_write 3 33852 NULL
126141 +get_user_pages_33908 get_user_pages 0 33908 NULL
126142 +sg_nents_33909 sg_nents 0 33909 NULL
126143 +ath6kl_roam_mode_write_33912 ath6kl_roam_mode_write 3 33912 NULL
126144 +queue_logical_block_size_33918 queue_logical_block_size 0 33918 NULL
126145 +sel_read_avc_cache_threshold_33942 sel_read_avc_cache_threshold 3 33942 NULL
126146 +lpfc_idiag_ctlacc_read_33943 lpfc_idiag_ctlacc_read 3 33943 NULL
126147 +read_file_tgt_rx_stats_33944 read_file_tgt_rx_stats 3 33944 NULL
126148 +rs_sta_dbgfs_drv_tx_stats_read_33946 rs_sta_dbgfs_drv_tx_stats_read 3 33946 NULL
126149 +__proc_dump_kernel_33954 __proc_dump_kernel 5 33954 NULL
126150 +vga_switcheroo_debugfs_write_33984 vga_switcheroo_debugfs_write 3 33984 NULL
126151 +lbs_lowrssi_write_34025 lbs_lowrssi_write 3 34025 NULL
126152 +ppp_write_34034 ppp_write 3 34034 NULL
126153 +tty_insert_flip_string_34042 tty_insert_flip_string 3-0 34042 NULL
126154 +calc_linear_pos_34067 calc_linear_pos 0-4 34067 NULL
126155 +memcg_update_all_caches_34068 memcg_update_all_caches 1 34068 NULL
126156 +pipeline_pipeline_fifo_full_read_34095 pipeline_pipeline_fifo_full_read 3 34095 NULL
126157 +__irq_domain_add_34101 __irq_domain_add 2 34101 NULL
126158 +proc_scsi_host_write_34107 proc_scsi_host_write 3 34107 NULL
126159 +islpci_mgt_transmit_34133 islpci_mgt_transmit 5 34133 NULL
126160 +ttm_dma_page_pool_free_34135 ttm_dma_page_pool_free 2-0 34135 NULL
126161 +ixgbe_dbg_netdev_ops_write_34141 ixgbe_dbg_netdev_ops_write 3 34141 NULL
126162 +shmem_pread_fast_34147 shmem_pread_fast 3 34147 NULL
126163 +skb_to_sgvec_34171 skb_to_sgvec 0 34171 NULL
126164 +rsi_debug_zone_write_34206 rsi_debug_zone_write 3 34206 NULL
126165 +ext4_da_write_begin_34215 ext4_da_write_begin 3-4 34215 NULL
126166 +bl_pipe_downcall_34264 bl_pipe_downcall 3 34264 NULL
126167 +xgmac_reg_addr_write_34284 xgmac_reg_addr_write 3 34284 NULL
126168 +ext4_get_groups_count_34324 ext4_get_groups_count 0 34324 NULL
126169 +pcpu_need_to_extend_34326 pcpu_need_to_extend 0 34326 NULL nohasharray
126170 +iov_iter_single_seg_count_34326 iov_iter_single_seg_count 0 34326 &pcpu_need_to_extend_34326
126171 +crypto_ablkcipher_ivsize_34363 crypto_ablkcipher_ivsize 0 34363 NULL nohasharray
126172 +sync_page_io_34363 sync_page_io 3 34363 &crypto_ablkcipher_ivsize_34363
126173 +rngapi_reset_34366 rngapi_reset 3 34366 NULL
126174 +_iwl_dbgfs_low_latency_write_34378 _iwl_dbgfs_low_latency_write 3 34378 NULL nohasharray
126175 +ea_read_34378 ea_read 0 34378 &_iwl_dbgfs_low_latency_write_34378
126176 +fuse_send_read_34379 fuse_send_read 4-0 34379 NULL
126177 +av7110_vbi_write_34384 av7110_vbi_write 3 34384 NULL
126178 +usbvision_v4l2_read_34386 usbvision_v4l2_read 3 34386 NULL
126179 +read_rbu_image_type_34387 read_rbu_image_type 6 34387 NULL
126180 +ivtv_read_pos_34400 ivtv_read_pos 3 34400 NULL nohasharray
126181 +iwl_calib_set_34400 iwl_calib_set 3 34400 &ivtv_read_pos_34400
126182 +wd_exp_mode_write_34407 wd_exp_mode_write 3 34407 NULL
126183 +nl80211_send_disassoc_34424 nl80211_send_disassoc 4 34424 NULL
126184 +security_socket_create_34439 security_socket_create 0 34439 NULL
126185 +usbtest_alloc_urb_34446 usbtest_alloc_urb 3-5 34446 NULL
126186 +mwifiex_regrdwr_read_34472 mwifiex_regrdwr_read 3 34472 NULL
126187 +skcipher_sndbuf_34476 skcipher_sndbuf 0 34476 NULL
126188 +i2o_parm_field_get_34477 i2o_parm_field_get 5 34477 NULL
126189 +security_inode_permission_34488 security_inode_permission 0 34488 NULL
126190 +SyS_pwritev_34494 SyS_pwritev 3 34494 NULL
126191 +qp_alloc_res_34496 qp_alloc_res 5 34496 NULL
126192 +lu_buf_check_and_alloc_34505 lu_buf_check_and_alloc 2 34505 NULL
126193 +tracing_stats_read_34537 tracing_stats_read 3 34537 NULL nohasharray
126194 +ext4_fallocate_34537 ext4_fallocate 4-3 34537 &tracing_stats_read_34537
126195 +hugetlbfs_read_actor_34547 hugetlbfs_read_actor 2-5-4-0 34547 NULL
126196 +dbBackSplit_34561 dbBackSplit 0 34561 NULL
126197 +alloc_ieee80211_rsl_34564 alloc_ieee80211_rsl 1 34564 NULL nohasharray
126198 +self_check_peb_ec_hdr_34564 self_check_peb_ec_hdr 0 34564 &alloc_ieee80211_rsl_34564
126199 +ext4_ind_direct_IO_34574 ext4_ind_direct_IO 4 34574 NULL
126200 +lov_stripecount_seq_write_34582 lov_stripecount_seq_write 3 34582 NULL
126201 +init_send_hfcd_34586 init_send_hfcd 1 34586 NULL
126202 +inet6_ifla6_size_34591 inet6_ifla6_size 0 34591 NULL
126203 +ceph_msgpool_init_34599 ceph_msgpool_init 4 34599 NULL nohasharray
126204 +cw1200_queue_init_34599 cw1200_queue_init 4 34599 &ceph_msgpool_init_34599
126205 +bio_integrity_bytes_34602 bio_integrity_bytes 2 34602 NULL
126206 +__jffs2_ref_totlen_34609 __jffs2_ref_totlen 0 34609 NULL nohasharray
126207 +mtd_write_34609 mtd_write 0 34609 &__jffs2_ref_totlen_34609
126208 +__cfg80211_disconnected_34622 __cfg80211_disconnected 3 34622 NULL
126209 +cnic_alloc_dma_34641 cnic_alloc_dma 3 34641 NULL
126210 +kvm_set_spte_hva_34671 kvm_set_spte_hva 2 34671 NULL
126211 +sleep_auth_write_34676 sleep_auth_write 3 34676 NULL
126212 +f2fs_direct_IO_34685 f2fs_direct_IO 4 34685 NULL
126213 +isr_fiqs_read_34687 isr_fiqs_read 3 34687 NULL
126214 +batadv_tvlv_realloc_packet_buff_34688 batadv_tvlv_realloc_packet_buff 3-4 34688 NULL
126215 +port_print_34704 port_print 3 34704 NULL
126216 +ieee80211_if_read_num_sta_ps_34722 ieee80211_if_read_num_sta_ps 3 34722 NULL
126217 +platform_list_read_file_34734 platform_list_read_file 3 34734 NULL
126218 +reg_w_ixbuf_34736 reg_w_ixbuf 4 34736 NULL
126219 +lsm_alloc_plain_34755 lsm_alloc_plain 1 34755 NULL
126220 +bootmode_store_34762 bootmode_store 4 34762 NULL
126221 +qib_cdev_init_34778 qib_cdev_init 1 34778 NULL
126222 +ext3_direct_IO_34798 ext3_direct_IO 4 34798 NULL
126223 +SYSC_keyctl_34800 SYSC_keyctl 4 34800 NULL
126224 +can_nocow_extent_34801 can_nocow_extent 2 34801 NULL
126225 +drbd_get_max_capacity_34804 drbd_get_max_capacity 0 34804 NULL
126226 +ll_setxattr_34806 ll_setxattr 4 34806 NULL
126227 +file_page_index_34820 file_page_index 0-2 34820 NULL
126228 +bio_segments_34832 bio_segments 0 34832 NULL
126229 +b43_debugfs_write_34838 b43_debugfs_write 3 34838 NULL
126230 +nl_portid_hash_zalloc_34843 nl_portid_hash_zalloc 1 34843 NULL
126231 +acpi_system_write_wakeup_device_34853 acpi_system_write_wakeup_device 3 34853 NULL
126232 +usb_serial_generic_prepare_write_buffer_34857 usb_serial_generic_prepare_write_buffer 3 34857 NULL
126233 +ieee80211_if_read_txpower_34871 ieee80211_if_read_txpower 3 34871 NULL
126234 +msg_print_text_34889 msg_print_text 0 34889 NULL
126235 +ieee80211_if_write_34894 ieee80211_if_write 3 34894 NULL
126236 +si476x_radio_read_rsq_primary_blob_34916 si476x_radio_read_rsq_primary_blob 3 34916 NULL
126237 +__inode_permission_34925 __inode_permission 0 34925 NULL nohasharray
126238 +btrfs_super_chunk_root_34925 btrfs_super_chunk_root 0 34925 &__inode_permission_34925
126239 +snd_info_entry_read_34938 snd_info_entry_read 3 34938 NULL
126240 +do_add_page_to_bio_34974 do_add_page_to_bio 10-2 34974 NULL
126241 +schedule_erase_34996 schedule_erase 0 34996 NULL
126242 +rx_rx_hdr_overflow_read_35002 rx_rx_hdr_overflow_read 3 35002 NULL
126243 +l2cap_skbuff_fromiovec_35003 l2cap_skbuff_fromiovec 4-3 35003 NULL
126244 +sisusb_copy_memory_35016 sisusb_copy_memory 4 35016 NULL
126245 +coda_psdev_read_35029 coda_psdev_read 3 35029 NULL
126246 +hwdep_read_locked_35037 hwdep_read_locked 3 35037 NULL
126247 +pwr_connection_out_of_sync_read_35061 pwr_connection_out_of_sync_read 3 35061 NULL
126248 +__kfifo_uint_must_check_helper_35097 __kfifo_uint_must_check_helper 0-1 35097 NULL
126249 +capi_write_35104 capi_write 3 35104 NULL nohasharray
126250 +tx_tx_done_template_read_35104 tx_tx_done_template_read 3 35104 &capi_write_35104
126251 +ide_settings_proc_write_35110 ide_settings_proc_write 3 35110 NULL
126252 +addrs_per_inode_35151 addrs_per_inode 0 35151 NULL
126253 +message_stats_print_35158 message_stats_print 6 35158 NULL
126254 +iscsi_conn_setup_35159 iscsi_conn_setup 2 35159 NULL
126255 +ieee80211_if_read_bssid_35161 ieee80211_if_read_bssid 3 35161 NULL
126256 +compat_SyS_pselect6_35203 compat_SyS_pselect6 1 35203 NULL
126257 +unix_stream_recvmsg_35210 unix_stream_recvmsg 4 35210 NULL
126258 +security_key_getsecurity_35218 security_key_getsecurity 0 35218 NULL nohasharray
126259 +striped_read_35218 striped_read 0-2 35218 &security_key_getsecurity_35218
126260 +rx_rx_cmplt_task_read_35226 rx_rx_cmplt_task_read 3 35226 NULL
126261 +set_fd_set_35249 set_fd_set 1 35249 NULL
126262 +ioapic_setup_resources_35255 ioapic_setup_resources 1 35255 NULL
126263 +dis_disc_write_35265 dis_disc_write 3 35265 NULL
126264 +dma_show_regs_35266 dma_show_regs 3 35266 NULL
126265 +irda_recvmsg_stream_35280 irda_recvmsg_stream 4 35280 NULL
126266 +i2o_block_end_request_35282 i2o_block_end_request 3 35282 NULL
126267 +isr_rx_rdys_read_35283 isr_rx_rdys_read 3 35283 NULL
126268 +__btrfs_buffered_write_35311 __btrfs_buffered_write 3 35311 NULL nohasharray
126269 +brcmf_sdio_forensic_read_35311 brcmf_sdio_forensic_read 3 35311 &__btrfs_buffered_write_35311
126270 +tracing_read_pipe_35312 tracing_read_pipe 3 35312 NULL
126271 +sta_tx_latency_stat_write_35323 sta_tx_latency_stat_write 3 35323 NULL
126272 +ieee80211_if_fmt_ap_power_level_35347 ieee80211_if_fmt_ap_power_level 3 35347 NULL
126273 +nouveau_devinit_create__35348 nouveau_devinit_create_ 4 35348 NULL
126274 +ieee80211_rx_mgmt_deauth_35351 ieee80211_rx_mgmt_deauth 3 35351 NULL
126275 +compat_filldir64_35354 compat_filldir64 3 35354 NULL
126276 +SyS_getxattr_35408 SyS_getxattr 4 35408 NULL
126277 +rawv6_send_hdrinc_35425 rawv6_send_hdrinc 3 35425 NULL
126278 +iwl_dbgfs_drv_rx_stats_read_35430 iwl_dbgfs_drv_rx_stats_read 3 35430 NULL
126279 +buffer_to_user_35439 buffer_to_user 3 35439 NULL
126280 +efx_mcdi_rpc_async_quiet_35460 efx_mcdi_rpc_async_quiet 4-5 35460 NULL
126281 +macvtap_do_read_35475 macvtap_do_read 3 35475 NULL
126282 +fiemap_prepare_and_copy_exts_35494 fiemap_prepare_and_copy_exts 5 35494 NULL
126283 +btrfs_prealloc_file_range_trans_35500 btrfs_prealloc_file_range_trans 4 35500 NULL
126284 +async_setkey_35521 async_setkey 3 35521 NULL
126285 +__filemap_fdatawrite_range_35528 __filemap_fdatawrite_range 0 35528 NULL
126286 +iwl_dbgfs_bt_traffic_read_35534 iwl_dbgfs_bt_traffic_read 3 35534 NULL
126287 +pstore_mkfile_35536 pstore_mkfile 7 35536 NULL
126288 +rxpipe_tx_xfr_host_int_trig_rx_data_read_35538 rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 NULL
126289 +ocfs2_write_zero_page_35539 ocfs2_write_zero_page 3 35539 NULL
126290 +ibnl_put_attr_35541 ibnl_put_attr 3 35541 NULL
126291 +ieee80211_if_write_smps_35550 ieee80211_if_write_smps 3 35550 NULL
126292 +ext4_blocks_for_truncate_35579 ext4_blocks_for_truncate 0 35579 NULL
126293 +ext2_acl_from_disk_35580 ext2_acl_from_disk 2 35580 NULL
126294 +spk_msg_set_35586 spk_msg_set 3 35586 NULL
126295 +kernel_readv_35617 kernel_readv 3 35617 NULL
126296 +reiserfs_readpages_35629 reiserfs_readpages 4 35629 NULL
126297 +ptlrpcd_steal_rqset_35637 ptlrpcd_steal_rqset 0 35637 NULL
126298 +spi_register_board_info_35651 spi_register_board_info 2 35651 NULL
126299 +rdmaltWithLock_35669 rdmaltWithLock 0 35669 NULL
126300 +SYSC_pwritev_35690 SYSC_pwritev 3 35690 NULL
126301 +rds_page_copy_user_35691 rds_page_copy_user 4 35691 NULL
126302 +md_super_write_35703 md_super_write 4 35703 NULL
126303 +iwl_dbgfs_disable_ht40_read_35761 iwl_dbgfs_disable_ht40_read 3 35761 NULL
126304 +udf_alloc_i_data_35786 udf_alloc_i_data 2 35786 NULL
126305 +pvr2_hdw_cpufw_get_35824 pvr2_hdw_cpufw_get 0-4-2 35824 NULL
126306 +tx_tx_cmplt_read_35854 tx_tx_cmplt_read 3 35854 NULL
126307 +vx_query_hbuffer_size_35859 vx_query_hbuffer_size 0 35859 NULL
126308 +mthca_buf_alloc_35861 mthca_buf_alloc 2 35861 NULL
126309 +kvm_dirty_bitmap_bytes_35886 kvm_dirty_bitmap_bytes 0 35886 NULL
126310 +ieee80211_if_fmt_dot11MeshRetryTimeout_35890 ieee80211_if_fmt_dot11MeshRetryTimeout 3 35890 NULL
126311 +uwb_rc_cmd_done_35892 uwb_rc_cmd_done 4 35892 NULL
126312 +kernel_setsockopt_35913 kernel_setsockopt 5 35913 NULL
126313 +rbio_nr_pages_35916 rbio_nr_pages 0-1-2 35916 NULL
126314 +sctp_tsnmap_mark_35929 sctp_tsnmap_mark 2 35929 NULL
126315 +rx_defrag_init_called_read_35935 rx_defrag_init_called_read 3 35935 NULL
126316 +put_cmsg_compat_35937 put_cmsg_compat 4 35937 NULL
126317 +generic_ocp_read_35974 generic_ocp_read 3 35974 NULL nohasharray
126318 +ceph_buffer_new_35974 ceph_buffer_new 1 35974 &generic_ocp_read_35974
126319 +acl_alloc_35979 acl_alloc 1 35979 NULL
126320 +write_file_antenna_35998 write_file_antenna 3 35998 NULL nohasharray
126321 +kuc_alloc_35998 kuc_alloc 1 35998 &write_file_antenna_35998
126322 +lov_mds_md_max_stripe_count_36008 lov_mds_md_max_stripe_count 0-1 36008 NULL
126323 +il3945_ucode_tx_stats_read_36016 il3945_ucode_tx_stats_read 3 36016 NULL
126324 +ubi_eba_write_leb_36029 ubi_eba_write_leb 0 36029 NULL
126325 +__videobuf_alloc_36031 __videobuf_alloc 1 36031 NULL
126326 +account_shadowed_36048 account_shadowed 2 36048 NULL
126327 +gpio_power_read_36059 gpio_power_read 3 36059 NULL
126328 +write_emulate_36065 write_emulate 2-4 36065 NULL
126329 +stack_max_size_write_36068 stack_max_size_write 3 36068 NULL
126330 +radeon_vm_num_pdes_36070 radeon_vm_num_pdes 0 36070 NULL
126331 +ieee80211_if_fmt_peer_36071 ieee80211_if_fmt_peer 3 36071 NULL
126332 +ieee80211_if_write_tsf_36077 ieee80211_if_write_tsf 3 36077 NULL
126333 +snd_pcm_plug_read_transfer_36080 snd_pcm_plug_read_transfer 0-3 36080 NULL
126334 +mtip_hw_read_device_status_36082 mtip_hw_read_device_status 3 36082 NULL
126335 +vga_arb_write_36112 vga_arb_write 3 36112 NULL
126336 +simple_xattr_alloc_36118 simple_xattr_alloc 2 36118 NULL
126337 +ext3_readpages_36144 ext3_readpages 4 36144 NULL
126338 +twl_set_36154 twl_set 2 36154 NULL
126339 +b1_alloc_card_36155 b1_alloc_card 1 36155 NULL
126340 +snd_korg1212_copy_from_36169 snd_korg1212_copy_from 6 36169 NULL
126341 +ramoops_init_przs_36199 ramoops_init_przs 4 36199 NULL
126342 +SYSC_sched_getaffinity_36208 SYSC_sched_getaffinity 2 36208 NULL
126343 +SYSC_process_vm_readv_36216 SYSC_process_vm_readv 3-5 36216 NULL
126344 +atomic_stats_read_36228 atomic_stats_read 3 36228 NULL
126345 +viafb_iga1_odev_proc_write_36241 viafb_iga1_odev_proc_write 3 36241 NULL
126346 +SYSC_getxattr_36242 SYSC_getxattr 4 36242 NULL
126347 +vmsplice_to_user_36245 vmsplice_to_user 3 36245 NULL nohasharray
126348 +rproc_recovery_read_36245 rproc_recovery_read 3 36245 &vmsplice_to_user_36245
126349 +cfs_hash_buckets_realloc_36276 cfs_hash_buckets_realloc 4 36276 NULL
126350 +codec_reg_read_file_36280 codec_reg_read_file 3 36280 NULL
126351 +crypto_shash_digestsize_36284 crypto_shash_digestsize 0 36284 NULL
126352 +lpfc_debugfs_dif_err_read_36303 lpfc_debugfs_dif_err_read 3 36303 NULL
126353 +cfg80211_rx_mlme_mgmt_36306 cfg80211_rx_mlme_mgmt 3 36306 NULL
126354 +ad7879_spi_xfer_36311 ad7879_spi_xfer 3 36311 NULL
126355 +__compat_sys_pwritev64_36328 __compat_sys_pwritev64 3 36328 NULL nohasharray
126356 +fat_compat_ioctl_filldir_36328 fat_compat_ioctl_filldir 3 36328 &__compat_sys_pwritev64_36328
126357 +lc_create_36332 lc_create 4 36332 NULL
126358 +jbd2_journal_init_revoke_table_36336 jbd2_journal_init_revoke_table 1 36336 NULL
126359 +isku_sysfs_read_key_mask_36343 isku_sysfs_read_key_mask 6 36343 NULL
126360 +ath6kl_regwrite_write_36351 ath6kl_regwrite_write 3 36351 NULL
126361 +v9fs_file_readn_36353 v9fs_file_readn 4 36353 NULL
126362 +to_sector_36361 to_sector 0-1 36361 NULL
126363 +tunables_read_36385 tunables_read 3 36385 NULL
126364 +afs_alloc_flat_call_36399 afs_alloc_flat_call 2-3 36399 NULL
126365 +sierra_write_36402 sierra_write 4 36402 NULL
126366 +SyS_sethostname_36417 SyS_sethostname 2 36417 NULL
126367 +sctp_tsnmap_init_36446 sctp_tsnmap_init 2 36446 NULL
126368 +alloc_etherdev_mqs_36450 alloc_etherdev_mqs 1 36450 NULL
126369 +SyS_process_vm_writev_36476 SyS_process_vm_writev 3-5 36476 NULL
126370 +b43_nphy_load_samples_36481 b43_nphy_load_samples 3 36481 NULL
126371 +tx_tx_checksum_result_read_36490 tx_tx_checksum_result_read 3 36490 NULL
126372 +__hwahc_op_set_ptk_36510 __hwahc_op_set_ptk 5 36510 NULL
126373 +mcam_v4l_read_36513 mcam_v4l_read 3 36513 NULL
126374 +_iwl_dbgfs_fw_nmi_write_36515 _iwl_dbgfs_fw_nmi_write 3 36515 NULL
126375 +get_param_l_36518 get_param_l 0 36518 NULL
126376 +ieee80211_if_read_fwded_frames_36520 ieee80211_if_read_fwded_frames 3 36520 NULL
126377 +crypto_aead_authsize_36537 crypto_aead_authsize 0 36537 NULL
126378 +cpu_type_read_36540 cpu_type_read 3 36540 NULL
126379 +__kfifo_to_user_36555 __kfifo_to_user 3-0 36555 NULL
126380 +btrfs_get_token_64_36572 btrfs_get_token_64 0 36572 NULL
126381 +__erst_read_36579 __erst_read 0 36579 NULL
126382 +put_cmsg_36589 put_cmsg 4 36589 NULL
126383 +fat_ioctl_filldir_36621 fat_ioctl_filldir 3 36621 NULL
126384 +vxge_config_vpaths_36636 vxge_config_vpaths 0 36636 NULL
126385 +convert_extent_item_v0_36645 convert_extent_item_v0 4 36645 NULL
126386 +ced_ioctl_36647 ced_ioctl 2 36647 NULL
126387 +lpfc_idiag_extacc_alloc_get_36648 lpfc_idiag_extacc_alloc_get 0-3 36648 NULL
126388 +osd_req_list_collection_objects_36664 osd_req_list_collection_objects 5 36664 NULL
126389 +iscsi_host_alloc_36671 iscsi_host_alloc 2 36671 NULL
126390 +xillybus_read_36678 xillybus_read 3 36678 NULL
126391 +gsmtty_write_36702 gsmtty_write 3 36702 NULL
126392 +snd_rawmidi_kernel_read1_36740 snd_rawmidi_kernel_read1 4-0 36740 NULL
126393 +cxgbi_device_register_36746 cxgbi_device_register 1-2 36746 NULL
126394 +ps_poll_upsd_timeouts_read_36755 ps_poll_upsd_timeouts_read 3 36755 NULL
126395 +ptp_filter_init_36780 ptp_filter_init 2 36780 NULL
126396 +i40e_init_lan_hmc_36796 i40e_init_lan_hmc 5-4-3-2 36796 NULL
126397 +proc_fault_inject_read_36802 proc_fault_inject_read 3 36802 NULL
126398 +hiddev_ioctl_36816 hiddev_ioctl 2 36816 NULL
126399 +int_hardware_entry_36833 int_hardware_entry 3 36833 NULL
126400 +fc_change_queue_depth_36841 fc_change_queue_depth 2 36841 NULL
126401 +keyctl_describe_key_36853 keyctl_describe_key 3 36853 NULL
126402 +tipc_link_iovec_long_xmit_36871 tipc_link_iovec_long_xmit 3 36871 NULL nohasharray
126403 +tx_tx_data_programmed_read_36871 tx_tx_data_programmed_read 3 36871 &tipc_link_iovec_long_xmit_36871
126404 +svc_setsockopt_36876 svc_setsockopt 5 36876 NULL
126405 +raid56_parity_write_36877 raid56_parity_write 5 36877 NULL
126406 +__btrfs_map_block_36883 __btrfs_map_block 3 36883 NULL
126407 +ib_ucm_alloc_data_36885 ib_ucm_alloc_data 3 36885 NULL
126408 +selinux_inode_notifysecctx_36896 selinux_inode_notifysecctx 3 36896 NULL
126409 +il4965_rs_sta_dbgfs_scale_table_write_36979 il4965_rs_sta_dbgfs_scale_table_write 3 36979 NULL
126410 +drbd_new_dev_size_36998 drbd_new_dev_size 0-3 36998 NULL
126411 +auok190xfb_write_37001 auok190xfb_write 3 37001 NULL
126412 +setxattr_37006 setxattr 4 37006 NULL
126413 +ec_i2c_xfer_37029 ec_i2c_xfer 3 37029 NULL
126414 +command_file_read_37038 command_file_read 3 37038 NULL
126415 +figure_loop_size_37051 figure_loop_size 2-3 37051 NULL
126416 +qp_broker_create_37053 qp_broker_create 6-5 37053 NULL nohasharray
126417 +ieee80211_if_read_drop_unencrypted_37053 ieee80211_if_read_drop_unencrypted 3 37053 &qp_broker_create_37053
126418 +_iwl_dbgfs_bcast_filters_macs_write_37069 _iwl_dbgfs_bcast_filters_macs_write 3 37069 NULL
126419 +SYSC_setxattr_37078 SYSC_setxattr 4 37078 NULL
126420 +parse_command_37079 parse_command 2 37079 NULL
126421 +pipeline_cs_rx_packet_in_read_37089 pipeline_cs_rx_packet_in_read 3 37089 NULL
126422 +tun_get_user_37094 tun_get_user 5 37094 NULL
126423 +has_wrprotected_page_37123 has_wrprotected_page 3-2 37123 NULL
126424 +snd_hda_get_conn_list_37132 snd_hda_get_conn_list 0 37132 NULL
126425 +mtt_free_res_37144 mtt_free_res 5 37144 NULL
126426 +msg_word_37164 msg_word 0 37164 NULL
126427 +vcc_recvmsg_37198 vcc_recvmsg 4 37198 NULL
126428 +forced_ps_write_37209 forced_ps_write 3 37209 NULL
126429 +crypto_shash_descsize_37212 crypto_shash_descsize 0 37212 NULL
126430 +regmap_access_read_file_37223 regmap_access_read_file 3 37223 NULL
126431 +__do_replace_37227 __do_replace 5 37227 NULL
126432 +iwl_dbgfs_d3_sram_read_37237 iwl_dbgfs_d3_sram_read 3 37237 NULL
126433 +__btrfs_inc_extent_ref_37238 __btrfs_inc_extent_ref 7 37238 NULL nohasharray
126434 +rx_filter_dup_filter_read_37238 rx_filter_dup_filter_read 3 37238 &__btrfs_inc_extent_ref_37238
126435 +prot_queue_del_37258 prot_queue_del 0 37258 NULL
126436 +exofs_max_io_pages_37263 exofs_max_io_pages 0-2 37263 NULL
126437 +_iwl_dbgfs_fw_restart_write_37270 _iwl_dbgfs_fw_restart_write 3 37270 NULL
126438 +ieee80211_if_read_power_mode_37305 ieee80211_if_read_power_mode 3 37305 NULL
126439 +jffs2_write_dirent_37311 jffs2_write_dirent 5 37311 NULL
126440 +tipc_send_37315 tipc_send 3 37315 NULL
126441 +l2cap_create_connless_pdu_37327 l2cap_create_connless_pdu 3 37327 NULL
126442 +scsi_mode_select_37330 scsi_mode_select 6 37330 NULL
126443 +rxrpc_server_sendmsg_37331 rxrpc_server_sendmsg 4 37331 NULL
126444 +security_inode_getsecurity_37354 security_inode_getsecurity 0 37354 NULL
126445 +hci_sock_sendmsg_37420 hci_sock_sendmsg 4 37420 NULL
126446 +acpi_os_allocate_zeroed_37422 acpi_os_allocate_zeroed 1 37422 NULL nohasharray
126447 +find_next_bit_37422 find_next_bit 0 37422 &acpi_os_allocate_zeroed_37422
126448 +tty_insert_flip_string_fixed_flag_37428 tty_insert_flip_string_fixed_flag 4-0 37428 NULL
126449 +iwl_print_last_event_logs_37433 iwl_print_last_event_logs 7-9-0 37433 NULL
126450 +fru_alloc_37442 fru_alloc 1 37442 NULL
126451 +tcp_established_options_37450 tcp_established_options 0 37450 NULL
126452 +brcmf_sdio_dump_console_37455 brcmf_sdio_dump_console 4 37455 NULL
126453 +get_est_timing_37484 get_est_timing 0 37484 NULL
126454 +kmem_realloc_37489 kmem_realloc 2 37489 NULL
126455 +bitmap_dirty_bits_37503 bitmap_dirty_bits 2 37503 NULL
126456 +osc_active_seq_write_37514 osc_active_seq_write 3 37514 NULL
126457 +bdev_writeseg_37519 bdev_writeseg 2-3 37519 NULL
126458 +xz_dec_test_write_37527 xz_dec_test_write 3 37527 NULL
126459 +fault_inject_read_37534 fault_inject_read 3 37534 NULL
126460 +hdr_size_37536 hdr_size 0 37536 NULL
126461 +extent_map_end_37550 extent_map_end 0 37550 NULL
126462 +sep_create_dcb_dmatables_context_37551 sep_create_dcb_dmatables_context 6 37551 NULL
126463 +xhci_alloc_streams_37586 xhci_alloc_streams 5 37586 NULL
126464 +qla2x00_debounce_register_37597 qla2x00_debounce_register 0 37597 NULL
126465 +kvm_read_guest_page_mmu_37611 kvm_read_guest_page_mmu 6 37611 NULL
126466 +SYSC_mbind_37622 SYSC_mbind 5 37622 NULL
126467 +SyS_mbind_37638 SyS_mbind 5 37638 NULL
126468 +bio_copy_user_iov_37660 bio_copy_user_iov 4 37660 NULL
126469 +rfcomm_sock_sendmsg_37661 rfcomm_sock_sendmsg 4 37661 NULL nohasharray
126470 +vmw_framebuffer_dmabuf_dirty_37661 vmw_framebuffer_dmabuf_dirty 6 37661 &rfcomm_sock_sendmsg_37661
126471 +SYSC_get_mempolicy_37664 SYSC_get_mempolicy 3 37664 NULL
126472 +__wa_seg_calculate_isoc_frame_count_37672 __wa_seg_calculate_isoc_frame_count 0 37672 NULL
126473 +ieee80211_if_read_rc_rateidx_mcs_mask_2ghz_37675 ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 NULL
126474 +tracing_saved_cmdlines_size_write_37684 tracing_saved_cmdlines_size_write 3 37684 NULL
126475 +regmap_map_read_file_37685 regmap_map_read_file 3 37685 NULL
126476 +nametbl_header_37698 nametbl_header 2-0 37698 NULL
126477 +__le32_to_cpup_37702 __le32_to_cpup 0 37702 NULL
126478 +dynamic_ps_timeout_write_37713 dynamic_ps_timeout_write 3 37713 NULL
126479 +read_enabled_file_bool_37744 read_enabled_file_bool 3 37744 NULL
126480 +ocfs2_control_cfu_37750 ocfs2_control_cfu 2 37750 NULL
126481 +ipath_cdev_init_37752 ipath_cdev_init 1 37752 NULL
126482 +dccp_setsockopt_cscov_37766 dccp_setsockopt_cscov 2 37766 NULL
126483 +il4965_rs_sta_dbgfs_rate_scale_data_read_37792 il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 NULL
126484 +smk_read_logging_37804 smk_read_logging 3 37804 NULL
126485 +ocrdma_alloc_frmr_page_list_37815 ocrdma_alloc_frmr_page_list 2 37815 NULL
126486 +rx_decrypt_key_not_found_read_37820 rx_decrypt_key_not_found_read 3 37820 NULL
126487 +android_get_p2p_addr_37832 android_get_p2p_addr 0 37832 NULL
126488 +o2hb_debug_read_37851 o2hb_debug_read 3 37851 NULL
126489 +xfs_dir2_block_to_sf_37868 xfs_dir2_block_to_sf 3 37868 NULL
126490 +btrfs_leaf_data_37869 btrfs_leaf_data 0 37869 NULL
126491 +btrfs_stack_file_extent_disk_bytenr_37888 btrfs_stack_file_extent_disk_bytenr 0 37888 NULL
126492 +pkt_alloc_packet_data_37928 pkt_alloc_packet_data 1 37928 NULL nohasharray
126493 +_rtw_malloc_37928 _rtw_malloc 1 37928 &pkt_alloc_packet_data_37928
126494 +read_rbu_packet_size_37939 read_rbu_packet_size 6 37939 NULL
126495 +write_file_bool_37957 write_file_bool 3 37957 NULL
126496 +fifo_alloc_37961 fifo_alloc 1 37961 NULL
126497 +rds_rdma_extra_size_37990 rds_rdma_extra_size 0 37990 NULL
126498 +persistent_ram_old_size_37997 persistent_ram_old_size 0 37997 NULL
126499 +vfs_readv_38011 vfs_readv 3 38011 NULL
126500 +aggr_recv_addba_req_evt_38037 aggr_recv_addba_req_evt 4 38037 NULL
126501 +il_dbgfs_chain_noise_read_38044 il_dbgfs_chain_noise_read 3 38044 NULL nohasharray
126502 +klsi_105_prepare_write_buffer_38044 klsi_105_prepare_write_buffer 3 38044 &il_dbgfs_chain_noise_read_38044
126503 +SyS_llistxattr_38048 SyS_llistxattr 3 38048 NULL
126504 +_xfs_buf_alloc_38058 _xfs_buf_alloc 3 38058 NULL
126505 +nsm_create_handle_38060 nsm_create_handle 4 38060 NULL
126506 +alloc_ltalkdev_38071 alloc_ltalkdev 1 38071 NULL
126507 +xfs_buf_readahead_map_38081 xfs_buf_readahead_map 3 38081 NULL
126508 +uwb_mac_addr_print_38085 uwb_mac_addr_print 2 38085 NULL
126509 +request_key_auth_new_38092 request_key_auth_new 3 38092 NULL
126510 +proc_self_readlink_38094 proc_self_readlink 3 38094 NULL
126511 +ep0_read_38095 ep0_read 3 38095 NULL
126512 +osc_checksum_seq_write_38096 osc_checksum_seq_write 3 38096 NULL nohasharray
126513 +sk_wmem_schedule_38096 sk_wmem_schedule 2 38096 &osc_checksum_seq_write_38096
126514 +o2hb_read_slots_38105 o2hb_read_slots 2 38105 NULL
126515 +snd_pcm_oss_write_38108 snd_pcm_oss_write 3 38108 NULL
126516 +vmw_kms_present_38130 vmw_kms_present 9 38130 NULL
126517 +__ntfs_copy_from_user_iovec_inatomic_38153 __ntfs_copy_from_user_iovec_inatomic 3-4-0 38153 NULL
126518 +btrfs_extent_same_38163 btrfs_extent_same 3-2-5 38163 NULL
126519 +kvm_clear_guest_38164 kvm_clear_guest 3-2 38164 NULL
126520 +cdev_add_38176 cdev_add 2-3 38176 NULL
126521 +rt2x00debug_write_rf_38195 rt2x00debug_write_rf 3 38195 NULL
126522 +get_ucode_user_38202 get_ucode_user 3 38202 NULL
126523 +osd_req_list_partition_collections_38223 osd_req_list_partition_collections 5 38223 NULL
126524 +ceph_decode_16_38239 ceph_decode_16 0 38239 NULL
126525 +_ipw_read_reg32_38245 _ipw_read_reg32 0 38245 NULL
126526 +mthca_alloc_icm_table_38268 mthca_alloc_icm_table 4-3 38268 NULL nohasharray
126527 +ieee80211_if_read_auto_open_plinks_38268 ieee80211_if_read_auto_open_plinks 3 38268 &mthca_alloc_icm_table_38268
126528 +xfs_bmdr_to_bmbt_38275 xfs_bmdr_to_bmbt 5 38275 NULL nohasharray
126529 +xfs_bmbt_to_bmdr_38275 xfs_bmbt_to_bmdr 3 38275 &xfs_bmdr_to_bmbt_38275
126530 +ftdi_process_packet_38281 ftdi_process_packet 4 38281 NULL
126531 +C_SYSC_pselect6_38296 C_SYSC_pselect6 1 38296 NULL
126532 +ucma_query_path_38305 ucma_query_path 3 38305 NULL
126533 +isr_rx_headers_read_38325 isr_rx_headers_read 3 38325 NULL
126534 +ida_simple_get_38326 ida_simple_get 0 38326 NULL
126535 +__snd_gf1_look8_38333 __snd_gf1_look8 0 38333 NULL
126536 +btrfs_file_extent_disk_num_bytes_38363 btrfs_file_extent_disk_num_bytes 0 38363 NULL
126537 +dn_sendmsg_38390 dn_sendmsg 4 38390 NULL
126538 +ieee80211_if_read_dtim_count_38419 ieee80211_if_read_dtim_count 3 38419 NULL
126539 +pmcraid_copy_sglist_38431 pmcraid_copy_sglist 3 38431 NULL
126540 +iov_iter_npages_iovec_38448 iov_iter_npages_iovec 0-2 38448 NULL
126541 +kvm_write_guest_38454 kvm_write_guest 4-2 38454 NULL
126542 +_iwl_dbgfs_scan_ant_rxchain_write_38479 _iwl_dbgfs_scan_ant_rxchain_write 3 38479 NULL
126543 +blk_end_bidi_request_38482 blk_end_bidi_request 3-4 38482 NULL
126544 +dev_names_read_38509 dev_names_read 3 38509 NULL
126545 +iscsi_create_iface_38510 iscsi_create_iface 5 38510 NULL
126546 +event_rx_mismatch_read_38518 event_rx_mismatch_read 3 38518 NULL
126547 +ubifs_idx_node_sz_38546 ubifs_idx_node_sz 0-2 38546 NULL
126548 +btrfs_discard_extent_38547 btrfs_discard_extent 2 38547 NULL
126549 +kuc_len_38557 kuc_len 0-1 38557 NULL
126550 +irda_sendmsg_dgram_38563 irda_sendmsg_dgram 4 38563 NULL
126551 +il4965_rs_sta_dbgfs_scale_table_read_38564 il4965_rs_sta_dbgfs_scale_table_read 3 38564 NULL
126552 +_ipw_read32_38565 _ipw_read32 0 38565 NULL
126553 +snd_nm256_playback_copy_38567 snd_nm256_playback_copy 3-5 38567 NULL
126554 +copy_ctl_value_to_user_38587 copy_ctl_value_to_user 4 38587 NULL
126555 +rd_allocate_sgl_table_38607 rd_allocate_sgl_table 3 38607 NULL
126556 +icn_writecmd_38629 icn_writecmd 2 38629 NULL
126557 +write_enabled_file_bool_38630 write_enabled_file_bool 3 38630 NULL
126558 +ext2_readpages_38640 ext2_readpages 4 38640 NULL
126559 +audit_init_entry_38644 audit_init_entry 1 38644 NULL
126560 +qp_broker_alloc_38646 qp_broker_alloc 6-5 38646 NULL
126561 +mmc_send_cxd_data_38655 mmc_send_cxd_data 5 38655 NULL
126562 +nouveau_instmem_create__38664 nouveau_instmem_create_ 4 38664 NULL
126563 +iscsit_dump_data_payload_38683 iscsit_dump_data_payload 2 38683 NULL
126564 +validate_vid_hdr_38699 validate_vid_hdr 0 38699 NULL
126565 +rbio_add_io_page_38700 rbio_add_io_page 6 38700 NULL
126566 +udf_readpages_38761 udf_readpages 4 38761 NULL
126567 +iwl_dbgfs_thermal_throttling_read_38779 iwl_dbgfs_thermal_throttling_read 3 38779 NULL
126568 +bcache_device_init_38781 bcache_device_init 3 38781 NULL
126569 +snd_gus_dram_write_38784 snd_gus_dram_write 4 38784 NULL
126570 +err_decode_38804 err_decode 2 38804 NULL
126571 +ipv6_renew_option_38813 ipv6_renew_option 3 38813 NULL
126572 +direct_entry_38836 direct_entry 3 38836 NULL
126573 +compat_udp_setsockopt_38840 compat_udp_setsockopt 5 38840 NULL
126574 +interfaces_38859 interfaces 2 38859 NULL
126575 +dbgfs_state_38894 dbgfs_state 3 38894 NULL
126576 +il_dbgfs_sram_write_38942 il_dbgfs_sram_write 3 38942 NULL
126577 +__ath6kl_wmi_send_mgmt_cmd_38971 __ath6kl_wmi_send_mgmt_cmd 7 38971 NULL
126578 +C_SYSC_preadv64_38977 C_SYSC_preadv64 3 38977 NULL nohasharray
126579 +usb_maxpacket_38977 usb_maxpacket 0 38977 &C_SYSC_preadv64_38977
126580 +OSDSetBlock_38986 OSDSetBlock 2-4 38986 NULL
126581 +bio_clone_range_38997 bio_clone_range 2 38997 NULL
126582 +lpfc_idiag_extacc_write_38998 lpfc_idiag_extacc_write 3 38998 NULL
126583 +get_nodes_39012 get_nodes 3 39012 NULL
126584 +twl6030_interrupt_unmask_39013 twl6030_interrupt_unmask 2 39013 NULL
126585 +force_sc_support_read_39014 force_sc_support_read 3 39014 NULL
126586 +__blkdev_issue_zeroout_39020 __blkdev_issue_zeroout 3 39020 NULL
126587 +_zd_iowrite32v_async_locked_39034 _zd_iowrite32v_async_locked 3 39034 NULL
126588 +tomoyo_truncate_39105 tomoyo_truncate 0 39105 NULL
126589 +leb_write_lock_39111 leb_write_lock 0 39111 NULL
126590 +__kfifo_to_user_r_39123 __kfifo_to_user_r 5-3 39123 NULL
126591 +ea_foreach_39133 ea_foreach 0 39133 NULL
126592 +generic_permission_39150 generic_permission 0 39150 NULL
126593 +proc_coredump_filter_read_39153 proc_coredump_filter_read 3 39153 NULL
126594 +ath9k_hw_ar9003_dump_eeprom_39156 ath9k_hw_ar9003_dump_eeprom 5-4 39156 NULL
126595 +echo_client_kbrw_39170 echo_client_kbrw 6 39170 NULL
126596 +ext3_xattr_check_names_39174 ext3_xattr_check_names 0 39174 NULL
126597 +ubi_more_update_data_39189 ubi_more_update_data 4 39189 NULL
126598 +qcam_read_bytes_39205 qcam_read_bytes 0 39205 NULL
126599 +ivtv_v4l2_write_39226 ivtv_v4l2_write 3 39226 NULL
126600 +posix_acl_to_xattr_39237 posix_acl_to_xattr 0 39237 NULL
126601 +r128_compat_ioctl_39250 r128_compat_ioctl 2 39250 NULL nohasharray
126602 +pwr_cont_miss_bcns_spread_read_39250 pwr_cont_miss_bcns_spread_read 3 39250 &r128_compat_ioctl_39250
126603 +i915_error_state_read_39254 i915_error_state_read 3 39254 NULL
126604 +rx_filter_protection_filter_read_39282 rx_filter_protection_filter_read 3 39282 NULL
126605 +_iwl_dbgfs_pm_params_write_39325 _iwl_dbgfs_pm_params_write 3 39325 NULL
126606 +__cfg80211_connect_result_39326 __cfg80211_connect_result 4-6 39326 NULL
126607 +insert_reserved_file_extent_39327 insert_reserved_file_extent 3 39327 NULL
126608 +wimax_msg_alloc_39343 wimax_msg_alloc 4 39343 NULL
126609 +ide_complete_rq_39354 ide_complete_rq 3 39354 NULL
126610 +do_write_log_from_user_39362 do_write_log_from_user 3-0 39362 NULL
126611 +vortex_wtdma_getlinearpos_39371 vortex_wtdma_getlinearpos 0 39371 NULL
126612 +regmap_name_read_file_39379 regmap_name_read_file 3 39379 NULL
126613 +fnic_trace_debugfs_read_39380 fnic_trace_debugfs_read 3 39380 NULL
126614 +ps_poll_ps_poll_utilization_read_39383 ps_poll_ps_poll_utilization_read 3 39383 NULL
126615 +__send_to_port_39386 __send_to_port 3 39386 NULL
126616 +user_power_read_39414 user_power_read 3 39414 NULL
126617 +hash_ipmark4_expire_39419 hash_ipmark4_expire 4 39419 NULL
126618 +alloc_agpphysmem_i8xx_39427 alloc_agpphysmem_i8xx 1 39427 NULL
126619 +mic_desc_size_39464 mic_desc_size 0 39464 NULL
126620 +setkey_unaligned_39474 setkey_unaligned 3 39474 NULL
126621 +ieee80211_if_fmt_dot11MeshHWMPmaxPREQretries_39499 ieee80211_if_fmt_dot11MeshHWMPmaxPREQretries 3 39499 NULL
126622 +cl_req_alloc_39523 cl_req_alloc 4 39523 NULL
126623 +int_proc_write_39542 int_proc_write 3 39542 NULL
126624 +ext4_alloc_file_blocks_39551 ext4_alloc_file_blocks 3 39551 NULL
126625 +pp_write_39554 pp_write 3 39554 NULL
126626 +datablob_format_39571 datablob_format 2 39571 NULL nohasharray
126627 +ieee80211_if_read_fwded_mcast_39571 ieee80211_if_read_fwded_mcast 3 39571 &datablob_format_39571
126628 +memblock_virt_alloc_internal_39600 memblock_virt_alloc_internal 1 39600 NULL
126629 +ext_depth_39607 ext_depth 0 39607 NULL
126630 +batadv_tt_tvlv_generate_39615 batadv_tt_tvlv_generate 4 39615 NULL
126631 +nfs_idmap_get_key_39616 nfs_idmap_get_key 2 39616 NULL
126632 +sdio_readb_39618 sdio_readb 0 39618 NULL
126633 +set_dev_class_39645 set_dev_class 4 39645 NULL
126634 +snd_rme32_capture_copy_39653 snd_rme32_capture_copy 5 39653 NULL
126635 +tcp_try_rmem_schedule_39657 tcp_try_rmem_schedule 3 39657 NULL
126636 +kvm_read_guest_cached_39666 kvm_read_guest_cached 4 39666 NULL
126637 +v4l_stk_read_39672 v4l_stk_read 3 39672 NULL
126638 +hsc_msg_len_get_39673 hsc_msg_len_get 0 39673 NULL
126639 +do_surface_dirty_sou_39678 do_surface_dirty_sou 7 39678 NULL
126640 +ftrace_pid_write_39710 ftrace_pid_write 3 39710 NULL
126641 +adt7316_spi_multi_read_39765 adt7316_spi_multi_read 3 39765 NULL
126642 +security_inode_listsecurity_39812 security_inode_listsecurity 0 39812 NULL
126643 +snd_pcm_oss_writev3_39818 snd_pcm_oss_writev3 3 39818 NULL
126644 +get_priv_size_39828 get_priv_size 0-1 39828 NULL
126645 +pkt_add_39897 pkt_add 3 39897 NULL
126646 +read_file_modal_eeprom_39909 read_file_modal_eeprom 3 39909 NULL
126647 +gen_pool_add_virt_39913 gen_pool_add_virt 4 39913 NULL
126648 +dw210x_op_rw_39915 dw210x_op_rw 6 39915 NULL
126649 +aes_encrypt_interrupt_read_39919 aes_encrypt_interrupt_read 3 39919 NULL
126650 +oom_score_adj_read_39921 oom_score_adj_read 3 39921 NULL nohasharray
126651 +exofs_read_kern_39921 exofs_read_kern 6 39921 &oom_score_adj_read_39921
126652 +__spi_async_39932 __spi_async 0 39932 NULL
126653 +__get_order_39935 __get_order 0 39935 NULL
126654 +error_error_frame_read_39947 error_error_frame_read 3 39947 NULL
126655 +tty_prepare_flip_string_39955 tty_prepare_flip_string 3-0 39955 NULL
126656 +lstcon_group_list_39958 lstcon_group_list 2 39958 NULL
126657 +bio_chain_clone_range_39967 bio_chain_clone_range 3 39967 NULL
126658 +dma_push_rx_39973 dma_push_rx 2 39973 NULL
126659 +broadsheetfb_write_39976 broadsheetfb_write 3 39976 NULL
126660 +mthca_array_init_39987 mthca_array_init 2 39987 NULL
126661 +fw_device_op_read_39990 fw_device_op_read 3 39990 NULL
126662 +xen_hvm_config_40018 xen_hvm_config 2 40018 NULL
126663 +ivtvfb_write_40023 ivtvfb_write 3 40023 NULL
126664 +disc_pwup_write_40027 disc_pwup_write 3 40027 NULL
126665 +ea_foreach_i_40028 ea_foreach_i 0 40028 NULL
126666 +datablob_hmac_append_40038 datablob_hmac_append 3 40038 NULL
126667 +l2cap_create_iframe_pdu_40055 l2cap_create_iframe_pdu 3 40055 NULL nohasharray
126668 +add_tty_40055 add_tty 1 40055 &l2cap_create_iframe_pdu_40055
126669 +atomic_xchg_40070 atomic_xchg 0 40070 NULL
126670 +sctp_setsockopt_delayed_ack_40129 sctp_setsockopt_delayed_ack 3 40129 NULL
126671 +dwc2_max_desc_num_40132 dwc2_max_desc_num 0 40132 NULL
126672 +rx_rx_frame_checksum_read_40140 rx_rx_frame_checksum_read 3 40140 NULL
126673 +ath10k_write_simulate_fw_crash_40143 ath10k_write_simulate_fw_crash 3 40143 NULL
126674 +iwch_alloc_fastreg_pbl_40153 iwch_alloc_fastreg_pbl 2 40153 NULL
126675 +pt_write_40159 pt_write 3 40159 NULL
126676 +scsi_sg_count_40182 scsi_sg_count 0 40182 NULL
126677 +ipr_alloc_ucode_buffer_40199 ipr_alloc_ucode_buffer 1 40199 NULL
126678 +allocate_probes_40204 allocate_probes 1 40204 NULL
126679 +au0828_v4l2_read_40220 au0828_v4l2_read 3 40220 NULL
126680 +compress_file_range_40225 compress_file_range 3-4 40225 NULL
126681 +ocrdma_dbgfs_ops_read_40232 ocrdma_dbgfs_ops_read 3 40232 NULL
126682 +osst_read_40237 osst_read 3 40237 NULL
126683 +lpage_info_slot_40243 lpage_info_slot 1-3 40243 NULL
126684 +ocfs2_zero_extend_get_range_40248 ocfs2_zero_extend_get_range 4 40248 NULL
126685 +of_get_child_count_40254 of_get_child_count 0 40254 NULL
126686 +rs_sta_dbgfs_scale_table_read_40262 rs_sta_dbgfs_scale_table_read 3 40262 NULL
126687 +ext2_fiemap_40271 ext2_fiemap 4 40271 NULL
126688 +usbnet_read_cmd_40275 usbnet_read_cmd 7 40275 NULL
126689 +rx_xfr_hint_trig_read_40283 rx_xfr_hint_trig_read 3 40283 NULL
126690 +SyS_bind_40303 SyS_bind 3 40303 NULL
126691 +ubi_io_write_data_40305 ubi_io_write_data 0 40305 NULL
126692 +ib_get_mad_data_offset_40336 ib_get_mad_data_offset 0 40336 NULL
126693 +mmio_read_40348 mmio_read 4 40348 NULL
126694 +event_rx_mem_empty_read_40363 event_rx_mem_empty_read 3 40363 NULL
126695 +ocfs2_check_range_for_refcount_40365 ocfs2_check_range_for_refcount 2-3 40365 NULL
126696 +get_chars_40373 get_chars 3 40373 NULL
126697 +fb_prepare_extra_logos_40429 fb_prepare_extra_logos 0-2 40429 NULL
126698 +tomoyo_update_policy_40458 tomoyo_update_policy 2 40458 NULL
126699 +zd_usb_scnprint_id_40459 zd_usb_scnprint_id 0-3 40459 NULL
126700 +gp2ap020a00f_write_event_threshold_40461 gp2ap020a00f_write_event_threshold 2 40461 NULL
126701 +SyS_writev_40467 SyS_writev 3 40467 NULL
126702 +SyS_select_40473 SyS_select 1 40473 NULL
126703 +afs_fs_store_data_40484 afs_fs_store_data 3-4-5-6 40484 NULL
126704 +batadv_hash_new_40491 batadv_hash_new 1 40491 NULL
126705 +devcgroup_inode_permission_40492 devcgroup_inode_permission 0 40492 NULL
126706 +__ethtool_get_sset_count_40511 __ethtool_get_sset_count 0 40511 NULL
126707 +TSS_checkhmac2_40520 TSS_checkhmac2 5-7 40520 NULL
126708 +ixgbe_dbg_reg_ops_read_40540 ixgbe_dbg_reg_ops_read 3 40540 NULL
126709 +ima_write_policy_40548 ima_write_policy 3 40548 NULL
126710 +esp_alloc_tmp_40558 esp_alloc_tmp 3-2 40558 NULL
126711 +get_priv_descr_and_size_40612 get_priv_descr_and_size 0 40612 NULL
126712 +twl4030_kpwrite_u8_40665 twl4030_kpwrite_u8 3 40665 NULL
126713 +__cfg80211_roamed_40668 __cfg80211_roamed 4-6 40668 NULL
126714 +pipeline_rx_complete_stat_fifo_int_read_40671 pipeline_rx_complete_stat_fifo_int_read 3 40671 NULL
126715 +fops_read_40672 fops_read 3 40672 NULL
126716 +idr_get_empty_slot_40674 idr_get_empty_slot 0 40674 NULL
126717 +alloc_rbio_40676 alloc_rbio 4 40676 NULL
126718 +videobuf_dma_init_user_locked_40678 videobuf_dma_init_user_locked 4-3 40678 NULL
126719 +nfc_hci_set_param_40697 nfc_hci_set_param 5 40697 NULL
126720 +__seq_open_private_40715 __seq_open_private 3 40715 NULL
126721 +of_pdt_build_one_prop_40735 of_pdt_build_one_prop 5 40735 NULL
126722 +fuse_readpages_40737 fuse_readpages 4 40737 NULL
126723 +xfs_iext_remove_direct_40744 xfs_iext_remove_direct 3 40744 NULL
126724 +security_inode_listxattr_40752 security_inode_listxattr 0 40752 NULL
126725 +card_send_command_40757 card_send_command 3 40757 NULL
126726 +ad1889_readl_40765 ad1889_readl 0 40765 NULL
126727 +pg_write_40766 pg_write 3 40766 NULL
126728 +kernfs_fop_read_40770 kernfs_fop_read 3 40770 NULL
126729 +show_list_40775 show_list 3-0 40775 NULL
126730 +kfifo_out_copy_r_40784 kfifo_out_copy_r 0-3 40784 NULL
126731 +bitmap_weight_40791 bitmap_weight 0 40791 NULL
126732 +pyra_sysfs_read_40795 pyra_sysfs_read 6 40795 NULL
126733 +rtw_add_beacon_40801 rtw_add_beacon 3-5 40801 NULL
126734 +add_action_40811 add_action 4 40811 NULL
126735 +nl80211_send_roamed_40825 nl80211_send_roamed 5-7 40825 NULL
126736 +nilfs_mdt_init_40849 nilfs_mdt_init 3 40849 NULL
126737 +v9fs_file_read_40858 v9fs_file_read 3 40858 NULL
126738 +read_file_queue_40895 read_file_queue 3 40895 NULL
126739 +waiters_read_40902 waiters_read 3 40902 NULL
126740 +isdn_add_channels_40905 isdn_add_channels 3 40905 NULL
126741 +gfs2_ea_find_40913 gfs2_ea_find 0 40913 NULL
126742 +vol_cdev_write_40915 vol_cdev_write 3 40915 NULL
126743 +snd_vx_create_40948 snd_vx_create 4 40948 NULL
126744 +rds_sendmsg_40976 rds_sendmsg 4 40976 NULL
126745 +insert_old_idx_40987 insert_old_idx 0 40987 NULL
126746 +il_dbgfs_fh_reg_read_40993 il_dbgfs_fh_reg_read 3 40993 NULL
126747 +iwl_dbgfs_scan_ant_rxchain_read_40999 iwl_dbgfs_scan_ant_rxchain_read 3 40999 NULL
126748 +mac80211_format_buffer_41010 mac80211_format_buffer 2 41010 NULL
126749 +get_pages_alloc_bvec_41012 get_pages_alloc_bvec 0-3 41012 NULL
126750 +mtd_block_isbad_41015 mtd_block_isbad 0 41015 NULL
126751 +__proc_dobitmasks_41029 __proc_dobitmasks 5 41029 NULL
126752 +_req_append_segment_41031 _req_append_segment 2 41031 NULL
126753 +mISDN_sock_sendmsg_41035 mISDN_sock_sendmsg 4 41035 NULL
126754 +ocfs2_xattr_index_block_find_41040 ocfs2_xattr_index_block_find 0 41040 NULL
126755 +lprocfs_write_frac_helper_41050 lprocfs_write_frac_helper 2 41050 NULL
126756 +vfs_listxattr_41062 vfs_listxattr 0 41062 NULL nohasharray
126757 +beacon_filtering_write_41062 beacon_filtering_write 3 41062 &vfs_listxattr_41062
126758 +sc_only_mode_read_41076 sc_only_mode_read 3 41076 NULL
126759 +cfg80211_inform_bss_frame_41078 cfg80211_inform_bss_frame 4 41078 NULL
126760 +nvme_map_user_pages_41093 nvme_map_user_pages 4-3 41093 NULL nohasharray
126761 +roccat_read_41093 roccat_read 3 41093 &nvme_map_user_pages_41093
126762 +dma_attach_41094 dma_attach 5-6 41094 NULL
126763 +provide_user_output_41105 provide_user_output 3 41105 NULL
126764 +f_audio_buffer_alloc_41110 f_audio_buffer_alloc 1 41110 NULL
126765 +ath10k_read_wmi_services_41112 ath10k_read_wmi_services 3 41112 NULL
126766 +v4l2_ctrl_new_int_menu_41151 v4l2_ctrl_new_int_menu 4 41151 NULL
126767 +tx_frag_mpdu_alloc_failed_read_41167 tx_frag_mpdu_alloc_failed_read 3 41167 NULL
126768 +dvb_ca_write_41171 dvb_ca_write 3 41171 NULL
126769 +dfs_file_write_41196 dfs_file_write 3 41196 NULL
126770 +nfs_page_array_len_41219 nfs_page_array_len 0-2-1 41219 NULL
126771 +cfg80211_process_disassoc_41231 cfg80211_process_disassoc 3 41231 NULL
126772 +hiddev_compat_ioctl_41255 hiddev_compat_ioctl 2 41255 NULL
126773 +erst_read_41260 erst_read 0 41260 NULL
126774 +alloc_context_41283 alloc_context 1 41283 NULL
126775 +of_count_phandle_with_args_41291 of_count_phandle_with_args 0 41291 NULL
126776 +o2hb_setup_one_bio_41341 o2hb_setup_one_bio 4 41341 NULL
126777 +twl_change_queue_depth_41342 twl_change_queue_depth 2 41342 NULL
126778 +rtw_android_set_block_41347 rtw_android_set_block 0 41347 NULL
126779 +ceph_do_getattr_41349 ceph_do_getattr 0 41349 NULL
126780 +cnic_init_id_tbl_41354 cnic_init_id_tbl 2 41354 NULL
126781 +kmp_init_41373 kmp_init 2 41373 NULL
126782 +isr_commands_read_41398 isr_commands_read 3 41398 NULL
126783 +rx_defrag_decrypt_failed_read_41411 rx_defrag_decrypt_failed_read 3 41411 NULL
126784 +xfs_iext_add_41422 xfs_iext_add 3 41422 NULL
126785 +isdn_ppp_fill_rq_41428 isdn_ppp_fill_rq 2 41428 NULL
126786 +lbs_rdrf_read_41431 lbs_rdrf_read 3 41431 NULL
126787 +iio_device_alloc_41440 iio_device_alloc 1 41440 NULL
126788 +ntfs_file_buffered_write_41442 ntfs_file_buffered_write 6-4 41442 NULL
126789 +pcpu_build_alloc_info_41443 pcpu_build_alloc_info 1-2-3 41443 NULL
126790 +se_io_cb_41461 se_io_cb 3 41461 NULL
126791 +layout_leb_in_gaps_41470 layout_leb_in_gaps 0 41470 NULL
126792 +rt2x00debug_write_rfcsr_41473 rt2x00debug_write_rfcsr 3 41473 NULL
126793 +bl_alloc_init_bio_41478 bl_alloc_init_bio 1 41478 NULL
126794 +kvm_unmap_hva_range_41484 kvm_unmap_hva_range 3-2 41484 NULL
126795 +wep_interrupt_read_41492 wep_interrupt_read 3 41492 NULL
126796 +hpfs_translate_name_41497 hpfs_translate_name 3 41497 NULL
126797 +xfrm_hash_new_size_41505 xfrm_hash_new_size 0-1 41505 NULL
126798 +SyS_preadv_41523 SyS_preadv 3 41523 NULL
126799 +dm_get_reserved_rq_based_ios_41529 dm_get_reserved_rq_based_ios 0 41529 NULL
126800 +tx_tx_frame_checksum_read_41553 tx_tx_frame_checksum_read 3 41553 NULL
126801 +ath6kl_endpoint_stats_read_41554 ath6kl_endpoint_stats_read 3 41554 NULL
126802 +si476x_radio_fops_read_41559 si476x_radio_fops_read 3 41559 NULL nohasharray
126803 +nr_status_frames_41559 nr_status_frames 0-1 41559 &si476x_radio_fops_read_41559
126804 +rng_dev_read_41581 rng_dev_read 3 41581 NULL
126805 +nfsd_readv_41585 nfsd_readv 4 41585 NULL
126806 +batadv_tvlv_container_ogm_append_41588 batadv_tvlv_container_ogm_append 4 41588 NULL
126807 +tcp_hdrlen_41610 tcp_hdrlen 0 41610 NULL
126808 +usb_endpoint_maxp_41613 usb_endpoint_maxp 0 41613 NULL nohasharray
126809 +lbs_bcnmiss_write_41613 lbs_bcnmiss_write 3 41613 &usb_endpoint_maxp_41613
126810 +a2mp_send_41615 a2mp_send 4 41615 NULL
126811 +lstcon_batch_list_41627 lstcon_batch_list 2 41627 NULL
126812 +mempool_create_kmalloc_pool_41650 mempool_create_kmalloc_pool 1 41650 NULL
126813 +rx_rx_pre_complt_read_41653 rx_rx_pre_complt_read 3 41653 NULL
126814 +get_std_timing_41654 get_std_timing 0 41654 NULL
126815 +ieee80211_if_fmt_bssid_41677 ieee80211_if_fmt_bssid 3 41677 NULL
126816 +lov_unpackmd_41701 lov_unpackmd 4 41701 NULL
126817 +fillonedir_41746 fillonedir 3 41746 NULL
126818 +iwl_dbgfs_bt_notif_read_41794 iwl_dbgfs_bt_notif_read 3 41794 NULL
126819 +hsi_alloc_controller_41802 hsi_alloc_controller 1 41802 NULL
126820 +rtw_android_get_macaddr_41812 rtw_android_get_macaddr 0 41812 NULL
126821 +sco_send_frame_41815 sco_send_frame 3 41815 NULL
126822 +copy_page_to_iter_bvec_41830 copy_page_to_iter_bvec 0-3 41830 NULL
126823 +ixgbe_dbg_netdev_ops_read_41839 ixgbe_dbg_netdev_ops_read 3 41839 NULL
126824 +do_ip_setsockopt_41852 do_ip_setsockopt 5 41852 NULL
126825 +keyctl_instantiate_key_41855 keyctl_instantiate_key 3 41855 NULL
126826 +pci_map_single_41869 pci_map_single 0 41869 NULL
126827 +get_fdb_entries_41916 get_fdb_entries 3 41916 NULL
126828 +ext4_da_write_inline_data_begin_41935 ext4_da_write_inline_data_begin 4-3 41935 NULL
126829 +sci_rxfill_41945 sci_rxfill 0 41945 NULL
126830 +read_gssp_41947 read_gssp 3 41947 NULL
126831 +ocfs2_xattr_bucket_get_name_value_41949 ocfs2_xattr_bucket_get_name_value 0 41949 NULL
126832 +portnames_read_41958 portnames_read 3 41958 NULL
126833 +ubi_self_check_all_ff_41959 ubi_self_check_all_ff 0 41959 NULL
126834 +dst_mtu_41969 dst_mtu 0 41969 NULL
126835 +cx24116_writeregN_41975 cx24116_writeregN 4 41975 NULL
126836 +ubi_io_is_bad_41983 ubi_io_is_bad 0 41983 NULL
126837 +pool_allocate_42012 pool_allocate 3 42012 NULL
126838 +spidev_sync_read_42014 spidev_sync_read 0 42014 NULL
126839 +rs_sta_dbgfs_scale_table_write_42017 rs_sta_dbgfs_scale_table_write 3 42017 NULL
126840 +acpi_ut_create_buffer_object_42030 acpi_ut_create_buffer_object 1 42030 NULL
126841 +__hwahc_op_set_gtk_42038 __hwahc_op_set_gtk 4 42038 NULL
126842 +alloc_trace_kprobe_42041 alloc_trace_kprobe 6 42041 NULL
126843 +irda_sendmsg_ultra_42047 irda_sendmsg_ultra 4 42047 NULL
126844 +jffs2_do_link_42048 jffs2_do_link 6 42048 NULL
126845 +ps_poll_upsd_max_ap_turn_read_42050 ps_poll_upsd_max_ap_turn_read 3 42050 NULL
126846 +InterfaceTransmitPacket_42058 InterfaceTransmitPacket 3 42058 NULL
126847 +scsi_execute_req_42088 scsi_execute_req 5 42088 NULL
126848 +sk_chk_filter_42095 sk_chk_filter 2 42095 NULL
126849 +submit_inquiry_42108 submit_inquiry 3 42108 NULL
126850 +dw_dma_cyclic_prep_42113 dw_dma_cyclic_prep 3-4 42113 NULL
126851 +blk_ioctl_zeroout_42160 blk_ioctl_zeroout 3 42160 NULL
126852 +mmc_align_data_size_42161 mmc_align_data_size 0-2 42161 NULL
126853 +read_file_base_eeprom_42168 read_file_base_eeprom 3 42168 NULL
126854 +oprofilefs_str_to_user_42182 oprofilefs_str_to_user 3 42182 NULL
126855 +write_file_beacon_42185 write_file_beacon 3 42185 NULL
126856 +get_znodes_to_commit_42201 get_znodes_to_commit 0 42201 NULL
126857 +pla_ocp_read_42235 pla_ocp_read 3 42235 NULL nohasharray
126858 +blockdev_direct_IO_42235 blockdev_direct_IO 5 42235 &pla_ocp_read_42235
126859 +rx_defrag_need_decrypt_read_42253 rx_defrag_need_decrypt_read 3 42253 NULL
126860 +find_last_bit_42260 find_last_bit 0 42260 NULL
126861 +__pcpu_size_to_slot_42271 __pcpu_size_to_slot 0 42271 NULL
126862 +__tty_buffer_request_room_42276 __tty_buffer_request_room 2-0 42276 NULL
126863 +snd_pcm_hw_param_value_max_42280 snd_pcm_hw_param_value_max 0 42280 NULL
126864 +__cpus_weight_42299 __cpus_weight 0 42299 NULL
126865 +sel_read_perm_42302 sel_read_perm 3 42302 NULL
126866 +sctp_setsockopt_del_key_42304 sctp_setsockopt_del_key 3 42304 NULL nohasharray
126867 +ulong_read_file_42304 ulong_read_file 3 42304 &sctp_setsockopt_del_key_42304
126868 +xfs_vm_readpages_42308 xfs_vm_readpages 4 42308 NULL
126869 +hysdn_conf_read_42324 hysdn_conf_read 3 42324 NULL
126870 +tcp_sync_mss_42330 tcp_sync_mss 0-2 42330 NULL
126871 +ide_raw_taskfile_42355 ide_raw_taskfile 4 42355 NULL
126872 +drbd_md_last_sector_42378 drbd_md_last_sector 0 42378 NULL
126873 +il_dbgfs_disable_ht40_read_42386 il_dbgfs_disable_ht40_read 3 42386 NULL
126874 +msnd_fifo_read_42406 msnd_fifo_read 0-3 42406 NULL
126875 +krng_get_random_42420 krng_get_random 3 42420 NULL
126876 +gsm_data_alloc_42437 gsm_data_alloc 3 42437 NULL
126877 +spr_wm_latency_write_42441 spr_wm_latency_write 3 42441 NULL
126878 +key_conf_keyidx_read_42443 key_conf_keyidx_read 3 42443 NULL
126879 +snd_pcm_action_group_42452 snd_pcm_action_group 0 42452 NULL
126880 +tcm_loop_change_queue_depth_42454 tcm_loop_change_queue_depth 2 42454 NULL
126881 +kuc_free_42455 kuc_free 2 42455 NULL
126882 +__simple_xattr_set_42474 __simple_xattr_set 4 42474 NULL
126883 +omfs_readpages_42490 omfs_readpages 4 42490 NULL
126884 +bypass_write_42498 bypass_write 3 42498 NULL
126885 +SyS_mincore_42511 SyS_mincore 2-1 42511 NULL
126886 +kvm_write_wall_clock_42520 kvm_write_wall_clock 2 42520 NULL
126887 +dio_bio_complete_42524 dio_bio_complete 0 42524 NULL
126888 +smk_write_netlbladdr_42525 smk_write_netlbladdr 3 42525 NULL
126889 +self_check_ec_hdr_42528 self_check_ec_hdr 0 42528 NULL
126890 +dbAllocNear_42546 dbAllocNear 0 42546 NULL
126891 +ath6kl_wmi_proc_events_vif_42549 ath6kl_wmi_proc_events_vif 5 42549 NULL
126892 +udp_recvmsg_42558 udp_recvmsg 4 42558 NULL
126893 +iwl_print_event_log_42566 iwl_print_event_log 7-5-0 42566 NULL
126894 +xfrm_new_hash_mask_42579 xfrm_new_hash_mask 0-1 42579 NULL
126895 +oom_score_adj_write_42594 oom_score_adj_write 3 42594 NULL
126896 +ieee80211_if_fmt_dot11MeshHWMPactivePathTimeout_42635 ieee80211_if_fmt_dot11MeshHWMPactivePathTimeout 3 42635 NULL
126897 +scsi_activate_tcq_42640 scsi_activate_tcq 2 42640 NULL
126898 +br_mdb_rehash_42643 br_mdb_rehash 2 42643 NULL
126899 +_regmap_raw_write_42652 _regmap_raw_write 4-2 42652 NULL
126900 +request_key_and_link_42693 request_key_and_link 4 42693 NULL
126901 +vb2_read_42703 vb2_read 3 42703 NULL
126902 +dvb_demux_ioctl_42733 dvb_demux_ioctl 2 42733 NULL
126903 +set_aoe_iflist_42737 set_aoe_iflist 2 42737 NULL
126904 +ax25_setsockopt_42740 ax25_setsockopt 5 42740 NULL
126905 +x25_recvmsg_42777 x25_recvmsg 4 42777 NULL
126906 +snd_midi_event_decode_42780 snd_midi_event_decode 0 42780 NULL
126907 +cryptd_hash_setkey_42781 cryptd_hash_setkey 3 42781 NULL nohasharray
126908 +isku_sysfs_read_info_42781 isku_sysfs_read_info 6 42781 &cryptd_hash_setkey_42781
126909 +koneplus_sysfs_read_42792 koneplus_sysfs_read 6 42792 NULL
126910 +ntfs_attr_extend_allocation_42796 ntfs_attr_extend_allocation 0 42796 NULL
126911 +fw_device_op_compat_ioctl_42804 fw_device_op_compat_ioctl 2 42804 NULL
126912 +drm_ioctl_42813 drm_ioctl 2 42813 NULL
126913 +iwl_dbgfs_ucode_bt_stats_read_42820 iwl_dbgfs_ucode_bt_stats_read 3 42820 NULL
126914 +set_arg_42824 set_arg 3 42824 NULL
126915 +si476x_radio_read_rsq_blob_42827 si476x_radio_read_rsq_blob 3 42827 NULL
126916 +ocfs2_clusters_for_bytes_42872 ocfs2_clusters_for_bytes 0-2 42872 NULL
126917 +nvme_trans_unit_serial_page_42879 nvme_trans_unit_serial_page 4 42879 NULL
126918 +xpc_kmalloc_cacheline_aligned_42895 xpc_kmalloc_cacheline_aligned 1 42895 NULL
126919 +hd_end_request_42904 hd_end_request 2 42904 NULL
126920 +sta_last_rx_rate_read_42909 sta_last_rx_rate_read 3 42909 NULL
126921 +sctp_getsockopt_maxburst_42941 sctp_getsockopt_maxburst 2 42941 NULL
126922 +vx_reset_chk_42946 vx_reset_chk 0 42946 NULL
126923 +compat_udpv6_setsockopt_42981 compat_udpv6_setsockopt 5 42981 NULL
126924 +nfs_idmap_get_desc_42990 nfs_idmap_get_desc 4-2 42990 NULL nohasharray
126925 +rtw_os_xmit_resource_alloc_42990 rtw_os_xmit_resource_alloc 3 42990 &nfs_idmap_get_desc_42990
126926 +isr_rx_mem_overflow_read_43025 isr_rx_mem_overflow_read 3 43025 NULL
126927 +wep_default_key_count_read_43035 wep_default_key_count_read 3 43035 NULL
126928 +nouveau_gpuobj_create__43072 nouveau_gpuobj_create_ 9 43072 NULL
126929 +nfs_map_group_to_gid_43082 nfs_map_group_to_gid 3 43082 NULL
126930 +_xfer_secondary_pool_43089 _xfer_secondary_pool 2 43089 NULL
126931 +ieee80211_if_fmt_drop_unencrypted_43107 ieee80211_if_fmt_drop_unencrypted 3 43107 NULL
126932 +calculate_node_totalpages_43118 calculate_node_totalpages 2-3 43118 NULL
126933 +read_file_dfs_43145 read_file_dfs 3 43145 NULL
126934 +cfs_cpt_table_alloc_43159 cfs_cpt_table_alloc 1 43159 NULL
126935 +usb_string_sub_43164 usb_string_sub 0 43164 NULL
126936 +il_dbgfs_power_save_status_read_43165 il_dbgfs_power_save_status_read 3 43165 NULL
126937 +ath6kl_set_assoc_req_ies_43185 ath6kl_set_assoc_req_ies 3 43185 NULL
126938 +ext4_xattr_ibody_get_43200 ext4_xattr_ibody_get 0 43200 NULL
126939 +uio_write_43202 uio_write 3 43202 NULL
126940 +iso_callback_43208 iso_callback 3 43208 NULL
126941 +ath10k_p2p_calc_noa_ie_len_43209 ath10k_p2p_calc_noa_ie_len 0 43209 NULL
126942 +f2fs_acl_from_disk_43210 f2fs_acl_from_disk 2 43210 NULL
126943 +atomic_long_add_return_43217 atomic_long_add_return 1 43217 NULL
126944 +gfs2_direct_IO_43220 gfs2_direct_IO 4 43220 NULL
126945 +batadv_tt_tvlv_unicast_handler_v1_43239 batadv_tt_tvlv_unicast_handler_v1 5 43239 NULL
126946 +vmemmap_alloc_block_43245 vmemmap_alloc_block 1 43245 NULL
126947 +ide_end_rq_43269 ide_end_rq 4 43269 NULL
126948 +evtchn_write_43278 evtchn_write 3 43278 NULL
126949 +filemap_write_and_wait_range_43279 filemap_write_and_wait_range 0 43279 NULL
126950 +mpage_alloc_43299 mpage_alloc 3 43299 NULL
126951 +mmu_set_spte_43327 mmu_set_spte 7-6 43327 NULL
126952 +__ext4_get_inode_loc_43332 __ext4_get_inode_loc 0 43332 NULL
126953 +xenfb_write_43412 xenfb_write 3 43412 NULL
126954 +__alloc_bootmem_low_43423 __alloc_bootmem_low 1 43423 NULL
126955 +usb_alloc_urb_43436 usb_alloc_urb 1 43436 NULL
126956 +ath6kl_wmi_roam_tbl_event_rx_43440 ath6kl_wmi_roam_tbl_event_rx 3 43440 NULL
126957 +usb_string_43443 usb_string 0 43443 NULL nohasharray
126958 +usemap_size_43443 usemap_size 0-1-2 43443 &usb_string_43443
126959 +get_vm_area_size_43444 get_vm_area_size 0 43444 NULL
126960 +fs_path_prepare_for_add_43453 fs_path_prepare_for_add 2 43453 NULL
126961 +nvme_trans_device_id_page_43466 nvme_trans_device_id_page 4 43466 NULL
126962 +tx_tx_data_prepared_read_43497 tx_tx_data_prepared_read 3 43497 NULL
126963 +ieee80211_if_fmt_dot11MeshHWMPnetDiameterTraversalTime_43505 ieee80211_if_fmt_dot11MeshHWMPnetDiameterTraversalTime 3 43505 NULL
126964 +ll_direct_IO_26_43530 ll_direct_IO_26 4 43530 NULL
126965 +dvb_ca_en50221_io_write_43533 dvb_ca_en50221_io_write 3 43533 NULL
126966 +read_events_43534 read_events 3 43534 NULL
126967 +cachefiles_daemon_write_43535 cachefiles_daemon_write 3 43535 NULL
126968 +tx_frag_failed_read_43540 tx_frag_failed_read 3 43540 NULL
126969 +rpc_malloc_43573 rpc_malloc 2 43573 NULL
126970 +lpfc_idiag_drbacc_read_reg_43606 lpfc_idiag_drbacc_read_reg 0-3 43606 NULL
126971 +proc_read_43614 proc_read 3 43614 NULL
126972 +alloc_thread_groups_43625 alloc_thread_groups 2 43625 NULL
126973 +random_write_43656 random_write 3 43656 NULL
126974 +bio_integrity_tag_43658 bio_integrity_tag 3 43658 NULL
126975 +ext4_acl_count_43659 ext4_acl_count 0-1 43659 NULL
126976 +write_file_tx99_power_43670 write_file_tx99_power 3 43670 NULL
126977 +dmam_declare_coherent_memory_43679 dmam_declare_coherent_memory 4 43679 NULL
126978 +max77693_bulk_write_43698 max77693_bulk_write 2-3 43698 NULL
126979 +nvkm_connector_create__43711 nvkm_connector_create_ 6 43711 NULL
126980 +drbd_md_first_sector_43729 drbd_md_first_sector 0 43729 NULL
126981 +snd_rme32_playback_copy_43732 snd_rme32_playback_copy 5 43732 NULL
126982 +fuse_conn_congestion_threshold_write_43736 fuse_conn_congestion_threshold_write 3 43736 NULL
126983 +gigaset_initcs_43753 gigaset_initcs 2 43753 NULL
126984 +sctp_setsockopt_active_key_43755 sctp_setsockopt_active_key 3 43755 NULL
126985 +ocfs2_xattr_get_value_outside_43787 ocfs2_xattr_get_value_outside 0 43787 NULL nohasharray
126986 +byte_pos_43787 byte_pos 0 43787 &ocfs2_xattr_get_value_outside_43787
126987 +btrfs_copy_from_user_43806 btrfs_copy_from_user 0-3-1 43806 NULL
126988 +ieee80211_if_fmt_element_ttl_43825 ieee80211_if_fmt_element_ttl 3 43825 NULL
126989 +ieee80211_alloc_hw_43829 ieee80211_alloc_hw 1 43829 NULL
126990 +read_flush_43851 read_flush 3 43851 NULL
126991 +pm860x_bulk_write_43875 pm860x_bulk_write 2-3 43875 NULL
126992 +ec_dbgfs_cmd_write_43895 ec_dbgfs_cmd_write 3 43895 NULL
126993 +SendString_43928 SendString 3 43928 NULL
126994 +stats_dot11RTSFailureCount_read_43948 stats_dot11RTSFailureCount_read 3 43948 NULL
126995 +__get_required_blob_size_43980 __get_required_blob_size 0-3-2 43980 NULL
126996 +nla_reserve_43984 nla_reserve 3 43984 NULL
126997 +__clkdev_alloc_43990 __clkdev_alloc 1 43990 NULL
126998 +kvm_read_guest_virt_43992 kvm_read_guest_virt 4-2 43992 NULL nohasharray
126999 +bcm_recvmsg_43992 bcm_recvmsg 4 43992 &kvm_read_guest_virt_43992 nohasharray
127000 +scsi_command_size_43992 scsi_command_size 0 43992 &bcm_recvmsg_43992
127001 +emit_flags_44006 emit_flags 4-3 44006 NULL
127002 +write_flush_procfs_44011 write_flush_procfs 3 44011 NULL
127003 +fru_strlen_44046 fru_strlen 0 44046 NULL
127004 +ath9k_def_dump_modal_eeprom_44078 ath9k_def_dump_modal_eeprom 3-2-0 44078 NULL
127005 +SYSC_add_key_44079 SYSC_add_key 4 44079 NULL
127006 +pci_msix_vec_count_44093 pci_msix_vec_count 0 44093 NULL
127007 +xlog_recover_add_to_cont_trans_44102 xlog_recover_add_to_cont_trans 4 44102 NULL
127008 +skb_frag_dma_map_44112 skb_frag_dma_map 0 44112 NULL
127009 +nouveau_clock_create__44116 nouveau_clock_create_ 6 44116 NULL
127010 +tracing_set_trace_read_44122 tracing_set_trace_read 3 44122 NULL
127011 +SyS_process_vm_writev_44129 SyS_process_vm_writev 3-5 44129 NULL
127012 +tracing_resize_saved_cmdlines_44140 tracing_resize_saved_cmdlines 1 44140 NULL
127013 +ttm_get_pages_44142 ttm_get_pages 2 44142 NULL
127014 +scsi_get_resid_44147 scsi_get_resid 0 44147 NULL
127015 +ubifs_find_dirty_idx_leb_44169 ubifs_find_dirty_idx_leb 0 44169 NULL
127016 +ocfs2_xattr_bucket_find_44174 ocfs2_xattr_bucket_find 0 44174 NULL
127017 +SYSC_set_mempolicy_44176 SYSC_set_mempolicy 3 44176 NULL
127018 +handle_eviocgbit_44193 handle_eviocgbit 3 44193 NULL
127019 +btrfs_item_offset_nr_44220 btrfs_item_offset_nr 0 44220 NULL
127020 +srp_alloc_iu_44227 srp_alloc_iu 2 44227 NULL
127021 +scsi_track_queue_full_44239 scsi_track_queue_full 2 44239 NULL
127022 +sigma_action_write_regmap_44240 sigma_action_write_regmap 3 44240 NULL
127023 +ath6kl_keepalive_read_44303 ath6kl_keepalive_read 3 44303 NULL
127024 +bitmap_scnprintf_44318 bitmap_scnprintf 0-2 44318 NULL
127025 +dispatch_proc_write_44320 dispatch_proc_write 3 44320 NULL
127026 +ccp_init_data_44324 ccp_init_data 5 44324 NULL
127027 +rs_init_44327 rs_init 1 44327 NULL
127028 +blk_queue_init_tags_44355 blk_queue_init_tags 2 44355 NULL nohasharray
127029 +nfs_fscache_get_super_cookie_44355 nfs_fscache_get_super_cookie 3 44355 &blk_queue_init_tags_44355
127030 +rts_threshold_read_44384 rts_threshold_read 3 44384 NULL
127031 +mtip_hw_read_flags_44396 mtip_hw_read_flags 3 44396 NULL
127032 +aoedev_flush_44398 aoedev_flush 2 44398 NULL
127033 +drm_buffer_alloc_44405 drm_buffer_alloc 2 44405 NULL
127034 +osst_do_scsi_44410 osst_do_scsi 4 44410 NULL
127035 +ieee80211_if_read_rc_rateidx_mcs_mask_5ghz_44423 ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 NULL
127036 +write_file_debug_44476 write_file_debug 3 44476 NULL
127037 +btrfs_chunk_item_size_44478 btrfs_chunk_item_size 0-1 44478 NULL
127038 +sdio_align_size_44489 sdio_align_size 0-2 44489 NULL
127039 +bio_advance_44496 bio_advance 2 44496 NULL
127040 +ieee80211_if_read_dropped_frames_ttl_44500 ieee80211_if_read_dropped_frames_ttl 3 44500 NULL
127041 +ac_register_board_44504 ac_register_board 3 44504 NULL
127042 +security_getprocattr_44505 security_getprocattr 0 44505 NULL nohasharray
127043 +iwl_dbgfs_sram_read_44505 iwl_dbgfs_sram_read 3 44505 &security_getprocattr_44505
127044 +spidev_write_44510 spidev_write 3 44510 NULL
127045 +SyS_io_getevents_44519 SyS_io_getevents 3 44519 NULL
127046 +ieee80211_rx_mgmt_assoc_resp_44525 ieee80211_rx_mgmt_assoc_resp 3 44525 NULL
127047 +comm_write_44537 comm_write 3 44537 NULL
127048 +dgrp_config_proc_write_44571 dgrp_config_proc_write 3 44571 NULL
127049 +nouveau_perfmon_create__44602 nouveau_perfmon_create_ 4 44602 NULL
127050 +xpcs_mmd_write_44633 xpcs_mmd_write 3 44633 NULL
127051 +alloc_ctrl_packet_44667 alloc_ctrl_packet 1 44667 NULL
127052 +mpi_resize_44674 mpi_resize 2 44674 NULL
127053 +ts_read_44687 ts_read 3 44687 NULL
127054 +lov_emerg_alloc_44698 lov_emerg_alloc 1 44698 NULL
127055 +C_SYSC_select_44701 C_SYSC_select 1 44701 NULL
127056 +__generic_block_fiemap_44713 __generic_block_fiemap 4 44713 NULL nohasharray
127057 +xfer_to_user_44713 xfer_to_user 3 44713 &__generic_block_fiemap_44713
127058 +nft_hash_tbl_size_44724 nft_hash_tbl_size 0 44724 NULL
127059 +_zd_iowrite32v_locked_44725 _zd_iowrite32v_locked 3 44725 NULL
127060 +clusterip_proc_write_44729 clusterip_proc_write 3 44729 NULL
127061 +fib_count_nexthops_44730 fib_count_nexthops 0 44730 NULL
127062 +key_tx_rx_count_read_44742 key_tx_rx_count_read 3 44742 NULL
127063 +bch_bio_max_sectors_44755 bch_bio_max_sectors 0 44755 NULL
127064 +tnode_new_44757 tnode_new 3 44757 NULL nohasharray
127065 +pty_write_44757 pty_write 3 44757 &tnode_new_44757
127066 +__videobuf_copy_stream_44769 __videobuf_copy_stream 4-0 44769 NULL
127067 +handsfree_ramp_44777 handsfree_ramp 2 44777 NULL
127068 +irq_domain_add_legacy_44781 irq_domain_add_legacy 4-2 44781 NULL
127069 +sctp_setsockopt_44788 sctp_setsockopt 5 44788 NULL
127070 +rx_dropped_read_44799 rx_dropped_read 3 44799 NULL
127071 +qla4xxx_alloc_work_44813 qla4xxx_alloc_work 2 44813 NULL
127072 +force_static_address_write_44819 force_static_address_write 3 44819 NULL
127073 +mei_cl_read_start_44824 mei_cl_read_start 2 44824 NULL
127074 +rmap_write_protect_44833 rmap_write_protect 2 44833 NULL
127075 +sisusb_write_44834 sisusb_write 3 44834 NULL
127076 +kvm_read_hva_44847 kvm_read_hva 3 44847 NULL
127077 +qib_verbs_send_dma_44850 qib_verbs_send_dma 6 44850 NULL
127078 +copydesc_user_44855 copydesc_user 3 44855 NULL
127079 +set_advertising_44870 set_advertising 4 44870 NULL
127080 +init_rs_44873 init_rs 1 44873 NULL
127081 +skb_availroom_44883 skb_availroom 0 44883 NULL
127082 +do_tty_write_44896 do_tty_write 5 44896 NULL
127083 +regmap_spi_read_44921 regmap_spi_read 3-5 44921 NULL
127084 +tx_queue_status_read_44978 tx_queue_status_read 3 44978 NULL
127085 +bytepos_delta_45017 bytepos_delta 0 45017 NULL
127086 +ptrace_writedata_45021 ptrace_writedata 4 45021 NULL
127087 +dm_kvzalloc_45025 dm_kvzalloc 1 45025 NULL
127088 +sel_write_user_45060 sel_write_user 3 45060 NULL
127089 +snd_mixart_BA0_read_45069 snd_mixart_BA0_read 5 45069 NULL
127090 +snd_card_new_45104 snd_card_new 5 45104 NULL
127091 +kvm_mmu_page_get_gfn_45110 kvm_mmu_page_get_gfn 0-2 45110 NULL
127092 +pwr_missing_bcns_cnt_read_45113 pwr_missing_bcns_cnt_read 3 45113 NULL
127093 +usbdev_read_45114 usbdev_read 3 45114 NULL
127094 +send_to_tty_45141 send_to_tty 3 45141 NULL
127095 +cfs_trace_daemon_command_usrstr_45147 cfs_trace_daemon_command_usrstr 2 45147 NULL
127096 +gen_bitmask_string_45149 gen_bitmask_string 6 45149 NULL
127097 +device_write_45156 device_write 3 45156 NULL nohasharray
127098 +ocfs2_remove_inode_range_45156 ocfs2_remove_inode_range 3 45156 &device_write_45156
127099 +tomoyo_write_self_45161 tomoyo_write_self 3 45161 NULL
127100 +sta_agg_status_write_45164 sta_agg_status_write 3 45164 NULL
127101 +sctp_pack_cookie_45190 sctp_pack_cookie 6 45190 NULL nohasharray
127102 +snd_sb_csp_load_user_45190 snd_sb_csp_load_user 3 45190 &sctp_pack_cookie_45190
127103 +iso_alloc_urb_45206 iso_alloc_urb 4-5 45206 NULL
127104 +spi_alloc_master_45223 spi_alloc_master 2 45223 NULL
127105 +ieee80211_if_read_peer_45233 ieee80211_if_read_peer 3 45233 NULL
127106 +event_enable_write_45238 event_enable_write 3 45238 NULL
127107 +prism2_pda_proc_read_45246 prism2_pda_proc_read 3 45246 NULL
127108 +input_mt_init_slots_45279 input_mt_init_slots 2 45279 NULL
127109 +gfs2_fiemap_45282 gfs2_fiemap 4 45282 NULL
127110 +snd_pcm_oss_sync1_45298 snd_pcm_oss_sync1 2 45298 NULL
127111 +e1000_tx_map_45309 e1000_tx_map 5 45309 NULL
127112 +copy_vm86_regs_from_user_45340 copy_vm86_regs_from_user 3 45340 NULL
127113 +brcmf_sdio_died_dump_45359 brcmf_sdio_died_dump 3 45359 NULL
127114 +null_alloc_repbuf_45375 null_alloc_repbuf 3 45375 NULL
127115 +count_skb_frag_slots_45395 count_skb_frag_slots 0 45395 NULL
127116 +sock_recv_errqueue_45412 sock_recv_errqueue 3 45412 NULL
127117 +ieee80211_if_fmt_dot11MeshHWMProotInterval_45421 ieee80211_if_fmt_dot11MeshHWMProotInterval 3 45421 NULL
127118 +ll_iocontrol_register_45430 ll_iocontrol_register 2 45430 NULL
127119 +tty_buffer_alloc_45437 tty_buffer_alloc 2 45437 NULL
127120 +blkdev_direct_IO_45440 blkdev_direct_IO 4 45440 NULL
127121 +rds_ib_set_wr_signal_state_45463 rds_ib_set_wr_signal_state 0 45463 NULL
127122 +tracing_read_dyn_info_45468 tracing_read_dyn_info 3 45468 NULL
127123 +rds_message_copy_from_user_45510 rds_message_copy_from_user 3 45510 NULL
127124 +copy_macs_45534 copy_macs 4 45534 NULL
127125 +nla_attr_size_45545 nla_attr_size 0-1 45545 NULL
127126 +v9fs_direct_read_45546 v9fs_direct_read 3 45546 NULL
127127 +cx18_copy_mdl_to_user_45549 cx18_copy_mdl_to_user 4 45549 NULL
127128 +stats_dot11ACKFailureCount_read_45558 stats_dot11ACKFailureCount_read 3 45558 NULL
127129 +_regmap_bus_raw_write_45559 _regmap_bus_raw_write 2 45559 NULL
127130 +posix_acl_xattr_size_45561 posix_acl_xattr_size 0-1 45561 NULL
127131 +venus_rmdir_45564 venus_rmdir 4 45564 NULL
127132 +ath6kl_keepalive_write_45600 ath6kl_keepalive_write 3 45600 NULL
127133 +hidraw_get_report_45609 hidraw_get_report 3 45609 NULL
127134 +compat_mpctl_ioctl_45671 compat_mpctl_ioctl 2 45671 NULL
127135 +dgram_sendmsg_45679 dgram_sendmsg 4 45679 NULL
127136 +smk_write_ambient_45691 smk_write_ambient 3 45691 NULL
127137 +bscnl_emit_45699 bscnl_emit 2-5-0 45699 NULL nohasharray
127138 +unix_dgram_sendmsg_45699 unix_dgram_sendmsg 4 45699 &bscnl_emit_45699
127139 +sg_proc_write_adio_45704 sg_proc_write_adio 3 45704 NULL
127140 +snd_cs46xx_io_read_45734 snd_cs46xx_io_read 5 45734 NULL
127141 +rw_copy_check_uvector_45748 rw_copy_check_uvector 3-0 45748 NULL nohasharray
127142 +v4l2_ctrl_new_std_45748 v4l2_ctrl_new_std 5 45748 &rw_copy_check_uvector_45748
127143 +lkdtm_debugfs_read_45752 lkdtm_debugfs_read 3 45752 NULL
127144 +alloc_ts_config_45775 alloc_ts_config 1 45775 NULL
127145 +osc_checksum_type_seq_write_45785 osc_checksum_type_seq_write 3 45785 NULL
127146 +raw_setsockopt_45800 raw_setsockopt 5 45800 NULL
127147 +rds_tcp_inc_copy_to_user_45804 rds_tcp_inc_copy_to_user 3 45804 NULL
127148 +lbs_rdbbp_read_45805 lbs_rdbbp_read 3 45805 NULL
127149 +pcpu_alloc_alloc_info_45813 pcpu_alloc_alloc_info 1-2 45813 NULL
127150 +ll_max_readahead_mb_seq_write_45815 ll_max_readahead_mb_seq_write 3 45815 NULL
127151 +memcg_update_cache_size_45828 memcg_update_cache_size 2 45828 NULL
127152 +ipv6_recv_rxpmtu_45830 ipv6_recv_rxpmtu 3 45830 NULL
127153 +x509_process_extension_45854 x509_process_extension 5 45854 NULL
127154 +efx_tx_queue_insert_45859 efx_tx_queue_insert 2 45859 NULL
127155 +isdn_write_45863 isdn_write 3 45863 NULL
127156 +get_rdac_req_45882 get_rdac_req 3 45882 NULL
127157 +ocfs2_xattr_block_find_45891 ocfs2_xattr_block_find 0 45891 NULL
127158 +cfs_cpt_weight_45903 cfs_cpt_weight 0 45903 NULL
127159 +wm_adsp_region_to_reg_45915 wm_adsp_region_to_reg 0-2 45915 NULL
127160 +dbgfs_frame_45917 dbgfs_frame 3 45917 NULL
127161 +btree_keys_cachelines_45928 btree_keys_cachelines 0 45928 NULL
127162 +alloc_mr_45935 alloc_mr 1 45935 NULL
127163 +rb_simple_read_45972 rb_simple_read 3 45972 NULL
127164 +ioat2_dca_count_dca_slots_45984 ioat2_dca_count_dca_slots 0 45984 NULL
127165 +sierra_setup_urb_46029 sierra_setup_urb 5 46029 NULL
127166 +fnic_reset_stats_read_46030 fnic_reset_stats_read 3 46030 NULL nohasharray
127167 +get_free_entries_46030 get_free_entries 1 46030 &fnic_reset_stats_read_46030
127168 +__access_remote_vm_46031 __access_remote_vm 0 46031 NULL
127169 +snd_emu10k1x_ptr_read_46049 snd_emu10k1x_ptr_read 0 46049 NULL
127170 +dma_tx_errors_read_46060 dma_tx_errors_read 3 46060 NULL nohasharray
127171 +__ocfs2_move_extent_46060 __ocfs2_move_extent 3-4 46060 &dma_tx_errors_read_46060
127172 +sel_commit_bools_write_46077 sel_commit_bools_write 3 46077 NULL
127173 +memcg_update_array_size_46111 memcg_update_array_size 1 46111 NULL nohasharray
127174 +il3945_ucode_general_stats_read_46111 il3945_ucode_general_stats_read 3 46111 &memcg_update_array_size_46111
127175 +C_SYSC_writev_46113 C_SYSC_writev 3 46113 NULL
127176 +mlx4_ib_alloc_fast_reg_page_list_46119 mlx4_ib_alloc_fast_reg_page_list 2 46119 NULL
127177 +rtw_buf_update_46138 rtw_buf_update 4 46138 NULL
127178 +vb2_dma_sg_get_userptr_46146 vb2_dma_sg_get_userptr 3-2 46146 NULL
127179 +__netlink_change_ngroups_46156 __netlink_change_ngroups 2 46156 NULL
127180 +twl_direction_out_46182 twl_direction_out 2 46182 NULL
127181 +vxge_os_dma_malloc_46184 vxge_os_dma_malloc 2 46184 NULL
127182 +fq_resize_46195 fq_resize 2 46195 NULL
127183 +add_conn_list_46197 add_conn_list 3-0 46197 NULL
127184 +i2400m_op_msg_from_user_46213 i2400m_op_msg_from_user 4 46213 NULL
127185 +tm6000_i2c_recv_regs_46215 tm6000_i2c_recv_regs 5 46215 NULL
127186 +dsp_write_46218 dsp_write 2 46218 NULL
127187 +hash_netiface4_expire_46226 hash_netiface4_expire 4 46226 NULL
127188 +xen_setup_msi_irqs_46245 xen_setup_msi_irqs 2 46245 NULL
127189 +mpi_read_raw_data_46248 mpi_read_raw_data 2 46248 NULL
127190 +sg_proc_write_dressz_46316 sg_proc_write_dressz 3 46316 NULL
127191 +C_SYSC_ppoll_46319 C_SYSC_ppoll 2 46319 NULL
127192 +compat_SyS_readv_46328 compat_SyS_readv 3 46328 NULL nohasharray
127193 +__hwahc_dev_set_key_46328 __hwahc_dev_set_key 5 46328 &compat_SyS_readv_46328
127194 +iwl_dbgfs_chain_noise_read_46355 iwl_dbgfs_chain_noise_read 3 46355 NULL
127195 +smk_write_direct_46363 smk_write_direct 3 46363 NULL
127196 +crypto_ablkcipher_reqsize_46411 crypto_ablkcipher_reqsize 0 46411 NULL
127197 +ttm_page_pool_get_pages_46431 ttm_page_pool_get_pages 0-5 46431 NULL
127198 +cfs_power2_roundup_46433 cfs_power2_roundup 0-1 46433 NULL
127199 +cp210x_set_config_46447 cp210x_set_config 4 46447 NULL
127200 +il_dbgfs_clear_traffic_stats_write_46458 il_dbgfs_clear_traffic_stats_write 3 46458 NULL
127201 +filldir64_46469 filldir64 3 46469 NULL
127202 +fill_in_write_vector_46498 fill_in_write_vector 0 46498 NULL
127203 +pin_code_reply_46510 pin_code_reply 4 46510 NULL
127204 +mthca_alloc_cq_buf_46512 mthca_alloc_cq_buf 3 46512 NULL
127205 +kmsg_read_46514 kmsg_read 3 46514 NULL nohasharray
127206 +nouveau_drm_ioctl_46514 nouveau_drm_ioctl 2 46514 &kmsg_read_46514
127207 +nl80211_send_rx_assoc_46538 nl80211_send_rx_assoc 4 46538 NULL
127208 +__btrfs_free_extent_46573 __btrfs_free_extent 7 46573 NULL
127209 +dn_current_mss_46574 dn_current_mss 0 46574 NULL
127210 +serverworks_create_gatt_pages_46582 serverworks_create_gatt_pages 1 46582 NULL
127211 +snd_compr_write_data_46592 snd_compr_write_data 3 46592 NULL
127212 +il3945_stats_flag_46606 il3945_stats_flag 3-0 46606 NULL
127213 +vscnprintf_46617 vscnprintf 0-2 46617 NULL
127214 +__kfifo_out_r_46623 __kfifo_out_r 0-3 46623 NULL
127215 +request_key_async_with_auxdata_46624 request_key_async_with_auxdata 4 46624 NULL
127216 +vfs_getxattr_alloc_46649 vfs_getxattr_alloc 0 46649 NULL
127217 +e1000_tx_map_46672 e1000_tx_map 4 46672 NULL
127218 +l2cap_create_le_flowctl_pdu_46682 l2cap_create_le_flowctl_pdu 3 46682 NULL
127219 +alloc_data_packet_46698 alloc_data_packet 1 46698 NULL
127220 +__ilog2_u32_46706 __ilog2_u32 0 46706 NULL
127221 +erst_dbg_write_46715 erst_dbg_write 3 46715 NULL
127222 +wl1271_rx_filter_alloc_field_46721 wl1271_rx_filter_alloc_field 5 46721 NULL
127223 +irq_domain_add_simple_46734 irq_domain_add_simple 2 46734 NULL
127224 +read_file_tx99_46741 read_file_tx99 3 46741 NULL
127225 +hest_ghes_dev_register_46766 hest_ghes_dev_register 1 46766 NULL
127226 +int_hw_irq_en_46776 int_hw_irq_en 3 46776 NULL
127227 +xfs_iroot_realloc_46826 xfs_iroot_realloc 2 46826 NULL
127228 +shmem_pwrite_fast_46842 shmem_pwrite_fast 3 46842 NULL
127229 +spi_async_46857 spi_async 0 46857 NULL
127230 +vsnprintf_46863 vsnprintf 0 46863 NULL
127231 +nvme_alloc_queue_46865 nvme_alloc_queue 3 46865 NULL
127232 +qp_memcpy_from_queue_iov_46874 qp_memcpy_from_queue_iov 5-4 46874 NULL
127233 +lov_iocontrol_46876 lov_iocontrol 3 46876 NULL
127234 +ixgbe_dbg_reg_ops_write_46895 ixgbe_dbg_reg_ops_write 3 46895 NULL
127235 +sk_mem_pages_46896 sk_mem_pages 0-1 46896 NULL
127236 +ieee80211_if_fmt_power_mode_46906 ieee80211_if_fmt_power_mode 3 46906 NULL
127237 +wlcore_alloc_hw_46917 wlcore_alloc_hw 1-3 46917 NULL
127238 +fb_write_46924 fb_write 3 46924 NULL
127239 +__sctp_setsockopt_connectx_46949 __sctp_setsockopt_connectx 3 46949 NULL
127240 +qla4xxx_post_aen_work_46953 qla4xxx_post_aen_work 3 46953 NULL
127241 +SYSC_poll_46965 SYSC_poll 2 46965 NULL
127242 +crypto_tfm_alg_alignmask_46971 crypto_tfm_alg_alignmask 0 46971 NULL
127243 +mgmt_pending_add_46976 mgmt_pending_add 5 46976 NULL
127244 +bitmap_file_clear_bit_46990 bitmap_file_clear_bit 2 46990 NULL
127245 +sel_write_bool_46996 sel_write_bool 3 46996 NULL
127246 +blk_rq_map_kern_47004 blk_rq_map_kern 4 47004 NULL
127247 +cx231xx_init_bulk_47024 cx231xx_init_bulk 3-2-4 47024 NULL
127248 +fs_path_len_47060 fs_path_len 0 47060 NULL
127249 +event_trigger_regex_write_47067 event_trigger_regex_write 3 47067 NULL
127250 +pipeline_dec_packet_in_read_47076 pipeline_dec_packet_in_read 3 47076 NULL
127251 +scsi_deactivate_tcq_47086 scsi_deactivate_tcq 2 47086 NULL
127252 +iwl_dump_nic_event_log_47089 iwl_dump_nic_event_log 0 47089 NULL
127253 +ptlrpc_lprocfs_threads_max_seq_write_47104 ptlrpc_lprocfs_threads_max_seq_write 3 47104 NULL
127254 +mousedev_read_47123 mousedev_read 3 47123 NULL
127255 +upcall_msg_size_47141 upcall_msg_size 2 47141 NULL
127256 +acpi_ut_initialize_buffer_47143 acpi_ut_initialize_buffer 2 47143 NULL nohasharray
127257 +ses_recv_diag_47143 ses_recv_diag 4 47143 &acpi_ut_initialize_buffer_47143
127258 +mxms_headerlen_47161 mxms_headerlen 0 47161 NULL
127259 +rs_sta_dbgfs_rate_scale_data_read_47165 rs_sta_dbgfs_rate_scale_data_read 3 47165 NULL
127260 +options_write_47243 options_write 3 47243 NULL
127261 +portcntrs_1_read_47253 portcntrs_1_read 3 47253 NULL
127262 +ablkcipher_next_slow_47274 ablkcipher_next_slow 4-3 47274 NULL
127263 +gfs2_readpages_47285 gfs2_readpages 4 47285 NULL
127264 +vsnprintf_47291 vsnprintf 0 47291 NULL
127265 +tx_internal_desc_overflow_read_47300 tx_internal_desc_overflow_read 3 47300 NULL
127266 +nouveau_fb_create__47316 nouveau_fb_create_ 4 47316 NULL
127267 +ieee80211_if_read_dot11MeshHoldingTimeout_47356 ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 NULL
127268 +avc_get_hash_stats_47359 avc_get_hash_stats 0 47359 NULL
127269 +kvm_arch_create_memslot_47364 kvm_arch_create_memslot 3 47364 NULL nohasharray
127270 +__output_copy_user_47364 __output_copy_user 3 47364 &kvm_arch_create_memslot_47364
127271 +__bio_map_kern_47379 __bio_map_kern 3 47379 NULL
127272 +trace_options_core_read_47390 trace_options_core_read 3 47390 NULL nohasharray
127273 +nv_rd32_47390 nv_rd32 0 47390 &trace_options_core_read_47390
127274 +nametbl_list_47391 nametbl_list 2 47391 NULL
127275 +dgrp_net_write_47392 dgrp_net_write 3 47392 NULL
127276 +pfkey_sendmsg_47394 pfkey_sendmsg 4 47394 NULL
127277 +lbs_wrmac_write_47400 lbs_wrmac_write 3 47400 NULL
127278 +sta_vht_capa_read_47409 sta_vht_capa_read 3 47409 NULL
127279 +crypto_ablkcipher_alignmask_47410 crypto_ablkcipher_alignmask 0 47410 NULL
127280 +lbs_wrrf_write_47418 lbs_wrrf_write 3 47418 NULL
127281 +C_SYSC_set_mempolicy_47466 C_SYSC_set_mempolicy 3 47466 NULL
127282 +lprocfs_fid_write_common_47471 lprocfs_fid_write_common 2 47471 NULL
127283 +nvme_trans_send_fw_cmd_47479 nvme_trans_send_fw_cmd 4 47479 NULL
127284 +newpart_47485 newpart 6-4 47485 NULL
127285 +mcp23s17_read_regs_47491 mcp23s17_read_regs 4 47491 NULL
127286 +core_sys_select_47494 core_sys_select 1 47494 NULL
127287 +as3722_block_write_47503 as3722_block_write 2-3 47503 NULL
127288 +unlink_simple_47506 unlink_simple 3 47506 NULL
127289 +pstore_decompress_47510 pstore_decompress 0 47510 NULL
127290 +ec_i2c_count_response_47518 ec_i2c_count_response 0 47518 NULL
127291 +__proc_lnet_portal_rotor_47529 __proc_lnet_portal_rotor 5 47529 NULL
127292 +process_vm_rw_47533 process_vm_rw 3-5 47533 NULL nohasharray
127293 +vscnprintf_47533 vscnprintf 0-2 47533 &process_vm_rw_47533
127294 +ieee80211_if_fmt_min_discovery_timeout_47539 ieee80211_if_fmt_min_discovery_timeout 3 47539 NULL
127295 +read_ldt_47570 read_ldt 2 47570 NULL
127296 +isku_sysfs_read_last_set_47572 isku_sysfs_read_last_set 6 47572 NULL
127297 +btrfs_stack_header_bytenr_47589 btrfs_stack_header_bytenr 0 47589 NULL
127298 +ext4_kvzalloc_47605 ext4_kvzalloc 1 47605 NULL
127299 +sctp_ssnmap_new_47608 sctp_ssnmap_new 2-1 47608 NULL
127300 +cache_read_pipefs_47615 cache_read_pipefs 3 47615 NULL
127301 +twl4030_clear_set_47624 twl4030_clear_set 4 47624 NULL
127302 +ccp_sha_setkey_47633 ccp_sha_setkey 3 47633 NULL
127303 +get_size_47644 get_size 1-2 47644 NULL
127304 +packet_recvmsg_47700 packet_recvmsg 4 47700 NULL
127305 +save_microcode_47717 save_microcode 3 47717 NULL
127306 +bits_to_user_47733 bits_to_user 2-3 47733 NULL
127307 +carl9170_debugfs_read_47738 carl9170_debugfs_read 3 47738 NULL
127308 +ir_prepare_write_buffer_47747 ir_prepare_write_buffer 3 47747 NULL
127309 +mvumi_alloc_mem_resource_47750 mvumi_alloc_mem_resource 3 47750 NULL
127310 +alloc_sched_domains_47756 alloc_sched_domains 1 47756 NULL
127311 +uwb_ie_dump_hex_47774 uwb_ie_dump_hex 4 47774 NULL
127312 +SyS_setgroups16_47780 SyS_setgroups16 1 47780 NULL
127313 +error_error_numll_frame_cts_start_read_47781 error_error_numll_frame_cts_start_read 3 47781 NULL
127314 +posix_acl_fix_xattr_from_user_47793 posix_acl_fix_xattr_from_user 2 47793 NULL
127315 +lov_packmd_47810 lov_packmd 0 47810 NULL
127316 +tree_mod_log_insert_move_47823 tree_mod_log_insert_move 5 47823 NULL
127317 +pinconf_dbg_config_write_47835 pinconf_dbg_config_write 3 47835 NULL
127318 +KEY_SIZE_47855 KEY_SIZE 0 47855 NULL
127319 +vhci_read_47878 vhci_read 3 47878 NULL
127320 +ubi_wl_put_peb_47886 ubi_wl_put_peb 0 47886 NULL
127321 +keyctl_instantiate_key_common_47889 keyctl_instantiate_key_common 4 47889 NULL
127322 +cfs_percpt_alloc_47918 cfs_percpt_alloc 2 47918 NULL
127323 +comedi_write_47926 comedi_write 3 47926 NULL
127324 +nvme_trans_get_blk_desc_len_47946 nvme_trans_get_blk_desc_len 0-2 47946 NULL
127325 +mempool_resize_47983 mempool_resize 2 47983 NULL nohasharray
127326 +iwl_dbgfs_ucode_tracing_read_47983 iwl_dbgfs_ucode_tracing_read 3 47983 &mempool_resize_47983
127327 +dbg_port_buf_47990 dbg_port_buf 2 47990 NULL
127328 +ib_umad_write_47993 ib_umad_write 3 47993 NULL
127329 +lustre_cfg_len_48002 lustre_cfg_len 0 48002 NULL
127330 +gdm_tty_recv_complete_48011 gdm_tty_recv_complete 2 48011 NULL
127331 +bio_integrity_set_tag_48035 bio_integrity_set_tag 3 48035 NULL
127332 +pppoe_sendmsg_48039 pppoe_sendmsg 4 48039 NULL
127333 +SYSC_writev_48040 SYSC_writev 3 48040 NULL
127334 +wpan_phy_alloc_48056 wpan_phy_alloc 1 48056 NULL
127335 +posix_acl_alloc_48063 posix_acl_alloc 1 48063 NULL
127336 +palmas_bulk_write_48068 palmas_bulk_write 2-3-5 48068 NULL
127337 +disc_write_48070 disc_write 3 48070 NULL
127338 +mmc_alloc_host_48097 mmc_alloc_host 1 48097 NULL
127339 +skb_copy_datagram_const_iovec_48102 skb_copy_datagram_const_iovec 4-2-5 48102 NULL
127340 +wm_latency_write_48125 wm_latency_write 3 48125 NULL
127341 +vmw_framebuffer_surface_dirty_48132 vmw_framebuffer_surface_dirty 6 48132 NULL
127342 +set_discoverable_48141 set_discoverable 4 48141 NULL
127343 +dn_fib_count_nhs_48145 dn_fib_count_nhs 0 48145 NULL
127344 +SyS_vmsplice_48150 SyS_vmsplice 3 48150 NULL
127345 +_add_to_r4w_48152 _add_to_r4w 4 48152 NULL
127346 +isr_dma1_done_read_48159 isr_dma1_done_read 3 48159 NULL
127347 +c4iw_id_table_alloc_48163 c4iw_id_table_alloc 3 48163 NULL
127348 +rbd_obj_method_sync_48170 rbd_obj_method_sync 8 48170 NULL
127349 +alloc_cc770dev_48186 alloc_cc770dev 1 48186 NULL
127350 +cfg80211_process_deauth_48200 cfg80211_process_deauth 3 48200 NULL
127351 +ext4_index_trans_blocks_48205 ext4_index_trans_blocks 0-2 48205 NULL
127352 +snd_seq_dump_var_event_48209 snd_seq_dump_var_event 0 48209 NULL
127353 +uv_blade_nr_possible_cpus_48226 uv_blade_nr_possible_cpus 0 48226 NULL
127354 +nilfs_readpages_48229 nilfs_readpages 4 48229 NULL
127355 +read_file_recv_48232 read_file_recv 3 48232 NULL
127356 +unaccount_shadowed_48233 unaccount_shadowed 2 48233 NULL
127357 +nouveau_i2c_port_create__48240 nouveau_i2c_port_create_ 7 48240 NULL
127358 +nfsctl_transaction_read_48250 nfsctl_transaction_read 3 48250 NULL
127359 +batadv_socket_read_48257 batadv_socket_read 3 48257 NULL
127360 +cache_write_pipefs_48270 cache_write_pipefs 3 48270 NULL
127361 +trace_options_write_48275 trace_options_write 3 48275 NULL
127362 +send_set_info_48288 send_set_info 7 48288 NULL
127363 +lpfc_idiag_extacc_read_48301 lpfc_idiag_extacc_read 3 48301 NULL
127364 +timblogiw_read_48305 timblogiw_read 3 48305 NULL
127365 +hash_setkey_48310 hash_setkey 3 48310 NULL
127366 +skb_add_data_48363 skb_add_data 3 48363 NULL
127367 +tx_frag_init_called_read_48377 tx_frag_init_called_read 3 48377 NULL
127368 +lbs_debugfs_write_48413 lbs_debugfs_write 3 48413 NULL
127369 +uhid_event_from_user_48417 uhid_event_from_user 2 48417 NULL
127370 +div64_u64_rem_48418 div64_u64_rem 0-1-2 48418 NULL
127371 +pwr_tx_without_ps_read_48423 pwr_tx_without_ps_read 3 48423 NULL
127372 +print_filtered_48442 print_filtered 2-0 48442 NULL
127373 +tun_recvmsg_48463 tun_recvmsg 4 48463 NULL
127374 +copy_page_from_iter_iovec_48466 copy_page_from_iter_iovec 3-0 48466 NULL
127375 +compat_SyS_preadv64_48469 compat_SyS_preadv64 3 48469 NULL
127376 +_iwl_dbgfs_bt_tx_prio_write_48473 _iwl_dbgfs_bt_tx_prio_write 3 48473 NULL
127377 +r8712_usbctrl_vendorreq_48489 r8712_usbctrl_vendorreq 6 48489 NULL
127378 +send_control_msg_48498 send_control_msg 6 48498 NULL
127379 +count_masked_bytes_48507 count_masked_bytes 0-1 48507 NULL
127380 +diva_os_copy_to_user_48508 diva_os_copy_to_user 4 48508 NULL
127381 +brcmf_sdio_trap_info_48510 brcmf_sdio_trap_info 4 48510 NULL
127382 +phantom_get_free_48514 phantom_get_free 0 48514 NULL
127383 +drbd_bm_capacity_48530 drbd_bm_capacity 0 48530 NULL
127384 +raid10_size_48571 raid10_size 0-2-3 48571 NULL
127385 +llog_data_len_48607 llog_data_len 1 48607 NULL
127386 +do_ip_vs_set_ctl_48641 do_ip_vs_set_ctl 4 48641 NULL
127387 +kernel_sock_ioctl_48644 kernel_sock_ioctl 0 48644 NULL
127388 +ll_rw_extents_stats_pp_seq_write_48651 ll_rw_extents_stats_pp_seq_write 3 48651 NULL
127389 +mtd_read_48655 mtd_read 0 48655 NULL
127390 +aes_encrypt_packets_read_48666 aes_encrypt_packets_read 3 48666 NULL
127391 +sm501_create_subdev_48668 sm501_create_subdev 3-4 48668 NULL
127392 +ubi_eba_unmap_leb_48671 ubi_eba_unmap_leb 0 48671 NULL
127393 +hysdn_log_write_48694 hysdn_log_write 3 48694 NULL
127394 +altera_drscan_48698 altera_drscan 2 48698 NULL
127395 +kvm_set_irq_routing_48704 kvm_set_irq_routing 3 48704 NULL
127396 +lpfc_idiag_drbacc_write_48712 lpfc_idiag_drbacc_write 3 48712 NULL
127397 +SyS_lgetxattr_48719 SyS_lgetxattr 4 48719 NULL
127398 +ath6kl_usb_bmi_read_48745 ath6kl_usb_bmi_read 3 48745 NULL
127399 +ath6kl_regwrite_read_48747 ath6kl_regwrite_read 3 48747 NULL
127400 +l2cap_segment_sdu_48772 l2cap_segment_sdu 4 48772 NULL
127401 +il3945_sta_dbgfs_stats_table_read_48802 il3945_sta_dbgfs_stats_table_read 3 48802 NULL
127402 +twa_change_queue_depth_48808 twa_change_queue_depth 2 48808 NULL
127403 +atomic_counters_read_48827 atomic_counters_read 3 48827 NULL
127404 +azx_get_position_48841 azx_get_position 0 48841 NULL
127405 +vc_do_resize_48842 vc_do_resize 3-4 48842 NULL
127406 +suspend_dtim_interval_write_48854 suspend_dtim_interval_write 3 48854 NULL
127407 +C_SYSC_pwritev64_48864 C_SYSC_pwritev64 3 48864 NULL nohasharray
127408 +viafb_dvp1_proc_write_48864 viafb_dvp1_proc_write 3 48864 &C_SYSC_pwritev64_48864
127409 +__ffs_ep0_read_events_48868 __ffs_ep0_read_events 3 48868 NULL
127410 +crypto_cipher_ctxsize_48890 crypto_cipher_ctxsize 0 48890 NULL
127411 +joydev_handle_JSIOCSAXMAP_48898 joydev_handle_JSIOCSAXMAP 3 48898 NULL
127412 +xdi_copy_to_user_48900 xdi_copy_to_user 4 48900 NULL
127413 +msg_hdr_sz_48908 msg_hdr_sz 0 48908 NULL
127414 +sep_crypto_dma_48937 sep_crypto_dma 0 48937 NULL
127415 +si5351_write_parameters_48940 si5351_write_parameters 2 48940 NULL
127416 +event_heart_beat_read_48961 event_heart_beat_read 3 48961 NULL
127417 +nand_ecc_test_run_48966 nand_ecc_test_run 1 48966 NULL
127418 +vmci_handle_arr_create_48971 vmci_handle_arr_create 1 48971 NULL
127419 +nilfs_direct_IO_48981 nilfs_direct_IO 4 48981 NULL
127420 +rds_rm_size_48996 rds_rm_size 0-2 48996 NULL
127421 +sel_write_enforce_48998 sel_write_enforce 3 48998 NULL
127422 +null_alloc_rs_49019 null_alloc_rs 2 49019 NULL
127423 +filemap_check_errors_49022 filemap_check_errors 0 49022 NULL
127424 +transient_status_49027 transient_status 4 49027 NULL
127425 +ll_xattr_cache_add_49032 ll_xattr_cache_add 4-0 49032 NULL
127426 +scsi_register_49094 scsi_register 2 49094 NULL
127427 +compat_do_readv_writev_49102 compat_do_readv_writev 4 49102 NULL
127428 +xfrm_replay_state_esn_len_49119 xfrm_replay_state_esn_len 0 49119 NULL
127429 +ll_max_cached_mb_seq_write_49122 ll_max_cached_mb_seq_write 3 49122 NULL
127430 +pt_read_49136 pt_read 3 49136 NULL
127431 +ipwireless_tty_received_49154 ipwireless_tty_received 3 49154 NULL
127432 +f2fs_acl_count_49155 f2fs_acl_count 0-1 49155 NULL
127433 +ipw_queue_tx_init_49161 ipw_queue_tx_init 3 49161 NULL
127434 +__jfs_setxattr_49175 __jfs_setxattr 5 49175 NULL
127435 +ath6kl_bgscan_int_write_49178 ath6kl_bgscan_int_write 3 49178 NULL
127436 +dvb_dvr_ioctl_49182 dvb_dvr_ioctl 2 49182 NULL
127437 +print_queue_49191 print_queue 4-0 49191 NULL
127438 +iwl_dbgfs_ucode_general_stats_read_49199 iwl_dbgfs_ucode_general_stats_read 3 49199 NULL
127439 +il4965_rs_sta_dbgfs_stats_table_read_49206 il4965_rs_sta_dbgfs_stats_table_read 3 49206 NULL
127440 +do_jffs2_getxattr_49210 do_jffs2_getxattr 0 49210 NULL
127441 +nouveau_therm_create__49228 nouveau_therm_create_ 4 49228 NULL
127442 +ieee80211_if_read_rssi_threshold_49260 ieee80211_if_read_rssi_threshold 3 49260 NULL
127443 +isku_sysfs_read_keys_media_49268 isku_sysfs_read_keys_media 6 49268 NULL
127444 +ptlrpc_check_set_49277 ptlrpc_check_set 0 49277 NULL
127445 +rx_filter_beacon_filter_read_49279 rx_filter_beacon_filter_read 3 49279 NULL
127446 +viafb_dfph_proc_write_49288 viafb_dfph_proc_write 3 49288 NULL
127447 +uio_read_49300 uio_read 3 49300 NULL
127448 +isku_sysfs_read_keys_macro_49312 isku_sysfs_read_keys_macro 6 49312 NULL
127449 +SYSC_mincore_49319 SYSC_mincore 1-2 49319 NULL
127450 +fwtty_port_handler_49327 fwtty_port_handler 9 49327 NULL
127451 +srpt_alloc_ioctx_ring_49330 srpt_alloc_ioctx_ring 2-4-3 49330 NULL
127452 +joydev_ioctl_common_49359 joydev_ioctl_common 2 49359 NULL
127453 +iscsi_alloc_session_49390 iscsi_alloc_session 3 49390 NULL
127454 +ext4_ext_index_trans_blocks_49396 ext4_ext_index_trans_blocks 0 49396 NULL
127455 +rx_streaming_always_read_49401 rx_streaming_always_read 3 49401 NULL
127456 +tnode_alloc_49407 tnode_alloc 1 49407 NULL
127457 +samples_to_bytes_49426 samples_to_bytes 0-2 49426 NULL
127458 +compat_do_msg_fill_49440 compat_do_msg_fill 3 49440 NULL
127459 +__hfsplus_getxattr_49460 __hfsplus_getxattr 0 49460 NULL
127460 +agp_3_5_isochronous_node_enable_49465 agp_3_5_isochronous_node_enable 3 49465 NULL
127461 +xfs_iformat_local_49472 xfs_iformat_local 4 49472 NULL
127462 +isr_decrypt_done_read_49490 isr_decrypt_done_read 3 49490 NULL
127463 +iwl_dbgfs_disable_power_off_read_49517 iwl_dbgfs_disable_power_off_read 3 49517 NULL
127464 +SyS_listxattr_49519 SyS_listxattr 3 49519 NULL
127465 +emulator_write_phys_49520 emulator_write_phys 2-4 49520 NULL
127466 +smk_write_access_49561 smk_write_access 3 49561 NULL
127467 +alloc_chunk_49575 alloc_chunk 1 49575 NULL
127468 +sctp_setsockopt_default_send_param_49578 sctp_setsockopt_default_send_param 3 49578 NULL
127469 +tap_write_49595 tap_write 3 49595 NULL
127470 +isr_wakeups_read_49607 isr_wakeups_read 3 49607 NULL
127471 +btrfs_mksubvol_49616 btrfs_mksubvol 3 49616 NULL
127472 +heap_init_49617 heap_init 2 49617 NULL
127473 +smk_write_doi_49621 smk_write_doi 3 49621 NULL
127474 +port_fops_read_49626 port_fops_read 3 49626 NULL
127475 +btrfsic_cmp_log_and_dev_bytenr_49628 btrfsic_cmp_log_and_dev_bytenr 2 49628 NULL
127476 +__swab32p_49657 __swab32p 0 49657 NULL
127477 +aa_simple_write_to_buffer_49683 aa_simple_write_to_buffer 4-3 49683 NULL
127478 +SyS_pwritev_49688 SyS_pwritev 3 49688 NULL
127479 +__copy_from_user_nocheck_49699 __copy_from_user_nocheck 0-3 49699 NULL
127480 +cx2341x_ctrl_new_menu_49700 cx2341x_ctrl_new_menu 3 49700 NULL
127481 +write_pool_49718 write_pool 3 49718 NULL
127482 +kvm_mmu_notifier_invalidate_page_49723 kvm_mmu_notifier_invalidate_page 3 49723 NULL
127483 +sep_create_dcb_dmatables_context_kernel_49728 sep_create_dcb_dmatables_context_kernel 6 49728 NULL
127484 +zd_usb_iowrite16v_49744 zd_usb_iowrite16v 3 49744 NULL
127485 +btrfs_chunk_num_stripes_49751 btrfs_chunk_num_stripes 0 49751 NULL
127486 +fuse_wr_pages_49753 fuse_wr_pages 0-1-2 49753 NULL
127487 +key_conf_keylen_read_49758 key_conf_keylen_read 3 49758 NULL
127488 +fuse_conn_waiting_read_49762 fuse_conn_waiting_read 3 49762 NULL
127489 +ceph_osdc_readpages_49789 ceph_osdc_readpages 0 49789 NULL
127490 +nfs4_acl_new_49806 nfs4_acl_new 1 49806 NULL
127491 +__of_parse_phandle_with_args_49807 __of_parse_phandle_with_args 0 49807 NULL
127492 +ntfs_copy_from_user_iovec_49829 ntfs_copy_from_user_iovec 6-3-0 49829 NULL
127493 +add_uuid_49831 add_uuid 4 49831 NULL
127494 +twl4030_write_49846 twl4030_write 2 49846 NULL
127495 +scsi_dispatch_cmd_entry_49848 scsi_dispatch_cmd_entry 3 49848 NULL
127496 +timeradd_entry_49850 timeradd_entry 3 49850 NULL
127497 +fiemap_count_to_size_49869 fiemap_count_to_size 0-1 49869 NULL
127498 +sctp_setsockopt_bindx_49870 sctp_setsockopt_bindx 3 49870 NULL
127499 +osc_brw_49896 osc_brw 4 49896 NULL
127500 +ieee80211_if_fmt_dtim_count_49987 ieee80211_if_fmt_dtim_count 3 49987 NULL
127501 +drm_buffer_copy_from_user_49990 drm_buffer_copy_from_user 3 49990 NULL
127502 +l2cap_chan_send_49995 l2cap_chan_send 3 49995 NULL
127503 +dn_mss_from_pmtu_50011 dn_mss_from_pmtu 0-2 50011 NULL
127504 +security_context_to_sid_50019 security_context_to_sid 2 50019 NULL
127505 +isdn_read_50021 isdn_read 3 50021 NULL
127506 +mdc_rename_pack_50023 mdc_rename_pack 4-6 50023 NULL
127507 +brcmf_debugfs_chipinfo_read_50033 brcmf_debugfs_chipinfo_read 3 50033 NULL
127508 +ioread8_50049 ioread8 0 50049 NULL
127509 +fuse_conn_max_background_write_50061 fuse_conn_max_background_write 3 50061 NULL
127510 +__kfifo_dma_in_prepare_50081 __kfifo_dma_in_prepare 4 50081 NULL
127511 +libcfs_ioctl_popdata_50087 libcfs_ioctl_popdata 3 50087 NULL
127512 +sock_setsockopt_50088 sock_setsockopt 5 50088 NULL
127513 +altera_swap_dr_50090 altera_swap_dr 2 50090 NULL
127514 +android_set_cntry_50100 android_set_cntry 0 50100 NULL
127515 +read_file_slot_50111 read_file_slot 3 50111 NULL
127516 +rx_streaming_interval_write_50120 rx_streaming_interval_write 3 50120 NULL
127517 +SYSC_preadv_50134 SYSC_preadv 3 50134 NULL
127518 +tx_frag_need_fragmentation_read_50153 tx_frag_need_fragmentation_read 3 50153 NULL
127519 +kmalloc_node_50163 kmalloc_node 1 50163 NULL
127520 +rx_filter_ibss_filter_read_50167 rx_filter_ibss_filter_read 3 50167 NULL
127521 +ahd_probe_stack_size_50168 ahd_probe_stack_size 0 50168 NULL
127522 +odev_update_50169 odev_update 2 50169 NULL
127523 +ieee80211_if_fmt_dot11MeshHWMPRannInterval_50172 ieee80211_if_fmt_dot11MeshHWMPRannInterval 3 50172 NULL nohasharray
127524 +ubi_resize_volume_50172 ubi_resize_volume 2 50172 &ieee80211_if_fmt_dot11MeshHWMPRannInterval_50172
127525 +cfg80211_roamed_bss_50198 cfg80211_roamed_bss 4-6 50198 NULL
127526 +cyttsp4_probe_50201 cyttsp4_probe 4 50201 NULL
127527 +rx_rx_timeout_wa_read_50204 rx_rx_timeout_wa_read 3 50204 NULL
127528 +l2cap_sock_setsockopt_50207 l2cap_sock_setsockopt 5 50207 NULL
127529 +mon_bin_compat_ioctl_50234 mon_bin_compat_ioctl 3 50234 NULL
127530 +sg_kmalloc_50240 sg_kmalloc 1 50240 NULL
127531 +rxrpc_setsockopt_50286 rxrpc_setsockopt 5 50286 NULL
127532 +soc_codec_reg_show_50302 soc_codec_reg_show 0-3 50302 NULL
127533 +SYSC_flistxattr_50307 SYSC_flistxattr 3 50307 NULL
127534 +SYSC_sched_setaffinity_50310 SYSC_sched_setaffinity 2 50310 NULL
127535 +soc_camera_read_50319 soc_camera_read 3 50319 NULL
127536 +do_launder_page_50329 do_launder_page 0 50329 NULL
127537 +nouveau_engine_create__50331 nouveau_engine_create_ 7 50331 NULL
127538 +lpfc_idiag_pcicfg_read_50334 lpfc_idiag_pcicfg_read 3 50334 NULL
127539 +snd_pcm_lib_writev_50337 snd_pcm_lib_writev 0-3 50337 NULL
127540 +tpm_read_50344 tpm_read 3 50344 NULL
127541 +isdn_ppp_read_50356 isdn_ppp_read 4 50356 NULL
127542 +iwl_dbgfs_echo_test_write_50362 iwl_dbgfs_echo_test_write 3 50362 NULL
127543 +xfrm_send_migrate_50365 xfrm_send_migrate 5 50365 NULL
127544 +roccat_common2_receive_50369 roccat_common2_receive 4 50369 NULL
127545 +sl_alloc_bufs_50380 sl_alloc_bufs 2 50380 NULL
127546 +l2tp_ip_sendmsg_50411 l2tp_ip_sendmsg 4 50411 NULL
127547 +iscsi_create_conn_50425 iscsi_create_conn 2 50425 NULL
127548 +validate_acl_mac_addrs_50429 validate_acl_mac_addrs 0 50429 NULL
127549 +btrfs_error_discard_extent_50444 btrfs_error_discard_extent 2 50444 NULL
127550 +pgctrl_write_50453 pgctrl_write 3 50453 NULL
127551 +cfs_size_round_50472 cfs_size_round 0-1 50472 NULL
127552 +cdrom_read_cdda_50478 cdrom_read_cdda 4 50478 NULL
127553 +mei_io_cb_alloc_req_buf_50493 mei_io_cb_alloc_req_buf 2 50493 NULL
127554 +pwr_rcvd_awake_beacons_read_50505 pwr_rcvd_awake_beacons_read 3 50505 NULL
127555 +ath6kl_set_ap_probe_resp_ies_50539 ath6kl_set_ap_probe_resp_ies 3 50539 NULL
127556 +usbat_flash_write_data_50553 usbat_flash_write_data 4 50553 NULL
127557 +self_check_peb_vid_hdr_50563 self_check_peb_vid_hdr 0 50563 NULL
127558 +fat_readpages_50582 fat_readpages 4 50582 NULL
127559 +iwl_dbgfs_missed_beacon_read_50584 iwl_dbgfs_missed_beacon_read 3 50584 NULL
127560 +xillybus_write_50605 xillybus_write 3 50605 NULL
127561 +rx_rx_checksum_result_read_50617 rx_rx_checksum_result_read 3 50617 NULL
127562 +sparse_early_usemaps_alloc_node_50623 sparse_early_usemaps_alloc_node 4 50623 NULL
127563 +simple_transaction_get_50633 simple_transaction_get 3 50633 NULL
127564 +ath6kl_tm_rx_event_50664 ath6kl_tm_rx_event 3 50664 NULL
127565 +bnad_debugfs_read_50665 bnad_debugfs_read 3 50665 NULL
127566 +prism2_read_fid_reg_50689 prism2_read_fid_reg 0 50689 NULL
127567 +xfs_growfs_get_hdr_buf_50697 xfs_growfs_get_hdr_buf 3 50697 NULL
127568 +dev_mem_read_50706 dev_mem_read 3 50706 NULL
127569 +blk_check_plugged_50736 blk_check_plugged 3 50736 NULL
127570 +__ext3_get_inode_loc_50744 __ext3_get_inode_loc 0 50744 NULL
127571 +ocfs2_xattr_block_get_50773 ocfs2_xattr_block_get 0 50773 NULL
127572 +tm6000_read_write_usb_50774 tm6000_read_write_usb 7 50774 NULL
127573 +tpm_write_50798 tpm_write 3 50798 NULL
127574 +tun_do_read_50800 tun_do_read 4 50800 NULL
127575 +write_flush_50803 write_flush 3 50803 NULL
127576 +dvb_play_50814 dvb_play 3 50814 NULL
127577 +btrfs_stack_file_extent_disk_num_bytes_50825 btrfs_stack_file_extent_disk_num_bytes 0 50825 NULL
127578 +dpcm_show_state_50827 dpcm_show_state 0 50827 NULL
127579 +SetArea_50835 SetArea 4 50835 NULL
127580 +nft_trans_alloc_50836 nft_trans_alloc 3 50836 NULL
127581 +videobuf_dma_init_user_50839 videobuf_dma_init_user 4-3 50839 NULL
127582 +self_check_write_50856 self_check_write 0 50856 NULL
127583 +carl9170_debugfs_write_50857 carl9170_debugfs_write 3 50857 NULL
127584 +SyS_lgetxattr_50889 SyS_lgetxattr 4 50889 NULL
127585 +netlbl_secattr_catmap_walk_rng_50894 netlbl_secattr_catmap_walk_rng 0-2 50894 NULL
127586 +__bdev_writeseg_50903 __bdev_writeseg 4 50903 NULL
127587 +xfs_iext_remove_50909 xfs_iext_remove 3 50909 NULL
127588 +blk_rq_cur_sectors_50910 blk_rq_cur_sectors 0 50910 NULL
127589 +hash_recvmsg_50924 hash_recvmsg 4 50924 NULL
127590 +chd_dec_fetch_cdata_50926 chd_dec_fetch_cdata 3 50926 NULL
127591 +show_device_status_50947 show_device_status 0 50947 NULL
127592 +irq_timeout_write_50950 irq_timeout_write 3 50950 NULL
127593 +virtio_cread16_50951 virtio_cread16 0 50951 NULL
127594 +sdio_uart_write_50954 sdio_uart_write 3 50954 NULL
127595 +SyS_setxattr_50957 SyS_setxattr 4 50957 NULL
127596 +iwl_statistics_flag_50981 iwl_statistics_flag 3-0 50981 NULL
127597 +timeout_write_50991 timeout_write 3 50991 NULL
127598 +proc_write_51003 proc_write 3 51003 NULL
127599 +jbd2_journal_extend_51012 jbd2_journal_extend 2 51012 NULL
127600 +lbs_dev_info_51023 lbs_dev_info 3 51023 NULL
127601 +fuse_conn_congestion_threshold_read_51028 fuse_conn_congestion_threshold_read 3 51028 NULL
127602 +BcmGetSectionValEndOffset_51039 BcmGetSectionValEndOffset 0 51039 NULL
127603 +dump_midi_51040 dump_midi 3 51040 NULL
127604 +usb_get_descriptor_51041 usb_get_descriptor 0 51041 NULL
127605 +srpt_alloc_ioctx_51042 srpt_alloc_ioctx 2-3 51042 NULL
127606 +do_arpt_set_ctl_51053 do_arpt_set_ctl 4 51053 NULL
127607 +wusb_prf_64_51065 wusb_prf_64 7 51065 NULL
127608 +jbd2_journal_init_revoke_51088 jbd2_journal_init_revoke 2 51088 NULL
127609 +__ocfs2_find_path_51096 __ocfs2_find_path 0 51096 NULL
127610 +ti_recv_51110 ti_recv 3 51110 NULL
127611 +alloc_rtllib_51136 alloc_rtllib 1 51136 NULL
127612 +simple_xattr_set_51140 simple_xattr_set 4 51140 NULL
127613 +xfs_trans_get_efd_51148 xfs_trans_get_efd 3 51148 NULL
127614 +iwl_dbgfs_bcast_filters_macs_read_51231 iwl_dbgfs_bcast_filters_macs_read 3 51231 NULL
127615 +nf_ct_ext_create_51232 nf_ct_ext_create 3 51232 NULL
127616 +snd_pcm_write_51235 snd_pcm_write 3 51235 NULL
127617 +drm_property_create_51239 drm_property_create 4 51239 NULL
127618 +st_read_51251 st_read 3 51251 NULL
127619 +compat_dccp_setsockopt_51263 compat_dccp_setsockopt 5 51263 NULL
127620 +target_alloc_sgl_51264 target_alloc_sgl 3 51264 NULL
127621 +dvb_audio_write_51275 dvb_audio_write 3 51275 NULL
127622 +ipwireless_network_packet_received_51277 ipwireless_network_packet_received 4 51277 NULL
127623 +pvr2_std_id_to_str_51288 pvr2_std_id_to_str 2 51288 NULL
127624 +bnad_debugfs_read_regrd_51308 bnad_debugfs_read_regrd 3 51308 NULL
127625 +init_map_ipmac_51317 init_map_ipmac 5 51317 NULL
127626 +alloc_hippi_dev_51320 alloc_hippi_dev 1 51320 NULL
127627 +ext2_xattr_get_51327 ext2_xattr_get 0 51327 NULL
127628 +smk_write_ptrace_51333 smk_write_ptrace 3 51333 NULL
127629 +alloc_smp_req_51337 alloc_smp_req 1 51337 NULL
127630 +ipw_get_event_log_len_51341 ipw_get_event_log_len 0 51341 NULL
127631 +ieee80211_if_fmt_estab_plinks_51370 ieee80211_if_fmt_estab_plinks 3 51370 NULL
127632 +radeon_kms_compat_ioctl_51371 radeon_kms_compat_ioctl 2 51371 NULL
127633 +blk_register_region_51424 blk_register_region 1-2 51424 NULL
127634 +mwifiex_rdeeprom_read_51429 mwifiex_rdeeprom_read 3 51429 NULL
127635 +hfsplus_brec_read_51436 hfsplus_brec_read 0 51436 NULL
127636 +ieee80211_if_read_dot11MeshHWMPRootMode_51441 ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 NULL
127637 +print_devstats_dot11ACKFailureCount_51443 print_devstats_dot11ACKFailureCount 3 51443 NULL
127638 +____alloc_ei_netdev_51475 ____alloc_ei_netdev 1 51475 NULL
127639 +xfs_buf_get_uncached_51477 xfs_buf_get_uncached 2 51477 NULL
127640 +kvm_fetch_guest_virt_51493 kvm_fetch_guest_virt 4-2 51493 NULL
127641 +ieee80211_if_write_uapsd_queues_51526 ieee80211_if_write_uapsd_queues 3 51526 NULL
127642 +__alloc_eip_netdev_51549 __alloc_eip_netdev 1 51549 NULL
127643 +batadv_tt_prepare_tvlv_local_data_51568 batadv_tt_prepare_tvlv_local_data 0 51568 NULL
127644 +ixgb_get_eeprom_len_51586 ixgb_get_eeprom_len 0 51586 NULL
127645 +aac_convert_sgraw2_51598 aac_convert_sgraw2 4 51598 NULL
127646 +table_size_to_number_of_entries_51613 table_size_to_number_of_entries 0-1 51613 NULL
127647 +extent_fiemap_51621 extent_fiemap 3 51621 NULL
127648 +sctp_auth_create_key_51641 sctp_auth_create_key 1 51641 NULL
127649 +iscsi_create_session_51647 iscsi_create_session 3 51647 NULL
127650 +ps_upsd_utilization_read_51669 ps_upsd_utilization_read 3 51669 NULL
127651 +sctp_setsockopt_associnfo_51684 sctp_setsockopt_associnfo 3 51684 NULL
127652 +rtw_os_xmit_resource_alloc23a_51693 rtw_os_xmit_resource_alloc23a 3 51693 NULL
127653 +host_mapping_level_51696 host_mapping_level 0 51696 NULL
127654 +sel_write_access_51704 sel_write_access 3 51704 NULL
127655 +tty_cdev_add_51714 tty_cdev_add 2-4 51714 NULL
127656 +v9fs_alloc_rdir_buf_51716 v9fs_alloc_rdir_buf 2 51716 NULL
127657 +drm_compat_ioctl_51717 drm_compat_ioctl 2 51717 NULL
127658 +sg_read_oxfer_51724 sg_read_oxfer 3 51724 NULL
127659 +cm4040_read_51732 cm4040_read 3 51732 NULL
127660 +get_user_pages_fast_51751 get_user_pages_fast 0 51751 NULL
127661 +ifx_spi_insert_flip_string_51752 ifx_spi_insert_flip_string 3 51752 NULL
127662 +if_write_51756 if_write 3 51756 NULL
127663 +ssd1307fb_alloc_array_51788 ssd1307fb_alloc_array 1 51788 NULL
127664 +qib_alloc_devdata_51819 qib_alloc_devdata 2 51819 NULL
127665 +buffer_from_user_51826 buffer_from_user 3 51826 NULL
127666 +ioread32_51847 ioread32 0 51847 NULL nohasharray
127667 +read_file_tgt_tx_stats_51847 read_file_tgt_tx_stats 3 51847 &ioread32_51847
127668 +do_readv_writev_51849 do_readv_writev 4 51849 NULL
127669 +SYSC_sendto_51852 SYSC_sendto 6 51852 NULL
127670 +bm_page_io_async_51858 bm_page_io_async 2 51858 NULL
127671 +pointer_size_read_51863 pointer_size_read 3 51863 NULL
127672 +get_indirect_ea_51869 get_indirect_ea 4 51869 NULL
127673 +user_read_51881 user_read 3 51881 NULL
127674 +dbAdjCtl_51888 dbAdjCtl 0 51888 NULL
127675 +SyS_mq_timedsend_51896 SyS_mq_timedsend 3 51896 NULL
127676 +wmi_set_ie_51919 wmi_set_ie 3 51919 NULL
127677 +dbg_status_buf_51930 dbg_status_buf 2 51930 NULL
127678 +__tcp_mtu_to_mss_51938 __tcp_mtu_to_mss 0-2 51938 NULL
127679 +xfrm_alg_len_51940 xfrm_alg_len 0 51940 NULL
127680 +scsi_get_vpd_page_51951 scsi_get_vpd_page 4 51951 NULL
127681 +snd_mask_min_51969 snd_mask_min 0 51969 NULL
127682 +get_zone_51981 get_zone 0-1 51981 NULL
127683 +ath6kl_sdio_alloc_prep_scat_req_51986 ath6kl_sdio_alloc_prep_scat_req 2 51986 NULL
127684 +dwc3_mode_write_51997 dwc3_mode_write 3 51997 NULL
127685 +skb_copy_datagram_from_iovec_52014 skb_copy_datagram_from_iovec 4-2-5 52014 NULL
127686 +rdmalt_52022 rdmalt 0 52022 NULL
127687 +override_release_52032 override_release 2 52032 NULL
127688 +end_port_52042 end_port 0 52042 NULL
127689 +dma_rx_errors_read_52045 dma_rx_errors_read 3 52045 NULL
127690 +msnd_fifo_write_52052 msnd_fifo_write 0-3 52052 NULL
127691 +dvb_ringbuffer_avail_52057 dvb_ringbuffer_avail 0 52057 NULL
127692 +__fuse_request_alloc_52060 __fuse_request_alloc 1 52060 NULL
127693 +isofs_readpages_52067 isofs_readpages 4 52067 NULL
127694 +mxuport_process_read_urb_data_52072 mxuport_process_read_urb_data 3 52072 NULL
127695 +nsm_get_handle_52089 nsm_get_handle 4 52089 NULL
127696 +o2net_debug_read_52105 o2net_debug_read 3 52105 NULL
127697 +split_scan_timeout_write_52128 split_scan_timeout_write 3 52128 NULL
127698 +retry_count_read_52129 retry_count_read 3 52129 NULL
127699 +gdm_usb_hci_send_52138 gdm_usb_hci_send 3 52138 NULL
127700 +sub_alloc_52140 sub_alloc 0 52140 NULL
127701 +hysdn_conf_write_52145 hysdn_conf_write 3 52145 NULL
127702 +htable_size_52148 htable_size 0-1 52148 NULL
127703 +smk_write_load2_52155 smk_write_load2 3 52155 NULL
127704 +ieee80211_if_read_dot11MeshRetryTimeout_52168 ieee80211_if_read_dot11MeshRetryTimeout 3 52168 NULL
127705 +mga_compat_ioctl_52170 mga_compat_ioctl 2 52170 NULL
127706 +print_prefix_52176 print_prefix 0 52176 NULL
127707 +proc_pid_readlink_52186 proc_pid_readlink 3 52186 NULL
127708 +reiserfs_posix_acl_from_disk_52191 reiserfs_posix_acl_from_disk 2 52191 NULL
127709 +f2fs_seek_block_52194 f2fs_seek_block 2 52194 NULL
127710 +vmci_qp_broker_alloc_52216 vmci_qp_broker_alloc 6-5 52216 NULL
127711 +fuse_request_alloc_52243 fuse_request_alloc 1 52243 NULL
127712 +mdiobus_alloc_size_52259 mdiobus_alloc_size 1 52259 NULL
127713 +shrink_slab_52261 shrink_slab 2 52261 NULL
127714 +ext2_direct_IO_52270 ext2_direct_IO 4 52270 NULL
127715 +sisusbcon_do_font_op_52271 sisusbcon_do_font_op 9 52271 NULL
127716 +read_file_reset_52310 read_file_reset 3 52310 NULL
127717 +ssd1307fb_write_52315 ssd1307fb_write 3 52315 NULL
127718 +request_asymmetric_key_52317 request_asymmetric_key 2-4 52317 NULL
127719 +hwflags_read_52318 hwflags_read 3 52318 NULL
127720 +test_unaligned_bulk_52333 test_unaligned_bulk 3 52333 NULL
127721 +hur_len_52339 hur_len 0 52339 NULL
127722 +bytes_to_frames_52362 bytes_to_frames 0-2 52362 NULL
127723 +copy_entries_to_user_52367 copy_entries_to_user 1 52367 NULL
127724 +iwl_dump_fh_52371 iwl_dump_fh 0 52371 NULL
127725 +hfsplus_find_attr_52374 hfsplus_find_attr 0 52374 NULL
127726 +mq_emit_config_values_52378 mq_emit_config_values 3 52378 NULL
127727 +isdn_writebuf_stub_52383 isdn_writebuf_stub 4 52383 NULL
127728 +jfs_setxattr_52389 jfs_setxattr 4 52389 NULL
127729 +aer_inject_write_52399 aer_inject_write 3 52399 NULL
127730 +line6_midibuf_init_52425 line6_midibuf_init 2 52425 NULL
127731 +hso_serial_common_create_52428 hso_serial_common_create 4 52428 NULL
127732 +delay_status_52431 delay_status 5 52431 NULL
127733 +ath6kl_delete_qos_write_52435 ath6kl_delete_qos_write 3 52435 NULL
127734 +ieee80211_if_fmt_num_sta_ps_52438 ieee80211_if_fmt_num_sta_ps 3 52438 NULL
127735 +alauda_read_data_52452 alauda_read_data 3 52452 NULL
127736 +bt_alloc_52457 bt_alloc 2 52457 NULL
127737 +ieee80211_alloc_txb_52477 ieee80211_alloc_txb 1 52477 NULL
127738 +usb_tranzport_write_52479 usb_tranzport_write 3 52479 NULL
127739 +ocfs2_extend_no_holes_52483 ocfs2_extend_no_holes 3-4 52483 NULL
127740 +fd_do_rw_52495 fd_do_rw 3 52495 NULL
127741 +int_tasklet_entry_52500 int_tasklet_entry 3 52500 NULL
127742 +lmv_get_easize_52504 lmv_get_easize 0 52504 NULL
127743 +pm_qos_power_write_52513 pm_qos_power_write 3 52513 NULL
127744 +bt_sock_stream_recvmsg_52518 bt_sock_stream_recvmsg 4 52518 NULL
127745 +dup_variable_bug_52525 dup_variable_bug 3 52525 NULL
127746 +raw_recvmsg_52529 raw_recvmsg 4 52529 NULL
127747 +SyS_vmsplice_52540 SyS_vmsplice 3 52540 NULL
127748 +dccpprobe_read_52549 dccpprobe_read 3 52549 NULL
127749 +debug_level_proc_write_52572 debug_level_proc_write 3 52572 NULL
127750 +isku_sysfs_read_macro_52587 isku_sysfs_read_macro 6 52587 NULL
127751 +SyS_setsockopt_52610 SyS_setsockopt 5 52610 NULL
127752 +ll_sa_entry_alloc_52611 ll_sa_entry_alloc 4 52611 NULL
127753 +tps80031_writes_52638 tps80031_writes 3-4 52638 NULL
127754 +brcmf_sdio_assert_info_52653 brcmf_sdio_assert_info 4 52653 NULL
127755 +nvme_queue_extra_52661 nvme_queue_extra 0-1 52661 NULL
127756 +SYSC_gethostname_52677 SYSC_gethostname 2 52677 NULL
127757 +nvd0_disp_pioc_create__52693 nvd0_disp_pioc_create_ 5 52693 NULL
127758 +nouveau_client_create__52715 nouveau_client_create_ 5 52715 NULL
127759 +__dm_stat_bio_52722 __dm_stat_bio 3 52722 NULL
127760 +cx25840_ir_rx_read_52724 cx25840_ir_rx_read 3 52724 NULL
127761 +blkcipher_next_slow_52733 blkcipher_next_slow 3-4 52733 NULL
127762 +relay_alloc_page_array_52735 relay_alloc_page_array 1 52735 NULL
127763 +carl9170_debugfs_vif_dump_read_52755 carl9170_debugfs_vif_dump_read 3 52755 NULL
127764 +ieee80211_if_read_beacon_timeout_52756 ieee80211_if_read_beacon_timeout 3 52756 NULL
127765 +nvme_trans_ext_inq_page_52776 nvme_trans_ext_inq_page 3 52776 NULL
127766 +pwr_rcvd_beacons_read_52836 pwr_rcvd_beacons_read 3 52836 NULL
127767 +lb_alloc_ep_req_52837 lb_alloc_ep_req 2 52837 NULL
127768 +mon_bin_get_event_52863 mon_bin_get_event 4-6 52863 NULL
127769 +twl6030_gpadc_write_52867 twl6030_gpadc_write 1 52867 NULL
127770 +twlreg_write_52880 twlreg_write 3 52880 NULL
127771 +pvr2_ctrl_value_to_sym_internal_52881 pvr2_ctrl_value_to_sym_internal 5 52881 NULL
127772 +cache_read_procfs_52882 cache_read_procfs 3 52882 NULL
127773 +kvm_kvzalloc_52894 kvm_kvzalloc 1 52894 NULL
127774 +dio_bio_reap_52913 dio_bio_reap 0 52913 NULL
127775 +__kfifo_out_peek_r_52919 __kfifo_out_peek_r 3 52919 NULL
127776 +iblock_get_bio_52936 iblock_get_bio 3 52936 NULL
127777 +ieee80211_if_fmt_fwded_mcast_52961 ieee80211_if_fmt_fwded_mcast 3 52961 NULL
127778 +tx_tx_exch_read_52986 tx_tx_exch_read 3 52986 NULL
127779 +num_node_state_52989 num_node_state 0 52989 NULL
127780 +btrfs_free_and_pin_reserved_extent_53016 btrfs_free_and_pin_reserved_extent 2 53016 NULL
127781 +tx_tx_exch_pending_read_53018 tx_tx_exch_pending_read 3 53018 NULL
127782 +bio_cur_bytes_53037 bio_cur_bytes 0 53037 NULL
127783 +regcache_lzo_block_count_53056 regcache_lzo_block_count 0 53056 NULL
127784 +cfi_read_query_53066 cfi_read_query 0 53066 NULL
127785 +iwl_dbgfs_interrupt_write_53069 iwl_dbgfs_interrupt_write 3 53069 NULL
127786 +mwifiex_debug_read_53074 mwifiex_debug_read 3 53074 NULL
127787 +mic_virtio_copy_from_user_53107 mic_virtio_copy_from_user 3 53107 NULL
127788 +verity_status_53120 verity_status 5 53120 NULL
127789 +brcmf_usb_dl_cmd_53130 brcmf_usb_dl_cmd 4 53130 NULL
127790 +ps_poll_ps_poll_max_ap_turn_read_53140 ps_poll_ps_poll_max_ap_turn_read 3 53140 NULL
127791 +ieee80211_bss_info_update_53170 ieee80211_bss_info_update 4 53170 NULL
127792 +btrfs_io_bio_alloc_53179 btrfs_io_bio_alloc 2 53179 NULL
127793 +clear_capture_buf_53192 clear_capture_buf 2 53192 NULL
127794 +tx_tx_start_data_read_53219 tx_tx_start_data_read 3 53219 NULL
127795 +ptlrpc_lprocfs_req_history_max_seq_write_53243 ptlrpc_lprocfs_req_history_max_seq_write 3 53243 NULL
127796 +xfs_trans_read_buf_map_53258 xfs_trans_read_buf_map 5 53258 NULL
127797 +wil_write_file_ssid_53266 wil_write_file_ssid 3 53266 NULL
127798 +btrfs_file_extent_num_bytes_53269 btrfs_file_extent_num_bytes 0 53269 NULL
127799 +f2fs_fiemap_53310 f2fs_fiemap 4 53310 NULL
127800 +ftrace_profile_write_53327 ftrace_profile_write 3 53327 NULL
127801 +find_nr_power_limit_53330 find_nr_power_limit 0 53330 NULL
127802 +gsm_control_reply_53333 gsm_control_reply 4 53333 NULL
127803 +btree_keys_bytes_53348 btree_keys_bytes 0 53348 NULL
127804 +sock_setbindtodevice_53369 sock_setbindtodevice 3 53369 NULL
127805 +get_random_bytes_arch_53370 get_random_bytes_arch 2 53370 NULL
127806 +isr_cmd_cmplt_read_53439 isr_cmd_cmplt_read 3 53439 NULL
127807 +mwifiex_info_read_53447 mwifiex_info_read 3 53447 NULL
127808 +apei_exec_run_optional_53452 apei_exec_run_optional 0 53452 NULL
127809 +paging64_prefetch_gpte_53468 paging64_prefetch_gpte 4 53468 NULL
127810 +ima_write_template_field_data_53475 ima_write_template_field_data 2 53475 NULL nohasharray
127811 +create_trace_kprobe_53475 create_trace_kprobe 1 53475 &ima_write_template_field_data_53475
127812 +iowarrior_read_53483 iowarrior_read 3 53483 NULL
127813 +osd_req_write_kern_53486 osd_req_write_kern 5 53486 NULL
127814 +do_verify_xattr_datum_53499 do_verify_xattr_datum 0 53499 NULL
127815 +snd_pcm_format_physical_width_53505 snd_pcm_format_physical_width 0 53505 NULL
127816 +dbAllocNext_53506 dbAllocNext 0 53506 NULL
127817 +check_acl_53512 check_acl 0 53512 NULL nohasharray
127818 +force_sc_support_write_53512 force_sc_support_write 3 53512 &check_acl_53512
127819 +nft_data_dump_53549 nft_data_dump 5 53549 NULL
127820 +SYSC_bind_53582 SYSC_bind 3 53582 NULL
127821 +cifs_utf16_bytes_53593 cifs_utf16_bytes 0 53593 NULL
127822 +proc_uid_map_write_53596 proc_uid_map_write 3 53596 NULL
127823 +pfkey_recvmsg_53604 pfkey_recvmsg 4 53604 NULL
127824 +___alloc_bootmem_nopanic_53626 ___alloc_bootmem_nopanic 1 53626 NULL
127825 +ccid_getsockopt_builtin_ccids_53634 ccid_getsockopt_builtin_ccids 2 53634 NULL
127826 +nr_sendmsg_53656 nr_sendmsg 4 53656 NULL
127827 +fuse_fill_write_pages_53682 fuse_fill_write_pages 0-4 53682 NULL
127828 +v4l2_event_subscribe_53687 v4l2_event_subscribe 3 53687 NULL
127829 +bdev_logical_block_size_53690 bdev_logical_block_size 0 53690 NULL nohasharray
127830 +igb_alloc_q_vector_53690 igb_alloc_q_vector 4-6 53690 &bdev_logical_block_size_53690
127831 +find_overflow_devnum_53711 find_overflow_devnum 0 53711 NULL
127832 +__proc_debug_mb_53732 __proc_debug_mb 5 53732 NULL
127833 +wdm_write_53735 wdm_write 3 53735 NULL
127834 +lpfc_idiag_queacc_read_qe_53755 lpfc_idiag_queacc_read_qe 0-2 53755 NULL
127835 +wa_populate_buf_in_urb_53758 wa_populate_buf_in_urb 3-4 53758 NULL
127836 +ext2_acl_count_53773 ext2_acl_count 0-1 53773 NULL
127837 +__kfifo_dma_in_prepare_r_53792 __kfifo_dma_in_prepare_r 4-5 53792 NULL
127838 +qp_alloc_host_work_53798 qp_alloc_host_work 5-3 53798 NULL
127839 +regmap_raw_write_53803 regmap_raw_write 2-4 53803 NULL
127840 +lpfc_idiag_ctlacc_read_reg_53809 lpfc_idiag_ctlacc_read_reg 0-3 53809 NULL
127841 +nls_nullsize_53815 nls_nullsize 0 53815 NULL
127842 +setup_data_read_53822 setup_data_read 3 53822 NULL
127843 +btrfs_free_reserved_extent_53873 btrfs_free_reserved_extent 2 53873 NULL nohasharray
127844 +pms_read_53873 pms_read 3 53873 &btrfs_free_reserved_extent_53873
127845 +ieee80211_if_fmt_dropped_frames_congestion_53883 ieee80211_if_fmt_dropped_frames_congestion 3 53883 NULL
127846 +SyS_setgroups_53900 SyS_setgroups 1 53900 NULL
127847 +batadv_tt_tvlv_ogm_handler_v1_53909 batadv_tt_tvlv_ogm_handler_v1 5 53909 NULL
127848 +azx_via_get_position_53916 azx_via_get_position 0 53916 NULL
127849 +usb_serial_generic_write_53927 usb_serial_generic_write 4 53927 NULL
127850 +idetape_chrdev_write_53976 idetape_chrdev_write 3 53976 NULL
127851 +__ocfs2_xattr_set_value_outside_53981 __ocfs2_xattr_set_value_outside 5 53981 NULL
127852 +ieee80211_if_fmt_dot11MeshHWMPperrMinInterval_53998 ieee80211_if_fmt_dot11MeshHWMPperrMinInterval 3 53998 NULL
127853 +hfsplus_attr_build_key_54013 hfsplus_attr_build_key 0 54013 NULL
127854 +snd_pcm_lib_write_transfer_54018 snd_pcm_lib_write_transfer 5-2-4 54018 NULL
127855 +mdc_kuc_write_54019 mdc_kuc_write 3 54019 NULL
127856 +ipxrtr_route_packet_54036 ipxrtr_route_packet 4 54036 NULL
127857 +batadv_tt_update_orig_54049 batadv_tt_update_orig 6-4 54049 NULL
127858 +pipeline_dec_packet_out_read_54052 pipeline_dec_packet_out_read 3 54052 NULL
127859 +nl80211_send_disconnected_54056 nl80211_send_disconnected 5 54056 NULL
127860 +rproc_state_read_54057 rproc_state_read 3 54057 NULL
127861 +altera_set_ir_pre_54103 altera_set_ir_pre 2 54103 NULL nohasharray
127862 +lustre_posix_acl_xattr_filter_54103 lustre_posix_acl_xattr_filter 2 54103 &altera_set_ir_pre_54103
127863 +strn_len_54122 strn_len 0 54122 NULL
127864 +isku_receive_54130 isku_receive 4 54130 NULL
127865 +isr_host_acknowledges_read_54136 isr_host_acknowledges_read 3 54136 NULL
127866 +irq_blk_threshold_write_54138 irq_blk_threshold_write 3 54138 NULL
127867 +memcpy_toiovec_54166 memcpy_toiovec 3 54166 NULL
127868 +nouveau_falcon_create__54169 nouveau_falcon_create_ 8 54169 NULL
127869 +p9_client_prepare_req_54175 p9_client_prepare_req 3 54175 NULL
127870 +do_sys_poll_54221 do_sys_poll 2 54221 NULL
127871 +__register_chrdev_54223 __register_chrdev 2-3 54223 NULL
127872 +pi_read_regr_54231 pi_read_regr 0 54231 NULL
127873 +mcp23s08_read_regs_54246 mcp23s08_read_regs 4 54246 NULL
127874 +reada_add_block_54247 reada_add_block 2 54247 NULL
127875 +xfs_dir2_sf_addname_hard_54254 xfs_dir2_sf_addname_hard 3 54254 NULL
127876 +ceph_msgpool_get_54258 ceph_msgpool_get 2 54258 NULL
127877 +audio_write_54261 audio_write 4 54261 NULL nohasharray
127878 +wusb_prf_54261 wusb_prf 7 54261 &audio_write_54261
127879 +mwifiex_getlog_read_54269 mwifiex_getlog_read 3 54269 NULL
127880 +kstrtou16_from_user_54274 kstrtou16_from_user 2 54274 NULL
127881 +sizeof_long_54276 sizeof_long 0 54276 NULL
127882 +altera_set_dr_post_54291 altera_set_dr_post 2 54291 NULL
127883 +dlm_alloc_pagevec_54296 dlm_alloc_pagevec 1 54296 NULL
127884 +reclaim_pages_54301 reclaim_pages 3 54301 NULL
127885 +sprintf_54306 sprintf 0 54306 NULL
127886 +bio_add_pc_page_54319 bio_add_pc_page 4 54319 NULL
127887 +br_fdb_fillbuf_54339 br_fdb_fillbuf 0 54339 NULL
127888 +__alloc_dev_table_54343 __alloc_dev_table 2 54343 NULL
127889 +__get_free_pages_54352 __get_free_pages 0 54352 NULL
127890 +readlink_copy_54366 readlink_copy 2 54366 NULL
127891 +read_file_credit_dist_stats_54367 read_file_credit_dist_stats 3 54367 NULL
127892 +do_dccp_setsockopt_54377 do_dccp_setsockopt 5 54377 NULL nohasharray
127893 +intel_sdvo_write_cmd_54377 intel_sdvo_write_cmd 4 54377 &do_dccp_setsockopt_54377
127894 +ah_alloc_tmp_54378 ah_alloc_tmp 3-2 54378 NULL
127895 +snd_pcm_oss_read2_54387 snd_pcm_oss_read2 0-3 54387 NULL
127896 +iwl_dbgfs_power_save_status_read_54392 iwl_dbgfs_power_save_status_read 3 54392 NULL
127897 +ll_ra_count_get_54410 ll_ra_count_get 3 54410 NULL
127898 +copy_gadget_strings_54417 copy_gadget_strings 2-3 54417 NULL
127899 +sparse_early_mem_maps_alloc_node_54485 sparse_early_mem_maps_alloc_node 4 54485 NULL
127900 +simple_strtoull_54493 simple_strtoull 0 54493 NULL
127901 +btrfs_ordered_sum_size_54509 btrfs_ordered_sum_size 0-2 54509 NULL
127902 +rfc4106_set_key_54519 rfc4106_set_key 3 54519 NULL
127903 +vmci_transport_dgram_enqueue_54525 vmci_transport_dgram_enqueue 4 54525 NULL
127904 +viacam_read_54526 viacam_read 3 54526 NULL
127905 +unix_dgram_connect_54535 unix_dgram_connect 3 54535 NULL
127906 +setsockopt_54539 setsockopt 5 54539 NULL
127907 +lbs_lowsnr_write_54549 lbs_lowsnr_write 3 54549 NULL
127908 +SYSC_setsockopt_54561 SYSC_setsockopt 5 54561 NULL
127909 +nfsd_vfs_write_54577 nfsd_vfs_write 6 54577 NULL
127910 +fw_iso_buffer_init_54582 fw_iso_buffer_init 3 54582 NULL
127911 +nvme_npages_54601 nvme_npages 0-1 54601 NULL
127912 +irq_pkt_threshold_write_54605 irq_pkt_threshold_write 3 54605 NULL
127913 +port_fops_write_54627 port_fops_write 3 54627 NULL
127914 +tipc_send_stream_54648 tipc_send_stream 4 54648 NULL
127915 +irq_timeout_read_54653 irq_timeout_read 3 54653 NULL
127916 +dns_resolver_read_54658 dns_resolver_read 3 54658 NULL
127917 +twl6030_interrupt_mask_54659 twl6030_interrupt_mask 2 54659 NULL
127918 +tdp_page_fault_54663 tdp_page_fault 2 54663 NULL
127919 +cw1200_queue_stats_init_54670 cw1200_queue_stats_init 2 54670 NULL
127920 +bio_kmalloc_54672 bio_kmalloc 2 54672 NULL
127921 +evm_read_key_54674 evm_read_key 3 54674 NULL
127922 +jfs_direct_IO_54687 jfs_direct_IO 4 54687 NULL
127923 +rfkill_fop_read_54711 rfkill_fop_read 3 54711 NULL
127924 +ocfs2_control_write_54737 ocfs2_control_write 3 54737 NULL
127925 +kzalloc_54740 kzalloc 1 54740 NULL
127926 +wep_iv_read_54744 wep_iv_read 3 54744 NULL
127927 +lpfc_idiag_pcicfg_write_54749 lpfc_idiag_pcicfg_write 3 54749 NULL
127928 +crystalhd_user_data_54754 crystalhd_user_data 3 54754 NULL
127929 +iio_event_chrdev_read_54757 iio_event_chrdev_read 3 54757 NULL
127930 +adis16480_show_firmware_date_54762 adis16480_show_firmware_date 3 54762 NULL
127931 +ldsem_atomic_update_54774 ldsem_atomic_update 1 54774 NULL
127932 +flexcop_device_kmalloc_54793 flexcop_device_kmalloc 1 54793 NULL
127933 +nfsd_write_54809 nfsd_write 6 54809 NULL
127934 +ar9287_dump_modal_eeprom_54814 ar9287_dump_modal_eeprom 3-2 54814 NULL
127935 +crypto_tfm_ctx_alignment_54815 crypto_tfm_ctx_alignment 0 54815 NULL nohasharray
127936 +aes_decrypt_fail_read_54815 aes_decrypt_fail_read 3 54815 &crypto_tfm_ctx_alignment_54815 nohasharray
127937 +kvzalloc_54815 kvzalloc 1 54815 &aes_decrypt_fail_read_54815
127938 +generic_perform_write_54832 generic_perform_write 3 54832 NULL
127939 +write_rio_54837 write_rio 3 54837 NULL
127940 +ext3_acl_from_disk_54839 ext3_acl_from_disk 2 54839 NULL nohasharray
127941 +nouveau_engctx_create__54839 nouveau_engctx_create_ 8 54839 &ext3_acl_from_disk_54839
127942 +ufx_ops_write_54848 ufx_ops_write 3 54848 NULL
127943 +printer_read_54851 printer_read 3 54851 NULL
127944 +broadsheet_spiflash_rewrite_sector_54864 broadsheet_spiflash_rewrite_sector 2 54864 NULL
127945 +prism_build_supp_rates_54865 prism_build_supp_rates 0 54865 NULL
127946 +iscsi_pool_init_54913 iscsi_pool_init 2-4 54913 NULL
127947 +btrfs_stack_chunk_num_stripes_54923 btrfs_stack_chunk_num_stripes 0 54923 NULL
127948 +bio_add_page_54933 bio_add_page 0-3 54933 NULL
127949 +mxms_structlen_54939 mxms_structlen 0 54939 NULL
127950 +add_port_54941 add_port 2 54941 NULL
127951 +tipc_send2name_54946 tipc_send2name 5 54946 NULL
127952 +ath9k_dump_btcoex_54949 ath9k_dump_btcoex 3-0 54949 NULL
127953 +alauda_write_data_54967 alauda_write_data 3 54967 NULL
127954 +c4_add_card_54968 c4_add_card 3 54968 NULL
127955 +ext3_xattr_get_54989 ext3_xattr_get 0 54989 NULL
127956 +cx231xx_v4l2_read_55014 cx231xx_v4l2_read 3 55014 NULL
127957 +error_error_null_Frame_tx_start_read_55024 error_error_null_Frame_tx_start_read 3 55024 NULL
127958 +efw_transaction_55052 efw_transaction 5-7 55052 NULL
127959 +apei_exec_run_55075 apei_exec_run 0 55075 NULL
127960 +bitmap_storage_alloc_55077 bitmap_storage_alloc 2 55077 NULL
127961 +rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read_55106 rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 NULL
127962 +crypto_ahash_setkey_55134 crypto_ahash_setkey 3 55134 NULL
127963 +filldir_55137 filldir 3 55137 NULL
127964 +ocfs2_truncate_file_55148 ocfs2_truncate_file 3 55148 NULL
127965 +npages_to_npools_55149 npages_to_npools 0-1 55149 NULL
127966 +ieee80211_if_read_uapsd_queues_55150 ieee80211_if_read_uapsd_queues 3 55150 NULL
127967 +sel_write_relabel_55195 sel_write_relabel 3 55195 NULL
127968 +compat_SyS_ppoll_55196 compat_SyS_ppoll 2 55196 NULL
127969 +sched_feat_write_55202 sched_feat_write 3 55202 NULL
127970 +ht40allow_map_read_55209 ht40allow_map_read 3 55209 NULL
127971 +__kfifo_dma_out_prepare_r_55211 __kfifo_dma_out_prepare_r 4-5 55211 NULL
127972 +do_raw_setsockopt_55215 do_raw_setsockopt 5 55215 NULL
127973 +qxl_alloc_client_monitors_config_55216 qxl_alloc_client_monitors_config 2 55216 NULL
127974 +nouveau_mc_create__55217 nouveau_mc_create_ 4 55217 NULL
127975 +dbAllocDmap_55227 dbAllocDmap 0 55227 NULL
127976 +memcpy_fromiovec_55247 memcpy_fromiovec 3 55247 NULL
127977 +lbs_failcount_write_55276 lbs_failcount_write 3 55276 NULL
127978 +persistent_ram_new_55286 persistent_ram_new 1-2 55286 NULL
127979 +rx_streaming_interval_read_55291 rx_streaming_interval_read 3 55291 NULL
127980 +lov_get_stripecnt_55297 lov_get_stripecnt 0-3 55297 NULL
127981 +gsm_control_modem_55303 gsm_control_modem 3 55303 NULL
127982 +compat_SyS_process_vm_readv_55305 compat_SyS_process_vm_readv 3-5 55305 NULL nohasharray
127983 +qp_alloc_guest_work_55305 qp_alloc_guest_work 5-3 55305 &compat_SyS_process_vm_readv_55305
127984 +compat_SyS_mbind_55329 compat_SyS_mbind 5 55329 NULL
127985 +vme_user_read_55338 vme_user_read 3 55338 NULL
127986 +sctp_datamsg_from_user_55342 sctp_datamsg_from_user 4 55342 NULL nohasharray
127987 +__wa_xfer_setup_sizes_55342 __wa_xfer_setup_sizes 0 55342 &sctp_datamsg_from_user_55342
127988 +cw1200_sdio_align_size_55391 cw1200_sdio_align_size 2 55391 NULL
127989 +iwl_dbgfs_plcp_delta_read_55407 iwl_dbgfs_plcp_delta_read 3 55407 NULL
127990 +nouveau_cli_create_55425 nouveau_cli_create 3 55425 NULL
127991 +si476x_radio_read_rds_blckcnt_blob_55427 si476x_radio_read_rds_blckcnt_blob 3 55427 NULL
127992 +__vxge_hw_channel_allocate_55462 __vxge_hw_channel_allocate 3 55462 NULL
127993 +cx23888_ir_rx_read_55473 cx23888_ir_rx_read 3 55473 NULL
127994 +snd_pcm_lib_write_55483 snd_pcm_lib_write 0-3 55483 NULL
127995 +i2o_pool_alloc_55485 i2o_pool_alloc 4 55485 NULL
127996 +batadv_tt_entries_55487 batadv_tt_entries 0-1 55487 NULL
127997 +ras_stride_increase_window_55501 ras_stride_increase_window 3 55501 NULL
127998 +tx_tx_done_int_template_read_55511 tx_tx_done_int_template_read 3 55511 NULL
127999 +ea_get_55522 ea_get 3-0 55522 NULL
128000 +buffer_size_55534 buffer_size 0 55534 NULL
128001 +set_msr_interception_55538 set_msr_interception 2 55538 NULL
128002 +tty_port_register_device_55543 tty_port_register_device 3 55543 NULL
128003 +hash_ipport6_expire_55549 hash_ipport6_expire 4 55549 NULL
128004 +dm_stats_list_55551 dm_stats_list 4 55551 NULL
128005 +compat_SyS_setsockopt_55581 compat_SyS_setsockopt 5 55581 NULL
128006 +add_partition_55588 add_partition 2 55588 NULL
128007 +kstrtou8_from_user_55599 kstrtou8_from_user 2 55599 NULL
128008 +SyS_keyctl_55602 SyS_keyctl 4 55602 NULL
128009 +macvtap_put_user_55609 macvtap_put_user 4 55609 NULL
128010 +selinux_setprocattr_55611 selinux_setprocattr 4 55611 NULL
128011 +edge_tty_recv_55622 edge_tty_recv 3 55622 NULL
128012 +pktgen_if_write_55628 pktgen_if_write 3 55628 NULL nohasharray
128013 +reiserfs_xattr_get_55628 reiserfs_xattr_get 0 55628 &pktgen_if_write_55628
128014 +osc_obd_max_pages_per_rpc_seq_write_55636 osc_obd_max_pages_per_rpc_seq_write 3 55636 NULL
128015 +xfs_bmbt_maxrecs_55649 xfs_bmbt_maxrecs 0-2 55649 NULL
128016 +lpfc_idiag_queinfo_read_55662 lpfc_idiag_queinfo_read 3 55662 NULL
128017 +il_dbgfs_tx_queue_read_55668 il_dbgfs_tx_queue_read 3 55668 NULL
128018 +get_info_55681 get_info 3 55681 NULL
128019 +iwl_dbgfs_plcp_delta_write_55682 iwl_dbgfs_plcp_delta_write 3 55682 NULL
128020 +genl_allocate_reserve_groups_55705 genl_allocate_reserve_groups 1 55705 NULL
128021 +pm8001_store_update_fw_55716 pm8001_store_update_fw 4 55716 NULL
128022 +tap_pwup_write_55723 tap_pwup_write 3 55723 NULL
128023 +__iio_allocate_kfifo_55738 __iio_allocate_kfifo 2 55738 NULL
128024 +set_local_name_55757 set_local_name 4 55757 NULL
128025 +ethtool_copy_validate_indir_55769 ethtool_copy_validate_indir 4 55769 NULL
128026 +strlen_55778 strlen 0 55778 NULL nohasharray
128027 +is_idx_node_in_tnc_55778 is_idx_node_in_tnc 0 55778 &strlen_55778
128028 +set_spte_55783 set_spte 4-5 55783 NULL
128029 +conf_read_55786 conf_read 3 55786 NULL nohasharray
128030 +req_bio_endio_55786 req_bio_endio 3 55786 &conf_read_55786
128031 +uwb_rc_neh_grok_event_55799 uwb_rc_neh_grok_event 3 55799 NULL
128032 +sb16_copy_from_user_55836 sb16_copy_from_user 10-6-7 55836 NULL
128033 +ip_hdrlen_55849 ip_hdrlen 0 55849 NULL
128034 +hcd_alloc_coherent_55862 hcd_alloc_coherent 5 55862 NULL
128035 +shmem_setxattr_55867 shmem_setxattr 4 55867 NULL
128036 +hsc_write_55875 hsc_write 3 55875 NULL
128037 +ramdisk_store_55885 ramdisk_store 4 55885 NULL
128038 +pm_qos_power_read_55891 pm_qos_power_read 3 55891 NULL
128039 +hash_ip4_expire_55911 hash_ip4_expire 4 55911 NULL
128040 +snd_pcm_hw_param_value_min_55917 snd_pcm_hw_param_value_min 0 55917 NULL
128041 +kvm_write_guest_virt_system_55944 kvm_write_guest_virt_system 4-2 55944 NULL
128042 +sel_read_policy_55947 sel_read_policy 3 55947 NULL
128043 +ceph_get_direct_page_vector_55956 ceph_get_direct_page_vector 2 55956 NULL
128044 +simple_read_from_buffer_55957 simple_read_from_buffer 5-2 55957 NULL
128045 +tx_tx_imm_resp_read_55964 tx_tx_imm_resp_read 3 55964 NULL
128046 +btrfs_clone_55977 btrfs_clone 5-3-6 55977 NULL
128047 +wa_xfer_create_subset_sg_55992 wa_xfer_create_subset_sg 3-2 55992 NULL
128048 +nvme_alloc_iod_56027 nvme_alloc_iod 1-2 56027 NULL
128049 +iwl_trans_read_prph_56052 iwl_trans_read_prph 0 56052 NULL
128050 +dccp_sendmsg_56058 dccp_sendmsg 4 56058 NULL
128051 +pscsi_get_bio_56103 pscsi_get_bio 1 56103 NULL
128052 +usb_alloc_stream_buffers_56123 usb_alloc_stream_buffers 3 56123 NULL
128053 +sel_read_handle_status_56139 sel_read_handle_status 3 56139 NULL
128054 +write_file_frameerrors_56145 write_file_frameerrors 3 56145 NULL
128055 +rawv6_setsockopt_56165 rawv6_setsockopt 5 56165 NULL
128056 +ath9k_dump_legacy_btcoex_56194 ath9k_dump_legacy_btcoex 3-0 56194 NULL
128057 +vring_add_indirect_56222 vring_add_indirect 4 56222 NULL
128058 +ocfs2_find_xe_in_bucket_56224 ocfs2_find_xe_in_bucket 0 56224 NULL
128059 +do_ipt_set_ctl_56238 do_ipt_set_ctl 4 56238 NULL
128060 +fd_copyin_56247 fd_copyin 3 56247 NULL
128061 +sk_rmem_schedule_56255 sk_rmem_schedule 3 56255 NULL
128062 +acpi_ex_get_serial_access_length_56275 acpi_ex_get_serial_access_length 0-2 56275 NULL
128063 +il4965_ucode_general_stats_read_56277 il4965_ucode_general_stats_read 3 56277 NULL
128064 +ieee80211_if_fmt_user_power_level_56283 ieee80211_if_fmt_user_power_level 3 56283 NULL
128065 +RESIZE_IF_NEEDED_56286 RESIZE_IF_NEEDED 2 56286 NULL
128066 +dvb_aplay_56296 dvb_aplay 3 56296 NULL
128067 +btmrvl_hscfgcmd_read_56303 btmrvl_hscfgcmd_read 3 56303 NULL
128068 +speakup_file_write_56310 speakup_file_write 3 56310 NULL
128069 +pipeline_pre_to_defrag_swi_read_56321 pipeline_pre_to_defrag_swi_read 3 56321 NULL
128070 +journal_init_revoke_table_56331 journal_init_revoke_table 1 56331 NULL
128071 +snd_rawmidi_read_56337 snd_rawmidi_read 3 56337 NULL
128072 +vxge_os_dma_malloc_async_56348 vxge_os_dma_malloc_async 3 56348 NULL
128073 +iov_iter_copy_from_user_atomic_56368 iov_iter_copy_from_user_atomic 0-4 56368 NULL
128074 +dev_read_56369 dev_read 3 56369 NULL
128075 +ath10k_read_simulate_fw_crash_56371 ath10k_read_simulate_fw_crash 3 56371 NULL
128076 +write_gssp_56404 write_gssp 3 56404 NULL
128077 +ocfs2_control_read_56405 ocfs2_control_read 3 56405 NULL
128078 +store_msg_56417 store_msg 3 56417 NULL
128079 +pppol2tp_sendmsg_56420 pppol2tp_sendmsg 4 56420 NULL
128080 +l2cap_segment_le_sdu_56426 l2cap_segment_le_sdu 4 56426 NULL
128081 +lprocfs_fid_space_seq_write_56431 lprocfs_fid_space_seq_write 3 56431 NULL nohasharray
128082 +ec_dbgfs_cmd_read_56431 ec_dbgfs_cmd_read 3 56431 &lprocfs_fid_space_seq_write_56431
128083 +fl_create_56435 fl_create 5 56435 NULL
128084 +gnttab_map_56439 gnttab_map 2 56439 NULL
128085 +cx231xx_init_isoc_56453 cx231xx_init_isoc 3-2-4 56453 NULL
128086 +set_connectable_56458 set_connectable 4 56458 NULL
128087 +osd_req_list_partition_objects_56464 osd_req_list_partition_objects 5 56464 NULL
128088 +putused_user_56467 putused_user 3 56467 NULL
128089 +ocfs2_zero_extend_range_56468 ocfs2_zero_extend_range 3-2 56468 NULL
128090 +lbs_rdmac_write_56471 lbs_rdmac_write 3 56471 NULL
128091 +crypto_shash_alignmask_56486 crypto_shash_alignmask 0 56486 NULL
128092 +ieee80211_rx_mgmt_probe_beacon_56491 ieee80211_rx_mgmt_probe_beacon 3 56491 NULL
128093 +memblock_virt_alloc_56501 memblock_virt_alloc 1 56501 NULL
128094 +init_map_ip_56508 init_map_ip 5 56508 NULL
128095 +lustre_posix_acl_xattr_reduce_space_56512 lustre_posix_acl_xattr_reduce_space 3 56512 NULL
128096 +cfg80211_connect_result_56515 cfg80211_connect_result 4-6 56515 NULL
128097 +ip_options_get_56538 ip_options_get 4 56538 NULL
128098 +ll_wr_track_id_56544 ll_wr_track_id 2 56544 NULL
128099 +alloc_apertures_56561 alloc_apertures 1 56561 NULL
128100 +rs_sta_dbgfs_stats_table_read_56573 rs_sta_dbgfs_stats_table_read 3 56573 NULL
128101 +portcntrs_2_read_56586 portcntrs_2_read 3 56586 NULL
128102 +gro_pull_from_frag0_56593 gro_pull_from_frag0 2 56593 NULL
128103 +event_filter_write_56609 event_filter_write 3 56609 NULL
128104 +nvme_trans_log_temperature_56613 nvme_trans_log_temperature 3 56613 NULL
128105 +gather_array_56641 gather_array 3 56641 NULL
128106 +lookup_extent_backref_56644 lookup_extent_backref 9 56644 NULL
128107 +uvc_debugfs_stats_read_56651 uvc_debugfs_stats_read 3 56651 NULL
128108 +tg3_nvram_write_block_56666 tg3_nvram_write_block 3 56666 NULL
128109 +snd_gus_dram_read_56686 snd_gus_dram_read 4 56686 NULL
128110 +dvb_ringbuffer_read_user_56702 dvb_ringbuffer_read_user 3-0 56702 NULL
128111 +sta_flags_read_56710 sta_flags_read 3 56710 NULL
128112 +ipv6_getsockopt_sticky_56711 ipv6_getsockopt_sticky 5 56711 NULL
128113 +__wa_xfer_setup_segs_56725 __wa_xfer_setup_segs 2 56725 NULL
128114 +__copy_from_user_ll_56738 __copy_from_user_ll 0-3 56738 NULL
128115 +drm_agp_bind_pages_56748 drm_agp_bind_pages 3 56748 NULL
128116 +btrfsic_map_block_56751 btrfsic_map_block 2 56751 NULL
128117 +ttm_alloc_new_pages_56792 ttm_alloc_new_pages 5 56792 NULL
128118 +ion_ioctl_56806 ion_ioctl 2 56806 NULL
128119 +do_syslog_56807 do_syslog 3 56807 NULL
128120 +mtdchar_write_56831 mtdchar_write 3 56831 NULL
128121 +snd_rawmidi_kernel_write1_56847 snd_rawmidi_kernel_write1 4-0 56847 NULL
128122 +si476x_radio_read_agc_blob_56849 si476x_radio_read_agc_blob 3 56849 NULL
128123 +gk20a_ram_get_56863 gk20a_ram_get 2 56863 NULL
128124 +ext3_xattr_ibody_get_56880 ext3_xattr_ibody_get 0 56880 NULL
128125 +pvr2_debugifc_print_status_56890 pvr2_debugifc_print_status 3 56890 NULL
128126 +debug_debug3_read_56894 debug_debug3_read 3 56894 NULL
128127 +batadv_tt_update_changes_56895 batadv_tt_update_changes 3 56895 NULL nohasharray
128128 +le_auto_conn_write_56895 le_auto_conn_write 3 56895 &batadv_tt_update_changes_56895
128129 +hfsplus_find_cat_56899 hfsplus_find_cat 0 56899 NULL
128130 +__kfifo_out_56927 __kfifo_out 0-3 56927 NULL
128131 +journal_init_revoke_56933 journal_init_revoke 2 56933 NULL
128132 +nouveau_xtensa_create__56952 nouveau_xtensa_create_ 8 56952 NULL
128133 +diva_get_driver_info_56967 diva_get_driver_info 0 56967 NULL
128134 +vlsi_alloc_ring_57003 vlsi_alloc_ring 3-4 57003 NULL
128135 +btrfs_super_csum_size_57004 btrfs_super_csum_size 0 57004 NULL
128136 +aircable_process_packet_57027 aircable_process_packet 4 57027 NULL
128137 +ieee80211_if_fmt_state_57043 ieee80211_if_fmt_state 3 57043 NULL
128138 +bytes_to_samples_57049 bytes_to_samples 0-2 57049 NULL
128139 +xfs_buf_read_map_57053 xfs_buf_read_map 3 57053 NULL
128140 +cx2341x_ctrl_new_std_57061 cx2341x_ctrl_new_std 4 57061 NULL
128141 +sca3000_read_data_57064 sca3000_read_data 4 57064 NULL
128142 +pcmcia_replace_cis_57066 pcmcia_replace_cis 3 57066 NULL
128143 +tracing_set_trace_write_57096 tracing_set_trace_write 3 57096 NULL
128144 +hpfs_readpages_57106 hpfs_readpages 4 57106 NULL
128145 +crypto_compress_ctxsize_57109 crypto_compress_ctxsize 0 57109 NULL
128146 +cipso_v4_gentag_loc_57119 cipso_v4_gentag_loc 0 57119 NULL
128147 +ima_show_htable_value_57136 ima_show_htable_value 2 57136 NULL nohasharray
128148 +rds_ib_sub_signaled_57136 rds_ib_sub_signaled 2 57136 &ima_show_htable_value_57136 nohasharray
128149 +nl80211_send_deauth_57136 nl80211_send_deauth 4 57136 &rds_ib_sub_signaled_57136
128150 +snd_sonicvibes_getdmac_57140 snd_sonicvibes_getdmac 0 57140 NULL
128151 +_iwl_dbgfs_bf_params_write_57141 _iwl_dbgfs_bf_params_write 3 57141 NULL
128152 +udl_prime_create_57159 udl_prime_create 2 57159 NULL
128153 +stk_prepare_sio_buffers_57168 stk_prepare_sio_buffers 2 57168 NULL
128154 +rx_hw_stuck_read_57179 rx_hw_stuck_read 3 57179 NULL
128155 +hash_netnet6_expire_57191 hash_netnet6_expire 4 57191 NULL
128156 +tt3650_ci_msg_57219 tt3650_ci_msg 4 57219 NULL
128157 +dma_fifo_alloc_57236 dma_fifo_alloc 2-3-5 57236 NULL
128158 +rsxx_cram_write_57244 rsxx_cram_write 3 57244 NULL
128159 +ieee80211_if_fmt_tsf_57249 ieee80211_if_fmt_tsf 3 57249 NULL
128160 +oprofilefs_ulong_from_user_57251 oprofilefs_ulong_from_user 3 57251 NULL
128161 +alloc_flex_gd_57259 alloc_flex_gd 1 57259 NULL
128162 +lbs_sleepparams_write_57283 lbs_sleepparams_write 3 57283 NULL
128163 +pstore_file_read_57288 pstore_file_read 3 57288 NULL
128164 +snd_pcm_read_57289 snd_pcm_read 3 57289 NULL
128165 +ftdi_elan_write_57309 ftdi_elan_write 3 57309 NULL
128166 +write_file_regval_57313 write_file_regval 3 57313 NULL
128167 +__mxt_write_reg_57326 __mxt_write_reg 3 57326 NULL
128168 +usblp_read_57342 usblp_read 3 57342 NULL
128169 +print_devstats_dot11RTSFailureCount_57347 print_devstats_dot11RTSFailureCount 3 57347 NULL
128170 +dio_send_cur_page_57348 dio_send_cur_page 0 57348 NULL
128171 +tipc_bclink_stats_57372 tipc_bclink_stats 2 57372 NULL
128172 +tty_register_device_attr_57381 tty_register_device_attr 2 57381 NULL
128173 +read_file_blob_57406 read_file_blob 3 57406 NULL
128174 +enclosure_register_57412 enclosure_register 3 57412 NULL
128175 +compat_keyctl_instantiate_key_iov_57431 compat_keyctl_instantiate_key_iov 3 57431 NULL
128176 +copy_to_user_fromio_57432 copy_to_user_fromio 3 57432 NULL
128177 +__roundup_pow_of_two_57461 __roundup_pow_of_two 0 57461 NULL
128178 +sisusb_clear_vram_57466 sisusb_clear_vram 2-3 57466 NULL
128179 +ieee80211_if_read_flags_57470 ieee80211_if_read_flags 3 57470 NULL
128180 +read_file_skb_rx_57490 read_file_skb_rx 3 57490 NULL
128181 +bnad_debugfs_write_regwr_57500 bnad_debugfs_write_regwr 3 57500 NULL
128182 +skb_headlen_57501 skb_headlen 0 57501 NULL
128183 +copy_in_user_57502 copy_in_user 3 57502 NULL
128184 +ckhdid_printf_57505 ckhdid_printf 2 57505 NULL
128185 +init_tag_map_57515 init_tag_map 3 57515 NULL
128186 +wil_read_file_ssid_57517 wil_read_file_ssid 3 57517 NULL nohasharray
128187 +il_dbgfs_force_reset_read_57517 il_dbgfs_force_reset_read 3 57517 &wil_read_file_ssid_57517
128188 +cmm_read_57520 cmm_read 3 57520 NULL
128189 +inode_permission_57531 inode_permission 0 57531 NULL
128190 +acpi_dev_get_resources_57534 acpi_dev_get_resources 0 57534 NULL
128191 +ptlrpc_lprocfs_hp_ratio_seq_write_57537 ptlrpc_lprocfs_hp_ratio_seq_write 3 57537 NULL
128192 +compat_SyS_process_vm_writev_57542 compat_SyS_process_vm_writev 3-5 57542 NULL
128193 +snd_pcm_playback_ioctl1_57569 snd_pcm_playback_ioctl1 0 57569 NULL
128194 +get_bridge_ifindices_57579 get_bridge_ifindices 0 57579 NULL
128195 +ldlm_cli_enqueue_local_57582 ldlm_cli_enqueue_local 11 57582 NULL
128196 +il_dbgfs_interrupt_write_57591 il_dbgfs_interrupt_write 3 57591 NULL
128197 +read_file_spectral_fft_period_57593 read_file_spectral_fft_period 3 57593 NULL
128198 +tx_tx_retry_template_read_57623 tx_tx_retry_template_read 3 57623 NULL
128199 +sisusbcon_putcs_57630 sisusbcon_putcs 3 57630 NULL
128200 +mem_read_57631 mem_read 3 57631 NULL
128201 +r3964_write_57662 r3964_write 4 57662 NULL
128202 +proc_ns_readlink_57664 proc_ns_readlink 3 57664 NULL
128203 +__lgwrite_57669 __lgwrite 4 57669 NULL
128204 +i2400m_rx_stats_read_57706 i2400m_rx_stats_read 3 57706 NULL
128205 +ieee80211_if_read_dot11MeshHWMPconfirmationInterval_57722 ieee80211_if_read_dot11MeshHWMPconfirmationInterval 3 57722 NULL
128206 +pppol2tp_recvmsg_57742 pppol2tp_recvmsg 4 57742 NULL
128207 +ieee80211_if_fmt_dot11MeshHWMPpreqMinInterval_57762 ieee80211_if_fmt_dot11MeshHWMPpreqMinInterval 3 57762 NULL
128208 +SYSC_process_vm_writev_57776 SYSC_process_vm_writev 3-5 57776 NULL
128209 +ld2_57794 ld2 0 57794 NULL
128210 +ivtv_read_57796 ivtv_read 3 57796 NULL
128211 +ion_test_ioctl_57799 ion_test_ioctl 2 57799 NULL
128212 +bfad_debugfs_read_regrd_57830 bfad_debugfs_read_regrd 3 57830 NULL
128213 +copy_to_user_57835 copy_to_user 3-0 57835 NULL
128214 +flash_read_57843 flash_read 3 57843 NULL
128215 +kiblnd_create_tx_pool_57846 kiblnd_create_tx_pool 2 57846 NULL
128216 +radeon_ttm_gtt_read_57879 radeon_ttm_gtt_read 3 57879 NULL
128217 +xt_alloc_table_info_57903 xt_alloc_table_info 1 57903 NULL
128218 +iio_read_first_n_kfifo_57910 iio_read_first_n_kfifo 2 57910 NULL
128219 +ll_xattr_find_get_lock_57912 ll_xattr_find_get_lock 0 57912 NULL
128220 +memcg_caches_array_size_57918 memcg_caches_array_size 0-1 57918 NULL
128221 +twl_i2c_write_57923 twl_i2c_write 3-4 57923 NULL
128222 +__snd_gf1_look16_57925 __snd_gf1_look16 0 57925 NULL
128223 +sel_read_handle_unknown_57933 sel_read_handle_unknown 3 57933 NULL
128224 +xfs_mru_cache_create_57943 xfs_mru_cache_create 3 57943 NULL
128225 +key_algorithm_read_57946 key_algorithm_read 3 57946 NULL
128226 +arch_gnttab_init_57948 arch_gnttab_init 2-1 57948 NULL
128227 +ip_set_alloc_57953 ip_set_alloc 1 57953 NULL nohasharray
128228 +ioat3_dca_count_dca_slots_57953 ioat3_dca_count_dca_slots 0 57953 &ip_set_alloc_57953
128229 +iov_iter_npages_57979 iov_iter_npages 0-2 57979 NULL
128230 +rx_reset_counter_read_58001 rx_reset_counter_read 3 58001 NULL
128231 +iwl_dbgfs_ucode_rx_stats_read_58023 iwl_dbgfs_ucode_rx_stats_read 3 58023 NULL
128232 +io_playback_transfer_58030 io_playback_transfer 4 58030 NULL
128233 +mce_async_out_58056 mce_async_out 3 58056 NULL
128234 +ocfs2_find_leaf_58065 ocfs2_find_leaf 0 58065 NULL
128235 +dt3155_alloc_coherent_58073 dt3155_alloc_coherent 2 58073 NULL
128236 +cm4040_write_58079 cm4040_write 3 58079 NULL
128237 +ipv6_flowlabel_opt_58135 ipv6_flowlabel_opt 3 58135 NULL nohasharray
128238 +slhc_init_58135 slhc_init 1-2 58135 &ipv6_flowlabel_opt_58135
128239 +garmin_write_bulk_58191 garmin_write_bulk 3 58191 NULL
128240 +ieee80211_if_fmt_flags_58205 ieee80211_if_fmt_flags 3 58205 NULL
128241 +i40evf_allocate_virt_mem_d_58210 i40evf_allocate_virt_mem_d 3 58210 NULL
128242 +btrfsic_create_link_to_next_block_58246 btrfsic_create_link_to_next_block 4 58246 NULL
128243 +read_file_debug_58256 read_file_debug 3 58256 NULL
128244 +osc_max_dirty_mb_seq_write_58263 osc_max_dirty_mb_seq_write 3 58263 NULL
128245 +cfg80211_mgmt_tx_status_58266 cfg80211_mgmt_tx_status 4 58266 NULL
128246 +profile_load_58267 profile_load 3 58267 NULL
128247 +kstrtos8_from_user_58268 kstrtos8_from_user 2 58268 NULL
128248 +acpi_ds_build_internal_package_obj_58271 acpi_ds_build_internal_package_obj 3 58271 NULL
128249 +iscsi_decode_text_input_58292 iscsi_decode_text_input 4 58292 NULL
128250 +ieee80211_if_read_dot11MeshTTL_58307 ieee80211_if_read_dot11MeshTTL 3 58307 NULL
128251 +tx_tx_start_int_templates_read_58324 tx_tx_start_int_templates_read 3 58324 NULL
128252 +ext4_ext_truncate_extend_restart_58331 ext4_ext_truncate_extend_restart 3 58331 NULL
128253 +__copy_from_user_swizzled_58337 __copy_from_user_swizzled 2-4 58337 NULL
128254 +brcmf_debugfs_sdio_counter_read_58369 brcmf_debugfs_sdio_counter_read 3 58369 NULL
128255 +il_dbgfs_status_read_58388 il_dbgfs_status_read 3 58388 NULL
128256 +_drbd_md_sync_page_io_58403 _drbd_md_sync_page_io 6 58403 NULL
128257 +kvm_mmu_write_protect_pt_masked_58406 kvm_mmu_write_protect_pt_masked 3 58406 NULL nohasharray
128258 +idetape_pad_zeros_58406 idetape_pad_zeros 2 58406 &kvm_mmu_write_protect_pt_masked_58406
128259 +i2400m_pld_size_58415 i2400m_pld_size 0 58415 NULL
128260 +capabilities_read_58457 capabilities_read 3 58457 NULL
128261 +usnic_vnic_get_resources_58462 usnic_vnic_get_resources 3 58462 NULL
128262 +compat_do_ipt_set_ctl_58466 compat_do_ipt_set_ctl 4 58466 NULL nohasharray
128263 +lpfc_idiag_baracc_read_58466 lpfc_idiag_baracc_read 3 58466 &compat_do_ipt_set_ctl_58466
128264 +nv_rd08_58472 nv_rd08 0 58472 NULL
128265 +snd_gf1_read_addr_58483 snd_gf1_read_addr 0 58483 NULL
128266 +snd_rme96_capture_copy_58484 snd_rme96_capture_copy 5 58484 NULL
128267 +btrfs_cont_expand_58498 btrfs_cont_expand 2-3 58498 NULL
128268 +tcf_hash_create_58507 tcf_hash_create 4 58507 NULL
128269 +rndis_add_response_58544 rndis_add_response 2 58544 NULL
128270 +wep_decrypt_fail_read_58567 wep_decrypt_fail_read 3 58567 NULL
128271 +scnprint_mac_oui_58578 scnprint_mac_oui 3-0 58578 NULL
128272 +cur_wm_latency_write_58581 cur_wm_latency_write 3 58581 NULL
128273 +ea_read_inline_58589 ea_read_inline 0 58589 NULL
128274 +isku_sysfs_read_keys_thumbster_58590 isku_sysfs_read_keys_thumbster 6 58590 NULL
128275 +xip_file_read_58592 xip_file_read 3 58592 NULL
128276 +ecryptfs_write_end_58594 ecryptfs_write_end 5-3 58594 NULL
128277 +radeon_bo_size_58606 radeon_bo_size 0 58606 NULL
128278 +btrfs_direct_IO_58608 btrfs_direct_IO 4 58608 NULL
128279 +skb_copy_to_page_nocache_58624 skb_copy_to_page_nocache 6 58624 NULL
128280 +tx_tx_start_fw_gen_read_58648 tx_tx_start_fw_gen_read 3 58648 NULL
128281 +iwl_dbgfs_rx_handlers_write_58655 iwl_dbgfs_rx_handlers_write 3 58655 NULL
128282 +find_zero_58685 find_zero 0-1 58685 NULL
128283 +uwb_bce_print_IEs_58686 uwb_bce_print_IEs 4 58686 NULL
128284 +tps6586x_writes_58689 tps6586x_writes 2-3 58689 NULL
128285 +vx_send_msg_58711 vx_send_msg 0 58711 NULL
128286 +csum_exist_in_range_58730 csum_exist_in_range 2-3 58730 NULL
128287 +frames_to_bytes_58741 frames_to_bytes 0-2 58741 NULL
128288 +ieee80211_if_write_tkip_mic_test_58748 ieee80211_if_write_tkip_mic_test 3 58748 NULL
128289 +agp_allocate_memory_58761 agp_allocate_memory 2 58761 NULL
128290 +regmap_calc_reg_len_58795 regmap_calc_reg_len 0 58795 NULL
128291 +raw_send_hdrinc_58803 raw_send_hdrinc 4 58803 NULL
128292 +isku_sysfs_read_58806 isku_sysfs_read 5 58806 NULL
128293 +ep_read_58813 ep_read 3 58813 NULL
128294 +command_write_58841 command_write 3 58841 NULL
128295 +ath6kl_wmi_send_action_cmd_58860 ath6kl_wmi_send_action_cmd 7 58860 NULL
128296 +gs_alloc_req_58883 gs_alloc_req 2 58883 NULL
128297 +esas2r_change_queue_depth_58886 esas2r_change_queue_depth 2 58886 NULL
128298 +lprocfs_wr_pinger_recov_58914 lprocfs_wr_pinger_recov 3 58914 NULL
128299 +print_devstats_dot11FCSErrorCount_58919 print_devstats_dot11FCSErrorCount 3 58919 NULL
128300 +pipeline_cs_rx_packet_out_read_58926 pipeline_cs_rx_packet_out_read 3 58926 NULL
128301 +wait_table_hash_nr_entries_58962 wait_table_hash_nr_entries 0 58962 NULL
128302 +ieee80211_if_fmt_dot11MeshHWMPactivePathToRootTimeout_58965 ieee80211_if_fmt_dot11MeshHWMPactivePathToRootTimeout 3 58965 NULL
128303 +crypto_aead_ivsize_58970 crypto_aead_ivsize 0 58970 NULL
128304 +init_list_set_59005 init_list_set 3 59005 NULL
128305 +ep_write_59008 ep_write 3 59008 NULL
128306 +lpfc_idiag_baracc_write_59014 lpfc_idiag_baracc_write 3 59014 NULL
128307 +SyS_preadv_59029 SyS_preadv 3 59029 NULL
128308 +init_pci_cap_msi_perm_59033 init_pci_cap_msi_perm 2 59033 NULL
128309 +selinux_transaction_write_59038 selinux_transaction_write 3 59038 NULL
128310 +crypto_aead_reqsize_59039 crypto_aead_reqsize 0 59039 NULL
128311 +regmap_bulk_write_59049 regmap_bulk_write 2-4 59049 NULL
128312 +mmc_sd_num_wr_blocks_59112 mmc_sd_num_wr_blocks 0 59112 NULL
128313 +sta_tx_latency_stat_table_59122 sta_tx_latency_stat_table 5-4-0 59122 NULL nohasharray
128314 +scsi_io_completion_59122 scsi_io_completion 2 59122 &sta_tx_latency_stat_table_59122
128315 +nfc_llcp_send_i_frame_59130 nfc_llcp_send_i_frame 3 59130 NULL
128316 +framebuffer_alloc_59145 framebuffer_alloc 1 59145 NULL nohasharray
128317 +print_devstats_dot11RTSSuccessCount_59145 print_devstats_dot11RTSSuccessCount 3 59145 &framebuffer_alloc_59145
128318 +radeon_compat_ioctl_59150 radeon_compat_ioctl 2 59150 NULL
128319 +pvr2_hdw_report_clients_59152 pvr2_hdw_report_clients 3 59152 NULL
128320 +ksize_59176 ksize 0 59176 NULL
128321 +setup_window_59178 setup_window 4-2-5-7 59178 NULL
128322 +ocfs2_move_extent_59187 ocfs2_move_extent 2-5 59187 NULL
128323 +xfs_iext_realloc_indirect_59211 xfs_iext_realloc_indirect 2 59211 NULL
128324 +dt3155_read_59226 dt3155_read 3 59226 NULL
128325 +paging64_gpte_to_gfn_lvl_59229 paging64_gpte_to_gfn_lvl 0-2-1 59229 NULL
128326 +nla_len_59258 nla_len 0 59258 NULL
128327 +drbd_bm_write_page_59290 drbd_bm_write_page 2 59290 NULL
128328 +btrfs_insert_dir_item_59304 btrfs_insert_dir_item 4 59304 NULL
128329 +fd_copyout_59323 fd_copyout 3 59323 NULL
128330 +rx_defrag_in_process_called_read_59338 rx_defrag_in_process_called_read 3 59338 NULL
128331 +xfs_attrmulti_attr_set_59346 xfs_attrmulti_attr_set 4 59346 NULL
128332 +f2fs_fallocate_59377 f2fs_fallocate 4-3 59377 NULL
128333 +pvr2_debugifc_print_info_59380 pvr2_debugifc_print_info 3 59380 NULL
128334 +journal_init_dev_59384 journal_init_dev 5 59384 NULL
128335 +__net_get_random_once_59389 __net_get_random_once 2 59389 NULL
128336 +isku_sysfs_read_keys_function_59412 isku_sysfs_read_keys_function 6 59412 NULL
128337 +vxge_hw_ring_rxds_per_block_get_59425 vxge_hw_ring_rxds_per_block_get 0 59425 NULL
128338 +SyS_sched_setaffinity_59442 SyS_sched_setaffinity 2 59442 NULL
128339 +fs_path_ensure_buf_59445 fs_path_ensure_buf 2 59445 NULL
128340 +tipc_recv_stream_59456 tipc_recv_stream 4 59456 NULL
128341 +_iwl_dbgfs_bcast_filters_write_59491 _iwl_dbgfs_bcast_filters_write 3 59491 NULL
128342 +ib_copy_from_udata_59502 ib_copy_from_udata 3 59502 NULL
128343 +C_SYSC_get_mempolicy_59516 C_SYSC_get_mempolicy 3 59516 NULL
128344 +mic_vringh_copy_59523 mic_vringh_copy 4 59523 NULL
128345 +mpi_get_nbits_59551 mpi_get_nbits 0 59551 NULL
128346 +tunables_write_59563 tunables_write 3 59563 NULL
128347 +bio_split_59564 bio_split 2 59564 NULL
128348 +__copy_from_user_ll_nozero_59571 __copy_from_user_ll_nozero 0-3 59571 NULL
128349 +memdup_user_59590 memdup_user 2 59590 NULL
128350 +mem_fwlog_free_mem_blks_read_59616 mem_fwlog_free_mem_blks_read 3 59616 NULL nohasharray
128351 +xrcdn_free_res_59616 xrcdn_free_res 5 59616 &mem_fwlog_free_mem_blks_read_59616
128352 +ath6kl_endpoint_stats_write_59621 ath6kl_endpoint_stats_write 3 59621 NULL
128353 +mtrr_write_59622 mtrr_write 3 59622 NULL
128354 +find_first_zero_bit_59636 find_first_zero_bit 0 59636 NULL
128355 +SyS_setdomainname_59646 SyS_setdomainname 2 59646 NULL
128356 +hidraw_read_59650 hidraw_read 3 59650 NULL
128357 +v9fs_xattr_set_acl_59651 v9fs_xattr_set_acl 4 59651 NULL
128358 +__devcgroup_check_permission_59665 __devcgroup_check_permission 0 59665 NULL
128359 +iwl_dbgfs_mac_params_read_59666 iwl_dbgfs_mac_params_read 3 59666 NULL
128360 +alloc_dca_provider_59670 alloc_dca_provider 2 59670 NULL
128361 +mic_calc_failure_read_59700 mic_calc_failure_read 3 59700 NULL
128362 +ioperm_get_59701 ioperm_get 4-3 59701 NULL
128363 +prism2_info_scanresults_59729 prism2_info_scanresults 3 59729 NULL
128364 +ieee80211_if_read_fwded_unicast_59740 ieee80211_if_read_fwded_unicast 3 59740 NULL
128365 +qib_decode_7220_sdma_errs_59745 qib_decode_7220_sdma_errs 4 59745 NULL
128366 +strnlen_59746 strnlen 0 59746 NULL
128367 +ext3_acl_count_59754 ext3_acl_count 0-1 59754 NULL
128368 +long_retry_limit_read_59766 long_retry_limit_read 3 59766 NULL
128369 +venus_remove_59781 venus_remove 4 59781 NULL
128370 +mei_nfc_recv_59784 mei_nfc_recv 3 59784 NULL
128371 +C_SYSC_preadv_59801 C_SYSC_preadv 3 59801 NULL
128372 +ipw_write_59807 ipw_write 3 59807 NULL
128373 +scsi_init_shared_tag_map_59812 scsi_init_shared_tag_map 2 59812 NULL
128374 +ieee80211_if_read_dot11MeshHWMPmaxPREQretries_59829 ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 NULL
128375 +gspca_dev_probe2_59833 gspca_dev_probe2 4 59833 NULL
128376 +regmap_raw_write_async_59849 regmap_raw_write_async 2-4 59849 NULL
128377 +biovec_create_pool_59878 biovec_create_pool 1 59878 NULL
128378 +pvr2_ioread_set_sync_key_59882 pvr2_ioread_set_sync_key 3 59882 NULL
128379 +l2cap_sock_recvmsg_59886 l2cap_sock_recvmsg 4 59886 NULL
128380 +ffs_prepare_buffer_59892 ffs_prepare_buffer 2 59892 NULL
128381 +kvm_mmu_notifier_invalidate_range_start_59944 kvm_mmu_notifier_invalidate_range_start 3-4 59944 NULL
128382 +ath10k_read_dfs_stats_59949 ath10k_read_dfs_stats 3 59949 NULL
128383 +dapm_widget_power_read_file_59950 dapm_widget_power_read_file 3 59950 NULL nohasharray
128384 +il_dbgfs_rxon_flags_read_59950 il_dbgfs_rxon_flags_read 3 59950 &dapm_widget_power_read_file_59950
128385 +il_dbgfs_missed_beacon_read_59956 il_dbgfs_missed_beacon_read 3 59956 NULL
128386 +__arch_hweight16_59975 __arch_hweight16 0 59975 NULL
128387 +osd_req_read_kern_59990 osd_req_read_kern 5 59990 NULL
128388 +ghash_async_setkey_60001 ghash_async_setkey 3 60001 NULL
128389 +ieee80211_if_fmt_dot11MeshAwakeWindowDuration_60006 ieee80211_if_fmt_dot11MeshAwakeWindowDuration 3 60006 NULL
128390 +copy_items_60009 copy_items 7 60009 NULL
128391 +rawsock_sendmsg_60010 rawsock_sendmsg 4 60010 NULL
128392 +mthca_init_cq_60011 mthca_init_cq 2 60011 NULL
128393 +osd_req_list_dev_partitions_60027 osd_req_list_dev_partitions 4 60027 NULL
128394 +xlog_bread_offset_60030 xlog_bread_offset 3 60030 NULL
128395 +bio_integrity_hw_sectors_60039 bio_integrity_hw_sectors 0-2 60039 NULL
128396 +do_ip6t_set_ctl_60040 do_ip6t_set_ctl 4 60040 NULL
128397 +vcs_size_60050 vcs_size 0 60050 NULL
128398 +gru_alloc_gts_60056 gru_alloc_gts 3-2 60056 NULL
128399 +compat_writev_60063 compat_writev 3 60063 NULL
128400 +ath6kl_listen_int_write_60066 ath6kl_listen_int_write 3 60066 NULL
128401 +c4iw_num_stags_60073 c4iw_num_stags 0 60073 NULL
128402 +usb_os_desc_prepare_interf_dir_60075 usb_os_desc_prepare_interf_dir 2 60075 NULL
128403 +rxrpc_kernel_send_data_60083 rxrpc_kernel_send_data 3 60083 NULL
128404 +ieee80211_if_fmt_fwded_frames_60103 ieee80211_if_fmt_fwded_frames 3 60103 NULL
128405 +SYSC_msgsnd_60113 SYSC_msgsnd 3 60113 NULL
128406 +nfs_idmap_request_key_60124 nfs_idmap_request_key 2 60124 NULL
128407 +__mutex_lock_common_60134 __mutex_lock_common 0 60134 NULL
128408 +ld_usb_read_60156 ld_usb_read 3 60156 NULL
128409 +jmb38x_ms_count_slots_60164 jmb38x_ms_count_slots 0 60164 NULL
128410 +init_state_60165 init_state 2 60165 NULL
128411 +sg_build_sgat_60179 sg_build_sgat 3 60179 NULL nohasharray
128412 +jffs2_alloc_full_dirent_60179 jffs2_alloc_full_dirent 1 60179 &sg_build_sgat_60179
128413 +fuse_async_req_send_60183 fuse_async_req_send 0-3 60183 NULL
128414 +rx_rx_tkip_replays_read_60193 rx_rx_tkip_replays_read 3 60193 NULL
128415 +qib_reg_phys_mr_60202 qib_reg_phys_mr 3 60202 NULL
128416 +btrfs_get_token_16_60220 btrfs_get_token_16 0 60220 NULL
128417 +irq_alloc_domain_generic_chips_60264 irq_alloc_domain_generic_chips 2-3 60264 NULL
128418 +display_crc_ctl_write_60273 display_crc_ctl_write 3 60273 NULL
128419 +printer_write_60276 printer_write 3 60276 NULL
128420 +do_xip_mapping_read_60297 do_xip_mapping_read 5 60297 NULL
128421 +getDataLength_60301 getDataLength 0 60301 NULL
128422 +bch_subtract_dirty_60306 bch_subtract_dirty 3-4 60306 NULL
128423 +usb_alphatrack_write_60341 usb_alphatrack_write 3 60341 NULL
128424 +__kfifo_from_user_r_60345 __kfifo_from_user_r 5-3 60345 NULL
128425 +dccp_setsockopt_60367 dccp_setsockopt 5 60367 NULL
128426 +ubi_eba_atomic_leb_change_60379 ubi_eba_atomic_leb_change 0 60379 NULL
128427 +mthca_alloc_resize_buf_60394 mthca_alloc_resize_buf 3 60394 NULL
128428 +ocfs2_zero_extend_60396 ocfs2_zero_extend 3 60396 NULL
128429 +driver_names_read_60399 driver_names_read 3 60399 NULL
128430 +simple_alloc_urb_60420 simple_alloc_urb 3 60420 NULL
128431 +excessive_retries_read_60425 excessive_retries_read 3 60425 NULL
128432 +kmalloc_60432 kmalloc 1 60432 NULL nohasharray
128433 +tstats_write_60432 tstats_write 3 60432 &kmalloc_60432
128434 +snd_hda_get_num_raw_conns_60462 snd_hda_get_num_raw_conns 0 60462 NULL
128435 +crypto_shash_setkey_60483 crypto_shash_setkey 3 60483 NULL
128436 +lustre_msg_early_size_60496 lustre_msg_early_size 0 60496 NULL
128437 +compat_SyS_get_mempolicy_60527 compat_SyS_get_mempolicy 3 60527 NULL
128438 +v9fs_fid_readn_60544 v9fs_fid_readn 4 60544 NULL
128439 +nonpaging_map_60551 nonpaging_map 4 60551 NULL
128440 +osc_lockless_truncate_seq_write_60553 osc_lockless_truncate_seq_write 3 60553 NULL
128441 +xfs_vm_direct_IO_60557 xfs_vm_direct_IO 4 60557 NULL
128442 +tracing_entries_write_60563 tracing_entries_write 3 60563 NULL
128443 +memblock_virt_alloc_try_nid_nopanic_60604 memblock_virt_alloc_try_nid_nopanic 1 60604 NULL
128444 +skb_transport_offset_60619 skb_transport_offset 0 60619 NULL
128445 +wl1273_fm_fops_write_60621 wl1273_fm_fops_write 3 60621 NULL
128446 +acl_alloc_stack_init_60630 acl_alloc_stack_init 1 60630 NULL
128447 +__proc_lnet_stats_60647 __proc_lnet_stats 5 60647 NULL
128448 +if_sdio_host_to_card_60666 if_sdio_host_to_card 4 60666 NULL
128449 +ieee80211_if_read_dot11MeshConfirmTimeout_60670 ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 NULL
128450 +snd_ice1712_ds_read_60754 snd_ice1712_ds_read 0 60754 NULL
128451 +raid_status_60755 raid_status 5 60755 NULL
128452 +sel_write_checkreqprot_60774 sel_write_checkreqprot 3 60774 NULL
128453 +opticon_write_60775 opticon_write 4 60775 NULL
128454 +acl_alloc_num_60778 acl_alloc_num 1-2 60778 NULL
128455 +snd_pcm_oss_readv3_60792 snd_pcm_oss_readv3 3 60792 NULL
128456 +pwr_tx_with_ps_read_60851 pwr_tx_with_ps_read 3 60851 NULL
128457 +alloc_buf_60864 alloc_buf 3-2 60864 NULL
128458 +generic_writepages_60871 generic_writepages 0 60871 NULL
128459 +ubifs_read_one_lp_60882 ubifs_read_one_lp 0 60882 NULL
128460 +ext4_update_inline_data_60888 ext4_update_inline_data 3 60888 NULL
128461 +iio_debugfs_read_reg_60908 iio_debugfs_read_reg 3 60908 NULL
128462 +libcfs_sock_ioctl_60915 libcfs_sock_ioctl 0 60915 NULL
128463 +mgt_set_varlen_60916 mgt_set_varlen 4 60916 NULL
128464 +submit_extent_page_60928 submit_extent_page 5 60928 NULL
128465 +pti_char_write_60960 pti_char_write 3 60960 NULL
128466 +mwifiex_alloc_sdio_mpa_buffers_60961 mwifiex_alloc_sdio_mpa_buffers 2-3 60961 NULL
128467 +__a2mp_build_60987 __a2mp_build 3 60987 NULL
128468 +hsc_msg_alloc_60990 hsc_msg_alloc 1 60990 NULL
128469 +generic_file_direct_write_60995 generic_file_direct_write 0 60995 NULL
128470 +ath6kl_lrssi_roam_read_61022 ath6kl_lrssi_roam_read 3 61022 NULL
128471 +graph_depth_write_61024 graph_depth_write 3 61024 NULL
128472 +sdhci_pltfm_register_61031 sdhci_pltfm_register 3 61031 NULL
128473 +lpfc_idiag_queacc_write_61043 lpfc_idiag_queacc_write 3 61043 NULL
128474 +symtab_init_61050 symtab_init 2 61050 NULL
128475 +fuse_send_write_61053 fuse_send_write 0-4 61053 NULL
128476 +bitmap_scnlistprintf_61062 bitmap_scnlistprintf 2-0 61062 NULL
128477 +ahash_align_buffer_size_61070 ahash_align_buffer_size 0-1-2 61070 NULL
128478 +get_derived_key_61100 get_derived_key 4 61100 NULL
128479 +i40e_calculate_l2fpm_size_61104 i40e_calculate_l2fpm_size 0-4-3-2-1 61104 NULL
128480 +alloc_chrdev_region_61112 alloc_chrdev_region 0 61112 NULL
128481 +__probe_kernel_read_61119 __probe_kernel_read 3 61119 NULL
128482 +vmemmap_alloc_block_buf_61126 vmemmap_alloc_block_buf 1 61126 NULL
128483 +afs_proc_cells_write_61139 afs_proc_cells_write 3 61139 NULL
128484 +pair_device_61175 pair_device 4 61175 NULL nohasharray
128485 +event_oom_late_read_61175 event_oom_late_read 3 61175 &pair_device_61175
128486 +dio_bio_add_page_61178 dio_bio_add_page 0 61178 NULL
128487 +SyS_prctl_61202 SyS_prctl 4 61202 NULL
128488 +srp_create_fr_pool_61207 srp_create_fr_pool 3 61207 NULL
128489 +smk_read_ambient_61220 smk_read_ambient 3 61220 NULL
128490 +v9fs_mmap_file_read_61262 v9fs_mmap_file_read 3 61262 NULL
128491 +btrfs_bio_alloc_61270 btrfs_bio_alloc 3 61270 NULL nohasharray
128492 +find_get_pages_tag_61270 find_get_pages_tag 0 61270 &btrfs_bio_alloc_61270
128493 +hfsplus_getxattr_finder_info_61283 hfsplus_getxattr_finder_info 0 61283 NULL nohasharray
128494 +vortex_adbdma_getlinearpos_61283 vortex_adbdma_getlinearpos 0 61283 &hfsplus_getxattr_finder_info_61283
128495 +nvme_trans_copy_to_user_61288 nvme_trans_copy_to_user 3 61288 NULL
128496 +xfer_from_user_61307 xfer_from_user 3 61307 NULL
128497 +xfrm_user_sec_ctx_size_61320 xfrm_user_sec_ctx_size 0 61320 NULL
128498 +C_SYSC_msgsnd_61330 C_SYSC_msgsnd 3 61330 NULL
128499 +write_file_spectral_short_repeat_61335 write_file_spectral_short_repeat 3 61335 NULL
128500 +st5481_setup_isocpipes_61340 st5481_setup_isocpipes 4-6 61340 NULL
128501 +rx_rx_wa_ba_not_expected_read_61341 rx_rx_wa_ba_not_expected_read 3 61341 NULL
128502 +__dm_get_reserved_ios_61342 __dm_get_reserved_ios 0-3-2 61342 NULL
128503 +debug_debug4_read_61367 debug_debug4_read 3 61367 NULL
128504 +system_enable_write_61396 system_enable_write 3 61396 NULL
128505 +unix_stream_sendmsg_61455 unix_stream_sendmsg 4 61455 NULL
128506 +snd_pcm_lib_writev_transfer_61483 snd_pcm_lib_writev_transfer 5-4-2 61483 NULL
128507 +btrfs_item_size_61485 btrfs_item_size 0 61485 NULL
128508 +erst_errno_61526 erst_errno 0 61526 NULL
128509 +compat_SyS_select_61542 compat_SyS_select 1 61542 NULL
128510 +trace_options_core_write_61551 trace_options_core_write 3 61551 NULL
128511 +dvb_net_ioctl_61559 dvb_net_ioctl 2 61559 NULL
128512 +fan_proc_write_61569 fan_proc_write 3 61569 NULL
128513 +ieee80211_if_read_rc_rateidx_mask_2ghz_61570 ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 NULL
128514 +ldlm_pool_rw_atomic_seq_write_61572 ldlm_pool_rw_atomic_seq_write 3 61572 NULL
128515 +seq_open_private_61589 seq_open_private 3 61589 NULL
128516 +ept_gpte_to_gfn_lvl_61591 ept_gpte_to_gfn_lvl 0-2-1 61591 NULL
128517 +netlink_recvmsg_61600 netlink_recvmsg 4 61600 NULL
128518 +nfs4_init_uniform_client_string_61601 nfs4_init_uniform_client_string 3 61601 NULL
128519 +configfs_write_file_61621 configfs_write_file 3 61621 NULL
128520 +ieee80211_if_fmt_hw_queues_61629 ieee80211_if_fmt_hw_queues 3 61629 NULL
128521 +i2o_parm_table_get_61635 i2o_parm_table_get 6 61635 NULL
128522 +snd_pcm_oss_read3_61643 snd_pcm_oss_read3 0-3 61643 NULL nohasharray
128523 +tcf_hashinfo_init_61643 tcf_hashinfo_init 2 61643 &snd_pcm_oss_read3_61643
128524 +resize_stripes_61650 resize_stripes 2 61650 NULL
128525 +ttm_page_pool_free_61661 ttm_page_pool_free 2-0 61661 NULL
128526 +insert_one_name_61668 insert_one_name 7 61668 NULL
128527 +lock_loop_61681 lock_loop 1 61681 NULL
128528 +filter_read_61692 filter_read 3 61692 NULL
128529 +iov_length_61716 iov_length 0 61716 NULL
128530 +fragmentation_threshold_read_61718 fragmentation_threshold_read 3 61718 NULL
128531 +null_alloc_reqbuf_61719 null_alloc_reqbuf 3 61719 NULL
128532 +read_file_interrupt_61742 read_file_interrupt 3 61742 NULL nohasharray
128533 +read_file_regval_61742 read_file_regval 3 61742 &read_file_interrupt_61742
128534 +SyS_sendto_61763 SyS_sendto 6 61763 NULL
128535 +mls_compute_context_len_61812 mls_compute_context_len 0 61812 NULL
128536 +bfad_debugfs_write_regwr_61841 bfad_debugfs_write_regwr 3 61841 NULL
128537 +regcache_sync_block_61846 regcache_sync_block 5-4 61846 NULL
128538 +ath9k_hw_def_dump_eeprom_61853 ath9k_hw_def_dump_eeprom 5-4 61853 NULL
128539 +evdev_compute_buffer_size_61863 evdev_compute_buffer_size 0 61863 NULL
128540 +SYSC_lsetxattr_61869 SYSC_lsetxattr 4 61869 NULL
128541 +get_fw_name_61874 get_fw_name 3 61874 NULL
128542 +btrfs_ioctl_clone_61886 btrfs_ioctl_clone 3-4-5 61886 NULL
128543 +lprocfs_write_frac_u64_helper_61897 lprocfs_write_frac_u64_helper 2 61897 NULL
128544 +rx_filter_arp_filter_read_61914 rx_filter_arp_filter_read 3 61914 NULL
128545 +au0828_init_isoc_61917 au0828_init_isoc 3-2-4 61917 NULL
128546 +sctp_sendmsg_61919 sctp_sendmsg 4 61919 NULL
128547 +il4965_ucode_rx_stats_read_61948 il4965_ucode_rx_stats_read 3 61948 NULL
128548 +squashfs_read_id_index_table_61961 squashfs_read_id_index_table 4 61961 NULL
128549 +fix_read_error_61965 fix_read_error 4 61965 NULL
128550 +cow_file_range_61979 cow_file_range 3 61979 NULL
128551 +dequeue_event_62000 dequeue_event 3 62000 NULL
128552 +xt_compat_match_offset_62011 xt_compat_match_offset 0 62011 NULL
128553 +SyS_setxattr_62019 SyS_setxattr 4 62019 NULL
128554 +jffs2_do_unlink_62020 jffs2_do_unlink 4 62020 NULL
128555 +SYSC_select_62024 SYSC_select 1 62024 NULL
128556 +pmcraid_build_passthrough_ioadls_62034 pmcraid_build_passthrough_ioadls 2 62034 NULL
128557 +sctp_user_addto_chunk_62047 sctp_user_addto_chunk 2-3 62047 NULL
128558 +do_pselect_62061 do_pselect 1 62061 NULL
128559 +pcpu_alloc_bootmem_62074 pcpu_alloc_bootmem 2 62074 NULL
128560 +jffs2_security_setxattr_62107 jffs2_security_setxattr 4 62107 NULL
128561 +ip_recv_error_62117 ip_recv_error 3 62117 NULL
128562 +generic_block_fiemap_62122 generic_block_fiemap 4 62122 NULL
128563 +llc_ui_header_len_62131 llc_ui_header_len 0 62131 NULL
128564 +qib_diag_write_62133 qib_diag_write 3 62133 NULL
128565 +ql_status_62135 ql_status 5 62135 NULL
128566 +video_usercopy_62151 video_usercopy 2 62151 NULL
128567 +SyS_getxattr_62166 SyS_getxattr 4 62166 NULL
128568 +prism54_wpa_bss_ie_get_62173 prism54_wpa_bss_ie_get 0 62173 NULL
128569 +write_file_dfs_62180 write_file_dfs 3 62180 NULL
128570 +alloc_upcall_62186 alloc_upcall 2 62186 NULL
128571 +sock_kmalloc_62205 sock_kmalloc 2 62205 NULL
128572 +smk_read_syslog_62227 smk_read_syslog 3 62227 NULL
128573 +SYSC_setgroups16_62232 SYSC_setgroups16 1 62232 NULL
128574 +ion_handle_test_dma_62262 ion_handle_test_dma 4-5 62262 NULL
128575 +il_dbgfs_sram_read_62296 il_dbgfs_sram_read 3 62296 NULL
128576 +sparse_early_usemaps_alloc_pgdat_section_62304 sparse_early_usemaps_alloc_pgdat_section 2 62304 NULL
128577 +subsystem_filter_read_62310 subsystem_filter_read 3 62310 NULL
128578 +Wb35Reg_BurstWrite_62327 Wb35Reg_BurstWrite 4 62327 NULL
128579 +subseq_list_62332 subseq_list 3-0 62332 NULL
128580 +ll_statahead_max_seq_write_62333 ll_statahead_max_seq_write 3 62333 NULL
128581 +flash_write_62354 flash_write 3 62354 NULL
128582 +xfpregs_set_62363 xfpregs_set 4 62363 NULL
128583 +rx_rx_timeout_read_62389 rx_rx_timeout_read 3 62389 NULL
128584 +altera_irscan_62396 altera_irscan 2 62396 NULL
128585 +set_ssp_62411 set_ssp 4 62411 NULL
128586 +tracing_saved_cmdlines_size_read_62491 tracing_saved_cmdlines_size_read 3 62491 NULL
128587 +pep_sendmsg_62524 pep_sendmsg 4 62524 NULL
128588 +test_iso_queue_62534 test_iso_queue 5 62534 NULL
128589 +debugfs_read_62535 debugfs_read 3 62535 NULL
128590 +sco_sock_sendmsg_62542 sco_sock_sendmsg 4 62542 NULL
128591 +qib_refresh_qsfp_cache_62547 qib_refresh_qsfp_cache 0 62547 NULL
128592 +xfrm_user_policy_62573 xfrm_user_policy 4 62573 NULL
128593 +get_subdir_62581 get_subdir 3 62581 NULL
128594 +dut_mode_write_62630 dut_mode_write 3 62630 NULL
128595 +vfs_fsync_range_62635 vfs_fsync_range 0 62635 NULL
128596 +lpfc_sli4_queue_alloc_62646 lpfc_sli4_queue_alloc 3 62646 NULL
128597 +printer_req_alloc_62687 printer_req_alloc 2 62687 NULL
128598 +bioset_integrity_create_62708 bioset_integrity_create 2 62708 NULL
128599 +gfs2_log_write_62717 gfs2_log_write 3 62717 NULL
128600 +rdm_62719 rdm 0 62719 NULL
128601 +obd_ioctl_popdata_62741 obd_ioctl_popdata 3 62741 NULL
128602 +key_replays_read_62746 key_replays_read 3 62746 NULL
128603 +lov_verify_lmm_62747 lov_verify_lmm 2 62747 NULL
128604 +mwifiex_rdeeprom_write_62754 mwifiex_rdeeprom_write 3 62754 NULL
128605 +mxt_obj_instances_62764 mxt_obj_instances 0 62764 NULL
128606 +copy_page_to_iter_iovec_62770 copy_page_to_iter_iovec 3-0 62770 NULL nohasharray
128607 +ax25_sendmsg_62770 ax25_sendmsg 4 62770 &copy_page_to_iter_iovec_62770
128608 +C_SYSC_ipc_62776 C_SYSC_ipc 3 62776 NULL
128609 +SyS_sched_getaffinity_62786 SyS_sched_getaffinity 2 62786 NULL
128610 +dm_stats_account_io_62787 dm_stats_account_io 3 62787 NULL
128611 +tracing_total_entries_read_62817 tracing_total_entries_read 3 62817 NULL
128612 +__rounddown_pow_of_two_62836 __rounddown_pow_of_two 0 62836 NULL
128613 +bio_get_nr_vecs_62838 bio_get_nr_vecs 0 62838 NULL
128614 +xlog_recover_add_to_trans_62839 xlog_recover_add_to_trans 4 62839 NULL
128615 +rx_fcs_err_read_62844 rx_fcs_err_read 3 62844 NULL
128616 +l2tp_ip6_recvmsg_62874 l2tp_ip6_recvmsg 4 62874 NULL
128617 +aoechr_write_62883 aoechr_write 3 62883 NULL
128618 +if_spi_host_to_card_62890 if_spi_host_to_card 4 62890 NULL
128619 +mempool_create_slab_pool_62907 mempool_create_slab_pool 1 62907 NULL
128620 +getdqbuf_62908 getdqbuf 1 62908 NULL
128621 +ll_statahead_agl_seq_write_62928 ll_statahead_agl_seq_write 3 62928 NULL
128622 +agp_create_user_memory_62955 agp_create_user_memory 1 62955 NULL
128623 +hwdep_read_62992 hwdep_read 3 62992 NULL
128624 +kstrtoull_from_user_63026 kstrtoull_from_user 2 63026 NULL
128625 +__vb2_perform_fileio_63033 __vb2_perform_fileio 3 63033 NULL
128626 +pipeline_defrag_to_csum_swi_read_63037 pipeline_defrag_to_csum_swi_read 3 63037 NULL
128627 +scsi_host_alloc_63041 scsi_host_alloc 2 63041 NULL
128628 +unlink1_63059 unlink1 3 63059 NULL
128629 +xen_set_nslabs_63066 xen_set_nslabs 0 63066 NULL
128630 +iwl_dbgfs_fw_rx_stats_read_63070 iwl_dbgfs_fw_rx_stats_read 3 63070 NULL
128631 +sep_prepare_input_output_dma_table_in_dcb_63087 sep_prepare_input_output_dma_table_in_dcb 4-5 63087 NULL
128632 +iwl_dbgfs_sensitivity_read_63116 iwl_dbgfs_sensitivity_read 3 63116 NULL
128633 +ext4_chunk_trans_blocks_63123 ext4_chunk_trans_blocks 0-2 63123 NULL
128634 +ubifs_change_one_lp_63157 ubifs_change_one_lp 0 63157 NULL
128635 +smk_write_revoke_subj_63173 smk_write_revoke_subj 3 63173 NULL
128636 +SyS_syslog_63178 SyS_syslog 3 63178 NULL
128637 +vme_master_read_63221 vme_master_read 0 63221 NULL
128638 +SyS_gethostname_63227 SyS_gethostname 2 63227 NULL
128639 +ptp_read_63251 ptp_read 4 63251 NULL
128640 +xfs_dir2_leaf_getdents_63262 xfs_dir2_leaf_getdents 3 63262 NULL
128641 +iwl_dbgfs_fw_error_dump_read_63263 iwl_dbgfs_fw_error_dump_read 3 63263 NULL
128642 +raid5_resize_63306 raid5_resize 2 63306 NULL
128643 +nfsd_vfs_read_63307 nfsd_vfs_read 5 63307 NULL
128644 +ath10k_read_fw_dbglog_63323 ath10k_read_fw_dbglog 3 63323 NULL
128645 +proc_info_read_63344 proc_info_read 3 63344 NULL
128646 +ps_upsd_max_sptime_read_63362 ps_upsd_max_sptime_read 3 63362 NULL
128647 +idmouse_read_63374 idmouse_read 3 63374 NULL
128648 +edac_pci_alloc_ctl_info_63388 edac_pci_alloc_ctl_info 1 63388 NULL nohasharray
128649 +usbnet_read_cmd_nopm_63388 usbnet_read_cmd_nopm 7 63388 &edac_pci_alloc_ctl_info_63388
128650 +rxpipe_missed_beacon_host_int_trig_rx_data_read_63405 rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 NULL
128651 +l2cap_sock_sendmsg_63427 l2cap_sock_sendmsg 4 63427 NULL
128652 +nfsd_symlink_63442 nfsd_symlink 6 63442 NULL
128653 +si5351_bulk_write_63468 si5351_bulk_write 2-3 63468 NULL
128654 +snd_info_entry_write_63474 snd_info_entry_write 3 63474 NULL
128655 +reada_find_extent_63486 reada_find_extent 2 63486 NULL
128656 +iwl_dbgfs_bcast_filters_read_63489 iwl_dbgfs_bcast_filters_read 3 63489 NULL
128657 +snd_pcm_plug_write_transfer_63503 snd_pcm_plug_write_transfer 0-3 63503 NULL
128658 +efx_mcdi_rpc_async_63529 efx_mcdi_rpc_async 4-5 63529 NULL
128659 +ubi_more_leb_change_data_63534 ubi_more_leb_change_data 4 63534 NULL
128660 +write_file_spectral_period_63536 write_file_spectral_period 3 63536 NULL
128661 +if_sdio_read_scratch_63540 if_sdio_read_scratch 0 63540 NULL
128662 +append_to_buffer_63550 append_to_buffer 3 63550 NULL
128663 +kvm_write_guest_page_63555 kvm_write_guest_page 5 63555 NULL
128664 +rproc_alloc_63577 rproc_alloc 5 63577 NULL
128665 +write_debug_level_63613 write_debug_level 3 63613 NULL
128666 +__spi_validate_63618 __spi_validate 0 63618 NULL
128667 +symbol_build_supp_rates_63634 symbol_build_supp_rates 0 63634 NULL
128668 +hid_report_len_63637 hid_report_len 0 63637 NULL
128669 +proc_loginuid_write_63648 proc_loginuid_write 3 63648 NULL
128670 +ValidateDSDParamsChecksum_63654 ValidateDSDParamsChecksum 3 63654 NULL
128671 +ldlm_cli_enqueue_63657 ldlm_cli_enqueue 8 63657 NULL
128672 +hidraw_ioctl_63658 hidraw_ioctl 2 63658 NULL
128673 +vbi_read_63673 vbi_read 3 63673 NULL
128674 +write_file_spectral_fft_period_63696 write_file_spectral_fft_period 3 63696 NULL
128675 +nouveau_object_create__63715 nouveau_object_create_ 5 63715 NULL
128676 +btrfs_insert_delayed_dir_index_63720 btrfs_insert_delayed_dir_index 4 63720 NULL
128677 +selinux_secctx_to_secid_63744 selinux_secctx_to_secid 2 63744 NULL
128678 +snd_pcm_oss_read1_63771 snd_pcm_oss_read1 3 63771 NULL
128679 +snd_opl4_mem_proc_read_63774 snd_opl4_mem_proc_read 5 63774 NULL
128680 +spidev_compat_ioctl_63778 spidev_compat_ioctl 2 63778 NULL
128681 +mwifiex_11n_create_rx_reorder_tbl_63806 mwifiex_11n_create_rx_reorder_tbl 4 63806 NULL
128682 +copy_nodes_to_user_63807 copy_nodes_to_user 2 63807 NULL
128683 +C_SYSC_process_vm_readv_63811 C_SYSC_process_vm_readv 3-5 63811 NULL
128684 +regmap_multi_reg_write_63826 regmap_multi_reg_write 3 63826 NULL
128685 +sel_write_load_63830 sel_write_load 3 63830 NULL
128686 +proc_pid_attr_write_63845 proc_pid_attr_write 3 63845 NULL
128687 +xhci_alloc_stream_info_63902 xhci_alloc_stream_info 3 63902 NULL
128688 +uvc_alloc_urb_buffers_63922 uvc_alloc_urb_buffers 0-2-3 63922 NULL
128689 +snd_compr_write_63923 snd_compr_write 3 63923 NULL
128690 +afs_send_simple_reply_63940 afs_send_simple_reply 3 63940 NULL
128691 +__team_options_register_63941 __team_options_register 3 63941 NULL
128692 +macvtap_recvmsg_63949 macvtap_recvmsg 4 63949 NULL
128693 +set_bredr_63975 set_bredr 4 63975 NULL
128694 +construct_key_and_link_63985 construct_key_and_link 3 63985 NULL
128695 +rs_extent_to_bm_page_63996 rs_extent_to_bm_page 0-1 63996 NULL
128696 +read_file_frameerrors_64001 read_file_frameerrors 3 64001 NULL
128697 +SyS_rt_sigpending_64018 SyS_rt_sigpending 2 64018 NULL
128698 +dbAllocDmapLev_64030 dbAllocDmapLev 0 64030 NULL
128699 +SyS_fsetxattr_64039 SyS_fsetxattr 4 64039 NULL
128700 +__sock_create_64069 __sock_create 0 64069 NULL
128701 +get_u8_64076 get_u8 0 64076 NULL
128702 +xilly_malloc_64077 xilly_malloc 2 64077 NULL
128703 +sl_realloc_bufs_64086 sl_realloc_bufs 2 64086 NULL
128704 +vmci_handle_arr_get_size_64088 vmci_handle_arr_get_size 0 64088 NULL
128705 +lbs_highrssi_read_64089 lbs_highrssi_read 3 64089 NULL
128706 +SyS_set_mempolicy_64096 SyS_set_mempolicy 3 64096 NULL
128707 +to_bytes_64103 to_bytes 0-1 64103 NULL
128708 +SyS_mq_timedsend_64107 SyS_mq_timedsend 3 64107 NULL
128709 +rdma_addr_size_64116 rdma_addr_size 0 64116 NULL
128710 +do_load_xattr_datum_64118 do_load_xattr_datum 0 64118 NULL
128711 +bypass_wd_write_64120 bypass_wd_write 3 64120 NULL
128712 +ext4_prepare_inline_data_64124 ext4_prepare_inline_data 3 64124 NULL
128713 +init_bch_64130 init_bch 1-2 64130 NULL
128714 +ablkcipher_copy_iv_64140 ablkcipher_copy_iv 3 64140 NULL
128715 +dlfb_ops_write_64150 dlfb_ops_write 3 64150 NULL
128716 +bnx2x_vf_mcast_64166 bnx2x_vf_mcast 4 64166 NULL
128717 +cpumask_scnprintf_64170 cpumask_scnprintf 0-2 64170 NULL
128718 +kernfs_iop_setxattr_64220 kernfs_iop_setxattr 4 64220 NULL
128719 +read_pulse_64227 read_pulse 0-3 64227 NULL
128720 +ea_len_64229 ea_len 0 64229 NULL
128721 +io_capture_transfer_64276 io_capture_transfer 4 64276 NULL
128722 +btrfs_file_extent_offset_64278 btrfs_file_extent_offset 0 64278 NULL
128723 +sta_current_tx_rate_read_64286 sta_current_tx_rate_read 3 64286 NULL
128724 +event_id_read_64288 event_id_read 3 64288 NULL nohasharray
128725 +xfs_dir_cilookup_result_64288 xfs_dir_cilookup_result 3 64288 &event_id_read_64288
128726 +ocfs2_block_check_validate_bhs_64302 ocfs2_block_check_validate_bhs 0 64302 NULL
128727 +snd_hda_get_sub_nodes_64304 snd_hda_get_sub_nodes 0 64304 NULL
128728 +error_error_bar_retry_read_64305 error_error_bar_retry_read 3 64305 NULL
128729 +sisusbcon_clear_64329 sisusbcon_clear 4-3-5 64329 NULL
128730 +ts_write_64336 ts_write 3 64336 NULL
128731 +usbtmc_write_64340 usbtmc_write 3 64340 NULL
128732 +user_regset_copyin_64360 user_regset_copyin 7 64360 NULL
128733 +wlc_phy_loadsampletable_nphy_64367 wlc_phy_loadsampletable_nphy 3 64367 NULL
128734 +reg_create_64372 reg_create 5 64372 NULL
128735 +ilo_write_64378 ilo_write 3 64378 NULL
128736 +btrfs_map_block_64379 btrfs_map_block 3 64379 NULL
128737 +vmcs_readl_64381 vmcs_readl 0 64381 NULL
128738 +nilfs_alloc_seg_bio_64383 nilfs_alloc_seg_bio 3 64383 NULL
128739 +ir_lirc_transmit_ir_64403 ir_lirc_transmit_ir 3 64403 NULL
128740 +pidlist_allocate_64404 pidlist_allocate 1 64404 NULL
128741 +rx_hdr_overflow_read_64407 rx_hdr_overflow_read 3 64407 NULL
128742 +keyctl_get_security_64418 keyctl_get_security 3 64418 NULL
128743 +oom_adj_write_64428 oom_adj_write 3 64428 NULL
128744 +read_file_spectral_short_repeat_64431 read_file_spectral_short_repeat 3 64431 NULL
128745 +ax25_recvmsg_64441 ax25_recvmsg 4 64441 NULL
128746 +single_open_size_64483 single_open_size 4 64483 NULL
128747 +p54_parse_rssical_64493 p54_parse_rssical 3 64493 NULL
128748 +msg_data_sz_64503 msg_data_sz 0 64503 NULL
128749 +remove_uuid_64505 remove_uuid 4 64505 NULL
128750 +opera1_usb_i2c_msgxfer_64521 opera1_usb_i2c_msgxfer 4 64521 NULL
128751 +iwl_dbgfs_ucode_tracing_write_64524 iwl_dbgfs_ucode_tracing_write 3 64524 NULL
128752 +ses_send_diag_64527 ses_send_diag 4 64527 NULL
128753 +prctl_set_mm_64538 prctl_set_mm 3 64538 NULL
128754 +SyS_bind_64544 SyS_bind 3 64544 NULL
128755 +rbd_obj_read_sync_64554 rbd_obj_read_sync 3-4 64554 NULL
128756 +__btrfs_prealloc_file_range_64557 __btrfs_prealloc_file_range 3 64557 NULL
128757 +ll_max_rw_chunk_seq_write_64561 ll_max_rw_chunk_seq_write 3 64561 NULL nohasharray
128758 +__spi_sync_64561 __spi_sync 0 64561 &ll_max_rw_chunk_seq_write_64561
128759 +__apei_exec_run_64563 __apei_exec_run 0 64563 NULL
128760 +kstrtoul_from_user_64569 kstrtoul_from_user 2 64569 NULL
128761 +do_erase_64574 do_erase 4 64574 NULL
128762 +fanotify_write_64623 fanotify_write 3 64623 NULL
128763 +_iwl_dbgfs_d0i3_refs_write_64642 _iwl_dbgfs_d0i3_refs_write 3 64642 NULL
128764 +regmap_read_debugfs_64658 regmap_read_debugfs 5 64658 NULL
128765 +tlbflush_read_file_64661 tlbflush_read_file 3 64661 NULL nohasharray
128766 +ocfs2_read_xattr_block_64661 ocfs2_read_xattr_block 0 64661 &tlbflush_read_file_64661
128767 +efx_tsoh_get_buffer_64664 efx_tsoh_get_buffer 3 64664 NULL
128768 +rx_rx_out_of_mpdu_nodes_read_64668 rx_rx_out_of_mpdu_nodes_read 3 64668 NULL
128769 +nr_free_zone_pages_64680 nr_free_zone_pages 0 64680 NULL
128770 +snd_pcm_oss_capture_position_fixup_64713 snd_pcm_oss_capture_position_fixup 0 64713 NULL
128771 +dapm_bias_read_file_64715 dapm_bias_read_file 3 64715 NULL
128772 +atomic_add_return_64720 atomic_add_return 0-1 64720 NULL
128773 +i2400m_msg_to_dev_64722 i2400m_msg_to_dev 3 64722 NULL
128774 +squashfs_read_inode_lookup_table_64739 squashfs_read_inode_lookup_table 4 64739 NULL
128775 +bio_map_kern_64751 bio_map_kern 3 64751 NULL
128776 +rt2x00debug_write_csr_64753 rt2x00debug_write_csr 3 64753 NULL
128777 +hwdep_write_64776 hwdep_write 3 64776 NULL
128778 +message_for_md_64777 message_for_md 5 64777 NULL
128779 +isr_low_rssi_read_64789 isr_low_rssi_read 3 64789 NULL
128780 +regmap_reg_ranges_read_file_64798 regmap_reg_ranges_read_file 3 64798 NULL
128781 +nfsctl_transaction_write_64800 nfsctl_transaction_write 3 64800 NULL
128782 +rfkill_fop_write_64808 rfkill_fop_write 3 64808 NULL
128783 +proc_projid_map_write_64810 proc_projid_map_write 3 64810 NULL
128784 +megaraid_change_queue_depth_64815 megaraid_change_queue_depth 2 64815 NULL
128785 +ecryptfs_send_miscdev_64816 ecryptfs_send_miscdev 2 64816 NULL
128786 +altera_set_dr_pre_64862 altera_set_dr_pre 2 64862 NULL
128787 +pci_vc_do_save_buffer_64876 pci_vc_do_save_buffer 0 64876 NULL
128788 +lprocfs_write_u64_helper_64880 lprocfs_write_u64_helper 2 64880 NULL
128789 +ieee80211_if_read_ave_beacon_64924 ieee80211_if_read_ave_beacon 3 64924 NULL
128790 +ip_options_get_from_user_64958 ip_options_get_from_user 4 64958 NULL nohasharray
128791 +tipc_port_iovec_reject_64958 tipc_port_iovec_reject 4 64958 &ip_options_get_from_user_64958
128792 +traceprobe_probes_write_64969 traceprobe_probes_write 3 64969 NULL
128793 +suspend_dtim_interval_read_64971 suspend_dtim_interval_read 3 64971 NULL
128794 +crypto_ahash_digestsize_65014 crypto_ahash_digestsize 0 65014 NULL
128795 +insert_dent_65034 insert_dent 7 65034 NULL
128796 +ext4_ind_trans_blocks_65053 ext4_ind_trans_blocks 0-2 65053 NULL
128797 +make_idx_node_65068 make_idx_node 0 65068 NULL
128798 +__alloc_bootmem_node_high_65076 __alloc_bootmem_node_high 2 65076 NULL
128799 +batadv_socket_write_65083 batadv_socket_write 3 65083 NULL
128800 +ocfs2_truncate_cluster_pages_65086 ocfs2_truncate_cluster_pages 2 65086 NULL
128801 +ath9k_dump_mci_btcoex_65090 ath9k_dump_mci_btcoex 3-0 65090 NULL
128802 +rx_rx_done_read_65217 rx_rx_done_read 3 65217 NULL
128803 +nouveau_event_create_65229 nouveau_event_create 2-1 65229 NULL
128804 +print_endpoint_stat_65232 print_endpoint_stat 3-4-0 65232 NULL
128805 +whci_n_caps_65247 whci_n_caps 0 65247 NULL
128806 +kmalloc_parameter_65279 kmalloc_parameter 1 65279 NULL
128807 +compat_core_sys_select_65285 compat_core_sys_select 1 65285 NULL
128808 +mpi_set_buffer_65294 mpi_set_buffer 3 65294 NULL
128809 +fat_direct_IO_65295 fat_direct_IO 4 65295 NULL
128810 +redirected_tty_write_65297 redirected_tty_write 3 65297 NULL
128811 +get_var_len_65304 get_var_len 0 65304 NULL
128812 +unpack_array_65318 unpack_array 0 65318 NULL
128813 +pci_vpd_find_tag_65325 pci_vpd_find_tag 0-2 65325 NULL
128814 +dccp_setsockopt_service_65336 dccp_setsockopt_service 4 65336 NULL
128815 +dma_rx_requested_read_65354 dma_rx_requested_read 3 65354 NULL
128816 +alloc_cpu_rmap_65363 alloc_cpu_rmap 1 65363 NULL
128817 +SyS_writev_65372 SyS_writev 3 65372 NULL
128818 +__alloc_bootmem_nopanic_65397 __alloc_bootmem_nopanic 1 65397 NULL
128819 +trace_seq_to_user_65398 trace_seq_to_user 3 65398 NULL
128820 +ocfs2_write_begin_nolock_65410 ocfs2_write_begin_nolock 3-4 65410 NULL
128821 +xpc_kzalloc_cacheline_aligned_65433 xpc_kzalloc_cacheline_aligned 1 65433 NULL
128822 +usb_alloc_coherent_65444 usb_alloc_coherent 2 65444 NULL
128823 +il_dbgfs_wd_timeout_write_65464 il_dbgfs_wd_timeout_write 3 65464 NULL
128824 +clear_user_65470 clear_user 2 65470 NULL
128825 +dpcm_state_read_file_65489 dpcm_state_read_file 3 65489 NULL
128826 +lookup_inline_extent_backref_65493 lookup_inline_extent_backref 9 65493 NULL
128827 +nvme_trans_standard_inquiry_page_65526 nvme_trans_standard_inquiry_page 4 65526 NULL
128828 +tree_mod_log_eb_copy_65535 tree_mod_log_eb_copy 6 65535 NULL
128829 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_hash_aux.data b/tools/gcc/size_overflow_plugin/size_overflow_hash_aux.data
128830 new file mode 100644
128831 index 0000000..560cd7b
128832 --- /dev/null
128833 +++ b/tools/gcc/size_overflow_plugin/size_overflow_hash_aux.data
128834 @@ -0,0 +1,92 @@
128835 +spa_set_aux_vdevs_746 spa_set_aux_vdevs 3 746 NULL
128836 +zfs_lookup_2144 zfs_lookup 0 2144 NULL
128837 +mappedread_2627 mappedread 2 2627 NULL
128838 +vdev_disk_dio_alloc_2957 vdev_disk_dio_alloc 1 2957 NULL
128839 +nv_alloc_pushpage_spl_4286 nv_alloc_pushpage_spl 2 4286 NULL
128840 +zpl_xattr_get_4574 zpl_xattr_get 0 4574 NULL
128841 +sa_replace_all_by_template_5699 sa_replace_all_by_template 3 5699 NULL
128842 +dmu_write_6048 dmu_write 4-3 6048 NULL
128843 +dmu_buf_hold_array_6095 dmu_buf_hold_array 4-3 6095 NULL
128844 +update_pages_6225 update_pages 2-3 6225 NULL
128845 +bio_nr_pages_7117 bio_nr_pages 0-2 7117 NULL
128846 +dmu_buf_hold_array_by_bonus_8562 dmu_buf_hold_array_by_bonus 3-2 8562 NULL
128847 +zpios_dmu_write_8858 zpios_dmu_write 4-5 8858 NULL
128848 +ddi_copyout_9401 ddi_copyout 3 9401 NULL
128849 +avl_numnodes_12384 avl_numnodes 0 12384 NULL
128850 +dmu_write_uio_dnode_12473 dmu_write_uio_dnode 3 12473 NULL
128851 +dmu_xuio_init_12866 dmu_xuio_init 2 12866 NULL
128852 +zpl_read_common_14389 zpl_read_common 0 14389 NULL
128853 +dmu_snapshot_realname_14632 dmu_snapshot_realname 4 14632 NULL
128854 +kmem_alloc_debug_14852 kmem_alloc_debug 1 14852 NULL
128855 +kmalloc_node_nofail_15151 kmalloc_node_nofail 1 15151 NULL
128856 +dmu_write_uio_16351 dmu_write_uio 4 16351 NULL
128857 +zfs_log_write_16524 zfs_log_write 6-5 16524 NULL
128858 +sa_build_layouts_16910 sa_build_layouts 3 16910 NULL
128859 +dsl_dir_namelen_17053 dsl_dir_namelen 0 17053 NULL
128860 +kcopy_copy_to_user_17336 kcopy_copy_to_user 5 17336 NULL
128861 +sa_add_layout_entry_17507 sa_add_layout_entry 3 17507 NULL
128862 +sa_attr_table_setup_18029 sa_attr_table_setup 3 18029 NULL
128863 +uiocopy_18680 uiocopy 2 18680 NULL
128864 +dmu_buf_hold_array_by_dnode_19125 dmu_buf_hold_array_by_dnode 2-3 19125 NULL
128865 +zpl_acl_from_xattr_21141 zpl_acl_from_xattr 2 21141 NULL
128866 +dsl_pool_tx_assign_init_22518 dsl_pool_tx_assign_init 2 22518 NULL
128867 +nvlist_lookup_byte_array_22527 nvlist_lookup_byte_array 0 22527 NULL
128868 +sa_replace_all_by_template_locked_22533 sa_replace_all_by_template_locked 3 22533 NULL
128869 +tsd_hash_table_init_22559 tsd_hash_table_init 1 22559 NULL
128870 +spa_vdev_remove_aux_23966 spa_vdev_remove_aux 4 23966 NULL
128871 +zpl_xattr_acl_set_access_24129 zpl_xattr_acl_set_access 4 24129 NULL
128872 +dmu_assign_arcbuf_24622 dmu_assign_arcbuf 2 24622 NULL
128873 +zap_lookup_norm_25166 zap_lookup_norm 9 25166 NULL
128874 +dmu_prealloc_25456 dmu_prealloc 4-3 25456 NULL
128875 +kmalloc_nofail_26347 kmalloc_nofail 1 26347 NULL
128876 +zfsctl_snapshot_zpath_27578 zfsctl_snapshot_zpath 2 27578 NULL
128877 +zpios_dmu_read_30015 zpios_dmu_read 4-5 30015 NULL
128878 +splat_write_30943 splat_write 3 30943 NULL
128879 +zpl_xattr_get_sa_31183 zpl_xattr_get_sa 0 31183 NULL
128880 +dmu_read_uio_31467 dmu_read_uio 4 31467 NULL
128881 +zfs_replay_fuids_31479 zfs_replay_fuids 4 31479 NULL
128882 +spa_history_log_to_phys_31632 spa_history_log_to_phys 0-1 31632 NULL
128883 +__zpl_xattr_get_32601 __zpl_xattr_get 0 32601 NULL
128884 +proc_copyout_string_34049 proc_copyout_string 2 34049 NULL
128885 +nv_alloc_sleep_spl_34544 nv_alloc_sleep_spl 2 34544 NULL
128886 +nv_alloc_nosleep_spl_34761 nv_alloc_nosleep_spl 2 34761 NULL
128887 +zap_leaf_array_match_36922 zap_leaf_array_match 4 36922 NULL
128888 +copyinstr_36980 copyinstr 3 36980 NULL
128889 +zpl_xattr_acl_set_default_37864 zpl_xattr_acl_set_default 4 37864 NULL
128890 +splat_read_38116 splat_read 3 38116 NULL
128891 +sa_setup_38756 sa_setup 4 38756 NULL
128892 +vdev_disk_physio_39898 vdev_disk_physio 3 39898 NULL
128893 +arc_buf_size_39982 arc_buf_size 0 39982 NULL
128894 +kzalloc_nofail_40719 kzalloc_nofail 1 40719 NULL
128895 +fuidstr_to_sid_40777 fuidstr_to_sid 4 40777 NULL
128896 +vdev_raidz_matrix_reconstruct_40852 vdev_raidz_matrix_reconstruct 2-3 40852 NULL
128897 +sa_find_layout_40892 sa_find_layout 4 40892 NULL
128898 +zpl_xattr_get_dir_41918 zpl_xattr_get_dir 0 41918 NULL
128899 +zfs_sa_get_xattr_42600 zfs_sa_get_xattr 0 42600 NULL
128900 +zpl_xattr_acl_set_42808 zpl_xattr_acl_set 4 42808 NULL
128901 +xdr_dec_array_43091 xdr_dec_array 5 43091 NULL
128902 +dsl_dataset_namelen_43136 dsl_dataset_namelen 0 43136 NULL
128903 +kcopy_write_43683 kcopy_write 3 43683 NULL
128904 +uiomove_44355 uiomove 2 44355 NULL
128905 +dmu_read_44418 dmu_read 4-3 44418 NULL
128906 +ddi_copyin_44846 ddi_copyin 3 44846 NULL
128907 +kcopy_do_get_45061 kcopy_do_get 5 45061 NULL
128908 +copyin_45945 copyin 3 45945 NULL
128909 +zil_itx_create_46555 zil_itx_create 2 46555 NULL
128910 +dmu_write_uio_dbuf_48064 dmu_write_uio_dbuf 3 48064 NULL
128911 +blk_rq_pos_48233 blk_rq_pos 0 48233 NULL
128912 +spa_history_write_49650 spa_history_write 3 49650 NULL
128913 +kcopy_copy_pages_to_user_49823 kcopy_copy_pages_to_user 3-4 49823 NULL
128914 +zfs_log_write_50162 zfs_log_write 6-5 50162 NULL
128915 +i_fm_alloc_51038 i_fm_alloc 2 51038 NULL
128916 +copyout_51409 copyout 3 51409 NULL
128917 +zvol_log_write_54898 zvol_log_write 4-3 54898 NULL
128918 +zfs_acl_node_alloc_55641 zfs_acl_node_alloc 1 55641 NULL
128919 +get_nvlist_56685 get_nvlist 2 56685 NULL
128920 +zprop_get_numprops_56820 zprop_get_numprops 0 56820 NULL
128921 +splat_taskq_test4_common_59829 splat_taskq_test4_common 5 59829 NULL
128922 +zfs_replay_domain_cnt_61399 zfs_replay_domain_cnt 0 61399 NULL
128923 +zpios_write_61823 zpios_write 3 61823 NULL
128924 +proc_copyin_string_62019 proc_copyin_string 4 62019 NULL
128925 +random_get_pseudo_bytes_64611 random_get_pseudo_bytes 2 64611 NULL
128926 +zpios_read_64734 zpios_read 3 64734 NULL
128927 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin/size_overflow_plugin.c
128928 new file mode 100644
128929 index 0000000..95f7abd
128930 --- /dev/null
128931 +++ b/tools/gcc/size_overflow_plugin/size_overflow_plugin.c
128932 @@ -0,0 +1,259 @@
128933 +/*
128934 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
128935 + * Licensed under the GPL v2, or (at your option) v3
128936 + *
128937 + * Homepage:
128938 + * http://www.grsecurity.net/~ephox/overflow_plugin/
128939 + *
128940 + * Documentation:
128941 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
128942 + *
128943 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
128944 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
128945 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
128946 + *
128947 + * Usage:
128948 + * $ make
128949 + * $ make run
128950 + */
128951 +
128952 +#include "gcc-common.h"
128953 +#include "size_overflow.h"
128954 +
128955 +int plugin_is_GPL_compatible;
128956 +
128957 +tree report_size_overflow_decl;
128958 +
128959 +tree size_overflow_type_HI;
128960 +tree size_overflow_type_SI;
128961 +tree size_overflow_type_DI;
128962 +tree size_overflow_type_TI;
128963 +
128964 +static struct plugin_info size_overflow_plugin_info = {
128965 + .version = "20140725",
128966 + .help = "no-size-overflow\tturn off size overflow checking\n",
128967 +};
128968 +
128969 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
128970 +{
128971 + unsigned int arg_count;
128972 + enum tree_code code = TREE_CODE(*node);
128973 +
128974 + switch (code) {
128975 + case FUNCTION_DECL:
128976 + arg_count = type_num_arguments(TREE_TYPE(*node));
128977 + break;
128978 + case FUNCTION_TYPE:
128979 + case METHOD_TYPE:
128980 + arg_count = type_num_arguments(*node);
128981 + break;
128982 + default:
128983 + *no_add_attrs = true;
128984 + error("%s: %qE attribute only applies to functions", __func__, name);
128985 + return NULL_TREE;
128986 + }
128987 +
128988 + for (; args; args = TREE_CHAIN(args)) {
128989 + tree position = TREE_VALUE(args);
128990 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_LOW(position) > arg_count ) {
128991 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
128992 + *no_add_attrs = true;
128993 + }
128994 + }
128995 + return NULL_TREE;
128996 +}
128997 +
128998 +static tree handle_intentional_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
128999 +{
129000 + unsigned int arg_count;
129001 + enum tree_code code = TREE_CODE(*node);
129002 +
129003 + switch (code) {
129004 + case FUNCTION_DECL:
129005 + arg_count = type_num_arguments(TREE_TYPE(*node));
129006 + break;
129007 + case FUNCTION_TYPE:
129008 + case METHOD_TYPE:
129009 + arg_count = type_num_arguments(*node);
129010 + break;
129011 + case FIELD_DECL:
129012 + return NULL_TREE;
129013 + default:
129014 + *no_add_attrs = true;
129015 + error("%qE attribute only applies to functions", name);
129016 + return NULL_TREE;
129017 + }
129018 +
129019 + if (TREE_INT_CST_HIGH(TREE_VALUE(args)) != 0)
129020 + return NULL_TREE;
129021 +
129022 + for (; args; args = TREE_CHAIN(args)) {
129023 + tree position = TREE_VALUE(args);
129024 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_LOW(position) > arg_count ) {
129025 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
129026 + *no_add_attrs = true;
129027 + }
129028 + }
129029 + return NULL_TREE;
129030 +}
129031 +
129032 +static struct attribute_spec size_overflow_attr = {
129033 + .name = "size_overflow",
129034 + .min_length = 1,
129035 + .max_length = -1,
129036 + .decl_required = true,
129037 + .type_required = false,
129038 + .function_type_required = false,
129039 + .handler = handle_size_overflow_attribute,
129040 +#if BUILDING_GCC_VERSION >= 4007
129041 + .affects_type_identity = false
129042 +#endif
129043 +};
129044 +
129045 +static struct attribute_spec intentional_overflow_attr = {
129046 + .name = "intentional_overflow",
129047 + .min_length = 1,
129048 + .max_length = -1,
129049 + .decl_required = true,
129050 + .type_required = false,
129051 + .function_type_required = false,
129052 + .handler = handle_intentional_overflow_attribute,
129053 +#if BUILDING_GCC_VERSION >= 4007
129054 + .affects_type_identity = false
129055 +#endif
129056 +};
129057 +
129058 +static void register_attributes(void __unused *event_data, void __unused *data)
129059 +{
129060 + register_attribute(&size_overflow_attr);
129061 + register_attribute(&intentional_overflow_attr);
129062 +}
129063 +
129064 +static tree create_typedef(tree type, const char* ident)
129065 +{
129066 + tree new_type, decl;
129067 +
129068 + new_type = build_variant_type_copy(type);
129069 + decl = build_decl(BUILTINS_LOCATION, TYPE_DECL, get_identifier(ident), new_type);
129070 + DECL_ORIGINAL_TYPE(decl) = type;
129071 + TYPE_NAME(new_type) = decl;
129072 + return new_type;
129073 +}
129074 +
129075 +// Create the noreturn report_size_overflow() function decl.
129076 +static void size_overflow_start_unit(void __unused *gcc_data, void __unused *user_data)
129077 +{
129078 + tree const_char_ptr_type_node;
129079 + tree fntype;
129080 +
129081 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
129082 +
129083 + size_overflow_type_HI = create_typedef(intHI_type_node, "size_overflow_type_HI");
129084 + size_overflow_type_SI = create_typedef(intSI_type_node, "size_overflow_type_SI");
129085 + size_overflow_type_DI = create_typedef(intDI_type_node, "size_overflow_type_DI");
129086 + size_overflow_type_TI = create_typedef(intTI_type_node, "size_overflow_type_TI");
129087 +
129088 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func, const char *ssa_var)
129089 + fntype = build_function_type_list(void_type_node,
129090 + const_char_ptr_type_node,
129091 + unsigned_type_node,
129092 + const_char_ptr_type_node,
129093 + const_char_ptr_type_node,
129094 + NULL_TREE);
129095 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
129096 +
129097 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
129098 + TREE_PUBLIC(report_size_overflow_decl) = 1;
129099 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
129100 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
129101 + TREE_THIS_VOLATILE(report_size_overflow_decl) = 1;
129102 +}
129103 +
129104 +
129105 +extern struct gimple_opt_pass pass_dce;
129106 +
129107 +static struct opt_pass *make_dce_pass(void)
129108 +{
129109 +#if BUILDING_GCC_VERSION >= 4009
129110 + return make_pass_dce(g);
129111 +#else
129112 + return &pass_dce.pass;
129113 +#endif
129114 +}
129115 +
129116 +
129117 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
129118 +{
129119 + int i;
129120 + const char * const plugin_name = plugin_info->base_name;
129121 + const int argc = plugin_info->argc;
129122 + const struct plugin_argument * const argv = plugin_info->argv;
129123 + bool enable = true;
129124 + struct register_pass_info insert_size_overflow_asm_pass_info;
129125 + struct register_pass_info __unused dump_before_pass_info;
129126 + struct register_pass_info __unused dump_after_pass_info;
129127 + struct register_pass_info insert_size_overflow_check_info;
129128 + struct register_pass_info dce_pass_info;
129129 + static const struct ggc_root_tab gt_ggc_r_gt_size_overflow[] = {
129130 + {
129131 + .base = &report_size_overflow_decl,
129132 + .nelt = 1,
129133 + .stride = sizeof(report_size_overflow_decl),
129134 + .cb = &gt_ggc_mx_tree_node,
129135 + .pchw = &gt_pch_nx_tree_node
129136 + },
129137 + LAST_GGC_ROOT_TAB
129138 + };
129139 +
129140 + insert_size_overflow_asm_pass_info.pass = make_insert_size_overflow_asm_pass();
129141 + insert_size_overflow_asm_pass_info.reference_pass_name = "ssa";
129142 + insert_size_overflow_asm_pass_info.ref_pass_instance_number = 1;
129143 + insert_size_overflow_asm_pass_info.pos_op = PASS_POS_INSERT_AFTER;
129144 +
129145 + dump_before_pass_info.pass = make_dump_pass();
129146 + dump_before_pass_info.reference_pass_name = "increase_alignment";
129147 + dump_before_pass_info.ref_pass_instance_number = 1;
129148 + dump_before_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
129149 +
129150 + insert_size_overflow_check_info.pass = make_insert_size_overflow_check();
129151 + insert_size_overflow_check_info.reference_pass_name = "increase_alignment";
129152 + insert_size_overflow_check_info.ref_pass_instance_number = 1;
129153 + insert_size_overflow_check_info.pos_op = PASS_POS_INSERT_BEFORE;
129154 +
129155 + dump_after_pass_info.pass = make_dump_pass();
129156 + dump_after_pass_info.reference_pass_name = "increase_alignment";
129157 + dump_after_pass_info.ref_pass_instance_number = 1;
129158 + dump_after_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
129159 +
129160 + dce_pass_info.pass = make_dce_pass();
129161 + dce_pass_info.reference_pass_name = "vrp";
129162 + dce_pass_info.ref_pass_instance_number = 1;
129163 + dce_pass_info.pos_op = PASS_POS_INSERT_AFTER;
129164 +
129165 + if (!plugin_default_version_check(version, &gcc_version)) {
129166 + error(G_("incompatible gcc/plugin versions"));
129167 + return 1;
129168 + }
129169 +
129170 + for (i = 0; i < argc; ++i) {
129171 + if (!strcmp(argv[i].key, "no-size-overflow")) {
129172 + enable = false;
129173 + continue;
129174 + }
129175 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
129176 + }
129177 +
129178 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
129179 + if (enable) {
129180 + register_callback(plugin_name, PLUGIN_START_UNIT, &size_overflow_start_unit, NULL);
129181 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_size_overflow);
129182 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &insert_size_overflow_asm_pass_info);
129183 +// register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dump_before_pass_info);
129184 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &insert_size_overflow_check_info);
129185 +// register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dump_after_pass_info);
129186 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dce_pass_info);
129187 + }
129188 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
129189 +
129190 + return 0;
129191 +}
129192 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_plugin_hash.c b/tools/gcc/size_overflow_plugin/size_overflow_plugin_hash.c
129193 new file mode 100644
129194 index 0000000..0888f6c
129195 --- /dev/null
129196 +++ b/tools/gcc/size_overflow_plugin/size_overflow_plugin_hash.c
129197 @@ -0,0 +1,364 @@
129198 +/*
129199 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
129200 + * Licensed under the GPL v2, or (at your option) v3
129201 + *
129202 + * Homepage:
129203 + * http://www.grsecurity.net/~ephox/overflow_plugin/
129204 + *
129205 + * Documentation:
129206 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
129207 + *
129208 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
129209 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
129210 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
129211 + *
129212 + * Usage:
129213 + * $ make
129214 + * $ make run
129215 + */
129216 +
129217 +#include "gcc-common.h"
129218 +#include "size_overflow.h"
129219 +
129220 +#include "size_overflow_hash.h"
129221 +#include "size_overflow_hash_aux.h"
129222 +
129223 +#define CODES_LIMIT 32
129224 +
129225 +static unsigned char get_tree_code(const_tree type)
129226 +{
129227 + switch (TREE_CODE(type)) {
129228 + case ARRAY_TYPE:
129229 + return 0;
129230 + case BOOLEAN_TYPE:
129231 + return 1;
129232 + case ENUMERAL_TYPE:
129233 + return 2;
129234 + case FUNCTION_TYPE:
129235 + return 3;
129236 + case INTEGER_TYPE:
129237 + return 4;
129238 + case POINTER_TYPE:
129239 + return 5;
129240 + case RECORD_TYPE:
129241 + return 6;
129242 + case UNION_TYPE:
129243 + return 7;
129244 + case VOID_TYPE:
129245 + return 8;
129246 + case REAL_TYPE:
129247 + return 9;
129248 + case VECTOR_TYPE:
129249 + return 10;
129250 + case REFERENCE_TYPE:
129251 + return 11;
129252 + case OFFSET_TYPE:
129253 + return 12;
129254 + case COMPLEX_TYPE:
129255 + return 13;
129256 + default:
129257 + debug_tree((tree)type);
129258 + gcc_unreachable();
129259 + }
129260 +}
129261 +
129262 +struct function_hash {
129263 + size_t tree_codes_len;
129264 + unsigned char tree_codes[CODES_LIMIT];
129265 + const_tree fndecl;
129266 + unsigned int hash;
129267 +};
129268 +
129269 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
129270 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
129271 +{
129272 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
129273 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
129274 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
129275 +
129276 + unsigned int m = 0x57559429;
129277 + unsigned int n = 0x5052acdb;
129278 + const unsigned int *key4 = (const unsigned int *)key;
129279 + unsigned int h = len;
129280 + unsigned int k = len + seed + n;
129281 + unsigned long long p;
129282 +
129283 + while (len >= 8) {
129284 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
129285 + len -= 8;
129286 + }
129287 + if (len >= 4) {
129288 + cwmixb(key4[0]) key4 += 1;
129289 + len -= 4;
129290 + }
129291 + if (len)
129292 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
129293 + cwmixb(h ^ (k + n));
129294 + return k ^ h;
129295 +
129296 +#undef cwfold
129297 +#undef cwmixa
129298 +#undef cwmixb
129299 +}
129300 +
129301 +static void set_hash(const char *fn_name, struct function_hash *fn_hash_data)
129302 +{
129303 + unsigned int fn, codes, seed = 0;
129304 +
129305 + fn = CrapWow(fn_name, strlen(fn_name), seed) & 0xffff;
129306 + codes = CrapWow((const char*)fn_hash_data->tree_codes, fn_hash_data->tree_codes_len, seed) & 0xffff;
129307 +
129308 + fn_hash_data->hash = fn ^ codes;
129309 +}
129310 +
129311 +static void set_node_codes(const_tree type, struct function_hash *fn_hash_data)
129312 +{
129313 + gcc_assert(type != NULL_TREE);
129314 + gcc_assert(TREE_CODE_CLASS(TREE_CODE(type)) == tcc_type);
129315 +
129316 + while (type && fn_hash_data->tree_codes_len < CODES_LIMIT) {
129317 + fn_hash_data->tree_codes[fn_hash_data->tree_codes_len] = get_tree_code(type);
129318 + fn_hash_data->tree_codes_len++;
129319 + type = TREE_TYPE(type);
129320 + }
129321 +}
129322 +
129323 +static void set_result_codes(const_tree node, struct function_hash *fn_hash_data)
129324 +{
129325 + const_tree result;
129326 +
129327 + gcc_assert(node != NULL_TREE);
129328 +
129329 + if (DECL_P(node)) {
129330 + result = DECL_RESULT(node);
129331 + if (result != NULL_TREE)
129332 + return set_node_codes(TREE_TYPE(result), fn_hash_data);
129333 + return set_result_codes(TREE_TYPE(node), fn_hash_data);
129334 + }
129335 +
129336 + gcc_assert(TYPE_P(node));
129337 +
129338 + if (TREE_CODE(node) == FUNCTION_TYPE)
129339 + return set_result_codes(TREE_TYPE(node), fn_hash_data);
129340 +
129341 + return set_node_codes(node, fn_hash_data);
129342 +}
129343 +
129344 +static void set_function_codes(struct function_hash *fn_hash_data)
129345 +{
129346 + const_tree arg, type = TREE_TYPE(fn_hash_data->fndecl);
129347 + enum tree_code code = TREE_CODE(type);
129348 +
129349 + gcc_assert(code == FUNCTION_TYPE || code == METHOD_TYPE);
129350 +
129351 + set_result_codes(fn_hash_data->fndecl, fn_hash_data);
129352 +
129353 + for (arg = TYPE_ARG_TYPES(type); arg != NULL_TREE && fn_hash_data->tree_codes_len < CODES_LIMIT; arg = TREE_CHAIN(arg))
129354 + set_node_codes(TREE_VALUE(arg), fn_hash_data);
129355 +}
129356 +
129357 +static const struct size_overflow_hash *get_proper_hash_chain(const struct size_overflow_hash *entry, const char *func_name)
129358 +{
129359 + while (entry) {
129360 + if (!strcmp(entry->name, func_name))
129361 + return entry;
129362 + entry = entry->next;
129363 + }
129364 + return NULL;
129365 +}
129366 +
129367 +const struct size_overflow_hash *get_function_hash(const_tree fndecl)
129368 +{
129369 + const struct size_overflow_hash *entry;
129370 + struct function_hash fn_hash_data;
129371 + const char *func_name;
129372 +
129373 + // skip builtins __builtin_constant_p
129374 + if (DECL_BUILT_IN(fndecl))
129375 + return NULL;
129376 +
129377 + fn_hash_data.fndecl = fndecl;
129378 + fn_hash_data.tree_codes_len = 0;
129379 +
129380 + set_function_codes(&fn_hash_data);
129381 + gcc_assert(fn_hash_data.tree_codes_len != 0);
129382 +
129383 + func_name = DECL_NAME_POINTER(fn_hash_data.fndecl);
129384 + set_hash(func_name, &fn_hash_data);
129385 +
129386 + entry = size_overflow_hash[fn_hash_data.hash];
129387 + entry = get_proper_hash_chain(entry, func_name);
129388 + if (entry)
129389 + return entry;
129390 + entry = size_overflow_hash_aux[fn_hash_data.hash];
129391 + return get_proper_hash_chain(entry, func_name);
129392 +}
129393 +
129394 +static void print_missing_msg(const_tree func, unsigned int argnum)
129395 +{
129396 + location_t loc;
129397 + const char *curfunc;
129398 + struct function_hash fn_hash_data;
129399 +
129400 + fn_hash_data.fndecl = DECL_ORIGIN(func);
129401 + fn_hash_data.tree_codes_len = 0;
129402 +
129403 + loc = DECL_SOURCE_LOCATION(fn_hash_data.fndecl);
129404 + curfunc = DECL_NAME_POINTER(fn_hash_data.fndecl);
129405 +
129406 + set_function_codes(&fn_hash_data);
129407 + set_hash(curfunc, &fn_hash_data);
129408 +
129409 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%u+%u+", curfunc, curfunc, argnum, fn_hash_data.hash);
129410 +}
129411 +
129412 +unsigned int find_arg_number_tree(const_tree arg, const_tree func)
129413 +{
129414 + tree var;
129415 + unsigned int argnum = 1;
129416 +
129417 + if (TREE_CODE(arg) == SSA_NAME)
129418 + arg = SSA_NAME_VAR(arg);
129419 +
129420 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var), argnum++) {
129421 + if (!operand_equal_p(arg, var, 0) && strcmp(DECL_NAME_POINTER(var), DECL_NAME_POINTER(arg)))
129422 + continue;
129423 + if (!skip_types(var))
129424 + return argnum;
129425 + }
129426 +
129427 + return CANNOT_FIND_ARG;
129428 +}
129429 +
129430 +static const char *get_asm_string(const_gimple stmt)
129431 +{
129432 + if (!stmt)
129433 + return NULL;
129434 + if (gimple_code(stmt) != GIMPLE_ASM)
129435 + return NULL;
129436 +
129437 + return gimple_asm_string(stmt);
129438 +}
129439 +
129440 +bool is_size_overflow_intentional_asm_turn_off(const_gimple stmt)
129441 +{
129442 + const char *str;
129443 +
129444 + str = get_asm_string(stmt);
129445 + if (!str)
129446 + return false;
129447 + return !strncmp(str, TURN_OFF_ASM_STR, sizeof(TURN_OFF_ASM_STR) - 1);
129448 +}
129449 +
129450 +bool is_size_overflow_intentional_asm_yes(const_gimple stmt)
129451 +{
129452 + const char *str;
129453 +
129454 + str = get_asm_string(stmt);
129455 + if (!str)
129456 + return false;
129457 + return !strncmp(str, YES_ASM_STR, sizeof(YES_ASM_STR) - 1);
129458 +}
129459 +
129460 +bool is_size_overflow_asm(const_gimple stmt)
129461 +{
129462 + const char *str;
129463 +
129464 + str = get_asm_string(stmt);
129465 + if (!str)
129466 + return false;
129467 + return !strncmp(str, OK_ASM_STR, sizeof(OK_ASM_STR) - 1);
129468 +}
129469 +
129470 +bool is_a_return_check(const_tree node)
129471 +{
129472 + if (TREE_CODE(node) == FUNCTION_DECL)
129473 + return true;
129474 +
129475 + gcc_assert(TREE_CODE(node) == PARM_DECL);
129476 + return false;
129477 +}
129478 +
129479 +// Get the argnum of a function decl, if node is a return then the argnum is 0
129480 +unsigned int get_function_num(const_tree node, const_tree orig_fndecl)
129481 +{
129482 + if (is_a_return_check(node))
129483 + return 0;
129484 + else
129485 + return find_arg_number_tree(node, orig_fndecl);
129486 +}
129487 +
129488 +unsigned int get_correct_arg_count(unsigned int argnum, const_tree fndecl)
129489 +{
129490 + const struct size_overflow_hash *hash;
129491 + unsigned int new_argnum;
129492 + tree arg;
129493 + const_tree origarg;
129494 +
129495 + if (argnum == 0)
129496 + return argnum;
129497 +
129498 + hash = get_function_hash(fndecl);
129499 + if (hash && hash->param & (1U << argnum))
129500 + return argnum;
129501 +
129502 + if (DECL_EXTERNAL(fndecl))
129503 + return argnum;
129504 +
129505 + origarg = DECL_ARGUMENTS(DECL_ORIGIN(fndecl));
129506 + argnum--;
129507 + while (origarg && argnum) {
129508 + origarg = TREE_CHAIN(origarg);
129509 + argnum--;
129510 + }
129511 + gcc_assert(argnum == 0);
129512 + gcc_assert(origarg != NULL_TREE);
129513 +
129514 + for (arg = DECL_ARGUMENTS(fndecl), new_argnum = 1; arg; arg = TREE_CHAIN(arg), new_argnum++)
129515 + if (operand_equal_p(origarg, arg, 0) || !strcmp(DECL_NAME_POINTER(origarg), DECL_NAME_POINTER(arg)))
129516 + return new_argnum;
129517 +
129518 + return CANNOT_FIND_ARG;
129519 +}
129520 +
129521 +static bool is_in_hash_table(const_tree fndecl, unsigned int num)
129522 +{
129523 + const struct size_overflow_hash *hash;
129524 +
129525 + hash = get_function_hash(fndecl);
129526 + if (hash && (hash->param & (1U << num)))
129527 + return true;
129528 + return false;
129529 +}
129530 +
129531 +/* Check if the function has a size_overflow attribute or it is in the size_overflow hash table.
129532 + * If the function is missing everywhere then print the missing message into stderr.
129533 + */
129534 +bool is_missing_function(const_tree orig_fndecl, unsigned int num)
129535 +{
129536 + switch (DECL_FUNCTION_CODE(orig_fndecl)) {
129537 +#if BUILDING_GCC_VERSION >= 4008
129538 + case BUILT_IN_BSWAP16:
129539 +#endif
129540 + case BUILT_IN_BSWAP32:
129541 + case BUILT_IN_BSWAP64:
129542 + case BUILT_IN_EXPECT:
129543 + case BUILT_IN_MEMCMP:
129544 + return false;
129545 + default:
129546 + break;
129547 + }
129548 +
129549 + // skip test.c
129550 + if (strcmp(DECL_NAME_POINTER(current_function_decl), "coolmalloc")) {
129551 + if (lookup_attribute("size_overflow", DECL_ATTRIBUTES(orig_fndecl)))
129552 + warning(0, "unnecessary size_overflow attribute on: %s\n", DECL_NAME_POINTER(orig_fndecl));
129553 + }
129554 +
129555 + if (is_in_hash_table(orig_fndecl, num))
129556 + return false;
129557 +
129558 + print_missing_msg(orig_fndecl, num);
129559 + return true;
129560 +}
129561 +
129562 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
129563 new file mode 100644
129564 index 0000000..924652b
129565 --- /dev/null
129566 +++ b/tools/gcc/stackleak_plugin.c
129567 @@ -0,0 +1,395 @@
129568 +/*
129569 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
129570 + * Licensed under the GPL v2
129571 + *
129572 + * Note: the choice of the license means that the compilation process is
129573 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
129574 + * but for the kernel it doesn't matter since it doesn't link against
129575 + * any of the gcc libraries
129576 + *
129577 + * gcc plugin to help implement various PaX features
129578 + *
129579 + * - track lowest stack pointer
129580 + *
129581 + * TODO:
129582 + * - initialize all local variables
129583 + *
129584 + * BUGS:
129585 + * - none known
129586 + */
129587 +
129588 +#include "gcc-common.h"
129589 +
129590 +int plugin_is_GPL_compatible;
129591 +
129592 +static int track_frame_size = -1;
129593 +static const char track_function[] = "pax_track_stack";
129594 +static const char check_function[] = "pax_check_alloca";
129595 +static tree track_function_decl, check_function_decl;
129596 +static bool init_locals;
129597 +
129598 +static struct plugin_info stackleak_plugin_info = {
129599 + .version = "201408011900",
129600 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
129601 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
129602 +};
129603 +
129604 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
129605 +{
129606 + gimple check_alloca;
129607 + tree alloca_size;
129608 +
129609 + // insert call to void pax_check_alloca(unsigned long size)
129610 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
129611 + check_alloca = gimple_build_call(check_function_decl, 1, alloca_size);
129612 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
129613 +}
129614 +
129615 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
129616 +{
129617 + gimple track_stack;
129618 +
129619 + // insert call to void pax_track_stack(void)
129620 + track_stack = gimple_build_call(track_function_decl, 0);
129621 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
129622 +}
129623 +
129624 +static bool is_alloca(gimple stmt)
129625 +{
129626 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
129627 + return true;
129628 +
129629 +#if BUILDING_GCC_VERSION >= 4007
129630 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
129631 + return true;
129632 +#endif
129633 +
129634 + return false;
129635 +}
129636 +
129637 +static unsigned int execute_stackleak_tree_instrument(void)
129638 +{
129639 + basic_block bb, entry_bb;
129640 + bool prologue_instrumented = false, is_leaf = true;
129641 +
129642 + entry_bb = ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb;
129643 +
129644 + // 1. loop through BBs and GIMPLE statements
129645 + FOR_EACH_BB_FN(bb, cfun) {
129646 + gimple_stmt_iterator gsi;
129647 +
129648 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
129649 + gimple stmt;
129650 +
129651 + stmt = gsi_stmt(gsi);
129652 +
129653 + if (is_gimple_call(stmt))
129654 + is_leaf = false;
129655 +
129656 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
129657 + if (!is_alloca(stmt))
129658 + continue;
129659 +
129660 + // 2. insert stack overflow check before each __builtin_alloca call
129661 + stackleak_check_alloca(&gsi);
129662 +
129663 + // 3. insert track call after each __builtin_alloca call
129664 + stackleak_add_instrumentation(&gsi);
129665 + if (bb == entry_bb)
129666 + prologue_instrumented = true;
129667 + }
129668 + }
129669 +
129670 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
129671 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
129672 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
129673 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
129674 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
129675 + return 0;
129676 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
129677 + return 0;
129678 +
129679 + // 4. insert track call at the beginning
129680 + if (!prologue_instrumented) {
129681 + gimple_stmt_iterator gsi;
129682 +
129683 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
129684 + if (dom_info_available_p(CDI_DOMINATORS))
129685 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
129686 + gsi = gsi_start_bb(bb);
129687 + stackleak_add_instrumentation(&gsi);
129688 + }
129689 +
129690 + return 0;
129691 +}
129692 +
129693 +static unsigned int execute_stackleak_final(void)
129694 +{
129695 + rtx insn, next;
129696 +
129697 + if (cfun->calls_alloca)
129698 + return 0;
129699 +
129700 + // keep calls only if function frame is big enough
129701 + if (get_frame_size() >= track_frame_size)
129702 + return 0;
129703 +
129704 + // 1. find pax_track_stack calls
129705 + for (insn = get_insns(); insn; insn = next) {
129706 + // 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))
129707 + rtx body;
129708 +
129709 + next = NEXT_INSN(insn);
129710 + if (!CALL_P(insn))
129711 + continue;
129712 + body = PATTERN(insn);
129713 + if (GET_CODE(body) != CALL)
129714 + continue;
129715 + body = XEXP(body, 0);
129716 + if (GET_CODE(body) != MEM)
129717 + continue;
129718 + body = XEXP(body, 0);
129719 + if (GET_CODE(body) != SYMBOL_REF)
129720 + continue;
129721 +// if (strcmp(XSTR(body, 0), track_function))
129722 + if (SYMBOL_REF_DECL(body) != track_function_decl)
129723 + continue;
129724 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
129725 + // 2. delete call
129726 + delete_insn_and_edges(insn);
129727 +#if BUILDING_GCC_VERSION >= 4007
129728 + if (GET_CODE(next) == NOTE && NOTE_KIND(next) == NOTE_INSN_CALL_ARG_LOCATION) {
129729 + insn = next;
129730 + next = NEXT_INSN(insn);
129731 + delete_insn_and_edges(insn);
129732 + }
129733 +#endif
129734 + }
129735 +
129736 +// print_simple_rtl(stderr, get_insns());
129737 +// print_rtl(stderr, get_insns());
129738 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
129739 +
129740 + return 0;
129741 +}
129742 +
129743 +static bool gate_stackleak_track_stack(void)
129744 +{
129745 + tree section;
129746 +
129747 + if (ix86_cmodel != CM_KERNEL)
129748 + return false;
129749 +
129750 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
129751 + if (section && TREE_VALUE(section)) {
129752 + section = TREE_VALUE(TREE_VALUE(section));
129753 +
129754 + if (!strncmp(TREE_STRING_POINTER(section), ".init.text", 10))
129755 + return false;
129756 + if (!strncmp(TREE_STRING_POINTER(section), ".devinit.text", 13))
129757 + return false;
129758 + if (!strncmp(TREE_STRING_POINTER(section), ".cpuinit.text", 13))
129759 + return false;
129760 + if (!strncmp(TREE_STRING_POINTER(section), ".meminit.text", 13))
129761 + return false;
129762 + }
129763 +
129764 + return track_frame_size >= 0;
129765 +}
129766 +
129767 +static void stackleak_start_unit(void *gcc_data, void *user_data)
129768 +{
129769 + tree fntype;
129770 +
129771 + // void pax_track_stack(void)
129772 + fntype = build_function_type_list(void_type_node, NULL_TREE);
129773 + track_function_decl = build_fn_decl(track_function, fntype);
129774 + DECL_ASSEMBLER_NAME(track_function_decl); // for LTO
129775 + TREE_PUBLIC(track_function_decl) = 1;
129776 + DECL_EXTERNAL(track_function_decl) = 1;
129777 + DECL_ARTIFICIAL(track_function_decl) = 1;
129778 +
129779 + // void pax_check_alloca(unsigned long)
129780 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
129781 + check_function_decl = build_fn_decl(check_function, fntype);
129782 + DECL_ASSEMBLER_NAME(check_function_decl); // for LTO
129783 + TREE_PUBLIC(check_function_decl) = 1;
129784 + DECL_EXTERNAL(check_function_decl) = 1;
129785 + DECL_ARTIFICIAL(check_function_decl) = 1;
129786 +}
129787 +
129788 +#if BUILDING_GCC_VERSION >= 4009
129789 +static const struct pass_data stackleak_tree_instrument_pass_data = {
129790 +#else
129791 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
129792 + .pass = {
129793 +#endif
129794 + .type = GIMPLE_PASS,
129795 + .name = "stackleak_tree_instrument",
129796 +#if BUILDING_GCC_VERSION >= 4008
129797 + .optinfo_flags = OPTGROUP_NONE,
129798 +#endif
129799 +#if BUILDING_GCC_VERSION >= 4009
129800 + .has_gate = true,
129801 + .has_execute = true,
129802 +#else
129803 + .gate = gate_stackleak_track_stack,
129804 + .execute = execute_stackleak_tree_instrument,
129805 + .sub = NULL,
129806 + .next = NULL,
129807 + .static_pass_number = 0,
129808 +#endif
129809 + .tv_id = TV_NONE,
129810 + .properties_required = PROP_gimple_leh | PROP_cfg,
129811 + .properties_provided = 0,
129812 + .properties_destroyed = 0,
129813 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
129814 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa | TODO_rebuild_cgraph_edges
129815 +#if BUILDING_GCC_VERSION < 4009
129816 + }
129817 +#endif
129818 +};
129819 +
129820 +#if BUILDING_GCC_VERSION >= 4009
129821 +static const struct pass_data stackleak_final_rtl_opt_pass_data = {
129822 +#else
129823 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
129824 + .pass = {
129825 +#endif
129826 + .type = RTL_PASS,
129827 + .name = "stackleak_final",
129828 +#if BUILDING_GCC_VERSION >= 4008
129829 + .optinfo_flags = OPTGROUP_NONE,
129830 +#endif
129831 +#if BUILDING_GCC_VERSION >= 4009
129832 + .has_gate = true,
129833 + .has_execute = true,
129834 +#else
129835 + .gate = gate_stackleak_track_stack,
129836 + .execute = execute_stackleak_final,
129837 + .sub = NULL,
129838 + .next = NULL,
129839 + .static_pass_number = 0,
129840 +#endif
129841 + .tv_id = TV_NONE,
129842 + .properties_required = 0,
129843 + .properties_provided = 0,
129844 + .properties_destroyed = 0,
129845 + .todo_flags_start = 0,
129846 + .todo_flags_finish = TODO_dump_func
129847 +#if BUILDING_GCC_VERSION < 4009
129848 + }
129849 +#endif
129850 +};
129851 +
129852 +#if BUILDING_GCC_VERSION >= 4009
129853 +namespace {
129854 +class stackleak_tree_instrument_pass : public gimple_opt_pass {
129855 +public:
129856 + stackleak_tree_instrument_pass() : gimple_opt_pass(stackleak_tree_instrument_pass_data, g) {}
129857 + bool gate() { return gate_stackleak_track_stack(); }
129858 + unsigned int execute() { return execute_stackleak_tree_instrument(); }
129859 +};
129860 +
129861 +class stackleak_final_rtl_opt_pass : public rtl_opt_pass {
129862 +public:
129863 + stackleak_final_rtl_opt_pass() : rtl_opt_pass(stackleak_final_rtl_opt_pass_data, g) {}
129864 + bool gate() { return gate_stackleak_track_stack(); }
129865 + unsigned int execute() { return execute_stackleak_final(); }
129866 +};
129867 +}
129868 +
129869 +static opt_pass *make_stackleak_tree_instrument_pass(void)
129870 +{
129871 + return new stackleak_tree_instrument_pass();
129872 +}
129873 +
129874 +static opt_pass *make_stackleak_final_rtl_opt_pass(void)
129875 +{
129876 + return new stackleak_final_rtl_opt_pass();
129877 +}
129878 +#else
129879 +static struct opt_pass *make_stackleak_tree_instrument_pass(void)
129880 +{
129881 + return &stackleak_tree_instrument_pass.pass;
129882 +}
129883 +
129884 +static struct opt_pass *make_stackleak_final_rtl_opt_pass(void)
129885 +{
129886 + return &stackleak_final_rtl_opt_pass.pass;
129887 +}
129888 +#endif
129889 +
129890 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
129891 +{
129892 + const char * const plugin_name = plugin_info->base_name;
129893 + const int argc = plugin_info->argc;
129894 + const struct plugin_argument * const argv = plugin_info->argv;
129895 + int i;
129896 + struct register_pass_info stackleak_tree_instrument_pass_info;
129897 + struct register_pass_info stackleak_final_pass_info;
129898 + static const struct ggc_root_tab gt_ggc_r_gt_stackleak[] = {
129899 + {
129900 + .base = &track_function_decl,
129901 + .nelt = 1,
129902 + .stride = sizeof(track_function_decl),
129903 + .cb = &gt_ggc_mx_tree_node,
129904 + .pchw = &gt_pch_nx_tree_node
129905 + },
129906 + {
129907 + .base = &check_function_decl,
129908 + .nelt = 1,
129909 + .stride = sizeof(check_function_decl),
129910 + .cb = &gt_ggc_mx_tree_node,
129911 + .pchw = &gt_pch_nx_tree_node
129912 + },
129913 + LAST_GGC_ROOT_TAB
129914 + };
129915 +
129916 + stackleak_tree_instrument_pass_info.pass = make_stackleak_tree_instrument_pass();
129917 +// stackleak_tree_instrument_pass_info.reference_pass_name = "tree_profile";
129918 + stackleak_tree_instrument_pass_info.reference_pass_name = "optimized";
129919 + stackleak_tree_instrument_pass_info.ref_pass_instance_number = 1;
129920 + stackleak_tree_instrument_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
129921 +
129922 + stackleak_final_pass_info.pass = make_stackleak_final_rtl_opt_pass();
129923 + stackleak_final_pass_info.reference_pass_name = "final";
129924 + stackleak_final_pass_info.ref_pass_instance_number = 1;
129925 + stackleak_final_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
129926 +
129927 + if (!plugin_default_version_check(version, &gcc_version)) {
129928 + error(G_("incompatible gcc/plugin versions"));
129929 + return 1;
129930 + }
129931 +
129932 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
129933 +
129934 + for (i = 0; i < argc; ++i) {
129935 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
129936 + if (!argv[i].value) {
129937 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
129938 + continue;
129939 + }
129940 + track_frame_size = atoi(argv[i].value);
129941 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
129942 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
129943 + continue;
129944 + }
129945 + if (!strcmp(argv[i].key, "initialize-locals")) {
129946 + if (argv[i].value) {
129947 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
129948 + continue;
129949 + }
129950 + init_locals = true;
129951 + continue;
129952 + }
129953 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
129954 + }
129955 +
129956 + register_callback(plugin_name, PLUGIN_START_UNIT, &stackleak_start_unit, NULL);
129957 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_stackleak);
129958 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
129959 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
129960 +
129961 + return 0;
129962 +}
129963 diff --git a/tools/gcc/structleak_plugin.c b/tools/gcc/structleak_plugin.c
129964 new file mode 100644
129965 index 0000000..4ee2231
129966 --- /dev/null
129967 +++ b/tools/gcc/structleak_plugin.c
129968 @@ -0,0 +1,274 @@
129969 +/*
129970 + * Copyright 2013-2014 by PaX Team <pageexec@freemail.hu>
129971 + * Licensed under the GPL v2
129972 + *
129973 + * Note: the choice of the license means that the compilation process is
129974 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
129975 + * but for the kernel it doesn't matter since it doesn't link against
129976 + * any of the gcc libraries
129977 + *
129978 + * gcc plugin to forcibly initialize certain local variables that could
129979 + * otherwise leak kernel stack to userland if they aren't properly initialized
129980 + * by later code
129981 + *
129982 + * Homepage: http://pax.grsecurity.net/
129983 + *
129984 + * Usage:
129985 + * $ # for 4.5/4.6/C based 4.7
129986 + * $ 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
129987 + * $ # for C++ based 4.7/4.8+
129988 + * $ 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
129989 + * $ gcc -fplugin=./structleak_plugin.so test.c -O2
129990 + *
129991 + * TODO: eliminate redundant initializers
129992 + * increase type coverage
129993 + */
129994 +
129995 +#include "gcc-common.h"
129996 +
129997 +// unused C type flag in all versions 4.5-4.9
129998 +#define TYPE_USERSPACE(TYPE) TYPE_LANG_FLAG_3(TYPE)
129999 +
130000 +int plugin_is_GPL_compatible;
130001 +
130002 +static struct plugin_info structleak_plugin_info = {
130003 + .version = "201401260140",
130004 + .help = "disable\tdo not activate plugin\n",
130005 +};
130006 +
130007 +static tree handle_user_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
130008 +{
130009 + *no_add_attrs = true;
130010 +
130011 + // check for types? for now accept everything linux has to offer
130012 + if (TREE_CODE(*node) != FIELD_DECL)
130013 + return NULL_TREE;
130014 +
130015 + *no_add_attrs = false;
130016 + return NULL_TREE;
130017 +}
130018 +
130019 +static struct attribute_spec user_attr = {
130020 + .name = "user",
130021 + .min_length = 0,
130022 + .max_length = 0,
130023 + .decl_required = false,
130024 + .type_required = false,
130025 + .function_type_required = false,
130026 + .handler = handle_user_attribute,
130027 +#if BUILDING_GCC_VERSION >= 4007
130028 + .affects_type_identity = true
130029 +#endif
130030 +};
130031 +
130032 +static void register_attributes(void *event_data, void *data)
130033 +{
130034 + register_attribute(&user_attr);
130035 +// register_attribute(&force_attr);
130036 +}
130037 +
130038 +static tree get_field_type(tree field)
130039 +{
130040 + return strip_array_types(TREE_TYPE(field));
130041 +}
130042 +
130043 +static bool is_userspace_type(tree type)
130044 +{
130045 + tree field;
130046 +
130047 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
130048 + tree fieldtype = get_field_type(field);
130049 + enum tree_code code = TREE_CODE(fieldtype);
130050 +
130051 + if (code == RECORD_TYPE || code == UNION_TYPE)
130052 + if (is_userspace_type(fieldtype))
130053 + return true;
130054 +
130055 + if (lookup_attribute("user", DECL_ATTRIBUTES(field)))
130056 + return true;
130057 + }
130058 + return false;
130059 +}
130060 +
130061 +static void finish_type(void *event_data, void *data)
130062 +{
130063 + tree type = (tree)event_data;
130064 +
130065 + if (TYPE_USERSPACE(type))
130066 + return;
130067 +
130068 + if (is_userspace_type(type))
130069 + TYPE_USERSPACE(type) = 1;
130070 +}
130071 +
130072 +static void initialize(tree var)
130073 +{
130074 + basic_block bb;
130075 + gimple_stmt_iterator gsi;
130076 + tree initializer;
130077 + gimple init_stmt;
130078 +
130079 + // this is the original entry bb before the forced split
130080 + // TODO: check further BBs in case more splits occured before us
130081 + bb = ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb->next_bb;
130082 +
130083 + // first check if the variable is already initialized, warn otherwise
130084 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
130085 + gimple stmt = gsi_stmt(gsi);
130086 + tree rhs1;
130087 +
130088 + // we're looking for an assignment of a single rhs...
130089 + if (!gimple_assign_single_p(stmt))
130090 + continue;
130091 + rhs1 = gimple_assign_rhs1(stmt);
130092 +#if BUILDING_GCC_VERSION >= 4007
130093 + // ... of a non-clobbering expression...
130094 + if (TREE_CLOBBER_P(rhs1))
130095 + continue;
130096 +#endif
130097 + // ... to our variable...
130098 + if (gimple_get_lhs(stmt) != var)
130099 + continue;
130100 + // if it's an initializer then we're good
130101 + if (TREE_CODE(rhs1) == CONSTRUCTOR)
130102 + return;
130103 + }
130104 +
130105 + // these aren't the 0days you're looking for
130106 +// inform(DECL_SOURCE_LOCATION(var), "userspace variable will be forcibly initialized");
130107 +
130108 + // build the initializer expression
130109 + initializer = build_constructor(TREE_TYPE(var), NULL);
130110 +
130111 + // build the initializer stmt
130112 + init_stmt = gimple_build_assign(var, initializer);
130113 + gsi = gsi_start_bb(ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb);
130114 + gsi_insert_before(&gsi, init_stmt, GSI_NEW_STMT);
130115 + update_stmt(init_stmt);
130116 +}
130117 +
130118 +static unsigned int handle_function(void)
130119 +{
130120 + basic_block bb;
130121 + unsigned int ret = 0;
130122 + tree var;
130123 + unsigned int i;
130124 +
130125 + // split the first bb where we can put the forced initializers
130126 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
130127 + if (dom_info_available_p(CDI_DOMINATORS))
130128 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
130129 +
130130 + // enumarate all local variables and forcibly initialize our targets
130131 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
130132 + tree type = TREE_TYPE(var);
130133 +
130134 + gcc_assert(DECL_P(var));
130135 + if (!auto_var_in_fn_p(var, current_function_decl))
130136 + continue;
130137 +
130138 + // only care about structure types
130139 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
130140 + continue;
130141 +
130142 + // if the type is of interest, examine the variable
130143 + if (TYPE_USERSPACE(type))
130144 + initialize(var);
130145 + }
130146 +
130147 + return ret;
130148 +}
130149 +
130150 +#if BUILDING_GCC_VERSION >= 4009
130151 +static const struct pass_data structleak_pass_data = {
130152 +#else
130153 +static struct gimple_opt_pass structleak_pass = {
130154 + .pass = {
130155 +#endif
130156 + .type = GIMPLE_PASS,
130157 + .name = "structleak",
130158 +#if BUILDING_GCC_VERSION >= 4008
130159 + .optinfo_flags = OPTGROUP_NONE,
130160 +#endif
130161 +#if BUILDING_GCC_VERSION >= 4009
130162 + .has_gate = false,
130163 + .has_execute = true,
130164 +#else
130165 + .gate = NULL,
130166 + .execute = handle_function,
130167 + .sub = NULL,
130168 + .next = NULL,
130169 + .static_pass_number = 0,
130170 +#endif
130171 + .tv_id = TV_NONE,
130172 + .properties_required = PROP_cfg,
130173 + .properties_provided = 0,
130174 + .properties_destroyed = 0,
130175 + .todo_flags_start = 0,
130176 + .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
130177 +#if BUILDING_GCC_VERSION < 4009
130178 + }
130179 +#endif
130180 +};
130181 +
130182 +#if BUILDING_GCC_VERSION >= 4009
130183 +namespace {
130184 +class structleak_pass : public gimple_opt_pass {
130185 +public:
130186 + structleak_pass() : gimple_opt_pass(structleak_pass_data, g) {}
130187 + unsigned int execute() { return handle_function(); }
130188 +};
130189 +}
130190 +
130191 +static opt_pass *make_structleak_pass(void)
130192 +{
130193 + return new structleak_pass();
130194 +}
130195 +#else
130196 +static struct opt_pass *make_structleak_pass(void)
130197 +{
130198 + return &structleak_pass.pass;
130199 +}
130200 +#endif
130201 +
130202 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
130203 +{
130204 + int i;
130205 + const char * const plugin_name = plugin_info->base_name;
130206 + const int argc = plugin_info->argc;
130207 + const struct plugin_argument * const argv = plugin_info->argv;
130208 + bool enable = true;
130209 + struct register_pass_info structleak_pass_info;
130210 +
130211 + structleak_pass_info.pass = make_structleak_pass();
130212 + structleak_pass_info.reference_pass_name = "ssa";
130213 + structleak_pass_info.ref_pass_instance_number = 1;
130214 + structleak_pass_info.pos_op = PASS_POS_INSERT_AFTER;
130215 +
130216 + if (!plugin_default_version_check(version, &gcc_version)) {
130217 + error(G_("incompatible gcc/plugin versions"));
130218 + return 1;
130219 + }
130220 +
130221 + if (strcmp(lang_hooks.name, "GNU C")) {
130222 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
130223 + enable = false;
130224 + }
130225 +
130226 + for (i = 0; i < argc; ++i) {
130227 + if (!strcmp(argv[i].key, "disable")) {
130228 + enable = false;
130229 + continue;
130230 + }
130231 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
130232 + }
130233 +
130234 + register_callback(plugin_name, PLUGIN_INFO, NULL, &structleak_plugin_info);
130235 + if (enable) {
130236 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &structleak_pass_info);
130237 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
130238 + }
130239 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
130240 +
130241 + return 0;
130242 +}
130243 diff --git a/tools/include/linux/compiler.h b/tools/include/linux/compiler.h
130244 index 88461f0..6fb70a0 100644
130245 --- a/tools/include/linux/compiler.h
130246 +++ b/tools/include/linux/compiler.h
130247 @@ -35,6 +35,14 @@
130248 # define unlikely(x) __builtin_expect(!!(x), 0)
130249 #endif
130250
130251 +#ifndef __size_overflow
130252 +# define __size_overflow(...)
130253 +#endif
130254 +
130255 +#ifndef __intentional_overflow
130256 +# define __intentional_overflow(...)
130257 +#endif
130258 +
130259 #define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
130260
130261 #endif /* _TOOLS_LINUX_COMPILER_H */
130262 diff --git a/tools/lib/api/Makefile b/tools/lib/api/Makefile
130263 index ce00f7e..0aca5e4 100644
130264 --- a/tools/lib/api/Makefile
130265 +++ b/tools/lib/api/Makefile
130266 @@ -16,7 +16,7 @@ LIB_OBJS += $(OUTPUT)fs/fs.o
130267
130268 LIBFILE = libapikfs.a
130269
130270 -CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC
130271 +CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC
130272 EXTLIBS = -lelf -lpthread -lrt -lm
130273 ALL_CFLAGS = $(CFLAGS) $(BASIC_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
130274 ALL_LDFLAGS = $(LDFLAGS)
130275 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
130276 index 6789d788..4afd019e 100644
130277 --- a/tools/perf/util/include/asm/alternative-asm.h
130278 +++ b/tools/perf/util/include/asm/alternative-asm.h
130279 @@ -5,4 +5,7 @@
130280
130281 #define altinstruction_entry #
130282
130283 + .macro pax_force_retaddr rip=0, reload=0
130284 + .endm
130285 +
130286 #endif
130287 diff --git a/tools/virtio/linux/uaccess.h b/tools/virtio/linux/uaccess.h
130288 index 0a578fe..b81f62d 100644
130289 --- a/tools/virtio/linux/uaccess.h
130290 +++ b/tools/virtio/linux/uaccess.h
130291 @@ -13,7 +13,7 @@ static inline void __chk_user_ptr(const volatile void *p, size_t size)
130292 ({ \
130293 typeof(ptr) __pu_ptr = (ptr); \
130294 __chk_user_ptr(__pu_ptr, sizeof(*__pu_ptr)); \
130295 - ACCESS_ONCE(*(__pu_ptr)) = x; \
130296 + ACCESS_ONCE_RW(*(__pu_ptr)) = x; \
130297 0; \
130298 })
130299
130300 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
130301 index 4b6c01b..16eb755 100644
130302 --- a/virt/kvm/kvm_main.c
130303 +++ b/virt/kvm/kvm_main.c
130304 @@ -76,12 +76,17 @@ LIST_HEAD(vm_list);
130305
130306 static cpumask_var_t cpus_hardware_enabled;
130307 static int kvm_usage_count = 0;
130308 -static atomic_t hardware_enable_failed;
130309 +static atomic_unchecked_t hardware_enable_failed;
130310
130311 struct kmem_cache *kvm_vcpu_cache;
130312 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
130313
130314 -static __read_mostly struct preempt_ops kvm_preempt_ops;
130315 +static void kvm_sched_in(struct preempt_notifier *pn, int cpu);
130316 +static void kvm_sched_out(struct preempt_notifier *pn, struct task_struct *next);
130317 +static struct preempt_ops kvm_preempt_ops = {
130318 + .sched_in = kvm_sched_in,
130319 + .sched_out = kvm_sched_out,
130320 +};
130321
130322 struct dentry *kvm_debugfs_dir;
130323
130324 @@ -761,7 +766,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
130325 /* We can read the guest memory with __xxx_user() later on. */
130326 if ((mem->slot < KVM_USER_MEM_SLOTS) &&
130327 ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
130328 - !access_ok(VERIFY_WRITE,
130329 + !access_ok_noprefault(VERIFY_WRITE,
130330 (void __user *)(unsigned long)mem->userspace_addr,
130331 mem->memory_size)))
130332 goto out;
130333 @@ -1618,9 +1623,17 @@ EXPORT_SYMBOL_GPL(kvm_read_guest_cached);
130334
130335 int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len)
130336 {
130337 - const void *zero_page = (const void *) __va(page_to_phys(ZERO_PAGE(0)));
130338 + int r;
130339 + unsigned long addr;
130340
130341 - return kvm_write_guest_page(kvm, gfn, zero_page, offset, len);
130342 + addr = gfn_to_hva(kvm, gfn);
130343 + if (kvm_is_error_hva(addr))
130344 + return -EFAULT;
130345 + r = __clear_user((void __user *)addr + offset, len);
130346 + if (r)
130347 + return -EFAULT;
130348 + mark_page_dirty(kvm, gfn);
130349 + return 0;
130350 }
130351 EXPORT_SYMBOL_GPL(kvm_clear_guest_page);
130352
130353 @@ -1870,7 +1883,7 @@ static int kvm_vcpu_release(struct inode *inode, struct file *filp)
130354 return 0;
130355 }
130356
130357 -static struct file_operations kvm_vcpu_fops = {
130358 +static file_operations_no_const kvm_vcpu_fops __read_only = {
130359 .release = kvm_vcpu_release,
130360 .unlocked_ioctl = kvm_vcpu_ioctl,
130361 #ifdef CONFIG_COMPAT
130362 @@ -2540,7 +2553,7 @@ out:
130363 }
130364 #endif
130365
130366 -static struct file_operations kvm_vm_fops = {
130367 +static file_operations_no_const kvm_vm_fops __read_only = {
130368 .release = kvm_vm_release,
130369 .unlocked_ioctl = kvm_vm_ioctl,
130370 #ifdef CONFIG_COMPAT
130371 @@ -2640,7 +2653,7 @@ out:
130372 return r;
130373 }
130374
130375 -static struct file_operations kvm_chardev_ops = {
130376 +static file_operations_no_const kvm_chardev_ops __read_only = {
130377 .unlocked_ioctl = kvm_dev_ioctl,
130378 .compat_ioctl = kvm_dev_ioctl,
130379 .llseek = noop_llseek,
130380 @@ -2666,7 +2679,7 @@ static void hardware_enable_nolock(void *junk)
130381
130382 if (r) {
130383 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
130384 - atomic_inc(&hardware_enable_failed);
130385 + atomic_inc_unchecked(&hardware_enable_failed);
130386 printk(KERN_INFO "kvm: enabling virtualization on "
130387 "CPU%d failed\n", cpu);
130388 }
130389 @@ -2722,10 +2735,10 @@ static int hardware_enable_all(void)
130390
130391 kvm_usage_count++;
130392 if (kvm_usage_count == 1) {
130393 - atomic_set(&hardware_enable_failed, 0);
130394 + atomic_set_unchecked(&hardware_enable_failed, 0);
130395 on_each_cpu(hardware_enable_nolock, NULL, 1);
130396
130397 - if (atomic_read(&hardware_enable_failed)) {
130398 + if (atomic_read_unchecked(&hardware_enable_failed)) {
130399 hardware_disable_all_nolock();
130400 r = -EBUSY;
130401 }
130402 @@ -3130,7 +3143,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
130403 kvm_arch_vcpu_put(vcpu);
130404 }
130405
130406 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
130407 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
130408 struct module *module)
130409 {
130410 int r;
130411 @@ -3177,7 +3190,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
130412 if (!vcpu_align)
130413 vcpu_align = __alignof__(struct kvm_vcpu);
130414 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
130415 - 0, NULL);
130416 + SLAB_USERCOPY, NULL);
130417 if (!kvm_vcpu_cache) {
130418 r = -ENOMEM;
130419 goto out_free_3;
130420 @@ -3187,9 +3200,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
130421 if (r)
130422 goto out_free;
130423
130424 + pax_open_kernel();
130425 kvm_chardev_ops.owner = module;
130426 kvm_vm_fops.owner = module;
130427 kvm_vcpu_fops.owner = module;
130428 + pax_close_kernel();
130429
130430 r = misc_register(&kvm_dev);
130431 if (r) {
130432 @@ -3199,9 +3214,6 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
130433
130434 register_syscore_ops(&kvm_syscore_ops);
130435
130436 - kvm_preempt_ops.sched_in = kvm_sched_in;
130437 - kvm_preempt_ops.sched_out = kvm_sched_out;
130438 -
130439 r = kvm_init_debug();
130440 if (r) {
130441 printk(KERN_ERR "kvm: create debugfs files failed\n");